1 /*
2 Copyright (C) 1994-1995 Apogee Software, Ltd.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 #ifndef _rt_def_public
21 #define _rt_def_public
22 
23 
24 // RT_DEF.H Zee big one
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "develop.h"
29 #define SAVE_SCREEN  1
30 
31 #if PLATFORM_UNIX
32 #include <unistd.h>
33 #include <sys/types.h>
34 #include <limits.h>
35 #include <dirent.h>
36 #include <ctype.h>
37 #endif
38 
39 #if (defined _MSC_VER)
40 /* __int64 is built in. */
41 #include <malloc.h>
42 #include <fcntl.h>
43 #include <io.h>
44 //#define alloca(x) _alloca(x)
45 #define access(x, y) _access(x, y)
46 #define F_OK  0
47 #elif (defined __GNUC__)
48 #define __int64 long long
49 #else
50 #error please define your platform.
51 #endif
52 
53 #if PLATFORM_DOS || PLATFORM_WIN32
54 #define PATH_SEP_CHAR '\\'
55 #define PATH_SEP_STR  "\\"
56 #elif PLATFORM_UNIX
57 #define PATH_SEP_CHAR '/'
58 #define PATH_SEP_STR  "/"
59 #define ROOTDIR       "/"
60 #define CURDIR        "./"
61 #elif PLATFORM_MACCLASSIC
62 #define PATH_SEP_CHAR ':'
63 #define PATH_SEP_STR  ":"
64 #else
65 #error please define your platform.
66 #endif
67 
68 #if (!defined MAX_PATH)
69   #if (defined MAXPATHLEN)
70     #define MAX_PATH MAXPATHLEN
71   #elif (defined PATH_MAX)
72     #define MAX_PATH PATH_MAX
73   #else
74     #define MAX_PATH 256
75   #endif
76 #endif
77 
78 //
79 //
80 //
81 //***************************************************************************
82 //
83 //    Global Constants
84 //
85 //***************************************************************************
86 
87 #undef PI
88 #undef M_PI
89 
90 #ifndef NULL
91 #define NULL       0
92 #endif
93 
94 #define PI      3.141592657
95 #define LONG(a) ((int)a)
96 #define M_PI            3.14159
97 
98 #ifndef O_BINARY
99 #define O_BINARY 0
100 #endif
101 
102 #ifndef O_TEXT
103 #define O_TEXT 0
104 #endif
105 
106 #ifndef min
107 #define min(a, b)  (((a) < (b)) ? (a) : (b))
108 #endif
109 
110 #ifndef max
111 #define max(a, b)  (((a) > (b)) ? (a) : (b))
112 #endif
113 
114 #if !PLATFORM_DOS
115   #if PLATFORM_WIN32
116     #define strcmpi(x, y) stricmp(x, y)
117     #define _fstricmp(x, y) stricmp(x, y)
118   #elif PLATFORM_UNIX
119     #ifndef strcmpi
120       #define strcmpi(x, y) strcasecmp(x, y)
121     #endif
122 
123     #ifndef stricmp
124       #define stricmp(x, y) strcasecmp(x, y)
125     #endif
126 
127     #ifndef _fstricmp
128       #define _fstricmp(x, y) strcasecmp(x, y)
129     #endif
130 
131     char *strupr(char *);
132     char *itoa(int, char *, int);
133     char *ltoa(long, char *, int);
134     char *ultoa(unsigned long, char *, int);
135     char getch(void);
136     long filelength(int handle);
137   #else
138     #error please define for your platform.
139   #endif
140 
141 #if !defined(ANSIESC)
142 #define STUB_FUNCTION fprintf(stderr,"STUB: %s at " __FILE__ ", line %d, thread %d\n",__FUNCTION__,__LINE__,getpid())
143 #else
144 #define STUB_FUNCTION
145 #endif
146 
147 #define far
148 #define cdecl
149 #endif
150 
151 //***************************************************************************
152 //
153 //    Screen Constants
154 //
155 //***************************************************************************
156 #define VIEWGLOBAL              0x10000         // globals visable flush to wall
157 #define VIEWWIDTH               320             // size of view window
158 #define VIEWHEIGHT              200
159 #define MAXSCANLINES            200             // size of ylookup table
160 #define CHARWIDTH               2
161 #define TILEWIDTH               4
162 #define STATUSLINES             16
163 
164 //***************************************************************************
165 //
166 //    Engine Constants
167 //
168 //***************************************************************************
169 
170 #define ANGLES                            2048 // must be divisible by 4
171 #define ANGLEQUAD                         (ANGLES/4)
172 #define FINEANGLES                        2048
173 #define FINEANGLEQUAD                     (FINEANGLES/4)
174 #define ANG90                             (FINEANGLES/4)
175 #define ANG180                            (ANG90*2)
176 #define ANG270                            (ANG90*3)
177 #define ANG360                            (ANG90*4)
178 #define VANG90                            (ANGLES/4)
179 #define VANG180                           (VANG90*2)
180 #define VANG270                           (VANG90*3)
181 #define VANG360                           (VANG90*4)
182 #define ANGLESDIV8                        (ANGLES/8)
183 #define MINDIST                           (0x5800l)
184 #define PIXRADIUS                         512
185 #define FOCALLENGTH                       (0x5700l)             // in global coordinates
186 #define MAXTICS                           10
187 
188 //***************************************************************************
189 //
190 //    Map Constants/ macros
191 //
192 //***************************************************************************
193 
194 
195 #define GLOBAL1                           (1l<<16)
196 #define TILEGLOBAL                        GLOBAL1
197 #define PIXGLOBAL                         (GLOBAL1/64)
198 #define TILESHIFT                         16l
199 #define UNSIGNEDSHIFT                     8
200 #define PLAYERSIZE                        0x5700l                       // player radius
201 #define MAPSIZE                           128                         // maps are 64*64 max
202 #define NUMAREAS                          47
203 #define MAPSPOT(x,y,plane)                (mapplanes[plane][MAPSIZE*(y)+(x)])
204 #define AREATILE                          107
205 #define ICONARROWS                        72
206 #define PUSHABLETILE                      80
207 #define ELEVATORTILE                      72
208 #define ALTELEVATORTILE                   106
209 #define LASTLEVELVALUE                    459
210 
211 #define AREANUMBER(x,y)                   (MAPSPOT((x),(y),0)-AREATILE)
212 
213 //***************************************************************************
214 //
215 //    Scale Constants
216 //
217 //***************************************************************************
218 
219 #define SFRACBITS 16
220 #define SFRACUNIT (0x10000)
221 #define FRACUNIT (0x100)
222 
223 //***************************************************************************
224 //
225 //    Actor Constants
226 //
227 //***************************************************************************
228 
229 #define RUNSPEED                6000
230 #define MINACTORDIST            0x9000l
231 #define MAXSTATS                400                           // max number of lamps, bonus, etc
232 
233 #define MAXWALLTILES            105          // max number of wall tiles
234 #define MAXACTORS               600
235 #define NORTH                   0
236 #define EAST                    1
237 #define SOUTH                   2
238 #define WEST                    3
239 
240 //***************************************************************************
241 //
242 //    Input Defines - joystick, keyboard and mouse
243 //
244 //***************************************************************************
245 
246 #define MaxJoys            2
247 #define MaxKbds            2
248 #define MaxJoys            2
249 #define NumCodes           128
250 #define MReset             0
251 #define MButtons           3
252 #define MDelta             11
253 
254 // Key definitions
255 
256 #define  key_None    0
257 #define  key_Return     0x0d
258 #define  key_Enter      key_Return
259 #define  key_Escape     0x1b
260 #define  key_Space      0x20
261 #define  key_BackSpace  0x08
262 #define  key_Tab        0x09
263 #define  key_Delete     0x7f
264 
265 #define  ANGLEBITS      16
266 #define  ANGLEFRACMAX   (FINEANGLES<<ANGLEBITS)
267 
268 
269 //***************************************************************************
270 //
271 //    SWIFT Constants
272 //
273 //***************************************************************************
274 
275 //
276 // device type codes, returned in deviceType field (SWIFT_StaticData)
277 //
278 #define SWIFT_DEV_NONE		0
279 #define SWIFT_DEV_CYBERMAN	1
280 
281 //
282 // Dynamic device data
283 //
284 #define SDD_EXTERNAL_POWER_CONNECTED	1
285 #define SDD_EXTERNAL_POWER_TOO_HIGH	   2
286 
287 #define AX(r) ((r).x.eax)
288 #define BX(r) ((r).x.ebx)
289 #define CX(r) ((r).x.ecx)
290 #define DX(r) ((r).x.edx)
291 #define SI(r) ((r).x.esi)
292 #define DI(r) ((r).x.edi)
293 
294 //***************************************************************************
295 //
296 //    Global Types
297 //
298 //***************************************************************************
299 
300 ///////////////////      GLOBAL DATA TYPES ///////////////////////////////
301 
302 
303 typedef unsigned char           byte;
304 typedef unsigned short int      word;
305 typedef unsigned long           longword;
306 typedef long fixed;
307 
308 
309 //////////////////////////////////////////////////////////////////////////
310 
311 
312 //////////////////      GLOBAL ENUMERATED TYPES    ///////////////////////
313 
314 #ifdef __WATCOMC__
315 typedef enum
316  {false,
317   true
318  }
319  boolean;
320 #else
321 /* boolean is serialized at the moment, and watcomc made it a byte. */
322 
323 typedef unsigned char boolean;
324 enum {
325   false, true
326 };
327 #endif
328 
329 
330 
331 
332 typedef enum {
333 		  east,
334 		  northeast,
335 		  north,
336 		  northwest,
337 		  west,
338 		  southwest,
339 		  south,
340 		  southeast,
341 		  nodir
342 } dirtype;
343 
344 typedef enum
345  {SPRITE,
346   WALL,
347   ACTOR,
348   DOOR,
349   PWALL,
350   MWALL
351  }
352  thingtype;
353 
354 #define NUMTXBUTTONS    16
355 enum    {
356 		  bt_nobutton=-1,
357 		  bt_attack=0,
358 		  bt_strafe=1,
359 		  bt_run=2,
360 		  bt_use=3,
361 		  bt_lookup=4,
362 		  bt_lookdown=5,
363 		  bt_swapweapon=6,
364 		  bt_dropweapon=7,
365 		  bt_horizonup=8,
366         bt_horizondown=9,
367         bt_pistol=10,
368         bt_dualpistol=11,
369         bt_mp40=12,
370         bt_missileweapon=13,
371         bt_autorun=14,
372 		  bt_recordsound=15,
373 		  bt_strafeleft=16,
374 		  bt_straferight=17,
375         bt_turnaround=18,
376         bt_aimbutton=19,
377         di_north=20,
378         di_east=21,
379         di_south=22,
380         di_west=23,
381         bt_map=24,
382         bt_message=25,
383         bt_directmsg=26,
384         NUMBUTTONS
385 };
386 
387 
388 #if (SHAREWARE == 0)
389  #define MAXWEAPONS  13
390 #else
391  #define MAXWEAPONS  9
392 #endif
393 
394 
395 typedef enum    { wp_pistol,
396 						wp_twopistol,
397 						wp_mp40,
398 						wp_bazooka,
399 						wp_heatseeker,
400                   wp_drunk,
401                   wp_firebomb,
402                   wp_firewall,
403 						wp_godhand,
404 
405 #if (SHAREWARE == 0)
406                   wp_split,
407 						wp_kes,
408 						wp_bat,
409                   wp_dog
410 #endif
411 
412                 } weapontype;
413 
414 
415 
416 enum    {
417 						gd_baby,
418 						gd_easy,
419 						gd_medium,
420 						gd_hard
421 };
422 
423 
424 typedef enum    {
425 		  ex_stillplaying,
426 		  ex_completed,
427 		  ex_died,
428 		  ex_warped,
429 		  ex_resetgame,
430 		  ex_loadedgame,
431 		  ex_victorious,
432 		  ex_abort,
433 		  ex_demodone,
434 		  ex_skiplevel,
435 		  ex_secretlevel,
436         ex_secretdone,
437         ex_titles,
438 		  ex_demorecord,
439 		  ex_demoplayback,
440 
441 		  ex_bossdied,
442 		  ex_gameover,
443 		  ex_battledone
444 } exit_t;
445 
446 ////////////////////////////////////////////////////////////////////////////
447 
448 /////////////////      GLOBAL STRUCTURE TYPES     //////////////////////////
449 
450 
451 //=================== SHARED FLAGS =====================================//
452 
453 #define FL_SHOOTABLE            0x01
454 #define FL_ACTIVE               0x02
455 #define FL_VISIBLE              0x08
456 #define FL_NOFRICTION           0x100 //
457 #define FL_DYING                0x1000
458 #define FL_ALTERNATE            0x20000
459 #define FL_GODSTRUCK            0x80000
460 #define FL_ABP                  0x400000
461 #define FL_BLOCK                0x800000
462 #define FL_HBM                  0x1000000
463 #define FL_RIDING               0x2000000
464 #define FL_SOLIDCOLOR           0x4000000
465 #define FL_SEEN                 0x8000000
466 #define FL_COLORED              0x10000000
467 #define FL_FULLLIGHT       0x80000000
468 
469 //=================== ACTOR FLAGS =====================================//
470 
471 #define FL_NEVERMARK            4
472 #define FL_ATTACKMODE           0x10
473 #define FL_FIRSTATTACK          0x20
474 #define FL_ISFIRE               0x20
475 #define FL_AMBUSH               0x40
476 #define FL_NONMARK              0x80
477 #define FL_DONE                 0x200 // used by push column
478 #define FL_DODGE                0x400 // "
479 #define FL_STUCK                0x800 //
480 #define FL_HASAUTO              0x2000
481 #define FL_FALLINGOBJECT        0x4000
482 #define FL_KEYACTOR             0x8000
483 #define FL_HEAD                 0x40000
484 #define FL_TARGET               0x200000
485 #define FL_FLIPPED              0x40000000
486 #define FL_CRAZY                0x40000000
487 
488 
489 //================== PLAYER FLAGS ======================================//
490 
491 #define FL_BPV                  0x10
492 #define FL_SHROOMS              0x20
493 #define FL_AV                   0x40
494 #define FL_ELASTO               0x200
495 #define FL_FLEET                0x400
496 #define FL_PUSHED               0x2000
497 #define FL_PAIN                 0x4000
498 #define FL_GODMODE              0x8000
499 #define FL_DOGMODE              0x10000
500 #define FL_GASMASK              0x100000
501 #define FL_DESIGNATED           0x20000000
502 #define FL_DIDTAG               0x40000000
503 
504 //================== SPRITE FLAGS ======================================//
505 
506 #define NOTHING                 -1
507 #define FL_BONUS                0x04
508 #define FL_LIGHT                0x20
509 #define FL_CHANGES              0x40
510 #define FL_BACKWARDS            0x100
511 #define FL_BANDF                0x200
512 #define FL_HEAT                 0x400
513 #define FL_LIGHTOFF             0x800
514 #define FL_ACTOR                0x1000
515 #define FL_ROTATING             0x2000
516 #define FL_RESPAWN              0x4000
517 #define FL_WOODEN               0x8000
518 #define FL_METALLIC             0x10000
519 #define FL_EARTHEN              0x20000
520 #define FL_LIGHTON              0x40000
521 #define FL_FADING               0x80000
522 #define FL_DEADBODY             0x100000
523 #define FL_WEAPON               0x200000
524 #define FL_TRANSLUCENT          0x2000000
525 #define FL_HEIGHTFLIPPABLE      0x40000000
526 
527 #endif
528