1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: doomdef.h 4469 2014-01-03 23:38:29Z dr_sean $
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 // Copyright (C) 2006-2014 by The Odamex Team.
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // DESCRIPTION:
20 // Internally used data structures for virtually everything,
21 // key definitions, lots of other stuff.
22 //
23 //-----------------------------------------------------------------------------
24
25
26 #ifndef __DOOMDEF_H__
27 #define __DOOMDEF_H__
28
29 #include <stdio.h>
30 #include <cstring>
31
32 // GhostlyDeath -- MSVC++ 8+, remove "deprecated" warnings
33 #if _MSC_VER >= 1400
34 #pragma warning(disable : 4996)
35 #endif
36
37 //
38 // The packed attribute forces structures to be packed into the minimum
39 // space necessary. If this is not done, the compiler may align structure
40 // fields differently to optimise memory access, inflating the overall
41 // structure size. It is important to use the packed attribute on certain
42 // structures where alignment is important, particularly data read/written
43 // to disk.
44 //
45
46 #ifdef __GNUC__
47 #define PACKEDATTR __attribute__((packed))
48 #else
49 #define PACKEDATTR
50 #endif
51
52
53 #include "farchive.h"
54
55 //
56 // denis
57 //
58 // if(clientside) { do visual effects, sounds, etc }
59 // if(serverside) { spawn/destroy things, change maps, etc }
60 //
61 extern bool clientside, serverside;
62
63 // [Nes] - Determines which program the user is running.
64 enum baseapp_t
65 {
66 client, // Odamex.exe
67 server // Odasrv.exe
68 };
69
70 extern baseapp_t baseapp;
71
72 //
73 // Global parameters/defines.
74 //
75
76 // Game mode handling - identify IWAD version
77 // to handle IWAD dependend animations etc.
78 enum GameMode_t
79 {
80 shareware, // DOOM 1 shareware, E1, M9
81 registered, // DOOM 1 registered, E3, M27
82 commercial, // DOOM 2 retail, E1 M34
83 // DOOM 2 german edition not handled
84 retail, // DOOM 1 retail, E4, M36
85 retail_chex, // Chex Quest
86 retail_bfg, // Doom 1 BFG Edition
87 commercial_bfg, // Doom 2 BFG Edition
88 undetermined // Well, no IWAD found.
89 };
90
91
92 // Mission packs - might be useful for TC stuff?
93 enum GameMission_t
94 {
95 doom, // DOOM 1
96 doom2, // DOOM 2
97 pack_tnt, // TNT mission pack
98 pack_plut, // Plutonia pack
99 chex, // Chex Quest
100 retail_freedoom,
101 commercial_freedoom,
102 none
103 };
104
105 // If rangecheck is undefined,
106 // most parameter validation debugging code will not be compiled
107 #define RANGECHECK
108
109 // The maximum number of players, multiplayer/networking.
110 #define MAXPLAYERS 255
111 #define MAXPLAYERS_VANILLA 4
112
113 // Margin of error used when calculating percentages against player numbers.
114 #define MPEPSILON (float)1 / (MAXPLAYERS * 2)
115
116 // State updates, number of tics / second.
117 #define TICRATE 35
118
119 // The current state of the game: whether we are
120 // playing, gazing at the intermission screen,
121 // the game final animation, or a demo.
122 enum gamestate_t
123 {
124 GS_LEVEL,
125 GS_INTERMISSION,
126 GS_FINALE,
127 GS_DEMOSCREEN,
128 GS_FULLCONSOLE, // [RH] Fullscreen console
129 GS_HIDECONSOLE, // [RH] The menu just did something that should hide fs console
130 GS_STARTUP, // [RH] Console is fullscreen, and game is just starting
131 GS_DOWNLOAD, // denis - wad downloading
132 GS_CONNECTING, // denis - replace the old global "tryingtoconnect"
133 GS_CONNECTED, // [ML] - For that brief time before GS_LEVEL But after GS_CONNECTING should be done
134
135 GS_FORCEWIPE = -1
136 };
137
138 //
139 // Difficulty/skill settings/filters.
140 //
141
142 // Skill flags.
143 #define MTF_EASY 1
144 #define MTF_NORMAL 2
145 #define MTF_HARD 4
146
147 // Deaf monsters/do not react to sound.
148 #define MTF_AMBUSH 8
149
150 // Gravity
151 #define GRAVITY FRACUNIT
152
153 enum skill_t
154 {
155 sk_baby = 1,
156 sk_easy,
157 sk_medium,
158 sk_hard,
159 sk_nightmare
160 };
161
162 //
163 // Key cards.
164 //
165 enum card_t
166 {
167 it_bluecard,
168 it_yellowcard,
169 it_redcard,
170 it_blueskull,
171 it_yellowskull,
172 it_redskull,
173
174 NUMCARDS,
175
176 // GhostlyDeath <August 31, 2008> -- Before this was not = 0 and when
177 // the map is loaded the value is just bitshifted so that the values
178 // that were here were incorrect, keyed generalized doors work now
179 NoKey = 0,
180 RCard,
181 BCard,
182 YCard,
183 RSkull,
184 BSkull,
185 YSkull,
186
187 AnyKey = 100,
188 AllKeys = 101,
189
190 CardIsSkull = 128
191 };
192
193 //
194 // [Toke - CTF] CTF Flags
195 //
196 enum flag_t
197 {
198 it_blueflag,
199 it_redflag,
200
201 NUMFLAGS
202 };
203
204 inline FArchive &operator<< (FArchive &arc, card_t i)
205 {
206 return arc << (BYTE)i;
207 }
208 inline FArchive &operator>> (FArchive &arc, card_t &i)
209 {
210 BYTE in; arc >> in; i = (card_t)in; return arc;
211 }
212
213
214 // The defined weapons,
215 // including a marker indicating
216 // user has not changed weapon.
217 enum weapontype_t
218 {
219 wp_fist,
220 wp_pistol,
221 wp_shotgun,
222 wp_chaingun,
223 wp_missile,
224 wp_plasma,
225 wp_bfg,
226 wp_chainsaw,
227 wp_supershotgun,
228
229 NUMWEAPONS,
230
231 // No pending weapon change.
232 wp_nochange
233 };
234
235 inline FArchive &operator<< (FArchive &arc, weapontype_t i)
236 {
237 return arc << (BYTE)i;
238 }
239 inline FArchive &operator>> (FArchive &arc, weapontype_t &i)
240 {
241 BYTE in; arc >> in; i = (weapontype_t)in; return arc;
242 }
243
244
245 // Ammunition types defined.
246 enum ammotype_t
247 {
248 am_clip, // Pistol / chaingun ammo.
249 am_shell, // Shotgun / double barreled shotgun.
250 am_cell, // Plasma rifle, BFG.
251 am_misl, // Missile launcher.
252 NUMAMMO,
253 am_noammo // Unlimited for chainsaw / fist.
254
255 };
256
257 inline FArchive &operator<< (FArchive &arc, ammotype_t i)
258 {
259 return arc << (BYTE)i;
260 }
261 inline FArchive &operator>> (FArchive &arc, ammotype_t &i)
262 {
263 BYTE in; arc >> in; i = (ammotype_t)in; return arc;
264 }
265
266
267 // Power up artifacts.
268 enum powertype_t
269 {
270 pw_invulnerability,
271 pw_strength,
272 pw_invisibility,
273 pw_ironfeet,
274 pw_allmap,
275 pw_infrared,
276 NUMPOWERS
277 };
278
279 inline FArchive &operator<< (FArchive &arc, powertype_t i)
280 {
281 return arc << (BYTE)i;
282 }
283 inline FArchive &operator>> (FArchive &arc, powertype_t &i)
284 {
285 BYTE in; arc >> in; i = (powertype_t)in; return arc;
286 }
287
288
289 //
290 // Power up durations, how many tics till expiration.
291 //
292 #define INVULNTICS (30*TICRATE)
293 #define INVISTICS (60*TICRATE)
294 #define INFRATICS (120*TICRATE)
295 #define IRONTICS (60*TICRATE)
296
297 // [ML] 1/5/10: Move input defs to doomkeys.h
298 #include "doomkeys.h"
299
300 // [ML] Default intermission length
301 #define DEFINTSECS 10
302
303 // phares 3/20/98:
304 //
305 // Player friction is variable, based on controlling
306 // linedefs. More friction can create mud, sludge,
307 // magnetized floors, etc. Less friction can create ice.
308
309 #define MORE_FRICTION_MOMENTUM 15000 // mud factor based on momentum
310 #define ORIG_FRICTION 0xE800 // original value
311 #define ORIG_FRICTION_FACTOR 2048 // original value
312 #define FRICTION_FLY 0xeb00
313
314 #ifndef __BIG_ENDIAN__
315 #define MAKE_ID(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
316 #else
317 #define MAKE_ID(a,b,c,d) ((d)|((c)<<8)|((b)<<16)|((a)<<24))
318 #endif
319
320
321 //==========================================================================
322 //
323 // BinarySearch
324 //
325 // Searches an array sorted in ascending order for an element matching
326 // the desired key.
327 //
328 // Template parameters:
329 // ClassType - The class to be searched
330 // KeyType - The type of the key contained in the class
331 //
332 // Function parameters:
333 // first - Pointer to the first element in the array
334 // max - The number of elements in the array
335 // keyptr - Pointer to the key member of ClassType
336 // key - The key value to look for
337 //
338 // Returns:
339 // A pointer to the element with a matching key or NULL if none found.
340 //==========================================================================
341
342 template<class ClassType, class KeyType>
343 inline
BinarySearch(const ClassType * first,int max,const KeyType ClassType::* keyptr,const KeyType key)344 const ClassType *BinarySearch (const ClassType *first, int max,
345 const KeyType ClassType::*keyptr, const KeyType key)
346 {
347 int min = 0;
348 --max;
349
350 while (min <= max)
351 {
352 int mid = (min + max) / 2;
353 const ClassType *probe = &first[mid];
354 const KeyType &seekey = probe->*keyptr;
355 if (seekey == key)
356 {
357 return probe;
358 }
359 else if (seekey < key)
360 {
361 min = mid + 1;
362 }
363 else
364 {
365 max = mid - 1;
366 }
367 }
368 return NULL;
369 }
370
371 //==========================================================================
372 //
373 // BinarySearchFlexible
374 //
375 // THIS DOES NOT WORK RIGHT WITH VISUAL C++
376 // ONLY ONE COMPTYPE SEEMS TO BE USED FOR ANY INSTANCE OF THIS FUNCTION
377 // IN A DEBUG BUILD. RELEASE MIGHT BE DIFFERENT--I DIDN'T BOTHER TRYING.
378 //
379 // Similar to BinarySearch, except another function is used to copmare
380 // items in the array.
381 //
382 // Template parameters:
383 // IndexType - The type used to index the array (int, size_t, etc.)
384 // KeyType - The type of the key
385 // CompType - A class with a static DoCompare(IndexType, KeyType) method.
386 //
387 // Function parameters:
388 // max - The number of elements in the array
389 // key - The key value to look for
390 // noIndex - The value to return if no matching element is found.
391 //
392 // Returns:
393 // The index of the matching element or noIndex.
394 //==========================================================================
395
396 template<class IndexType, class KeyType, class CompType>
397 inline
BinarySearchFlexible(IndexType max,const KeyType key,IndexType noIndex)398 IndexType BinarySearchFlexible (IndexType max, const KeyType key, IndexType noIndex)
399 {
400 IndexType min = 0;
401 --max;
402
403 while (min <= max)
404 {
405 IndexType mid = (min + max) / 2;
406 int lexx = CompType::DoCompare (mid, key);
407 if (lexx == 0)
408 {
409 return mid;
410 }
411 else if (lexx < 0)
412 {
413 min = mid + 1;
414 }
415 else
416 {
417 max = mid - 1;
418 }
419 }
420 return noIndex;
421 }
422
423
424 #endif // __DOOMDEF_H__
425