-
Notifications
You must be signed in to change notification settings - Fork 54
/
C3_DEF.H
533 lines (373 loc) · 12.5 KB
/
C3_DEF.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
/* Catacomb 3-D 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 NAMESTART 180
#define UNMARKGRCHUNK(chunk) (grneeded[chunk]&=~ca_levelbit)
#define MOUSEINT 0x33
#define EXPWALLSTART 8
#define NUMEXPWALLS 7
#define WALLEXP 15
#define NUMFLOORS 36
#define NUMFLOORS 36
#define NUMLATCHPICS 100
#define NUMSCALEPICS 100
#define NUMSCALEWALLS 30
#define FLASHCOLOR 5
#define FLASHTICS 4
#define NUMLEVELS 20
#define VIEWX 0 // corner of view window
#define VIEWY 0
#define VIEWWIDTH (33*8) // size of view window
#define VIEWHEIGHT (18*8)
#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 150 // 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 PAGE1START 0x900
#define PAGE2START 0x2000
#define PAGE3START 0x3700
#define FREESTART 0x4e00
#define PIXRADIUS 512
#define STATUSLINES (200-VIEWHEIGHT)
enum bonusnumbers {B_BOLT,B_NUKE,B_POTION,B_RKEY,B_YKEY,B_GKEY,B_BKEY,B_SCROLL1,
B_SCROLL2,B_SCROLL3,B_SCROLL4,B_SCROLL5,B_SCROLL6,B_SCROLL7,B_SCROLL8,
B_GOAL,B_CHEST};
/*
=============================================================================
GLOBAL TYPES
=============================================================================
*/
enum {BLANKCHAR=9,BOLTCHAR,NUKECHAR,POTIONCHAR,KEYCHARS,SCROLLCHARS=17,
NUMBERCHARS=25};
typedef long fixed;
typedef struct {int x,y;} tilept;
typedef struct {fixed x,y;} globpt;
typedef struct
{
int x1,x2,leftclip,rightclip;// first 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} 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,yes} 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 struct
{
int difficulty;
int mapon;
int bolts,nukes,potions,keys[4],scrolls[8];
long score;
int body,shotpower;
} gametype;
typedef enum {ex_stillplaying,ex_died,ex_warped,ex_resetgame
,ex_loadedgame,ex_victorious,ex_abort} exittype;
/*
=============================================================================
C3_MAIN DEFINITIONS
=============================================================================
*/
extern char str[80],str2[20];
extern unsigned tedlevelnum;
extern boolean tedlevel;
extern gametype gamestate;
extern exittype playstate;
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
=============================================================================
*/
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);
/*
=============================================================================
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];
//==========================================================================
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);
/*
=============================================================================
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,
scaleblockdest;
extern byte plotpix[8];
extern byte bitmasks1[8][8];
extern byte bitmasks2[8][8];
extern t_compscale _seg *scaledirectory[MAXSCALE+1];
extern t_compshape _seg *shapedirectory[NUMSCALEPICS];
extern memptr walldirectory[NUMSCALEWALLS];
extern unsigned shapesize[MAXSCALE+1];
void DeplanePic (int picnum);
void ScaleShape (int xcenter, t_compshape _seg *compshape, unsigned scale);
unsigned BuildCompShape (t_compshape _seg **finalspot);
/*
=============================================================================
C3_ASM DEFINITIONS
=============================================================================
*/
extern unsigned wallheight [VIEWWIDTH];
extern unsigned wallwidth [VIEWWIDTH];
extern unsigned wallseg [VIEWWIDTH];
extern unsigned wallofs [VIEWWIDTH];
extern unsigned screenbyte [VIEWWIDTH];
extern unsigned screenbit [VIEWWIDTH];
extern unsigned bitmasks [64];
extern long wallscalecall;
void ScaleWalls (void);
/*
=============================================================================
C3_WIZ DEFINITIONS
=============================================================================
*/
#define MAXHANDHEIGHT 72
extern long lastnuke;
extern int handheight;
extern int boltsleft;
/*
=============================================================================
C3_ACT1 DEFINITIONS
=============================================================================
*/
extern statetype s_trollouch;
extern statetype s_trolldie1;
extern statetype s_orcpause;
extern statetype s_orc1;
extern statetype s_orc2;
extern statetype s_orc3;
extern statetype s_orc4;
extern statetype s_orcattack1;
extern statetype s_orcattack2;
extern statetype s_orcattack3;
extern statetype s_orcouch;
extern statetype s_orcdie1;
extern statetype s_orcdie2;
extern statetype s_orcdie3;
extern statetype s_demonouch;
extern statetype s_demondie1;
extern statetype s_mageouch;
extern statetype s_magedie1;
extern statetype s_grelouch;
extern statetype s_greldie1;
extern statetype s_batdie1;