// C Header File // Created 11/27/2002; 12:59:39 PM /**************************************************************************** * OBLIVION VERSION STUFF * ****************************************************************************/ const char* const titleVersionString = "OBLIVION v1.15"; const char* const authorString = "Malcolm Smith"; const char* const webSiteString = "http://ti.malcolm-s.net"; /**************************************************************************** * DEFINES * ****************************************************************************/ //#define DEBUG #define STARTLEVEL 1 #define STARTHEALTH 100 #define STARTARMOR 50 #define END_OF_GAME 9 #define NEW_LEVEL 8 #define OLD_LEVEL 7 #define PLAYER_DIED 6 #define LOAD_SAVE 5 #define FORCE_QUIT 4 #define SPRITE_CODE_MIN ((char)-0x01) #define SPRITE_CODE_MAX ((char)-0x3F) #define EVENT_CODE_MIN ((char)-0x40) #define EVENT_CODE_MAX ((char)-0x7E) //0x7F is reserved for doors! #define SPRITE_FREE 0 #define SPRITE_INUSE 1 #define INVINCIBLE (-1) #define INFINITE_AMMO (-1) #define LIGHTS_BUTTON 0x3F #define TURN_SIZE (ANGLE_015/2) #define WEAPON_COUNT 6 #define DEFAULT_WEAPON FOOT #define MAX_BUTTONS 12 //If this needs to be changed, update LvlMaker too #define MAX_UNIQUE_BUTTONS 3 #define MAX_DOORS (MAX_BUTTONS*2) #define MAX_LEVEL_SPRITES 25 #define MAX_EXTRA_SPRITES 8 //Spawned explosions, etc #define MAX_SPRITES (MAX_LEVEL_SPRITES+MAX_EXTRA_SPRITES) //#define MAX_SPRITES_ONSCREEN 4 #define MAX_PLAYER_PROJECTILES 9 #define MAX_ENEMY_PROJECTILES 9 #define MAX_PROJECTILES (MAX_PLAYER_PROJECTILES+MAX_ENEMY_PROJECTILES) #define MAX_PROJECTILE_CYCLES 60 #define MAX_DIFFERENT_ANIMATED_WALLS 3 #ifdef COMPRESSED_TEXTURES #define MAX_TEXTURES 17 #endif #define MAX_DOOR_WAIT 50 #define MAX_ARMOR 200 #define MAX_HEALTH 100 #define MAX_VEHICLE_SPEED 14 #define MAX_CHGWEAPON 4 #define NR_TEXTURES (TOTAL_TEXCONFIGS_IN_oblvgfx1 + MAX_UNIQUE_BUTTONS*2\ + MAX_DIFFERENT_ANIMATED_WALLS) #define MARQUEE_SIZE 512 #define NR_STARS 300 #define ZOFFSET 200 #define ADDITIONALLY_LINES 8 // the textplane is oversized, so no // clipping is necessary #define LINES_TO_SCROLL 1 // how much lines gets scrolled each time #define BGMAX 3 #define OBLIVION_ERROR_COUNT 5 #define MAX_NR_DOORS 64 #define RANDOM_STRENGTH 3 #define MENUCHOICES 5 #define OPTIONS 3 #define DIFFICULTIES 5 /**************************************************************************** * ENUMERATIONS * ****************************************************************************/ enum GameDirections { LEFT,RIGHT }; enum faceDirections { FACEAWAY,FACETOWARD }; enum EnemyBehaviors { COMING, GOING, FLEEING }; enum WeaponNumbers { FOOT,PISTOL,MACHINEGUN,ROCKETLAUNCHER,PLASMAGUN,RAILGUN }; enum healthStuff { becomesSmallHealth = 1, becomesLargeHealth = 2 }; enum Lights { LIGHTS_OFF,LIGHTS_ON }; enum ButtonStatus { BUTTON_UNPRESSED, BUTTON_PRESSED }; enum LevelStyles { level_normal, level_fadeIntoDistance, level_killAllEnemiesToExit, level_killGuardianToContinue, level_findWorkingVehicle, level_vehicle, level_destroyAllMonitors, level_destroyAllPanels, level_destroyAllGenerators }; enum FileConstants { HOWMANY = 50, MAXLEN = 9 }; enum OblivionErrors { OBLIVION_OUT_OF_MEM, OBLIVION_GFX_FILE_ERROR, OBLIVION_DATA_FILE_ERROR, OBLIVION_MAP_INCORRECT_ERROR, OBLIVION_MAP_FILE_ERROR }; enum GameKeys { KEY_FIRE,KEY_STRAFE,KEY_PRESSBUTTON, KEY_SWITCHWEAPON,KEY_SPEEDUP,KEY_PAUSE, KEY_BOSS,KEY_SAVE, KEY_LOAD }; enum enemyDesires { ENEMY_NONE=0x0,ENEMY_SHOOTER=0x1,ENEMY_CHASER=0x2,ENEMY_BOSS=0x4 }; enum ButtonBehaviors { SHOOT_ONLY=1, PRESS_ONLY }; enum GameStrings { ePaused,ePressAnyKey,ePressOnToTurnOff,eGameSaved, ePressLoadToConfirm,ePressHomeToRestart, ePressAppsToChangeKeys,eDoorToggled,eNeedKeycard,eLocked, eFindWorkingVehicle,eVehicle, eKillAllEnemiesToExit,eKillGuardianToContinue,eDestroyAllMonitors, eDestroyAllPanels, eDestroyAllGenerators,eObjectiveNotComplete,eCoalRealization, eButtonToGoBack, e10Health,e25Health,e15Health,e50Armor,e100Armor,eKeycard, ePistolAmmo,eMachGunAmmo,eRocketAmmo,ePlasmaAmmo,eRailGunAmmo, ePistol,eMachinegun,eRocketLauncher,ePlasmaGun,eRailGun, eLoadWhenGameStarts,eToLoadMidSave, eHealthHUD,eArmorHUD,eAmmoHUD,eLevel,eFloor,eRoof }; /**************************************************************************** * STRUCTURES * ****************************************************************************/ //----------------------------------------------------------------------------- // single texture strip 16 pixel "wide" and 64 pixel "tall" // (in real it's 64 pixel "wide" and 16 pixel "tall" due to 90 degree rotation) //----------------------------------------------------------------------------- typedef struct { unsigned short* lightdata; // pointer to a 16 "columns" wide strip (light plane data) unsigned short* darkdata; // pointer to a 16 "columns" wide strip (dark plane data) unsigned short* maskdata; // a possible mask for it or NULL (ignored for walls!!) short mirrored; // if ==STRIP_NORMAL this strip is rendered normal // if ==STRIP_MIRRORED this strip is rendered mirrored // if ==STRIP_IGNORE this strip will be ignored (not rendered) } TEXSTRIP; //----------------------------------------------------------------------------- // texture description (64x64 pixels) //----------------------------------------------------------------------------- typedef struct { TEXSTRIP strips[4]; // each 64x64 pixel texture consists of 4 texture strips } TEXCONFIG; //----------------------------------------------------------------------------- // sprite description //----------------------------------------------------------------------------- typedef struct _FATSPRITE { short xpos; // x position of sprite short ypos; // y position of sprite short orientation; // orientation of sprite short nr_textures; // number of textures used for this sprite // should be 8 for 8 directional sprites TEXCONFIG* textures; // pointer to start of texture array short height; // filled by FAT engine (-1 not visible) short centerx; // filled by FAT engine (-1 not visible) struct _FATSPRITE* prev; // --- used by FAT engine for reversed Z drawing // (if this is NULL, than the actual sprite is the // farthest away sprite which is still visible) struct _FATSPRITE* next; // --- used by FAT engine for reversed Z drawing // (starting from the farthest away sprite this // points to the next nearest sprite OR NULL if // there are no more visible sprites) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! void* clientdata; // maybe used freely by the client program to // store any data it wants (NOT USED BY ENGINE) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! unsigned short drawmode; // sprite drawing mode to use short dist; // ONLY for FAT engine's internal use! short angle; // filled by FAT engine (angle between player and sprite) // (OR: -1 if sprite not visible!) unsigned short reserved1; // --- reserved for FAT engine's internals unsigned long reserved2; // --- reserved for FAT engine's internals unsigned long reserved3; // --- reserved for FAT engine's internals } FATSPRITE; //----------------------------------------------------------------------------- // the main config structure for the FAT-Engine //----------------------------------------------------------------------------- typedef struct { short map_width; // width of the map short map_height; // height of the map char* map_data; // pointer to the map data itself TEXCONFIG* textures; // pointer to the used textures short nr_sprites; // number of sprites FATSPRITE* sprites; // the sprite array short cam_xpos; // camera position x short cam_ypos; // camera position y short cam_orientation; // camera orientation (0 .. 575) unsigned short* dest_plane0; // destination plane0 to copy result into unsigned short* dest_plane1; // destination plane1 to copy result into unsigned short* background; // pointer to image with 96x96 pixels and 2 planes unsigned long frame_counter; // frame counter (gets incremented by engine) } FATCONFIG; //----------------------------------------------------------------------------- // door description //----------------------------------------------------------------------------- typedef struct { short xtile; // x position of door (field MUST be HERE!!) short ytile; // y position of door (field MUST be HERE!!) unsigned char type; // DOOR_HORIZONTAL or DOOR_VERTICAL (NOT yet: PWALL_NORTH ...) unsigned char state; // DOOR_OPEN, DOOR_OPENING, DOOR_CLOSED, or DOOR_CLOSING // Note: state is not evaluated by the engine, its only // for the client to keep track of the state of a door short position; // 0 = closed, 64 or higher = open, between = partially open TEXCONFIG* doortexture; // pointer to door texture TEXCONFIG* sidetexture; // pointer to side texture //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! void* clientdata; // maybe used freely by the client program to // store any data it wants (NOT USED BY ENGINE) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } FATDOOR; typedef struct { unsigned char state; // DOOR_OPEN, DOOR_OPENING, DOOR_CLOSED, or DOOR_CLOSING // Note: state is not evaluated by the engine, its only // for the client to keep track of the state of a door short position; // 0 = closed, 64 or higher = open, between = partially open } PartialDoor; typedef struct //Weapon { const short start_ammo; const short clip_ammo; const short maxammo; const short maxdamage; const short repeatdelay; // In game cycles, at least 1 const short persistence; const unsigned char instant_hit; const unsigned char splashdamage; const short max_tiles; //Max distance, in tiles, the ammo travels const unsigned char projectile_speed; //Distance in one cycle (if applicable) const short ammosprite; const short nr_sprites; short hud_x; //Size in pixels short hud_y; //Size in pixels unsigned char* lightdata[2]; unsigned char* darkdata[2]; unsigned char* maskdata[2]; } Weapon; typedef struct //WeaponInstance { short ammo; short curdelay; short cur_persistence; Weapon *cur; } WeaponInstance; typedef struct //ProjectileStruct { short inuse; FATSPRITE spr; char player_shot; //TRUE or FALSE unsigned char splashdamage; long x; long y; short maxdamage; short speed; short orientation; short distance; short maxdistance; } ProjectileStruct; typedef struct //SpriteStruct { char type; //From level data short life; char pickup; //TRUE or FALSE char becomesHealth; char moving; char active; char speed; unsigned short drawmode; short orientation; TEXCONFIG *src; unsigned char animated; //just TRUE or FALSE unsigned char lastframe; //starts at 0, not 1 unsigned char pos; unsigned char first_idx; unsigned char firesprite; unsigned char deathsprite; unsigned char deathsize; unsigned char delaycycles; unsigned char nr_textures; unsigned char noexplode; unsigned char cycles; const unsigned char *pattern; unsigned char passthrough; unsigned char desire; char curwait; char curinc; char tile; WeaponInstance weapon; } SpriteStruct; typedef struct //DoorInfo { unsigned char x; unsigned char y; } DoorInfo; typedef struct //ButtonInfo { unsigned char x; //Highest bit set if it's a keycard thing unsigned char y; unsigned char doorx; unsigned char doory; } ButtonInfo; typedef struct //Button { unsigned char status; char basetile; char beforetile; char aftertile; unsigned char shootonly; unsigned char isKeycard; } Button; typedef struct //Player { short life; short armor; } Player; typedef struct //LSbeginning { Player player; short current_level; char WeaponsValid[WEAPON_COUNT]; short ammo[WEAPON_COUNT]; short cur_weapon; } LSbeginning; typedef struct //LSmid { Player player; char WeaponsValid[WEAPON_COUNT]; short ammo[WEAPON_COUNT]; short cur_weapon; PartialDoor doors[MAX_NR_DOORS]; Button buttons[MAX_BUTTONS]; ButtonInfo button_data[MAX_BUTTONS]; FATSPRITE sprites[MAX_SPRITES]; SpriteStruct sprites_extra[MAX_SPRITES]; char map[64*64]; unsigned char lights; char invert; short playerHasKeycard; short cur_orientation; short vehicle_speed; short projectile_count; short panel_count,monitor_count; char floormode, floormode2; char ceilmode, ceilmode2; short sprite_count; short current_level; char levelstyle; char canExit; short difficulty; //char oldtilex,oldtiley; short oldBossHealth; unsigned char automove; unsigned char autoturn; unsigned char autokeys; char old_tile; short cam_xpos; short cam_ypos; short cam_orientation; ProjectileStruct projectiles[MAX_PROJECTILES]; short doortimers[MAX_DOORS]; } LSmid; typedef struct //LSdata { LSbeginning beginning; LSmid mid; } LSdata; typedef struct //EnemyStruct { FATSPRITE *spr; short rocket_idx; //Total number of current rockets short desire; } EnemyStruct; typedef struct //star_type (Starfield) { short x,y,z; } star_type; typedef struct //RowKey { short row; short key; } RowKey; typedef struct //Config { //fire, strafe, pressbutton, switchweapon, // speedup, pause, boss, save, load; RowKey keys[9]; short intro; } Config; typedef struct { FATSPRITE *sprites; BYTE *plane1,*plane2; Config cfg; unsigned long* textplane; char chgbutton_flag; char shoot_flag; char switchweapon_flag; char strafe_flag; char speedup_flag; char oldWeaponIsFiring; char oldChgbutton_flag; unsigned char weapon_count; unsigned char cur_weapon; unsigned char cached_button; char contrastcur; char old_level; Player player; Player oldPlayer; short oldAmmo; DoorInfo *door_data; ButtonInfo *button_data; short *doortimers; short buttoncount; short doorcount; #ifdef COMPRESSED_TEXTURES char unpackedtex[MAX_TEXTURES]; BYTE *texspace; BYTE *texptrs[TOTAL_TEXCONFIGS_IN_oblvgfx1]; #endif BYTE *texptr; BYTE *gfx0,*text; //BYTE *dest3; short total_animated_walls; short HW2; Button *button; BYTE *BGlight,*BGdark; short hitwall,oldhitwall; FATDOOR *olddoor; short *HUDlight; short *HUDdark; short *HUDmask; unsigned char* bg_img[BGMAX]; unsigned short *light_data[MAX_UNIQUE_BUTTONS]; unsigned short *dark_data[MAX_UNIQUE_BUTTONS]; unsigned short *light_data2[MAX_UNIQUE_BUTTONS]; unsigned short *dark_data2[MAX_UNIQUE_BUTTONS]; //unsigned short *black; short marquee_time; short bg_cycle; ProjectileStruct *projectiles; //ProjectileStruct projectiles[MAX_PROJECTILES]; TEXCONFIG *sprites_s,*projectilemodels,*enemysprites; TEXCONFIG *textures; //FATSPRITE sprites[MAX_SPRITES+MAX_PROJECTILES]; SpriteStruct *sprites_extra; //SpriteStruct sprites_extra[MAX_SPRITES]; char *marquee,*textbuf,marquee_cur[20]; unsigned char* weapmodel; short oldlen; ///////////////////////////// //Also needed in load_data... unsigned char lights; char invert; char playerHasKeycard; char oldPlayerHasKeycard; short cur_orientation; short vehicle_speed; short projectile_count; short panel_count,monitor_count; char floormode, floormode2; char ceilmode, ceilmode2; short sprite_count; short current_level; char levelstyle; char canExit; short difficulty; //char oldtilex,oldtiley; short oldBossHealth; unsigned char automove; unsigned char autoturn; unsigned char autokeys; char old_tile; ///////////////////////////// short quitting; LSdata *load_data; char *ext_level_data; //Following 4 must stay together! char loadbeginning __attribute__ ((aligned)); char loadmid; char midSaveIsLoaded; char beginningSaveIsLoaded; ///////////////////////////////// char *glcd; HANDLE texfile0,texfile,texfile2,texfile3,texfile4,textfile; short turning; star_type* stars; short zoffset; } GameGlobals; /**************************************************************************** * VARIABLE DECLARATIONS * ****************************************************************************/ /*register */GameGlobals *gg /*asm("a4")*/; /*register */FATCONFIG *fc /*asm("a3")*/; short lev; /*char chgbutton_flag; char shoot_flag; char switchweapon_flag; char strafe_flag; char speedup_flag; char levelstyle; char oldWeaponIsFiring; char oldChgbutton_flag; char canExit;*/ const char *const OblivionErrorStrings[OBLIVION_ERROR_COUNT] = { "Out of Memory", "GFX File or Out of Memory", "Incorrect size for data file!", "Map is missing needed tiles!", "Map file error!" }; const char *const FatErrorStrings[] = { "Unknown FAT Error", "Game not ExePacked", "Send this FATLIB version", "Locking FATengine failed", "FAT: Out of Memory" }; const unsigned char walkingAnimation[]={0,1,2,1, 3}; const char * const cfgname = "oblivcfg"; const char * const savename = "oblvsave"; const char * const mapname = "oblivmap"; const char * const textname = "oblvtext"; const char suffix[7] = {0,'o','b','l','v',0,OTH_TAG}; const char * const SEE_README_STRING1 = "Fatal Error. Press key."; const char * const SEE_README_STRING2 = "See the Readme for more info."; /*const char * const choices[MENUCHOICES]= {"Play Game!","Reset Progress","Story","Options","Quit"}; const char * const options[OPTIONS]= {"Intro ","Config Keys","-Go Back-"}; const char * const difficulties[DIFFICULTIES]= {"Normal","Harder","Insane","-Go Back-"};*/ /**************************************************************************** * MACROS * ****************************************************************************/ #define SaveCoords() {oldx = lfc.cam_xpos;oldy=lfc.cam_ypos;} #define CoordsChanged (!(oldx == lfc.cam_xpos && oldy==lfc.cam_ypos)) #define iRound(x,a) (((x)+(1<<((a)-1)))>>(a)) #define iRoundEqual(x1,x2,a) ( (abs(x1-x2)) < (1<<(a-1)) ) //#define distSquared(x,y) ((long)x*x + (long)y*y) #define dist(x,y) ({typeof(x) __x = (x); typeof(y) __y = (y);\ FAT_FastSqrt((long)__x*__x + (long)__y*__y);}) //#define shrtDist(x,y) ((short)FAT_FastSqrt((long)a*a + (long)b*b)) #define E2Q(a) (-a-1) #define BlackGrayScreen() \ {memset(gg->plane1,0xFF,3840);memset(gg->plane2,0xFF,3840);} #define BlackGrayScreen2B(a,b) \ {memset(a,0xFF,3840);memset(b,0xFF,3840);} #define DrawGrayStr1B(x,y,s,attr,plane) \ {PortSet(plane,239,127);DrawStr(x,y,s,attr);} #define OblivionShowError(a) {DrawStr(1,51,OblivionErrorStrings[a],A_NORMAL);} #define ShowFatLoadError(a) {DrawStr(1,51,FatErrorStrings[a],A_NORMAL);} #define KeyCheck(k) (_keytest(gg->cfg.keys[k].row,gg->cfg.keys[k].key)) #define SWAP(a,b) {s=a;a=b;b=s;} #ifdef COMPRESSED_TEXTURES #define ResetTexSpace() {memset(gg->unpackedtex,0,MAX_TEXTURES);} #endif #define getNrLines(ptr,set)\ (*(unsigned short*)(ptr+oblvtext_count*sizeof(short) + (*((unsigned short*)ptr+set)))) /**************************************************************************** * SPECIAL MEMORY HANDLING ROUTINES * ****************************************************************************/ #ifdef DEBUG unsigned long alloc_mem; void free_special (void *ptr) { alloc_mem -= HeapSize(*((unsigned short*)ptr-1)); free(ptr); } void *malloc_special (unsigned long size) { alloc_mem += size; return malloc(size); } #else /*#define free_special free #define malloc_special malloc*/ void free_special (void *ptr) { free(ptr); } void *malloc_special (unsigned long size) { return malloc(size); } #endif