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