]> icculus.org git repositories - theoddone33/hheretic.git/blob - include/doomdef.h
Misc changes
[theoddone33/hheretic.git] / include / doomdef.h
1
2 // DoomDef.h
3
4 #ifndef __DOOMDEF__
5 #define __DOOMDEF__
6 #include <stdio.h>
7 #include <string.h>
8 #ifdef __WATCOMC__
9 #include <malloc.h>
10 #define strcasecmp strcmpi
11 #define strncasecmp strnicmp
12 #endif
13
14 #include "config.h"
15
16 #define VERSION 130
17 #define VERSION_TEXT "v1.3"
18 #define HHERETIC_VERSION "0.1"
19
20 // if rangecheck is undefined, most parameter validation debugging code
21 // will not be compiled
22 //#define RANGECHECK
23
24 // all external data is defined here
25 #include "doomdata.h"
26
27 // all important printed strings
28 #include "dstrings.h"
29
30 // header generated by multigen utility
31 #include "info.h"
32
33 extern byte *destview, *destscreen;     // PC direct to screen pointers
34
35 //
36 // most key data are simple ascii (uppercased)
37 //
38 #define KEY_RIGHTARROW          0xae
39 #define KEY_LEFTARROW           0xac
40 #define KEY_UPARROW                     0xad
41 #define KEY_DOWNARROW           0xaf
42 #define KEY_ESCAPE                      27
43 #define KEY_ENTER                       13
44 #define KEY_F1                          (0x80+0x3b)
45 #define KEY_F2                          (0x80+0x3c)
46 #define KEY_F3                          (0x80+0x3d)
47 #define KEY_F4                          (0x80+0x3e)
48 #define KEY_F5                          (0x80+0x3f)
49 #define KEY_F6                          (0x80+0x40)
50 #define KEY_F7                          (0x80+0x41)
51 #define KEY_F8                          (0x80+0x42)
52 #define KEY_F9                          (0x80+0x43)
53 #define KEY_F10                         (0x80+0x44)
54 #define KEY_F11                         (0x80+0x57)
55 #define KEY_F12                         (0x80+0x58)
56
57 #define KEY_BACKSPACE           127
58 #define KEY_PAUSE                       0xff
59
60 #define KEY_EQUALS                      0x3d
61 #define KEY_MINUS                       0x2d
62
63 #define KEY_RSHIFT                      (0x80+0x36)
64 #define KEY_RCTRL                       (0x80+0x1d)
65 #define KEY_RALT                        (0x80+0x38)
66
67 #define KEY_LALT                        KEY_RALT
68
69
70
71 #define MAXCHAR ((char)0x7f)
72 #define MAXSHORT ((short)0x7fff)
73 #define MAXINT  ((int)0x7fffffff)       /* max pos 32-bit int */
74 #define MAXLONG ((long)0x7fffffff)
75
76 #define MINCHAR ((char)0x80)
77 #define MINSHORT ((short)0x8000)
78 #define MININT  ((int)0x80000000)       /* max negative 32-bit integer */
79 #define MINLONG ((long)0x80000000)
80
81 #define FINEANGLES                      8192
82 #define FINEMASK                        (FINEANGLES-1)
83 #define ANGLETOFINESHIFT        19      // 0x100000000 to 0x2000
84
85 #define SAVEGAMENAME "hticsav"
86 #define SAVEGAMENAMECD "c:\\heretic.cd\\hticsav"
87
88 /*
89 ===============================================================================
90
91                                                 GLOBAL TYPES
92
93 ===============================================================================
94 */
95
96 #define NUMARTIFCTS     28
97 #define MAXPLAYERS      4
98 #define TICRATE         35                      // number of tics / second
99 #define TICSPERSEC      35
100
101 #define FRACBITS                16
102 #define FRACUNIT                (1<<FRACBITS)
103 typedef int fixed_t;
104
105 #define ANGLE_1         0x01000000
106 #define ANGLE_45        0x20000000
107 #define ANGLE_90        0x40000000
108 #define ANGLE_180       0x80000000
109 #define ANGLE_MAX       0xffffffff
110
111 #define ANG45   0x20000000
112 #define ANG90   0x40000000
113 #define ANG180  0x80000000
114 #define ANG270  0xc0000000
115
116 typedef unsigned angle_t;
117
118 typedef enum
119 {
120         sk_baby,
121         sk_easy,
122         sk_medium,
123         sk_hard,
124         sk_nightmare
125 } skill_t;
126
127 typedef enum
128 {
129         ev_keydown,
130         ev_keyup,
131         ev_mouse,
132         ev_joystick
133 } evtype_t;
134
135 typedef struct
136 {
137         evtype_t        type;
138         int                     data1;          // keys / mouse/joystick buttons
139         int                     data2;          // mouse/joystick x move
140         int                     data3;          // mouse/joystick y move
141 } event_t;
142
143 typedef struct
144 {
145         char            forwardmove;            // *2048 for move
146         char            sidemove;                       // *2048 for move
147         short           angleturn;                      // <<16 for angle delta
148         short           consistancy;            // checks for net game
149         byte            chatchar;
150         byte            buttons;
151         byte            lookfly;                        // look/fly up/down/centering
152         byte            arti;                           // artitype_t to use
153 } ticcmd_t;
154
155 #define BT_ATTACK               1
156 #define BT_USE                  2
157 #define BT_CHANGE               4                       // if true, the next 3 bits hold weapon num
158 #define BT_WEAPONMASK   (8+16+32)
159 #define BT_WEAPONSHIFT  3
160
161 #define BT_SPECIAL              128                     // game events, not really buttons
162 #define BTS_SAVEMASK    (4+8+16)
163 #define BTS_SAVESHIFT   2
164 #define BT_SPECIALMASK  3
165 #define BTS_PAUSE               1                       // pause the game
166 #define BTS_SAVEGAME    2                       // save the game at each console
167 // savegame slot numbers occupy the second byte of buttons
168
169 typedef enum
170 {
171         GS_LEVEL,
172         GS_INTERMISSION,
173         GS_FINALE,
174         GS_DEMOSCREEN
175 } gamestate_t;
176
177 typedef enum
178 {
179         ga_nothing,
180         ga_loadlevel,
181         ga_newgame,
182         ga_loadgame,
183         ga_savegame,
184         ga_playdemo,
185         ga_completed,
186         ga_victory,
187         ga_worlddone,
188         ga_screenshot
189 } gameaction_t;
190
191 typedef enum
192 {
193         wipe_0,
194         wipe_1,
195         wipe_2,
196         wipe_3,
197         wipe_4,
198         NUMWIPES,
199         wipe_random
200 } wipe_t;
201
202 /*
203 ===============================================================================
204
205                                                         MAPOBJ DATA
206
207 ===============================================================================
208 */
209
210 // think_t is a function pointer to a routine to handle an actor
211 typedef void (*think_t) ();
212
213 typedef struct thinker_s
214 {
215         struct          thinker_s       *prev, *next;
216         think_t         function;
217 } thinker_t;
218
219 struct player_s;
220
221 typedef struct mobj_s
222 {
223         thinker_t               thinker;                        // thinker links
224
225 // info for drawing
226         fixed_t                 x,y,z;
227         struct  mobj_s  *snext, *sprev;         // links in sector (if needed)
228         angle_t                 angle;
229         spritenum_t             sprite;                         // used to find patch_t and flip value
230         int                             frame;                          // might be ord with FF_FULLBRIGHT
231
232 // interaction info
233         struct mobj_s   *bnext, *bprev;         // links in blocks (if needed)
234         struct subsector_s      *subsector;
235         fixed_t                 floorz, ceilingz;       // closest together of contacted secs
236         fixed_t                 radius, height;         // for movement checking
237         fixed_t                 momx, momy, momz;       // momentums
238
239         int                             validcount;                     // if == validcount, already checked
240
241         mobjtype_t              type;
242         mobjinfo_t              *info;                          // &mobjinfo[mobj->type]
243         int                             tics;                           // state tic counter
244         state_t                 *state;
245         int                             damage;                 // For missiles
246         int                             flags;
247         int                             flags2;                 // Heretic flags
248         int                             special1;               // Special info
249         int                             special2;               // Special info
250         int                             health;
251         int                             movedir;                // 0-7
252         int                             movecount;              // when 0, select a new dir
253         struct mobj_s   *target;                // thing being chased/attacked (or NULL)
254                                                                         // also the originator for missiles
255         int                             reactiontime;   // if non 0, don't attack yet
256                                                                         // used by player to freeze a bit after
257                                                                         // teleporting
258         int                             threshold;              // if >0, the target will be chased
259                                                                         // no matter what (even if shot)
260         struct player_s *player;                // only valid if type == MT_PLAYER
261         int                             lastlook;               // player number last looked for
262
263         mapthing_t              spawnpoint;             // for nightmare respawn
264 } mobj_t;
265
266 // each sector has a degenmobj_t in it's center for sound origin purposes
267 typedef struct
268 {
269         thinker_t               thinker;                // not used for anything
270         fixed_t                 x,y,z;
271 } degenmobj_t;
272
273 // Most damage defined using HITDICE
274 #define HITDICE(a) ((1+(P_Random()&7))*a)
275
276 //
277 // frame flags
278 //
279 #define FF_FULLBRIGHT   0x8000          // flag in thing->frame
280 #define FF_FRAMEMASK    0x7fff
281
282 // --- mobj.flags ---
283
284 #define MF_SPECIAL              1                       // call P_SpecialThing when touched
285 #define MF_SOLID                2
286 #define MF_SHOOTABLE    4
287 #define MF_NOSECTOR             8                       // don't use the sector links
288                                                                         // (invisible but touchable)
289 #define MF_NOBLOCKMAP   16                      // don't use the blocklinks
290                                                                         // (inert but displayable)
291 #define MF_AMBUSH               32
292 #define MF_JUSTHIT              64                      // try to attack right back
293 #define MF_JUSTATTACKED 128                     // take at least one step before attacking
294 #define MF_SPAWNCEILING 256                     // hang from ceiling instead of floor
295 #define MF_NOGRAVITY    512                     // don't apply gravity every tic
296
297 // movement flags
298 #define MF_DROPOFF              0x400           // allow jumps from high places
299 #define MF_PICKUP               0x800           // for players to pick up items
300 #define MF_NOCLIP               0x1000          // player cheat
301 #define MF_SLIDE                0x2000          // keep info about sliding along walls
302 #define MF_FLOAT                0x4000          // allow moves to any height, no gravity
303 #define MF_TELEPORT             0x8000          // don't cross lines or look at heights
304 #define MF_MISSILE              0x10000         // don't hit same species, explode on block
305
306 #define MF_DROPPED              0x20000         // dropped by a demon, not level spawned
307 #define MF_SHADOW               0x40000         // use fuzzy draw (shadow demons / invis)
308 #define MF_NOBLOOD              0x80000         // don't bleed when shot (use puff)
309 #define MF_CORPSE               0x100000        // don't stop moving halfway off a step
310 #define MF_INFLOAT              0x200000        // floating to a height for a move, don't
311                                                                         // auto float to target's height
312
313 #define MF_COUNTKILL    0x400000        // count towards intermission kill total
314 #define MF_COUNTITEM    0x800000        // count towards intermission item total
315
316 #define MF_SKULLFLY             0x1000000       // skull in flight
317 #define MF_NOTDMATCH    0x2000000       // don't spawn in death match (key cards)
318
319 #define MF_TRANSLATION  0xc000000       // if 0x4 0x8 or 0xc, use a translation
320 #define MF_TRANSSHIFT   26                      // table for player colormaps
321
322 // --- mobj.flags2 ---
323
324 #define MF2_LOGRAV                      0x00000001      // alternate gravity setting
325 #define MF2_WINDTHRUST          0x00000002      // gets pushed around by the wind
326                                                                                 // specials
327 #define MF2_FLOORBOUNCE         0x00000004      // bounces off the floor
328 #define MF2_THRUGHOST           0x00000008      // missile will pass through ghosts
329 #define MF2_FLY                         0x00000010      // fly mode is active
330 #define MF2_FOOTCLIP            0x00000020      // if feet are allowed to be clipped
331 #define MF2_SPAWNFLOAT          0x00000040      // spawn random float z
332 #define MF2_NOTELEPORT          0x00000080      // does not teleport
333 #define MF2_RIP                         0x00000100      // missile rips through solid
334                                                                                 // targets
335 #define MF2_PUSHABLE            0x00000200      // can be pushed by other moving
336                                                                                 // mobjs
337 #define MF2_SLIDE                       0x00000400      // slides against walls
338 #define MF2_ONMOBJ                      0x00000800      // mobj is resting on top of another
339                                                                                 // mobj
340 #define MF2_PASSMOBJ            0x00001000      // Enable z block checking.  If on,
341                                                                                 // this flag will allow the mobj to
342                                                                                 // pass over/under other mobjs.
343 #define MF2_CANNOTPUSH          0x00002000      // cannot push other pushable mobjs
344 #define MF2_FEETARECLIPPED      0x00004000      // a mobj's feet are now being cut
345 #define MF2_BOSS                        0x00008000      // mobj is a major boss
346 #define MF2_FIREDAMAGE          0x00010000      // does fire damage
347 #define MF2_NODMGTHRUST         0x00020000      // does not thrust target when
348                                                                                 // damaging
349 #define MF2_TELESTOMP           0x00040000      // mobj can stomp another
350 #define MF2_FLOATBOB            0x00080000      // use float bobbing z movement
351 #define MF2_DONTDRAW            0X00100000      // don't generate a vissprite
352
353 //=============================================================================
354 typedef enum
355 {
356         PST_LIVE,                       // playing
357         PST_DEAD,                       // dead on the ground
358         PST_REBORN                      // ready to restart
359 } playerstate_t;
360
361 // psprites are scaled shapes directly on the view screen
362 // coordinates are given for a 320*200 view screen
363 typedef enum
364 {
365         ps_weapon,
366         ps_flash,
367         NUMPSPRITES
368 } psprnum_t;
369
370 typedef struct
371 {
372         state_t *state;         // a NULL state means not active
373         int             tics;
374         fixed_t sx, sy;
375 } pspdef_t;
376
377 typedef enum
378 {
379         key_yellow,
380         key_green,
381         key_blue,
382         NUMKEYS
383 } keytype_t;
384
385 typedef enum
386 {
387         wp_staff,
388         wp_goldwand,
389         wp_crossbow,
390         wp_blaster,
391         wp_skullrod,
392         wp_phoenixrod,
393         wp_mace,
394         wp_gauntlets,
395         wp_beak,
396         NUMWEAPONS,
397         wp_nochange
398 } weapontype_t;
399
400 #define AMMO_GWND_WIMPY 10
401 #define AMMO_GWND_HEFTY 50
402 #define AMMO_CBOW_WIMPY 5
403 #define AMMO_CBOW_HEFTY 20
404 #define AMMO_BLSR_WIMPY 10
405 #define AMMO_BLSR_HEFTY 25
406 #define AMMO_SKRD_WIMPY 20
407 #define AMMO_SKRD_HEFTY 100
408 #define AMMO_PHRD_WIMPY 1
409 #define AMMO_PHRD_HEFTY 10
410 #define AMMO_MACE_WIMPY 20
411 #define AMMO_MACE_HEFTY 100
412
413 typedef enum
414 {
415         am_goldwand,
416         am_crossbow,
417         am_blaster,
418         am_skullrod,
419         am_phoenixrod,
420         am_mace,
421         NUMAMMO,
422         am_noammo // staff, gauntlets
423 } ammotype_t;
424
425 typedef struct
426 {
427         ammotype_t ammo;
428         int upstate;
429         int downstate;
430         int readystate;
431         int atkstate;
432         int holdatkstate;
433         int flashstate;
434 } weaponinfo_t;
435
436 extern weaponinfo_t wpnlev1info[NUMWEAPONS];
437 extern weaponinfo_t wpnlev2info[NUMWEAPONS];
438
439 typedef enum
440 {
441         arti_none,
442         arti_invulnerability,
443         arti_invisibility,
444         arti_health,
445         arti_superhealth,
446         arti_tomeofpower,
447         arti_torch,
448         arti_firebomb,
449         arti_egg,
450         arti_fly,
451         arti_teleport,
452         NUMARTIFACTS
453 } artitype_t;
454
455 typedef enum
456 {
457         pw_None,
458         pw_invulnerability,
459         pw_invisibility,
460         pw_allmap,
461         pw_infrared,
462         pw_weaponlevel2,
463         pw_flight,
464         pw_shield,
465         pw_health2,
466         NUMPOWERS
467 } powertype_t;
468
469 #define INVULNTICS (30*35)
470 #define INVISTICS (60*35)
471 #define INFRATICS (120*35)
472 #define IRONTICS (60*35)
473 #define WPNLEV2TICS (40*35)
474 #define FLIGHTTICS (60*35)
475
476 #define CHICKENTICS (40*35)
477
478 #define MESSAGETICS (4*35)
479 #define BLINKTHRESHOLD (4*32)
480
481 #define NUMINVENTORYSLOTS       14
482 typedef struct
483 {
484         int type;
485         int count;
486 } inventory_t;
487
488 /*
489 ================
490 =
491 = player_t
492 =
493 ================
494 */
495
496 typedef struct player_s
497 {
498         mobj_t *mo;
499         playerstate_t playerstate;
500         ticcmd_t cmd;
501
502         fixed_t         viewz;                                  // focal origin above r.z
503         fixed_t         viewheight;                             // base height above floor for viewz
504         fixed_t         deltaviewheight;                // squat speed
505         fixed_t         bob;                                    // bounded/scaled total momentum
506
507         int                     flyheight;
508         int                     lookdir;
509         boolean         centering;
510         int                     health;                                 // only used between levels, mo->health
511                                                                                 // is used during levels
512         int                     armorpoints, armortype; // armor type is 0-2
513
514         inventory_t     inventory[NUMINVENTORYSLOTS];
515         artitype_t      readyArtifact;
516         int                     artifactCount;
517         int             inventorySlotNum;
518         int                     powers[NUMPOWERS];
519         boolean         keys[NUMKEYS];
520         boolean         backpack;
521         signed int                      frags[MAXPLAYERS];              // kills of other players
522         weapontype_t    readyweapon;
523         weapontype_t    pendingweapon;          // wp_nochange if not changing
524         boolean         weaponowned[NUMWEAPONS];
525         int                     ammo[NUMAMMO];
526         int                     maxammo[NUMAMMO];
527         int                     attackdown, usedown;    // true if button down last tic
528         int                     cheats;                                 // bit flags
529
530         int                     refire;                                 // refired shots are less accurate
531
532         int                     killcount, itemcount, secretcount;              // for intermission
533         char            *message;                               // hint messages
534         int                     messageTics;                    // counter for showing messages
535         int                     damagecount, bonuscount;// for screen flashing
536         int                     flamecount;                             // for flame thrower duration
537         mobj_t          *attacker;                              // who did damage (NULL for floors)
538         int                     extralight;                             // so gun flashes light up areas
539         int                     fixedcolormap;                  // can be set to REDCOLORMAP, etc
540         int                     colormap;                               // 0-3 for which color to draw player
541         pspdef_t        psprites[NUMPSPRITES];  // view sprites (gun, etc)
542         boolean         didsecret;                              // true if secret level has been done
543         int                     chickenTics;                    // player is a chicken if > 0
544         int                     chickenPeck;                    // chicken peck countdown
545         mobj_t          *rain1;                                 // active rain maker 1
546         mobj_t          *rain2;                                 // active rain maker 2
547 } player_t;
548
549 #define CF_NOCLIP               1
550 #define CF_GODMODE              2
551 #define CF_NOMOMENTUM   4 // not really a cheat, just a debug aid
552
553
554 #define         BACKUPTICS              12              // CHANGED FROM 12 !?!?
555
556 typedef struct
557 {
558         unsigned        checksum;                                       // high bit is retransmit request
559         byte            retransmitfrom;                         // only valid if NCMD_RETRANSMIT
560         byte            starttic;
561         byte            player, numtics;
562         ticcmd_t        cmds[BACKUPTICS];
563 } doomdata_t;
564
565 typedef struct
566 {
567         long    id;
568         short   intnum;                 // DOOM executes an int to execute commands
569
570 // communication between DOOM and the driver
571         short   command;                // CMD_SEND or CMD_GET
572         short   remotenode;             // dest for send, set by get (-1 = no packet)
573         short   datalength;             // bytes in doomdata to be sent
574
575 // info common to all nodes
576         short   numnodes;               // console is allways node 0
577         short   ticdup;                 // 1 = no duplication, 2-5 = dup for slow nets
578         short   extratics;              // 1 = send a backup tic in every packet
579         short   deathmatch;             // 1 = deathmatch
580         short   savegame;               // -1 = new game, 0-5 = load savegame
581         short   episode;                // 1-3
582         short   map;                    // 1-9
583         short   skill;                  // 1-5
584
585 // info specific to this node
586         short   consoleplayer;
587         short   numplayers;
588         short   angleoffset;    // 1 = left, 0 = center, -1 = right
589         short   drone;                  // 1 = drone
590
591 // packet data to be sent
592         doomdata_t      data;
593 } doomcom_t;
594
595 #define DOOMCOM_ID              0x12345678l
596
597 extern  doomcom_t               *doomcom;
598 extern  doomdata_t              *netbuffer;             // points inside doomcom
599
600 #define MAXNETNODES             8                       // max computers in a game
601
602 #define CMD_SEND        1
603 #define CMD_GET         2
604
605 #define SBARHEIGHT      42                      // status bar height at bottom of screen
606
607
608 /*
609 ===============================================================================
610
611                                         GLOBAL VARIABLES
612
613 ===============================================================================
614 */
615
616 #define TELEFOGHEIGHT (32*FRACUNIT)
617
618 #define MAXEVENTS 64
619
620 extern event_t events[MAXEVENTS];
621 extern int eventhead;
622 extern int eventtail;
623
624 extern fixed_t finesine[5*FINEANGLES/4];
625 extern fixed_t *finecosine;
626
627 extern gameaction_t gameaction;
628
629 extern boolean paused;
630
631 extern boolean shareware; // true if main WAD is the shareware version
632 extern boolean ExtendedWAD; // true if main WAD is the extended version
633
634 extern boolean nomonsters; // checkparm of -nomonsters
635
636 extern boolean respawnparm; // checkparm of -respawn
637
638 extern boolean debugmode; // checkparm of -debug
639
640 extern boolean usergame; // ok to save / end game
641
642 extern boolean ravpic; // checkparm of -ravpic
643
644 extern boolean altpal; // checkparm to use an alternate palette routine
645
646 extern boolean cdrom; // true if cd-rom mode active ("-cdrom")
647
648 extern boolean deathmatch; // only if started as net death
649
650 extern boolean netgame; // only true if >1 player
651
652 extern boolean playeringame[MAXPLAYERS];
653
654 extern int consoleplayer; // player taking events and displaying
655
656 extern int displayplayer;
657
658 extern int viewangleoffset;     // ANG90 = left side, ANG270 = right
659
660 extern player_t players[MAXPLAYERS];
661
662 extern  boolean         singletics;                     // debug flag to cancel adaptiveness
663
664 extern boolean DebugSound; // debug flag for displaying sound info
665
666 extern  int                     maxammo[NUMAMMO];
667
668 extern  boolean         demoplayback;
669 extern  int                     skytexture;
670
671 extern  gamestate_t     gamestate;
672 extern  skill_t         gameskill;
673 extern  boolean         respawnmonsters;
674 extern  int                     gameepisode;
675 extern  int                     gamemap;
676 extern  int                     prevmap;
677 extern  int                     totalkills, totalitems, totalsecret;    // for intermission
678 extern  int                     levelstarttic;          // gametic at level start
679 extern  int                     leveltime;                      // tics in game play for par
680
681 extern  ticcmd_t        netcmds[MAXPLAYERS][BACKUPTICS];
682 extern int ticdup;
683
684 #define MAXNETNODES             8
685 extern  ticcmd_t                localcmds[BACKUPTICS];
686 extern int rndindex;
687 extern int gametic, maketic;
688 extern  int             nettics[MAXNETNODES];
689
690 #define SAVEGAMESIZE 0x30000
691 #define SAVESTRINGSIZE 24
692 extern byte *savebuffer;
693 extern byte *save_p;
694
695 extern mapthing_t *deathmatch_p;
696 extern mapthing_t deathmatchstarts[10];
697 extern mapthing_t playerstarts[MAXPLAYERS];
698
699 extern int viewwindowx;
700 extern int viewwindowy;
701 extern int viewwidth;
702 extern int scaledviewwidth;
703 extern int viewheight;
704
705 extern int mouseSensitivity;
706
707 extern boolean precache; // if true, load all graphics at level load
708
709 extern byte *screen; // off screen work buffer, from V_video.c
710
711 extern boolean singledemo; // quit after playing a demo from cmdline
712
713 extern FILE *debugfile;
714 extern int bodyqueslot;
715 extern skill_t startskill;
716 extern int startepisode;
717 extern int startmap;
718 extern boolean autostart;
719
720 /*
721 ===============================================================================
722
723                                         GLOBAL FUNCTIONS
724
725 ===============================================================================
726 */
727
728
729 fixed_t FixedMul (fixed_t a, fixed_t b);
730 fixed_t FixedDiv (fixed_t a, fixed_t b);
731 fixed_t FixedDiv2 (fixed_t a, fixed_t b);
732
733 #ifdef __WATCOMC__
734 #pragma aux FixedMul =  \
735         "imul ebx",                     \
736         "shrd eax,edx,16"       \
737         parm    [eax] [ebx] \
738         value   [eax]           \
739         modify exact [eax edx]
740
741 #pragma aux FixedDiv2 = \
742         "cdq",                          \
743         "shld edx,eax,16",      \
744         "sal eax,16",           \
745         "idiv ebx"                      \
746         parm    [eax] [ebx] \
747         value   [eax]           \
748         modify exact [eax edx]
749 #endif
750
751 #ifdef __BIG_ENDIAN__
752 short ShortSwap(short);
753 long LongSwap(long);
754 #define SHORT(x)        ShortSwap(x)
755 #define LONG(x)         LongSwap(x)
756 #else
757 #define SHORT(x)        (x)
758 #define LONG(x)         (x)
759 #endif
760
761
762 //-----------
763 //MEMORY ZONE
764 //-----------
765 // tags < 100 are not overwritten until freed
766 #define PU_STATIC               1                       // static entire execution time
767 #define PU_SOUND                2                       // static while playing
768 #define PU_MUSIC                3                       // static while playing
769 #define PU_DAVE                 4                       // anything else Dave wants static
770 #define PU_LEVEL                50                      // static until level exited
771 #define PU_LEVSPEC              51                      // a special thinker in a level
772 // tags >= 100 are purgable whenever needed
773 #define PU_PURGELEVEL   100
774 #define PU_CACHE                101
775
776 void    Z_Init (void);
777 void    *Z_Malloc (int size, int tag, void *ptr);
778 void    Z_Free (void *ptr);
779 void    Z_FreeTags (int lowtag, int hightag);
780 void    Z_DumpHeap (int lowtag, int hightag);
781 void    Z_FileDumpHeap (FILE *f);
782 void    Z_CheckHeap (void);
783 void    Z_ChangeTag2 (void *ptr, int tag);
784 int     Z_FreeMemory (void);
785 void    Z_Shutdown (void);
786
787 extern boolean MallocFailureOk;
788
789 typedef struct memblock_s
790 {
791         int                     size;           // including the header and possibly tiny fragments
792         void            **user;         // NULL if a free block
793         int                     tag;            // purgelevel
794         int                     id;                     // should be ZONEID
795         struct memblock_s       *next, *prev;
796 } memblock_t;
797
798 #define Z_ChangeTag(p,t) \
799 { \
800 if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \
801         I_Error("Z_CT at "__FILE__":%i",__LINE__); \
802 Z_ChangeTag2(p,t); \
803 };
804
805 //-------
806 //WADFILE
807 //-------
808 typedef struct
809 {
810         char            name[8];
811         int                     handle,position,size;
812 } lumpinfo_t;
813
814 extern lumpinfo_t *lumpinfo;
815 extern  int                     numlumps;
816
817 void    W_InitMultipleFiles (char **filenames);
818
819 int             W_CheckNumForName (char *name);
820 int             W_GetNumForName (char *name);
821
822 int             W_LumpLength (int lump);
823 void    W_ReadLump (int lump, void *dest);
824
825 void    *W_CacheLumpNum (int lump, int tag);
826 void    *W_CacheLumpName (char *name, int tag);
827 void    W_Shutdown (void);
828
829
830
831 //----------
832 //BASE LEVEL
833 //----------
834 void D_DoomMain (void);
835 void IncThermo(void);
836 void InitThermo(int max);
837 void tprintf(char *string, int initflag);
838 // not a globally visible function, just included for source reference
839 // calls all startup code
840 // parses command line options
841 // if not overrided, calls N_AdvanceDemo
842
843 void D_DoomLoop (void);
844 // not a globally visible function, just included for source reference
845 // called by D_DoomMain, never exits
846 // manages timing and IO
847 // calls all ?_Responder, ?_Ticker, and ?_Drawer functions
848 // calls I_GetTime, I_StartFrame, and I_StartTic
849
850 void D_PostEvent (event_t *ev);
851 // called by IO functions when input is detected
852
853 void NetUpdate (void);
854 // create any new ticcmds and broadcast to other players
855
856 void D_QuitNetGame (void);
857 // broadcasts special packets to other players to notify of game exit
858
859 void TryRunTics (void);
860
861 //---------
862 //SYSTEM IO
863 //---------
864 #if 1
865 #define SCREENWIDTH             320
866 #define SCREENHEIGHT    200
867 #else
868 #define SCREENWIDTH             560
869 #define SCREENHEIGHT    375
870 #endif
871
872 byte *I_ZoneBase (int *size);
873 // called by startup code to get the ammount of memory to malloc
874 // for the zone management
875
876 int I_GetTime (void);
877 // called by D_DoomLoop
878 // returns current time in tics
879
880 void I_StartFrame (void);
881 // called by D_DoomLoop
882 // called before processing any tics in a frame (just after displaying a frame)
883 // time consuming syncronous operations are performed here (joystick reading)
884 // can call D_PostEvent
885
886 void I_StartTic (void);
887 // called by D_DoomLoop
888 // called before processing each tic in a frame
889 // quick syncronous operations are performed here
890 // can call D_PostEvent
891
892 // asyncronous interrupt functions should maintain private ques that are
893 // read by the syncronous functions to be converted into events
894
895 void I_Init (void);
896 // called by D_DoomMain
897 // determines the hardware configuration and sets up the video mode
898
899 void I_InitGraphics (void);
900
901 void I_InitNetwork (void);
902 void I_NetCmd (void);
903
904 void I_Error (char *error, ...);
905 // called by anything that can generate a terminal error
906 // bad exit with diagnostic message
907
908 void I_Quit (void);
909 // called by M_Responder when quit is selected
910 // clean exit, displays sell blurb
911
912 void I_SetPalette (byte *palette);
913 // takes full 8 bit values
914
915 void I_Update(void);
916 // Copy buffer to video
917
918 void I_WipeUpdate(wipe_t wipe);
919 // Copy buffer to video with wipe effect
920
921 void I_WaitVBL(int count);
922 // wait for vertical retrace or pause a bit
923
924 void I_BeginRead (void);
925 void I_EndRead (void);
926
927 byte    *I_AllocLow (int length);
928 // allocates from low memory under dos, just mallocs under unix
929
930 void I_Tactile (int on, int off, int total);
931
932 extern boolean useexterndriver;
933
934 #define EBT_FIRE                        1
935 #define EBT_OPENDOOR            2
936 #define EBT_SPEED                       4
937 #define EBT_STRAFE                      8
938 #define EBT_MAP                         0x10
939 #define EBT_INVENTORYLEFT       0x20
940 #define EBT_INVENTORYRIGHT      0x40
941 #define EBT_USEARTIFACT         0x80
942 #define EBT_FLYDROP                     0x100
943 #define EBT_CENTERVIEW          0x200
944 #define EBT_PAUSE                       0x400
945 #define EBT_WEAPONCYCLE         0x800
946
947 typedef struct
948 {
949         short vector; // Interrupt vector
950         
951         signed char moveForward; // forward/backward (maxes at 50)
952         signed char moveSideways; // strafe (maxes at 24)
953         short angleTurn; // turning speed (640 [slow] 1280 [fast])
954         short angleHead; // head angle (+2080 [left] : 0 [center] : -2048 [right])
955         signed char pitch; // look up/down (-110 : +90)
956         signed char flyDirection; // flyheight (+1/-1)
957         unsigned short buttons; // EBT_* flags
958 } externdata_t;
959
960 //----
961 //GAME
962 //----
963
964 void G_DeathMatchSpawnPlayer (int playernum);
965
966 void G_InitNew (skill_t skill, int episode, int map);
967
968 void G_DeferedInitNew (skill_t skill, int episode, int map);
969 // can be called by the startup code or M_Responder
970 // a normal game starts at map 1, but a warp test can start elsewhere
971
972 void G_DeferedPlayDemo (char *demo);
973
974 void G_LoadGame (char *name);
975 // can be called by the startup code or M_Responder
976 // calls P_SetupLevel or W_EnterWorld
977 void G_DoLoadGame (void);
978
979 void G_SaveGame (int slot, char *description);
980 // called by M_Responder
981
982 // Support routines for saving games
983 void SV_Open(char *fileName);
984 void SV_Close(char *fileName);
985 void SV_Write(void *buffer, int size);
986 void SV_WriteByte(byte val);
987 void SV_WriteWord(unsigned short val);
988 void SV_WriteLong(unsigned int val);
989
990 void G_RecordDemo (skill_t skill, int numplayers, int episode
991         , int map, char *name);
992 // only called by startup code
993
994 void G_PlayDemo (char *name);
995 void G_TimeDemo (char *name);
996
997 void G_ExitLevel (void);
998 void G_SecretExitLevel (void);
999
1000 void G_WorldDone (void);
1001
1002 void G_Ticker (void);
1003 boolean G_Responder (event_t *ev);
1004
1005 void G_ScreenShot (void);
1006
1007 //-----
1008 //PLAY
1009 //-----
1010
1011 void P_Ticker (void);
1012 // called by C_Ticker
1013 // can call G_PlayerExited
1014 // carries out all thinking of monsters and players
1015
1016 void P_SetupLevel (int episode, int map, int playermask, skill_t skill);
1017 // called by W_Ticker
1018
1019 void P_Init (void);
1020 // called by startup code
1021
1022 void P_ArchivePlayers (void);
1023 void P_UnArchivePlayers (void);
1024 void P_ArchiveWorld (void);
1025 void P_UnArchiveWorld (void);
1026 void P_ArchiveThinkers (void);
1027 void P_UnArchiveThinkers (void);
1028 void P_ArchiveSpecials (void);
1029 void P_UnArchiveSpecials (void);
1030 // load / save game routines
1031
1032
1033 //-------
1034 //REFRESH
1035 //-------
1036
1037 extern boolean setsizeneeded;
1038
1039 extern boolean BorderNeedRefresh;
1040 extern boolean BorderTopRefresh;
1041
1042 extern int UpdateState;
1043 // define the different areas for the dirty map
1044 #define I_NOUPDATE      0
1045 #define I_FULLVIEW      1
1046 #define I_STATBAR       2
1047 #define I_MESSAGES      4
1048 #define I_FULLSCRN      8
1049
1050 void R_RenderPlayerView (player_t *player);
1051 // called by G_Drawer
1052
1053 void R_Init (void);
1054 // called by startup code
1055
1056 void R_DrawViewBorder (void);
1057 void R_DrawTopBorder (void);
1058 // if the view size is not full screen, draws a border around it
1059
1060 void R_SetViewSize (int blocks, int detail);
1061 // called by M_Responder
1062
1063 int     R_FlatNumForName (char *name);
1064
1065 int     R_TextureNumForName (char *name);
1066 int     R_CheckTextureNumForName (char *name);
1067 // called by P_Ticker for switches and animations
1068 // returns the texture number for the texture name
1069
1070
1071 //----
1072 //MISC
1073 //----
1074 extern  int             myargc;
1075 extern  char    **myargv;
1076
1077 int     M_CheckParm (char *check);
1078 // returns the position of the given parameter in the arg list (0 if not found)
1079
1080 boolean M_ValidEpisodeMap(int episode, int map);
1081 // returns true if the episode/map combo is valid for the current
1082 // game configuration
1083
1084 void M_ForceUppercase(char *text);
1085 // Changes a string to uppercase
1086
1087 int M_Random (void);
1088 // returns a number from 0 to 255
1089 int P_Random (void);
1090 // as M_Random, but used only by the play simulation
1091
1092 void M_ClearRandom (void);
1093 // fix randoms for demos
1094
1095 void M_FindResponseFile(void);
1096
1097 void M_ClearBox (fixed_t *box);
1098 void M_AddToBox (fixed_t *box, fixed_t x, fixed_t y);
1099 // bounding box functions
1100
1101 boolean M_WriteFile (char const *name, void *source, int length);
1102 int M_ReadFile (char const *name, byte **buffer);
1103
1104 void M_ScreenShot (void);
1105
1106 void M_LoadDefaults (void);
1107
1108 void M_SaveDefaults (void);
1109
1110 int M_DrawText (int x, int y, boolean direct, char *string);
1111
1112 //----------------------
1113 // Interlude (IN_lude.c)
1114 //----------------------
1115
1116 extern boolean intermission;
1117
1118 void IN_Start(void);
1119 void IN_Ticker(void);
1120 void IN_Drawer(void);
1121
1122 //----------------------
1123 // Chat mode (CT_chat.c)
1124 //----------------------
1125
1126 void CT_Init(void);
1127 void CT_Drawer(void);
1128 boolean CT_Responder(event_t *ev);
1129 void CT_Ticker(void);
1130 char CT_dequeueChatChar(void);
1131
1132 extern boolean chatmodeon;
1133 extern boolean ultimatemsg;
1134
1135 //--------------------
1136 // Finale (F_finale.c)
1137 //--------------------
1138
1139 void F_Drawer(void);
1140 void F_Ticker(void);
1141 void F_StartFinale(void);
1142
1143 //----------------------
1144 // STATUS BAR (SB_bar.c)
1145 //----------------------
1146
1147 extern int SB_state;
1148 void SB_Init(void);
1149 boolean SB_Responder(event_t *event);
1150 void SB_Ticker(void);
1151 void SB_Drawer(void);
1152
1153 //-----------------
1154 // MENU (MN_menu.c)
1155 //-----------------
1156
1157 void MN_Init(void);
1158 void MN_ActivateMenu(void);
1159 void MN_DeactivateMenu(void);
1160 boolean MN_Responder(event_t *event);
1161 void MN_Ticker(void);
1162 void MN_Drawer(void);
1163 void MN_DrTextA(char *text, int x, int y);
1164 int MN_TextAWidth(char *text);
1165 void MN_DrTextB(char *text, int x, int y);
1166 int MN_TextBWidth(char *text);
1167
1168 //------
1169 // VIDEO
1170 //------
1171
1172 extern int dirtybox[4];
1173 extern byte gammatable[5][256];
1174 extern int usegamma;
1175
1176 void V_Init(void); // Allocates buffer screens, call before R_Init
1177 void V_DrawPatch(int x, int y, patch_t *patch);
1178 void V_DrawFuzzPatch(int x, int y, patch_t *patch);
1179 void V_DrawShadowedPatch(int x, int y, patch_t *patch);
1180 void V_DrawRawScreen(byte *raw);
1181
1182 #include "sounds.h"
1183
1184 #ifdef RENDER3D
1185 #define FIX2FLT(x)      ((float)((x)>>FRACBITS) + (float)((x)&(FRACUNIT-1)) / (float)(FRACUNIT))
1186 #define Q_FIX2FLT(x)    ((float)((x)>>FRACBITS))
1187 #endif
1188
1189 #endif // __DOOMDEF__