12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658 |
- /* Catacomb Armageddon Source Code
- * Copyright (C) 1993-2014 Flat Rock Software
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
- // C3_GAME.C
- #include <stdlib.h>
- #include "DEF.H"
- #include "gelib.h"
- #pragma hdrstop
- #ifdef PROFILE
- #include "TIME.H"
- #endif
- /*
- =============================================================================
- LOCAL CONSTANTS
- =============================================================================
- */
- #define NUMLUMPS 61
- #define SUCCUBUSLUMP 0
- #define FATDEMONLUMP 1
- #define BOLTLUMP 2
- #define NUKELUMP 3
- #define POTIONLUMP 4
- #define RKEYLUMP 5
- #define YKEYLUMP 6
- #define GKEYLUMP 7
- #define BKEYLUMP 8
- //#define SCROLLLUMP 9
- #define CHESTLUMP 10
- #define PLAYERLUMP 11
- #define WALL1LUMP 12
- #define WALL2LUMP 13
- #define BDOORLUMP 14
- #define GODESSLUMP 15
- #define MAGELUMP 16
- #define BATLUMP 17
- #define GRELLUMP 18
- #define TOMBSTONESLUMP 19
- #define ZOMBIELUMP 20
- #define ANTLUMP 21
- #define SKELETONLUMP 22
- #define RGEMLUMP 23
- #define GGEMLUMP 24
- #define BGEMLUMP 25
- #define YGEMLUMP 26
- #define PGEMLUMP 27
- //#define RKEY2LUMP 28
- #define DRAGONLUMP 29
- #define OBJ_WARPLUMP 30
- #define EYELUMP 31
- #define REDDEMONLUMP 32
- //#define PITLUMP 33
- #define FTIMELUMP 34
- #define WATERCHESTLUMP 35
- #define TREELUMP 36
- #define ARCH1LUMP 37
- #define BUNNYLUMP 38
- #define ANTHILLLUMP 39
- #define COLUMNLUMP 40
- #define SULPHURGASLUMP 41
- #define FIREPOTLUMP 42
- //#define WHIRLPOOLLUMP 43
- #define FOUNTAINLUMP 44
- #define FORCEFIELDLUMP 45
- #define ARCH2LUMP 46
- #define ARCH3LUMP 47
- #define ARCH4LUMP 48
- #define ARCH5LUMP 49
- #define ARCH6LUMP 50
- #define SKELHANGLUMP 51
- //#define SKELPILELUMP 52
- #define ARCH7LUMP 53
- #define ARCH8LUMP 54
- #define ARCH9LUMP 55
- #define ARCH10LUMP 56
- #define ARCH11LUMP 57
- #define ARCH12LUMP 58
- #define ARCH13LUMP 59
- int lumpstart[NUMLUMPS] = {
- SUCCUBUS_LUMP_START,
- FATDEMON_LUMP_START,
- BOLT_LUMP_START,
- NUKE_LUMP_START,
- POTION_LUMP_START,
- RKEY_LUMP_START,
- YKEY_LUMP_START,
- GKEY_LUMP_START,
- BKEY_LUMP_START,
- 0,
- //SCROLL_LUMP_START,
- CHEST_LUMP_START,
- PLAYER_LUMP_START,
- //WALL1_LUMP_START,
- //WALL2_LUMP_START,
- //BDOOR_LUMP_START,
- 0,0,0,
- GODESS_LUMP_START,
- MAGE_LUMP_START,
- BAT_LUMP_START,
- GREL_LUMP_START,
- TOMBSTONES_LUMP_START,
- ZOMBIE_LUMP_START,
- ANT_LUMP_START,
- SKELDUDE_LUMP_START,
- RGEM_LUMP_START,
- GGEM_LUMP_START,
- BGEM_LUMP_START,
- YGEM_LUMP_START,
- PGEM_LUMP_START,
- 0, //RKEY2_LUMP_START,
- DRAGON_LUMP_START,
- OBJ_WARP_LUMP_START,
- EYE_LUMP_START,
- REDDEMON_LUMP_START,
- 0, //PIT_LUMP_START,
- TIME_LUMP_START,
- O_WATER_CHEST_LUMP_START,
- TREE_LUMP_START,
- ARCH1_LUMP_START,
- BUNNY_LUMP_START,
- ANTHILL_LUMP_START,
- COLUMN_LUMP_START,
- SULPHURGAS_LUMP_START,
- FIREPOT_LUMP_START,
- 0, //WHIRLPOOL_LUMP_START,
- FOUNTAIN_LUMP_START,
- FORCEFIELD_LUMP_START,
- ARCH2_LUMP_START,
- ARCH3_LUMP_START,
- ARCH4_LUMP_START,
- ARCH5_LUMP_START,
- ARCH6_LUMP_START,
- SKELHANG_LUMP_START,
- 0, //SKELPILE_LUMP_START,
- ARCH7_LUMP_START,
- ARCH8_LUMP_START,
- ARCH9_LUMP_START,
- ARCH10_LUMP_START,
- ARCH11_LUMP_START,
- ARCH12_LUMP_START,
- ARCH13_LUMP_START,
- };
- int lumpend[NUMLUMPS] = {
- SUCCUBUS_LUMP_END,
- FATDEMON_LUMP_END,
- BOLT_LUMP_END,
- NUKE_LUMP_END,
- POTION_LUMP_END,
- RKEY_LUMP_END,
- YKEY_LUMP_END,
- GKEY_LUMP_END,
- BKEY_LUMP_END,
- 0,
- //SCROLL_LUMP_END,
- CHEST_LUMP_END,
- PLAYER_LUMP_END,
- 0,0,0,
- GODESS_LUMP_END,
- MAGE_LUMP_END,
- BAT_LUMP_END,
- GREL_LUMP_END,
- TOMBSTONES_LUMP_END,
- ZOMBIE_LUMP_END,
- ANT_LUMP_END,
- SKELDUDE_LUMP_END,
- RGEM_LUMP_END,
- GGEM_LUMP_END,
- BGEM_LUMP_END,
- YGEM_LUMP_END,
- PGEM_LUMP_END,
- 0, //RKEY2_LUMP_END,
- DRAGON_LUMP_END,
- OBJ_WARP_LUMP_END,
- EYE_LUMP_END,
- REDDEMON_LUMP_END,
- 0, //PIT_LUMP_END,
- TIME_LUMP_END,
- O_WATER_CHEST_LUMP_END,
- TREE_LUMP_END,
- ARCH1_LUMP_END,
- BUNNY_LUMP_END,
- ANTHILL_LUMP_END,
- COLUMN_LUMP_END,
- SULPHURGAS_LUMP_END,
- FIREPOT_LUMP_END,
- 0, //WHIRLPOOL_LUMP_END,
- FOUNTAIN_LUMP_END,
- FORCEFIELD_LUMP_END,
- ARCH2_LUMP_END,
- ARCH3_LUMP_END,
- ARCH4_LUMP_END,
- ARCH5_LUMP_END,
- ARCH6_LUMP_END,
- SKELHANG_LUMP_END,
- 0, //SKELPILE_LUMP_END,
- ARCH7_LUMP_END,
- ARCH8_LUMP_END,
- ARCH9_LUMP_END,
- ARCH10_LUMP_END,
- ARCH11_LUMP_END,
- ARCH12_LUMP_END,
- ARCH13_LUMP_END,
- };
- //extern unsigned scolor,gcolor;
- /*
- =============================================================================
- GLOBAL VARIABLES
- =============================================================================
- */
- unsigned latchpics[NUMLATCHPICS];
- unsigned tileoffsets[NUMTILE16];
- unsigned textstarts[27];
- boolean splitscreen=false;
- /*
- =============================================================================
- LOCAL VARIABLES
- =============================================================================
- */
- boolean lumpneeded[NUMLUMPS];
- //===========================================================================
- //==========================================================================
- //
- //
- // LOCAL PROTOTYPES
- //
- //
- //==========================================================================
- void CashPoints(void);
- /*
- ==========================
- =
- = ScanInfoPlane
- =
- = Spawn all actors and mark down special places
- =
- ==========================
- */
- void ScanInfoPlane (void)
- {
- unsigned char hibyte;
- unsigned x,y,i,j;
- unsigned int tile;
- unsigned far *start;
- InitObjList(); // start spawning things with a clean slate
- scolor = gcolor = 0;
- skycolor = &scolor;
- groundcolor = &gcolor;
- memset (lumpneeded,0,sizeof(lumpneeded));
- start = mapsegs[2];
- for (y=0;y<mapheight;y++)
- for (x=0;x<mapwidth;x++)
- {
- tile = *start++;
- hibyte = tile >> 8;
- tile &= 0xff;
- switch (hibyte)
- {
- char hi;
- case 0xFB:
- wall_anim_time = tile;
- tile = 0;
- break;
- case 0xfa: // sky/ground color
- case 0xf9: // sky/ground 'strip'
- x++;
- tile = *start++;
- hi = tile >> 8;
- tile &= 0xff;
- switch (hibyte)
- {
- case 0xfa: // sky / ground color
- scolor = ((hi)|(hi<<8));
- gcolor = ((tile)|(tile<<8));
- skycolor = &scolor;
- groundcolor = &gcolor;
- break;
- case 0xf9: // sky / ground 'strip'
- break;
- }
- break;
- }
- if ((!tile) || (hibyte))
- continue;
- switch (tile)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- lumpneeded[PLAYERLUMP] = true;
- SpawnPlayer(x,y,NORTH+tile-1);
- break;
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- lumpneeded[tile-5+BOLTLUMP] = true;
- SpawnBonus(x,y,tile-5);
- break;
- #if 0
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- case 19:
- lumpneeded[SCROLLLUMP] = true;
- SpawnBonus(x,y,B_SCROLL1+tile-12);
- break;
- #endif
- case 20:
- lumpneeded[REDDEMONLUMP] = true;
- SpawnRedDemon (x,y);
- break;
- #if 0
- case 20: // goal
- lumpneeded[GOALLUMP] = true;
- SpawnBonus(x,y,B_GOAL);
- break;
- #endif
- case 21:
- lumpneeded[GODESSLUMP] = true;
- SpawnGodess (x,y);
- break;
- case 22:
- lumpneeded[FATDEMONLUMP] = true;
- SpawnFatDemon (x,y);
- break;
- case 23:
- lumpneeded[SUCCUBUSLUMP] = true;
- SpawnSuccubus (x,y);
- break;
- case 24:
- lumpneeded[DRAGONLUMP] = true;
- SpawnDragon(x,y);
- break;
- case 25:
- lumpneeded[BATLUMP] = true;
- SpawnBat (x,y);
- break;
- case 26:
- lumpneeded[EYELUMP] = true;
- SpawnEye(x,y);
- break;
- case 27:
- lumpneeded[MAGELUMP] = true;
- SpawnMage (x,y);
- break;
- case 28:
- lumpneeded[RKEYLUMP] = lumpneeded[GRELLUMP] = true;
- SpawnGrelminar (x,y);
- break;
- case 30:
- lumpneeded[ANTLUMP] = true;
- SpawnAnt(x,y);
- break;
- case 31:
- case 32:
- case 33:
- case 34:
- case 35:
- lumpneeded[OBJ_WARPLUMP] = true;
- SpawnWarp (x,y,tile-30);
- break;
- case 36:
- lumpneeded[ZOMBIELUMP] = true;
- SpawnZombie(x,y);
- break;
- case 37:
- lumpneeded[SKELETONLUMP] = true;
- SpawnSkeleton(x,y);
- break;
- case 38:
- lumpneeded[SKELETONLUMP] = true;
- SpawnWallSkeleton(x,y);
- break;
- case 39:
- lumpneeded[FTIMELUMP] = true;
- SpawnFTime(x,y);
- break;
- case 40:
- case 41:
- case 42:
- case 43:
- case 44:
- lumpneeded[tile-40+RGEMLUMP] = true;
- SpawnBonus(x,y,tile-40+B_RGEM);
- break;
- case 45:
- case 46:
- case 47:
- lumpneeded[TOMBSTONESLUMP] = true;
- SpawnTombstone(x,y,tile-45);
- break;
- #if 0
- case 48:
- lumpneeded[PITLUMP] = true;
- SpawnWarp(x,y,0);
- break;
- #endif
- case 49: // chest
- if (gcolor == 0x0101)
- lumpneeded[WATERCHESTLUMP] = true;
- else
- lumpneeded[CHESTLUMP] = true;
- SpawnBonus(x,y,B_CHEST);
- break;
- case 50:
- lumpneeded[TREELUMP] = true;
- SpawnTree(x,y);
- break;
- case 51:
- lumpneeded[BUNNYLUMP] = true;
- SpawnBunny(x,y);
- break;
- case 52:
- lumpneeded[ARCH1LUMP] = true;
- SpawnArch(x,y,1);
- break;
- case 53:
- lumpneeded[ANTHILLLUMP] = true;
- SpawnWarp(x,y,0);
- break;
- case 54:
- lumpneeded[COLUMNLUMP] = true;
- SpawnMiscObjects(x,y,1); //1=column,2=sulphur hole,3=fire pot,4=fountain
- break;
- case 55:
- lumpneeded[SULPHURGASLUMP] = true;
- SpawnMiscObjects(x,y,2);
- break;
- case 56:
- lumpneeded[FIREPOTLUMP] = true;
- SpawnMiscObjects(x,y,3);
- break;
- case 57:
- lumpneeded[ARCH13LUMP] = true;
- SpawnArch(x,y,13);
- break;
- case 58:
- lumpneeded[FOUNTAINLUMP] = true;
- SpawnMiscObjects(x,y,4);
- break;
- case 59:
- lumpneeded[FORCEFIELDLUMP] = true;
- SpawnForceField(x,y);
- break;
- case 60:
- lumpneeded[ARCH2LUMP] = true;
- SpawnArch(x,y,2);
- break;
- case 61:
- lumpneeded[ARCH3LUMP] = true;
- SpawnArch(x,y,3);
- break;
- case 62:
- lumpneeded[ARCH4LUMP] = true;
- SpawnArch(x,y,4);
- break;
- case 63:
- lumpneeded[ARCH5LUMP] = true;
- SpawnArch(x,y,5);
- break;
- case 64:
- lumpneeded[ARCH6LUMP] = true;
- SpawnArch(x,y,6);
- break;
- case 65:
- lumpneeded[SKELHANGLUMP] = true;
- lumpneeded[SKELETONLUMP] = true;
- SpawnSkeletonHanging(x,y);
- break;
- case 66:
- lumpneeded[ARCH12LUMP] = true;
- SpawnArch(x,y,12);
- break;
- case 67:
- lumpneeded[ARCH7LUMP] = true;
- SpawnArch(x,y,7);
- break;
- case 68:
- lumpneeded[ARCH8LUMP] = true;
- SpawnArch(x,y,8);
- break;
- case 69:
- lumpneeded[ARCH9LUMP] = true;
- SpawnArch(x,y,9);
- break;
- case 70:
- lumpneeded[ARCH10LUMP] = true;
- SpawnArch(x,y,10);
- break;
- case 71:
- lumpneeded[ARCH11LUMP] = true;
- SpawnArch(x,y,11);
- break;
- }
- }
- }
- //==========================================================================
- /*
- ==================
- =
- = ScanText
- =
- ==================
- */
- void ScanText (void)
- {
- int i;
- char far *text;
- text = (char _seg *)grsegs[LEVEL1TEXT+mapon];
- textstarts[0] = 0;
- for (i=1;i<=26;i++)
- {
- while (*text != '\n')
- {
- if (*text == '\r')
- *text = 0;
- text++;
- }
- text++;
- textstarts[i] = FP_OFF(text);
- }
- }
- //==========================================================================
- /*
- ==================
- =
- = DrawEnterScreen
- =
- ==================
- */
- #if 0
- static char *levelnames[] =
- {
- "Programmers Test Map",
- "The Garden of Tears",
- "The Den of Zombies",
- "The Mausoleum Grounds",
- "The Main Floor of the Mausoleum",
- "Mike's Blastable Passage",
- "The Crypt of Nemesis the Undead",
- "The Subterranean Vault",
- "The Ancient Aqueduct",
- "The Orc Mines",
- "The Lair of the Troll",
- "The Demon's Inferno",
- "The Battleground of the Titans",
- "The Coven of Mages",
- "The Inner Sanctum",
- "The Haunt of Nemesis",
- "The Passage to the Surface",
- "Big Jim's Domain",
- "Nolan",
- "19",
- "20",
- "21",
- "22",
- "23",
- "24",
- "25",
- "26",
- "27",
- "28",
- "29",
- "30",
- "31",
- "32",
- "33",
- "34",
- "35",
- "36",
- "37",
- "38",
- "39",
- };
- #endif
- void DrawEnterScreen (void)
- {
- int width;
- bufferofs = displayofs = screenloc[screenpage];
- VW_Bar(0,0,VIEWWIDTH,VIEWHEIGHT,0);
- // width = strlen(levelnames[gamestate.mapon]);
- width = strlen("You enter a new area ...");
- if (width < 20)
- width = 20;
- CenterWindow(width,3);
- US_CPrint("\nYou enter a new area ...\n");
- // US_CPrint(levelnames[gamestate.mapon]);
- }
- //==========================================================================
- boolean tileneeded[NUMFLOORS];
- /*
- ==================
- =
- = CacheScaleds
- =
- ==================
- */
- void CacheScaleds (void)
- {
- int i,j;
- unsigned source,dest;
- FreeUpMemory ();
- CA_CacheGrChunk(LEVEL1TEXT+mapon);
- ScanText ();
- //
- // make sure we are displaying screenpage 0
- //
- if (screenpage)
- {
- source = screenloc[screenpage];
- dest = screenloc[0];
- VW_ScreenToScreen (source,dest,40,VIEWHEIGHT);
- screenpage = 0;
- VW_SetScreen (dest,0);
- displayofs = dest;
- }
- //
- // cache wall pictures
- //
- for (i=1;i<NUMFLOORS;i++)
- if (tileneeded[i])
- {
- SetupScaleWall (walllight1[i]);
- SetupScaleWall (walldark1[i]);
- }
- //
- // cache the actor pictures
- //
- for (i=0;i<NUMLUMPS;i++)
- if (lumpneeded[i])
- for (j=lumpstart[i];j<=lumpend[i];j++)
- SetupScalePic(j);
- source = screenloc[0];
- for (i=1;i<=2;i++)
- {
- dest = screenloc[i];
- VW_ScreenToScreen (source,dest,40,VIEWHEIGHT);
- }
- screenpage = 1;
- }
- //==========================================================================
- /*
- ==================
- =
- = SetupGameLevel
- =
- ==================
- */
- void SetupGameLevel ()
- {
- int x,y,i,loop;
- unsigned far *map,tile,far *spotptr,spot;
- unsigned search_tile;
- boolean exploding_walls_present = false;
- memset (tileneeded,0,sizeof(tileneeded));
- //
- // randomize if not a demo
- //
- #if 0
- if (DemoMode)
- {
- US_InitRndT(false);
- gamestate.difficulty = gd_Normal;
- }
- else
- #endif
- US_InitRndT(true);
- //
- // load the level
- //
- CA_CacheMap (gamestate.mapon);
- mapwidth = mapheaderseg[mapon]->width;
- mapheight = mapheaderseg[mapon]->height;
- //
- // make a lookup table for the maps left edge
- //
- spot = 0;
- for (y=0;y<mapheight;y++)
- {
- farmapylookup[y] = spot;
- spot += mapwidth;
- }
- //
- // copy the wall data to a data segment array
- //
- memset (tilemap,0,sizeof(tilemap));
- memset (actorat,0,sizeof(actorat));
- map = mapsegs[0];
- spotptr = mapsegs[2];
- for (y=0;y<mapheight;y++)
- for (x=0;x<mapwidth;x++)
- {
- tile = *map++;
- if (((*spotptr)>>8) == EXP_WALL_CODE)
- {
- exploding_walls_present = true;
- }
- if (tile<NUMFLOORS)
- {
- #if 0
- if (tile == WALL_SKELETON_CODE)
- {
- tileneeded[tile+1] = tileneeded[tile+2] = true;
- tilemap[x][y] = tile;
- }
- #endif
- if ((tile == 66) || (tile == 67) || (tile == 68) || (tile == 69))
- {
- if ((tile == 66) || (tile == 67))
- tileneeded[tile+2] = true;
- tileneeded[21] = tileneeded[tile] = true;
- tilemap[x][y] = tile;
- }
- else
- if (tile != INVISIBLEWALL)
- {
- tileneeded[tile] = true;
- tilemap[x][y] = tile;
- if (ANIM_FLAGS(tile))
- {
- search_tile = tile+(char signed)ANIM_FLAGS(tile);
- if (!tileneeded[search_tile])
- while (search_tile != tile)
- {
- tileneeded[search_tile] = true;
- if (ANIM_FLAGS(search_tile))
- search_tile += (char signed)ANIM_FLAGS(search_tile);
- else
- TrashProg("Unending Tile Animation!");
- }
- }
- }
- if (tile>0)
- (unsigned)actorat[x][y] = tile;
- }
- spotptr++;
- }
- //
- // Mark any gfx chunks needed
- //
- // CA_MarkGrChunk(NORTHICONSPR);
- // CA_CacheMarks(NULL);
- //
- // decide which graphics are needed and spawn actors
- //
- zombie_base_delay = 0; // (1*60) + random(1*60);
- ScanInfoPlane ();
- _fmemset(wall_anim_pos,0,sizeof(wall_anim_pos));
- //
- // mark which exploding walls are needed ---- the check for floor color
- // is preformed in ScanInfoPlane.
- //
- if (exploding_walls_present)
- {
- extern unsigned gnd_colors[];
- if (gcolor == 0x0101)
- tileneeded[WATEREXP] = tileneeded[WATEREXP+1] = tileneeded[WATEREXP+2] = true;
- else
- tileneeded[WALLEXP] = tileneeded[WALLEXP+1] = tileneeded[WALLEXP+2] = true;
- }
- //
- // have the caching manager load and purge stuff to make sure all marks
- // are in memory
- //
- CA_LoadAllSounds ();
- }
- //==========================================================================
- /*
- =====================
- =
- = LatchDrawPic
- =
- =====================
- */
- void LatchDrawPic (unsigned x, unsigned y, unsigned picnum)
- {
- unsigned height, source, dest;
- unsigned wide;
- wide = pictable[picnum-STARTPICS].width;
- height = pictable[picnum-STARTPICS].height;
- dest = bufferofs + ylookup[y]+x;
- source = latchpics[picnum-FIRSTLATCHPIC];
- EGAWRITEMODE(1);
- EGAMAPMASK(15);
- asm mov bx,[linewidth]
- asm sub bx,[wide]
- asm mov ax,[screenseg]
- asm mov es,ax
- asm mov ds,ax
- asm mov si,[source]
- asm mov di,[dest]
- asm mov dx,[height] // scan lines to draw
- asm mov ax,[wide]
- lineloop:
- asm mov cx,ax
- asm rep movsb
- asm add di,bx
- asm dec dx
- asm jnz lineloop
- asm mov ax,ss
- asm mov ds,ax // restore turbo's data segment
- EGAWRITEMODE(0);
- }
- #if USE_STRIPS
- //--------------------------------------------------------------------------
- // LatchDrawPicStrip() - srcoff is distance into source file (in PIXELS!)
- //--------------------------------------------------------------------------
- void LatchDrawPicStrip (unsigned x, unsigned y, unsigned picnum, unsigned srcoff)
- {
- unsigned wide, height, source, dest, shift, srcmod;
- shift = (srcoff & 7) >> 1;
- srcoff >>= 3;
- wide = pictable[picnum-STARTPICS].width;
- srcmod = wide - linewidth + (shift != 3);
- if (wide > linewidth)
- wide = linewidth;
- height = pictable[picnum-STARTPICS].height;
- dest = bufferofs + ylookup[y]+x;
- picnum = ((picnum - (FIRSTSTRIPPIC+1)) >> 2) + (shift);
- source = latchpics[(FIRSTSTRIPPIC-FIRSTLATCHPIC+1)+picnum];
- EGAWRITEMODE(1);
- EGAMAPMASK(15);
- asm mov bx,[linewidth]
- asm sub bx,[wide]
- asm mov ax,[screenseg]
- asm mov es,ax
- asm mov ds,ax
- asm mov si,[source]
- asm add si,[srcoff]
- asm mov di,[dest]
- asm mov dx,[height] // scan lines to draw
- asm mov ax,[wide]
- lineloop:
- asm mov cx,ax
- asm rep movsb
- asm add di,bx
- asm add si,[srcmod]
- asm dec dx
- asm jnz lineloop
- asm mov ax,ss
- asm mov ds,ax // restore turbo's data segment
- EGAWRITEMODE(0);
- }
- #endif
- //==========================================================================
- /*
- =====================
- =
- = Victory
- =
- =====================
- */
- void Victory (boolean playsounds)
- {
- struct Shape shape;
- if (playsounds)
- {
- SD_PlaySound (GETBOLTSND);
- SD_WaitSoundDone ();
- SD_PlaySound (GETNUKESND);
- SD_WaitSoundDone ();
- SD_PlaySound (GETPOTIONSND);
- SD_WaitSoundDone ();
- SD_PlaySound (GETKEYSND);
- SD_WaitSoundDone ();
- SD_PlaySound (GETSCROLLSND);
- SD_WaitSoundDone ();
- SD_PlaySound (GETPOINTSSND);
- }
- FreeUpMemory();
- if (!screenfaded)
- VW_FadeOut();
- NormalScreen ();
- screenpage = bufferofs = 0;
- CA_CacheGrChunk (FINALEPIC);
- UNMARKGRCHUNK(FINALEPIC);
- VW_DrawPic(0, 0, FINALEPIC);
- VW_FadeIn();
- }
- //==========================================================================
- #if 0
- /*
- ===================
- =
- = Died
- =
- ===================
- */
- void Died (void)
- {
- unsigned page1,page2;
- //
- // fizzle fade screen to grey
- //
- FreeUpMemory ();
- SD_PlaySound (GAMEOVERSND);
- bufferofs = screenloc[(screenpage+1)%3];
- DisplayMsg("Though fallen, your Spirit ...",NULL);
- // LatchDrawPic(0,0,DEADPIC);
- // FizzleFade(bufferofs,displayofs,VIEWWIDTH,VIEWHEIGHT,false);
- IN_ClearKeysDown();
- while (!Keyboard[sc_Enter]);
- // IN_Ack();
- VW_SetScreen (bufferofs,0);
- VW_ColorBorder(0);
- }
- #endif
- //==========================================================================
- /*
- ===================
- =
- = NormalScreen
- =
- ===================
- */
- void NormalScreen (void)
- {
- VW_SetSplitScreen (200);
- bufferofs = displayofs = SCREEN1START;
- VW_Bar(0,0,320,200,0);
- bufferofs = SCREEN2START;
- VW_Bar(0,0,320,200,0);
- VW_SetScreen (displayofs,0);
- splitscreen = false;
- }
- //==========================================================================
- /*
- ===================
- =
- = DrawPlayScreen
- =
- ===================
- */
- void DrawPlayScreen (void)
- {
- int i,j,p,m;
- screenpage = 0;
- bufferofs = 0;
- VW_Bar (0,0,320,STATUSLINES,0);
- for (i=0;i<3;i++)
- {
- bufferofs = screenloc[i];
- VW_Bar (0,0,320,VIEWHEIGHT,0);
- }
- splitscreen = true;
- VW_SetSplitScreen(120);
- VW_SetScreen(screenloc[0],0);
- CA_CacheGrChunk (STATUSPIC);
- bufferofs = 0;
- VW_DrawPic (0,0,STATUSPIC);
- grneeded[STATUSPIC] &= ~ca_levelbit;
- MM_SetPurge(&grsegs[STATUSPIC],3);
- RedrawStatusWindow ();
- bufferofs = displayofs = screenloc[0];
- }
- //==========================================================================
- /*
- ===================
- =
- = LoadLatchMem
- =
- ===================
- */
- unsigned latchmemavail;
- void LoadLatchMem (void)
- {
- static unsigned base_destoff=0;
- static int base_numpics=0;
- int i,j,p,m,numpics;
- byte far *src, far *dest;
- unsigned destoff;
- EGAWRITEMODE(0);
- //
- // draw some pics into latch memory
- //
- if (!base_numpics)
- {
- //
- // tile 8s
- //
- latchpics[0] = freelatch;
- src = (byte _seg *)grsegs[STARTTILE8];
- dest = MK_FP(0xa000,freelatch);
- for (i=0;i<NUMTILE8;i++)
- {
- for (p=0;p<4;p++)
- {
- m = 1<<p;
- asm mov dx,SC_INDEX
- asm mov al,SC_MAPMASK
- asm mov ah,[BYTE PTR m]
- asm out dx,ax
- for (j=0;j<8;j++)
- *(dest+j)=*src++;
- }
- dest+=8;
- }
- //
- // tile 16s
- //
- src = (byte _seg *)grsegs[STARTTILE16];
- for (i=0;i<NUMTILE16;i++)
- {
- CA_CacheGrChunk (STARTTILE16+i);
- src = (byte _seg *)grsegs[STARTTILE16+i];
- if (src)
- {
- tileoffsets[i] = FP_OFF(dest);
- for (p=0;p<4;p++)
- {
- m = 1<<p;
- asm mov dx,SC_INDEX
- asm mov al,SC_MAPMASK
- asm mov ah,[BYTE PTR m]
- asm out dx,ax
- for (j=0;j<32;j++)
- *(dest+j)=*src++;
- }
- dest+=32;
- MM_FreePtr (&grsegs[STARTTILE16+i]);
- UNMARKGRCHUNK(STARTTILE16+i);
- }
- else
- tileoffsets[i] = 0;
- }
- //
- // pics
- //
- numpics=1;
- destoff = FP_OFF(dest);
- for (i=FIRSTLATCHPIC+1;i<FIRSTGROUNDPIC;i++)
- {
- latchpics[numpics++] = destoff;
- CA_CacheGrChunk (i);
- j = pictable[i-STARTPICS].width * pictable[i-STARTPICS].height;
- VW_MemToScreen (grsegs[i],destoff,j,1);
- destoff+=j;
- MM_FreePtr (&grsegs[i]);
- UNMARKGRCHUNK(i);
- }
- base_numpics = numpics;
- base_destoff = destoff;
- }
- numpics = base_numpics;
- destoff = base_destoff;
- #if USE_STRIPS
- //
- // ground pics
- //
- numpics++;
- for (i=FIRSTGROUNDPIC+1;i<FIRSTSTRIPPIC;i++)
- {
- int shape = (*groundcolor & 0xf0) - 16;
- // Is current shape needed?
- //
- if (shape != (i-(FIRSTGROUNDPIC+1)))
- {
- numpics++;
- continue;
- }
- latchpics[numpics++] = destoff;
- CA_CacheGrChunk (i);
- j = pictable[i-STARTPICS].width * pictable[i-STARTPICS].height;
- VW_MemToScreen (grsegs[i],destoff,j,1);
- destoff+=j;
- MM_FreePtr (&grsegs[i]);
- UNMARKGRCHUNK(i);
- }
- //
- // 'parallax' strips - used in place of a sky color
- //
- // Under current setup, each strip takes about 7k in latch memory.
- // To create 2 pixel scrolling, 4 strips are needed, that's 28k of
- // latch memory needed to produce this effect.
- //
- numpics++;
- for (i=FIRSTSTRIPPIC+1;i<FIRSTSCALEPIC;i++)
- {
- memptr work;
- unsigned workdest,stripsize,planesize;
- short loop,pic=i-STARTPICS;
- int shape = (*skycolor & 0xf0) - 16;
- // Is current shape needed?
- //
- if (shape != (i-(FIRSTSTRIPPIC+1)))
- {
- numpics++;
- continue;
- }
- // CAL_ShiftSprite() works with the SRC and DST in the same
- // segment. So we must allocate memory for two strips, and
- // move the base strip into that segment. Then we can use the
- // 2nd half of that memory for each shifted strip.
- //
- CA_CacheGrChunk (i);
- planesize = (pictable[pic].width+1) * pictable[pic].height;
- stripsize = planesize * 4;
- // MM_GetPtr(&work,(stripsize*2)+0000);
- MM_GetPtr(&work,65536);
- movedata((unsigned)grsegs[i],0,(unsigned)work,0,stripsize);
- workdest = 32768; //(stripsize+15) & 0xFFF0;
- // Free base strip
- //
- MM_FreePtr (&grsegs[i]);
- UNMARKGRCHUNK(i);
- // Create three shifted strips and move 'em to latch!
- //
- for (loop=3; loop; loop--)
- {
- // Produce current shift for this strip
- //
- latchpics[numpics++] = destoff;
- CAL_ShiftSprite ((unsigned)work,0,workdest,pictable[pic].width,
- pictable[pic].height,loop*2,false);
- // Copy this shift to latch memory
- //
- VW_MemToScreen ((memptr)((unsigned)work+(workdest>>4)),destoff,planesize,1);
- destoff+=planesize;
- }
- // Copy unshifted strip to latch
- //
- latchpics[numpics++] = destoff;
- planesize = pictable[pic].width * pictable[pic].height;
- VW_MemToScreen (work,destoff,planesize,1);
- destoff+=planesize;
- // Free work buffer
- //
- MM_FreePtr(&work);
- }
- #endif
- // Keep track of how much latch memory we have...
- //
- latchmemavail = 65535-destoff;
- EGAMAPMASK(15);
- }
- //==========================================================================
- /*
- ===================
- =
- = FizzleOut
- =
- ===================
- */
- void FizzleOut (int showlevel)
- {
- unsigned page1,page2;
- //
- // fizzle fade screen to grey
- //
- bufferofs = screenloc[(screenpage+1)%3];
- if (showlevel)
- DrawEnterScreen ();
- FizzleFade(bufferofs,displayofs,VIEWWIDTH,VIEWHEIGHT,false);
- }
- //==========================================================================
- /*
- ====================
- =
- = FreeUpMemory
- =
- ====================
- */
- void FreeUpMemory (void)
- {
- int i;
- for (i=0;i<NUMSCALEPICS;i++)
- if (shapedirectory[i])
- MM_SetPurge (&(memptr)shapedirectory[i],3);
- for (i=0;i<NUMSCALEWALLS;i++)
- if (walldirectory[i])
- MM_SetPurge (&(memptr)walldirectory[i],3);
- }
- //==========================================================================
- #if 0
- /*
- ==================
- =
- = DrawHighScores
- =
- ==================
- */
- void DrawHighScores(void)
- {
- char buffer[16],*str;
- word i,j,
- w,h,
- x,y;
- HighScore *s;
- CA_CacheGrChunk (HIGHSCORESPIC);
- VWB_DrawPic (0,0,HIGHSCORESPIC);
- MM_SetPurge (&grsegs[HIGHSCORESPIC],3);
- UNMARKGRCHUNK(HIGHSCORESPIC);
- for (i = 0,s = Scores;i < MaxScores;i++,s++)
- {
- PrintY = 68 + (16 * i);
- //
- // name
- //
- PrintX = 60;
- US_Print(s->name);
- //
- // level
- //
- ultoa(s->completed,buffer,10);
- for (str = buffer;*str;str++)
- *str = *str + (129 - '0'); // Used fixed-width numbers (129...)
- USL_MeasureString(buffer,&w,&h);
- PrintX = (25 * 8) - 8 - w;
- US_Print(buffer);
- //
- // score
- //
- ultoa(s->score,buffer,10);
- for (str = buffer;*str;str++)
- *str = *str + (129 - '0'); // Used fixed-width numbers (129...)
- USL_MeasureString(buffer,&w,&h);
- PrintX = (34 * 8) - 8 - w;
- US_Print(buffer);
- }
- fontcolor = F_BLACK;
- }
- /*
- =======================
- =
- = CheckHighScore
- =
- =======================
- */
- void CheckHighScore (long score,word other)
- {
- word i,j;
- int n;
- HighScore myscore;
- strcpy(myscore.name,"");
- myscore.score = score;
- myscore.completed = other;
- for (i = 0,n = -1;i < MaxScores;i++)
- {
- if
- (
- (myscore.score > Scores[i].score)
- || (
- (myscore.score == Scores[i].score)
- && (myscore.completed > Scores[i].completed)
- )
- )
- {
- for (j = MaxScores;--j > i;)
- Scores[j] = Scores[j - 1];
- Scores[i] = myscore;
- n = i;
- HighScoresDirty = true;
- break;
- }
- }
- if (n != -1)
- {
- //
- // got a high score
- //
- DrawHighScores ();
- PrintY = 68 + (16 * n);
- PrintX = 60;
- US_LineInput(PrintX,PrintY,Scores[n].name,nil,true,MaxHighName,100);
- }
- }
- #endif
- //==========================================================================
- /*
- ===================
- =
- = GameLoop
- =
- ===================
- */
- void GameLoop (void)
- {
- boolean wait = false;
- int i,xl,yl,xh,yh;
- char num[20];
- #ifdef PROFILE
- clock_t start,end;
- #endif
- DrawPlayScreen ();
- IN_ClearKeysDown();
- restart:
- if (!loadedgame)
- {
- gamestate.difficulty = restartgame;
- restartgame = gd_Continue;
- DrawEnterScreen ();
- if (gamestate.mapon != 8)
- fizzlein = true;
- wait = true;
- }
- do
- {
- playstate = gd_Continue;
- if (!loadedgame)
- SetupGameLevel ();
- else
- loadedgame = false;
- FreeUpMemory();
- LoadLatchMem();
- CacheScaleds ();
- if (EASYMODEON)
- DisplaySMsg("*** NOVICE ***", NULL);
- else
- DisplaySMsg("*** WARRIOR ***", NULL);
- status_delay = 250;
- RedrawStatusWindow();
- if (wait)
- {
- VW_WaitVBL(120);
- wait = false;
- }
- #ifdef PROFILE
- start = clock();
- while (start == clock());
- start++;
- #endif
- PlayLoop ();
- #ifdef PROFILE
- end = clock();
- itoa(end-start,str,10);
- Quit (str);
- #endif
- switch (playstate)
- {
- case ex_abort:
- FreeUpMemory ();
- return;
- case ex_resetgame:
- NewGame();
- case ex_loadedgame:
- case ex_warped:
- FreeUpMemory();
- if (playstate != ex_resetgame)
- DisplayMsg(" ", NULL);
- DisplaySMsg(" ", NULL);
- goto restart;
- case ex_victorious:
- screenpage = 0;
- bufferofs = 0;
- status_flag = 0;
- return;
- }
- } while (1);
- }
- #if 0
- //
- // make wall pictures purgable
- //
- for (i=0;i<NUMSCALEWALLS;i++)
- if (walldirectory[i])
- MM_SetPurge (&(memptr)walldirectory[i],3);
- //
- // cache wall pictures back in
- //
- for (i=1;i<NUMFLOORS;i++)
- if (tileneeded[i])
- {
- SetupScaleWall (walllight1[i]);
- SetupScaleWall (walllight2[i]);
- SetupScaleWall (walldark1[i]);
- SetupScaleWall (walldark2[i]);
- }
- #endif
|