Subversion Repositories eduke32

Rev

Rev 8792 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5196 hendricks2 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 1997, 2005 - 3D Realms Entertainment
4
 
5
This file is part of Shadow Warrior version 1.2
6
 
7
Shadow Warrior is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 
16
See the GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
 
22
Original Source: 1997 - Frank Maddin and Jim Norwood
23
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24
*/
25
//-------------------------------------------------------------------------
26
 
27
#ifndef GAME_H
28
 
29
#define GAME_H
30
 
31
#ifndef DEBUG
32
#define DEBUG 0
33
#endif
34
 
35
#include "compat.h"
36
#include "baselayer.h"
37
#include "mmulti.h"
8601 hendricks2 38
#include "build.h"
5196 hendricks2 39
 
40
#include "mytypes.h"
41
#include "keyboard.h"
42
#include "sounds.h"
43
#include "settings.h"
8504 hendricks2 44
#include "common_game.h"
5196 hendricks2 45
 
46
// Turn warning off for unreferenced variables.
47
// I really should fix them at some point
48
//#pragma off(unreferenced)
49
 
50
 
51
#define ERR_STD_ARG __FILE__, __LINE__
52
 
8349 hendricks2 53
void _Assert(const char *expr, const char *strFile, unsigned uLine);
54
#define PRODUCTION_ASSERT(f) \
55
    do { \
56
        if (!(f)) \
57
            _Assert(#f,ERR_STD_ARG); \
58
    } while (0)
59
 
60
#if DEBUG || defined DEBUGGINGAIDS
61
#define ASSERT(f) PRODUCTION_ASSERT(f)
62
#else
63
#define ASSERT(f) do { } while (0)
64
#endif
65
 
5196 hendricks2 66
#if DEBUG
67
void HeapCheck(char *, int);
68
#define HEAP_CHECK() HeapCheck(__FILE__, __LINE__)
69
 
70
void dsprintf(char *, char *, ...);
71
#define DSPRINTF dsprintf
72
 
5198 hendricks2 73
void PokeStringMono(uint8_t Attr, uint8_t* String);
5196 hendricks2 74
 
75
#if 1  // !JIM! Frank, I redirect this for me you'll want to set this back for you
76
extern int DispMono;
77
#define MONO_PRINT(str) if (DispMono) PokeStringMono(/*MDA_NORMAL*/ 0, str)
78
#else
7499 hendricks2 79
void adduserquote(const char *daquote);
5196 hendricks2 80
extern int DispMono;
81
#define MONO_PRINT(str) if (DispMono) CON_ConMessage(str); // Put it in my userquote stuff!
82
//#define MONO_PRINT(str) if (DispMono) printf(str);
83
#endif
84
 
85
#define RANDOM_DEBUG 1 // Set this to 1 for network testing.
86
#else
87
#define MONO_PRINT(str)
88
 
7499 hendricks2 89
void dsprintf_null(char *str, const char *format, ...);
5196 hendricks2 90
#define DSPRINTF dsprintf_null
91
//#define DSPRINTF()
92
 
93
#define HEAP_CHECK()
94
#define RANDOM_DEBUG 0
95
#endif
96
 
97
 
98
#if RANDOM_DEBUG
99
int RandomRange(int, char *, unsigned);
100
int krand1(char *, unsigned);
101
#define RANDOM_P2(pwr_of_2) (MOD_P2(krand1(__FILE__,__LINE__),(pwr_of_2)))
102
#define RANDOM_RANGE(range) (RandomRange(range,__FILE__,__LINE__))
103
#define RANDOM() (krand1(__FILE__,__LINE__))
104
#else
105
int RandomRange(int);
106
int krand1(void);
107
#define RANDOM_P2(pwr_of_2) (MOD_P2(krand1(),(pwr_of_2)))
108
#define RANDOM_RANGE(range) (RandomRange(range))
109
#define RANDOM() (krand1())
110
#endif
111
 
112
 
113
#define PRINT(line,str) DebugPrint(line,str)
114
 
115
#include "pragmas.h"
116
 
117
 
118
//
119
// Map directions/degrees
120
//
121
 
5203 hendricks2 122
#if 0
5196 hendricks2 123
y--
124
^ 1536
125
|
126
|
127
|
128
|
129
|
130
|            2047
131
<---------------------------->
132
1024         |              0
133
x--          |             x++
134
|
135
|
136
|
137
|
138
V 512
139
y++
140
 
141
#endif
142
 
143
//////////////////////////////////////////////////////
144
//
145
// KEYBOARD
146
//
147
//////////////////////////////////////////////////////
148
 
5198 hendricks2 149
extern SWBOOL MenuInputMode;
150
extern SWBOOL MessageInputMode;
151
extern SWBOOL ConInputMode;
152
extern SWBOOL ConPanel;
153
extern SWBOOL InputMode;
5196 hendricks2 154
extern char MessageInputString[256];
155
extern char MessageOutputString[256];
156
 
157
//
158
// Defines
159
//
160
 
161
#define CIRCLE_CAMERA_DIST_MIN 12000
162
 
163
// dist at which actors will not move (unless shot?? to do)
164
#define MAX_ACTIVE_RANGE 42000
165
// dist at which actors roam about on their own
166
#define MIN_ACTIVE_RANGE 20000
167
 
168
#undef  KEYSC_UP
169
#define KEYSC_UP        sc_UpArrow
170
#undef  KEYSC_DOWN
171
#define KEYSC_DOWN      sc_DownArrow
172
#undef  KEYSC_LEFT
173
#define KEYSC_LEFT      sc_LeftArrow
174
#undef  KEYSC_RIGHT
175
#define KEYSC_RIGHT     sc_RightArrow
176
#undef  KEYSC_INS
177
#define KEYSC_INS       sc_Insert
178
#undef  KEYSC_DEL
179
#define KEYSC_DEL       sc_Delete
180
#undef  KEYSC_HOME
181
#define KEYSC_HOME      sc_Home
182
#undef  KEYSC_END
183
#define KEYSC_END       sc_End
184
#undef  KEYSC_PGUP
185
#define KEYSC_PGUP      sc_PgUp
186
#undef  KEYSC_PGDN
187
#define KEYSC_PGDN      sc_PgDn
188
 
189
#define KEYSC_RALT      sc_RightAlt
190
#define KEYSC_RCTRL     sc_RightControl
191
#define KEYSC_KPSLASH   sc_kpad_Slash
192
#define KEYSC_KPENTER   sc_kpad_Enter
193
#define KEYSC_PRINTSCREEN sc_PrintScreen
194
#define KEYSC_LASTSC      sc_LastScanCode
195
 
196
#define KEYSC_KP_1      sc_kpad_1
197
#define KEYSC_KP_2      sc_kpad_2
198
#define KEYSC_KP_3      sc_kpad_3
199
#define KEYSC_KP_4      sc_kpad_4
200
#define KEYSC_KP_6      sc_kpad_6
201
#define KEYSC_KP_5     sc_kpad_5
202
#define KEYSC_KP_7      sc_kpad_7
203
#define KEYSC_KP_8      sc_kpad_8
204
#define KEYSC_KP_9      sc_kpad_9
205
#define KEYSC_KP_0      sc_kpad_0
206
#define KEYSC_KPMINUS  sc_kpad_Minus
207
#define KEYSC_KPPLUS   sc_kpad_Plus
208
#define KEYSC_KPPERIOD sc_kpad_Period
209
 
210
#define KEYSC_EUP        sc_UpArrow
211
#define KEYSC_EDOWN      sc_DownArrow
212
#define KEYSC_ELEFT      sc_LeftArrow
213
#define KEYSC_ERIGHT     sc_RightArrow
214
#define KEYSC_EINS       sc_Insert
215
#define KEYSC_EDEL       sc_Delete
216
#define KEYSC_EHOME      sc_Home
217
#define KEYSC_EEND       sc_End
218
#define KEYSC_EPGUP      sc_PgUp
219
#define KEYSC_EPGDN      sc_PgDn
220
 
221
#undef KB_KeyPressed
222
#define KB_KeyPressed( scan ) \
223
    ( KB_KeyDown[( scan )])
224
#define KEY_PRESSED(sc) KB_KeyPressed((sc))
225
#define PKEY_PRESSED(sc) KB_KeyPressed((sc))
226
 
227
//
228
// NETWORK - REDEFINABLE SHARED (SYNC) KEYS BIT POSITIONS
229
//
230
 
231
// weapons takes up 4 bits
232
#define SK_WEAPON_BIT0 0
233
#define SK_WEAPON_BIT1 1
234
#define SK_WEAPON_BIT2 2
235
#define SK_WEAPON_BIT3 3
236
#define SK_WEAPON_MASK (BIT(SK_WEAPON_BIT0)| \
237
                        BIT(SK_WEAPON_BIT1)| \
238
                        BIT(SK_WEAPON_BIT2)| \
239
                        BIT(SK_WEAPON_BIT3))     // 16 possible numbers 0-15
240
 
241
#define SK_INV_HOTKEY_BIT0 4
242
#define SK_INV_HOTKEY_BIT1 5
243
#define SK_INV_HOTKEY_BIT2 6
244
#define SK_INV_HOTKEY_MASK (BIT(SK_INV_HOTKEY_BIT0)|BIT(SK_INV_HOTKEY_BIT1)|BIT(SK_INV_HOTKEY_BIT2))
245
 
246
#define SK_AUTO_AIM    7
247
#define SK_CENTER_VIEW 8
248
#define SK_PAUSE       9
249
#define SK_RUN_LOCK   10
250
 
251
#define SK_MESSAGE    11
252
#define SK_LOOK_UP    12
253
#define SK_LOOK_DOWN  13
254
#define SK_CRAWL_LOCK 14
255
#define SK_FLY        15
256
 
257
#define SK_RUN        16
258
#define SK_SHOOT      17
259
#define SK_OPERATE    18
260
#define SK_JUMP       19
261
#define SK_CRAWL      20
262
#define SK_SNAP_UP    21
263
#define SK_SNAP_DOWN  22
264
#define SK_QUIT_GAME  23
265
 
266
#define SK_MULTI_VIEW 24
267
 
268
#define SK_TURN_180   25
269
 
270
#define SK_INV_LEFT   26
271
#define SK_INV_RIGHT  27
272
 
273
#define SK_INV_USE   29
274
#define SK_HIDE_WEAPON  30
275
#define SK_SPACE_BAR  31
276
 
277
 
278
// REDEFINABLE PLAYER KEYS NUMBERS
279
 
280
#define PK_FORWARD      0
281
#define PK_BACKWARD     1
282
#define PK_LEFT         2
283
#define PK_RIGHT        3
284
#define PK_RUN          4
285
#define PK_STRAFE       5
286
#define PK_SHOOT        6
287
#define PK_OPERATE      7
288
#define PK_JUMP         8
289
#define PK_CRAWL        9
290
#define PK_LOOK_UP      10
291
#define PK_LOOK_DOWN    11
292
#define PK_STRAFE_LEFT  12
293
#define PK_STRAFE_RIGHT 13
294
#define PK_MAP          14
295
#define PK_MULTI_VIEW   15
296
#define PK_ZOOM_IN      16
297
#define PK_ZOOM_OUT     17
298
#define PK_MESSAGE      18
299
 
300
//    #define PKEY(num) KEY_PRESSED(keys[num])
301
 
5198 hendricks2 302
#define MK_FIXED(msw,lsw) (((int32_t)(msw)<<16)|(lsw))
5196 hendricks2 303
#define FIXED(msw,lsw) MK_FIXED(msw,lsw)
304
 
305
#if B_LITTLE_ENDIAN != 0
5198 hendricks2 306
# define MSW_VAR(fixed) (*(((uint16_t*)&(fixed)) + 1))
307
# define LSW_VAR(fixed) (*((uint16_t*)&(fixed)))
5196 hendricks2 308
 
5198 hendricks2 309
# define MSB_VAR(fixed) (*(((uint8_t*)&(fixed)) + 1))
310
# define LSB_VAR(fixed) (*((uint8_t*)&(fixed)))
5196 hendricks2 311
#else
5198 hendricks2 312
# define LSW_VAR(fixed) (*(((uint16_t*)&(fixed)) + 1))
313
# define MSW_VAR(fixed) (*((uint16_t*)&(fixed)))
5196 hendricks2 314
 
5198 hendricks2 315
# define LSB_VAR(fixed) (*(((uint8_t*)&(fixed)) + 1))
316
# define MSB_VAR(fixed) (*((uint8_t*)&(fixed)))
5196 hendricks2 317
#endif
318
 
319
#define MSW(fixed) ((fixed)>>16)
5198 hendricks2 320
#define LSW(fixed) (((int16_t)(fixed)))
5196 hendricks2 321
 
322
// Defines for reading in ST1 sprite tagging
323
#define SP_TAG1(sp) ((sp)->hitag)
324
#define SP_TAG2(sp) ((sp)->lotag)
325
#define SP_TAG3(sp) ((sp)->clipdist)
326
#define SP_TAG4(sp) ((sp)->ang)
327
#define SP_TAG5(sp) ((sp)->xvel)
328
#define SP_TAG6(sp) ((sp)->yvel)
329
#define SP_TAG7(sp) (MSB_VAR((sp)->zvel))
330
#define SP_TAG8(sp) (LSB_VAR((sp)->zvel))
331
#define SP_TAG9(sp) (MSB_VAR((sp)->owner))
332
#define SP_TAG10(sp) (LSB_VAR((sp)->owner))
333
#define SP_TAG11(sp) ((sp)->shade)
334
#define SP_TAG12(sp) ((sp)->pal)
335
#define SP_TAG13(sp) B_LITTLE16(*((short*)&(sp)->xoffset))
336
#define SP_TAG14(sp) B_LITTLE16(*((short*)&(sp)->xrepeat))
337
#define SP_TAG15(sp) ((sp)->z)
338
#define SET_SP_TAG13(sp,val) (*((short*)&(sp)->xoffset)) = B_LITTLE16(val)
339
#define SET_SP_TAG14(sp,val) (*((short*)&(sp)->xrepeat)) = B_LITTLE16(val)
340
 
341
#define SPRITE_TAG1(sp) (sprite[sp].hitag)
342
#define SPRITE_TAG2(sp) (sprite[sp].lotag)
343
#define SPRITE_TAG3(sp) (sprite[sp].clipdist)
344
#define SPRITE_TAG4(sp) (sprite[sp].ang)
345
#define SPRITE_TAG5(sp) (sprite[sp].xvel)
346
#define SPRITE_TAG6(sp) (sprite[sp].yvel)
347
#define SPRITE_TAG7(sp) (MSB_VAR(sprite[sp].zvel))
348
#define SPRITE_TAG8(sp) (LSB_VAR(sprite[sp].zvel))
349
#define SPRITE_TAG9(sp) (MSB_VAR(sprite[sp].owner))
350
#define SPRITE_TAG10(sp) (LSB_VAR(sprite[sp].owner))
351
#define SPRITE_TAG11(sp) (sprite[sp].shade)
352
#define SPRITE_TAG12(sp) (sprite[sp].pal)
353
#define SPRITE_TAG13(sp) B_LITTLE16(*((short*)&sprite[sp].xoffset))
354
#define SPRITE_TAG14(sp) B_LITTLE16(*((short*)&sprite[sp].xrepeat))
355
#define SPRITE_TAG15(sp) (sprite[sp].z)
356
#define SET_SPRITE_TAG13(sp,val) (*((short*)&sprite[sp].xoffset)) = B_LITTLE16(val)
357
#define SET_SPRITE_TAG14(sp,val) (*((short*)&sprite[sp].xrepeat)) = B_LITTLE16(val)
358
 
359
// OVER and UNDER water macros
360
#define SpriteInDiveArea(sp) (TEST(sector[(sp)->sectnum].extra, SECTFX_DIVE_AREA) ? TRUE : FALSE)
361
#define SpriteInUnderwaterArea(sp) (TEST(sector[(sp)->sectnum].extra, SECTFX_UNDERWATER|SECTFX_UNDERWATER2) ? TRUE : FALSE)
362
 
363
#define SectorIsDiveArea(sect) (TEST(sector[sect].extra, SECTFX_DIVE_AREA) ? TRUE : FALSE)
364
#define SectorIsUnderwaterArea(sect) (TEST(sector[sect].extra, SECTFX_UNDERWATER|SECTFX_UNDERWATER2) ? TRUE : FALSE)
365
 
366
// Key Press Flags macros
367
#define FLAG_KEY_PRESSED(pp,sync_key) TEST(pp->KeyPressFlags,1<<sync_key)
368
#define FLAG_KEY_RELEASE(pp,sync_key) RESET(pp->KeyPressFlags,1<<sync_key)
369
#define FLAG_KEY_RESET(pp,sync_key) SET(pp->KeyPressFlags,1<<sync_key)
370
 
371
// syncbit manipulation macros
372
// key_test MUST be a boolean - force it to be
373
#define SET_SYNC_KEY(player, sync_num, key_test) SET((player)->input.bits, ((!!(key_test)) << (sync_num)))
374
#define TEST_SYNC_KEY(player, sync_num) TEST((player)->input.bits, (1 << (sync_num)))
375
#define RESET_SYNC_KEY(player, sync_num) RESET((player)->input.bits, (1 << (sync_num)))
376
 
8347 hendricks2 377
#define TRAVERSE_SPRITE_SECT(l, o, n)    for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritesect[o], (o) != -1; (o) = (n))
378
#define TRAVERSE_SPRITE_STAT(l, o, n)    for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritestat[o], (o) != -1; (o) = (n))
5196 hendricks2 379
#define TRAVERSE_CONNECT(i)   for (i = connecthead; i != -1; i = connectpoint2[i])
380
 
381
 
382
#define NORM_ANGLE(ang) ((ang) & 2047)
383
#define ANGLE_2_PLAYER(pp,x,y) (NORM_ANGLE(getangle(pp->posx-(x), pp->posy-(y))))
384
 
385
 
386
int StdRandomRange(int range);
387
#define STD_RANDOM_P2(pwr_of_2) (MOD_P2(rand(),(pwr_of_2)))
388
#define STD_RANDOM_RANGE(range) (StdRandomRange(range))
389
#define STD_RANDOM() (rand())
390
 
8798 ny00123 391
#if 0
392
// TODO: PedanticMode
393
#define RANDOM_NEG(x,y) (PedanticMode \
394
                        ? ((RANDOM_P2(((x)<<(y))<<1) -  (x))<<(y)) \
395
                        :  (RANDOM_P2(((x)<<(y))<<1) - ((x) <<(y))))
396
#else
397
#define RANDOM_NEG(x,y) ((RANDOM_P2(((x)<<(y))<<1) - (x))<<(y))
398
#endif
399
 
5196 hendricks2 400
#define MOVEx(vel,ang) (((int)(vel) * (int)sintable[NORM_ANGLE((ang) + 512)]) >> 14)
401
#define MOVEy(vel,ang) (((int)(vel) * (int)sintable[NORM_ANGLE((ang))]) >> 14)
402
 
403
#define DIST(x1, y1, x2, y2) ksqrt( SQ((x1) - (x2)) + SQ((y1) - (y2)) )
404
 
5204 hendricks2 405
#define PIC_SIZX(sn) (tilesiz[sprite[sn].picnum].x)
406
#define PIC_SIZY(sn) (tilesiz[sprite[sn].picnum].y)
5196 hendricks2 407
 
408
// Distance macro - tx, ty, tmin are holding vars that must be declared in the routine
409
// that uses this macro
410
#define DISTANCE(x1, y1, x2, y2, dist, tx, ty, tmin) \
411
    {                                    \
412
        tx = labs(x2-x1);                    \
413
        ty = labs(y2-y1);                    \
414
        tmin = min(tx,ty);                   \
415
        dist = tx + ty - DIV2(tmin);         \
416
    }
417
 
418
#define SPRITE_SIZE_X(sp_num)   ((sprite[sp_num].xrepeat == 64) ?                         \
5204 hendricks2 419
                                 tilesiz[sprite[sp_num].picnum].x :                   \
420
                                 ((sprite[sp_num].xrepeat * tilesiz[sprite[sp_num].picnum].x) >> 6) \
5196 hendricks2 421
                                 )
422
 
423
#define SPRITE_SIZE_Y(sp_num)   ((sprite[sp_num].yrepeat == 64) ?                          \
5204 hendricks2 424
                                 tilesiz[sprite[sp_num].picnum].y :                    \
425
                                 ((sprite[sp_num].yrepeat * tilesiz[sprite[sp_num].picnum].y) >> 6) \
5196 hendricks2 426
                                 )
427
 
428
#define SPRITE_SIZE_Z(sp_num)   ((sprite[sp_num].yrepeat == 64) ?                          \
5204 hendricks2 429
                                 Z(tilesiz[sprite[sp_num].picnum].y) :                 \
430
                                 ((sprite[sp_num].yrepeat * tilesiz[sprite[sp_num].picnum].y) << 2) \
5196 hendricks2 431
                                 )
432
 
433
#define SPRITEp_SIZE_X(sp)   (((sp)->xrepeat == 64) ?                         \
5204 hendricks2 434
                              tilesiz[(sp)->picnum].x :                   \
435
                              (((sp)->xrepeat * tilesiz[(sp)->picnum].x) >> 6) \
5196 hendricks2 436
                              )
437
 
438
#define SPRITEp_SIZE_Y(sp)   (((sp)->yrepeat == 64) ?                          \
5204 hendricks2 439
                              tilesiz[(sp)->picnum].y :                    \
440
                              (((sp)->yrepeat * tilesiz[(sp)->picnum].y) >> 6) \
5196 hendricks2 441
                              )
442
 
443
#define SPRITEp_SIZE_Z(sp)   (((sp)->yrepeat == 64) ?                          \
5204 hendricks2 444
                              Z(tilesiz[(sp)->picnum].y) :                 \
445
                              (((sp)->yrepeat * tilesiz[(sp)->picnum].y) << 2) \
5196 hendricks2 446
                              )
447
 
448
// Given a z height and sprite return the correct x repeat value
5204 hendricks2 449
#define SPRITEp_SIZE_X_2_XREPEAT(sp, x) (((x)*64)/tilesiz[(sp)->picnum].x)
5196 hendricks2 450
// Given a z height and sprite return the correct y repeat value
5204 hendricks2 451
#define SPRITEp_SIZE_Z_2_YREPEAT(sp, zh) ((zh)/(4*tilesiz[(sp)->picnum].y))
452
#define SPRITEp_SIZE_Y_2_YREPEAT(sp, y) (((y)*64)/tilesiz[(sp)->picnum].y)
5196 hendricks2 453
 
454
 
455
// x & y offset of tile
5203 hendricks2 456
#define TILE_XOFF(picnum) (picanm[(picnum)].xofs)
457
#define TILE_YOFF(picnum) (picanm[(picnum)].yofs)
5196 hendricks2 458
 
459
// x & y offset of current sprite tile
5203 hendricks2 460
#define SPRITEp_XOFF(sp) (picanm[(sp)->picnum].xofs)
461
#define SPRITEp_YOFF(sp) (picanm[(sp)->picnum].yofs)
5196 hendricks2 462
 
463
// Z size of top (TOS) and bottom (BOS) part of sprite
464
#define SPRITEp_SIZE_TOS(sp) (DIV2(SPRITEp_SIZE_Z(sp)) + Z(SPRITEp_YOFF(sp)))
465
#define SPRITEp_SIZE_BOS(sp) (DIV2(SPRITEp_SIZE_Z(sp)) - Z(SPRITEp_YOFF(sp)))
466
 
6657 pogokeen 467
// actual Z for TOS and BOS - handles both WYSIWYG and old style
5196 hendricks2 468
#define SPRITEp_TOS(sp) (TEST((sp)->cstat, CSTAT_SPRITE_YCENTER) ? \
469
                         ((sp)->z - SPRITEp_SIZE_TOS(sp)) :         \
470
                         ((sp)->z - SPRITEp_SIZE_Z(sp)))
471
 
472
#define SPRITEp_BOS(sp) (TEST((sp)->cstat, CSTAT_SPRITE_YCENTER) ? \
473
                         ((sp)->z + SPRITEp_SIZE_BOS(sp)) :         \
474
                         (sp)->z)
475
 
6657 pogokeen 476
// mid and upper/lower sprite calculations
5196 hendricks2 477
#define SPRITEp_MID(sp) (DIV2(SPRITEp_TOS(sp) + SPRITEp_BOS(sp)))
478
#define SPRITEp_UPPER(sp) (SPRITEp_TOS(sp) + DIV4(SPRITEp_SIZE_Z(sp)))
479
#define SPRITEp_LOWER(sp) (SPRITEp_BOS(sp) - DIV4(SPRITEp_SIZE_Z(sp)))
480
 
481
#define Z(value) ((int)(value) << 8)
482
#define PIXZ(value) ((int)(value) >> 8)
483
 
484
#define SQ(val) ((val) * (val))
485
 
486
#define KENFACING_PLAYER(pp,sp) (sintable[NORM_ANGLE(sp->ang+512)]*(pp->posy-sp->y) >= sintable[NORM_ANGLE(sp-ang)]*(pp->posx-sp->x))
487
#define FACING_PLAYER(pp,sp) (labs(GetDeltaAngle((sp)->ang, NORM_ANGLE(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y)))) < 512)
488
#define PLAYER_FACING(pp,sp) (labs(GetDeltaAngle((pp)->pang, NORM_ANGLE(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy)))) < 320)
489
#define FACING(sp1,sp2) (labs(GetDeltaAngle((sp2)->ang, NORM_ANGLE(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y)))) < 512)
490
 
491
#define FACING_PLAYER_RANGE(pp,sp,range) (labs(GetDeltaAngle((sp)->ang, NORM_ANGLE(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y)))) < (range))
492
#define PLAYER_FACING_RANGE(pp,sp,range) (labs(GetDeltaAngle((pp)->pang, NORM_ANGLE(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy)))) < (range))
493
#define FACING_RANGE(sp1,sp2,range) (labs(GetDeltaAngle((sp2)->ang, NORM_ANGLE(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y)))) < (range))
494
 
495
// two vectors
496
// can determin direction
6254 hendricks2 497
#define DOT_PRODUCT_2D(x1,y1,x2,y2) (mulscale16((x1), (x2)) + mulscale16((y1), (y2)))
498
#define DOT_PRODUCT_3D(x1,y1,z1,x2,y2,z2) (mulscale16((x1), (x2)) + mulscale16((y1), (y2)) + mulscale16((z1), (z2)))
5196 hendricks2 499
 
500
// just determine if the player is moving
501
#define PLAYER_MOVING(pp) ((pp)->xvect|(pp)->yvect)
502
 
503
#define KEY_EXT(scan) (KEY_PRESSED(scan) | KEY_PRESSED(scan+128))
504
 
505
#define TEST_GOTSECTOR(sect_num) (TEST(gotsector[(sect_num) >> 3], 1 << ((sect_num) & 7)))
506
#define RESET_GOTSECTOR(sect_num) (RESET(gotsector[(sect_num) >> 3], 1 << ((sect_num) & 7)))
507
#define SET_GOTSECTOR(sect_num) (SET(gotsector[(sect_num) >> 3], 1 << ((sect_num) & 7)))
508
 
509
#define TEST_GOTPIC(tile_num) (TEST(gotpic[(tile_num) >> 3], 1 << ((tile_num) & 7)))
510
#define RESET_GOTPIC(tile_num) (RESET(gotpic[(tile_num) >> 3], 1 << ((tile_num) & 7)))
511
#define SET_GOTPIC(tile_num) (SET(gotpic[(tile_num) >> 3], 1 << ((tile_num) & 7)))
512
 
513
#define LOW_TAG(sectnum) ( sector[sectnum].lotag )
514
#define HIGH_TAG(sectnum) ( sector[sectnum].hitag )
515
 
516
#define LOW_TAG_SPRITE(spnum) ( sprite[(spnum)].lotag )
517
#define HIGH_TAG_SPRITE(spnum) ( sprite[(spnum)].hitag )
518
 
519
#define LOW_TAG_WALL(wallnum) ( wall[(wallnum)].lotag )
520
#define HIGH_TAG_WALL(wallnum) ( wall[(wallnum)].hitag )
521
 
522
#define SEC(value) ((value)*120)
523
 
524
#define CEILING_DIST (Z(4))
525
#define FLOOR_DIST (Z(4))
526
 
527
// Attributes for monochrome text
528
#define MDA_BLANK          0x00
529
#define MDA_NORMAL         0x07
530
#define MDA_BLINK          0x87
531
#define MDA_HIGH           0x0F
532
#define MDA_HIGHBLINK      0x8F
533
#define MDA_UNDER          0x01
534
#define MDA_UNDERBLINK     0x81
535
#define MDA_UNDERHIGH      0x09
536
#define MDA_UNDERHIGHBLINK 0x89
537
#define MDA_REVERSE        0x70
538
#define MDA_REVERSEBLINK   0xF0
539
 
540
// defines for move_sprite return value
8350 hendricks2 541
#define HIT_MASK (BIT(14)|BIT(15)|BIT(16))
5196 hendricks2 542
#define HIT_SPRITE (BIT(14)|BIT(15))
543
#define HIT_WALL   BIT(15)
544
#define HIT_SECTOR BIT(14)
8350 hendricks2 545
#define HIT_PLAX_WALL BIT(16)
5196 hendricks2 546
 
6825 hendricks2 547
#define NORM_SPRITE(val) ((val) & (MAXSPRITES - 1))
548
#define NORM_WALL(val) ((val) & (MAXWALLS - 1))
549
#define NORM_SECTOR(val) ((val) & (MAXSECTORS - 1))
5196 hendricks2 550
 
6825 hendricks2 551
EDUKE32_STATIC_ASSERT(isPow2(MAXSPRITES));
552
EDUKE32_STATIC_ASSERT(isPow2(MAXWALLS));
553
EDUKE32_STATIC_ASSERT(isPow2(MAXSECTORS));
554
 
5196 hendricks2 555
// overwritesprite flags
556
#define OVER_SPRITE_MIDDLE      (BIT(0))
557
#define OVER_SPRITE_VIEW_CLIP   (BIT(1))
558
#define OVER_SPRITE_TRANSLUCENT (BIT(2))
559
#define OVER_SPRITE_XFLIP       (BIT(3))
560
#define OVER_SPRITE_YFLIP       (BIT(4))
561
 
562
// rotatesprite flags
563
#define ROTATE_SPRITE_TRANSLUCENT   (BIT(0))
564
#define ROTATE_SPRITE_VIEW_CLIP     (BIT(1)) // clip to view
565
#define ROTATE_SPRITE_YFLIP         (BIT(2))
566
#define ROTATE_SPRITE_IGNORE_START_MOST (BIT(3)) // don't clip to startumost
567
#define ROTATE_SPRITE_SCREEN_CLIP   (BIT(1)|BIT(3)) // use window
568
#define ROTATE_SPRITE_CORNER        (BIT(4)) // place sprite from upper left corner
569
#define ROTATE_SPRITE_TRANS_FLIP    (BIT(5))
570
#define ROTATE_SPRITE_NON_MASK      (BIT(6)) // non masked sprites
571
#define ROTATE_SPRITE_ALL_PAGES     (BIT(7)) // copies to all pages
572
 
573
#define RS_SCALE                    BIT(16)
574
 
575
// system defines for status bits
576
#define CEILING_STAT_PLAX           BIT(0)
577
#define CEILING_STAT_SLOPE          BIT(1)
578
#define CEILING_STAT_SWAPXY         BIT(2)
579
#define CEILING_STAT_SMOOSH         BIT(3)
580
#define CEILING_STAT_XFLIP          BIT(4)
581
#define CEILING_STAT_YFLIP          BIT(5)
582
#define CEILING_STAT_RELATIVE       BIT(6)
583
#define CEILING_STAT_TYPE_MASK     (BIT(7)|BIT(8))
584
#define CEILING_STAT_MASKED         BIT(7)
585
#define CEILING_STAT_TRANS          BIT(8)
586
#define CEILING_STAT_TRANS_FLIP     (BIT(7)|BIT(8))
587
#define CEILING_STAT_FAF_BLOCK_HITSCAN      BIT(15)
588
 
589
#define FLOOR_STAT_PLAX           BIT(0)
590
#define FLOOR_STAT_SLOPE          BIT(1)
591
#define FLOOR_STAT_SWAPXY         BIT(2)
592
#define FLOOR_STAT_SMOOSH         BIT(3)
593
#define FLOOR_STAT_XFLIP          BIT(4)
594
#define FLOOR_STAT_YFLIP          BIT(5)
595
#define FLOOR_STAT_RELATIVE       BIT(6)
596
#define FLOOR_STAT_TYPE_MASK     (BIT(7)|BIT(8))
597
#define FLOOR_STAT_MASKED         BIT(7)
598
#define FLOOR_STAT_TRANS          BIT(8)
599
#define FLOOR_STAT_TRANS_FLIP     (BIT(7)|BIT(8))
600
#define FLOOR_STAT_FAF_BLOCK_HITSCAN      BIT(15)
601
 
602
#define CSTAT_WALL_BLOCK            BIT(0)
603
#define CSTAT_WALL_BOTTOM_SWAP      BIT(1)
604
#define CSTAT_WALL_ALIGN_BOTTOM     BIT(2)
605
#define CSTAT_WALL_XFLIP            BIT(3)
606
#define CSTAT_WALL_MASKED           BIT(4)
607
#define CSTAT_WALL_1WAY             BIT(5)
608
#define CSTAT_WALL_BLOCK_HITSCAN    BIT(6)
609
#define CSTAT_WALL_TRANSLUCENT      BIT(7)
610
#define CSTAT_WALL_YFLIP            BIT(8)
611
#define CSTAT_WALL_TRANS_FLIP       BIT(9)
612
#define CSTAT_WALL_BLOCK_ACTOR (BIT(14)) // my def
613
#define CSTAT_WALL_WARP_HITSCAN (BIT(15)) // my def
614
 
615
//cstat, bit 0: 1 = Blocking sprite (use with clipmove, getzrange)    "B"
616
//       bit 1: 1 = 50/50 transluscence, 0 = normal                   "T"
617
//       bit 2: 1 = x-flipped, 0 = normal                             "F"
618
//       bit 3: 1 = y-flipped, 0 = normal                             "F"
619
//       bits 5-4: 00 = FACE sprite (default)                         "R"
620
//                 01 = WALL sprite (like masked walls)
621
//                 10 = FLOOR sprite (parallel to ceilings&floors)
622
//                 11 = SPIN sprite (face sprite that can spin 2draw style - not done yet)
623
//       bit 6: 1 = 1-sided sprite, 0 = normal                        "1"
624
//       bit 7: 1 = Real centered centering, 0 = foot center          "C"
625
//       bit 8: 1 = Blocking sprite (use with hitscan)                "H"
626
//       bit 9: reserved
627
//       bit 10: reserved
628
//       bit 11: reserved
629
//       bit 12: reserved
630
//       bit 13: reserved
631
//       bit 14: reserved
632
//       bit 15: 1 = Invisible sprite, 0 = not invisible
633
#define CSTAT_SPRITE_RESTORE        BIT(12) // my def
634
#define CSTAT_SPRITE_CLOSE_FLOOR    BIT(13) // my def - tells whether a sprite
635
// started out close to a ceiling or floor
636
#define CSTAT_SPRITE_BLOCK_MISSILE  BIT(14) // my def
637
 
638
#define CSTAT_SPRITE_BREAKABLE (CSTAT_SPRITE_BLOCK_HITSCAN|CSTAT_SPRITE_BLOCK_MISSILE)
639
 
640
#undef CLIPMASK0 // defined in build.h
641
#undef CLIPMASK1
642
 
643
// new define more readable defines
644
 
645
// Clip Sprite adjustment
646
#define CS(sprite_bit) ((sprite_bit)<<16)
647
 
648
// for players to clip against walls
649
#define CLIPMASK_PLAYER (CS(CSTAT_SPRITE_BLOCK) | CSTAT_WALL_BLOCK)
650
 
651
// for actors to clip against walls
652
#define CLIPMASK_ACTOR                   \
653
    (                                    \
6657 pogokeen 654
        CS(CSTAT_SPRITE_BLOCK) |          \
5196 hendricks2 655
        CSTAT_WALL_BLOCK |                   \
656
        CSTAT_WALL_BLOCK_ACTOR               \
657
    )
658
 
659
// for missiles to clip against actors
660
#define CLIPMASK_MISSILE                                            \
661
    (                                                               \
662
        CS(CSTAT_SPRITE_BLOCK_HITSCAN|CSTAT_SPRITE_BLOCK_MISSILE) |     \
663
        CSTAT_WALL_BLOCK_HITSCAN                                        \
664
    )
665
 
666
#define CLIPMASK_WARP_HITSCAN            \
667
    (                                    \
668
        CS(CSTAT_SPRITE_BLOCK_HITSCAN) |     \
669
        CSTAT_WALL_BLOCK_HITSCAN |           \
670
        CSTAT_WALL_WARP_HITSCAN              \
671
    )
672
 
673
 
6067 hendricks2 674
#define SIZ ARRAY_SIZE
5196 hendricks2 675
 
676
 
677
//
678
// Directions
679
//
680
 
681
#define DEGREE_45 256
682
#define DEGREE_90 512
683
 
684
////
685
//
686
// Directional enumerations
687
//
688
////
689
 
690
enum DirOrd
691
{
692
    ORD_NORTH, ORD_NE, ORD_EAST, ORD_SE, ORD_SOUTH, ORD_SW, ORD_WEST, ORD_NW
693
};
694
 
695
enum Dir8
696
{
697
    NORTH   = ORD_NORTH * DEGREE_45,
698
    NE      = ORD_NE    * DEGREE_45,
699
    EAST    = ORD_EAST  * DEGREE_45,
700
    SE      = ORD_SE    * DEGREE_45,
701
    SOUTH   = ORD_SOUTH * DEGREE_45,
702
    SW      = ORD_SW    * DEGREE_45,
703
    WEST    = ORD_WEST  * DEGREE_45,
704
    NW      = ORD_NW    * DEGREE_45,
705
};
706
 
707
typedef enum Dir8 DIR8;
708
 
709
// Auto building enumerations
710
 
711
#define DIGI_ENUM
712
enum digi
713
{
714
#include "digi.h"
715
    DIGI_MAX
716
};
717
#undef DIGI_ENUM
718
 
719
#define DAMAGE_ENUM
720
enum dam
721
{
722
#include "damage.h"
723
};
724
#undef DAMAGE_ENUM
725
 
726
////
727
//
728
// State declarations
729
//
730
////
731
 
732
 
733
// Forward declarations
734
struct STATEstruct;
735
typedef struct STATEstruct STATE, *STATEp, * *STATEpp;
736
 
737
//struct PIC_STATEstruct;
738
//typedef struct PIC_STATEstruct PIC_STATE, *PIC_STATEp;
739
 
740
struct PANEL_STATEstruct;
741
typedef struct PANEL_STATEstruct PANEL_STATE, *PANEL_STATEp;
742
 
743
struct PLAYERstruct;
744
typedef struct PLAYERstruct PLAYER, *PLAYERp;
745
 
746
struct PERSONALITYstruct;
747
typedef struct PERSONALITYstruct PERSONALITY, *PERSONALITYp;
748
 
749
struct ATTRIBUTEstruct;
750
typedef struct ATTRIBUTEstruct ATTRIBUTE, *ATTRIBUTEp;
751
 
752
struct SECTOR_OBJECTstruct;
753
typedef struct SECTOR_OBJECTstruct SECTOR_OBJECT, *SECTOR_OBJECTp;
754
 
755
struct PANEL_SPRITEstruct;
756
typedef struct PANEL_SPRITEstruct PANEL_SPRITE, *PANEL_SPRITEp;
757
 
758
struct ANIMstruct;
759
typedef struct ANIMstruct ANIM, *ANIMp;
760
 
5198 hendricks2 761
typedef int ANIMATOR (int16_t SpriteNum);
5196 hendricks2 762
typedef ANIMATOR *ANIMATORp;
763
 
764
typedef void pANIMATOR (PANEL_SPRITEp);
765
typedef pANIMATOR *pANIMATORp;
766
 
767
typedef void soANIMATOR (SECTOR_OBJECTp);
768
typedef soANIMATOR *soANIMATORp;
769
 
770
typedef spritetype SPRITE, *SPRITEp;
771
typedef sectortype SECTOR, *SECTORp;
772
typedef walltype WALL, *WALLp;
773
 
774
struct STATEstruct
775
{
776
    short     Pic;
777
    int       Tics;
778
    ANIMATORp Animator;
779
 
780
    STATEp   NextState;
781
};
782
 
783
//
784
// State Flags
785
//
786
 
787
#define SF_TICS_MASK 0xFFFF
788
#define SF_QUICK_CALL BIT(16)
789
#define SF_PLAYER_FUNC BIT(17) // only for players to execute
790
#define SF_TIC_ADJUST BIT(18) // use tic adjustment for these frames
791
#define SF_WALL_STATE BIT(19) // use for walls instead of sprite
792
 
793
///////////////////////////////////////////////////////////////////////////////
794
// Jim's MISC declarations from other files
795
///////////////////////////////////////////////////////////////////////////////
796
 
797
typedef enum {WATER_FOOT, BLOOD_FOOT} FOOT_TYPE;
798
 
799
extern FOOT_TYPE FootMode;
5198 hendricks2 800
extern SWBOOL InGame;                                  // Declared in game.c
801
extern SWBOOL Global_PLock;                            // Game.c
5202 hendricks2 802
int QueueFloorBlood(short hit_sprite);                // Weapon.c
803
int QueueFootPrint(short hit_sprite);                 // Weapon.c
5196 hendricks2 804
int QueueGeneric(short SpriteNum, short pic);        // Weapon.c
805
int QueueLoWangs(short SpriteNum);                   // Weapon.c
806
int SpawnShell(short SpriteNum, short ShellNum);     // Weapon.c
5202 hendricks2 807
void UnlockKeyLock(short key_num, short hit_sprite);  // JSector.c
5196 hendricks2 808
 
809
#define MAX_PAIN 5
810
extern int PlayerPainVocs[MAX_PAIN];
811
extern int PlayerLowHealthPainVocs[MAX_PAIN];
812
 
813
#define MAX_TAUNTAI 33
814
extern int TauntAIVocs[MAX_TAUNTAI];
815
 
816
#define MAX_GETSOUNDS 5
817
extern int PlayerGetItemVocs[MAX_GETSOUNDS];
818
 
819
#define MAX_YELLSOUNDS 3
820
extern int PlayerYellVocs[MAX_YELLSOUNDS];
821
 
5198 hendricks2 822
void BossHealthMeter(void);
5196 hendricks2 823
 
824
// Global variables used for modifying variouse things from the Console
825
 
826
///////////////////////////////////////////////////////////////////////////////////////////
827
//
828
// CALLER - DLL handler
829
//
830
///////////////////////////////////////////////////////////////////////////////////////////
831
extern unsigned char DLL_Loaded;
832
extern int DLL_Handle; // Global DLL handle
833
extern char *DLL_path; // DLL path name
834
 
835
int DLL_Load(char *DLLpathname);
5198 hendricks2 836
SWBOOL DLL_Unload(int procHandle);
837
SWBOOL DLL_ExecFunc(int procHandle, char *fName);
5196 hendricks2 838
 
839
///////////////////////////////////////////////////////////////////////////////////////////
840
//
841
// JPlayer
842
//
843
///////////////////////////////////////////////////////////////////////////////////////////
844
#define MESSAGE_LINE 142    // Used to be 164
845
#define MAXUSERQUOTES 6
846
#define MAXCONQUOTES 13
847
 
848
extern int quotebot, quotebotgoal;
849
extern short user_quote_time[MAXUSERQUOTES];
850
extern char user_quote[MAXUSERQUOTES][256];
851
 
852
extern int conbot, conbotgoal;
853
extern char con_quote[MAXCONQUOTES][256];
854
 
855
int minitext(int x,int y,char *t,char p,char sb);
856
int minitextshade(int x,int y,char *t,char s,char p,char sb);
857
void operatefta(void);
7499 hendricks2 858
void adduserquote(const char *daquote);
5196 hendricks2 859
void operateconfta(void);
860
void addconquote(char *daquote);
861
 
862
///////////////////////////////////////////////////////////////////////////////////////////
863
//
864
// Console
865
//
866
///////////////////////////////////////////////////////////////////////////////////////////
867
void CON_Message(const char *message, ...) PRINTF_FORMAT(1, 2);
868
void CON_ConMessage(const char *message, ...) PRINTF_FORMAT(1, 2);
869
void CON_StoreArg(const char *userarg);
5198 hendricks2 870
SWBOOL CON_CheckParm(const char *userarg);
5196 hendricks2 871
void CON_CommandHistory(signed char dir);
5198 hendricks2 872
SWBOOL CON_AddCommand(const char *command, void (*function)(void));
5196 hendricks2 873
void CON_ProcessUserCommand(void);
874
void CON_InitConsole(void);
8750 ny00123 875
void CON_Quit(void);
5196 hendricks2 876
 
877
///////////////////////////////////////////////////////////////////////////////////////////
878
//
879
// Weapon
880
//
881
///////////////////////////////////////////////////////////////////////////////////////////
882
 
883
#define MAX_WEAPONS_KEYS 10
884
#define MAX_WEAPONS_EXTRA 4 // extra weapons like the two extra head attacks
885
#define MAX_WEAPONS (MAX_WEAPONS_KEYS + MAX_WEAPONS_EXTRA)
886
 
887
// weapons that not missile type sprites
888
#define WPN_NM_LAVA (-8)
889
#define WPN_NM_SECTOR_SQUISH (-9)
890
 
891
//#define WEAP_ENTRY(id, init_func, damage_lo, damage_hi, radius)
892
 
893
typedef struct
894
{
5198 hendricks2 895
    void (*Init)(PLAYERp);
896
    int16_t damage_lo;
897
    int16_t damage_hi;
5196 hendricks2 898
    unsigned int radius;
5198 hendricks2 899
    int16_t max_ammo;
900
    int16_t min_ammo;
901
    int16_t with_weapon;
7499 hendricks2 902
    const char *weapon_name;
903
    const char *ammo_name;
5198 hendricks2 904
    int16_t weapon_pickup;
905
    int16_t ammo_pickup;
5196 hendricks2 906
} DAMAGE_DATA, *DAMAGE_DATAp;
907
 
908
extern DAMAGE_DATA DamageData[];
909
 
910
// bit arrays that determine if a) Weapon has no ammo b) Weapon is the ammo (no weapon exists)
911
extern int WeaponHasNoAmmo, WeaponIsAmmo;
912
 
913
 
5198 hendricks2 914
void InitWeaponFist(PLAYERp);
915
void InitWeaponStar(PLAYERp);
916
void InitWeaponShotgun(PLAYERp);
917
void InitWeaponRocket(PLAYERp);
918
void InitWeaponRail(PLAYERp);
919
void InitWeaponMicro(PLAYERp);
920
void InitWeaponUzi(PLAYERp);
921
void InitWeaponSword(PLAYERp);
922
void InitWeaponHothead(PLAYERp);
923
void InitWeaponElectro(PLAYERp);
924
void InitWeaponHeart(PLAYERp);
925
void InitWeaponGrenade(PLAYERp);
926
void InitWeaponMine(PLAYERp);
5196 hendricks2 927
 
5198 hendricks2 928
void InitWeaponNapalm(PLAYERp);
929
void InitWeaponRing(PLAYERp);
5196 hendricks2 930
 
5198 hendricks2 931
extern void (*InitWeapon[MAX_WEAPONS]) (PLAYERp);
5196 hendricks2 932
 
933
///////////////////////////////////////////////////////////////////////////////////////////
934
//
935
// Player
936
//
937
///////////////////////////////////////////////////////////////////////////////////////////
938
 
939
#define MAX_SW_PLAYERS_SW  (4)
940
#define MAX_SW_PLAYERS_REG (8)
8504 hendricks2 941
#define MAX_SW_PLAYERS (SW_SHAREWARE ? MAX_SW_PLAYERS_SW : MAX_SW_PLAYERS_REG)
5196 hendricks2 942
 
943
typedef struct
944
{
945
    char map_name[16];
946
    char numplayers;
947
    char Episode,Level;
948
    char LevelSong[16];
949
} DEMO_HEADER, *DEMO_HEADERp;
950
 
951
typedef struct
952
{
953
    int x,y,z;
954
} DEMO_START_POS, *DEMO_START_POSp;
955
 
956
#define MAX_LEVELS_REG 29
957
#define MAX_LEVELS_SW 4
8504 hendricks2 958
#define MAX_LEVELS (SW_SHAREWARE ? MAX_LEVELS_SW : MAX_LEVELS_REG)
5196 hendricks2 959
 
960
typedef struct
961
{
7499 hendricks2 962
    const char *LevelName;
963
    const char *SongName;
964
    const char *Description;
965
    const char *BestTime;
966
    const char *ParTime;
5196 hendricks2 967
} LEVEL_INFO, *LEVEL_INFOp, * *LEVEL_INFOpp;
968
 
969
extern LEVEL_INFO LevelInfo[MAX_LEVELS_REG+2];
970
 
971
#define MAX_EPISODE_NAME_LEN 24
972
extern char EpisodeNames[2][MAX_EPISODE_NAME_LEN+2];    // +2 = leading '^' and trailing NULL
973
 
974
#define MAX_EPISODE_SUBTITLE_LEN 40
975
extern char EpisodeSubtitles[2][MAX_EPISODE_SUBTITLE_LEN+1];
976
 
977
#define MAX_SKILL_NAME_LEN 24
978
extern char SkillNames[4][MAX_SKILL_NAME_LEN+2];
979
 
980
#define MAX_FORTUNES 16
7499 hendricks2 981
extern const char *ReadFortune[MAX_FORTUNES];
5196 hendricks2 982
 
983
#define MAX_KEYS 8
7499 hendricks2 984
extern const char *KeyMsg[MAX_KEYS];
985
extern const char *KeyDoorMessage[MAX_KEYS];
5196 hendricks2 986
 
8792 ny00123 987
// TODO: Support compatible read/write of struct for big-endian
988
#pragma pack(push,1)
5196 hendricks2 989
typedef struct
990
{
5198 hendricks2 991
    int16_t vel;
992
    int16_t svel;
993
    int8_t angvel;
994
    int8_t aimvel;
995
    int32_t bits;
5196 hendricks2 996
} SW_PACKET;
8792 ny00123 997
#pragma pack(pop)
5196 hendricks2 998
 
999
extern SW_PACKET loc;
1000
 
1001
#define PACK 1
1002
 
5198 hendricks2 1003
extern SWBOOL CameraTestMode;
5196 hendricks2 1004
 
1005
enum PlayerDeathTypes
1006
{
1007
    PLAYER_DEATH_FLIP, PLAYER_DEATH_CRUMBLE, PLAYER_DEATH_EXPLODE, PLAYER_DEATH_RIPPER, PLAYER_DEATH_SQUISH, PLAYER_DEATH_DROWN, MAX_PLAYER_DEATHS
1008
};
1009
 
1010
typedef void (*PLAYER_ACTION_FUNCp)(PLAYERp);
1011
 
1012
#include "inv.h"
1013
 
1014
typedef struct
1015
{
1016
    short cursectnum,lastcursectnum,pang,filler;
1017
    int xvect,yvect,oxvect,oyvect,slide_xvect,slide_yvect;
1018
    int posx,posy,posz;
1019
    SECTOR_OBJECTp sop_control;
1020
} REMOTE_CONTROL, *REMOTE_CONTROLp;
1021
 
1022
struct PLAYERstruct
1023
{
1024
    // variable that fit in the sprite or user structure
5201 hendricks2 1025
    int32_t posx, posy, posz;
5196 hendricks2 1026
    // interpolation
1027
    int
1028
        oposx, oposy, oposz;
1029
    short oang;
1030
    short ohoriz;
1031
 
1032
    // holds last valid move position
1033
    short lv_sectnum;
1034
    int lv_x,lv_y,lv_z;
1035
 
1036
    SPRITEp remote_sprite;
1037
    REMOTE_CONTROL remote;
1038
    SECTOR_OBJECTp sop_remote;
1039
    SECTOR_OBJECTp sop;  // will either be sop_remote or sop_control
1040
 
1041
    int jump_count, jump_speed;     // jumping
1042
    short down_speed, up_speed; // diving
1043
    int z_speed,oz_speed; // used for diving and flying instead of down_speed, up_speed
1044
    int climb_ndx;
1045
    int hiz,loz;
1046
    int ceiling_dist,floor_dist;
1047
    SECTORp hi_sectp, lo_sectp;
1048
    SPRITEp hi_sp, lo_sp;
1049
 
1050
    SPRITEp last_camera_sp;
1051
    int camera_dist; // view mode dist
1052
    int circle_camera_dist;
1053
    int six,siy,siz; // save player interp position for PlayerSprite
1054
    short siang;
1055
 
1056
    int xvect, yvect;
1057
    int oxvect, oyvect;
1058
    int friction;
1059
    int slide_xvect, slide_yvect;
1060
    short slide_ang;
1061
    int slide_dec;
1062
    int drive_angvel;
1063
    int drive_oangvel;
1064
 
1065
 
1066
 
1067
    // scroll 2D mode stuff
1068
    int scr_x, scr_y, oscr_x, oscr_y;
1069
    int scr_xvect, scr_yvect;
1070
    short scr_ang, oscr_ang, scr_sectnum;
1071
 
1072
    short view_outside_dang;  // outside view delta ang
1073
    short circle_camera_ang;
1074
    short camera_check_time_delay;
1075
 
1076
    short pang,cursectnum,lastcursectnum;
1077
    short turn180_target; // 180 degree turn
1078
 
1079
    // variables that do not fit into sprite structure
1080
    int horizbase,horiz,horizoff,hvel,tilt,tilt_dest;
1081
    short recoil_amt;
1082
    short recoil_speed;
1083
    short recoil_ndx;
1084
    short recoil_horizoff;
1085
 
1086
    int oldposx,oldposy,oldposz;
1087
    int RevolveX, RevolveY;
1088
    short RevolveDeltaAng, RevolveAng;
1089
 
1090
    // under vars are for wading and swimming
1091
    short PlayerSprite, PlayerUnderSprite;
1092
    SPRITEp SpriteP, UnderSpriteP;
1093
 
1094
 
1095
    short pnum; // carry along the player number
1096
 
1097
    short LadderSector,LadderAngle;
1098
    int lx,ly; // ladder x and y
1099
    short JumpDuration;
1100
    short WadeDepth;
1101
    short bob_amt;
1102
    short bob_ndx;
1103
    short bcnt; // bob count
1104
    int bob_z;
1105
 
1106
    //Multiplayer variables
1107
    SW_PACKET input;
1108
 
1109
    //FIFO queue to hold values while faketimerhandler is called from within the drawing routing
1110
#define MOVEFIFOSIZ 256
1111
    SW_PACKET inputfifo[MOVEFIFOSIZ];
1112
 
1113
 
1114
    int movefifoend;
1115
    int myminlag;
1116
    int syncvalhead;
1117
#define MAXSYNCBYTES 16
1118
    // TENSW: on really bad network connections, the sync FIFO queue can overflow if it is the
1119
    // same size as the move fifo.
1120
#define SYNCFIFOSIZ 1024
5198 hendricks2 1121
    uint8_t syncval[SYNCFIFOSIZ][MAXSYNCBYTES];
5196 hendricks2 1122
 
1123
    // must start out as 0
1124
    int playerreadyflag;
1125
 
1126
    PLAYER_ACTION_FUNCp DoPlayerAction;
1127
    int Flags, Flags2;
1128
    int KeyPressFlags;
1129
 
1130
    SECTOR_OBJECTp sop_control; // sector object pointer
1131
    SECTOR_OBJECTp sop_riding; // sector object pointer
1132
 
1133
    struct
1134
    {
1135
        PANEL_SPRITEp Next, Prev;
1136
    } PanelSpriteList;
1137
 
1138
    // Key stuff
1139
#define NUM_KEYS 8
1140
    unsigned char HasKey[NUM_KEYS];
1141
 
1142
    // Weapon stuff
1143
    short SwordAng;
1144
    int WpnGotOnceFlags; // for no respawn mode where weapons are allowed grabbed only once
1145
    int WpnFlags;
1146
    short WpnAmmo[MAX_WEAPONS];
1147
    short WpnNum;
1148
    PANEL_SPRITEp CurWpn;
1149
    PANEL_SPRITEp Wpn[MAX_WEAPONS];
1150
    PANEL_SPRITEp Chops;
1151
    unsigned char WpnRocketType; // rocket type
1152
    unsigned char WpnRocketHeat; // 5 to 0 range
1153
    unsigned char WpnRocketNuke; // 1, you have it, or you don't
1154
    unsigned char WpnFlameType; // Guardian weapons fire
1155
    unsigned char WpnFirstType; // First weapon type - Sword/Shuriken
1156
    unsigned char WeaponType; // for weapons with secondary functions
1157
    short FirePause; // for sector objects - limits rapid firing
1158
    //
1159
    // Inventory Vars
1160
    //
1161
    short InventoryNum;
1162
    short InventoryBarTics;
1163
    PANEL_SPRITEp InventorySprite[MAX_INVENTORY];
1164
    PANEL_SPRITEp InventorySelectionBox;
1165
    PANEL_SPRITEp MiniBarHealthBox, MiniBarAmmo;
1166
    PANEL_SPRITEp MiniBarHealthBoxDigit[3], MiniBarAmmoDigit[3];
1167
    short InventoryTics[MAX_INVENTORY];
1168
    short InventoryPercent[MAX_INVENTORY];
5198 hendricks2 1169
    int8_t InventoryAmount[MAX_INVENTORY];
1170
    SWBOOL InventoryActive[MAX_INVENTORY];
5196 hendricks2 1171
 
1172
    short DiveTics;
1173
    short DiveDamageTics;
1174
 
1175
    // Death stuff
8349 hendricks2 1176
    uint16_t DeathType;
5196 hendricks2 1177
    short Kills;
1178
    short Killer;  //who killed me
1179
    short KilledPlayer[MAX_SW_PLAYERS_REG];
1180
    short SecretsFound;
1181
 
1182
    // Health
1183
    short Armor;
1184
    short MaxHealth;
1185
 
1186
    //char RocketBarrel;
1187
    char PlayerName[32];
1188
 
1189
    unsigned char UziShellLeftAlt;
1190
    unsigned char UziShellRightAlt;
1191
    unsigned char TeamColor;  // used in team play and also used in regular mulit-play for show
1192
 
1193
    // palette fading up and down for player hit and get items
1194
    short FadeTics;                 // Tics between each fade cycle
1195
    short FadeAmt;                  // Current intensity of fade
5198 hendricks2 1196
    SWBOOL NightVision;               // Is player's night vision active?
5196 hendricks2 1197
    unsigned char StartColor;       // Darkest color in color range being used
1198
    //short electro[64];
1199
    unsigned char temp_pal[768];    // temporary working palette
5198 hendricks2 1200
    SWBOOL IsAI;                      // Is this and AI character?
5196 hendricks2 1201
    short fta,ftq;                  // First time active and first time quote, for talking in multiplayer games
1202
    short NumFootPrints;            // Number of foot prints left to lay down
5198 hendricks2 1203
    SWBOOL PlayerTalking;             // Is player currently talking
5196 hendricks2 1204
    int TalkVocnum;                 // Number of sound that player is using
1205
    int TalkVocHandle;              // Handle of sound in sound queue, to access in Dose's code
1206
    unsigned char WpnUziType;                // Toggle between single or double uzi's if you own 2.
1207
    unsigned char WpnShotgunType;            // Shotgun has normal or fully automatic fire
1208
    unsigned char WpnShotgunAuto;            // 50-0 automatic shotgun rounds
1209
    unsigned char WpnShotgunLastShell;       // Number of last shell fired
1210
    unsigned char WpnRailType;               // Normal Rail Gun or EMP Burst Mode
5198 hendricks2 1211
    SWBOOL Bloody;                    // Is player gooey from the slaughter?
5196 hendricks2 1212
    int nukevochandle;              // Stuff for the Nuke
5198 hendricks2 1213
    SWBOOL InitingNuke;
1214
    SWBOOL TestNukeInit;
1215
    SWBOOL NukeInitialized;           // Nuke already has counted down
5196 hendricks2 1216
    short FistAng;                  // KungFu attack angle
1217
    unsigned char WpnKungFuMove;             // KungFu special moves
5198 hendricks2 1218
    SWBOOL BunnyMode;                 // Can shoot Bunnies out of rocket launcher
5196 hendricks2 1219
    short HitBy;                    // SpriteNum of whatever player was last hit by
1220
    short Reverb;                   // Player's current reverb setting
1221
    short Heads;                    // Number of Accursed Heads orbiting player
1222
    int PlayerVersion;
1223
};
1224
 
1225
extern PLAYER Player[MAX_SW_PLAYERS_REG+1];
1226
 
1227
 
1228
//
1229
// Player Flags
1230
//
1231
 
1232
#define PF_DEAD             (BIT(1))
1233
#define PF_JUMPING          (BIT(2))
1234
#define PF_FALLING          (BIT(3))
1235
#define PF_LOCK_CRAWL       (BIT(4))
1236
#define PF_LOCK_HORIZ       (BIT(5))
1237
#define PF_LOOKING          (BIT(6))
1238
#define PF_PLAYER_MOVED     (BIT(7))
1239
#define PF_PLAYER_RIDING    (BIT(8))
1240
#define PF_AUTO_AIM         (BIT(9))
1241
#define PF_RECOIL           (BIT(10))
1242
 
1243
#define PF_FLYING           (BIT(11))
1244
#define PF_WEAPON_RETRACT   (BIT(12))
1245
#define PF_PICKED_UP_AN_UZI (BIT(13))
1246
#define PF_CRAWLING         (BIT(14))
1247
#define PF_CLIMBING         (BIT(15))
1248
#define PF_SWIMMING         (BIT(16))
1249
#define PF_DIVING           (BIT(17))
1250
#define PF_DIVING_IN_LAVA   (BIT(18))
1251
#define PF_TWO_UZI          (BIT(19))
1252
#define PF_LOCK_RUN         (BIT(20))
1253
#define PF_TURN_180         (BIT(21))
1254
#define PF_DEAD_HEAD        (BIT(22)) // are your a dead head
1255
#define PF_HEAD_CONTROL     (BIT(23)) // have control of turning when a head?
1256
#define PF_CLIP_CHEAT       (BIT(24)) // cheat for wall clipping
1257
#define PF_SLIDING          (BIT(25)) // cheat for wall clipping
1258
#define PF_VIEW_FROM_OUTSIDE   (BIT(26))
1259
#define PF_VIEW_OUTSIDE_WEAPON (BIT(27))
1260
#define PF_VIEW_FROM_CAMERA   (BIT(28))
1261
#define PF_TANK             (BIT(29)) // Doin the tank thang
1262
#define PF_MOUSE_AIMING_ON (BIT(30))
1263
#define PF_WEAPON_DOWN       (BIT(31))
1264
 
1265
#define PF2_TELEPORTED        (BIT(0))
1266
 
1267
///////////////////////////////////////////////////////////////////////////////////////////
1268
//
1269
// Actor
1270
//
1271
///////////////////////////////////////////////////////////////////////////////////////////
1272
 
1273
//
1274
// Hit Points
1275
//
1276
 
1277
#define HEALTH_RIPPER            70
1278
#define HEALTH_RIPPER2           200
1279
#define HEALTH_MOMMA_RIPPER      500
1280
#define HEALTH_NINJA             40
1281
#define HEALTH_RED_NINJA         160
1282
#define HEALTH_COOLIE            120
1283
#define HEALTH_COOLIE_GHOST      65
1284
#define HEALTH_SKEL_PRIEST       90
1285
#define HEALTH_GORO              200
1286
#define HEALTH_HORNET            4
1287
#define HEALTH_SKULL             4
1288
#define HEALTH_EEL               100
1289
 
1290
#define HEALTH_SERP_GOD          3800
1291
 
1292
//
1293
// Action Set Structure
1294
//
1295
 
1296
typedef struct
1297
{
1298
#define MAX_ACTOR_CLOSE_ATTACK 2
1299
#define MAX_ACTOR_ATTACK 6
1300
    STATEp *Stand;
1301
    STATEp *Run;
1302
    STATEp *Jump;
1303
    STATEp *Fall;
1304
    STATEp *Crawl;
1305
    STATEp *Swim;
1306
    STATEp *Fly;
1307
    STATEp *Rise;
1308
    STATEp *Sit;
1309
    STATEp *Look;
1310
    STATEp *Climb;
1311
    STATEp *Pain;
1312
    STATEp *Death1;
1313
    STATEp *Death2;
1314
    STATEp *Dead;
1315
    STATEp *DeathJump;
1316
    STATEp *DeathFall;
1317
 
1318
    STATEp *CloseAttack[MAX_ACTOR_CLOSE_ATTACK];
1319
    short  CloseAttackPercent[MAX_ACTOR_CLOSE_ATTACK];
1320
 
1321
    STATEp *Attack[MAX_ACTOR_ATTACK];
1322
    short  AttackPercent[MAX_ACTOR_ATTACK];
1323
 
1324
    STATEp *Special[2];
1325
    STATEp *Duck;
1326
    STATEp *Dive;
1327
} ACTOR_ACTION_SET,*ACTOR_ACTION_SETp;
1328
 
1329
typedef struct
1330
{
1331
    int pos;           // current position - always moves toward tgt
1332
    int open_dest;     // destination of open position
1333
    int tgt;           // current target
1334
    int speed;         // speed of movement
1335
    int orig_speed;    // original speed - vel jacks with speed
1336
    int vel;           // velocity adjuments
1337
    int num_walls;     // save off positions of walls for rotator
1338
    int *origx;
1339
    int *origy;
1340
} ROTATOR, *ROTATORp;
1341
 
1342
//
1343
// User Extension record
1344
//
1345
 
1346
typedef struct
1347
{
1348
    //
1349
    // Variables that can be used by actors and Player
1350
    //
1351
    ROTATORp rotator;
1352
 
1353
    // wall vars for lighting
1354
    int WallCount;
5198 hendricks2 1355
    int8_t* WallShade; // malloced - save off wall shades for lighting
5196 hendricks2 1356
 
1357
    WALLp WallP; // operate on wall instead of sprite
1358
    STATEp State;
1359
    STATEp *Rot;
1360
    STATEp StateStart;
1361
    STATEp StateEnd;
1362
    STATEp *StateFallOverride; // a bit kludgy - override std fall state
1363
 
1364
    ANIMATORp ActorActionFunc;
1365
    ACTOR_ACTION_SETp ActorActionSet;
1366
    PERSONALITYp Personality;
1367
    ATTRIBUTEp Attrib;
1368
    SECTOR_OBJECTp sop_parent;  // denotes that this sprite is a part of the
1369
    // sector object - contains info for the SO
1370
 
1371
    int ox, oy, oz;
1372
 
1373
    int Flags;
1374
    int Flags2;
1375
    int Tics;
1376
 
1377
    short RotNum;
1378
    short ID;
1379
 
1380
    // Health/Pain related
1381
    short Health;
1382
    short MaxHealth;
1383
 
1384
    short LastDamage;           // last damage amount taken
1385
    short PainThreshold;       // amount of damage that can be taken before
1386
    // going into pain frames.
1387
 
1388
    // jump & fall
1389
    short jump_speed;
1390
    short jump_grav;
1391
 
1392
    // clipmove
1393
    short ceiling_dist;
1394
    short floor_dist;
1395
    short lo_step;
1396
    int hiz,loz;
1397
    int zclip; // z height to move up for clipmove
1398
    SECTORp hi_sectp, lo_sectp;
1399
    SPRITEp hi_sp, lo_sp;
1400
 
1401
    int active_range;
1402
 
1403
    short   SpriteNum;
1404
    short   Attach;  // attach to sprite if needed - electro snake
1405
    SPRITEp SpriteP;
1406
 
1407
    // if a player's sprite points to player structure
1408
    PLAYERp PlayerP;
1409
    short Sibling;
1410
 
1411
 
1412
    //
1413
    // Possibly used by both.
1414
    //
1415
 
1416
    // precalculated vectors
1417
    int xchange,ychange,zchange;
1418
 
1419
    int  z_tgt;
1420
 
1421
    // velocity
1422
    int  vel_tgt;
1423
    short vel_rate;
5198 hendricks2 1424
    uint8_t speed; // Ordinal Speed Range 0-3 from slow to fast
5196 hendricks2 1425
 
1426
    short Counter;
1427
    short Counter2;
1428
    short Counter3;
1429
    short DamageTics;
1430
    short BladeDamageTics;
1431
 
1432
    short WpnGoal;
1433
    unsigned int Radius;    // for distance checking
1434
    int  OverlapZ;  // for z overlap variable
1435
 
1436
    //
1437
    // Only have a place for actors
1438
    //
1439
 
1440
    // For actors on fire
1441
    short flame;
1442
 
1443
    // target player for the enemy - can only handle one player at at time
1444
    //PLAYERp tgt_player;
1445
    SPRITEp tgt_sp;
1446
 
1447
    // scaling
1448
    short scale_speed;
1449
    unsigned short scale_value;
1450
    short scale_tgt;
1451
 
1452
    // zig zagging
1453
    short DistCheck;
1454
    //short ZigZagDist;
1455
    //short ZigZagAng;
1456
    //short ZigZagDir;
1457
 
1458
    short Dist;
1459
    short TargetDist;
1460
    short WaitTics;
1461
 
1462
    // track
1463
    short track;
1464
    short point;
1465
    short track_dir;
1466
    int  track_vel;
1467
 
1468
    // sliding variables - slide backwards etc
1469
    short slide_ang;
1470
    int  slide_vel;
1471
    short slide_dec;
1472
 
1473
    short motion_blur_dist;
1474
    short motion_blur_num;
1475
 
1476
    short wait_active_check;  // for enemy checking of player
1477
    short inactive_time; // length of time actor has been unaware of his tgt
1478
    int  sx,sy,sz;
1479
    short sang;
1480
    char spal;  // save off default palette number
1481
 
1482
    int ret; //holder for move_sprite return value
1483
 
1484
    // Need to get rid of these flags
1485
    int  Flag1;
1486
 
5198 hendricks2 1487
    int8_t  LastWeaponNum;
1488
    int8_t  WeaponNum;
5196 hendricks2 1489
 
1490
    short bounce;           // count bounces off wall for killing shrap stuff
1491
    // !JIM! my extensions
1492
    int ShellNum;          // This is shell no. 0 to whatever
1493
    // Shell gets deleted when ShellNum < (ShellCount - MAXSHELLS)
1494
    short FlagOwner;        // The spritenum of the original flag
1495
    short Vis;              // Shading upgrade, for shooting, etc...
5198 hendricks2 1496
    SWBOOL DidAlert;          // Has actor done his alert noise before?
5209 hendricks2 1497
 
1498
    uint8_t filler;
5196 hendricks2 1499
} USER,*USERp;
1500
 
1501
// sprite->extra flags
1502
// BUILD AND GAME - DO NOT MOVE THESE
1503
#define SPRX_SKILL              (BIT(0) | BIT(1) | BIT(2))
1504
 
1505
// BIT(4) ST1 BUILD AND GAME
1506
#define SPRX_STAY_PUT_VATOR     (BIT(5))    // BUILD AND GAME - will not move with vators etc
1507
// DO NOT MOVE THIS
1508
 
1509
#define SPRX_STAG               (BIT(6))    // BUILD AND GAME - NON-ST1 sprite with ST1 type tagging
1510
// DO NOT MOVE
1511
 
1512
#define SPRX_QUEUE_SPRITE       (BIT(7))    // Queue sprite -check queue when deleting
1513
#define SPRX_MULTI_ITEM         (BIT(9))    // BUILD AND GAME - multi player item
1514
 
1515
// have users - could be moved
1516
#define SPRX_PLAYER_OR_ENEMY    (BIT(11))   // for checking quickly if sprite is a
1517
// player or actor
1518
// do not need Users
1519
#define SPRX_FOUND              (BIT(12))   // BUILD ONLY INTERNAL - used for finding sprites
1520
#define SPRX_BLADE              (BIT(12))   // blade sprite
1521
#define SPRX_BREAKABLE          (BIT(13))   // breakable items
1522
#define SPRX_BURNABLE           (BIT(14))   // used for burnable sprites in the game
1523
 
1524
// temp use
1525
#define SPRX_BLOCK              (BIT(15))   // BUILD AND GAME
1526
// BUILD - tell which actors should not spawn
1527
// GAME - used for internal game code
1528
// ALT-M debug mode
1529
 
1530
// !LIGHT
1531
// all three bits set - should never happen with skill
1532
// #define SPRX_USER_NON_STANDARD  (BIT(0)|BIT(1)|BIT(2))   // used for lighting
1533
 
1534
// boolean flags carried over from build
1535
#define SPRX_BOOL11 (BIT(5))
1536
#define SPRX_BOOL1 (BIT(6))
1537
#define SPRX_BOOL2 (BIT(7))
1538
#define SPRX_BOOL3 (BIT(8))
1539
#define SPRX_BOOL4 (BIT(9))
1540
#define SPRX_BOOL5 (BIT(10))
1541
#define SPRX_BOOL6 (BIT(11))
1542
#define SPRX_BOOL7 (BIT(4))  // bit 12 was used build
1543
#define SPRX_BOOL8 (BIT(13))
1544
#define SPRX_BOOL9 (BIT(14))
1545
#define SPRX_BOOL10 (BIT(15))
1546
 
1547
#define SET_BOOL1(sp) SET((sp)->extra, SPRX_BOOL1)
1548
#define SET_BOOL2(sp) SET((sp)->extra, SPRX_BOOL2)
1549
#define SET_BOOL3(sp) SET((sp)->extra, SPRX_BOOL3)
1550
#define SET_BOOL4(sp) SET((sp)->extra, SPRX_BOOL4)
1551
#define SET_BOOL5(sp) SET((sp)->extra, SPRX_BOOL5)
1552
#define SET_BOOL6(sp) SET((sp)->extra, SPRX_BOOL6)
1553
#define SET_BOOL7(sp) SET((sp)->extra, SPRX_BOOL7)
1554
#define SET_BOOL8(sp) SET((sp)->extra, SPRX_BOOL8)
1555
#define SET_BOOL9(sp) SET((sp)->extra, SPRX_BOOL9)
1556
#define SET_BOOL10(sp) SET((sp)->extra, SPRX_BOOL10)
1557
#define SET_BOOL11(sp) SET((sp)->extra, SPRX_BOOL11)
1558
 
1559
#define RESET_BOOL1(sp) RESET((sp)->extra, SPRX_BOOL1)
1560
#define RESET_BOOL2(sp) RESET((sp)->extra, SPRX_BOOL2)
1561
#define RESET_BOOL3(sp) RESET((sp)->extra, SPRX_BOOL3)
1562
#define RESET_BOOL4(sp) RESET((sp)->extra, SPRX_BOOL4)
1563
#define RESET_BOOL5(sp) RESET((sp)->extra, SPRX_BOOL5)
1564
#define RESET_BOOL6(sp) RESET((sp)->extra, SPRX_BOOL6)
1565
#define RESET_BOOL7(sp) RESET((sp)->extra, SPRX_BOOL7)
1566
#define RESET_BOOL8(sp) RESET((sp)->extra, SPRX_BOOL8)
1567
#define RESET_BOOL9(sp) RESET((sp)->extra, SPRX_BOOL9)
1568
#define RESET_BOOL10(sp) RESET((sp)->extra, SPRX_BOOL10)
1569
#define RESET_BOOL11(sp) RESET((sp)->extra, SPRX_BOOL11)
1570
 
1571
#define TEST_BOOL1(sp) TEST((sp)->extra, SPRX_BOOL1)
1572
#define TEST_BOOL2(sp) TEST((sp)->extra, SPRX_BOOL2)
1573
#define TEST_BOOL3(sp) TEST((sp)->extra, SPRX_BOOL3)
1574
#define TEST_BOOL4(sp) TEST((sp)->extra, SPRX_BOOL4)
1575
#define TEST_BOOL5(sp) TEST((sp)->extra, SPRX_BOOL5)
1576
#define TEST_BOOL6(sp) TEST((sp)->extra, SPRX_BOOL6)
1577
#define TEST_BOOL7(sp) TEST((sp)->extra, SPRX_BOOL7)
1578
#define TEST_BOOL8(sp) TEST((sp)->extra, SPRX_BOOL8)
1579
#define TEST_BOOL9(sp) TEST((sp)->extra, SPRX_BOOL9)
1580
#define TEST_BOOL10(sp) TEST((sp)->extra, SPRX_BOOL10)
1581
#define TEST_BOOL11(sp) TEST((sp)->extra, SPRX_BOOL11)
1582
 
1583
// User->Flags flags
1584
#define SPR_MOVED               BIT(0) // Did actor move
1585
#define SPR_ATTACKED            BIT(1) // Is sprite being attacked?
1586
#define SPR_TARGETED            BIT(2) // Is sprite a target of a weapon?
1587
#define SPR_ACTIVE              BIT(3) // Is sprite aware of the player?
1588
#define SPR_ELECTRO_TOLERANT    BIT(4) // Electro spell does not slow actor
1589
#define SPR_JUMPING             BIT(5) // Actor is jumping
1590
#define SPR_FALLING             BIT(6) // Actor is falling
1591
#define SPR_CLIMBING            BIT(7) // Actor is falling
1592
#define SPR_DEAD               BIT(8) // Actor is dying
1593
 
1594
#define SPR_ZDIFF_MODE          BIT(10) // For following tracks at different z heights
1595
#define SPR_SPEED_UP            BIT(11) // For following tracks at different speeds
1596
#define SPR_SLOW_DOWN           BIT(12) // For following tracks at different speeds
1597
#define SPR_DONT_UPDATE_ANG     BIT(13) // For tracks - don't update the angle for a while
1598
 
1599
#define SPR_SO_ATTACHED            BIT(14) // sprite is part of a sector object
1600
#define SPR_SUICIDE             BIT(15) // sprite is set to kill itself
1601
 
1602
#define SPR_RUN_AWAY            BIT(16) // sprite is in "Run Away" track mode.
1603
#define SPR_FIND_PLAYER         BIT(17) // sprite is in "Find Player" track mode.
1604
 
1605
#define SPR_SWIMMING            BIT(18) // Actor is swimming
1606
#define SPR_WAIT_FOR_PLAYER     BIT(19) // Track Mode - Actor is waiting for player to come close
1607
#define SPR_WAIT_FOR_TRIGGER    BIT(20) // Track Mode - Actor is waiting for player to trigger
1608
#define SPR_SLIDING             BIT(21) // Actor is sliding
1609
#define SPR_ON_SO_SECTOR        BIT(22) // sprite is on a sector object sector
1610
 
1611
#define SPR_SHADE_DIR           BIT(23) // sprite is on a sector object sector
1612
#define SPR_XFLIP_TOGGLE        BIT(24) // sprite rotation xflip bit
1613
#define SPR_NO_SCAREDZ          BIT(25) // not afraid of falling
1614
 
1615
#define SPR_SET_POS_DONT_KILL   BIT(26) // Don't kill sprites in MissileSetPos
1616
#define SPR_SKIP2               BIT(27) // 20 moves ps
1617
#define SPR_SKIP4               BIT(28) // 10 moves ps
1618
 
1619
#define SPR_BOUNCE              BIT(29) // For shrapnel types that can bounce once
1620
#define SPR_UNDERWATER          BIT(30) // For missiles etc
1621
 
1622
#define SPR_SHADOW              BIT(31) // Sprites that have shadows
1623
 
1624
// User->Flags2 flags
1625
#define SPR2_BLUR_TAPER         (BIT(13)|BIT(14))   // taper type
1626
#define SPR2_BLUR_TAPER_FAST    (BIT(13))   // taper fast
1627
#define SPR2_BLUR_TAPER_SLOW    (BIT(14))   // taper slow
1628
#define SPR2_SPRITE_FAKE_BLOCK  (BIT(15))   // fake blocking bit for damage
1629
#define SPR2_NEVER_RESPAWN      (BIT(16))   // for item respawning
1630
#define SPR2_ATTACH_WALL        (BIT(17))
1631
#define SPR2_ATTACH_FLOOR       (BIT(18))
1632
#define SPR2_ATTACH_CEILING     (BIT(19))
1633
#define SPR2_CHILDREN           (BIT(20))   // sprite OWNS children
1634
#define SPR2_SO_MISSILE         (BIT(21))   // this is a missile from a SO
1635
#define SPR2_DYING              (BIT(22))   // Sprite is currently dying
1636
#define SPR2_VIS_SHADING        (BIT(23))   // Sprite shading to go along with vis adjustments
1637
#define SPR2_DONT_TARGET_OWNER  (BIT(24))
1638
 
1639
 
1640
extern USERp User[MAXSPRITES];
1641
 
1642
typedef struct
1643
{
1644
    short Xdim, Ydim, ScreenSize;
1645
} BORDER_INFO,*BORDER_INFOp;
1646
 
1647
 
1648
typedef struct
1649
{
1650
    short high;
1651
} RANGE,*RANGEp;
1652
 
1653
 
1654
///////////////////////////////////////////////////////////////////////////////////////////
1655
//
1656
// Sector Stuff - Sector Objects and Tracks
1657
//
1658
///////////////////////////////////////////////////////////////////////////////////////////
1659
 
1660
// flags in EXTRA variable
1661
#define SECTFX_SINK                  BIT(0)
1662
#define SECTFX_OPERATIONAL           BIT(1)
1663
#define SECTFX_WARP_SECTOR           BIT(2)
1664
#define SECTFX_CURRENT               BIT(3)
1665
#define SECTFX_Z_ADJUST              BIT(4) // adjust ceiling/floor
1666
#define SECTFX_NO_RIDE               BIT(5) // moving sector - don't ride it
1667
#define SECTFX_DYNAMIC_AREA          BIT(6)
1668
#define SECTFX_DIVE_AREA             BIT(7) // Diving area
1669
#define SECTFX_UNDERWATER            BIT(8) // Underwater area
1670
#define SECTFX_UNDERWATER2           BIT(9) // Underwater area
1671
 
1672
#define SECTFX_LIQUID_MASK           (BIT(10)|BIT(11)) // only valid for sectors with depth
1673
#define SECTFX_LIQUID_NONE           (0)
1674
#define SECTFX_LIQUID_LAVA           BIT(10)
1675
#define SECTFX_LIQUID_WATER          BIT(11)
1676
#define SECTFX_SECTOR_OBJECT         BIT(12)  // for collision detection
1677
#define SECTFX_VATOR                 BIT(13)  // denotes that this is a vertical moving sector
1678
// vator type
1679
#define SECTFX_TRIGGER               BIT(14)  // trigger type to replace tags.h trigger types
1680
 
1681
// flags in sector USER structure
1682
#define SECTFU_SO_DONT_BOB          BIT(0)
1683
#define SECTFU_SO_SINK_DEST         BIT(1)
1684
#define SECTFU_SO_DONT_SINK         BIT(2)
1685
#define SECTFU_DONT_COPY_PALETTE    BIT(3)
1686
#define SECTFU_SO_SLOPE_FLOOR_TO_POINT BIT(4)
1687
#define SECTFU_SO_SLOPE_CEILING_TO_POINT BIT(5)
1688
#define SECTFU_DAMAGE_ABOVE_SECTOR  BIT(6)
1689
#define SECTFU_VATOR_BOTH           BIT(7)  // vators set up for both ceiling and floor
1690
#define SECTFU_CANT_SURFACE         BIT(8)  // for diving
1691
#define SECTFU_SLIDE_SECTOR         BIT(9)  // for diving
1692
 
1693
#define MAKE_STAG_ENUM
1694
enum stag_id
1695
{
1696
#include "stag.h"
1697
};
1698
typedef enum stag_id STAG_ID;
1699
#undef MAKE_STAG_ENUM
1700
 
1701
 
1702
#define WALLFX_LOOP_DONT_SPIN            BIT(0)
1703
#define WALLFX_LOOP_REVERSE_SPIN         BIT(1)
1704
#define WALLFX_LOOP_SPIN_2X              BIT(2)
1705
#define WALLFX_LOOP_SPIN_4X              BIT(3)
1706
#define WALLFX_LOOP_OUTER                BIT(4) // for sector object
1707
#define WALLFX_DONT_MOVE                 BIT(5) // for sector object
1708
#define WALLFX_SECTOR_OBJECT             BIT(6) // for collision detection
1709
#define WALLFX_DONT_STICK                BIT(7) // for bullet holes and stars
1710
#define WALLFX_DONT_SCALE                BIT(8) // for sector object
1711
#define WALLFX_LOOP_OUTER_SECONDARY      BIT(9) // for sector object
1712
 
1713
enum ShrapType
1714
{
1715
    SHRAP_NONE              = 0,
1716
    SHRAP_GLASS             = 1,  //
1717
    SHRAP_TREE_BARK         = 2,  // (NEED) outside tree bark
1718
    SHRAP_SO_SMOKE          = 3,  // only used for damaged SO's
1719
    SHRAP_PAPER             = 4,  //
1720
    SHRAP_BLOOD             = 5,  // std blood from gibs
1721
    SHRAP_EXPLOSION         = 6,  // small explosion
1722
    SHRAP_LARGE_EXPLOSION   = 7,  // large explosion
1723
    SHRAP_METAL             = 8,  //
1724
    SHRAP_STONE             = 9,  // what we have might be ok
1725
    SHRAP_PLANT             = 10, // (NEED)
1726
    SHRAP_GIBS              = 11, // std blood and guts
1727
    SHRAP_WOOD              = 12, //
1728
    SHRAP_GENERIC           = 13, // what we have might be ok - sort of gray brown rock look
1729
    SHRAP_TREE_PULP         = 14, // (NEED) inside tree wood
1730
    SHRAP_COIN              = 15,
1731
    SHRAP_METALMIX          = 16,
1732
    SHRAP_WOODMIX           = 17,
1733
    SHRAP_MARBELS           = 18,
1734
    SHRAP_PAPERMIX          = 19,
1735
    SHRAP_USER_DEFINED      = 99
1736
};
1737
 
1738
typedef struct
1739
{
1740
    int dist, flags;
1741
    short depth_fract, depth; // do NOT change this, doubles as a long FIXED point number
1742
    short stag,    // ST? tag number - for certain things it helps to know it
1743
          ang,
1744
          height,
1745
          speed,
1746
          damage,
1747
          number;  // usually used for matching number
5198 hendricks2 1748
    uint8_t    flags2;
5196 hendricks2 1749
} SECT_USER, *SECT_USERp;
1750
 
1751
extern SECT_USERp SectUser[MAXSECTORS];
1752
SECT_USERp SpawnSectUser(short sectnum);
1753
 
1754
 
1755
typedef struct
1756
{
1757
    unsigned int size, checksum;
1758
} MEM_HDR,*MEM_HDRp;
1759
 
8515 hendricks2 1760
#if !DEBUG
1761
# define ValidPtr(ptr) ((SWBOOL)(TRUE))
1762
# define AllocMem(size) Xmalloc(size)
1763
# define CallocMem(size, num) Xcalloc(size, num)
1764
# define ReAllocMem(ptr, size) Xrealloc(ptr, size)
1765
# define FreeMem(ptr) Xfree(ptr)
1766
#else
5198 hendricks2 1767
SWBOOL ValidPtr(void *ptr);
1768
void *AllocMem(int size);
1769
void *CallocMem(int size, int num);
1770
void *ReAllocMem(void *ptr, int size);
1771
void FreeMem(void *ptr);
8515 hendricks2 1772
#endif
5196 hendricks2 1773
 
1774
typedef struct
1775
{
1776
    short sprite_num;
1777
    short dang;
1778
    int dist;
1779
    int weight;
1780
} TARGET_SORT, *TARGET_SORTp;
1781
 
1782
#define MAX_TARGET_SORT 16
1783
extern TARGET_SORT TargetSort[MAX_TARGET_SORT];
1784
extern unsigned TargetSortCount;
1785
 
1786
enum DoorType
1787
{
1788
    OPERATE_TYPE,
1789
    DOOR_HORIZ_TYPE,
1790
    DOOR_SLIDE_TYPE,
1791
    DOOR_SWING_TYPE,
1792
    DOOR_ROTATE_TYPE
1793
};
1794
 
1795
typedef enum DoorType DOOR_TYPE;
1796
 
1797
typedef struct
1798
{
1799
    DOOR_TYPE Type;
1800
    short Sector;
1801
    short Speed;
1802
    short TimeOut;
1803
} DOOR_AUTO_CLOSE, *DOOR_AUTO_CLOSEp;
1804
 
1805
#define MAX_DOOR_AUTO_CLOSE 16
1806
 
1807
typedef struct
1808
{
1809
    int origx[17], origy[17];
1810
    short sector, angopen, angclosed, angopendir, sang, anginc, wall[17];
1811
} SWING;
1812
 
1813
typedef struct
1814
{
1815
    int floor_origz, ceiling_origz, range;
1816
    short sector, sintable_ndx, speed_shift;
1817
    char flags;
1818
} SINE_WAVE_FLOOR, *SINE_WAVE_FLOORp;
1819
 
1820
#define MAX_SINE_WAVE 6
1821
extern SINE_WAVE_FLOOR SineWaveFloor[MAX_SINE_WAVE][21];
1822
 
1823
typedef struct
1824
{
1825
    int orig_xy, range;
1826
    short wall, sintable_ndx, speed_shift, type;
1827
} SINE_WALL, *SINE_WALLp;
1828
 
1829
#define MAX_SINE_WALL 10
1830
#define MAX_SINE_WALL_POINTS 64
1831
extern SINE_WALL SineWall[MAX_SINE_WALL][MAX_SINE_WALL_POINTS];
1832
 
1833
typedef struct
1834
{
1835
    short Sector, TimeOut;
1836
} SPRING_BOARD;
1837
 
1838
extern SPRING_BOARD SpringBoard[20];
1839
extern SWING Rotate[17];
1840
 
1841
typedef struct
1842
{
1843
    short sector, speed;
1844
    int xmid, ymid;
1845
} SPIN;
1846
 
1847
extern SPIN Spin[17];
1848
extern DOOR_AUTO_CLOSE DoorAutoClose[MAX_DOOR_AUTO_CLOSE];
1849
extern int x_min_bound, y_min_bound, x_max_bound, y_max_bound;
1850
 
1851
#define MAXANIM 256
1852
typedef void ANIM_CALLBACK (ANIMp, void *);
1853
typedef ANIM_CALLBACK *ANIM_CALLBACKp;
1854
typedef void *ANIM_DATAp;
1855
 
1856
struct ANIMstruct
1857
{
1858
    int *ptr, goal;
1859
    int vel;
1860
    short vel_adj;
1861
    ANIM_CALLBACKp callback;
1862
    ANIM_DATAp callbackdata;
1863
};
1864
 
1865
extern ANIM Anim[MAXANIM];
1866
extern short AnimCnt;
1867
 
1868
 
1869
typedef struct
1870
{
1871
    int x,y,z;
1872
    short ang, tag_low, tag_high, filler;
1873
} TRACK_POINT, *TRACK_POINTp;
1874
 
1875
typedef struct
1876
{
1877
    TRACK_POINTp TrackPoint;
1878
    int ttflags;
1879
    short flags;
1880
    short NumPoints;
1881
} TRACK, *TRACKp;
1882
 
1883
// Most track type flags are in tags.h
1884
 
1885
// Regular track flags
1886
#define TF_TRACK_OCCUPIED BIT(0)
1887
 
1888
typedef struct
1889
{
5198 hendricks2 1890
    uint8_t FromRange,ToRange,FromColor,ToColor;
5196 hendricks2 1891
} COLOR_MAP, *COLOR_MAPp;
1892
 
1893
#define MAX_TRACKS 100
1894
 
1895
extern TRACK Track[MAX_TRACKS];
1896
 
1897
struct SECTOR_OBJECTstruct
1898
{
1899
#define MAX_SO_SECTOR 40
1900
#define MAX_SO_POINTS (MAX_SO_SECTOR*15)
1901
#define MAX_SO_SPRITE 60
1902
#define MAX_CLIPBOX 32
1903
 
1904
    SECTORp sectp[MAX_SO_SECTOR];
1905
    soANIMATORp PreMoveAnimator;
1906
    soANIMATORp PostMoveAnimator;
1907
    soANIMATORp Animator;
1908
    SPRITEp controller;
1909
 
1910
    SPRITEp sp_child;  // child sprite that holds info for the sector object
1911
 
1912
    int    xmid,ymid,zmid, // midpoints of the sector object
1913
           vel,            // velocity
1914
           vel_tgt,        // target velocity
1915
           player_xoff,    // player x offset from the xmid
1916
           player_yoff,    // player y offset from the ymid
1917
           zorig_floor[MAX_SO_SECTOR],      // original z values for all sectors
1918
           zorig_ceiling[MAX_SO_SECTOR],      // original z values for all sectors
1919
           zdelta,         // z delta from original
1920
           z_tgt,          // target z delta
1921
           z_rate,         // rate at which z aproaches target
1922
           update,         // Distance from player at which you continue updating
1923
    // only works for single player.
1924
           bob_diff,       // bobbing difference for the frame
1925
           target_dist,    // distance to next point
1926
           floor_loz,      // floor low z
1927
           floor_hiz,      // floor hi z
1928
           morph_z,        // morphing point z
1929
           morph_z_min,    // morphing point z min
1930
           morph_z_max,
1931
           bob_amt,        // bob amount max in z coord
1932
    // variables set by mappers for drivables
1933
           drive_angspeed,
1934
           drive_angslide,
1935
           drive_speed,
1936
           drive_slide,
1937
           crush_z,
1938
           flags;
1939
 
1940
    short   sector[MAX_SO_SECTOR],     // hold the sector numbers of the sector object
1941
            sp_num[MAX_SO_SPRITE],     // hold the sprite numbers of the object
1942
            xorig[MAX_SO_POINTS],   // save the original x & y location of each wall so it can be
1943
            yorig[MAX_SO_POINTS],   // refreshed
1944
            sectnum,        // current secnum of midpoint
1945
            mid_sector,     // middle sector
1946
            max_damage,     // max damage
1947
            ram_damage,     // damage taken by ramming
1948
            wait_tics,      //
1949
            num_sectors,    // number of sectors
1950
            num_walls,      // number of sectors
1951
            track,          // the track # 0 to 20
1952
            point,          // the point on the track that the sector object is headed toward
1953
            vel_rate,       // rate at which velocity aproaches target
1954
            dir,            // direction traveling on the track
1955
            ang,            // angle facing
1956
            ang_moving,     // angle the SO is facing
1957
            clipdist,       // cliping distance for operational sector objects
1958
            clipbox_dist[MAX_CLIPBOX], // mult-clip box variables
1959
            clipbox_xoff[MAX_CLIPBOX], // mult-clip box variables
1960
            clipbox_yoff[MAX_CLIPBOX], // mult-clip box variables
1961
            clipbox_ang[MAX_CLIPBOX], // mult-clip box variables
1962
            clipbox_vdist[MAX_CLIPBOX], // mult-clip box variables
1963
            clipbox_num,
1964
            ang_tgt,        // target angle
1965
            ang_orig,       // original angle
1966
            last_ang,       // last angle before started spinning
1967
            old_ang,        // holding variable for the old angle
1968
            spin_speed,     // spin_speed
1969
            spin_ang,       // spin angle
1970
            turn_speed,     // shift value determines how fast SO turns to match new angle
1971
            bob_sine_ndx,   // index into sine table
1972
            bob_speed,      // shift value for speed
1973
            op_main_sector, // main sector operational SO moves in - for speed purposes
1974
            save_vel,       // save velocity
1975
            save_spin_speed, // save spin speed
1976
            match_event,    // match number
1977
            match_event_sprite, // spritenum of the match event sprite
1978
    // SO Scaling Vector Info
1979
            scale_type,         // type of scaling - enum controled
1980
            scale_active_type,  // activated by a switch or trigger
1981
 
1982
    // values for whole SO
1983
            scale_dist,         // distance from center
1984
            scale_speed,        // speed of scaling
1985
            scale_dist_min,     // absolute min
1986
            scale_dist_max,     // absolute max
1987
            scale_rand_freq,    // freqency of direction change - based on rand(1024)
1988
 
1989
    // values for single point scaling
1990
            scale_point_dist[MAX_SO_POINTS],         // distance from center
1991
            scale_point_speed[MAX_SO_POINTS],        // speed of scaling
1992
            scale_point_base_speed,                       // base speed of scaling
1993
            scale_point_dist_min,     // absolute min
1994
            scale_point_dist_max,     // absolute max
1995
            scale_point_rand_freq,    // freqency of direction change - based on rand(1024)
1996
 
1997
            scale_x_mult,           // x multiplyer for scaling
1998
            scale_y_mult,           // y multiplyer for scaling
1999
 
2000
    // Used for center point movement
2001
            morph_wall_point,       // actual wall point to drag
2002
            morph_ang,              // angle moving from CENTER
2003
            morph_speed,            // speed of movement
2004
            morph_dist_max,         // radius boundry
2005
            morph_rand_freq,        // freq of dir change
2006
            morph_dist,             // dist from CENTER
2007
            morph_z_speed,          // z speed for morph point
2008
            morph_xoff,             // save xoff from center
2009
            morph_yoff,             // save yoff from center
2010
 
2011
    //scale_rand_reverse,            // random at random interval
2012
    // limit rotation angle
2013
            limit_ang_center, // for limiting the angle of turning - turrets etc
2014
            limit_ang_delta; //
2015
};
2016
 
2017
#define MAX_SECTOR_OBJECTS 20
2018
 
2019
#define SOBJ_SPEED_UP           BIT(0)
2020
#define SOBJ_SLOW_DOWN          BIT(1)
2021
#define SOBJ_ZUP                BIT(2)
2022
#define SOBJ_ZDOWN              BIT(3)
2023
#define SOBJ_ZDIFF_MODE         BIT(4)
2024
#define SOBJ_MOVE_VERTICAL      BIT(5) // for sprite objects - move straight up/down
2025
#define SOBJ_ABSOLUTE_ANGLE     BIT(7)
2026
#define SOBJ_SPRITE_OBJ         BIT(8)
2027
#define SOBJ_DONT_ROTATE        BIT(9)
2028
#define SOBJ_WAIT_FOR_EVENT     BIT(10)
2029
#define SOBJ_HAS_WEAPON         BIT(11)
2030
#define SOBJ_SYNC1              BIT(12) // for syncing up several SO's perfectly
2031
#define SOBJ_SYNC2              BIT(13) // for syncing up several SO's perfectly
2032
#define SOBJ_DYNAMIC            BIT(14) // denotes scaling or morphing object
2033
#define SOBJ_ZMID_FLOOR         BIT(15) // can't remember which sector objects need this
2034
// think its the bobbing and sinking ones
2035
#define SOBJ_SLIDE              BIT(16)
2036
 
2037
#define SOBJ_OPERATIONAL        BIT(17)
2038
#define SOBJ_KILLABLE           BIT(18)
2039
#define SOBJ_DIE_HARD           BIT(19)
2040
#define SOBJ_UPDATE_ONCE        BIT(20)
2041
#define SOBJ_UPDATE             BIT(21)
2042
#define SOBJ_NO_QUAKE           BIT(22)
2043
#define SOBJ_REMOTE_ONLY        BIT(23)
2044
#define SOBJ_RECT_CLIP          BIT(24)
2045
#define SOBJ_BROKEN               BIT(25)
2046
 
2047
// track set to these to tell them apart
2048
#define SO_OPERATE_TRACK_START 90
2049
#define SO_TURRET_MGUN 96 // machine gun
2050
#define SO_TURRET 97
2051
#define SO_TANK 98
2052
#define SO_SPEED_BOAT 99
2053
 
2054
extern SECTOR_OBJECT SectorObject[MAX_SECTOR_OBJECTS];
2055
 
2056
///////////////////////////////////////////////////////////////////////////////////////////
2057
//
2058
// Prototypes
2059
//
2060
///////////////////////////////////////////////////////////////////////////////////////////
2061
 
2062
ANIMATOR NullAnimator;
2063
 
5198 hendricks2 2064
void SetBorder(PLAYERp pp, int);
2065
void SetFragBar(PLAYERp pp);
5196 hendricks2 2066
int Distance(int x1, int y1, int x2, int y2);
2067
short GetDeltaAngle(short, short);
2068
 
2069
int SetActorRotation(short SpriteNum,int,int);
2070
int NewStateGroup(short SpriteNum, STATEp SpriteGroup[]);
5198 hendricks2 2071
void SectorMidPoint(short sectnum, int *xmid, int *ymid, int *zmid);
5196 hendricks2 2072
USERp SpawnUser(short SpriteNum, short id, STATEp state);
2073
 
5198 hendricks2 2074
short ActorFindTrack(short SpriteNum, int8_t player_dir, int track_type, short *track_point_num, short *track_dir);
5196 hendricks2 2075
 
2076
SECT_USERp GetSectUser(short sectnum);
2077
 
2078
short SoundDist(int x, int y, int z, int basedist);
2079
short SoundAngle(int x, int  y);
2080
//void PlaySound(int num, short angle, short vol);
2081
int PlaySound(int num, int *x, int *y, int *z, Voc3D_Flags flags);
2082
void PlayerSound(int num, int *x, int *y, int *z, Voc3D_Flags flags, PLAYERp pp);
2083
 
2084
ANIMATOR DoActorBeginJump,DoActorJump,DoActorBeginFall,DoActorFall,DoActorDeathMove;
2085
 
2086
int SpawnShrap(short,short);
2087
 
5198 hendricks2 2088
void PlayerUpdateHealth(PLAYERp pp, short value);
2089
void PlayerUpdateAmmo(PLAYERp pp, short WeaponNum, short value);
2090
void PlayerUpdateWeapon(PLAYERp pp, short WeaponNum);
2091
void PlayerUpdateKills(PLAYERp pp, short value);
2092
void PlayerUpdatePanelInfo(PLAYERp pp);
2093
void RefreshInfoLine(PLAYERp pp);
5196 hendricks2 2094
 
5198 hendricks2 2095
void DoAnim(int numtics);
5196 hendricks2 2096
void AnimDelete(int *animptr);
2097
short AnimGetGoal(int *animptr);
2098
short AnimSet(int *animptr, int thegoal, int thevel);
2099
//short AnimSetCallback(int *animptr, int thegoal, int thevel, ANIM_CALLBACKp call, ANIM_DATAp data);
2100
short AnimSetCallback(short anim_ndx, ANIM_CALLBACKp call, ANIM_DATAp data);
2101
short AnimSetVelAdj(short anim_ndx, short vel_adj);
2102
 
5198 hendricks2 2103
void EnemyDefaults(short SpriteNum, ACTOR_ACTION_SETp action, PERSONALITYp person);
5196 hendricks2 2104
 
5198 hendricks2 2105
void getzrangepoint(int x, int y, int z, short sectnum, int32_t* ceilz, int32_t* ceilhit, int32_t* florz, int32_t* florhit);
2106
int move_sprite(short spritenum, int xchange, int ychange, int zchange, int ceildist, int flordist, uint32_t cliptype, int numtics);
2107
int move_missile(short spritenum, int xchange, int ychange, int zchange, int ceildist, int flordist, uint32_t cliptype, int numtics);
2108
int DoPickTarget(SPRITEp sp, uint32_t max_delta_ang, SWBOOL skip_targets);
5196 hendricks2 2109
 
5198 hendricks2 2110
void change_sprite_stat(short, short);
2111
void SetOwner(short, short);
2112
void SetAttach(short, short);
2113
void analyzesprites(int,int,int,SWBOOL);
2114
void ChangeState(short SpriteNum, STATEp statep);
5196 hendricks2 2115
 
5198 hendricks2 2116
void UpdateSectorFAF_Connect(short SpriteNum, int newz);
5196 hendricks2 2117
#if 0
5198 hendricks2 2118
SWBOOL FAF_ConnectCeiling(short sectnum);
2119
SWBOOL FAF_ConnectFloor(short sectnum);
5196 hendricks2 2120
#else
2121
#define FAF_PLACE_MIRROR_PIC 341
2122
#define FAF_MIRROR_PIC 2356
2123
#define FAF_ConnectCeiling(sectnum) (sector[(sectnum)].ceilingpicnum == FAF_MIRROR_PIC)
2124
#define FAF_ConnectFloor(sectnum) (sector[(sectnum)].floorpicnum == FAF_MIRROR_PIC)
2125
#define FAF_ConnectArea(sectnum) (FAF_ConnectCeiling(sectnum) || FAF_ConnectFloor(sectnum))
2126
#endif
2127
void updatesectorz(int, int, int, short *);
5198 hendricks2 2128
void FAF_ConnectPlayerCeiling(PLAYERp pp);
2129
void FAF_ConnectPlayerFloor(PLAYERp pp);
2130
SWBOOL PlayerCeilingHit(PLAYERp pp, int zlimit);
2131
SWBOOL PlayerFloorHit(PLAYERp pp, int zlimit);
5196 hendricks2 2132
 
5198 hendricks2 2133
void FAFhitscan(int32_t x, int32_t y, int32_t z, int16_t sectnum,
2134
                int32_t xvect, int32_t yvect, int32_t zvect,
5202 hendricks2 2135
                hitdata_t* hitinfo, int32_t clipmask);
5196 hendricks2 2136
 
5198 hendricks2 2137
SWBOOL FAFcansee(int32_t xs, int32_t ys, int32_t zs, int16_t sects, int32_t xe, int32_t ye, int32_t ze, int16_t secte);
5196 hendricks2 2138
 
5198 hendricks2 2139
void FAFgetzrange(int32_t x, int32_t y, int32_t z, int16_t sectnum,
2140
                  int32_t* hiz, int32_t* ceilhit,
2141
                  int32_t* loz, int32_t* florhit,
2142
                  int32_t clipdist, int32_t clipmask);
5196 hendricks2 2143
 
5198 hendricks2 2144
void FAFgetzrangepoint(int32_t x, int32_t y, int32_t z, int16_t sectnum,
2145
                       int32_t* hiz, int32_t* ceilhit,
2146
                       int32_t* loz, int32_t* florhit);
5196 hendricks2 2147
 
5198 hendricks2 2148
void COVERupdatesector(int32_t x, int32_t y, int16_t* newsector);
5196 hendricks2 2149
 
5198 hendricks2 2150
void updatesectorz(int,int,int,int16_t*);
5196 hendricks2 2151
 
2152
 
2153
void short_setinterpolation(short *posptr);
2154
void short_stopinterpolation(short *posptr);
2155
void short_updateinterpolations(void);
2156
void short_dointerpolations(int smoothratio);
2157
void short_restoreinterpolations(void);
2158
 
2159
enum SoundType
2160
{
2161
    SOUND_OBJECT_TYPE,
2162
    SOUND_EVERYTHING_TYPE
2163
};
2164
 
5198 hendricks2 2165
void DoSoundSpotMatch(short match, short sound_num, short sound_type);
5196 hendricks2 2166
 
2167
#define ACTOR_GRAVITY 8
2168
 
2169
///////////////////////////////////////////////////////////////////////////////////////////
2170
//
2171
//  Externs
2172
//
2173
///////////////////////////////////////////////////////////////////////////////////////////
2174
 
5198 hendricks2 2175
extern SWBOOL ExitLevel;
2176
extern SWBOOL Warping;
2177
extern uint8_t CommPlayers;
2178
extern SWBOOL CommEnabled;
5196 hendricks2 2179
extern char CommPlayerName[];
2180
extern short Level;
2181
extern short Episode;
2182
 
2183
extern int LastFrameTics;
2184
extern char ds[];
2185
extern short Skill;
2186
extern int GodMode;
2187
 
2188
extern int x_min_bound, y_min_bound, x_max_bound, y_max_bound;
2189
 
2190
//extern unsigned char synctics, lastsynctics;
2191
extern BORDER_INFO BorderInfo;
2192
extern short snum;
2193
 
2194
extern int lockspeed,totalsynctics;
2195
 
2196
#define synctics 3
2197
#define ACTORMOVETICS (synctics<<1)
2198
#define TICSPERMOVEMENT synctics
2199
#define FAKETIMERHANDLER()  if (totalclock >= ototalclock + synctics) faketimerhandler()
2200
 
2201
// subtract value from clipdist on getzrange calls
2202
#define GETZRANGE_CLIP_ADJ 8
2203
//#define GETZRANGE_CLIP_ADJ 0
2204
 
2205
// MULTIPLAYER
2206
// VARIABLES:  (You should extern these in your game.c)
2207
/*
2208
extern short numplayers, myconnectindex;
2209
extern short connecthead, connectpoint2[MAXPLAYERS];
2210
*/
2211
extern int *lastpacket2clock;
2212
extern char username[MAXPLAYERS][50];
2213
 
2214
// save player info when moving to a new level
2215
extern USER puser[MAX_SW_PLAYERS_REG];
2216
 
2217
///////////////////////////
2218
//
2219
// TEXT PRINTING
2220
//
2221
///////////////////////////
2222
 
2223
#define TEXT_TEST_LINE (200/2)
2224
#define TEXT_XCENTER(width) ((320 - width)/2)
2225
#define TEXT_YCENTER(h) ((200 - height)/2)
2226
#define TEXT_TEST_COL(width) TEXT_XCENTER(width)
2227
#define TEXT_TEST_TIME 2
2228
 
2229
void PutStringTimer(PLAYERp pp, short x, short y, const char *string, short seconds);
2230
 
2231
///////////////////////////
2232
//
2233
// OLDER network additions
2234
//
2235
///////////////////////////
2236
 
2237
/*
2238
int initmultiplayers(int, int, int);
2239
void uninitmultiplayers(void);
2240
 
2241
void sendlogon(void);
2242
void sendlogoff(void);
2243
*/
2244
 
2245
 
2246
///////////////////////////
2247
//
2248
// RECENT network additions
2249
//
2250
///////////////////////////
2251
 
2252
extern int ototalclock, save_totalclock, gotlastpacketclock,smoothratio;
5198 hendricks2 2253
extern SWBOOL ready2send;
5196 hendricks2 2254
 
2255
// local copy of variables updated by faketimerhandler
2256
extern int locselectedgun;
2257
 
2258
//FIFO queue to hold values while faketimerhandler is called from within the drawing routing
2259
extern int movefifoplc, movefifoend[];
2260
 
2261
 
5198 hendricks2 2262
extern SWBOOL MoveSkip4, MoveSkip2, MoveSkip8;
5196 hendricks2 2263
 
2264
#define MASTER_SWITCHING 1
2265
 
2266
extern char option[];
2267
extern char keys[];
2268
 
2269
extern short screenpeek;
2270
 
2271
extern int dimensionmode, zoom;
2272
 
2273
#define STAT_DAMAGE_LIST_SIZE 20
5198 hendricks2 2274
extern int16_t StatDamageList[STAT_DAMAGE_LIST_SIZE];
5196 hendricks2 2275
 
2276
///////////////////////////////////////////////////////////////
2277
//
2278
// Stuff for player palette flashes when hurt or getting items
2279
//
2280
///////////////////////////////////////////////////////////////
2281
 
2282
#define COLOR_PAIN  128  // Light red range
2283
extern void SetFadeAmt(PLAYERp pp, short damage, unsigned char startcolor);
2284
extern void DoPaletteFlash(PLAYERp pp);
2285
extern unsigned char palette_data[256][3];
5198 hendricks2 2286
extern SWBOOL NightVision;
5196 hendricks2 2287
#endif
2288
 
7499 hendricks2 2289
int _PlayerSound(const char *file, int line, int num, int *x, int *y, int *z, Voc3D_Flags flags, PLAYERp pp);
5196 hendricks2 2290
#define PlayerSound(num, x, y, z, flags, pp) _PlayerSound(__FILE__, __LINE__, (num), (x), (y), (z), (flags), (pp))
2291
 
8281 hendricks2 2292
#define MAXSO (INT32_MAX)
5196 hendricks2 2293
 
2294
///////////////////////////////////////////////////////////////
2295
//
2296
// Stuff added by JonoF. These should get put into their own
2297
// headers and included by that which needs them.
2298
//
2299
///////////////////////////////////////////////////////////////
2300
 
2301
int PickJumpMaxSpeed(short SpriteNum, short max_speed); // ripper.c
2302
int DoRipperRipHeart(short SpriteNum);  // ripper.c
2303
int DoRipper2RipHeart(short SpriteNum); // ripper2.c
2304
int BunnyHatch2(short Weapon);  // bunny.c
5198 hendricks2 2305
int DoSkullBeginDeath(int16_t SpriteNum); // skull.c
5196 hendricks2 2306
 
2307
void AnimateCacheCursor(void);  // game.c
5198 hendricks2 2308
void MapSetAll2D(uint8_t fill);    // game.c
5196 hendricks2 2309
void TerminateGame(void);   // game.c
2310
void TerminateLevel(void);  // game.c
2311
void ResetKeys(void);   // game.c
5198 hendricks2 2312
SWBOOL KeyPressed(void);  // game.c
5196 hendricks2 2313
void drawoverheadmap(int cposx,int cposy,int czoom,short cang); // game.c
2314
void COVERsetbrightness(int bright, unsigned char *pal);    // game.c
2315
void DrawMenuLevelScreen(void); // game.c
5198 hendricks2 2316
void DebugWriteString(char *string);    // game.c
2317
void ManualPlayerInsert(PLAYERp pp);    // game.c
5196 hendricks2 2318
 
5198 hendricks2 2319
void SetRedrawScreen(PLAYERp pp);   // border.c
5196 hendricks2 2320
void SetupAspectRatio(void);    // border.c
5198 hendricks2 2321
void ClearStartMost(void);  // border.c
2322
void SetCrosshair(void);    // border.c
5196 hendricks2 2323
 
2324
void initsynccrc(void);     // sync.c
2325
void demosync_record(void); // sync.c
2326
void demosync_test(int cnt);    // sync.c
2327
void getsyncstat(void); // sync.c
2328
void SyncStatMessage(void); // sync.c
2329
 
2330
void drawscreen(PLAYERp pp);    // draw.c
2331
void post_analyzesprites(void); // draw.c
2332
int COVERsetgamemode(int mode, int xdim, int ydim, int bpp);    // draw.c
5198 hendricks2 2333
void ScreenCaptureKeys(void);   // draw.c
5196 hendricks2 2334
 
8694 ny00123 2335
int minigametext(int x,int y,const char *t,short dabits);  // jplayer.c
5196 hendricks2 2336
void computergetinput(int snum,SW_PACKET *syn); // jplayer.c
2337
 
2338
void DrawOverlapRoom(int tx,int ty,int tz,short tang,int thoriz,short tsectnum);    // rooms.c
2339
void SetupMirrorTiles(void);    // rooms.c
5198 hendricks2 2340
SWBOOL FAF_Sector(short sectnum); // rooms.c
5196 hendricks2 2341
int GetZadjustment(short sectnum,short hitag);  // rooms.c
2342
 
2343
void TermSetup(void);   // swconfig.c
2344
 
2345
void InitSetup(void);   // setup.c
2346
 
7499 hendricks2 2347
void LoadKVXFromScript(const char *filename); // scrip2.c
2348
void LoadPLockFromScript(const char *filename);   // scrip2.c
2349
void LoadCustomInfoFromScript(const char *filename);  // scrip2.c
5196 hendricks2 2350
 
2351
void EveryCheatToggle(PLAYERp pp,char *cheat_string);   // cheats.c
2352
 
2353
int PlayerInitChemBomb(PLAYERp pp); // jweapon.c
2354
int PlayerInitFlashBomb(PLAYERp pp);    // jweapon.c
2355
int PlayerInitCaltrops(PLAYERp pp); // jweapon.c
5198 hendricks2 2356
int InitPhosphorus(int16_t SpriteNum);    // jweapon.c
5196 hendricks2 2357
void SpawnFloorSplash(short SpriteNum); // jweapon.c
2358
 
2359
int SaveGame(short save_num);   // save.c
2360
int LoadGame(short save_num);   // save.c
2361
int LoadGameFullHeader(short save_num, char *descr, short *level, short *skill);    // save,c
2362
void LoadGameDescr(short save_num, char *descr);    // save.c
2363
 
2364
void SetRotatorActive(short SpriteNum); // rotator.c
2365
 
5198 hendricks2 2366
SWBOOL VatorSwitch(short match, short setting); // vator.c
2367
void MoveSpritesWithSector(short sectnum,int z_amt,SWBOOL type);  // vator.c
5196 hendricks2 2368
void SetVatorActive(short SpriteNum);   // vator.c
2369
 
8694 ny00123 2370
short DoSpikeMatch(short match); // spike.c
5196 hendricks2 2371
void SpikeAlign(short SpriteNum);   // spike.c
2372
 
2373
short DoSectorObjectSetScale(short match);  // morph.c
2374
short DoSOevent(short match,short state);   // morph.c
2375
void SOBJ_AlignCeilingToPoint(SECTOR_OBJECTp sop,int x,int y,int z);    // morph.c
2376
void SOBJ_AlignFloorToPoint(SECTOR_OBJECTp sop,int x,int y,int z);  // morph.c
2377
void ScaleSectorObject(SECTOR_OBJECTp sop); // morph.c
2378
void MorphTornado(SECTOR_OBJECTp sop);  // morph.c
2379
void MorphFloor(SECTOR_OBJECTp sop);    // morph.c
2380
void ScaleRandomPoint(SECTOR_OBJECTp sop,short k,short ang,int x,int y,int *dx,int *dy);    // morph.c
2381
 
2382
void CopySectorMatch(short match);  // copysect.c
2383
 
2384
int DoWallMoveMatch(short match);   // wallmove.c
2385
int DoWallMove(SPRITEp sp); // wallmove.c
5198 hendricks2 2386
SWBOOL CanSeeWallMove(SPRITEp wp,short match);    // wallmove.c
5196 hendricks2 2387
 
8694 ny00123 2388
short DoSpikeOperate(short sectnum); // spike.c
5196 hendricks2 2389
void SetSpikeActive(short SpriteNum);   // spike.c
2390
 
2391
#define NTAG_SEARCH_LO 1
2392
#define NTAG_SEARCH_HI 2
2393
#define NTAG_SEARCH_LO_HI 3
2394
 
2395
int COVERinsertsprite(short sectnum, short statnum);   //returns (short)spritenum;
2396
 
2397
void AudioUpdate(void); // stupid
8337 hendricks2 2398
 
2399
extern short LastSaveNum;
2400
extern short QuickLoadNum;
2401
void LoadSaveMsg(const char *msg);
2402
SWBOOL DoQuickSave(short save_num);
2403
SWBOOL DoQuickLoad(void);