// Header File
// Created 6/6/2007; 12:50:59 PM
//AI STUFF CURTOSEY of MALCOLM SMITH
#define ERR_NORMAL_EXIT 0
#define ERR_MEMORY 1
#define ERR_TEXFILE1 2
#define ERR_TEXFILE2 3
#define ERR_TEXFILE3 4
#define ERR_TEXFILE4 5
#define ERR_TEXFILE5 6
#define ERR_TEXFILE6 7
#define ERR_TEXFILE7 8
#define ERR_TEXTFILE1 9
#define ERR_TEXTFILE2 10
#define ERR_MAPFILE 11
#define ERR_FONTFILE 12
#define ERR_UNKNOWN 13
#define SP_CPOS 1
#define SP_CYBORG 2
#define SP_ZOMBIE 3
#define SP_BARREL 4
#define SP_SHOTGUN 5
#define SP_RAILGUN 6
#define SP_HEALTH_LARGE 7
#define SP_HEALTH_SMALL 8
#define SP_AMMOBOX 9
#define SP_SHOTGUN_SHELLS 10
#define SP_IMP 11
#define SP_TORCH 12
#define SP_YELLOW_KEY 13
#define SP_BLUE_KEY 14
#define SP_COLUMN 15
#define SP_TURBINE 16
#define SP_BOSS 17
#define SP_SKULL_BOX 18
#define SP_PENDULUM 19
#define SP_FIRE 20
#define SP_SPIKES 21
#define SP_VINES_1 22
#define SP_VINES_2 23
#define SP_VINES_3 24
#define SP_HOSTAGE 26
#define SP_ARROWS 27
#define SP_PLASMA_AMMO 28
#define SP_ROCKET_AMMO 29
#define SP_ROCKET_LAUNCHER 30
#define SP_PLASMA_GUN 31
#define SP_EXPLOSION 32
#define SP_CAMERA_TRACKTILE 33
#define SP_DOOMGUY_FRONT 34
#define SP_DOOMGUY_BACK 35
#define SP_DOOMGUY_TRACKTILE 36
#define MAX_MSG_LENGTH 20

#define MAX_NR_FIREBALLS 2
#define MAX_NR_PLR_PROJECTILES 2
#define MAX_NR_LVL_SPRITES 60
#define MAX_NR_SPRITES (MAX_NR_LVL_SPRITES+MAX_NR_FIREBALLS+MAX_NR_PLR_PROJECTILES)
#define MAX_DOOR_WAIT 50


#define SPRITE_FREE 0
#define SPRITE_INUSE 1
#define THROW_FIREBALL 20
#define INSTANT_HIT 10
#define PROJ_UNUSED 0
#define PROJ_ROCKET 1
#define PROJ_PLASMA 2
#define DEAD 1
#define ALIVE 0
#define ROCKET 0
#define PLASMA 1
#define PISTOL 1
#define SHOTGUN 2
#define RAILGUN 3
#define FIST 4
#define ROCKET_LAUNCHER 5
#define PLASMA_GUN 6
#define EXPLODING 1
#define PROJ_NORMAL 0
#define NORMAL_LEVEL 0
#define DESTROY_ENEMIES 1
#define TURN_OFF_SWITCHES 2
#define DESTROY_TURBINES 3
#define FIND_BOXES 4
#define DESTROY_COMPUTERS 5
#define FREE_HOSTAGES 6
#define MAX_LEVEL_SWITCHES 25
#define MAX_LEVEL_COMPS 25
char  doortimers[MAX_NR_DOORS];
short switchdoors1[MAX_NR_DOORS][2];
short switchdoors2[MAX_NR_DOORS][2];
unsigned char deadtimers[MAX_NR_SPRITES];
short blue_key_doors[MAX_NR_DOORS][2];
short yellow_key_doors[MAX_NR_DOORS][2];
void* mapfile_handle;
unsigned short* current_map = 0; 
char firstrun = 1;
char timer = 0;
short display_offset  = 0; // will be set depending on calctype (TI89 or TI92p)
short display_offsetx = 0; // will be set depending on calctype (TI89 or TI92p)
short display_offsety = 0; // will be set depending on calctype (TI89 or TI92p)
char portal_nr;
char motion_background = 0;
char background_number = 0;
char Time = 0;
char Time2 = 0;

const char const* messages[][5] = {	
	{"You Need The" , "Yellow Key" , "", "", ""},	// 1
	{"You Need The" , "Blue Key" , "", "", ""}, // 2
	{"You Found A" , "Secret Area" , "", "", ""}, // 3 
	{"You Must" , "Destroy" , "All Enemies", "To Continue", ""},	// 4
	{"You Must" , "Turn Off" , "All Power", "To Continue", ""},	// 5
	{"You Must" , "Destroy" , "All Power", "Turbines", "To Continue"},	// 6
	{"You Must" , "Collect" , "All Boxes", "To Continue", ""},	// 7
	{"You Must" , "Destroy" , "All Computer","Terminals", "To Continue"}, // 8
	{"You Must" , "Free" , "All Hostages", "To Continue", ""}, // 9 
	{"You Have" , "Found A" , "Health Pack", "", ""}, // 10
	{"You Have" , "Found Some" , "Bullets", "", ""}, // 11
	{"You Have" , "Found Some" , "Shells", "", ""}, // 12
	{"You Have" , "Found Some" , "Rockets", "", ""}, // 13
	{"You Have" , "Found Some" , "Plasma", "", ""}, // 14
	{"You Have" , "Found A" , "Shotgun", "", ""}, // 15
	{"You Have" , "Found A" , "Minigun", "", ""}, // 16
	{"You Have" , "Found A" , "Rocket", "Launcher", ""}, // 17
	{"You Have" , "Found A" , "Plasma", "Rifle", ""}, // 18
	{"You Have" , "Found A" , "Yellow Key", "", ""}, // 19
	{"You Have" , "Found A" , "Blue Key", "", ""}, // 20
	{"Welcome to" , "Doom89" , "(c)2007", "Aaron Miller", ""}, // 21
	{"You Have" , "Found A" , "Box", "", ""}, // 22
};

short message_queue[10] = {0,0,0,0,0,0,0,0,0,0};
short message_counter = 0;
short message_step = 0;

char NumberHostages = 0;

short damageconfig[6] = {
	1,
	5,
	1,
	1,
	10,
	2
};

typedef struct
{
	unsigned char state;
	short position;
} partialdoor;

partialdoor PartialDoors[MAX_NR_DOORS];

typedef struct 
{
	short cam_track_x;
	short cam_track_y;
	short plr_track_x;
	short plr_track_y;
} TrackTiles;

TrackTiles cinematic_tile;

typedef struct //FireBall Structure
{
	short in_use;
	FATSPRITE fbspr;
	short xpos;
	short ypos;
	short speed;
	short orientation;
	char exploding;
	int shot_by;
	TEXCONFIG *src;
} FireBall;

FireBall fireballs[MAX_NR_FIREBALLS];

typedef struct //Projectile Structure
{
	short in_use;
	FATSPRITE pjspr;
	short xpos;
	short ypos;
	short speed;
	short orientation;
	char type;
	char exploding;
	TEXCONFIG *src;
} PlayerProjectile;

PlayerProjectile PlrProj[MAX_NR_PLR_PROJECTILES];


// Font stuff curtosy of David Randall // 

typedef struct
{
	unsigned char* pFont;
	unsigned char* pWidth;
	short height;
} UserFontType;

UserFontType userFont;

typedef struct
{
	short x;
	short y;
	char darkness;
} SpecialTile;

SpecialTile DarkTile = {
	0,
	0,
	0
};

typedef struct
{
	short x;
	short y;
}PortalDest;

PortalDest Portal[3];

unsigned char crosshair[]={0x18,0x24,0x24,0x18};
//sprite structure written by MAlCOlM SMITH.
typedef struct //SpriteStruct
{
	char type; //From level data
	short life;
	char moving;
	char speed;
	TEXCONFIG *src;
  short staticsprite;
  short desire;
  short dead;
  char damage;
} SpriteStruct;

SpriteStruct sprites_extra[MAX_NR_SPRITES];

typedef struct 
{
char i;
char shooting;
char health;
char lives;
char timer;
char pistol;
char shotgun;
char railgun;
char num_sprites;
char current_level;
char yellow_key;
char blue_key;
char number_switches;
char number_switches_on;
char difficulty;
char AETC;
char number_enemies;
char number_turbines;
char number_skullboxes;
char number_computers;
char num_fireballs;
char num_plr_proj;
char have_rocket_launcher;
char have_plasma_gun;
char Auto_Aim;
char darkness;
char switch_doors1;
char switch_doors2;
}gameglobals;



gameglobals gg = {
	0, //generic index integer
	0, // currently shooting? 
	100, // health
	5, // lives
	0,  // timer
	1, // pistol (always set may change later.) 
	0,  // have shotgun?
  0,  // have railgun?
  0, // total number of sprites
 -1, //currentmap
  0, // whether or not you have the yellow key.
  0,  // whether or not you have the blue key.
  0,	// number of switches in the level.
  0,  // number of switches on in the level (refers to power switches only)
  0,  // difficulty level
  0,  // wether or not you need to complete special task
  0, // number of enemies
  0, // number of power turbines.
  0, // number of skullboxes.
  0, // number of computer terminals.
  0, // number of fireballs.
  0, // number of player projectiles.
  0, // have the rocket launcher ?
  0, // have the plasma gun? 
  1, // Auto Aim is on?
  0, // darkness?
  0,
  0
};



typedef struct
{
	char xsize;
	char ysize;
} MapHeader;

MapHeader mapheader = {
	0,
	0,
};


typedef struct 
{
	char type;
	unsigned char ammo;
	unsigned char shells;
	unsigned char damage;
	unsigned char plasma_ammo;
	unsigned char rockets; 
}WeaponStruct;

WeaponStruct weapon =
{
	PISTOL, // type of gun;
	100, // bullets.
	0, // shotgun shells
	1, // weapon damage.
	0, // plasma gun ammo.
	0, // number of rockets. 
};

//=============================================================
// CODE curtosy of Malcolm Smith, edited by me.
//=============================================================

void PlayerMove2(FATCONFIG* fc,register short newxpos,register short newypos)
{
  short newxmod = newxpos >> 6;
  short newymod = newypos >> 6;
  //-------------------------------------------------------------------------
  // check if we are still within the map
  //-------------------------------------------------------------------------
  if (newxmod > fc->map_width - 1 ||
      newymod > fc->map_height - 1 || newxmod < 0 || newymod < 0)
    {
	 		return;
    }

  if (!ValidMove(fc,newxpos, newypos))
    {				// if new position is invalid ...
      // ...but old position is OK, we're against a wall to east or west
      if (ValidMove(fc, fc->cam_xpos, newypos))
	{
	  // don't change angle if movement is perpendicular to the wall
	  //if (stepy != 0)
	    {
	      // still allow movement along y = parallel to wall
	      fc->cam_ypos = newypos;
	    }
	}
      // ...but (new x, old y) is OK, we're against a wall to north or south
      if (ValidMove(fc, newxpos, fc->cam_ypos))
	{
	  // don't change angle if movement is perpendicular to the wall
	  //if (stepx != 0)
	    {
	      // still allow movement along x = parallel to wall
	      fc->cam_xpos = newxpos;
	    }
	}
      // ...otherwise we're in a corner, so do nothing
      return;
    }

  //-------------------------------------------------------------------------
  // everything okay -> let's set the new position
  //-------------------------------------------------------------------------

  fc->cam_xpos = newxpos;
  fc->cam_ypos = newypos;
}


void ResetGameGlobals(void)
{
gg.i = 0;
gg.shooting = 0;
gg.health = 100;
weapon.ammo = 100;
weapon.type = PISTOL;
weapon.shells = 0;
weapon.damage = 1;
weapon.plasma_ammo = 0;
weapon.rockets = 0;
gg.timer = 0;
gg.pistol = 1;
gg.shotgun = 0;
gg.railgun = 0;
gg.have_plasma_gun = 0;
gg.have_rocket_launcher = 0;
gg.num_sprites = 0;
gg.number_enemies = 0;
gg.num_fireballs = 0;
gg.num_plr_proj = 0;
gg.number_turbines = 0;
gg.number_skullboxes = 0;
gg.number_computers = 0;
gg.yellow_key = 0;
gg.blue_key = 0;
gg.darkness = 0;
}

typedef struct 
{
	int cont_choice;
	int switch_weapon;
	int shoot;
	int strafe;
	int run;
	int action;
	int contrast_up;
	int contrast_dn;
	int cur_keys[7];
}ControlStruct;

ControlStruct Controls = 
{
	0,
	PADSTATE_KC,
	PADSTATE_KA,
	PADSTATE_KB,
	PADSTATE_KE,
	PADSTATE_KF,
	PADSTATE_PLUS,
	PADSTATE_MINUS,
	{2,0,1,4,5,8,9}
};

typedef struct 
{
	const char const* Keys[10];
}ContEnum;

int ControlValue[10] = {PADSTATE_KA,PADSTATE_KB,PADSTATE_KC,PADSTATE_KD,PADSTATE_KE,PADSTATE_KF,PADSTATE_KG,PADSTATE_KH,
	 PADSTATE_PLUS,PADSTATE_MINUS};

ContEnum Keys160 = 
{
	{"[2nd]","[Diamond]","[Home]","[X]","[Shift]","[Alpha]","[Mode]","[Y]","[+]","[-]"}
};

ContEnum Keys240 = 
{
	{"[F1]","[F2]","[F3]","[F4]","[F5]","[F6]","[F7]","[F8]","[+]","[-]"}
};

const char const* GraphicQual[2] = {"LOW","HI"};
const char const* AutoAimStr[2] = {"OFF","ON"};

const char const* OptionChoices[7] = 
{"Switch Weapon:","Shoot Button:","Strafe Button:","Run Button:","Action Button:","Contrast Up:","Contrast Dn:"};


