1 #ifndef WL_DEF_H
2 #define WL_DEF_H
3 
4 #include <assert.h>
5 #include <fcntl.h>
6 #include <math.h>
7 #include <ctype.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #if defined(_arch_dreamcast)
11 #	include <kos.h>
12 #elif !defined(_WIN32)
13 #	include <stdint.h>
14 #	include <string.h>
15 #	include <stdarg.h>
16 #elif defined(__GNUC__)
17 #	include <stdint.h>
18 #endif
19 #include <SDL.h>
20 
21 #if !defined O_BINARY
22 #	define O_BINARY 0
23 #endif
24 
25 #ifdef _arch_dreamcast
26 typedef uint8 uint8_t;
27 typedef uint16 uint16_t;
28 typedef uint32 uint32_t;
29 typedef int8 int8_t;
30 typedef int16 int16_t;
31 typedef int32 int32_t;
32 typedef int64 int64_t;
33 typedef ptr_t uintptr_t;
34 #endif
35 
36 #define FRACBITS 16
37 #define FRACUNIT (1<<FRACBITS)
38 
39 typedef uint8_t byte;
40 typedef uint8_t BYTE;
41 typedef int8_t SBYTE;
42 typedef uint16_t word;
43 typedef uint16_t WORD;
44 typedef int16_t SWORD;
45 typedef int32_t fixed;
46 typedef fixed fixed_t;
47 typedef uint32_t longword;
48 #ifndef USE_WINDOWS_DWORD
49 typedef uint32_t DWORD;
50 #endif
51 typedef int32_t SDWORD;
52 typedef uint64_t QWORD;
53 typedef int64_t SQWORD;
54 typedef void * memptr;
55 typedef uint32_t uint32;
56 typedef uint32_t BITFIELD;
57 typedef int INTBOOL;
58 
59 // Screenshot buffer image data types
60 enum ESSType
61 {
62 	SS_PAL,
63 	SS_RGB,
64 	SS_BGRA
65 };
66 
67 void Quit(const char *errorStr, ...);
68 
69 #define FIXED2FLOAT(fixed) ((double)(fixed)/65536.0)
70 #define FLOAT2FIXED(x) (fixed_t((x)*FRACUNIT))
71 
72 #ifdef _WIN32
73 #define stricmp _stricmp
74 #endif
75 
76 typedef double real64;
77 typedef SDWORD int32;
78 #include "xs_Float.h"
79 
80 /*
81 =============================================================================
82 
83 							GLOBAL CONSTANTS
84 
85 =============================================================================
86 */
87 
88 #define MAXPLAYERS		8 // You wish! :P  (This is just here to satisfy ZDoom stuff)
89 #define BODYQUESIZE		32
90 #define NUMCOLORMAPS	64
91 
92 #define TICRATE 70
93 #define MAXTICS 10
94 #define DEMOTICS        4
95 
96 //
97 // tile constants
98 //
99 
100 #define ICONARROWS      90
101 #define PUSHABLETILE    98
102 #define EXITTILE        99          // at end of castle
103 #define AREATILE        107         // first of NUMAREAS floor tiles
104 #define NUMAREAS        37
105 #define ELEVATORTILE    21
106 #define AMBUSHTILE      106
107 #define ALTELEVATORTILE 107
108 
109 #define NUMBERCHARS     9
110 
111 
112 //----------------
113 
114 #define EXTRAPOINTS     40000
115 
116 #define PLAYERSPEED     3000
117 #define RUNSPEED        6000
118 
119 #define SCREENSEG       0xa000
120 
121 #define SCREENBWIDE     80
122 
123 #define HEIGHTRATIO     0.50            // also defined in id_mm.c
124 
125 #define FLASHCOLOR      5
126 #define FLASHTICS       4
127 
128 #undef M_PI
129 #define PI              3.141592657
130 #define M_PI PI
131 
132 #define GLOBAL1         (1l<<16)
133 #define TILEGLOBAL      GLOBAL1
134 #define TILESHIFT       16l
135 #define UNSIGNEDSHIFT   8
136 
137 #define ANGLETOFINESHIFT 19
138 #define FINEANGLES      8192
139 #define FINEMASK        (FINEANGLES-1)
140 #define ANG90           (FINEANGLES/4)
141 #define ANG180          (ANG90*2)
142 #define ANG270          (ANG90*3)
143 #define ANG360          (ANG90*4)
144 #define ANGLE_45		(0x20000000u)
145 #define ANGLE_90		(ANGLE_45*2)
146 #define ANGLE_180		(ANGLE_45*4)
147 #define ANGLE_270		(ANGLE_45*6)
148 #define ANGLE_1			(ANGLE_45/45)
149 #define ANGLE_60		(ANGLE_180/3)
150 #define ANGLE_NEG(x)	(static_cast<angle_t>(0xFFFFFFFFu-x+1u))
151 typedef uint32_t angle_t;
152 
153 #define TEXTURESHIFT    6
154 #define TEXTURESIZE     (1<<TEXTURESHIFT)
155 #define TEXTUREFROMFIXEDSHIFT 4
156 #define TEXTUREMASK     (TEXTURESIZE*(TEXTURESIZE-1))
157 
158 #define NORTH   0
159 #define EAST    1
160 #define SOUTH   2
161 #define WEST    3
162 
163 #define SCREENSIZE      (SCREENBWIDE*208)
164 #define PAGE1START      0
165 #define PAGE2START      (SCREENSIZE)
166 #define PAGE3START      (SCREENSIZE*2u)
167 #define FREESTART       (SCREENSIZE*3u)
168 
169 
170 #define PIXRADIUS       512
171 
172 #define STARTAMMO       8
173 
174 
175 // object flag values
176 
177 enum ActorFlag
178 {
179 	FL_SHOOTABLE        = 0x00000001,
180 	FL_VISABLE          = 0x00000008,
181 	FL_ATTACKMODE       = 0x00000010,
182 	FL_FIRSTATTACK      = 0x00000020,
183 	FL_AMBUSH           = 0x00000040,
184 	FL_BRIGHT           = 0x00000100,
185 #ifdef USE_DIR3DSPR
186 	// you can choose one of the following values in wl_act1.cpp
187 	// to make a static sprite a directional 3d sprite
188 	// (see example at the end of the statinfo array)
189 	FL_DIR_HORIZ_MID    = 0x00000200,
190 	FL_DIR_HORIZ_FW     = 0x00000400,
191 	FL_DIR_HORIZ_BW     = 0x00000600,
192 	FL_DIR_VERT_MID     = 0x00000a00,
193 	FL_DIR_VERT_FW      = 0x00000c00,
194 	FL_DIR_VERT_BW      = 0x00000e00,
195 
196 	// these values are just used to improve readability of code
197 	FL_DIR_NONE         = 0x00000000,
198 	FL_DIR_POS_MID      = 0x00000200,
199 	FL_DIR_POS_FW       = 0x00000400,
200 	FL_DIR_POS_BW       = 0x00000600,
201 	FL_DIR_POS_MASK     = 0x00000600,
202 	FL_DIR_VERT_FLAG    = 0x00000800,
203 	FL_DIR_MASK         = 0x00000e00,
204 #endif
205 	FL_ISMONSTER        = 0x00001000,
206 	FL_CANUSEWALLS		= 0x00002000,
207 	FL_COUNTKILL		= 0x00004000,
208 	FL_SOLID			= 0x00008000,
209 	FL_PATHING			= 0x00010000,
210 	FL_PICKUP			= 0x00020000,
211 	FL_MISSILE			= 0x00040000,
212 	FL_COUNTITEM		= 0x00080000,
213 	FL_COUNTSECRET		= 0x00100000,
214 	FL_DROPBASEDONTARGET= 0x00200000,
215 	FL_REQUIREKEYS		= 0x00400000,
216 	FL_ALWAYSFAST		= 0x00800000,
217 	FL_RANDOMIZE		= 0x01000000,
218 	FL_RIPPER			= 0x02000000,
219 	FL_DONTRIP			= 0x04000000,
220 	FL_OLDRANDOMCHASE	= 0x08000000,
221 	FL_PLOTONAUTOMAP	= 0x10000000,
222 
223 	FL_PLAYERMISSILE	= 0x80000000, // Temporary until missile can keep the player as a target.
224 };
225 
226 enum ItemFlag
227 {
228 	IF_AUTOACTIVATE		= 0x00000001,
229 	IF_INVBAR			= 0x00000002,
230 	IF_ALWAYSPICKUP		= 0x00000004,
231 	IF_INACTIVE			= 0x00000008, // For picked up items that remain on the map
232 };
233 
234 enum WeaponFlag
235 {
236 	WF_NOGRIN			= 0x00000001,
237 	WF_NOAUTOFIRE		= 0x00000002,
238 	WF_DONTBOB			= 0x00000004,
239 	WF_ALWAYSGRIN		= 0x00000008,
240 	WF_NOALERT			= 0x00000010,
241 };
242 
243 /*
244 =============================================================================
245 
246 							GLOBAL TYPES
247 
248 =============================================================================
249 */
250 
251 typedef enum {
252 	di_north,
253 	di_east,
254 	di_south,
255 	di_west
256 } controldir_t;
257 
258 typedef enum {
259 	east,
260 	northeast,
261 	north,
262 	northwest,
263 	west,
264 	southwest,
265 	south,
266 	southeast,
267 	nodir
268 } dirtype;
269 
270 static const int dirdeltax[9] = { 1, 1, 0, -1, -1, -1, 0, 1, 0 };
271 static const int dirdeltay[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
272 
273 //--------------------
274 //
275 // thinking actor structure
276 //
277 //--------------------
278 
279 class AActor;
280 
281 enum Button
282 {
283 	bt_nobutton=-1,
284 	bt_attack=0,
285 	bt_strafe,
286 	bt_run,
287 	bt_use,
288 	bt_slot0,
289 	bt_slot1,
290 	bt_slot2,
291 	bt_slot3,
292 	bt_slot4,
293 	bt_slot5,
294 	bt_slot6,
295 	bt_slot7,
296 	bt_slot8,
297 	bt_slot9,
298 	bt_nextweapon,
299 	bt_prevweapon,
300 	bt_esc,
301 	bt_pause,
302 	bt_strafeleft,
303 	bt_straferight,
304 	bt_moveforward,
305 	bt_movebackward,
306 	bt_turnleft,
307 	bt_turnright,
308 	bt_altattack,
309 	bt_reload,
310 	bt_zoom,
311 	bt_automap,
312 	bt_showstatusbar,
313 	NUMBUTTONS,
314 
315 	// AM buttons
316 	bt_zoomin = 0,
317 	bt_zoomout,
318 	bt_panup,
319 	bt_pandown,
320 	bt_panleft,
321 	bt_panright,
322 	NUMAMBUTTONS
323 };
324 
325 struct ControlScheme
326 {
327 	public:
328 		static void	setKeyboard(ControlScheme* scheme, Button button, int value);
329 		static void setJoystick(ControlScheme* scheme, Button button, int value);
330 		static void setMouse(ControlScheme* scheme, Button button, int value);
331 
332 		Button		button;
333 		const char*	name;
334 		int			joystick;
335 		int			keyboard;
336 		int			mouse;
337 		int			*axis;
338 		bool		negative;
339 };
340 
341 extern ControlScheme controlScheme[];
342 extern ControlScheme amControlScheme[];
343 extern ControlScheme &schemeAutomapKey;
344 
345 enum
346 {
347 	gd_baby,
348 	gd_easy,
349 	gd_medium,
350 	gd_hard
351 };
352 
353 typedef enum
354 {
355 	ex_stillplaying,
356 	ex_completed,
357 	ex_died,
358 	ex_warped,
359 	ex_resetgame,
360 	ex_loadedgame,
361 	ex_abort,
362 	ex_demodone,
363 	ex_secretlevel,
364 	ex_newmap,
365 	ex_victorious
366 } exit_t;
367 
368 /*
369 =============================================================================
370 
371 							MISC DEFINITIONS
372 
373 =============================================================================
374 */
375 
376 void atterm(void (*func)(void));
377 
378 extern const struct RatioInformation
379 {
380 	int baseWidth;
381 	int baseHeight;
382 	int viewGlobal;
383 	fixed tallscreen;
384 	int multiplier;
385 	bool isWide;
386 } AspectCorrection[];
387 #define CorrectWidthFactor(x)	((x)*AspectCorrection[r_ratio].multiplier/48)
388 #define CorrectHeightFactor(x)	((x)*48/AspectCorrection[r_ratio].multiplier)
389 
FixedMul(fixed a,fixed b)390 static inline fixed FixedMul(fixed a, fixed b)
391 {
392 	return (fixed)(((int64_t)a * b + 0x8000) >> 16);
393 }
394 
FixedDiv(fixed a,fixed b)395 static inline fixed FixedDiv(fixed a, fixed b)
396 {
397 	return (fixed)(((((int64_t)a)<<32) / b) >> 16);
398 }
399 
400 #define GetTicks() ((SDL_GetTicks()*7)/100)
401 
402 #define CHECKMALLOCRESULT(x) if(!(x)) Quit("Out of memory at %s:%i", __FILE__, __LINE__)
403 
404 #ifndef _WIN32
itoa(int value,char * string,int radix)405 	static inline char* itoa(int value, char* string, int radix)
406 	{
407 		sprintf(string, "%d", value);
408 		return string;
409 	}
410 
ltoa(long value,char * string,int radix)411 	static inline char* ltoa(long value, char* string, int radix)
412 	{
413 		sprintf(string, "%ld", value);
414 		return string;
415 	}
416 #endif
417 
418 #define typeoffsetof(type,variable) ((int)(size_t)&((type*)1)->variable - 1)
419 
420 #define lengthof(x) (sizeof(x) / sizeof(*(x)))
421 #define endof(x)    ((x) + lengthof(x))
422 
READWORD(byte * & ptr)423 static inline word READWORD(byte *&ptr)
424 {
425 	word val = ptr[0] | ptr[1] << 8;
426 	ptr += 2;
427 	return val;
428 }
429 
READLONGWORD(byte * & ptr)430 static inline longword READLONGWORD(byte *&ptr)
431 {
432 	longword val = ptr[0] | ptr[1] << 8 | ptr[2] << 16 | ptr[3] << 24;
433 	ptr += 4;
434 	return val;
435 }
436 
437 
438 /*
439 =============================================================================
440 
441 						FEATURE DEFINITIONS
442 
443 =============================================================================
444 */
445 
446 #ifdef USE_FEATUREFLAGS
447 	// The currently available feature flags
448 	#define FF_STARSKY      0x0001
449 	#define FF_PARALLAXSKY  0x0002
450 	#define FF_CLOUDSKY     0x0004
451 	#define FF_RAIN         0x0010
452 	#define FF_SNOW         0x0020
453 
454 	// The ffData... variables contain the 16-bit values of the according corners of the current level.
455 	// The corners are overwritten with adjacent tiles after initialization in SetupGameLevel
456 	// to avoid interpretation as e.g. doors.
457 	extern int ffDataTopLeft, ffDataTopRight, ffDataBottomLeft, ffDataBottomRight;
458 
459 	/*************************************************************
460 	* Current usage of ffData... variables:
461 	* ffDataTopLeft:     lower 8-bit: ShadeDefID
462 	* ffDataTopRight:    FeatureFlags
463 	* ffDataBottomLeft:  CloudSkyDefID or ParallaxStartTexture
464 	* ffDataBottomRight: unused
465 	*************************************************************/
466 
467 	// The feature flags are stored as a wall in the upper right corner of each level
GetFeatureFlags()468 	static inline word GetFeatureFlags()
469 	{
470 		return ffDataTopRight;
471 	}
472 
473 #endif
474 
475 #ifdef USE_PARALLAX
476 	void DrawParallax(byte *vbuf, unsigned vbufPitch);
477 #endif
478 
479 #ifdef USE_DIR3DSPR
480 	void Scale3DShape(byte *vbuf, unsigned vbufPitch, statobj_t *ob);
481 #endif
482 
483 #endif
484