#ifndef _MAIN_H_
#define _MAIN_H_

/*
Allegro includes.
*/
#include <allegro.h>

#ifdef ALLEGRO_WINDOWS
  #include <winalleg.h>
  #define random()   rand()
  #define srandom(x) srand(x)
#endif

/*
Standard library includes.
*/
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

/*
Calculation defines, simpifies often used calculations.
Note : I think they are horribly inefficient but I don't have time to figure this
out right now (SH '99).
*/
#define to360(x)        (((x)*360)>>8)
#define to256(x)        (((x)<<8)/360)
#define grad360(x)      ((x)/57.29578)
#define grad256(x)      ((x)/40.74366)
#define angle360(x,y)   ((int)(360-((atan2(x,y) + 2.87913) * 80.90022)))
#define angle256(x,y)   ((int)(256-((atan2(x,y) + 2.87913) * 57.52904)))


/*
Class includes.
*/
#include "c_efx.h"
#include "c_list.h"
#include "c_entity.h"

/*
Datafile includes.
*/
#include "buggy.h"
#include "gfxdata.h"

/*
Datafile defines, automates type-casting and referencing.
*/
#define _mainbitmap(x)  (BITMAP*)maindata[x].dat
#define _buggy(x, y)    (BITMAP*)maindata[BUGG10000_BMP + x + (y*8)].dat
#define _twentynine(x)  (BITMAP*)maindata[T90000_BMP + x].dat
#define _wheel(x)       (BITMAP*)maindata[WHEEL0000_BMP + x].dat
#define _mainpal        (RGB*)maindata[COLOR_PCX].dat
#define _explodata(x)   (BITMAP*)gfxdata[x+FIRE0000_TGA].dat
#define _font(x)        (FONT*)gfxdata[x+FONT8_1_PCX].dat
#define _firedata(x,y)  (BITMAP*)gfxdata[y+SHINE0A_TGA+(x*4)].dat

/*
Mathematical defines.
*/
#define CLAMP(x, a, b)  MIN(MAX(x, a), b)
#define mouseover(x1,y1,x2,y2)  (mouse_x >= x1 && mouse_x < x2 && mouse_y >= y1 && mouse_y < y2)


/*
Some global functions.
*/
BITMAP *load_map(int mn);
void draw_map(BITMAP *buffer, BITMAP *map);

#define msx sx
#define msy sy

/*
Global variables to be used by most if not all classes.
*/
extern BITMAP    *buffer;
extern BITMAP    *topbar;

extern short      sx;
extern short      sy;

extern DATAFILE  *maindata;
extern DATAFILE  *gfxdata;

extern COLOR_MAP  light_table;
extern COLOR_MAP  flare_table;
extern COLOR_MAP  trans_table[3];
extern RGB_MAP    rgb_table;

extern LIST       elist;
extern BUGGY     *player[50];
extern int        numplayers;

#endif

/* END */
