CATACOMB.C 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. /* The Catacomb Source Code
  2. * Copyright (C) 1993-2014 Flat Rock Software
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #define CATALOG
  19. /*
  20. ** catacomb II -- the c translation...
  21. */
  22. #include "pcrlib.h"
  23. #include "NGRABCA2.H"
  24. #include "SOUNDS.H"
  25. #define NUMDEMOS 1
  26. #define maxpics 2047
  27. #define numtiles 24*24 /*number of tiles displayed on screen*/
  28. #define numlevels 30
  29. #define maxobj 200 /*maximum possible active objects*/
  30. #define solidwall 129
  31. #define blankfloor 128
  32. #define leftoff 11
  33. #define topoff 11
  34. #define tile2s 256 /*tile number where the 2*2 pictures start*/
  35. #define tile3s tile2s+67*4
  36. #define tile4s tile3s+35*9
  37. #define tile5s tile4s+19*16
  38. #define lasttile tile5s+19*25
  39. typedef enum {playercmd,gargcmd,dragoncmd,ramstraight,ramdiag,straight,idle,
  40. fade,explode,gunthinke,gunthinks} thinktype;
  41. typedef enum {benign,monster,pshot,mshot,nukeshot} tagtype;
  42. typedef enum {nothing,player,goblin,skeleton,ogre,gargoyle,dragon,turbogre,
  43. wallhit,shot,bigshot,rock,dead1,dead2,dead3,dead4,dead5,dead6,teleporter,
  44. torch,secretgate,gune,guns,lastclass} classtype;
  45. typedef enum {ingame,intitle,inscores} statetype;
  46. typedef struct {
  47. boolean active; /*if false, the object has not seen the player yet*/
  48. classtype class;
  49. byte x,y, /*location of upper left corner in world*/
  50. stage, /*animation frame being drawn*/
  51. delay; /*number of frames to pause without doing anything*/
  52. dirtype dir; /*direction facing*/
  53. char hp; /*hit points*/
  54. byte oldx,oldy; /*position where it was last drawn*/
  55. int oldtile; /*origin tile when last drawn*/
  56. char filler[1]; /*pad to 16 bytes*/
  57. } activeobj;
  58. typedef struct { /*holds a copy of activeobj, and its class info*/
  59. boolean active; /*if false, the object has not seen the player yet*/
  60. classtype class;
  61. byte x,y, /*location of upper left corner in world*/
  62. stage, /*animation frame being drawn*/
  63. delay; /*number of frames to pause without doing anything*/
  64. dirtype dir; /*direction facing*/
  65. char hp; /*hit points*/
  66. byte oldx,oldy; /*position where it was last drawn*/
  67. int oldtile; /*origin tile when last drawn*/
  68. char filler[1]; /*pad to 16 bytes*/
  69. byte think;
  70. byte contact;
  71. byte solid;
  72. word firstchar;
  73. byte size;
  74. byte stages;
  75. byte dirmask;
  76. word speed;
  77. byte hitpoints;
  78. byte damage;
  79. word points;
  80. char filler2[2]; /*pad to 32 bytes*/
  81. } objdesc;
  82. /*=================*/
  83. /* */
  84. /* typed constants */
  85. /* */
  86. /*=================*/
  87. char altmeters[14][14] = {
  88. {127,127,127,127,127,127,127,127,127,127,127,127,127},
  89. {23,127,127,127,127,127,127,127,127,127,127,127,127},
  90. {23,25,127,127,127,127,127,127,127,127,127,127,127},
  91. {23,24,25,127,127,127,127,127,127,127,127,127,127},
  92. {23,24,24,25,127,127,127,127,127,127,127,127,127},
  93. {23,24,24,24,25,127,127,127,127,127,127,127,127},
  94. {23,24,24,24,24,25,127,127,127,127,127,127,127},
  95. {23,24,24,24,24,24,25,127,127,127,127,127,127},
  96. {23,24,24,24,24,24,24,25,127,127,127,127,127},
  97. {23,24,24,24,24,24,24,24,25,127,127,127,127},
  98. {23,24,24,24,24,24,24,24,24,25,127,127,127},
  99. {23,24,24,24,24,24,24,24,24,24,25,127,127},
  100. {23,24,24,24,24,24,24,24,24,24,24,25,127},
  101. {23,24,24,24,24,24,24,24,24,24,24,24,25} };
  102. char meters[14][14] = {
  103. {127,127,127,127,127,127,127,127,127,127,127,127,127},
  104. {26,127,127,127,127,127,127,127,127,127,127,127,127},
  105. {26,28,127,127,127,127,127,127,127,127,127,127,127},
  106. {26,27,28,127,127,127,127,127,127,127,127,127,127},
  107. {26,27,27,28,127,127,127,127,127,127,127,127,127},
  108. {26,27,27,27,28,127,127,127,127,127,127,127,127},
  109. {26,27,27,27,27,28,127,127,127,127,127,127,127},
  110. {26,27,27,27,27,27,28,127,127,127,127,127,127},
  111. {26,27,27,27,27,27,27,28,127,127,127,127,127},
  112. {26,27,27,27,27,27,27,27,28,127,127,127,127},
  113. {26,27,27,27,27,27,27,27,27,28,127,127,127},
  114. {26,27,27,27,27,27,27,27,27,27,28,127,127},
  115. {26,27,27,27,27,27,27,27,27,27,27,28,127},
  116. {26,27,27,27,27,27,27,27,27,27,27,27,28} };
  117. dirtype opposite[9] =
  118. {south,west,north,east,southwest,northwest,northeast,southeast,nodir};
  119. /*==================*/
  120. /* */
  121. /* global variables */
  122. /* */
  123. /*==================*/
  124. enum {quited,killed,reseted,victorious} gamexit; /*determines what to do after playloop*/
  125. int oldtiles [numtiles]; /*tile displayed last refresh*/
  126. int background[87][86]; /*base map*/
  127. int view[87][86]; /*base map with objects drawn in*/
  128. int originx, originy; /*current world location of ul corn*/
  129. byte priority [maxpics+1]; /*tile draw overlap priorities*/
  130. int items[6],saveitems[6];
  131. int shotpower; /*0-13 characters in power meter*/
  132. int side; /*which side shots come from*/
  133. int boltsleft; /*number of shots left in a bolt*/
  134. activeobj o[maxobj+1],saveo[1]; /*everything that moves is here*/
  135. objdesc obj , altobj; /*total info about objecton and alt*/
  136. int altnum; /*o[#] of altobj*/
  137. int numobj,objecton; /*number of objects in o now*/
  138. struct {
  139. byte think; /*some of these sizes are for the*/
  140. byte contact; /*convenience of the assembly routines*/
  141. byte solid;
  142. word firstchar;
  143. byte size;
  144. byte stages;
  145. byte dirmask;
  146. word speed;
  147. byte hitpoints;
  148. byte damage;
  149. word points;
  150. byte filler[2];
  151. } objdef [lastclass];
  152. int i,j,k,x,y,z;
  153. boolean playdone, leveldone;
  154. boolean tempb;
  155. char far *tempp;
  156. int chkx,chky,chkspot; /*spot being checked by walk*/
  157. word frameon;
  158. char far *grmem;
  159. classtype clvar;
  160. int VGAPAL; // just to make pcrlib happy
  161. boolean exitdemo,resetgame;
  162. statetype gamestate;
  163. ControlStruct ctrl;
  164. char far *pics, far *picsexact;
  165. unsigned EGADATASTART;
  166. long savescore;
  167. //NOLAN ADDED
  168. boolean GODMODE = false;
  169. /****************************************************************************/
  170. //////////////////////////////////
  171. //
  172. // function prototypes
  173. //
  174. //////////////////////////////////
  175. void extern drawobj (void);
  176. void extern eraseobj (void);
  177. void extern doall (void);
  178. void extern egamove (void);
  179. void extern cgarefresh (void);
  180. void extern egarefresh (void);
  181. void dofkeys (void);
  182. /*==============================*/
  183. /* */
  184. /* xxxrefresh */
  185. /* refresh the changed areas of */
  186. /* the tiles map in the various */
  187. /* graphics modes. */
  188. /* */
  189. /*==============================*/
  190. char demowin [5][16] = {
  191. {14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16},
  192. {17,' ','-','-','-',' ','D','E','M','O',' ','-','-','-',' ',18},
  193. {17,'S','P','A','C','E',' ','T','O',' ','S','T','A','R','T',18},
  194. {17,'F','1',' ','T','O',' ','G','E','T',' ','H','E','L','P',18},
  195. {19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21} };
  196. void refresh (void)
  197. {
  198. int x,y,basex,basey;
  199. word underwin [5][16];
  200. basex=originx+4;
  201. basey=originy+17;
  202. if (indemo)
  203. {
  204. for (y=0; y<=4; y++)
  205. for (x=0; x<=15; x++)
  206. {
  207. underwin[y][x]=view[y+basey][x+basex];
  208. view[y+basey][x+basex]=demowin[y][x];
  209. };
  210. }
  211. WaitVBL ();
  212. if (grmode==CGAgr)
  213. cgarefresh();
  214. else
  215. egarefresh();
  216. if (indemo)
  217. {
  218. for (y=0; y<=4; y++)
  219. for (x=0; x<=15; x++)
  220. view[y+basey][x+basex]=underwin[y][x];
  221. }
  222. WaitVBL ();
  223. }
  224. void simplerefresh(void)
  225. {
  226. WaitVBL ();
  227. if (grmode==CGAgr)
  228. cgarefresh();
  229. else
  230. egarefresh();
  231. }
  232. /*
  233. ===================
  234. =
  235. = loadgrfiles
  236. =
  237. = Loads the tiles and sprites, and sets up the pointers and tables
  238. =
  239. ===================
  240. */
  241. void loadgrfiles ()
  242. {
  243. int i;
  244. if (grmode==CGAgr)
  245. {
  246. if (picsexact != NULL)
  247. farfree (picsexact);
  248. pics= (char far *)bloadin("CGACHARS.CA2");
  249. picsexact = lastparalloc;
  250. installgrfile ("CGAPICS.CA2",0,0);
  251. setscreenmode (grmode);
  252. }
  253. else
  254. {
  255. EGADATASTART = 0xA800;
  256. installgrfile ("EGAPICS.CA2",0,0);
  257. setscreenmode (grmode);
  258. moveega ();
  259. pics= (char far *)bloadin("EGACHARS.CA2");
  260. EGAmove ();
  261. farfree (lastparalloc); // chars are allready in EGA mem
  262. }
  263. }
  264. /*======================================*/
  265. /* */
  266. /* restore */
  267. /* redraws every tile on the tiled area */
  268. /* by setting oldtiles to -1. used to */
  269. /* erase any temporary windows. */
  270. /* */
  271. /*======================================*/
  272. void clearold (void)
  273. {
  274. memset (&oldtiles,0xff,sizeof(oldtiles)); /*clear all oldtiles*/
  275. };
  276. void restore (void)
  277. {
  278. clearold ();
  279. simplerefresh ();
  280. };
  281. /* */
  282. /* help */
  283. /* */
  284. boolean wantmore (void)
  285. {
  286. sx=2;
  287. sy=20;
  288. print ("(space for more/esc)");
  289. sx=12;
  290. sy=21;
  291. ch = get ();
  292. if (ch==27)
  293. return false;
  294. return true;
  295. };
  296. /* */
  297. /* charpic */
  298. /* */
  299. void charpic(int x,int y, classtype c, dirtype dir, int stage)
  300. {
  301. int xx,yy,size,tilenum;
  302. size=objdef[c].size;
  303. tilenum=objdef[c].firstchar+size*size
  304. * ((dir & objdef[c].dirmask)*objdef[c].stages+stage);
  305. for (yy=y;yy<=y+size-1;yy++)
  306. for (xx=x;xx<=x+size-1;xx++)
  307. drawchar (xx,yy,tilenum++);
  308. };
  309. void help (void)
  310. {
  311. int x,y;
  312. char far *oldcharptr;
  313. #define OLDSET oldcharptr = charptr;charptr = MK_FP(0xa400,0);
  314. #define NEWSET charptr = oldcharptr;
  315. centerwindow (20,20);
  316. print (" C A T A C O M B \n");
  317. print (" - - - - - - - \n");
  318. print (" by John Carmack \n");
  319. print (" \n");
  320. print ("\n");
  321. print ("f1 = help \n");
  322. print ("f2 = control panel \n");
  323. print ("f3 = game reset \n");
  324. print ("f4 = save game \n");
  325. print ("f5 = load saved game\n");
  326. print ("f9 = pause \n");
  327. print ("f10 / ESC = quit \n");
  328. print ("\n");
  329. print ("hit fire at the demo\n");
  330. print ("to begin playing. \n");
  331. if (!wantmore())
  332. return;
  333. centerwindow (20,20);
  334. print ("\nKeyboard controls: \n\n");
  335. print ("move : arrows \n");
  336. print ("button1 : ctrl \n");
  337. print ("button2 : alt \n");
  338. print ("\nTo switch to mouse \n");
  339. print ("or joystick control,\n");
  340. print ("hit f2 \n");
  341. if (!wantmore())
  342. return;
  343. centerwindow (20,20);
  344. print ("Button 1 / ctrl key:\n");
  345. print ("Builds shot power. \n");
  346. print ("If the shot power \n");
  347. print ("meter is full when \n");
  348. print ("the button is \n");
  349. print ("released, a super \n");
  350. print ("shot will be \n");
  351. print ("launched. \n");
  352. print ("\n");
  353. OLDSET;
  354. for (y=11; y<=18; y++)
  355. for (x=3; x<=20; x++)
  356. drawchar (x,y,128);
  357. charpic (4,14,player,east,2);
  358. charpic (19,15,shot,east,1);
  359. charpic (17,14,shot,east,0);
  360. charpic (15,15,shot,east,1);
  361. charpic (8,14,bigshot,east,0);
  362. NEWSET;
  363. if (!wantmore())
  364. return;
  365. centerwindow (20,20);
  366. print ("Button 2 / alt key:\n");
  367. print ("Allows you to move \n");
  368. print ("without changing the\n");
  369. print ("direction you are \n");
  370. print ("facing. Good for \n");
  371. print ("searching walls and \n");
  372. print ("fighting retreats. \n");
  373. OLDSET;
  374. for (y=11; y<=18; y++)
  375. for (x=3; x<=20; x++)
  376. if (y==15)
  377. drawchar (x,y,129);
  378. else if (y==16)
  379. drawchar (x,y,131);
  380. else
  381. drawchar (x,y,128);
  382. charpic (6,13,player,south,2);
  383. sx=6;
  384. sy=15;
  385. print ("\35\35\36\36\37\37");
  386. NEWSET;
  387. if (!wantmore())
  388. return;
  389. centerwindow (20,20);
  390. print ("\"P\" or \"space\" will \n");
  391. print ("take a healing \n");
  392. print ("potion if you have \n");
  393. print ("one. This restores \n");
  394. print ("the body meter to \n");
  395. print ("full strength. Keep\n");
  396. print ("a sharp eye on the \n");
  397. print ("meter, because when \n");
  398. print ("it runs out, you are\n");
  399. print ("dead! \n\n");
  400. print ("\"B\" will cast a bolt\n");
  401. print ("spell if you have \n");
  402. print ("any. You can mow \n");
  403. print ("down a lot of \n");
  404. print ("monsters with a bit \n");
  405. print ("of skill. \n");
  406. if (!wantmore())
  407. return;
  408. centerwindow (20,20);
  409. print ("\"N\" or \"enter\" will \n");
  410. print ("cast a nuke spell. \n");
  411. print ("This usually wipes \n");
  412. print ("out all the monsters\n");
  413. print ("near you. Consider \n");
  414. print ("it a panic button \n");
  415. print ("when you are being \n");
  416. print ("mobbed by monsters! \n\n");
  417. OLDSET;
  418. print (" \200\200\200\n");
  419. print ("POTIONS: \200\242\200\n");
  420. print (" \200\200\200\n");
  421. print ("SCROLLS: \200\243\200\n");
  422. print (" (BOLTS/NUKES) \200\200\200\n");
  423. print ("TREASURE: \200\247\200\n");
  424. print (" (POINTS) \200\200\200\n");
  425. print (" \200\200\200\n");
  426. NEWSET;
  427. wantmore();
  428. };
  429. /* */
  430. /* reset */
  431. /* */
  432. void reset(void)
  433. {
  434. centerwindow (18,1);
  435. print ("reset game (y/n)?");
  436. ch= get ();
  437. if (ch=='y')
  438. {
  439. gamexit=killed;
  440. playdone=true;
  441. };
  442. };
  443. /*=========================================================================*/
  444. /*==============================*/
  445. /* */
  446. /* loadlevel / savelevel */
  447. /* loads map level into memory, */
  448. /* and sets everything up. */
  449. /* */
  450. /*==============================*/
  451. void loadlevel(void)
  452. {
  453. int i;
  454. classtype tokens[256-230] =
  455. {player,teleporter,goblin,skeleton,ogre,gargoyle,dragon,turbogre,
  456. guns,gune,secretgate,nothing,nothing,nothing,nothing,nothing,
  457. nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,
  458. nothing,nothing};
  459. char filename[64],st[64];
  460. int x,y,xx,yy,recs, btile;
  461. char sm[4096],rle[4096];
  462. strcpy (filename,"level");
  463. itoa (level,st,10);
  464. strcat (filename,st);
  465. strcat (filename,".CA2");
  466. LoadFile (filename,rle);
  467. RLEExpand(&rle[4],&sm,4096);
  468. numobj=0;
  469. o[0].x=13; /*just defaults if no player token is found*/
  470. o[0].y=13;
  471. o[0].stage=0;
  472. o[0].delay=0;
  473. o[0].dir=east;
  474. o[0].oldx=0;
  475. o[0].oldy=0;
  476. o[0].oldtile=-1;
  477. for (yy=0; yy<64; yy++)
  478. for (xx=0; xx<64; xx++)
  479. {
  480. btile=sm[yy*64+xx];
  481. if (btile<230)
  482. background[yy+topoff][xx+leftoff]=btile;
  483. else
  484. {
  485. /*hit a monster token*/
  486. background[yy+topoff][xx+leftoff]=blankfloor;
  487. if (tokens[btile-230]==player)
  488. /*the player token determines where you start in level*/
  489. {
  490. o[0].x=xx+topoff;
  491. o[0].y=yy+leftoff;
  492. }
  493. else
  494. /*monster tokens add to the object list*/
  495. {
  496. numobj++;
  497. o[numobj].active=false;
  498. o[numobj].class=tokens[btile-230];
  499. o[numobj].x=xx+leftoff;
  500. o[numobj].y=yy+topoff;
  501. o[numobj].stage=0;
  502. o[numobj].delay=0;
  503. o[numobj].dir=(dirtype)(rndt()/64); /*random 0-3*/
  504. o[numobj].hp=objdef[o[numobj].class].hitpoints;
  505. o[numobj].oldx=x;
  506. o[numobj].oldy=y;
  507. o[numobj].oldtile=-1;
  508. };
  509. };
  510. };
  511. originx = o[0].x-11;
  512. originy = o[0].y-11;
  513. shotpower=0;
  514. for (y=topoff-1; y<65+topoff; y++)
  515. for (x=leftoff-1; x<64+leftoff; x++)
  516. view[y][x]=background[y][x];
  517. sx=33; /*print the new level number on the right window*/
  518. sy=1;
  519. printint (level);
  520. print (" "); /*in case it went from double to single digit*/
  521. restore();
  522. for (i=0;i<6;i++)
  523. saveitems[i] = items[i];
  524. savescore = score;
  525. saveo[0] = o[0];
  526. };
  527. /*==========================================================================*/
  528. #include "cat_play.c"
  529. #include "objects.c"
  530. /*
  531. ==============
  532. =
  533. = drawside
  534. =
  535. ==============
  536. */
  537. void drawside ()
  538. {
  539. int i;
  540. for (sx=0;sx<40;sx++)
  541. drawchar (sx,24,0);
  542. for (sy=0;sy<24;sy++)
  543. drawchar (39,sy,0);
  544. drawwindow (24,0,38,23); /*draw the right side window*/
  545. print (" level\n\nscore:\n\ntop :\n\nk:\np:\nb:\nn:\n\n");
  546. print (" shot power\n\n\n body\n\n\n");
  547. printhighscore();
  548. printbody();
  549. printshotpower();
  550. printscore();
  551. sx=33; /*print the new level number on the right window*/
  552. sy=1;
  553. printint (level);
  554. drawpic (25*8,17*8,SIDEPIC);
  555. for (i=1; i<=items[1] && i<11; i++)
  556. drawchar (26+i,7,31); /*key icon*/
  557. for (i=1; i<=items[2] && i<11; i++)
  558. drawchar (26+i,8,29); /*potion icon*/
  559. for (i=1; i<=items[3] && i<11; i++)
  560. drawchar (26+i,9,30); /*scroll icon*/
  561. for (i=1; i<=items[5] && i<11; i++)
  562. drawchar (26+i,10,30); /*scroll icon*/
  563. }
  564. /*================================*/
  565. /* */
  566. /* playsetup */
  567. /* set up all data for a new game */
  568. /* does not start it playing */
  569. /* */
  570. /*================================*/
  571. void playsetup()
  572. {
  573. int i;
  574. shotpower=0;
  575. bar (0,0,23,23,0);
  576. if (level==0) // not restarting a saved game
  577. {
  578. for (i=1; i<6; i++)
  579. items[i]=0;
  580. score=0;
  581. level=1;
  582. o[0].active = true;
  583. o[0].class = player;
  584. o[0].hp = 13;
  585. o[0].dir=west;
  586. o[0].stage=0;
  587. o[0].delay=0;
  588. drawside ();
  589. /*give them a few items to start with*/
  590. givenuke();
  591. givenuke();
  592. givebolt();
  593. givebolt();
  594. givebolt();
  595. givepotion();
  596. givepotion();
  597. givepotion();
  598. }
  599. else
  600. drawside ();
  601. };
  602. /*
  603. =============
  604. =
  605. = repaintscreen
  606. =
  607. =============
  608. */
  609. void repaintscreen ()
  610. {
  611. switch (gamestate)
  612. {
  613. case intitle:
  614. drawpic (0,0,TITLEPIC);
  615. break;
  616. case ingame:
  617. restore ();
  618. drawside ();
  619. printscore ();
  620. sx=33; /*print the new level number on the right window*/
  621. sy=1;
  622. printint (level);
  623. break;
  624. case inscores:
  625. restore ();
  626. drawside ();
  627. printscore ();
  628. sx=33; /*print the new level number on the right window*/
  629. sy=1;
  630. printint (level);
  631. indemo = demoplay;
  632. break;
  633. default:
  634. sx=sy=10;
  635. print ("Bad gamestate!");
  636. clearkeys ();
  637. get();
  638. }
  639. }
  640. /*
  641. =============
  642. =
  643. = dofkeys
  644. =
  645. = Checks to see if an F-key is being pressed and handles it
  646. =
  647. =============
  648. */
  649. void dofkeys (void)
  650. {
  651. int i,handle;
  652. char st2[10];
  653. int key=bioskey(1)/256;
  654. if (key==1) // make ESC into F10
  655. key=0x44;
  656. if (key<0x3b || key>0x44)
  657. return;
  658. switch (key)
  659. {
  660. case 0x3b: // F1
  661. clearkeys ();
  662. help ();
  663. break;
  664. case 0x3c: // F2
  665. clearkeys ();
  666. controlpanel ();
  667. break;
  668. case 0x3d: // F3
  669. clearkeys ();
  670. expwin (18,1);
  671. print ("RESET GAME (Y/N)?");
  672. ch=toupper(get());
  673. if (ch=='Y')
  674. resetgame = true;
  675. break;
  676. case 0x3e: // F4
  677. clearkeys ();
  678. expwin (22,4);
  679. if (indemo != notdemo)
  680. {
  681. print ("Can't save game here!");
  682. get ();
  683. break;
  684. }
  685. print ("Save as game #(1-9):");
  686. ch=toupper(get());
  687. drawchar (sx,sy,ch);
  688. if (ch<'1' || ch>'9')
  689. break;
  690. //
  691. // save game
  692. //
  693. strcpy (str,"GAME0.CA2");
  694. str[4]=ch;
  695. if (_Verify(str))
  696. {
  697. print ("\nGame exists,\noverwrite (Y/N)?");
  698. ch=get();
  699. if (ch!='Y' && ch!='y')
  700. break;
  701. sx=leftedge;
  702. print (" ");
  703. sy--;
  704. sx=leftedge;
  705. print (" ");
  706. sx=leftedge;
  707. sy--;
  708. }
  709. if ((handle = open(str, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)) == -1)
  710. return;
  711. write(handle, &saveitems, sizeof(items));
  712. write(handle, &savescore, sizeof(score));
  713. write(handle, &level, sizeof(level));
  714. write(handle, &saveo[0],sizeof(o[0]));
  715. close(handle);
  716. print ("\nGame saved. Hit F5\n");
  717. print ("when you wish to\n");
  718. print ("restart the game.");
  719. get();
  720. break;
  721. case 0x3f: // F5
  722. clearkeys ();
  723. expwin (22,4);
  724. print ("Load game #(1-9):");
  725. ch=toupper(get());
  726. drawchar (sx,sy,ch);
  727. if (ch<'1' || ch>'9')
  728. break;
  729. //
  730. // load game
  731. //
  732. strcpy (str,"GAME0.CA2");
  733. str[4]=ch;
  734. if ((handle = open(str, O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1)
  735. {
  736. print ("\nGame not found.");
  737. get ();
  738. break;
  739. }
  740. read(handle, &items, sizeof(items));
  741. read(handle, &score, sizeof(score));
  742. read(handle, &level, sizeof(level));
  743. read(handle, &o[0],sizeof(o[0]));
  744. close(handle);
  745. exitdemo = true;
  746. if (indemo != notdemo)
  747. playdone = true;
  748. drawside (); // draw score, icons, etc
  749. leveldone = true;
  750. break;
  751. case 0x43: // F9
  752. clearkeys ();
  753. expwin (7,1);
  754. print ("PAUSED");
  755. get ();
  756. break;
  757. case 0x44: // F10
  758. clearkeys ();
  759. expwin (12,1);
  760. print ("QUIT (Y/N)?");
  761. ch=toupper(get());
  762. if (ch=='Y')
  763. _quit ("");
  764. break;
  765. default:
  766. return;
  767. }
  768. clearold ();
  769. clearkeys ();
  770. repaintscreen ();
  771. }
  772. /*=========================================================================*/
  773. /*
  774. =============
  775. =
  776. = dotitlepage
  777. =
  778. =============
  779. */
  780. void dotitlepage (void)
  781. {
  782. int i;
  783. drawpic (0,0,TITLEPIC);
  784. gamestate=intitle;
  785. for (i=0;i<300;i++)
  786. {
  787. WaitVBL ();
  788. indemo = notdemo;
  789. ctrl = ControlPlayer (1);
  790. if (ctrl.button1 || ctrl.button2 || keydown[0x39])
  791. {
  792. level = 0;
  793. exitdemo = true;
  794. break;
  795. }
  796. indemo = demoplay;
  797. if (bioskey (1))
  798. dofkeys ();
  799. if (exitdemo)
  800. break;
  801. }
  802. gamestate=ingame;
  803. }
  804. /*=========================================================================*/
  805. /*
  806. =============
  807. =
  808. = doendpage
  809. =
  810. =============
  811. */
  812. void doendpage (void)
  813. {
  814. WaitEndSound();
  815. drawpic (0,0,ENDPIC);
  816. PlaySound (TREASURESND);
  817. WaitEndSound();
  818. PlaySound (TREASURESND);
  819. WaitEndSound();
  820. PlaySound (TREASURESND);
  821. WaitEndSound();
  822. PlaySound (TREASURESND);
  823. WaitEndSound();
  824. drawwindow (0,0,17,9);
  825. print ("Congratulation! \n");
  826. print ("One as skilled \n");
  827. print ("as yourself \n");
  828. print ("deserves the \n");
  829. print ("10,000,000 gold \n");
  830. print ("you pulled out \n");
  831. print ("of the palace! ");
  832. clearkeys();
  833. get ();
  834. drawwindow (0,0,17,9);
  835. print ("Let us know what\n");
  836. print ("you enjoyed \n");
  837. print ("about this game,\n");
  838. print ("so we can give \n");
  839. print ("you more of it. \n");
  840. print ("Thank you for \n");
  841. print ("playing!");
  842. get ();
  843. }
  844. /*=========================================================================*/
  845. /*
  846. =============
  847. =
  848. = dodemo
  849. =
  850. = Shows a random demo
  851. =
  852. =============
  853. */
  854. void dodemo (void)
  855. {
  856. int i;
  857. while (!exitdemo)
  858. {
  859. dotitlepage ();
  860. if (exitdemo)
  861. break;
  862. i=random(NUMDEMOS)+1;
  863. LoadDemo (i);
  864. level=0;
  865. playsetup ();
  866. playloop ();
  867. if (exitdemo)
  868. break;
  869. level = 0;
  870. gamestate=inscores;
  871. indemo = demoplay;
  872. _showhighscores ();
  873. for (i=0;i<500;i++)
  874. {
  875. WaitVBL ();
  876. indemo = notdemo;
  877. ctrl = ControlPlayer (1);
  878. if (ctrl.button1 || ctrl.button2 || keydown[0x39])
  879. {
  880. exitdemo = true;
  881. break;
  882. }
  883. if (bioskey (1))
  884. dofkeys ();
  885. if (exitdemo)
  886. break;
  887. }
  888. }
  889. }
  890. /*=========================================================================*/
  891. /*
  892. ============
  893. =
  894. = gameover
  895. =
  896. = End game, check for high score
  897. =
  898. ============
  899. */
  900. void gameover (void)
  901. {
  902. int i;
  903. expwin (11,4);
  904. print ("\n GAME OVER\n ");
  905. WaitEndSound ();
  906. for (i=0;i<120;i++)
  907. WaitVBL ();
  908. gamestate=inscores;
  909. _checkhighscore ();
  910. level = 0;
  911. for (i=0;i<500;i++)
  912. {
  913. WaitVBL ();
  914. ctrl = ControlPlayer (1);
  915. if (ctrl.button1 || ctrl.button2 || keydown[0x39])
  916. break;
  917. if (bioskey (1))
  918. dofkeys ();
  919. if (exitdemo)
  920. break;
  921. }
  922. }
  923. /***************************************************************************/
  924. /***************************************************************************/
  925. ///////////////////////////////////////////////////////////////////////////
  926. //
  927. // US_CheckParm() - checks to see if a string matches one of a set of
  928. // strings. The check is case insensitive. The routine returns the
  929. // index of the string that matched, or -1 if no matches were found
  930. //
  931. ///////////////////////////////////////////////////////////////////////////
  932. int
  933. US_CheckParm(char *parm,char **strings)
  934. {
  935. char cp,cs,
  936. *p,*s;
  937. int i;
  938. while (!isalpha(*parm)) // Skip non-alphas
  939. parm++;
  940. for (i = 0;*strings && **strings;i++)
  941. {
  942. for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
  943. {
  944. cs = *s++;
  945. if (!cs)
  946. return(i);
  947. cp = *p++;
  948. if (isupper(cs))
  949. cs = tolower(cs);
  950. if (isupper(cp))
  951. cp = tolower(cp);
  952. }
  953. }
  954. return(-1);
  955. }
  956. /***************************************************************************/
  957. /***************************************************************************/
  958. static char *EntryParmStrings[] = {"detour",0};
  959. /*=========================*/
  960. /* */
  961. /* m a i n p r o g r a m */
  962. /* */
  963. /*=========================*/
  964. void main (void)
  965. {
  966. boolean LaunchedFromShell = false;
  967. if (stricmp(_argv[1], "/VER") == 0)
  968. {
  969. printf("The Catacomb\n");
  970. printf("Copyright 1990-93 Softdisk Publishing\n");
  971. printf("Version 1.02\n");
  972. exit(0);
  973. }
  974. for (i = 1;i < _argc;i++)
  975. {
  976. switch (US_CheckParm(_argv[i],EntryParmStrings))
  977. {
  978. case 0:
  979. LaunchedFromShell = true;
  980. break;
  981. }
  982. }
  983. #ifndef CATALOG
  984. if (!LaunchedFromShell)
  985. {
  986. clrscr();
  987. puts("You must type START at the DOS prompt to run THE CATACOMB.");
  988. exit(0);
  989. }
  990. #endif
  991. initobjects();
  992. memset (&priority,99,sizeof(priority));
  993. priority[blankfloor]=0;
  994. for (i=objdef[teleporter].firstchar; i<=objdef[teleporter].firstchar+20;i++)
  995. priority[i]=0;
  996. for (clvar=dead2; clvar<=dead5; clvar++)
  997. for (i=objdef[clvar].firstchar; i<=objdef[clvar].firstchar+
  998. objdef[clvar].size*objdef[clvar].size; i++)
  999. priority[i]=0; /*deadthing*/
  1000. for (i=152; i<=161; i++)
  1001. priority[i]=2; /*shots*/
  1002. for (i=objdef[bigshot].firstchar; i<= objdef[bigshot].firstchar + 31; i++)
  1003. priority[i]=2; /*bigshot*/
  1004. for (i=0; i<=tile2s-1; i++)
  1005. if (priority [i]==99)
  1006. priority[i]=3; /*most 1*1 tiles are walls, etc*/
  1007. priority[167]=1; // chest
  1008. for (i=tile2s; i<=maxpics; i++)
  1009. if (priority[i]==99)
  1010. priority[i]=4; /*most bigger tiles are monsters*/
  1011. for (i=objdef[player].firstchar; i<= objdef[player].firstchar + 63; i++)
  1012. priority[i]=5; /*player*/
  1013. side=0;
  1014. for (x=0; x<=85; x++)
  1015. {
  1016. for (y=0; y<=topoff-1; y++)
  1017. {
  1018. view[x][y]=solidwall;
  1019. view[x][85-y]=solidwall;
  1020. background[x][y]=solidwall;
  1021. background[x][85-y]=solidwall;
  1022. };
  1023. view[86][x]=solidwall;
  1024. };
  1025. for (y=11; y<=74; y++)
  1026. for (x=0; x<=leftoff-1; x++)
  1027. {
  1028. view[x][y]=solidwall;
  1029. view[85-x][y]=solidwall;
  1030. background[x][y]=solidwall;
  1031. background[85-x][y]=solidwall;
  1032. };
  1033. // puts ("CATACOMB II is executing");
  1034. // _dontplay = 1; // no sounds for debugging and profiling
  1035. _numlevels = 30;
  1036. _maxplayers = 1;
  1037. _cgaok = true;
  1038. _egaok = true;
  1039. _vgaok = false;
  1040. _extension = "CA2";
  1041. _setupgame ();
  1042. expwin (33,13);
  1043. print (" Softdisk Publishing presents\n\n");
  1044. print (" The Catacomb\n\n");
  1045. print (" By John Carmack\n\n");
  1046. print (" Copyright 1990-93\n");
  1047. print (" Softdisk Publishing");
  1048. print ("\n\n");
  1049. print ("\n\n");
  1050. print (" Press a key:");
  1051. get();
  1052. clearkeys ();
  1053. screencentery = 11;
  1054. screencenterx = 11;
  1055. exitdemo = false;
  1056. level = 0;
  1057. while (1) // go until quit () is called
  1058. {
  1059. dodemo ();
  1060. playsetup ();
  1061. indemo = notdemo;
  1062. gamestate = ingame;
  1063. playloop ();
  1064. if (!indemo)
  1065. {
  1066. exitdemo = false;
  1067. if (level > numlevels)
  1068. doendpage (); // finished all levels
  1069. gameover ();
  1070. }
  1071. }
  1072. }