-
Notifications
You must be signed in to change notification settings - Fork 26
/
MIKE.H
736 lines (536 loc) · 18.2 KB
/
MIKE.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/* Catacomb Abyss 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.
*/
#include "ID_HEADS.H"
#include <MATH.H>
#include <VALUES.H>
//#define PROFILE
/*
=============================================================================
GLOBAL CONSTANTS
=============================================================================
*/
#define PI 3.141592657
#define ROTATE_SPEED (6)
#define FL_QUICK 0x01
#define FL_CLEAR 0x01
#define GEM_SHIFT 1
#define FL_RGEM 0x02
#define FL_GGEM 0x04
#define FL_BGEM 0x08
#define FL_YGEM 0x10
#define FL_PGEM 0x20
#define MAXBOLTS 10
#define MAXNUKES 10
#define MAXPOTIONS 10
#define NUKE_COST (1000)
#define BOLT_COST (1200)
#define POTION_COST (1300)
#define NUKE_COST_TXT ("1000") // Allows for Q&D positioning..
#define BOLT_COST_TXT ("1200")
#define POTION_COST_TXT ("1300")
#define RADARX 31 // bytes
#define RADARY 11 // pixels
#define RADAR_WIDTH 51 // "
#define RADAR_HEIGHT 51 // "
#define RADAR_XCENTER ((RADARX*8)+(RADAR_WIDTH/2)+3) // "
#define RADAR_YCENTER ((RADARY-8)+(RADAR_HEIGHT/2)+5) // "
#define MAX_RADAR_BLIPS 60
#define RADAR_RADIUS 17
#define RADAR_RADIUS_NSEW 15
#define RADAR_X_IRADIUS (110/5)
#define RADAR_Y_IRADIUS (110/7)
#define RADAR_ICON_CENTER 4 // Center offset into icon.
#define NAMESTART 180
#define REMOVED_DOOR_TILE NAMESTART
#define NEXT_LEVEL_CODE 0xff
#define REMOVE_DOOR_CODE 0xfe
#define CANT_OPEN_CODE 0xfd
#define EXP_WALL_CODE 0xfc
#define WALL_SKELETON_CODE 6
#define UNMARKGRCHUNK(chunk) (grneeded[chunk]&=~ca_levelbit)
#define MOUSEINT 0x33
#define EXPWALLSTART 8
#define NUMEXPWALLS 7
#define WALLEXP 15
#define NUMFLOORS 62+5
#define NUMLATCHPICS (FIRSTWALLPIC-FIRSTLATCHPIC)+5
#define NUMSCALEPICS (FIRSTWALLPIC-FIRSTSCALEPIC)+5
#define NUMSCALEWALLS (LASTWALLPIC-FIRSTWALLPIC)+5
#define FLASHCOLOR 12
#define FLASHTICS 4
#define NUMLEVELS 21
#define VIEWX 0 // corner of view window
#define VIEWY 0
#define VIEWWIDTH (40*8) // size of view window // 33
#define VIEWHEIGHT (15*8) // 18
#define VIEWXH (VIEWX+VIEWWIDTH-1)
#define VIEWYH (VIEWY+VIEWHEIGHT-1)
#define CENTERX (VIEWX+VIEWWIDTH/2-1) // middle of view window
#define CENTERY (VIEWY+VIEWHEIGHT/2-1)
#define GLOBAL1 (1l<<16)
#define TILEGLOBAL GLOBAL1
#define TILESHIFT 16l
#define MINDIST (2*GLOBAL1/5)
#define FOCALLENGTH (TILEGLOBAL) // in global coordinates
#define ANGLES 360 // must be divisable by 4
#define MAPSIZE 64 // maps are 64*64 max
#define MAXACTORS 100 // max number of tanks, etc / map
#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3
#define SIGN(x) ((x)>0?1:-1)
#define ABS(x) ((int)(x)>0?(x):-(x))
#define LABS(x) ((long)(x)>0?(x):-(x))
#define MAXSCALE (VIEWWIDTH/2)
#define MAXBODY 64
#define MAXSHOTPOWER 56
#define SCREEN1START 0
#define SCREEN2START 8320
//#define STATUallptr);
void TraceRay (unsigned angle);
fixed FixedByFrac (fixed a, fixed b);
void TransformPoint (fixed gx, fixed gy, int *screenx, unsigned *screenheight);
fixed TransformX (fixed gx, fixed gy);
int FollowTrace (fixed tracex, fixed tracey, long deltax, long deltay, int max);
void ForwardTrace (void);
int FinishWall (void);
int TurnClockwise (void);
int TurnCounterClockwise (void);
void FollowWall (void);
void NewScene (void);
void BuildTables (void);
/*
=============================================================================
C3_SCALE DEFINITIONS
=============================================================================
*/
#define COMPSCALECODESTART (65*6) // offset to start of code in comp scaler
typedef struct
{
unsigned codeofs[65];
unsigned start[65];
unsigned width[65];
byte code[];
} t_compscale;
typedef struct
{
unsigned width;
unsigned codeofs[64];
} t_compshape;
extern unsigned scaleblockwidth,
scaleblockheight,
scalet pixel of wall (may not be visable)
unsigned height1,height2,color,walllength,side;
long planecoord;
} walltype;
typedef enum
{nothing,playerobj,bonusobj,orcobj,batobj,skeletonobj,trollobj,demonobj,
mageobj,pshotobj,bigpshotobj,mshotobj,inertobj,bounceobj,grelmobj,
gateobj,zombieobj,spookobj,wetobj,expobj,eyeobj,eshotobj,wallskelobj,
solidobj} classtype;
typedef enum {north,east,south,west,northeast,southeast,southwest,
northwest,nodir} dirtype; // a catacombs 2 carryover
typedef struct statestruct
{
int shapenum;
int tictime;
void (*think) ();
struct statestruct *next;
} statetype;
typedef struct objstruct
{
enum {no,noalways,yes,always} active;
int ticcount;
classtype obclass;
statetype *state;
boolean shootable;
boolean tileobject; // true if entirely inside one tile
long distance;
dirtype dir;
fixed x,y;
unsigned tilex,tiley;
int viewx;
unsigned viewheight;
int angle;
int hitpoints;
long speed;
unsigned size; // global radius for hit rect calculation
fixed xl,xh,yl,yh; // hit rectangle
int temp1,temp2;
struct objstruct *next,*prev;
} objtype;
typedef enum {ex_stillplaying,ex_died,ex_warped,ex_resetgame
,ex_loadedgame,ex_victorious,ex_abort} exittype;
typedef struct {
char x,y;
unsigned ondoor,underdoor;
} doorinfo;
typedef struct {
char x,y;
short angle;
// doorinfo doors[MAX_DOOR_STORAGE];
} levelinfo;
typedef struct
{
int difficulty;
int mapon;
int bolts,nukes,potions,keys[4],scrolls[8],gems[5];
long score;
int body,shotpower;
levelinfo levels[NUMLEVELS];
} gametype;
/*
=============================================================================
C3_MAIN DEFINITIONS
=============================================================================
*/
extern char inlevel[][2];
extern char str[80],str2[20];
extern unsigned tedlevelnum;
extern boolean tedlevel;
extern gametype gamestate;
extern exittype playstate;
extern char SlowMode;
extern unsigned Flags;
void NewGame (void);
boolean SaveTheGame(int file);
boolean LoadTheGame(int file);
void ResetGame(void);
void ShutdownId (void);
void InitGame (void);
void Quit (char *error);
void TEDDeath(void);
void DemoLoop (void);
void SetupScalePic (unsigned picnum);
void SetupScaleWall (unsigned picnum);
void SetupScaling (void);
void main (void);
/*
=============================================================================
C3_GAME DEFINITIONS
=============================================================================
*/
extern unsigned latchpics[NUMLATCHPICS];
extern unsigned tileoffsets[NUMTILE16];
extern unsigned textstarts[27];
#define L_CHARS 0
#define L_NOSHOT 1
#define L_SHOTBAR 2
#define L_NOBODY 3
#define L_BODYBAR 4
void ScanInfoPlane (void);
void ScanText (void);
void SetupGameLevel (void);
void Victory (void);
void Died (void);
void NormalScreen (void);
void DrawPlayScreen (void);
void LoadLatchMem (void);
void FizzleFade (unsigned source, unsigned dest,
unsigned width,unsigned height, boolean abortable);
void FizzleOut (int showlevel);
void FreeUpMemory (void);
void GameLoop (void);
/*
=============================================================================
C3_PLAY DEFINITIONS
=============================================================================
*/
#define BGF_NIGHT 0x01 // it is officially night
#define BGF_NOT_LIGHTNING 0x02 // lightning flash has ended
extern byte BGFLAGS;
extern unsigned *skycolor,*groundcolor;
extern ControlInfo c;
extern boolean running,slowturn;
extern int bordertime;
extern byte tilemap[MAPSIZE][MAPSIZE];
extern objtype *actorat[MAPSIZE][MAPSIZE];
extern byte spotvis[MAPSIZE][MAPSIZE];
extern objtype objlist[MAXACTORS],*new,*obj,*player;
extern unsigned farmapylookup[MAPSIZE];
extern byte *nearmapylookup[MAPSIZE];
extern byte update[];
extern boolean godmode,singlestep;
extern int extravbls;
extern int mousexmove,mouseymove;
extern int pointcount,pointsleft;
void CenterWindow(word w,word h);
void DebugMemory (void);
void PicturePause (void);
int DebugKeys (void);
void CheckKeys (void);
void InitObjList (void);
void GetNewObj (boolean usedummy);
void RemoveObj (objtype *gone);
void PollControlls (void);
void PlayLoop (void);
void InitBgChange(short stimer, unsigned *scolors, short gtimer, unsigned *gcolors, byte flag);
char GetKeyChoice(char *choices,boolean clear);
/*
=============================================================================
C3_STATE DEFINITIONS
=============================================================================
*/
void SpawnNewObj (unsigned x, unsigned y, statetype *state, unsigned size);
void SpawnNewObjFrac (long x, long y, statetype *state, unsigned size);
boolean CheckHandAttack (objtype *ob);
void T_DoDamage (objtype *ob);
boolean Walk (objtype *ob);
void ChaseThink (objtype *obj, boolean diagonal);
void MoveObj (objtype *ob, long move);
boolean Chase (objtype *ob, boolean diagonal);
extern dirtype opposite[9];
/*
=============================================================================
C3_TRACE DEFINITIONS
=============================================================================
*/
int FollowTrace (fixed tracex, fixed tracey, long deltax, long deltay, int max);
int BackTrace (int finish);
void ForwardTrace (void);
int FinishWall (void);
void InsideCorner (void);
void OutsideCorner (void);
void FollowWalls (void);
extern boolean aborttrace;
/*
=============================================================================
C3_DRAW DEFINITIONS
=============================================================================
*/
#define MAXWALLS 50
#define DANGERHIGH 45
#define MIDWALL (MAXWALLS/2)
//==========================================================================
extern tilept tile,lasttile,focal,left,mid,right;
extern globpt edge,view;
extern unsigned screenloc[3];
extern unsigned freelatch;
extern int screenpage;
extern boolean fizzlein;
extern long lasttimecount;
extern int firstangle,lastangle;
extern fixed prestep;
extern int traceclip,tracetop;
extern fixed sintable[ANGLES+ANGLES/4],*costable;
extern fixed viewx,viewy,viewsin,viewcos; // the focal point
extern int viewangle;
extern fixed scale,scaleglobal;
extern unsigned slideofs;
extern int zbuffer[VIEWXH+1];
extern walltype walls[MAXWALLS],*leftwall,*rightwall;
extern fixed tileglobal;
extern fixed focallength;
extern fixed mindist;
extern int viewheight;
extern fixed scale;
extern int walllight1[NUMFLOORS];
extern int walldark1[NUMFLOORS];
extern int walllight2[NUMFLOORS];
extern int walldark2[NUMFLOORS];
extern unsigned topcolor,bottomcolor;
//==========================================================================
void DrawLine (int xl, int xh, int y,int color);
void DrawWall (walltype *wallptr);
void TraceRay (unsigned angle);
fixed FixedByFrac (fixed a, fixed b);
void TransformPoint (fixed gx, fixed gy, int *screenx, unsigned *screenheight);
fixed TransformX (fixed gx, fixed gy);
int FollowTrace (fixed tracex, fixed tracey, long deltax, long deltay, int max);
void ForwardTrace (void);
int FinishWall (void);
int TurnClockwise (void);
int TurnCounterClockwise (void);
void FollowWall (void);
void NewScene (void);
void BuildTables (void);
/*
===============================tarted% "