Debian Codegraph @

prboom2/src/d_deh.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2004 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Dehacked file support
31 * New for the TeamTNT "Boom" engine
32 *
33 * Author: Ty Halderman, TeamTNT
34 *
35 *--------------------------------------------------------------------*/
36
37 // killough 5/2/98: fixed headers, removed rendunant external declarations:
38 #include "doomdef.h"
39 #include "doomtype.h"
40 #include "doomstat.h"
41 #include "d_deh.h"
42 #include "sounds.h"
43 #include "info.h"
44 #include "m_cheat.h"
45 #include "p_tick.h"
46 #include "p_inter.h"
47 #include "p_enemy.h"
48 #include "p_map.h"
49 #include "g_game.h"
50 #include "d_think.h"
51 #include "w_wad.h"
52 #include "m_file.h"
53 #include "m_misc.h"
54 #include "v_video.h"
55 #include "e6y.h"//e6y
56
57 // CPhipps - modify to use logical output routine
58 #include "lprintf.h"
59
60 #include "dsda/args.h"
61 #include "dsda/mobjinfo.h"
62 #include "dsda/music.h"
63 #include "dsda/settings.h"
64 #include "dsda/sfx.h"
65 #include "dsda/sprite.h"
66 #include "dsda/state.h"
67 #include "dsda/utility.h"
68
69 #define TRUE 1
70 #define FALSE 0
71
72 static dboolean bfgcells_modified = false;
73
74 static FILE *deh_log_file;
75
76 static int deh_log(const char *s, ...)
77 {
78 int r;
79 va_list v;
80
81 if (!deh_log_file) return 0;
82
83 va_start(v,s);
84 r = vfprintf(deh_log_file, s, v);
85 va_end(v);
86
87 return r;
88 }
89
90 // e6y: for compatibility with BOOM deh parser
91 int deh_strcasecmp(const char *str1, const char *str2)
92 {
93 if (prboom_comp[PC_BOOM_DEH_PARSER].state &&
94 compatibility_level >= boom_compatibility_compatibility &&
95 compatibility_level <= boom_202_compatibility)
96 {
97 return strcmp(str1, str2);
98 }
99 else
100 {
101 return strcasecmp(str1, str2);
102 }
103 }
104
105 const char * deh_getBitsDelims(void)
106 {
107 if (prboom_comp[PC_BOOM_DEH_PARSER].state &&
108 compatibility_level >= boom_compatibility_compatibility &&
109 compatibility_level <= boom_202_compatibility)
110 {
111 return "+";
112 }
113 else
114 {
115 return ",+| \t\f\r";
116 }
117 }
118
119 // killough 10/98: new functions, to allow processing DEH files in-memory
120 // (e.g. from wads)
121
122 typedef struct {
123 /* cph 2006/08/06 -
124 * if lump != NULL, lump is the start of the lump,
125 * inp is the current read pos. */
126 const byte *inp, *lump;
127 long size;
128 /* else, !lump, and f is the file being read */
129 FILE* f;
130 } DEHFILE;
131
132 // killough 10/98: emulate IO whether input really comes from a file or not
133
134 static char *dehfgets(char *buf, size_t n, DEHFILE *fp)
135 {
136 if (!fp->lump) // If this is a real file,
137 return (fgets)(buf, n, fp->f); // return regular fgets
138 if (!n || !*fp->inp || fp->size <= 0) // If no more characters
139 return NULL;
140 if (n == 1)
141 fp->size--, *buf = *fp->inp++;
142 else
143 { // copy buffer
144 char *p = buf;
145 while (n > 1 && *fp->inp && fp->size &&
146 (n--, fp->size--, *p++ = *fp->inp++) != '\n')
147 ;
148 *p = 0;
149 }
150 return buf; // Return buffer pointer
151 }
152
153 static int dehfeof(DEHFILE *fp)
154 {
155 return !fp->lump ? feof(fp->f) : !*fp->inp || fp->size <= 0;
156 }
157
158 static int dehfgetc(DEHFILE *fp)
159 {
160 return !fp->lump ? fgetc(fp->f) : fp->size > 0 ?
161 fp->size--, *fp->inp++ : EOF;
162 }
163
164 static long dehftell(DEHFILE *fp)
165 {
166 return !fp->lump ? ftell(fp->f) : (fp->inp - fp->lump);
167 }
168
169 static int dehfseek(DEHFILE *fp, long offset)
170 {
171 if (!fp->lump)
172 return fseek(fp->f, offset, SEEK_SET);
173 else
174 {
175 long total = (fp->inp - fp->lump) + fp->size;
176 offset = BETWEEN(0, total, offset);
177 fp->inp = fp->lump + offset;
178 fp->size = total - offset;
179 return 0;
180 }
181 }
182
183 static char *deh_sfx_name(const char *name)
184 {
185 dsda_string_t str;
186
187 dsda_StringPrintF(&str, "ds%s", name);
188
189 return str.string;
190 }
191
192 // haleyjd 9/22/99
193 int HelperThing = -1; // in P_SpawnMapThing to substitute helper thing
194
195 // variables used in other routines
196 dboolean deh_pars = FALSE; // in wi_stuff to allow pars in modified games
197
198 // #include "d_deh.h" -- we don't do that here but we declare the
199 // variables. This externalizes everything that there is a string
200 // set for in the language files. See d_deh.h for detailed comments,
201 // original English values etc. These are set to the macro values,
202 // which are set by D_ENGLSH.H or D_FRENCH.H(etc). BEX files are a
203 // better way of changing these strings globally by language.
204
205 // ====================================================================
206 // Any of these can be changed using the bex extensions
207 #include "dstrings.h" // to get the initial values
208
209 const char *s_PRESSKEY = PRESSKEY;
210 const char *s_PRESSYN = PRESSYN;
211 const char *s_QUITMSG = QUITMSG;
212 const char *s_QUITMSG1 = QUITMSG1;
213 const char *s_QUITMSG2 = QUITMSG2;
214 const char *s_QUITMSG3 = QUITMSG3;
215 const char *s_QUITMSG4 = QUITMSG4;
216 const char *s_QUITMSG5 = QUITMSG5;
217 const char *s_QUITMSG6 = QUITMSG6;
218 const char *s_QUITMSG7 = QUITMSG7;
219 const char *s_QUITMSG8 = QUITMSG8;
220 const char *s_QUITMSG9 = QUITMSG9;
221 const char *s_QUITMSG10 = QUITMSG10;
222 const char *s_QUITMSG11 = QUITMSG11;
223 const char *s_QUITMSG12 = QUITMSG12;
224 const char *s_QUITMSG13 = QUITMSG13;
225 const char *s_QUITMSG14 = QUITMSG14;
226 const char *s_QSAVESPOT = QSAVESPOT; // PRESSKEY;
227 const char *s_SAVEDEAD = SAVEDEAD; // PRESSKEY; // remove duplicate y/n
228 const char *s_NEWGAME = NEWGAME; // PRESSKEY;
229 const char *s_RESTARTLEVEL= RESTARTLEVEL; // PRESSYN;
230 const char *s_NIGHTMARE = NIGHTMARE; // PRESSYN;
231 const char *s_SWSTRING = SWSTRING; // PRESSKEY;
232 const char *s_MSGOFF = MSGOFF;
233 const char *s_MSGON = MSGON;
234 const char *s_NETEND = NETEND; // PRESSKEY;
235 const char *s_ENDGAME = ENDGAME; // PRESSYN; // killough 4/4/98: end
236 const char *s_DOSY = DOSY;
237 const char *s_DETAILHI = DETAILHI;
238 const char *s_DETAILLO = DETAILLO;
239 const char *s_GAMMALVL0 = GAMMALVL0;
240 const char *s_GAMMALVL1 = GAMMALVL1;
241 const char *s_GAMMALVL2 = GAMMALVL2;
242 const char *s_GAMMALVL3 = GAMMALVL3;
243 const char *s_GAMMALVL4 = GAMMALVL4;
244 const char *s_EMPTYSTRING = EMPTYSTRING;
245 const char *s_GOTARMOR = GOTARMOR;
246 const char *s_GOTMEGA = GOTMEGA;
247 const char *s_GOTHTHBONUS = GOTHTHBONUS;
248 const char *s_GOTARMBONUS = GOTARMBONUS;
249 const char *s_GOTSTIM = GOTSTIM;
250 const char *s_GOTMEDINEED = GOTMEDINEED;
251 const char *s_GOTMEDIKIT = GOTMEDIKIT;
252 const char *s_GOTSUPER = GOTSUPER;
253 const char *s_GOTBLUECARD = GOTBLUECARD;
254 const char *s_GOTYELWCARD = GOTYELWCARD;
255 const char *s_GOTREDCARD = GOTREDCARD;
256 const char *s_GOTBLUESKUL = GOTBLUESKUL;
257 const char *s_GOTYELWSKUL = GOTYELWSKUL;
258 const char *s_GOTREDSKULL = GOTREDSKULL;
259 const char *s_GOTINVUL = GOTINVUL;
260 const char *s_GOTBERSERK = GOTBERSERK;
261 const char *s_GOTINVIS = GOTINVIS;
262 const char *s_GOTSUIT = GOTSUIT;
263 const char *s_GOTMAP = GOTMAP;
264 const char *s_GOTVISOR = GOTVISOR;
265 const char *s_GOTMSPHERE = GOTMSPHERE;
266 const char *s_GOTCLIP = GOTCLIP;
267 const char *s_GOTCLIPBOX = GOTCLIPBOX;
268 const char *s_GOTROCKET = GOTROCKET;
269 const char *s_GOTROCKBOX = GOTROCKBOX;
270 const char *s_GOTCELL = GOTCELL;
271 const char *s_GOTCELLBOX = GOTCELLBOX;
272 const char *s_GOTSHELLS = GOTSHELLS;
273 const char *s_GOTSHELLBOX = GOTSHELLBOX;
274 const char *s_GOTBACKPACK = GOTBACKPACK;
275 const char *s_GOTBFG9000 = GOTBFG9000;
276 const char *s_GOTCHAINGUN = GOTCHAINGUN;
277 const char *s_GOTCHAINSAW = GOTCHAINSAW;
278 const char *s_GOTLAUNCHER = GOTLAUNCHER;
279 const char *s_GOTPLASMA = GOTPLASMA;
280 const char *s_GOTSHOTGUN = GOTSHOTGUN;
281 const char *s_GOTSHOTGUN2 = GOTSHOTGUN2;
282 const char *s_PD_BLUEO = PD_BLUEO;
283 const char *s_PD_REDO = PD_REDO;
284 const char *s_PD_YELLOWO = PD_YELLOWO;
285 const char *s_PD_BLUEK = PD_BLUEK;
286 const char *s_PD_REDK = PD_REDK;
287 const char *s_PD_YELLOWK = PD_YELLOWK;
288 const char *s_PD_BLUEC = PD_BLUEC;
289 const char *s_PD_REDC = PD_REDC;
290 const char *s_PD_YELLOWC = PD_YELLOWC;
291 const char *s_PD_BLUES = PD_BLUES;
292 const char *s_PD_REDS = PD_REDS;
293 const char *s_PD_YELLOWS = PD_YELLOWS;
294 const char *s_PD_ANY = PD_ANY;
295 const char *s_PD_ALL3 = PD_ALL3;
296 const char *s_PD_ALL6 = PD_ALL6;
297 const char *s_GGSAVED = GGSAVED;
298 const char *s_HUSTR_MSGU = HUSTR_MSGU;
299 const char *s_HUSTR_E1M1 = HUSTR_E1M1;
300 const char *s_HUSTR_E1M2 = HUSTR_E1M2;
301 const char *s_HUSTR_E1M3 = HUSTR_E1M3;
302 const char *s_HUSTR_E1M4 = HUSTR_E1M4;
303 const char *s_HUSTR_E1M5 = HUSTR_E1M5;
304 const char *s_HUSTR_E1M6 = HUSTR_E1M6;
305 const char *s_HUSTR_E1M7 = HUSTR_E1M7;
306 const char *s_HUSTR_E1M8 = HUSTR_E1M8;
307 const char *s_HUSTR_E1M9 = HUSTR_E1M9;
308 const char *s_HUSTR_E2M1 = HUSTR_E2M1;
309 const char *s_HUSTR_E2M2 = HUSTR_E2M2;
310 const char *s_HUSTR_E2M3 = HUSTR_E2M3;
311 const char *s_HUSTR_E2M4 = HUSTR_E2M4;
312 const char *s_HUSTR_E2M5 = HUSTR_E2M5;
313 const char *s_HUSTR_E2M6 = HUSTR_E2M6;
314 const char *s_HUSTR_E2M7 = HUSTR_E2M7;
315 const char *s_HUSTR_E2M8 = HUSTR_E2M8;
316 const char *s_HUSTR_E2M9 = HUSTR_E2M9;
317 const char *s_HUSTR_E3M1 = HUSTR_E3M1;
318 const char *s_HUSTR_E3M2 = HUSTR_E3M2;
319 const char *s_HUSTR_E3M3 = HUSTR_E3M3;
320 const char *s_HUSTR_E3M4 = HUSTR_E3M4;
321 const char *s_HUSTR_E3M5 = HUSTR_E3M5;
322 const char *s_HUSTR_E3M6 = HUSTR_E3M6;
323 const char *s_HUSTR_E3M7 = HUSTR_E3M7;
324 const char *s_HUSTR_E3M8 = HUSTR_E3M8;
325 const char *s_HUSTR_E3M9 = HUSTR_E3M9;
326 const char *s_HUSTR_E4M1 = HUSTR_E4M1;
327 const char *s_HUSTR_E4M2 = HUSTR_E4M2;
328 const char *s_HUSTR_E4M3 = HUSTR_E4M3;
329 const char *s_HUSTR_E4M4 = HUSTR_E4M4;
330 const char *s_HUSTR_E4M5 = HUSTR_E4M5;
331 const char *s_HUSTR_E4M6 = HUSTR_E4M6;
332 const char *s_HUSTR_E4M7 = HUSTR_E4M7;
333 const char *s_HUSTR_E4M8 = HUSTR_E4M8;
334 const char *s_HUSTR_E4M9 = HUSTR_E4M9;
335 const char *s_HUSTR_1 = HUSTR_1;
336 const char *s_HUSTR_2 = HUSTR_2;
337 const char *s_HUSTR_3 = HUSTR_3;
338 const char *s_HUSTR_4 = HUSTR_4;
339 const char *s_HUSTR_5 = HUSTR_5;
340 const char *s_HUSTR_6 = HUSTR_6;
341 const char *s_HUSTR_7 = HUSTR_7;
342 const char *s_HUSTR_8 = HUSTR_8;
343 const char *s_HUSTR_9 = HUSTR_9;
344 const char *s_HUSTR_10 = HUSTR_10;
345 const char *s_HUSTR_11 = HUSTR_11;
346 const char *s_HUSTR_12 = HUSTR_12;
347 const char *s_HUSTR_13 = HUSTR_13;
348 const char *s_HUSTR_14 = HUSTR_14;
349 const char *s_HUSTR_15 = HUSTR_15;
350 const char *s_HUSTR_16 = HUSTR_16;
351 const char *s_HUSTR_17 = HUSTR_17;
352 const char *s_HUSTR_18 = HUSTR_18;
353 const char *s_HUSTR_19 = HUSTR_19;
354 const char *s_HUSTR_20 = HUSTR_20;
355 const char *s_HUSTR_21 = HUSTR_21;
356 const char *s_HUSTR_22 = HUSTR_22;
357 const char *s_HUSTR_23 = HUSTR_23;
358 const char *s_HUSTR_24 = HUSTR_24;
359 const char *s_HUSTR_25 = HUSTR_25;
360 const char *s_HUSTR_26 = HUSTR_26;
361 const char *s_HUSTR_27 = HUSTR_27;
362 const char *s_HUSTR_28 = HUSTR_28;
363 const char *s_HUSTR_29 = HUSTR_29;
364 const char *s_HUSTR_30 = HUSTR_30;
365 const char *s_HUSTR_31 = HUSTR_31;
366 const char *s_HUSTR_32 = HUSTR_32;
367 const char *s_HUSTR_33 = HUSTR_33;
368 const char *s_PHUSTR_1 = PHUSTR_1;
369 const char *s_PHUSTR_2 = PHUSTR_2;
370 const char *s_PHUSTR_3 = PHUSTR_3;
371 const char *s_PHUSTR_4 = PHUSTR_4;
372 const char *s_PHUSTR_5 = PHUSTR_5;
373 const char *s_PHUSTR_6 = PHUSTR_6;
374 const char *s_PHUSTR_7 = PHUSTR_7;
375 const char *s_PHUSTR_8 = PHUSTR_8;
376 const char *s_PHUSTR_9 = PHUSTR_9;
377 const char *s_PHUSTR_10 = PHUSTR_10;
378 const char *s_PHUSTR_11 = PHUSTR_11;
379 const char *s_PHUSTR_12 = PHUSTR_12;
380 const char *s_PHUSTR_13 = PHUSTR_13;
381 const char *s_PHUSTR_14 = PHUSTR_14;
382 const char *s_PHUSTR_15 = PHUSTR_15;
383 const char *s_PHUSTR_16 = PHUSTR_16;
384 const char *s_PHUSTR_17 = PHUSTR_17;
385 const char *s_PHUSTR_18 = PHUSTR_18;
386 const char *s_PHUSTR_19 = PHUSTR_19;
387 const char *s_PHUSTR_20 = PHUSTR_20;
388 const char *s_PHUSTR_21 = PHUSTR_21;
389 const char *s_PHUSTR_22 = PHUSTR_22;
390 const char *s_PHUSTR_23 = PHUSTR_23;
391 const char *s_PHUSTR_24 = PHUSTR_24;
392 const char *s_PHUSTR_25 = PHUSTR_25;
393 const char *s_PHUSTR_26 = PHUSTR_26;
394 const char *s_PHUSTR_27 = PHUSTR_27;
395 const char *s_PHUSTR_28 = PHUSTR_28;
396 const char *s_PHUSTR_29 = PHUSTR_29;
397 const char *s_PHUSTR_30 = PHUSTR_30;
398 const char *s_PHUSTR_31 = PHUSTR_31;
399 const char *s_PHUSTR_32 = PHUSTR_32;
400 const char *s_THUSTR_1 = THUSTR_1;
401 const char *s_THUSTR_2 = THUSTR_2;
402 const char *s_THUSTR_3 = THUSTR_3;
403 const char *s_THUSTR_4 = THUSTR_4;
404 const char *s_THUSTR_5 = THUSTR_5;
405 const char *s_THUSTR_6 = THUSTR_6;
406 const char *s_THUSTR_7 = THUSTR_7;
407 const char *s_THUSTR_8 = THUSTR_8;
408 const char *s_THUSTR_9 = THUSTR_9;
409 const char *s_THUSTR_10 = THUSTR_10;
410 const char *s_THUSTR_11 = THUSTR_11;
411 const char *s_THUSTR_12 = THUSTR_12;
412 const char *s_THUSTR_13 = THUSTR_13;
413 const char *s_THUSTR_14 = THUSTR_14;
414 const char *s_THUSTR_15 = THUSTR_15;
415 const char *s_THUSTR_16 = THUSTR_16;
416 const char *s_THUSTR_17 = THUSTR_17;
417 const char *s_THUSTR_18 = THUSTR_18;
418 const char *s_THUSTR_19 = THUSTR_19;
419 const char *s_THUSTR_20 = THUSTR_20;
420 const char *s_THUSTR_21 = THUSTR_21;
421 const char *s_THUSTR_22 = THUSTR_22;
422 const char *s_THUSTR_23 = THUSTR_23;
423 const char *s_THUSTR_24 = THUSTR_24;
424 const char *s_THUSTR_25 = THUSTR_25;
425 const char *s_THUSTR_26 = THUSTR_26;
426 const char *s_THUSTR_27 = THUSTR_27;
427 const char *s_THUSTR_28 = THUSTR_28;
428 const char *s_THUSTR_29 = THUSTR_29;
429 const char *s_THUSTR_30 = THUSTR_30;
430 const char *s_THUSTR_31 = THUSTR_31;
431 const char *s_THUSTR_32 = THUSTR_32;
432 const char *s_AMSTR_FOLLOWON = AMSTR_FOLLOWON;
433 const char *s_AMSTR_FOLLOWOFF = AMSTR_FOLLOWOFF;
434 const char *s_AMSTR_GRIDON = AMSTR_GRIDON;
435 const char *s_AMSTR_GRIDOFF = AMSTR_GRIDOFF;
436 const char *s_AMSTR_MARKEDSPOT = AMSTR_MARKEDSPOT;
437 const char *s_AMSTR_MARKSCLEARED = AMSTR_MARKSCLEARED;
438 // CPhipps - automap rotate & overlay
439 const char* s_AMSTR_ROTATEON = AMSTR_ROTATEON;
440 const char* s_AMSTR_ROTATEOFF = AMSTR_ROTATEOFF;
441 const char* s_AMSTR_OVERLAYON = AMSTR_OVERLAYON;
442 const char* s_AMSTR_OVERLAYOFF = AMSTR_OVERLAYOFF;
443 // e6y: textured automap
444 const char* s_AMSTR_TEXTUREDON = AMSTR_TEXTUREDON;
445 const char* s_AMSTR_TEXTUREDOFF = AMSTR_TEXTUREDOFF;
446
447 const char *s_STSTR_MUS = STSTR_MUS;
448 const char *s_STSTR_NOMUS = STSTR_NOMUS;
449 const char *s_STSTR_DQDON = STSTR_DQDON;
450 const char *s_STSTR_DQDOFF = STSTR_DQDOFF;
451 const char *s_STSTR_KFAADDED = STSTR_KFAADDED;
452 const char *s_STSTR_FAADDED = STSTR_FAADDED;
453 const char *s_STSTR_NCON = STSTR_NCON;
454 const char *s_STSTR_NCOFF = STSTR_NCOFF;
455 const char *s_STSTR_BEHOLD = STSTR_BEHOLD;
456 const char *s_STSTR_BEHOLDX = STSTR_BEHOLDX;
457 const char *s_STSTR_CHOPPERS = STSTR_CHOPPERS;
458 const char *s_STSTR_CLEV = STSTR_CLEV;
459 const char *s_STSTR_COMPON = STSTR_COMPON;
460 const char *s_STSTR_COMPOFF = STSTR_COMPOFF;
461 const char *s_E1TEXT = E1TEXT;
462 const char *s_E2TEXT = E2TEXT;
463 const char *s_E3TEXT = E3TEXT;
464 const char *s_E4TEXT = E4TEXT;
465 const char *s_C1TEXT = C1TEXT;
466 const char *s_C2TEXT = C2TEXT;
467 const char *s_C3TEXT = C3TEXT;
468 const char *s_C4TEXT = C4TEXT;
469 const char *s_C5TEXT = C5TEXT;
470 const char *s_C6TEXT = C6TEXT;
471 const char *s_P1TEXT = P1TEXT;
472 const char *s_P2TEXT = P2TEXT;
473 const char *s_P3TEXT = P3TEXT;
474 const char *s_P4TEXT = P4TEXT;
475 const char *s_P5TEXT = P5TEXT;
476 const char *s_P6TEXT = P6TEXT;
477 const char *s_T1TEXT = T1TEXT;
478 const char *s_T2TEXT = T2TEXT;
479 const char *s_T3TEXT = T3TEXT;
480 const char *s_T4TEXT = T4TEXT;
481 const char *s_T5TEXT = T5TEXT;
482 const char *s_T6TEXT = T6TEXT;
483 const char *s_CC_ZOMBIE = CC_ZOMBIE;
484 const char *s_CC_SHOTGUN = CC_SHOTGUN;
485 const char *s_CC_HEAVY = CC_HEAVY;
486 const char *s_CC_IMP = CC_IMP;
487 const char *s_CC_DEMON = CC_DEMON;
488 const char *s_CC_LOST = CC_LOST;
489 const char *s_CC_CACO = CC_CACO;
490 const char *s_CC_HELL = CC_HELL;
491 const char *s_CC_BARON = CC_BARON;
492 const char *s_CC_ARACH = CC_ARACH;
493 const char *s_CC_PAIN = CC_PAIN;
494 const char *s_CC_REVEN = CC_REVEN;
495 const char *s_CC_MANCU = CC_MANCU;
496 const char *s_CC_ARCH = CC_ARCH;
497 const char *s_CC_SPIDER = CC_SPIDER;
498 const char *s_CC_CYBER = CC_CYBER;
499 const char *s_CC_HERO = CC_HERO;
500 // Ty 03/30/98 - new substitutions for background textures
501 // during int screens
502 const char *bgflatE1 = "FLOOR4_8"; // end of DOOM Episode 1
503 const char *bgflatE2 = "SFLR6_1"; // end of DOOM Episode 2
504 const char *bgflatE3 = "MFLR8_4"; // end of DOOM Episode 3
505 const char *bgflatE4 = "MFLR8_3"; // end of DOOM Episode 4
506 const char *bgflat06 = "SLIME16"; // DOOM2 after MAP06
507 const char *bgflat11 = "RROCK14"; // DOOM2 after MAP11
508 const char *bgflat20 = "RROCK07"; // DOOM2 after MAP20
509 const char *bgflat30 = "RROCK17"; // DOOM2 after MAP30
510 const char *bgflat15 = "RROCK13"; // DOOM2 going MAP15 to MAP31
511 const char *bgflat31 = "RROCK19"; // DOOM2 going MAP31 to MAP32
512 const char *bgcastcall = "BOSSBACK"; // Panel behind cast call
513
514 /* Ty 05/03/98 - externalized
515 * cph - updated for prboom */
516 const char *savegamename = PROJECT_TARNAME"-savegame";
517
518 // end d_deh.h variable declarations
519 // ====================================================================
520
521 // Do this for a lookup--the pointer (loaded above) is cross-referenced
522 // to a string key that is the same as the define above. We will use
523 // strdups to set these new values that we read from the file, orphaning
524 // the original value set above.
525
526 // CPhipps - make strings pointed to const
527 typedef struct {
528 const char **ppstr; // doubly indirect pointer to string
529 const char *lookup; // pointer to lookup string name
530 const char *orig;
531 } deh_strs;
532
533 /* CPhipps - const
534 * - removed redundant "Can't XXX in a netgame" strings
535 */
536 static deh_strs deh_strlookup[] = {
537 {&s_PRESSKEY,"PRESSKEY"},
538 {&s_PRESSYN,"PRESSYN"},
539 {&s_QUITMSG,"QUITMSG"},
540 {&s_QUITMSG1,"QUITMSG1"},
541 {&s_QUITMSG2,"QUITMSG2"},
542 {&s_QUITMSG3,"QUITMSG3"},
543 {&s_QUITMSG4,"QUITMSG4"},
544 {&s_QUITMSG5,"QUITMSG5"},
545 {&s_QUITMSG6,"QUITMSG6"},
546 {&s_QUITMSG7,"QUITMSG7"},
547 {&s_QUITMSG8,"QUITMSG8"},
548 {&s_QUITMSG9,"QUITMSG9"},
549 {&s_QUITMSG10,"QUITMSG10"},
550 {&s_QUITMSG11,"QUITMSG11"},
551 {&s_QUITMSG12,"QUITMSG12"},
552 {&s_QUITMSG13,"QUITMSG13"},
553 {&s_QUITMSG14,"QUITMSG14"},
554 {&s_QSAVESPOT,"QSAVESPOT"},
555 {&s_SAVEDEAD,"SAVEDEAD"},
556 {&s_NEWGAME,"NEWGAME"},
557 {&s_RESTARTLEVEL,"RESTARTLEVEL"},
558 {&s_NIGHTMARE,"NIGHTMARE"},
559 {&s_SWSTRING,"SWSTRING"},
560 {&s_MSGOFF,"MSGOFF"},
561 {&s_MSGON,"MSGON"},
562 {&s_NETEND,"NETEND"},
563 {&s_ENDGAME,"ENDGAME"},
564 {&s_DOSY,"DOSY"},
565 {&s_DETAILHI,"DETAILHI"},
566 {&s_DETAILLO,"DETAILLO"},
567 {&s_GAMMALVL0,"GAMMALVL0"},
568 {&s_GAMMALVL1,"GAMMALVL1"},
569 {&s_GAMMALVL2,"GAMMALVL2"},
570 {&s_GAMMALVL3,"GAMMALVL3"},
571 {&s_GAMMALVL4,"GAMMALVL4"},
572 {&s_EMPTYSTRING,"EMPTYSTRING"},
573 {&s_GOTARMOR,"GOTARMOR"},
574 {&s_GOTMEGA,"GOTMEGA"},
575 {&s_GOTHTHBONUS,"GOTHTHBONUS"},
576 {&s_GOTARMBONUS,"GOTARMBONUS"},
577 {&s_GOTSTIM,"GOTSTIM"},
578 {&s_GOTMEDINEED,"GOTMEDINEED"},
579 {&s_GOTMEDIKIT,"GOTMEDIKIT"},
580 {&s_GOTSUPER,"GOTSUPER"},
581 {&s_GOTBLUECARD,"GOTBLUECARD"},
582 {&s_GOTYELWCARD,"GOTYELWCARD"},
583 {&s_GOTREDCARD,"GOTREDCARD"},
584 {&s_GOTBLUESKUL,"GOTBLUESKUL"},
585 {&s_GOTYELWSKUL,"GOTYELWSKUL"},
586 {&s_GOTREDSKULL,"GOTREDSKULL"},
587 {&s_GOTINVUL,"GOTINVUL"},
588 {&s_GOTBERSERK,"GOTBERSERK"},
589 {&s_GOTINVIS,"GOTINVIS"},
590 {&s_GOTSUIT,"GOTSUIT"},
591 {&s_GOTMAP,"GOTMAP"},
592 {&s_GOTVISOR,"GOTVISOR"},
593 {&s_GOTMSPHERE,"GOTMSPHERE"},
594 {&s_GOTCLIP,"GOTCLIP"},
595 {&s_GOTCLIPBOX,"GOTCLIPBOX"},
596 {&s_GOTROCKET,"GOTROCKET"},
597 {&s_GOTROCKBOX,"GOTROCKBOX"},
598 {&s_GOTCELL,"GOTCELL"},
599 {&s_GOTCELLBOX,"GOTCELLBOX"},
600 {&s_GOTSHELLS,"GOTSHELLS"},
601 {&s_GOTSHELLBOX,"GOTSHELLBOX"},
602 {&s_GOTBACKPACK,"GOTBACKPACK"},
603 {&s_GOTBFG9000,"GOTBFG9000"},
604 {&s_GOTCHAINGUN,"GOTCHAINGUN"},
605 {&s_GOTCHAINSAW,"GOTCHAINSAW"},
606 {&s_GOTLAUNCHER,"GOTLAUNCHER"},
607 {&s_GOTPLASMA,"GOTPLASMA"},
608 {&s_GOTSHOTGUN,"GOTSHOTGUN"},
609 {&s_GOTSHOTGUN2,"GOTSHOTGUN2"},
610 {&s_PD_BLUEO,"PD_BLUEO"},
611 {&s_PD_REDO,"PD_REDO"},
612 {&s_PD_YELLOWO,"PD_YELLOWO"},
613 {&s_PD_BLUEK,"PD_BLUEK"},
614 {&s_PD_REDK,"PD_REDK"},
615 {&s_PD_YELLOWK,"PD_YELLOWK"},
616 {&s_PD_BLUEC,"PD_BLUEC"},
617 {&s_PD_REDC,"PD_REDC"},
618 {&s_PD_YELLOWC,"PD_YELLOWC"},
619 {&s_PD_BLUES,"PD_BLUES"},
620 {&s_PD_REDS,"PD_REDS"},
621 {&s_PD_YELLOWS,"PD_YELLOWS"},
622 {&s_PD_ANY,"PD_ANY"},
623 {&s_PD_ALL3,"PD_ALL3"},
624 {&s_PD_ALL6,"PD_ALL6"},
625 {&s_GGSAVED,"GGSAVED"},
626 {&s_HUSTR_MSGU,"HUSTR_MSGU"},
627 {&s_HUSTR_E1M1,"HUSTR_E1M1"},
628 {&s_HUSTR_E1M2,"HUSTR_E1M2"},
629 {&s_HUSTR_E1M3,"HUSTR_E1M3"},
630 {&s_HUSTR_E1M4,"HUSTR_E1M4"},
631 {&s_HUSTR_E1M5,"HUSTR_E1M5"},
632 {&s_HUSTR_E1M6,"HUSTR_E1M6"},
633 {&s_HUSTR_E1M7,"HUSTR_E1M7"},
634 {&s_HUSTR_E1M8,"HUSTR_E1M8"},
635 {&s_HUSTR_E1M9,"HUSTR_E1M9"},
636 {&s_HUSTR_E2M1,"HUSTR_E2M1"},
637 {&s_HUSTR_E2M2,"HUSTR_E2M2"},
638 {&s_HUSTR_E2M3,"HUSTR_E2M3"},
639 {&s_HUSTR_E2M4,"HUSTR_E2M4"},
640 {&s_HUSTR_E2M5,"HUSTR_E2M5"},
641 {&s_HUSTR_E2M6,"HUSTR_E2M6"},
642 {&s_HUSTR_E2M7,"HUSTR_E2M7"},
643 {&s_HUSTR_E2M8,"HUSTR_E2M8"},
644 {&s_HUSTR_E2M9,"HUSTR_E2M9"},
645 {&s_HUSTR_E3M1,"HUSTR_E3M1"},
646 {&s_HUSTR_E3M2,"HUSTR_E3M2"},
647 {&s_HUSTR_E3M3,"HUSTR_E3M3"},
648 {&s_HUSTR_E3M4,"HUSTR_E3M4"},
649 {&s_HUSTR_E3M5,"HUSTR_E3M5"},
650 {&s_HUSTR_E3M6,"HUSTR_E3M6"},
651 {&s_HUSTR_E3M7,"HUSTR_E3M7"},
652 {&s_HUSTR_E3M8,"HUSTR_E3M8"},
653 {&s_HUSTR_E3M9,"HUSTR_E3M9"},
654 {&s_HUSTR_E4M1,"HUSTR_E4M1"},
655 {&s_HUSTR_E4M2,"HUSTR_E4M2"},
656 {&s_HUSTR_E4M3,"HUSTR_E4M3"},
657 {&s_HUSTR_E4M4,"HUSTR_E4M4"},
658 {&s_HUSTR_E4M5,"HUSTR_E4M5"},
659 {&s_HUSTR_E4M6,"HUSTR_E4M6"},
660 {&s_HUSTR_E4M7,"HUSTR_E4M7"},
661 {&s_HUSTR_E4M8,"HUSTR_E4M8"},
662 {&s_HUSTR_E4M9,"HUSTR_E4M9"},
663 {&s_HUSTR_1,"HUSTR_1"},
664 {&s_HUSTR_2,"HUSTR_2"},
665 {&s_HUSTR_3,"HUSTR_3"},
666 {&s_HUSTR_4,"HUSTR_4"},
667 {&s_HUSTR_5,"HUSTR_5"},
668 {&s_HUSTR_6,"HUSTR_6"},
669 {&s_HUSTR_7,"HUSTR_7"},
670 {&s_HUSTR_8,"HUSTR_8"},
671 {&s_HUSTR_9,"HUSTR_9"},
672 {&s_HUSTR_10,"HUSTR_10"},
673 {&s_HUSTR_11,"HUSTR_11"},
674 {&s_HUSTR_12,"HUSTR_12"},
675 {&s_HUSTR_13,"HUSTR_13"},
676 {&s_HUSTR_14,"HUSTR_14"},
677 {&s_HUSTR_15,"HUSTR_15"},
678 {&s_HUSTR_16,"HUSTR_16"},
679 {&s_HUSTR_17,"HUSTR_17"},
680 {&s_HUSTR_18,"HUSTR_18"},
681 {&s_HUSTR_19,"HUSTR_19"},
682 {&s_HUSTR_20,"HUSTR_20"},
683 {&s_HUSTR_21,"HUSTR_21"},
684 {&s_HUSTR_22,"HUSTR_22"},
685 {&s_HUSTR_23,"HUSTR_23"},
686 {&s_HUSTR_24,"HUSTR_24"},
687 {&s_HUSTR_25,"HUSTR_25"},
688 {&s_HUSTR_26,"HUSTR_26"},
689 {&s_HUSTR_27,"HUSTR_27"},
690 {&s_HUSTR_28,"HUSTR_28"},
691 {&s_HUSTR_29,"HUSTR_29"},
692 {&s_HUSTR_30,"HUSTR_30"},
693 {&s_HUSTR_31,"HUSTR_31"},
694 {&s_HUSTR_32,"HUSTR_32"},
695 {&s_HUSTR_33,"HUSTR_33"},
696 {&s_PHUSTR_1,"PHUSTR_1"},
697 {&s_PHUSTR_2,"PHUSTR_2"},
698 {&s_PHUSTR_3,"PHUSTR_3"},
699 {&s_PHUSTR_4,"PHUSTR_4"},
700 {&s_PHUSTR_5,"PHUSTR_5"},
701 {&s_PHUSTR_6,"PHUSTR_6"},
702 {&s_PHUSTR_7,"PHUSTR_7"},
703 {&s_PHUSTR_8,"PHUSTR_8"},
704 {&s_PHUSTR_9,"PHUSTR_9"},
705 {&s_PHUSTR_10,"PHUSTR_10"},
706 {&s_PHUSTR_11,"PHUSTR_11"},
707 {&s_PHUSTR_12,"PHUSTR_12"},
708 {&s_PHUSTR_13,"PHUSTR_13"},
709 {&s_PHUSTR_14,"PHUSTR_14"},
710 {&s_PHUSTR_15,"PHUSTR_15"},
711 {&s_PHUSTR_16,"PHUSTR_16"},
712 {&s_PHUSTR_17,"PHUSTR_17"},
713 {&s_PHUSTR_18,"PHUSTR_18"},
714 {&s_PHUSTR_19,"PHUSTR_19"},
715 {&s_PHUSTR_20,"PHUSTR_20"},
716 {&s_PHUSTR_21,"PHUSTR_21"},
717 {&s_PHUSTR_22,"PHUSTR_22"},
718 {&s_PHUSTR_23,"PHUSTR_23"},
719 {&s_PHUSTR_24,"PHUSTR_24"},
720 {&s_PHUSTR_25,"PHUSTR_25"},
721 {&s_PHUSTR_26,"PHUSTR_26"},
722 {&s_PHUSTR_27,"PHUSTR_27"},
723 {&s_PHUSTR_28,"PHUSTR_28"},
724 {&s_PHUSTR_29,"PHUSTR_29"},
725 {&s_PHUSTR_30,"PHUSTR_30"},
726 {&s_PHUSTR_31,"PHUSTR_31"},
727 {&s_PHUSTR_32,"PHUSTR_32"},
728 {&s_THUSTR_1,"THUSTR_1"},
729 {&s_THUSTR_2,"THUSTR_2"},
730 {&s_THUSTR_3,"THUSTR_3"},
731 {&s_THUSTR_4,"THUSTR_4"},
732 {&s_THUSTR_5,"THUSTR_5"},
733 {&s_THUSTR_6,"THUSTR_6"},
734 {&s_THUSTR_7,"THUSTR_7"},
735 {&s_THUSTR_8,"THUSTR_8"},
736 {&s_THUSTR_9,"THUSTR_9"},
737 {&s_THUSTR_10,"THUSTR_10"},
738 {&s_THUSTR_11,"THUSTR_11"},
739 {&s_THUSTR_12,"THUSTR_12"},
740 {&s_THUSTR_13,"THUSTR_13"},
741 {&s_THUSTR_14,"THUSTR_14"},
742 {&s_THUSTR_15,"THUSTR_15"},
743 {&s_THUSTR_16,"THUSTR_16"},
744 {&s_THUSTR_17,"THUSTR_17"},
745 {&s_THUSTR_18,"THUSTR_18"},
746 {&s_THUSTR_19,"THUSTR_19"},
747 {&s_THUSTR_20,"THUSTR_20"},
748 {&s_THUSTR_21,"THUSTR_21"},
749 {&s_THUSTR_22,"THUSTR_22"},
750 {&s_THUSTR_23,"THUSTR_23"},
751 {&s_THUSTR_24,"THUSTR_24"},
752 {&s_THUSTR_25,"THUSTR_25"},
753 {&s_THUSTR_26,"THUSTR_26"},
754 {&s_THUSTR_27,"THUSTR_27"},
755 {&s_THUSTR_28,"THUSTR_28"},
756 {&s_THUSTR_29,"THUSTR_29"},
757 {&s_THUSTR_30,"THUSTR_30"},
758 {&s_THUSTR_31,"THUSTR_31"},
759 {&s_THUSTR_32,"THUSTR_32"},
760 {&s_AMSTR_FOLLOWON,"AMSTR_FOLLOWON"},
761 {&s_AMSTR_FOLLOWOFF,"AMSTR_FOLLOWOFF"},
762 {&s_AMSTR_GRIDON,"AMSTR_GRIDON"},
763 {&s_AMSTR_GRIDOFF,"AMSTR_GRIDOFF"},
764 {&s_AMSTR_MARKEDSPOT,"AMSTR_MARKEDSPOT"},
765 {&s_AMSTR_MARKSCLEARED,"AMSTR_MARKSCLEARED"},
766 {&s_STSTR_MUS,"STSTR_MUS"},
767 {&s_STSTR_NOMUS,"STSTR_NOMUS"},
768 {&s_STSTR_DQDON,"STSTR_DQDON"},
769 {&s_STSTR_DQDOFF,"STSTR_DQDOFF"},
770 {&s_STSTR_KFAADDED,"STSTR_KFAADDED"},
771 {&s_STSTR_FAADDED,"STSTR_FAADDED"},
772 {&s_STSTR_NCON,"STSTR_NCON"},
773 {&s_STSTR_NCOFF,"STSTR_NCOFF"},
774 {&s_STSTR_BEHOLD,"STSTR_BEHOLD"},
775 {&s_STSTR_BEHOLDX,"STSTR_BEHOLDX"},
776 {&s_STSTR_CHOPPERS,"STSTR_CHOPPERS"},
777 {&s_STSTR_CLEV,"STSTR_CLEV"},
778 {&s_STSTR_COMPON,"STSTR_COMPON"},
779 {&s_STSTR_COMPOFF,"STSTR_COMPOFF"},
780 {&s_E1TEXT,"E1TEXT"},
781 {&s_E2TEXT,"E2TEXT"},
782 {&s_E3TEXT,"E3TEXT"},
783 {&s_E4TEXT,"E4TEXT"},
784 {&s_C1TEXT,"C1TEXT"},
785 {&s_C2TEXT,"C2TEXT"},
786 {&s_C3TEXT,"C3TEXT"},
787 {&s_C4TEXT,"C4TEXT"},
788 {&s_C5TEXT,"C5TEXT"},
789 {&s_C6TEXT,"C6TEXT"},
790 {&s_P1TEXT,"P1TEXT"},
791 {&s_P2TEXT,"P2TEXT"},
792 {&s_P3TEXT,"P3TEXT"},
793 {&s_P4TEXT,"P4TEXT"},
794 {&s_P5TEXT,"P5TEXT"},
795 {&s_P6TEXT,"P6TEXT"},
796 {&s_T1TEXT,"T1TEXT"},
797 {&s_T2TEXT,"T2TEXT"},
798 {&s_T3TEXT,"T3TEXT"},
799 {&s_T4TEXT,"T4TEXT"},
800 {&s_T5TEXT,"T5TEXT"},
801 {&s_T6TEXT,"T6TEXT"},
802 {&s_CC_ZOMBIE,"CC_ZOMBIE"},
803 {&s_CC_SHOTGUN,"CC_SHOTGUN"},
804 {&s_CC_HEAVY,"CC_HEAVY"},
805 {&s_CC_IMP,"CC_IMP"},
806 {&s_CC_DEMON,"CC_DEMON"},
807 {&s_CC_LOST,"CC_LOST"},
808 {&s_CC_CACO,"CC_CACO"},
809 {&s_CC_HELL,"CC_HELL"},
810 {&s_CC_BARON,"CC_BARON"},
811 {&s_CC_ARACH,"CC_ARACH"},
812 {&s_CC_PAIN,"CC_PAIN"},
813 {&s_CC_REVEN,"CC_REVEN"},
814 {&s_CC_MANCU,"CC_MANCU"},
815 {&s_CC_ARCH,"CC_ARCH"},
816 {&s_CC_SPIDER,"CC_SPIDER"},
817 {&s_CC_CYBER,"CC_CYBER"},
818 {&s_CC_HERO,"CC_HERO"},
819 {&bgflatE1,"BGFLATE1"},
820 {&bgflatE2,"BGFLATE2"},
821 {&bgflatE3,"BGFLATE3"},
822 {&bgflatE4,"BGFLATE4"},
823 {&bgflat06,"BGFLAT06"},
824 {&bgflat11,"BGFLAT11"},
825 {&bgflat20,"BGFLAT20"},
826 {&bgflat30,"BGFLAT30"},
827 {&bgflat15,"BGFLAT15"},
828 {&bgflat31,"BGFLAT31"},
829 {&bgcastcall,"BGCASTCALL"},
830 {&savegamename,"SAVEGAMENAME"}, // Ty 05/03/98
831 };
832
833 static int deh_numstrlookup = sizeof(deh_strlookup) / sizeof(deh_strlookup[0]);
834
835 const char *deh_newlevel = "NEWLEVEL"; // CPhipps - const
836
837 // DOOM shareware/registered/retail (Ultimate) names.
838 // CPhipps - const**const
839 const char **const mapnames[] =
840 {
841 &s_HUSTR_E1M1,
842 &s_HUSTR_E1M2,
843 &s_HUSTR_E1M3,
844 &s_HUSTR_E1M4,
845 &s_HUSTR_E1M5,
846 &s_HUSTR_E1M6,
847 &s_HUSTR_E1M7,
848 &s_HUSTR_E1M8,
849 &s_HUSTR_E1M9,
850
851 &s_HUSTR_E2M1,
852 &s_HUSTR_E2M2,
853 &s_HUSTR_E2M3,
854 &s_HUSTR_E2M4,
855 &s_HUSTR_E2M5,
856 &s_HUSTR_E2M6,
857 &s_HUSTR_E2M7,
858 &s_HUSTR_E2M8,
859 &s_HUSTR_E2M9,
860
861 &s_HUSTR_E3M1,
862 &s_HUSTR_E3M2,
863 &s_HUSTR_E3M3,
864 &s_HUSTR_E3M4,
865 &s_HUSTR_E3M5,
866 &s_HUSTR_E3M6,
867 &s_HUSTR_E3M7,
868 &s_HUSTR_E3M8,
869 &s_HUSTR_E3M9,
870
871 &s_HUSTR_E4M1,
872 &s_HUSTR_E4M2,
873 &s_HUSTR_E4M3,
874 &s_HUSTR_E4M4,
875 &s_HUSTR_E4M5,
876 &s_HUSTR_E4M6,
877 &s_HUSTR_E4M7,
878 &s_HUSTR_E4M8,
879 &s_HUSTR_E4M9,
880
881 &deh_newlevel, // spares? Unused.
882 &deh_newlevel,
883 &deh_newlevel,
884 &deh_newlevel,
885 &deh_newlevel,
886 &deh_newlevel,
887 &deh_newlevel,
888 &deh_newlevel,
889 &deh_newlevel,
890
891 &deh_newlevel, // spares? Unused.
892 &deh_newlevel,
893 &deh_newlevel,
894 &deh_newlevel,
895 &deh_newlevel,
896 &deh_newlevel,
897 &deh_newlevel,
898 &deh_newlevel,
899 &deh_newlevel
900 };
901
902 // CPhipps - const**const
903 const char **const mapnames2[] = // DOOM 2 map names.
904 {
905 &s_HUSTR_1,
906 &s_HUSTR_2,
907 &s_HUSTR_3,
908 &s_HUSTR_4,
909 &s_HUSTR_5,
910 &s_HUSTR_6,
911 &s_HUSTR_7,
912 &s_HUSTR_8,
913 &s_HUSTR_9,
914 &s_HUSTR_10,
915 &s_HUSTR_11,
916
917 &s_HUSTR_12,
918 &s_HUSTR_13,
919 &s_HUSTR_14,
920 &s_HUSTR_15,
921 &s_HUSTR_16,
922 &s_HUSTR_17,
923 &s_HUSTR_18,
924 &s_HUSTR_19,
925 &s_HUSTR_20,
926
927 &s_HUSTR_21,
928 &s_HUSTR_22,
929 &s_HUSTR_23,
930 &s_HUSTR_24,
931 &s_HUSTR_25,
932 &s_HUSTR_26,
933 &s_HUSTR_27,
934 &s_HUSTR_28,
935 &s_HUSTR_29,
936 &s_HUSTR_30,
937 &s_HUSTR_31,
938 &s_HUSTR_32,
939 &s_HUSTR_33,
940 };
941
942 // CPhipps - const**const
943 const char **const mapnamesp[] = // Plutonia WAD map names.
944 {
945 &s_PHUSTR_1,
946 &s_PHUSTR_2,
947 &s_PHUSTR_3,
948 &s_PHUSTR_4,
949 &s_PHUSTR_5,
950 &s_PHUSTR_6,
951 &s_PHUSTR_7,
952 &s_PHUSTR_8,
953 &s_PHUSTR_9,
954 &s_PHUSTR_10,
955 &s_PHUSTR_11,
956
957 &s_PHUSTR_12,
958 &s_PHUSTR_13,
959 &s_PHUSTR_14,
960 &s_PHUSTR_15,
961 &s_PHUSTR_16,
962 &s_PHUSTR_17,
963 &s_PHUSTR_18,
964 &s_PHUSTR_19,
965 &s_PHUSTR_20,
966
967 &s_PHUSTR_21,
968 &s_PHUSTR_22,
969 &s_PHUSTR_23,
970 &s_PHUSTR_24,
971 &s_PHUSTR_25,
972 &s_PHUSTR_26,
973 &s_PHUSTR_27,
974 &s_PHUSTR_28,
975 &s_PHUSTR_29,
976 &s_PHUSTR_30,
977 &s_PHUSTR_31,
978 &s_PHUSTR_32,
979 };
980
981 // CPhipps - const**const
982 const char **const mapnamest[] = // TNT WAD map names.
983 {
984 &s_THUSTR_1,
985 &s_THUSTR_2,
986 &s_THUSTR_3,
987 &s_THUSTR_4,
988 &s_THUSTR_5,
989 &s_THUSTR_6,
990 &s_THUSTR_7,
991 &s_THUSTR_8,
992 &s_THUSTR_9,
993 &s_THUSTR_10,
994 &s_THUSTR_11,
995
996 &s_THUSTR_12,
997 &s_THUSTR_13,
998 &s_THUSTR_14,
999 &s_THUSTR_15,
1000 &s_THUSTR_16,
1001 &s_THUSTR_17,
1002 &s_THUSTR_18,
1003 &s_THUSTR_19,
1004 &s_THUSTR_20,
1005
1006 &s_THUSTR_21,
1007 &s_THUSTR_22,
1008 &s_THUSTR_23,
1009 &s_THUSTR_24,
1010 &s_THUSTR_25,
1011 &s_THUSTR_26,
1012 &s_THUSTR_27,
1013 &s_THUSTR_28,
1014 &s_THUSTR_29,
1015 &s_THUSTR_30,
1016 &s_THUSTR_31,
1017 &s_THUSTR_32,
1018 };
1019
1020 // Function prototypes
1021 void lfstrip(char *); // strip the \r and/or \n off of a line
1022 void rstrip(char *); // strip trailing whitespace
1023 char * ptr_lstrip(char *); // point past leading whitespace
1024 dboolean deh_GetData(char *, char *, uint64_t *, char **);
1025 dboolean deh_procStringSub(char *, char *, char *);
1026 char * dehReformatStr(char *);
1027
1028 // Prototypes for block processing functions
1029 // Pointers to these functions are used as the blocks are encountered.
1030
1031 static void deh_procThing(DEHFILE *fpin, char *line);
1032 static void deh_procFrame(DEHFILE *, char *);
1033 static void deh_procPointer(DEHFILE *, char *);
1034 static void deh_procSounds(DEHFILE *, char *);
1035 static void deh_procAmmo(DEHFILE *, char *);
1036 static void deh_procWeapon(DEHFILE *, char *);
1037 static void deh_procSprite(DEHFILE *, char *);
1038 static void deh_procCheat(DEHFILE *, char *);
1039 static void deh_procMisc(DEHFILE *, char *);
1040 static void deh_procText(DEHFILE *, char *);
1041 static void deh_procPars(DEHFILE *, char *);
1042 static void deh_procStrings(DEHFILE *, char *);
1043 static void deh_procError(DEHFILE *, char *);
1044 static void deh_procBexCodePointers(DEHFILE *, char *);
1045 static void deh_procHelperThing(DEHFILE *, char *); // haleyjd 9/22/99
1046 // haleyjd: handlers to fully deprecate the DeHackEd text section
1047 static void deh_procBexSounds(DEHFILE *, char *);
1048 static void deh_procBexMusic(DEHFILE *, char *);
1049 static void deh_procBexSprites(DEHFILE *, char *);
1050
1051 // Structure deh_block is used to hold the block names that can
1052 // be encountered, and the routines to use to decipher them
1053
1054 typedef struct
1055 {
1056 const char *key; // a mnemonic block code name // CPhipps - const*
1057 void (*const fptr)(DEHFILE *, char *); // handler
1058 } deh_block;
1059
1060 #define DEH_BUFFERMAX 1024 // input buffer area size, hardcodedfor now
1061 // killough 8/9/98: make DEH_BLOCKMAX self-adjusting
1062 #define DEH_BLOCKMAX (sizeof(deh_blocks) / sizeof(*deh_blocks)) // size of array
1063 #define DEH_MAXKEYLEN 32 // as much of any key as we'll look at
1064
1065 // Put all the block header values, and the function to be called when that
1066 // one is encountered, in this array:
1067 static const deh_block deh_blocks[] = { // CPhipps - static const
1068 /* 0 */ {"Thing",deh_procThing},
1069 /* 1 */ {"Frame",deh_procFrame},
1070 /* 2 */ {"Pointer",deh_procPointer},
1071 /* 3 */ {"Sound",deh_procSounds}, // Ty 03/16/98 corrected from "Sounds"
1072 /* 4 */ {"Ammo",deh_procAmmo},
1073 /* 5 */ {"Weapon",deh_procWeapon},
1074 /* 6 */ {"Sprite",deh_procSprite},
1075 /* 7 */ {"Cheat",deh_procCheat},
1076 /* 8 */ {"Misc",deh_procMisc},
1077 /* 9 */ {"Text",deh_procText}, // -- end of standard "deh" entries,
1078
1079 // begin BOOM Extensions (BEX)
1080
1081 /* 10 */ {"[STRINGS]",deh_procStrings}, // new string changes
1082 /* 11 */ {"[PARS]",deh_procPars}, // alternative block marker
1083 /* 12 */ {"[CODEPTR]",deh_procBexCodePointers}, // bex codepointers by mnemonic
1084 /* 13 */ {"[HELPER]", deh_procHelperThing}, // helper thing substitution haleyjd 9/22/99
1085 /* 14 */ {"[SPRITES]", deh_procBexSprites}, // bex style sprites
1086 /* 15 */ {"[SOUNDS]", deh_procBexSounds}, // bex style sounds
1087 /* 16 */ {"[MUSIC]", deh_procBexMusic}, // bex style music
1088 /* 17 */ {"", deh_procError} // dummy to handle anything else
1089 };
1090
1091 // flag to skip included deh-style text, used with INCLUDE NOTEXT directive
1092 static dboolean includenotext = false;
1093
1094 // MOBJINFO - Dehacked block name = "Thing"
1095 // Usage: Thing nn (name)
1096 // These are for mobjinfo_t types. Each is an integer
1097 // within the structure, so we can use index of the string in this
1098 // array to offset by sizeof(int) into the mobjinfo_t array at [nn]
1099 // * things are base zero but dehacked considers them to start at #1. ***
1100 // CPhipps - static const
1101
1102 static const char *deh_mobjinfo_fields[] =
1103 {
1104 "ID #", // .doomednum
1105 "Initial frame", // .spawnstate
1106 "Hit points", // .spawnhealth
1107 "First moving frame", // .seestate
1108 "Alert sound", // .seesound
1109 "Reaction time", // .reactiontime
1110 "Attack sound", // .attacksound
1111 "Injury frame", // .painstate
1112 "Pain chance", // .painchance
1113 "Pain sound", // .painsound
1114 "Close attack frame", // .meleestate
1115 "Far attack frame", // .missilestate
1116 "Death frame", // .deathstate
1117 "Exploding frame", // .xdeathstate
1118 "Death sound", // .deathsound
1119 "Speed", // .speed
1120 "Width", // .radius
1121 "Height", // .height
1122 "Mass", // .mass
1123 "Missile damage", // .damage
1124 "Action sound", // .activesound
1125 "Bits", // .flags
1126 "Bits2", // .flags
1127 "Respawn frame", // .raisestate
1128 "Dropped item", // .droppeditem
1129
1130 // mbf21
1131 "Infighting group", // .infighting_group
1132 "Projectile group", // .projectile_group
1133 "Splash group", // .splash_group
1134 "MBF21 Bits", // .flags2
1135 "Rip sound", // .ripsound
1136 "Fast speed", // .altspeed
1137 "Melee range", // .meleerange
1138
1139 // misc
1140 "Blood color", // .bloodcolor
1141
1142 NULL
1143 };
1144
1145 // Strings that are used to indicate flags ("Bits" in mobjinfo)
1146 // This is an array of bit masks that are related to p_mobj.h
1147 // values, using the smae names without the MF_ in front.
1148 // Ty 08/27/98 new code
1149 //
1150 // killough 10/98:
1151 //
1152 // Convert array to struct to allow multiple values, make array size variable
1153
1154 struct deh_flag_s {
1155 const char *name; // CPhipps - const*
1156 uint64_t value;
1157 };
1158
1159 static uint64_t deh_translate_bits(uint64_t value, const struct deh_flag_s *flags)
1160 {
1161 int i;
1162 uint64_t result = 0;
1163
1164 for (i = 0; flags[i].name; ++i)
1165 {
1166 if (value & 1)
1167 result |= flags[i].value;
1168
1169 value >>= 1;
1170 }
1171
1172 return result;
1173 }
1174
1175 // CPhipps - static const
1176 static const struct deh_flag_s deh_mobjflags[] = {
1177 {"SPECIAL", MF_SPECIAL}, // call P_Specialthing when touched
1178 {"SOLID", MF_SOLID}, // block movement
1179 {"SHOOTABLE", MF_SHOOTABLE}, // can be hit
1180 {"NOSECTOR", MF_NOSECTOR}, // invisible but touchable
1181 {"NOBLOCKMAP", MF_NOBLOCKMAP}, // inert but displayable
1182 {"AMBUSH", MF_AMBUSH}, // deaf monster
1183 {"JUSTHIT", MF_JUSTHIT}, // will try to attack right back
1184 {"JUSTATTACKED", MF_JUSTATTACKED}, // take at least 1 step before attacking
1185 {"SPAWNCEILING", MF_SPAWNCEILING}, // initially hang from ceiling
1186 {"NOGRAVITY", MF_NOGRAVITY}, // don't apply gravity during play
1187 {"DROPOFF", MF_DROPOFF}, // can jump from high places
1188 {"PICKUP", MF_PICKUP}, // will pick up items
1189 {"NOCLIP", MF_NOCLIP}, // goes through walls
1190 {"SLIDE", MF_SLIDE}, // keep info about sliding along walls
1191 {"FLOAT", MF_FLOAT}, // allow movement to any height
1192 {"TELEPORT", MF_TELEPORT}, // don't cross lines or look at heights
1193 {"MISSILE", MF_MISSILE}, // don't hit same species, explode on block
1194 {"DROPPED", MF_DROPPED}, // dropped, not spawned (like ammo clip)
1195 {"SHADOW", MF_SHADOW}, // use fuzzy draw like spectres
1196 {"NOBLOOD", MF_NOBLOOD}, // puffs instead of blood when shot
1197 {"CORPSE", MF_CORPSE}, // so it will slide down steps when dead
1198 {"INFLOAT", MF_INFLOAT}, // float but not to target height
1199 {"COUNTKILL", MF_COUNTKILL}, // count toward the kills total
1200 {"COUNTITEM", MF_COUNTITEM}, // count toward the items total
1201 {"SKULLFLY", MF_SKULLFLY}, // special handling for flying skulls
1202 {"NOTDMATCH", MF_NOTDMATCH}, // do not spawn in deathmatch
1203
1204 // killough 10/98: TRANSLATION consists of 2 bits, not 1:
1205
1206 {"TRANSLATION", MF_TRANSLATION1}, // for Boom bug-compatibility
1207 {"TRANSLATION1", MF_TRANSLATION1}, // use translation table for color (players)
1208 {"TRANSLATION2", MF_TRANSLATION2}, // use translation table for color (players)
1209 {"UNUSED1", MF_TRANSLATION2}, // unused bit # 1 -- For Boom bug-compatibility
1210 {"UNUSED2", MF_UNUSED2}, // unused bit # 2 -- For Boom compatibility
1211 {"UNUSED3", MF_UNUSED3}, // unused bit # 3 -- For Boom compatibility
1212 {"UNUSED4", MF_TRANSLUCENT}, // unused bit # 4 -- For Boom compatibility
1213 {"TRANSLUCENT", MF_TRANSLUCENT}, // apply translucency to sprite (BOOM)
1214 {"TOUCHY", MF_TOUCHY}, // dies on contact with solid objects (MBF)
1215 {"BOUNCES", MF_BOUNCES}, // bounces off floors, ceilings and maybe walls (MBF)
1216 {"FRIEND", MF_FRIEND}, // a friend of the player(s) (MBF)
1217 { NULL }
1218 };
1219
1220 static const struct deh_flag_s deh_mobjflags_standard[] = {
1221 {"SPECIAL", MF_SPECIAL}, // call P_Specialthing when touched
1222 {"SOLID", MF_SOLID}, // block movement
1223 {"SHOOTABLE", MF_SHOOTABLE}, // can be hit
1224 {"NOSECTOR", MF_NOSECTOR}, // invisible but touchable
1225 {"NOBLOCKMAP", MF_NOBLOCKMAP}, // inert but displayable
1226 {"AMBUSH", MF_AMBUSH}, // deaf monster
1227 {"JUSTHIT", MF_JUSTHIT}, // will try to attack right back
1228 {"JUSTATTACKED", MF_JUSTATTACKED}, // take at least 1 step before attacking
1229 {"SPAWNCEILING", MF_SPAWNCEILING}, // initially hang from ceiling
1230 {"NOGRAVITY", MF_NOGRAVITY}, // don't apply gravity during play
1231 {"DROPOFF", MF_DROPOFF}, // can jump from high places
1232 {"PICKUP", MF_PICKUP}, // will pick up items
1233 {"NOCLIP", MF_NOCLIP}, // goes through walls
1234 {"SLIDE", MF_SLIDE}, // keep info about sliding along walls
1235 {"FLOAT", MF_FLOAT}, // allow movement to any height
1236 {"TELEPORT", MF_TELEPORT}, // don't cross lines or look at heights
1237 {"MISSILE", MF_MISSILE}, // don't hit same species, explode on block
1238 {"DROPPED", MF_DROPPED}, // dropped, not spawned (like ammo clip)
1239 {"SHADOW", MF_SHADOW}, // use fuzzy draw like spectres
1240 {"NOBLOOD", MF_NOBLOOD}, // puffs instead of blood when shot
1241 {"CORPSE", MF_CORPSE}, // so it will slide down steps when dead
1242 {"INFLOAT", MF_INFLOAT}, // float but not to target height
1243 {"COUNTKILL", MF_COUNTKILL}, // count toward the kills total
1244 {"COUNTITEM", MF_COUNTITEM}, // count toward the items total
1245 {"SKULLFLY", MF_SKULLFLY}, // special handling for flying skulls
1246 {"NOTDMATCH", MF_NOTDMATCH}, // do not spawn in deathmatch
1247 {"TRANSLATION1", MF_TRANSLATION1}, // use translation table for color (players)
1248 {"TRANSLATION2", MF_TRANSLATION2}, // use translation table for color (players)
1249 {"TOUCHY", MF_TOUCHY}, // dies on contact with solid objects (MBF)
1250 {"BOUNCES", MF_BOUNCES}, // bounces off floors, ceilings and maybe walls (MBF)
1251 {"FRIEND", MF_FRIEND}, // a friend of the player(s) (MBF)
1252 {"TRANSLUCENT", MF_TRANSLUCENT}, // apply translucency to sprite (BOOM)
1253 { NULL }
1254 };
1255
1256 static const struct deh_flag_s deh_mobjflags_mbf21[] = {
1257 {"LOGRAV", MF2_LOGRAV}, // low gravity
1258 {"SHORTMRANGE", MF2_SHORTMRANGE}, // short missile range
1259 {"DMGIGNORED", MF2_DMGIGNORED}, // other things ignore its attacks
1260 {"NORADIUSDMG", MF2_NORADIUSDMG}, // doesn't take splash damage
1261 {"FORCERADIUSDMG", MF2_FORCERADIUSDMG}, // causes splash damage even if target immune
1262 {"HIGHERMPROB", MF2_HIGHERMPROB}, // higher missile attack probability
1263 {"RANGEHALF", MF2_RANGEHALF}, // use half distance for missile attack probability
1264 {"NOTHRESHOLD", MF2_NOTHRESHOLD}, // no targeting threshold
1265 {"LONGMELEE", MF2_LONGMELEE}, // long melee range
1266 {"BOSS", MF2_BOSS}, // full volume see / death sound + splash immunity
1267 {"MAP07BOSS1", MF2_MAP07BOSS1}, // Tag 666 "boss" on doom 2 map 7
1268 {"MAP07BOSS2", MF2_MAP07BOSS2}, // Tag 667 "boss" on doom 2 map 7
1269 {"E1M8BOSS", MF2_E1M8BOSS}, // E1M8 boss
1270 {"E2M8BOSS", MF2_E2M8BOSS}, // E2M8 boss
1271 {"E3M8BOSS", MF2_E3M8BOSS}, // E3M8 boss
1272 {"E4M6BOSS", MF2_E4M6BOSS}, // E4M6 boss
1273 {"E4M8BOSS", MF2_E4M8BOSS}, // E4M8 boss
1274 {"RIP", MF2_RIP}, // projectile rips through targets
1275 {"FULLVOLSOUNDS", MF2_FULLVOLSOUNDS}, // full volume see / death sound
1276 { NULL }
1277 };
1278
1279 static const struct deh_flag_s deh_weaponflags_mbf21[] = {
1280 { "NOTHRUST", WPF_NOTHRUST }, // doesn't thrust Mobj's
1281 { "SILENT", WPF_SILENT }, // weapon is silent
1282 { "NOAUTOFIRE", WPF_NOAUTOFIRE }, // weapon won't autofire in A_WeaponReady
1283 { "FLEEMELEE", WPF_FLEEMELEE }, // monsters consider it a melee weapon
1284 { "AUTOSWITCHFROM", WPF_AUTOSWITCHFROM }, // can be switched away from when ammo is picked up
1285 { "NOAUTOSWITCHTO", WPF_NOAUTOSWITCHTO }, // cannot be switched to when ammo is picked up
1286 { NULL }
1287 };
1288
1289 // STATE - Dehacked block name = "Frame" and "Pointer"
1290 // Usage: Frame nn
1291 // Usage: Pointer nn (Frame nn)
1292 // These are indexed separately, for lookup to the actual
1293 // function pointers. Here we'll take whatever Dehacked gives
1294 // us and go from there. The (Frame nn) after the pointer is the
1295 // real place to put this value. The "Pointer" value is an xref
1296 // that Dehacked uses and is useless to us.
1297 // * states are base zero and have a dummy #0 (TROO)
1298
1299 static const char *deh_state_fields[] = // CPhipps - static const*
1300 {
1301 "Sprite number", // .sprite (spritenum_t) // an enum
1302 "Sprite subnumber", // .frame (long)
1303 "Duration", // .tics (long)
1304 "Next frame", // .nextstate (statenum_t)
1305 // This is set in a separate "Pointer" block from Dehacked
1306 "Codep Frame", // pointer to first use of action (actionf_t)
1307 "Unknown 1", // .misc1 (long)
1308 "Unknown 2", // .misc2 (long)
1309 "Args1", // .args[0] (statearg_t)
1310 "Args2", // .args[1] (statearg_t)
1311 "Args3", // .args[2] (statearg_t)
1312 "Args4", // .args[3] (statearg_t)
1313 "Args5", // .args[4] (statearg_t)
1314 "Args6", // .args[5] (statearg_t)
1315 "Args7", // .args[6] (statearg_t)
1316 "Args8", // .args[7] (statearg_t)
1317 "MBF21 Bits", // .flags
1318 };
1319
1320 static const struct deh_flag_s deh_stateflags_mbf21[] = {
1321 { "SKILL5FAST", STATEF_SKILL5FAST }, // tics halve on nightmare skill
1322 { NULL }
1323 };
1324
1325 // AMMO - Dehacked block name = "Ammo"
1326 // usage = Ammo n (name)
1327 // Ammo information for the few types of ammo
1328
1329 static const char *deh_ammo[] = // CPhipps - static const*
1330 {
1331 "Max ammo", // maxammo[]
1332 "Per ammo" // clipammo[]
1333 };
1334
1335 // WEAPONS - Dehacked block name = "Weapon"
1336 // Usage: Weapon nn (name)
1337 // Basically a list of frames and what kind of ammo (see above)it uses.
1338
1339 static const char *deh_weapon[] = // CPhipps - static const*
1340 {
1341 "Ammo type", // .ammo
1342 "Deselect frame", // .upstate
1343 "Select frame", // .downstate
1344 "Bobbing frame", // .readystate
1345 "Shooting frame", // .atkstate
1346 "Firing frame", // .flashstate
1347 "Ammo per shot", // .ammopershot [XA] new to mbf21
1348 "MBF21 Bits", // .flags
1349 };
1350
1351 // CHEATS - Dehacked block name = "Cheat"
1352 // Usage: Cheat 0
1353 // Always uses a zero in the dehacked file, for consistency. No meaning.
1354 // These are just plain funky terms compared with id's
1355 //
1356 // killough 4/18/98: integrated into main cheat table now (see st_stuff.c)
1357
1358 // MISC - Dehacked block name = "Misc"
1359 // Usage: Misc 0
1360 // Always uses a zero in the dehacked file, for consistency. No meaning.
1361
1362 static const char *deh_misc[] = // CPhipps - static const*
1363 {
1364 "Initial Health", // initial_health
1365 "Initial Bullets", // initial_bullets
1366 "Max Health", // maxhealth
1367 "Max Armor", // max_armor
1368 "Green Armor Class", // green_armor_class
1369 "Blue Armor Class", // blue_armor_class
1370 "Max Soulsphere", // max_soul
1371 "Soulsphere Health", // soul_health
1372 "Megasphere Health", // mega_health
1373 "God Mode Health", // god_health
1374 "IDFA Armor", // idfa_armor
1375 "IDFA Armor Class", // idfa_armor_class
1376 "IDKFA Armor", // idkfa_armor
1377 "IDKFA Armor Class", // idkfa_armor_class
1378 "BFG Cells/Shot", // BFGCELLS
1379 "Monsters Infight" // Unknown--not a specific number it seems, but
1380 // the logic has to be here somewhere or
1381 // it'd happen always
1382 };
1383
1384 // TEXT - Dehacked block name = "Text"
1385 // Usage: Text fromlen tolen
1386 // Dehacked allows a bit of adjustment to the length (why?)
1387
1388 // BEX extension [CODEPTR]
1389 // Usage: Start block, then each line is:
1390 // FRAME nnn = PointerMnemonic
1391
1392 typedef struct {
1393 actionf_t cptr; // actual pointer to the subroutine
1394 const char *lookup; // mnemonic lookup string to be specified in BEX
1395 // CPhipps - const*
1396 short argcount; // [XA] number of mbf21 args this action uses, if any
1397 long default_args[MAXSTATEARGS]; // default values for mbf21 args
1398 short ti_flags; // thing index on these args
1399 } deh_bexptr;
1400
1401 #define TI_MISC1 0x0001
1402 #define TI_MISC2 0x0002
1403 #define TI_ARGSSHIFT 2
1404 #define TI_ARGS1 0x0004
1405 #define TI_ARGS2 0x0008
1406 #define TI_ARGS3 0x0010
1407 #define TI_ARGS4 0x0020
1408 #define TI_ARGS5 0x0040
1409 #define TI_ARGS6 0x0080
1410 #define TI_ARGS7 0x0100
1411 #define TI_ARGS8 0x0200
1412
1413 static const deh_bexptr deh_bexptrs[] = // CPhipps - static const
1414 {
1415 {A_Light0, "A_Light0"},
1416 {A_WeaponReady, "A_WeaponReady"},
1417 {A_Lower, "A_Lower"},
1418 {A_Raise, "A_Raise"},
1419 {A_Punch, "A_Punch"},
1420 {A_ReFire, "A_ReFire"},
1421 {A_FirePistol, "A_FirePistol"},
1422 {A_Light1, "A_Light1"},
1423 {A_FireShotgun, "A_FireShotgun"},
1424 {A_Light2, "A_Light2"},
1425 {A_FireShotgun2, "A_FireShotgun2"},
1426 {A_CheckReload, "A_CheckReload"},
1427 {A_OpenShotgun2, "A_OpenShotgun2"},
1428 {A_LoadShotgun2, "A_LoadShotgun2"},
1429 {A_CloseShotgun2, "A_CloseShotgun2"},
1430 {A_FireCGun, "A_FireCGun"},
1431 {A_GunFlash, "A_GunFlash"},
1432 {A_FireMissile, "A_FireMissile"},
1433 {A_Saw, "A_Saw"},
1434 {A_FirePlasma, "A_FirePlasma"},
1435 {A_BFGsound, "A_BFGsound"},
1436 {A_FireBFG, "A_FireBFG"},
1437 {A_BFGSpray, "A_BFGSpray"},
1438 {A_Explode, "A_Explode"},
1439 {A_Pain, "A_Pain"},
1440 {A_PlayerScream, "A_PlayerScream"},
1441 {A_Fall, "A_Fall"},
1442 {A_XScream, "A_XScream"},
1443 {A_Look, "A_Look"},
1444 {A_Chase, "A_Chase"},
1445 {A_FaceTarget, "A_FaceTarget"},
1446 {A_PosAttack, "A_PosAttack"},
1447 {A_Scream, "A_Scream"},
1448 {A_SPosAttack, "A_SPosAttack"},
1449 {A_VileChase, "A_VileChase"},
1450 {A_VileStart, "A_VileStart"},
1451 {A_VileTarget, "A_VileTarget"},
1452 {A_VileAttack, "A_VileAttack"},
1453 {A_StartFire, "A_StartFire"},
1454 {A_Fire, "A_Fire"},
1455 {A_FireCrackle, "A_FireCrackle"},
1456 {A_Tracer, "A_Tracer"},
1457 {A_SkelWhoosh, "A_SkelWhoosh"},
1458 {A_SkelFist, "A_SkelFist"},
1459 {A_SkelMissile, "A_SkelMissile"},
1460 {A_FatRaise, "A_FatRaise"},
1461 {A_FatAttack1, "A_FatAttack1"},
1462 {A_FatAttack2, "A_FatAttack2"},
1463 {A_FatAttack3, "A_FatAttack3"},
1464 {A_BossDeath, "A_BossDeath"},
1465 {A_CPosAttack, "A_CPosAttack"},
1466 {A_CPosRefire, "A_CPosRefire"},
1467 {A_TroopAttack, "A_TroopAttack"},
1468 {A_SargAttack, "A_SargAttack"},
1469 {A_HeadAttack, "A_HeadAttack"},
1470 {A_BruisAttack, "A_BruisAttack"},
1471 {A_SkullAttack, "A_SkullAttack"},
1472 {A_Metal, "A_Metal"},
1473 {A_SpidRefire, "A_SpidRefire"},
1474 {A_BabyMetal, "A_BabyMetal"},
1475 {A_BspiAttack, "A_BspiAttack"},
1476 {A_Hoof, "A_Hoof"},
1477 {A_CyberAttack, "A_CyberAttack"},
1478 {A_PainAttack, "A_PainAttack"},
1479 {A_PainDie, "A_PainDie"},
1480 {A_KeenDie, "A_KeenDie"},
1481 {A_BrainPain, "A_BrainPain"},
1482 {A_BrainScream, "A_BrainScream"},
1483 {A_BrainDie, "A_BrainDie"},
1484 {A_BrainAwake, "A_BrainAwake"},
1485 {A_BrainSpit, "A_BrainSpit"},
1486 {A_SpawnSound, "A_SpawnSound"},
1487 {A_SpawnFly, "A_SpawnFly"},
1488 {A_BrainExplode, "A_BrainExplode"},
1489 {A_Detonate, "A_Detonate"}, // killough 8/9/98
1490 {A_Mushroom, "A_Mushroom"}, // killough 10/98
1491 {A_Die, "A_Die"}, // killough 11/98
1492 {A_Spawn, "A_Spawn", 0, {0}, TI_MISC1}, // killough 11/98
1493 {A_Turn, "A_Turn"}, // killough 11/98
1494 {A_Face, "A_Face"}, // killough 11/98
1495 {A_Scratch, "A_Scratch"}, // killough 11/98
1496 {A_PlaySound, "A_PlaySound"}, // killough 11/98
1497 {A_RandomJump, "A_RandomJump"}, // killough 11/98
1498 {A_LineEffect, "A_LineEffect"}, // killough 11/98
1499
1500 {A_FireOldBFG, "A_FireOldBFG"}, // killough 7/19/98: classic BFG firing function
1501 {A_BetaSkullAttack, "A_BetaSkullAttack"}, // killough 10/98: beta lost souls attacked different
1502 {A_Stop, "A_Stop"},
1503
1504 // [XA] New mbf21 codepointers
1505 {A_SpawnObject, "A_SpawnObject", 8, {0}, TI_ARGS1},
1506 {A_MonsterProjectile, "A_MonsterProjectile", 5, {0}, TI_ARGS1},
1507 {A_MonsterBulletAttack, "A_MonsterBulletAttack", 5, {0, 0, 1, 3, 5}},
1508 {A_MonsterMeleeAttack, "A_MonsterMeleeAttack", 4, {3, 8, 0, 0}},
1509 {A_RadiusDamage, "A_RadiusDamage", 2},
1510 {A_NoiseAlert, "A_NoiseAlert", 0},
1511 {A_HealChase, "A_HealChase", 2},
1512 {A_SeekTracer, "A_SeekTracer", 2},
1513 {A_FindTracer, "A_FindTracer", 2, {0, 10}},
1514 {A_ClearTracer, "A_ClearTracer", 0},
1515 {A_JumpIfHealthBelow, "A_JumpIfHealthBelow", 2},
1516 {A_JumpIfTargetInSight, "A_JumpIfTargetInSight", 2},
1517 {A_JumpIfTargetCloser, "A_JumpIfTargetCloser", 2},
1518 {A_JumpIfTracerInSight, "A_JumpIfTracerInSight", 2},
1519 {A_JumpIfTracerCloser, "A_JumpIfTracerCloser", 2},
1520 {A_JumpIfFlagsSet, "A_JumpIfFlagsSet", 3},
1521 {A_AddFlags, "A_AddFlags", 2},
1522 {A_RemoveFlags, "A_RemoveFlags", 2},
1523 {A_WeaponProjectile, "A_WeaponProjectile", 5, {0}, TI_ARGS1},
1524 {A_WeaponBulletAttack, "A_WeaponBulletAttack", 5, {0, 0, 1, 5, 3}},
1525 {A_WeaponMeleeAttack, "A_WeaponMeleeAttack", 5, {2, 10, 1 * FRACUNIT, 0, 0}},
1526 {A_WeaponSound, "A_WeaponSound", 2},
1527 {A_WeaponAlert, "A_WeaponAlert", 0},
1528 {A_WeaponJump, "A_WeaponJump", 2},
1529 {A_ConsumeAmmo, "A_ConsumeAmmo", 1},
1530 {A_CheckAmmo, "A_CheckAmmo", 2},
1531 {A_RefireTo, "A_RefireTo", 2},
1532 {A_GunFlashTo, "A_GunFlashTo", 2},
1533
1534 // This NULL entry must be the last in the list
1535 {NULL, "A_NULL"}, // Ty 05/16/98
1536 };
1537
1538 int deh_maxhealth;
1539 int deh_max_soul;
1540 int deh_mega_health;
1541
1542 dboolean IsDehMaxHealth = false;
1543 dboolean IsDehMaxSoul = false;
1544 dboolean IsDehMegaHealth = false;
1545
1546 static uint64_t deh_stringToFlags(char *strval, const struct deh_flag_s *flags)
1547 {
1548 uint64_t value;
1549
1550 for (value = 0; (strval = strtok(strval, deh_getBitsDelims())); strval = NULL) {
1551 const struct deh_flag_s *flag;
1552
1553 for (flag = flags; flag->name; flag++) {
1554 if (deh_strcasecmp(strval, flag->name)) continue;
1555
1556 value |= flag->value;
1557 break;
1558 }
1559
1560 if (!flag->name)
1561 deh_log("Could not find MBF21 bit mnemonic %s\n", strval);
1562 }
1563
1564 return value;
1565 }
1566
1567 uint64_t deh_stringToMBF21MobjFlags(char *strval)
1568 {
1569 return deh_stringToFlags(strval, deh_mobjflags_mbf21);
1570 }
1571
1572 uint64_t deh_stringToMobjFlags(char *strval)
1573 {
1574 return deh_stringToFlags(strval, deh_mobjflags);
1575 }
1576
1577 void deh_changeCompTranslucency(void)
1578 {
1579 extern byte* edited_mobjinfo_bits;
1580 int i;
1581 int boom_translucent_sprites, vanilla_translucent_sprites, translucency_active;
1582 int predefined_translucency[] = {
1583 MT_FIRE, MT_SMOKE, MT_FATSHOT, MT_BRUISERSHOT, MT_SPAWNFIRE,
1584 MT_TROOPSHOT, MT_HEADSHOT, MT_PLASMA, MT_BFG, MT_ARACHPLAZ, MT_PUFF,
1585 MT_TFOG, MT_IFOG, MT_MISC12, MT_INV, MT_INS, MT_MEGA
1586 };
1587
1588 if (raven) return;
1589
1590 boom_translucent_sprites = dsda_IntConfig(dsda_config_translucent_sprites);
1591 vanilla_translucent_sprites = boom_translucent_sprites > 1;
1592 translucency_active = (compatibility_level >= boom_compatibility_compatibility) ? !comp[comp_translucency] : vanilla_translucent_sprites;
1593
1594 // Reset translucency
1595 for (i = 0; (size_t)i < sizeof(predefined_translucency) / sizeof(predefined_translucency[0]); i++)
1596 if (!edited_mobjinfo_bits[predefined_translucency[i]])
1597 mobjinfo[predefined_translucency[i]].flags &= ~MF_TRANSLUCENT;
1598
1599 // Set translucency
1600 if (translucency_active)
1601 for (i = 0; (size_t)i < sizeof(predefined_translucency) / sizeof(predefined_translucency[0]); i++)
1602 if (!edited_mobjinfo_bits[predefined_translucency[i]])
1603 if (boom_translucent_sprites)
1604 mobjinfo[predefined_translucency[i]].flags |= MF_TRANSLUCENT;
1605
1606 // This updates the existing things in the map.
1607 if (in_game)
1608 {
1609 thinker_t *th, *start_th;
1610 int i;
1611 th = &thinkercap;
1612 start_th = th;
1613
1614 do
1615 {
1616 th = th->next;
1617 if (th->function == P_MobjThinker)
1618 {
1619 mobj_t *mobj;
1620 mobj = (mobj_t *) th;
1621
1622 for (i = 0; (size_t)i < sizeof(predefined_translucency) / sizeof(predefined_translucency[0]); i++)
1623 if (mobj->type == predefined_translucency[i])
1624 mobj->flags = mobjinfo[predefined_translucency[i]].flags;
1625 }
1626 } while (th != start_th);
1627 }
1628 }
1629
1630 void deh_applyCompatibility(void)
1631 {
1632 extern byte* edited_mobjinfo_bits;
1633 int comp_max = (compatibility_level == doom_12_compatibility ? 199 : 200);
1634
1635 max_soul = (IsDehMaxSoul ? deh_max_soul : comp_max);
1636 mega_health = (IsDehMegaHealth ? deh_mega_health : comp_max);
1637
1638 if (comp[comp_maxhealth])
1639 {
1640 maxhealth = 100;
1641 maxhealthbonus = (IsDehMaxHealth ? deh_maxhealth : comp_max);
1642 }
1643 else
1644 {
1645 maxhealth = (IsDehMaxHealth ? deh_maxhealth : 100);
1646 maxhealthbonus = maxhealth * 2;
1647 }
1648
1649 if (raven) return;
1650
1651 if (!edited_mobjinfo_bits[MT_SKULL])
1652 {
1653 if (compatibility_level == doom_12_compatibility)
1654 mobjinfo[MT_SKULL].flags |= (MF_COUNTKILL);
1655 else
1656 mobjinfo[MT_SKULL].flags &= ~(MF_COUNTKILL);
1657 }
1658
1659 deh_changeCompTranslucency();
1660 }
1661
1662 // ====================================================================
1663 // ProcessDehFile
1664 // Purpose: Read and process a DEH or BEX file
1665 // Args: filename -- name of the DEH/BEX file
1666 // outfilename -- output file (DEHOUT.TXT), appended to here
1667 // Returns: void
1668 //
1669 // killough 10/98:
1670 // substantially modified to allow input from wad lumps instead of .deh files.
1671
1672 static int processed_dehacked;
1673
1674 void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum)
1675 {
1676 DEHFILE infile, *filein = &infile; // killough 10/98
1677 char inbuffer[DEH_BUFFERMAX]; // Place to put the primary infostring
1678 const char *file_or_lump;
1679 static unsigned last_block;
1680 static long filepos;
1681
1682 processed_dehacked = true;
1683
1684 // Open output file if we're writing output
1685 if (outfilename && *outfilename && !deh_log_file)
1686 {
1687 static dboolean firstfile = true; // to allow append to output log
1688 if (!strcmp(outfilename, "-"))
1689 deh_log_file = stdout;
1690 else if (!(deh_log_file = M_OpenFile(outfilename, firstfile ? "wt" : "at")))
1691 {
1692 lprintf(LO_WARN, "Could not open -dehout file %s\n... using stdout.\n", outfilename);
1693 deh_log_file = stdout;
1694 }
1695 firstfile = false;
1696 }
1697
1698 // killough 10/98: allow DEH files to come from wad lumps
1699
1700 if (filename)
1701 {
1702 if (!(infile.f = M_OpenFile(filename, "rt")))
1703 {
1704 lprintf(LO_WARN, "-deh file %s not found\n", filename);
1705 return; // should be checked up front anyway
1706 }
1707 infile.lump = NULL;
1708 file_or_lump = "file";
1709 }
1710 else // DEH file comes from lump indicated by third argument
1711 {
1712 infile.size = W_LumpLength(lumpnum);
1713 infile.inp = infile.lump = W_LumpByNum(lumpnum);
1714 // [FG] skip empty DEHACKED lumps
1715 if (!infile.inp)
1716 {
1717 lprintf(LO_WARN, "skipping empty DEHACKED (%d) lump\n", lumpnum);
1718 return;
1719 }
1720 filename = lumpinfo[lumpnum].wadfile->name;
1721 file_or_lump = "lump from";
1722 }
1723
1724 lprintf(LO_INFO, "Loading DEH %s %s\n", file_or_lump, filename);
1725 deh_log("\nLoading DEH %s %s\n\n", file_or_lump, filename);
1726
1727 // loop until end of file
1728
1729 last_block = DEH_BLOCKMAX - 1;
1730 filepos = 0;
1731 while (dehfgets(inbuffer,sizeof(inbuffer),filein))
1732 {
1733 dboolean match;
1734 unsigned i;
1735
1736 lfstrip(inbuffer);
1737 deh_log("Line='%s'\n", inbuffer);
1738 if (!*inbuffer || *inbuffer == '#' || *inbuffer == ' ')
1739 continue; /* Blank line or comment line */
1740
1741 // -- If DEH_BLOCKMAX is set right, the processing is independently
1742 // -- handled based on data in the deh_blocks[] structure array
1743
1744 // killough 10/98: INCLUDE code rewritten to allow arbitrary nesting,
1745 // and to greatly simplify code, fix memory leaks, other bugs
1746
1747 if (!strnicmp(inbuffer, "INCLUDE", 7)) // include a file
1748 {
1749 // preserve state while including a file
1750 // killough 10/98: moved to here
1751
1752 char *nextfile;
1753 dboolean oldnotext = includenotext; // killough 10/98
1754
1755 // killough 10/98: exclude if inside wads (only to discourage
1756 // the practice, since the code could otherwise handle it)
1757
1758 if (infile.lump)
1759 {
1760 deh_log("No files may be included from wads: %s\n", inbuffer);
1761 continue;
1762 }
1763
1764 // check for no-text directive, used when including a DEH
1765 // file but using the BEX format to handle strings
1766
1767 if (!strnicmp(nextfile = ptr_lstrip(inbuffer + 7), "NOTEXT", 6))
1768 includenotext = true, nextfile = ptr_lstrip(nextfile + 6);
1769
1770 deh_log("Branching to include file %s...\n", nextfile);
1771
1772 // killough 10/98:
1773 // Second argument must be NULL to prevent closing deh_log_file too soon
1774
1775 ProcessDehFile(nextfile, NULL, 0); // do the included file
1776
1777 includenotext = oldnotext;
1778 deh_log("...continuing with %s\n", filename);
1779 continue;
1780 }
1781
1782 for (match = 0, i = 0; i < DEH_BLOCKMAX - 1; i++)
1783 if (!strncasecmp(inbuffer, deh_blocks[i].key, strlen(deh_blocks[i].key)))
1784 { // matches one
1785 match = 1;
1786 break; // we got one, that's enough for this block
1787 }
1788
1789 if (match) // inbuffer matches a valid block code name
1790 last_block = i;
1791 else if (last_block >= 10 && last_block < DEH_BLOCKMAX - 1) // restrict to BEX style lumps
1792 { // process that same line again with the last valid block code handler
1793 i = last_block;
1794 dehfseek(filein, filepos);
1795 }
1796
1797 deh_log("Processing function [%d] for %s\n", i, deh_blocks[i].key);
1798 deh_blocks[i].fptr(filein, inbuffer); // call function
1799
1800 filepos = dehftell(filein);
1801 }
1802
1803 if (!infile.lump)
1804 fclose(infile.f); // Close real file
1805
1806 if (outfilename) // killough 10/98: only at top recursion level
1807 {
1808 if (deh_log_file != stdout)
1809 fclose(deh_log_file);
1810 deh_log_file = NULL;
1811 }
1812
1813 deh_applyCompatibility();
1814 }
1815
1816 // ====================================================================
1817 // deh_procBexCodePointers
1818 // Purpose: Handle [CODEPTR] block, BOOM Extension
1819 // Args: fpin -- input file stream
1820 // line -- current line in file to process
1821 // Returns: void
1822 //
1823 static void deh_procBexCodePointers(DEHFILE *fpin, char *line)
1824 {
1825 char key[DEH_MAXKEYLEN];
1826 char inbuffer[DEH_BUFFERMAX];
1827 int indexnum;
1828 char mnemonic[DEH_MAXKEYLEN]; // to hold the codepointer mnemonic
1829 int i; // looper
1830 dboolean found; // know if we found this one during lookup or not
1831 dsda_deh_state_t deh_state;
1832
1833 // Ty 05/16/98 - initialize it to something, dummy!
1834 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
1835
1836 // for this one, we just read 'em until we hit a blank line
1837 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
1838 {
1839 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
1840 lfstrip(inbuffer);
1841 if (!*inbuffer) break; // killough 11/98: really exit on blank line
1842
1843 // killough 8/98: allow hex numbers in input:
1844 if ((3 != sscanf(inbuffer, "%s %i = %s", key, &indexnum, mnemonic)) || (stricmp(key, "FRAME")))
1845 { // NOTE: different format from normal
1846 deh_log("Invalid BEX codepointer line - must start with 'FRAME': '%s'\n", inbuffer);
1847 return; // early return
1848 }
1849
1850 deh_log("Processing pointer at index %d: %s\n", indexnum, mnemonic);
1851 if (indexnum < 0)
1852 {
1853 deh_log("Pointer number must be positive (%d)\n", indexnum);
1854 return; // killough 10/98: fix SegViol
1855 }
1856 strcpy(key, "A_"); // reusing the key area to prefix the mnemonic
1857 strcat(key, ptr_lstrip(mnemonic));
1858
1859 deh_state = dsda_GetDehState(indexnum);
1860
1861 found = FALSE;
1862 i= -1; // incremented to start at zero at the top of the loop
1863 do // Ty 05/16/98 - fix loop logic to look for null ending entry
1864 {
1865 ++i;
1866 if (!stricmp(key, deh_bexptrs[i].lookup))
1867 { // Ty 06/01/98 - add to states[].action for new djgcc version
1868 deh_state.state->action = deh_bexptrs[i].cptr; // assign
1869 deh_log(" - applied %s from codeptr[%d] to states[%d]\n",
1870 deh_bexptrs[i].lookup, i, indexnum);
1871 found = TRUE;
1872 }
1873 } while (!found && (deh_bexptrs[i].cptr != NULL));
1874
1875 if (!found)
1876 deh_log("Invalid frame pointer mnemonic '%s' at %d\n", mnemonic, indexnum);
1877 }
1878 }
1879
1880 //---------------------------------------------------------------------------
1881 // To be on the safe, compatible side, we manually convert DEH bitflags
1882 // to prboom types - POPE
1883 //---------------------------------------------------------------------------
1884 static uint64_t getConvertedDEHBits(uint64_t bits) {
1885 static const uint64_t bitMap[32] = {
1886 /* cf linuxdoom-1.10 p_mobj.h */
1887 MF_SPECIAL, // 0 Can be picked up - When touched the thing can be picked up.
1888 MF_SOLID, // 1 Obstacle - The thing is solid and will not let you (or others) pass through it
1889 MF_SHOOTABLE, // 2 Shootable - Can be shot.
1890 MF_NOSECTOR, // 3 Total Invisibility - Invisible, but can be touched
1891 MF_NOBLOCKMAP, // 4 Don't use the blocklinks (inert but displayable)
1892 MF_AMBUSH, // 5 Semi deaf - The thing is a deaf monster
1893 MF_JUSTHIT, // 6 In pain - Will try to attack right back after being hit
1894 MF_JUSTATTACKED, // 7 Steps before attack - Will take at least one step before attacking
1895 MF_SPAWNCEILING, // 8 Hangs from ceiling - When the level starts, this thing will be at ceiling height.
1896 MF_NOGRAVITY, // 9 No gravity - Gravity does not affect this thing
1897 MF_DROPOFF, // 10 Travels over cliffs - Monsters normally do not walk off ledges/steps they could not walk up. With this set they can walk off any height of cliff. Usually only used for flying monsters.
1898 MF_PICKUP, // 11 Pick up items - The thing can pick up gettable items.
1899 MF_NOCLIP, // 12 No clipping - Thing can walk through walls.
1900 MF_SLIDE, // 13 Slides along walls - Keep info about sliding along walls (don't really know much about this one).
1901 MF_FLOAT, // 14 Floating - Thing can move to any height
1902 MF_TELEPORT, // 15 Semi no clipping - Don't cross lines or look at teleport heights. (don't really know much about this one either).
1903 MF_MISSILE, // 16 Projectiles - Behaves like a projectile, explodes when hitting something that blocks movement
1904 MF_DROPPED, // 17 Disappearing weapon - Dropped, not spawned (like an ammo clip) I have not had much success in using this one.
1905 MF_SHADOW, // 18 Partial invisibility - Drawn like a spectre.
1906 MF_NOBLOOD, // 19 Puffs (vs. bleeds) - If hit will spawn bullet puffs instead of blood splats.
1907 MF_CORPSE, // 20 Sliding helpless - Will slide down steps when dead.
1908 MF_INFLOAT, // 21 No auto levelling - float but not to target height (?)
1909 MF_COUNTKILL, // 22 Affects kill % - counted as a killable enemy and affects percentage kills on level summary.
1910 MF_COUNTITEM, // 23 Affects item % - affects percentage items gathered on level summary.
1911 MF_SKULLFLY, // 24 Running - special handling for flying skulls.
1912 MF_NOTDMATCH, // 25 Not in deathmatch - do not spawn in deathmatch (like keys)
1913 MF_TRANSLATION1, // 26 Color 1 (grey / red)
1914 MF_TRANSLATION2, // 27 Color 2 (brown / red)
1915 // Convert bit 28 to MF_TOUCHY, not (MF_TRANSLATION1|MF_TRANSLATION2)
1916 // fixes bug #1576151 (part 1)
1917 MF_TOUCHY, // 28 - explodes on contact (MBF)
1918 MF_BOUNCES, // 29 - bounces off walls and floors (MBF)
1919 MF_FRIEND, // 30 - friendly monster helps players (MBF)
1920 MF_TRANSLUCENT // e6y: Translucency via dehacked/bex doesn't work without it
1921 };
1922 int i;
1923 uint64_t shiftBits = bits;
1924 uint64_t convertedBits = 0;
1925 for (i=0; i<32; i++) {
1926 if (shiftBits & 0x1) convertedBits |= bitMap[i];
1927 shiftBits >>= 1;
1928 }
1929 return convertedBits;
1930 }
1931
1932 //---------------------------------------------------------------------------
1933 // See usage below for an explanation of this function's existence - POPE
1934 //---------------------------------------------------------------------------
1935 static void setMobjInfoValue(int mobjInfoIndex, int keyIndex, uint64_t value) {
1936 mobjinfo_t *mi;
1937 if (mobjInfoIndex >= num_mobj_types || mobjInfoIndex < 0) return;
1938 mi = &mobjinfo[mobjInfoIndex];
1939 switch (keyIndex) {
1940 case 0: mi->doomednum = (int)value; return;
1941 case 1: mi->spawnstate = (int)value; return;
1942 case 2: mi->spawnhealth = (int)value; return;
1943 case 3: mi->seestate = (int)value; return;
1944 case 4: mi->seesound = (int)value; return;
1945 case 5: mi->reactiontime = (int)value; return;
1946 case 6: mi->attacksound = (int)value; return;
1947 case 7: mi->painstate = (int)value; return;
1948 case 8: mi->painchance = (int)value; return;
1949 case 9: mi->painsound = (int)value; return;
1950 case 10: mi->meleestate = (int)value; return;
1951 case 11: mi->missilestate = (int)value; return;
1952 case 12: mi->deathstate = (int)value; return;
1953 case 13: mi->xdeathstate = (int)value; return;
1954 case 14: mi->deathsound = (int)value; return;
1955 case 15: mi->speed = (int)value; return;
1956 case 16: mi->radius = (int)value; return;
1957 case 17: mi->height = (int)value; return;
1958 case 18: mi->mass = (int)value; return;
1959 case 19: mi->damage = (int)value; return;
1960 case 20: mi->activesound = (int)value; return;
1961 case 21: mi->flags = value; return;
1962 // e6y
1963 // Correction of wrong processing of "Respawn frame" entry.
1964 // There is no more synch on http://www.doomworld.com/sda/dwdemo/w303-115.zip
1965 // (with correction in PIT_CheckThing)
1966 case 22:
1967 if (prboom_comp[PC_FORCE_INCORRECT_PROCESSING_OF_RESPAWN_FRAME_ENTRY].state)
1968 {
1969 mi->raisestate = (int)value;
1970 return;
1971 }
1972 break;
1973 case 23:
1974 if (!prboom_comp[PC_FORCE_INCORRECT_PROCESSING_OF_RESPAWN_FRAME_ENTRY].state)
1975 {
1976 mi->raisestate = (int)value;
1977 return;
1978 }
1979 break;
1980 case 24: // make it base zero (deh is 1-based)
1981 mi->droppeditem = dsda_TranslateDehMobjIndex((int)value) - 1;
1982 return;
1983
1984 // mbf21
1985 // custom groups count from the end of the vanilla list
1986 // -> no concern for clashes
1987 case 25:
1988 mi->infighting_group = (int)(value);
1989 if (mi->infighting_group < 0)
1990 {
1991 I_Error("Infighting groups must be >= 0 (check your dehacked)");
1992 return;
1993 }
1994 mi->infighting_group = mi->infighting_group + IG_END;
1995 return;
1996 case 26:
1997 mi->projectile_group = (int)(value);
1998 if (mi->projectile_group < 0)
1999 mi->projectile_group = PG_GROUPLESS;
2000 else
2001 mi->projectile_group = mi->projectile_group + PG_END;
2002 return;
2003 case 27:
2004 mi->splash_group = (int)(value);
2005 if (mi->splash_group < 0)
2006 {
2007 I_Error("Splash groups must be >= 0 (check your dehacked)");
2008 return;
2009 }
2010 mi->splash_group = mi->splash_group + SG_END;
2011 return;
2012 case 29: mi->ripsound = (int)value; return;
2013 case 30: mi->altspeed = (int)value; return;
2014 case 31: mi->meleerange = (int)value; return;
2015
2016 // misc
2017 case 32: mi->bloodcolor = V_BloodColor((int)value); return;
2018
2019 default: return;
2020 }
2021 }
2022
2023 // ====================================================================
2024 // deh_procThing
2025 // Purpose: Handle DEH Thing block
2026 // Args: fpin -- input file stream
2027 // line -- current line in file to process
2028 // Returns: void
2029 //
2030 // Ty 8/27/98 - revised to also allow mnemonics for
2031 // bit masks for monster attributes
2032 //
2033
2034 static void deh_procThing(DEHFILE *fpin, char *line)
2035 {
2036 char key[DEH_MAXKEYLEN];
2037 char inbuffer[DEH_BUFFERMAX];
2038 uint64_t value; // All deh values are ints or longs
2039 int indexnum;
2040 int internal_index;
2041 int ix;
2042 char *strval;
2043 dsda_deh_mobjinfo_t deh_mobjinfo;
2044
2045 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2046 deh_log("Thing line: '%s'\n", inbuffer);
2047
2048 // killough 8/98: allow hex numbers in input:
2049 ix = sscanf(inbuffer, "%s %i", key, &indexnum);
2050 deh_log("count=%d, Thing %d\n", ix, indexnum);
2051
2052 // Note that the mobjinfo[] array is base zero, but object numbers
2053 // in the dehacked file start with one. Grumble.
2054 internal_index = dsda_TranslateDehMobjIndex(indexnum) - 1;
2055
2056 deh_mobjinfo = dsda_GetDehMobjInfo(internal_index);
2057
2058 // now process the stuff
2059 // Note that for Things we can look up the key and use its offset
2060 // in the array of key strings as an int offset in the structure
2061
2062 // get a line until a blank or end of file--it's not
2063 // blank now because it has our incoming key in it
2064 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2065 {
2066 // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
2067 // No more desync on HACX demos.
2068 int bGetData;
2069
2070 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2071 lfstrip(inbuffer); // toss the end of line
2072
2073 // killough 11/98: really bail out on blank lines (break != continue)
2074 if (!*inbuffer) break; // bail out with blank line between sections
2075
2076 // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
2077 // No more desync on HACX demos.
2078 bGetData = deh_GetData(inbuffer, key, &value, &strval);
2079 if (!bGetData)
2080 {
2081 deh_log("Bad data pair in '%s'\n", inbuffer);
2082 continue;
2083 }
2084
2085 for (ix = 0; deh_mobjinfo_fields[ix]; ix++) {
2086 if (deh_strcasecmp(key, deh_mobjinfo_fields[ix])) continue;
2087
2088 if (!deh_strcasecmp(key, "MBF21 Bits")) {
2089 if (bGetData == 1)
2090 {
2091 value = deh_translate_bits(value, deh_mobjflags_mbf21);
2092 }
2093 else
2094 {
2095 value = deh_stringToMBF21MobjFlags(strval);
2096 }
2097
2098 deh_mobjinfo.info->flags2 = value;
2099 }
2100 else if (deh_strcasecmp(key, "Bits")) {
2101 // standard value set
2102
2103 // The old code here was the cause of a DEH-related bug in prboom.
2104 // When the mobjinfo_t.flags member was graduated to an int64, this
2105 // code was caught unawares and was indexing each property of the
2106 // mobjinfo as if it were still an int32. This caused sets of the
2107 // "raisestate" member to partially overwrite the "flags" member,
2108 // thus screwing everything up and making most DEH patches result in
2109 // unshootable enemy types. Moved to a separate function above
2110 // and stripped of all hairy struct address indexing. - POPE
2111 setMobjInfoValue(internal_index, ix, value);
2112 }
2113 else if (bGetData == 1)
2114 { // proff
2115 // bit set
2116 // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
2117 // No more desync on HACX demos.
2118
2119 value = getConvertedDEHBits(value);
2120 deh_mobjinfo.info->flags = value;
2121 *deh_mobjinfo.edited_bits = true; //e6y: changed by DEH
2122 }
2123 else
2124 {
2125 value = deh_stringToMobjFlags(strval);
2126
2127 // Don't worry about conversion -- simply print values
2128 deh_log("Bits = 0x%08lX%08lX\n",
2129 (unsigned long)(value>>32) & 0xffffffff,
2130 (unsigned long)value & 0xffffffff);
2131 deh_mobjinfo.info->flags = value; // e6y
2132 *deh_mobjinfo.edited_bits = true; //e6y: changed by DEH
2133 }
2134
2135 deh_log("Assigned 0x%08lx%08lx to %s(%d) at index %d\n",
2136 (unsigned long)(value>>32) & 0xffffffff,
2137 (unsigned long)value & 0xffffffff, key, indexnum, ix);
2138 }
2139 }
2140 }
2141
2142 // ====================================================================
2143 // deh_procFrame
2144 // Purpose: Handle DEH Frame block
2145 // Args: fpin -- input file stream
2146 // line -- current line in file to process
2147 // Returns: void
2148 //
2149 static void deh_procFrame(DEHFILE *fpin, char *line)
2150 {
2151 char key[DEH_MAXKEYLEN];
2152 char inbuffer[DEH_BUFFERMAX];
2153 uint64_t value; // All deh values are ints or longs
2154 int indexnum;
2155 char *strval;
2156 int bGetData;
2157 dsda_deh_state_t deh_state;
2158
2159 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2160
2161 // killough 8/98: allow hex numbers in input:
2162 sscanf(inbuffer, "%s %i", key, &indexnum);
2163 deh_log("Processing Frame at index %d: %s\n", indexnum, key);
2164 if (indexnum < 0)
2165 {
2166 deh_log("Frame number must be positive (%d)\n", indexnum);
2167 return;
2168 }
2169
2170 deh_state = dsda_GetDehState(indexnum);
2171
2172 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2173 {
2174 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2175 lfstrip(inbuffer);
2176 if (!*inbuffer) break; // killough 11/98
2177 bGetData = deh_GetData(inbuffer, key, &value, &strval);
2178 if (!bGetData) // returns TRUE if ok
2179 {
2180 deh_log("Bad data pair in '%s'\n", inbuffer);
2181 continue;
2182 }
2183
2184 if (!deh_strcasecmp(key, deh_state_fields[0])) // Sprite number
2185 {
2186 deh_log(" - sprite = %ld\n", (long)value);
2187 deh_state.state->sprite = (spritenum_t)value;
2188 }
2189 else if (!deh_strcasecmp(key, deh_state_fields[1])) // Sprite subnumber
2190 {
2191 deh_log(" - frame = %ld\n", (long)value);
2192 deh_state.state->frame = (long)value; // long
2193 }
2194 else if (!deh_strcasecmp(key, deh_state_fields[2])) // Duration
2195 {
2196 deh_log(" - tics = %ld\n", (long)value);
2197 deh_state.state->tics = (long)value; // long
2198 }
2199 else if (!deh_strcasecmp(key, deh_state_fields[3])) // Next frame
2200 {
2201 deh_log(" - nextstate = %ld\n", (long)value);
2202 deh_state.state->nextstate = (statenum_t)value;
2203 }
2204 else if (!deh_strcasecmp(key, deh_state_fields[4])) // Codep frame (not set in Frame deh block)
2205 {
2206 deh_log(" - codep, should not be set in Frame section!\n");
2207 /* nop */ ;
2208 }
2209 else if (!deh_strcasecmp(key, deh_state_fields[5])) // Unknown 1
2210 {
2211 deh_log(" - misc1 = %ld\n", (long)value);
2212 deh_state.state->misc1 = (long)value; // long
2213 }
2214 else if (!deh_strcasecmp(key, deh_state_fields[6])) // Unknown 2
2215 {
2216 deh_log(" - misc2 = %ld\n", (long)value);
2217 deh_state.state->misc2 = (long)value; // long
2218 }
2219 else if (!deh_strcasecmp(key, deh_state_fields[7])) // Args1
2220 {
2221 deh_log(" - args[0] = %lld\n", (statearg_t)value);
2222 deh_state.state->args[0] = (statearg_t)value;
2223 *deh_state.defined_codeptr_args |= (1 << 0);
2224 }
2225 else if (!deh_strcasecmp(key, deh_state_fields[8])) // Args2
2226 {
2227 deh_log(" - args[1] = %lld\n", (statearg_t)value);
2228 deh_state.state->args[1] = (statearg_t)value;
2229 *deh_state.defined_codeptr_args |= (1 << 1);
2230 }
2231 else if (!deh_strcasecmp(key, deh_state_fields[9])) // Args3
2232 {
2233 deh_log(" - args[2] = %lld\n", (statearg_t)value);
2234 deh_state.state->args[2] = (statearg_t)value;
2235 *deh_state.defined_codeptr_args |= (1 << 2);
2236 }
2237 else if (!deh_strcasecmp(key, deh_state_fields[10])) // Args4
2238 {
2239 deh_log(" - args[3] = %lld\n", (statearg_t)value);
2240 deh_state.state->args[3] = (statearg_t)value;
2241 *deh_state.defined_codeptr_args |= (1 << 3);
2242 }
2243 else if (!deh_strcasecmp(key, deh_state_fields[11])) // Args5
2244 {
2245 deh_log(" - args[4] = %lld\n", (statearg_t)value);
2246 deh_state.state->args[4] = (statearg_t)value;
2247 *deh_state.defined_codeptr_args |= (1 << 4);
2248 }
2249 else if (!deh_strcasecmp(key, deh_state_fields[12])) // Args6
2250 {
2251 deh_log(" - args[5] = %lld\n", (statearg_t)value);
2252 deh_state.state->args[5] = (statearg_t)value;
2253 *deh_state.defined_codeptr_args |= (1 << 5);
2254 }
2255 else if (!deh_strcasecmp(key, deh_state_fields[13])) // Args7
2256 {
2257 deh_log(" - args[6] = %lld\n", (statearg_t)value);
2258 deh_state.state->args[6] = (statearg_t)value;
2259 *deh_state.defined_codeptr_args |= (1 << 6);
2260 }
2261 else if (!deh_strcasecmp(key, deh_state_fields[14])) // Args8
2262 {
2263 deh_log(" - args[7] = %lld\n", (statearg_t)value);
2264 deh_state.state->args[7] = (statearg_t)value;
2265 *deh_state.defined_codeptr_args |= (1 << 7);
2266 }
2267 else if (!deh_strcasecmp(key, deh_state_fields[15])) // MBF21 Bits
2268 {
2269 if (bGetData == 1)
2270 {
2271 value = deh_translate_bits(value, deh_stateflags_mbf21);
2272 }
2273 else
2274 {
2275 for (value = 0; (strval = strtok(strval, deh_getBitsDelims())); strval = NULL) {
2276 const struct deh_flag_s *flag;
2277
2278 for (flag = deh_stateflags_mbf21; flag->name; flag++) {
2279 if (deh_strcasecmp(strval, flag->name)) continue;
2280
2281 value |= flag->value;
2282 break;
2283 }
2284
2285 if (!flag->name) {
2286 deh_log("Could not find MBF21 frame bit mnemonic %s\n", strval);
2287 }
2288 }
2289 }
2290
2291 deh_state.state->flags = value;
2292 }
2293 else
2294 deh_log("Invalid frame string index for '%s'\n", key);
2295 }
2296 }
2297
2298 // ====================================================================
2299 // deh_procPointer
2300 // Purpose: Handle DEH Code pointer block, can use BEX [CODEPTR] instead
2301 // Args: fpin -- input file stream
2302 // line -- current line in file to process
2303 // Returns: void
2304 //
2305 static void deh_procPointer(DEHFILE *fpin, char *line) // done
2306 {
2307 char key[DEH_MAXKEYLEN];
2308 char inbuffer[DEH_BUFFERMAX];
2309 uint64_t value; // All deh values are ints or longs
2310 int indexnum;
2311 size_t i; // looper
2312 dsda_deh_state_t deh_state, ptr_state;
2313
2314 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2315 // NOTE: different format from normal
2316
2317 // killough 8/98: allow hex numbers in input, fix error case:
2318 if (sscanf(inbuffer, "%*s %*i (%s %i)", key, &indexnum) != 2)
2319 {
2320 deh_log("Bad data pair in '%s'\n", inbuffer);
2321 return;
2322 }
2323
2324 deh_log("Processing Pointer at index %d: %s\n", indexnum, key);
2325 if (indexnum < 0)
2326 {
2327 deh_log("Pointer number must be positive (%d)\n", indexnum);
2328 return;
2329 }
2330
2331 deh_state = dsda_GetDehState(indexnum);
2332
2333 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2334 {
2335 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2336 lfstrip(inbuffer);
2337 if (!*inbuffer) break; // killough 11/98
2338 if (!deh_GetData(inbuffer, key, &value, NULL)) // returns TRUE if ok
2339 {
2340 deh_log("Bad data pair in '%s'\n", inbuffer);
2341 continue;
2342 }
2343
2344 ptr_state = dsda_GetDehState(value);
2345
2346 if (!deh_strcasecmp(key, deh_state_fields[4])) // Codep frame (not set in Frame deh block)
2347 {
2348 deh_state.state->action = *ptr_state.codeptr;
2349 deh_log(" - applied from codeptr[%ld] to states[%d]\n", (long)value, indexnum);
2350 // Write BEX-oriented line to match:
2351 for (i = 0; i < sizeof(deh_bexptrs) / sizeof(*deh_bexptrs); i++)
2352 {
2353 if (!memcmp(&deh_bexptrs[i].cptr, ptr_state.codeptr, sizeof(actionf_t)))
2354 {
2355 deh_log("BEX [CODEPTR] -> FRAME %d = %s\n", indexnum, &deh_bexptrs[i].lookup[2]);
2356 break;
2357 }
2358 if (deh_bexptrs[i].cptr == NULL) // stop at null entry
2359 break;
2360 }
2361 }
2362 else
2363 deh_log("Invalid frame pointer index for '%s' at %ld\n", key, (long)value);
2364 }
2365 }
2366
2367 // ====================================================================
2368 // deh_procSounds
2369 // Purpose: Handle DEH Sounds block
2370 // Args: fpin -- input file stream
2371 // line -- current line in file to process
2372 // Returns: void
2373 //
2374 static void deh_procSounds(DEHFILE *fpin, char *line)
2375 {
2376 char key[DEH_MAXKEYLEN];
2377 char inbuffer[DEH_BUFFERMAX];
2378 uint64_t value; // All deh values are ints or longs
2379 int indexnum;
2380 sfxinfo_t *deh_sfx;
2381
2382 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2383
2384 // killough 8/98: allow hex numbers in input:
2385 sscanf(inbuffer, "%s %i", key, &indexnum);
2386 deh_log("Processing Sounds at index %d: %s\n", indexnum, key);
2387 if (indexnum < 0)
2388 deh_log("Sound number must be positive (%d)\n", indexnum);
2389
2390 deh_sfx = dsda_GetDehSFX(indexnum);
2391
2392 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2393 {
2394 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2395 lfstrip(inbuffer);
2396 if (!*inbuffer) break; // killough 11/98
2397 if (!deh_GetData(inbuffer, key, &value, NULL)) // returns TRUE if ok
2398 {
2399 deh_log("Bad data pair in '%s'\n", inbuffer);
2400 continue;
2401 }
2402
2403 if (!deh_strcasecmp(key, "Offset"))
2404 ; // ignored
2405 else if (!deh_strcasecmp(key, "Zero/One"))
2406 ; // ignored
2407 else if (!deh_strcasecmp(key, "Value"))
2408 deh_sfx->priority = (int)value;
2409 else if (!deh_strcasecmp(key, "Zero 1"))
2410 ; // ignored
2411 else if (!deh_strcasecmp(key, "Zero 2"))
2412 deh_sfx->pitch = (int)value;
2413 else if (!deh_strcasecmp(key, "Zero 3"))
2414 ;
2415 else if (!deh_strcasecmp(key, "Zero 4"))
2416 ; // ignored
2417 else if (!deh_strcasecmp(key, "Neg. One 1"))
2418 ; // ignored
2419 else if (!deh_strcasecmp(key, "Neg. One 2"))
2420 ; // ignored
2421 else
2422 deh_log("Invalid sound string index for '%s'\n", key);
2423 }
2424 }
2425
2426 // ====================================================================
2427 // deh_procAmmo
2428 // Purpose: Handle DEH Ammo block
2429 // Args: fpin -- input file stream
2430 // line -- current line in file to process
2431 // Returns: void
2432 //
2433 static void deh_procAmmo(DEHFILE *fpin, char *line)
2434 {
2435 char key[DEH_MAXKEYLEN];
2436 char inbuffer[DEH_BUFFERMAX];
2437 uint64_t value; // All deh values are ints or longs
2438 int indexnum;
2439
2440 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2441
2442 // killough 8/98: allow hex numbers in input:
2443 sscanf(inbuffer, "%s %i", key, &indexnum);
2444 deh_log("Processing Ammo at index %d: %s\n", indexnum, key);
2445 if (indexnum < 0 || indexnum >= NUMAMMO)
2446 deh_log("Bad ammo number %d of %d\n", indexnum, NUMAMMO);
2447
2448 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2449 {
2450 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2451 lfstrip(inbuffer);
2452 if (!*inbuffer) break; // killough 11/98
2453 if (!deh_GetData(inbuffer, key, &value, NULL)) // returns TRUE if ok
2454 {
2455 deh_log("Bad data pair in '%s'\n", inbuffer);
2456 continue;
2457 }
2458 if (!deh_strcasecmp(key, deh_ammo[0])) // Max ammo
2459 maxammo[indexnum] = (int)value;
2460 else if (!deh_strcasecmp(key, deh_ammo[1])) // Per ammo
2461 clipammo[indexnum] = (int)value;
2462 else
2463 deh_log("Invalid ammo string index for '%s'\n", key);
2464 }
2465 }
2466
2467 // ====================================================================
2468 // deh_procWeapon
2469 // Purpose: Handle DEH Weapon block
2470 // Args: fpin -- input file stream
2471 // line -- current line in file to process
2472 // Returns: void
2473 //
2474 static void deh_procWeapon(DEHFILE *fpin, char *line)
2475 {
2476 char key[DEH_MAXKEYLEN];
2477 char inbuffer[DEH_BUFFERMAX];
2478 uint64_t value; // All deh values are ints or longs
2479 int indexnum;
2480 char *strval;
2481 int bGetData;
2482
2483 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2484
2485 // killough 8/98: allow hex numbers in input:
2486 sscanf(inbuffer, "%s %i", key, &indexnum);
2487 deh_log("Processing Weapon at index %d: %s\n", indexnum, key);
2488 if (indexnum < 0 || indexnum >= NUMWEAPONS)
2489 deh_log("Bad weapon number %d of %d\n", indexnum, NUMAMMO);
2490
2491 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2492 {
2493 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2494 lfstrip(inbuffer);
2495 if (!*inbuffer) break; // killough 11/98
2496 bGetData = deh_GetData(inbuffer, key, &value, &strval);
2497 if (!bGetData) // returns TRUE if ok
2498 {
2499 deh_log("Bad data pair in '%s'\n", inbuffer);
2500 continue;
2501 }
2502 if (!deh_strcasecmp(key, deh_weapon[0])) // Ammo type
2503 {
2504 if (!raven && value == 5) value = am_noammo;
2505 weaponinfo[indexnum].ammo = (ammotype_t)value;
2506 }
2507 else if (!deh_strcasecmp(key, deh_weapon[1])) // Deselect frame
2508 weaponinfo[indexnum].upstate = (int)value;
2509 else if (!deh_strcasecmp(key, deh_weapon[2])) // Select frame
2510 weaponinfo[indexnum].downstate = (int)value;
2511 else if (!deh_strcasecmp(key, deh_weapon[3])) // Bobbing frame
2512 weaponinfo[indexnum].readystate = (int)value;
2513 else if (!deh_strcasecmp(key, deh_weapon[4])) // Shooting frame
2514 weaponinfo[indexnum].atkstate = (int)value;
2515 else if (!deh_strcasecmp(key, deh_weapon[5])) // Firing frame
2516 weaponinfo[indexnum].flashstate = (int)value;
2517 else if (!deh_strcasecmp(key, deh_weapon[6])) // Ammo per shot
2518 {
2519 weaponinfo[indexnum].ammopershot = (int)value;
2520 weaponinfo[indexnum].intflags |= WIF_ENABLEAPS;
2521 }
2522 else if (!deh_strcasecmp(key, deh_weapon[7])) // MBF21 Bits
2523 {
2524 if (bGetData == 1)
2525 {
2526 value = deh_translate_bits(value, deh_weaponflags_mbf21);
2527 }
2528 else
2529 {
2530 for (value = 0; (strval = strtok(strval, deh_getBitsDelims())); strval = NULL) {
2531 const struct deh_flag_s *flag;
2532
2533 for (flag = deh_weaponflags_mbf21; flag->name; flag++) {
2534 if (deh_strcasecmp(strval, flag->name)) continue;
2535
2536 value |= flag->value;
2537 break;
2538 }
2539
2540 if (!flag->name) {
2541 deh_log("Could not find MBF21 weapon bit mnemonic %s\n", strval);
2542 }
2543 }
2544 }
2545
2546 weaponinfo[indexnum].flags = value;
2547 }
2548 else
2549 deh_log("Invalid weapon string index for '%s'\n",key);
2550 }
2551 }
2552
2553 // ====================================================================
2554 // deh_procSprite
2555 // Purpose: Dummy - we do not support the DEH Sprite block
2556 // Args: fpin -- input file stream
2557 // line -- current line in file to process
2558 // Returns: void
2559 //
2560 static void deh_procSprite(DEHFILE *fpin, char *line) // Not supported
2561 {
2562 char key[DEH_MAXKEYLEN];
2563 char inbuffer[DEH_BUFFERMAX];
2564 int indexnum;
2565
2566 // Too little is known about what this is supposed to do, and
2567 // there are better ways of handling sprite renaming. Not supported.
2568
2569 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2570
2571 // killough 8/98: allow hex numbers in input:
2572 sscanf(inbuffer, "%s %i", key, &indexnum);
2573 deh_log("Ignoring Sprite offset change at index %d: %s\n", indexnum, key);
2574 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2575 {
2576 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2577 lfstrip(inbuffer);
2578 if (!*inbuffer) break; // killough 11/98
2579 // ignore line
2580 deh_log("- %s\n", inbuffer);
2581 }
2582 }
2583
2584 // ====================================================================
2585 // deh_procPars
2586 // Purpose: Handle BEX extension for PAR times
2587 // Args: fpin -- input file stream
2588 // line -- current line in file to process
2589 // Returns: void
2590 //
2591 static void deh_procPars(DEHFILE *fpin, char *line) // extension
2592 {
2593 char key[DEH_MAXKEYLEN];
2594 char inbuffer[DEH_BUFFERMAX];
2595 int indexnum;
2596 int episode, level, partime, oldpar;
2597
2598 // new item, par times
2599 // usage: After [PARS] Par 0 section identifier, use one or more of these
2600 // lines:
2601 // par 3 5 120
2602 // par 14 230
2603 // The first would make the par for E3M5 be 120 seconds, and the
2604 // second one makes the par for MAP14 be 230 seconds. The number
2605 // of parameters on the line determines which group of par values
2606 // is being changed. Error checking is done based on current fixed
2607 // array sizes of[4][10] and [32]
2608
2609 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2610
2611 // killough 8/98: allow hex numbers in input:
2612 sscanf(inbuffer, "%s %i", key, &indexnum);
2613 deh_log("Processing Par value at index %d: %s\n", indexnum, key);
2614 // indexnum is a dummy entry
2615 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2616 {
2617 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2618 lfstrip(M_Strlwr(inbuffer)); // lowercase it
2619 if (!*inbuffer) break; // killough 11/98
2620 if (3 != sscanf(inbuffer, "par %i %i %i", &episode, &level, &partime))
2621 { // not 3
2622 if (2 != sscanf(inbuffer, "par %i %i", &level, &partime))
2623 { // not 2
2624 deh_log("Invalid par time setting string: %s\n", inbuffer);
2625 }
2626 else
2627 { // is 2
2628 // Ty 07/11/98 - wrong range check, not zero-based
2629 if (level < 1 || level > 32) // base 0 array (but 1-based parm)
2630 {
2631 deh_log("Invalid MAPnn value MAP%d\n", level);
2632 }
2633 else
2634 {
2635 oldpar = cpars[level-1];
2636 deh_log("Changed par time for MAP%02d from %d to %d\n", level, oldpar, partime);
2637 cpars[level - 1] = partime;
2638 deh_pars = TRUE;
2639 }
2640 }
2641 }
2642 else
2643 { // is 3
2644 // note that though it's a [4][10] array, the "left" and "top" aren't used,
2645 // effectively making it a base 1 array.
2646 // Ty 07/11/98 - level was being checked against max 3 - dumb error
2647 // Note that episode 4 does not have par times per original design
2648 // in Ultimate DOOM so that is not supported here.
2649 if (episode < 1 || episode > 3 || level < 1 || level > 9)
2650 {
2651 deh_log("Invalid ExMx values E%dM%d\n", episode, level);
2652 }
2653 else
2654 {
2655 oldpar = pars[episode][level];
2656 pars[episode][level] = partime;
2657 deh_log("Changed par time for E%dM%d from %d to %d\n", episode, level, oldpar, partime);
2658 deh_pars = TRUE;
2659 }
2660 }
2661 }
2662 }
2663
2664 // ====================================================================
2665 // deh_procCheat
2666 // Purpose: Handle DEH Cheat block
2667 // Args: fpin -- input file stream
2668 // line -- current line in file to process
2669 // Returns: void
2670 //
2671 static void deh_procCheat(DEHFILE *fpin, char *line) // done
2672 {
2673 char key[DEH_MAXKEYLEN];
2674 char inbuffer[DEH_BUFFERMAX];
2675 uint64_t value; // All deh values are ints or longs
2676 char ch = 0; // CPhipps - `writable' null string to initialise...
2677 char *strval = &ch; // pointer to the value area
2678 int ix, iy; // array indices
2679 char *p; // utility pointer
2680
2681 deh_log("Processing Cheat: %s\n", line);
2682
2683 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2684 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2685 {
2686 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2687 lfstrip(inbuffer);
2688 if (!*inbuffer) break; // killough 11/98
2689 if (!deh_GetData(inbuffer, key, &value, &strval)) // returns TRUE if ok
2690 {
2691 deh_log("Bad data pair in '%s'\n", inbuffer);
2692 continue;
2693 }
2694 // Otherwise we got a (perhaps valid) cheat name,
2695 // so look up the key in the array
2696
2697 // killough 4/18/98: use main cheat code table in st_stuff.c now
2698 for (ix = 0; cheat[ix].cheat; ix++)
2699 if (cheat[ix].deh_cheat) // killough 4/18/98: skip non-deh
2700 {
2701 if (!stricmp(key,cheat[ix].deh_cheat)) // found the cheat, ignored case
2702 {
2703 // replace it but don't overflow it. Use current length as limit.
2704 // Ty 03/13/98 - add 0xff code
2705 // Deal with the fact that the cheats in deh files are extended
2706 // with character 0xFF to the original cheat length, which we don't do.
2707 for (iy = 0; strval[iy]; iy++)
2708 strval[iy] = (strval[iy] == (char)0xff) ? '\0' : strval[iy];
2709
2710 iy = ix; // killough 4/18/98
2711
2712 // Ty 03/14/98 - skip leading spaces
2713 p = strval;
2714 while (*p == ' ') ++p;
2715
2716 //e6y: ability to ignore cheats in dehacked files.
2717 if (dsda_IntConfig(dsda_config_deh_apply_cheats) && !dsda_Flag(dsda_arg_nocheats))
2718 {
2719 cheat[iy].cheat = Z_Strdup(p);
2720 deh_log("Assigned new cheat '%s' to cheat '%s'at index %d\n",
2721 p, cheat[ix].deh_cheat, iy); // killough 4/18/98
2722 }
2723 }
2724 }
2725 deh_log("- %s\n", inbuffer);
2726 }
2727 }
2728
2729 // ====================================================================
2730 // deh_procMisc
2731 // Purpose: Handle DEH Misc block
2732 // Args: fpin -- input file stream
2733 // line -- current line in file to process
2734 // Returns: void
2735 //
2736 static void deh_procMisc(DEHFILE *fpin, char *line) // done
2737 {
2738 char key[DEH_MAXKEYLEN];
2739 char inbuffer[DEH_BUFFERMAX];
2740 uint64_t value; // All deh values are ints or longs
2741
2742 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2743 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2744 {
2745 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2746 lfstrip(inbuffer);
2747 if (!*inbuffer) break; // killough 11/98
2748 if (!deh_GetData(inbuffer, key, &value, NULL)) // returns TRUE if ok
2749 {
2750 deh_log("Bad data pair in '%s'\n", inbuffer);
2751 continue;
2752 }
2753 // Otherwise it's ok
2754 deh_log("Processing Misc item '%s'\n", key);
2755
2756 if (!deh_strcasecmp(key, deh_misc[0])) // Initial Health
2757 initial_health = (int)value;
2758 else if (!deh_strcasecmp(key, deh_misc[1])) // Initial Bullets
2759 initial_bullets = (int)value;
2760 else if (!deh_strcasecmp(key, deh_misc[2])) // Max Health
2761 {
2762 IsDehMaxHealth = true;
2763 deh_maxhealth = (int)value; //e6y
2764 }
2765 else if (!deh_strcasecmp(key, deh_misc[3])) // Max Armor
2766 max_armor = (int)value;
2767 else if (!deh_strcasecmp(key, deh_misc[4])) // Green Armor Class
2768 green_armor_class = (int)value;
2769 else if (!deh_strcasecmp(key, deh_misc[5])) // Blue Armor Class
2770 blue_armor_class = (int)value;
2771 else if (!deh_strcasecmp(key, deh_misc[6])) // Max Soulsphere
2772 {
2773 IsDehMaxSoul = true;
2774 deh_max_soul = (int)value; //e6y
2775 }
2776 else if (!deh_strcasecmp(key, deh_misc[7])) // Soulsphere Health
2777 soul_health = (int)value;
2778 else if (!deh_strcasecmp(key, deh_misc[8])) // Megasphere Health
2779 {
2780 IsDehMegaHealth = true;
2781 deh_mega_health = (int)value; //e6y
2782 }
2783 else if (!deh_strcasecmp(key, deh_misc[9])) // God Mode Health
2784 god_health = (int)value;
2785 else if (!deh_strcasecmp(key, deh_misc[10])) // IDFA Armor
2786 idfa_armor = (int)value;
2787 else if (!deh_strcasecmp(key, deh_misc[11])) // IDFA Armor Class
2788 idfa_armor_class = (int)value;
2789 else if (!deh_strcasecmp(key, deh_misc[12])) // IDKFA Armor
2790 idkfa_armor = (int)value;
2791 else if (!deh_strcasecmp(key, deh_misc[13])) // IDKFA Armor Class
2792 idkfa_armor_class = (int)value;
2793 else if (!deh_strcasecmp(key, deh_misc[14])) // BFG Cells/Shot
2794 {
2795 weaponinfo[wp_bfg].ammopershot = bfgcells = (int)value;
2796 bfgcells_modified = true;
2797 }
2798 else if (!deh_strcasecmp(key, deh_misc[15])) // Monsters Infight
2799 {
2800 // e6y: Dehacked support - monsters infight
2801 if (value == 202) monsters_infight = 0;
2802 else if (value == 221) monsters_infight = 1;
2803 else deh_log("Invalid value for 'Monsters Infight': %i", (int)value);
2804
2805 /* No such switch in DOOM - nop */ //e6y ;
2806 }
2807 else
2808 deh_log("Invalid misc item string index for '%s'\n", key);
2809 }
2810 }
2811
2812 // ====================================================================
2813 // deh_procText
2814 // Purpose: Handle DEH Text block
2815 // Notes: We look things up in the current information and if found
2816 // we replace it. At the same time we write the new and
2817 // improved BEX syntax to the log file for future use.
2818 // Args: fpin -- input file stream
2819 // line -- current line in file to process
2820 // Returns: void
2821 //
2822 static void deh_procText(DEHFILE *fpin, char *line)
2823 {
2824 char key[DEH_MAXKEYLEN];
2825 char inbuffer[DEH_BUFFERMAX * 2]; // can't use line -- double size buffer too.
2826 int i; // loop variable
2827 int fromlen, tolen; // as specified on the text block line
2828 int usedlen; // shorter of fromlen and tolen if not matched
2829 dboolean found = FALSE; // to allow early exit once found
2830 char* line2 = NULL; // duplicate line for rerouting
2831
2832 // Ty 04/11/98 - Included file may have NOTEXT skip flag set
2833 if (includenotext) // flag to skip included deh-style text
2834 {
2835 deh_log("Skipped text block because of notext directive\n");
2836 strcpy(inbuffer,line);
2837 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
2838 dehfgets(inbuffer, sizeof(inbuffer), fpin); // skip block
2839 // Ty 05/17/98 - don't care if this fails
2840 return; // ************** Early return
2841 }
2842
2843 // killough 8/98: allow hex numbers in input:
2844 sscanf(line, "%s %i %i", key, &fromlen, &tolen);
2845 deh_log("Processing Text (key=%s, from=%d, to=%d)\n", key, fromlen, tolen);
2846
2847 // killough 10/98: fix incorrect usage of feof
2848 {
2849 int c, totlen = 0;
2850 while (totlen < fromlen + tolen && (c = dehfgetc(fpin)) != EOF)
2851 if (c != '\r')
2852 inbuffer[totlen++] = c;
2853 inbuffer[totlen]='\0';
2854 }
2855
2856 // if the from and to are 4, this may be a sprite rename. Check it
2857 // against the array and process it as such if it matches. Remember
2858 // that the original names are (and should remain) uppercase.
2859 // Future: this will be from a separate [SPRITES] block.
2860 if (fromlen == 4 && tolen == 4)
2861 {
2862 i = dsda_GetDehSpriteIndex(inbuffer);
2863
2864 if (i >= 0)
2865 {
2866 char *s;
2867
2868 deh_log("Changing name of sprite at index %d from %s to %*s\n",
2869 i, sprnames[i], tolen, &inbuffer[fromlen]);
2870
2871 // CPhipps - fix constness problem
2872 sprnames[i] = s = Z_Strdup(sprnames[i]);
2873 strncpy(s, &inbuffer[fromlen], tolen);
2874
2875 found = TRUE;
2876 }
2877 }
2878
2879 if (!found && fromlen < 7 && tolen < 7) // lengths of music and sfx are 6 or shorter
2880 {
2881 usedlen = (fromlen < tolen) ? fromlen : tolen;
2882 if (fromlen != tolen)
2883 deh_log("Warning: Mismatched lengths from=%d, to=%d, used %d\n", fromlen, tolen, usedlen);
2884
2885 i = dsda_GetDehSFXIndex(inbuffer, (size_t) fromlen);
2886 if (i >= 0)
2887 {
2888 deh_log("Changing name of sfx from %s to %*s\n",
2889 S_sfx[i].name, usedlen, &inbuffer[fromlen]);
2890
2891 S_sfx[i].name = deh_sfx_name(&inbuffer[fromlen]);
2892
2893 found = TRUE;
2894 }
2895 else
2896 {
2897 i = dsda_GetDehMusicIndex(inbuffer, (size_t) fromlen);
2898 if (i >= 0)
2899 {
2900 deh_log("Changing name of music from %s to %*s\n",
2901 S_music[i].name, usedlen, &inbuffer[fromlen]);
2902
2903 S_music[i].name = Z_Strdup(&inbuffer[fromlen]);
2904
2905 found = TRUE;
2906 }
2907 }
2908 }
2909
2910 if (!found) // Nothing we want to handle here--see if strings can deal with it.
2911 {
2912 deh_log("Checking text area through strings for '%.12s%s' from=%d to=%d\n",
2913 inbuffer, (strlen(inbuffer) > 12) ? "..." : "", fromlen, tolen);
2914 if ((size_t)fromlen <= strlen(inbuffer))
2915 {
2916 line2 = Z_Strdup(&inbuffer[fromlen]);
2917 inbuffer[fromlen] = '\0';
2918 }
2919
2920 deh_procStringSub(NULL, inbuffer, line2);
2921 }
2922 Z_Free(line2); // may be NULL, ignored by free()
2923 }
2924
2925 static void deh_procError(DEHFILE *fpin, char *line)
2926 {
2927 char inbuffer[DEH_BUFFERMAX];
2928
2929 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2930 deh_log("Unmatched Block: '%s'\n", inbuffer);
2931 }
2932
2933 // ====================================================================
2934 // deh_procStrings
2935 // Purpose: Handle BEX [STRINGS] extension
2936 // Args: fpin -- input file stream
2937 // line -- current line in file to process
2938 // Returns: void
2939 //
2940 static void deh_procStrings(DEHFILE *fpin, char *line)
2941 {
2942 char key[DEH_MAXKEYLEN];
2943 char inbuffer[DEH_BUFFERMAX];
2944 uint64_t value; // All deh values are ints or longs
2945 char *strval; // holds the string value of the line
2946 static size_t maxstrlen = 128; // maximum string length, bumped 128 at
2947 // a time as needed
2948 // holds the final result of the string after concatenation
2949 static char *holdstring = NULL;
2950 dboolean found = false; // looking for string continuation
2951
2952 deh_log("Processing extended string substitution\n");
2953
2954 if (!holdstring) holdstring = Z_Malloc(maxstrlen * sizeof(*holdstring));
2955
2956 *holdstring = '\0'; // empty string to start with
2957 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
2958 // Ty 04/24/98 - have to allow inbuffer to start with a blank for
2959 // the continuations of C1TEXT etc.
2960 while (!dehfeof(fpin) && *inbuffer) /* && (*inbuffer != ' ') */
2961 {
2962 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
2963 if (*inbuffer == '#') continue; // skip comment lines
2964 lfstrip(inbuffer);
2965 if (!*inbuffer && !*holdstring) break; // killough 11/98
2966 if (!*holdstring) // first one--get the key
2967 {
2968 if (!deh_GetData(inbuffer, key, &value, &strval)) // returns TRUE if ok
2969 {
2970 deh_log("Bad data pair in '%s'\n", inbuffer);
2971 continue;
2972 }
2973 }
2974 while (strlen(holdstring) + strlen(inbuffer) > maxstrlen) // Ty03/29/98 - fix stupid error
2975 {
2976 // killough 11/98: allocate enough the first time
2977 maxstrlen = strlen(holdstring) + strlen(inbuffer);
2978 deh_log("* increased buffer from to %ld for buffer size %d\n",
2979 (long)maxstrlen, (int)strlen(inbuffer));
2980 holdstring = Z_Realloc(holdstring, maxstrlen * sizeof(*holdstring));
2981 }
2982 // concatenate the whole buffer if continuation or the value iffirst
2983 strcat(holdstring, ptr_lstrip(((*holdstring) ? inbuffer : strval)));
2984 rstrip(holdstring);
2985 // delete any trailing blanks past the backslash
2986 // note that blanks before the backslash will be concatenated
2987 // but ones at the beginning of the next line will not, allowing
2988 // indentation in the file to read well without affecting the
2989 // string itself.
2990 if (holdstring[strlen(holdstring) - 1] == '\\')
2991 {
2992 holdstring[strlen(holdstring) - 1] = '\0';
2993 continue; // ready to concatenate
2994 }
2995 if (*holdstring) // didn't have a backslash, trap above would catch that
2996 {
2997 // go process the current string
2998 found = deh_procStringSub(key, NULL, holdstring); // supply keyand not search string
2999
3000 if (!found)
3001 deh_log("Invalid string key '%s', substitution skipped.\n", key);
3002
3003 *holdstring = '\0'; // empty string for the next one
3004 }
3005 }
3006 }
3007
3008 // ====================================================================
3009 // deh_procStringSub
3010 // Purpose: Common string parsing and handling routine for DEH and BEX
3011 // Args: key -- place to put the mnemonic for the string if found
3012 // lookfor -- original value string to look for
3013 // newstring -- string to put in its place if found
3014 // Returns: dboolean: True if string found, false if not
3015 //
3016 dboolean deh_procStringSub(char *key, char *lookfor, char *newstring)
3017 {
3018 dboolean found; // loop exit flag
3019 int i; // looper
3020
3021 found = false;
3022 for (i = 0; i < deh_numstrlookup; i++)
3023 {
3024 if (deh_strlookup[i].orig == NULL)
3025 {
3026 deh_strlookup[i].orig = *deh_strlookup[i].ppstr;
3027 }
3028 found = lookfor ?
3029 !stricmp(deh_strlookup[i].orig, lookfor) :
3030 !stricmp(deh_strlookup[i].lookup, key);
3031
3032 if (found)
3033 {
3034 char *t;
3035 *deh_strlookup[i].ppstr = t = Z_Strdup(newstring); // orphan originalstring
3036 found = true;
3037 // Handle embedded \n's in the incoming string, convert to 0x0a's
3038 {
3039 const char *s;
3040 for (s = *deh_strlookup[i].ppstr; *s; ++s, ++t)
3041 {
3042 if (*s == '\\' && (s[1] == 'n' || s[1] == 'N')) //found one
3043 ++s, *t = '\n'; // skip one extra for second character
3044 else
3045 *t = *s;
3046 }
3047 *t = '\0'; // cap off the target string
3048 }
3049
3050 if (key)
3051 deh_log("Assigned key %s => '%s'\n", key, newstring);
3052
3053 if (!key)
3054 deh_log("Assigned '%.12s%s' to'%.12s%s' at key %s\n",
3055 lookfor, (strlen(lookfor) > 12) ? "..." : "",
3056 newstring, (strlen(newstring) > 12) ? "..." :"",
3057 deh_strlookup[i].lookup);
3058
3059 if (!key) // must have passed an old style string so showBEX
3060 deh_log("*BEX FORMAT:\n%s = %s\n*END BEX\n",
3061 deh_strlookup[i].lookup, dehReformatStr(newstring));
3062
3063 break;
3064 }
3065 }
3066 if (!found)
3067 deh_log("Could not find '%.12s'\n", key ? key : lookfor);
3068
3069 return found;
3070 }
3071
3072 //========================================================================
3073 // haleyjd 9/22/99
3074 //
3075 // deh_procHelperThing
3076 //
3077 // Allows handy substitution of any thing for helper dogs. DEH patches
3078 // are being made frequently for this purpose and it requires a complete
3079 // rewiring of the DOG thing. I feel this is a waste of effort, and so
3080 // have added this new [HELPER] BEX block
3081
3082 static void deh_procHelperThing(DEHFILE *fpin, char *line)
3083 {
3084 char key[DEH_MAXKEYLEN];
3085 char inbuffer[DEH_BUFFERMAX];
3086 uint64_t value; // All deh values are ints or longs
3087
3088 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
3089 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
3090 {
3091 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
3092 lfstrip(inbuffer);
3093 if (!*inbuffer) break;
3094 if (!deh_GetData(inbuffer, key, &value, NULL)) // returns TRUE if ok
3095 {
3096 deh_log("Bad data pair in '%s'\n", inbuffer);
3097 continue;
3098 }
3099 // Otherwise it's ok
3100 deh_log("Processing Helper Thing item '%s'\nvalue is %i", key, (int)value);
3101 if (!strncasecmp(key, "type", 4))
3102 HelperThing = dsda_TranslateDehMobjIndex((int)value);
3103 }
3104 }
3105
3106 //
3107 // deh_procBexSprites
3108 //
3109 // Supports sprite name substitutions without requiring use
3110 // of the DeHackEd Text block
3111 //
3112 static void deh_procBexSprites(DEHFILE *fpin, char *line)
3113 {
3114 char key[DEH_MAXKEYLEN];
3115 char inbuffer[DEH_BUFFERMAX];
3116 uint64_t value; // All deh values are ints or longs
3117 char *strval; // holds the string value of the line
3118 char candidate[5];
3119 int match;
3120
3121 deh_log("Processing sprite name substitution\n");
3122
3123 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
3124
3125 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
3126 {
3127 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin))
3128 break;
3129 if (*inbuffer == '#')
3130 continue; // skip comment lines
3131 lfstrip(inbuffer);
3132 if (!*inbuffer)
3133 break; // killough 11/98
3134 if (!deh_GetData(inbuffer, key, &value, &strval)) // returns TRUE if ok
3135 {
3136 deh_log("Bad data pair in '%s'\n", inbuffer);
3137 continue;
3138 }
3139 // do it
3140 memset(candidate, 0, sizeof(candidate));
3141 strncpy(candidate, ptr_lstrip(strval), 4);
3142 if (strlen(candidate) != 4)
3143 {
3144 deh_log("Bad length for sprite name '%s'\n", candidate);
3145 continue;
3146 }
3147
3148 match = dsda_GetOriginalSpriteIndex(key);
3149 if (match >= 0)
3150 {
3151 deh_log("Substituting '%s' for sprite '%s'\n", candidate, key);
3152 sprnames[match] = Z_Strdup(candidate);
3153 }
3154 }
3155 }
3156
3157 // ditto for sound names
3158 static void deh_procBexSounds(DEHFILE *fpin, char *line)
3159 {
3160 char key[DEH_MAXKEYLEN];
3161 char inbuffer[DEH_BUFFERMAX];
3162 uint64_t value; // All deh values are ints or longs
3163 char *strval; // holds the string value of the line
3164 char candidate[7];
3165 int match;
3166 size_t len;
3167
3168 deh_log("Processing sound name substitution\n");
3169
3170 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
3171
3172 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
3173 {
3174 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin))
3175 break;
3176 if (*inbuffer == '#')
3177 continue; // skip comment lines
3178 lfstrip(inbuffer);
3179 if (!*inbuffer)
3180 break; // killough 11/98
3181 if (!deh_GetData(inbuffer, key, &value, &strval)) // returns TRUE if ok
3182 {
3183 deh_log("Bad data pair in '%s'\n", inbuffer);
3184 continue;
3185 }
3186 // do it
3187 memset(candidate, 0, 7);
3188 strncpy(candidate, ptr_lstrip(strval), 6);
3189 len = strlen(candidate);
3190 if (len < 1 || len > 6)
3191 {
3192 deh_log("Bad length for sound name '%s'\n", candidate);
3193 continue;
3194 }
3195
3196 match = dsda_GetOriginalSFXIndex(key);
3197 if (match >= 0)
3198 {
3199 deh_log("Substituting '%s' for sound '%s'\n", candidate, key);
3200 dsda_GetDehSFX(match)->name = deh_sfx_name(candidate);
3201 }
3202 }
3203 }
3204
3205 // ditto for music names
3206 static void deh_procBexMusic(DEHFILE *fpin, char *line)
3207 {
3208 char key[DEH_MAXKEYLEN];
3209 char inbuffer[DEH_BUFFERMAX];
3210 uint64_t value; // All deh values are ints or longs
3211 char *strval; // holds the string value of the line
3212 char candidate[7];
3213 int match;
3214 size_t len;
3215
3216 deh_log("Processing music name substitution\n");
3217
3218 strncpy(inbuffer, line, DEH_BUFFERMAX - 1);
3219
3220 while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
3221 {
3222 if (!dehfgets(inbuffer, sizeof(inbuffer), fpin))
3223 break;
3224 if (*inbuffer == '#')
3225 continue; // skip comment lines
3226 lfstrip(inbuffer);
3227 if (!*inbuffer)
3228 break; // killough 11/98
3229 if (!deh_GetData(inbuffer, key, &value, &strval)) // returns TRUE if ok
3230 {
3231 deh_log("Bad data pair in '%s'\n", inbuffer);
3232 continue;
3233 }
3234 // do it
3235 memset(candidate, 0, 7);
3236 strncpy(candidate, ptr_lstrip(strval), 6);
3237 len = strlen(candidate);
3238 if (len < 1 || len > 6)
3239 {
3240 deh_log("Bad length for music name '%s'\n", candidate);
3241 continue;
3242 }
3243
3244 match = dsda_GetOriginalMusicIndex(key);
3245 if (match >= 0)
3246 {
3247 deh_log("Substituting '%s' for music '%s'\n", candidate, key);
3248 S_music[match].name = Z_Strdup(candidate);
3249 }
3250 }
3251 }
3252
3253 // ====================================================================
3254 // General utility function(s)
3255 // ====================================================================
3256
3257 // ====================================================================
3258 // dehReformatStr
3259 // Purpose: Convert a string into a continuous string with embedded
3260 // linefeeds for "\n" sequences in the source string
3261 // Args: string -- the string to convert
3262 // Returns: the converted string (converted in a static buffer)
3263 //
3264 char *dehReformatStr(char *string)
3265 {
3266 static char buff[DEH_BUFFERMAX]; // only processing the changed string,
3267 // don't need double buffer
3268 char *s, *t;
3269
3270 s = string; // source
3271 t = buff; // target
3272 // let's play...
3273
3274 while (*s)
3275 {
3276 if (*s == '\n')
3277 ++s, *t++ = '\\', *t++ = 'n', *t++ = '\\', *t++='\n';
3278 else
3279 *t++ = *s++;
3280 }
3281 *t = '\0';
3282 return buff;
3283 }
3284
3285 // ====================================================================
3286 // lfstrip
3287 // Purpose: Strips CR/LF off the end of a string
3288 // Args: s -- the string to work on
3289 // Returns: void -- the string is modified in place
3290 //
3291 // killough 10/98: only strip at end of line, not entire string
3292
3293 void lfstrip(char *s) // strip the \r and/or \n off of a line
3294 {
3295 char *p = s + strlen(s);
3296 while (p > s && (*--p == '\r' || *p == '\n'))
3297 *p = 0;
3298 }
3299
3300 // ====================================================================
3301 // rstrip
3302 // Purpose: Strips trailing blanks off a string
3303 // Args: s -- the string to work on
3304 // Returns: void -- the string is modified in place
3305 //
3306 void rstrip(char *s) // strip trailing whitespace
3307 {
3308 char *p = s + strlen(s); // killough 4/4/98: same here
3309 while (p > s && isspace(*--p)) // break on first non-whitespace
3310 *p = '\0';
3311 }
3312
3313 // ====================================================================
3314 // ptr_lstrip
3315 // Purpose: Points past leading whitespace in a string
3316 // Args: s -- the string to work on
3317 // Returns: char * pointing to the first nonblank character in the
3318 // string. The original string is not changed.
3319 //
3320 char *ptr_lstrip(char *p) // point past leading whitespace
3321 {
3322 while (isspace(*p))
3323 p++;
3324 return p;
3325 }
3326
3327 // ====================================================================
3328 // deh_GetData
3329 // Purpose: Get a key and data pair from a passed string
3330 // Args: s -- the string to be examined
3331 // k -- a place to put the key
3332 // l -- pointer to a long integer to store the number
3333 // strval -- a pointer to the place in s where the number
3334 // value comes from. Pass NULL to not use this.
3335 // Notes: Expects a key phrase, optional space, equal sign,
3336 // optional space and a value, mostly an int but treated
3337 // as a long just in case. The passed pointer to hold
3338 // the key must be DEH_MAXKEYLEN in size.
3339
3340 dboolean deh_GetData(char *s, char *k, uint64_t *l, char **strval)
3341 {
3342 char *t; // current char
3343 int val; // to hold value of pair
3344 char buffer[DEH_MAXKEYLEN]; // to hold key in progress
3345 // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
3346 // No more desync on HACX demos.
3347 dboolean okrc = 1; // assume good unless we have problems
3348 int i; // iterator
3349
3350 *buffer = '\0';
3351 val = 0; // defaults in case not otherwise set
3352 for (i = 0, t = s; *t && i < DEH_MAXKEYLEN; t++, i++)
3353 {
3354 if (*t == '=') break;
3355 buffer[i] = *t; // copy it
3356 }
3357 buffer[--i] = '\0'; // terminate the key before the '='
3358 if (!*t) // end of string with no equal sign
3359 {
3360 okrc = FALSE;
3361 }
3362 else
3363 {
3364 if (!*++t)
3365 {
3366 val = 0; // in case "thiskey =" with no value
3367 okrc = FALSE;
3368 }
3369 // we've incremented t
3370 // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
3371 // No more desync on HACX demos.
3372 // Old code: e6y val = strtol(t,NULL,0); // killough 8/9/98: allow hex or octal input
3373 if (!M_StrToInt(t, &val))
3374 {
3375 val = 0;
3376 okrc = 2;
3377 }
3378 }
3379
3380 // go put the results in the passed pointers
3381 *l = val; // may be a faked zero
3382
3383 // if spaces between key and equal sign, strip them
3384 strcpy(k, ptr_lstrip(buffer)); // could be a zero-length string
3385
3386 if (strval != NULL) // pass NULL if you don't want this back
3387 *strval = t; // pointer, has to be somewhere in s,
3388 // even if pointing at the zero byte.
3389
3390 return(okrc);
3391 }
3392
3393 static deh_bexptr null_bexptr = { NULL, "(NULL)" };
3394
3395 void PostProcessDeh(void)
3396 {
3397 int i, j;
3398 const deh_bexptr *bexptr_match;
3399
3400 // sanity-check bfgcells and bfg ammopershot
3401 if (
3402 bfgcells_modified &&
3403 weaponinfo[wp_bfg].intflags & WIF_ENABLEAPS &&
3404 bfgcells != weaponinfo[wp_bfg].ammopershot
3405 )
3406 I_Error("Mismatch between bfgcells and bfg ammo per shot modifications! Check your dehacked.");
3407
3408 if (processed_dehacked)
3409 {
3410 extern byte* defined_codeptr_args;
3411
3412 for (i = 0; i < num_states; i++)
3413 {
3414 bexptr_match = &null_bexptr;
3415
3416 for (j = 0; deh_bexptrs[j].cptr != NULL; ++j)
3417 if (states[i].action == deh_bexptrs[j].cptr)
3418 {
3419 bexptr_match = &deh_bexptrs[j];
3420 break;
3421 }
3422
3423 // ensure states don't use more mbf21 args than their
3424 // action pointer expects, for future-proofing's sake
3425 for (j = MAXSTATEARGS - 1; j >= bexptr_match->argcount; j--)
3426 if (states[i].args[j] != 0)
3427 I_Error("Action %s on state %d expects no more than %d nonzero args (%d found). Check your dehacked.",
3428 bexptr_match->lookup, i, bexptr_match->argcount, j+1);
3429
3430 // replace unset fields with default values
3431 for (; j >= 0; j--)
3432 if (!(defined_codeptr_args[i] & (1 << j)))
3433 states[i].args[j] = bexptr_match->default_args[j];
3434
3435 // State arguments that refer to thing indices need to be translated
3436 if (bexptr_match->ti_flags)
3437 {
3438 short args_i;
3439 short ti_flags = bexptr_match->ti_flags;
3440
3441 if (ti_flags & TI_MISC1)
3442 states[i].misc1 = dsda_TranslateDehMobjIndex(states[i].misc1);
3443
3444 if (ti_flags & TI_MISC2)
3445 states[i].misc2 = dsda_TranslateDehMobjIndex(states[i].misc2);
3446
3447 ti_flags >>= TI_ARGSSHIFT;
3448 for (args_i = 0; args_i < MAXSTATEARGS; ++args_i)
3449 if (ti_flags & (1 << args_i))
3450 states[i].args[args_i] = dsda_TranslateDehMobjIndex(states[i].args[args_i]);
3451 }
3452
3453 // Flags specifications aren't cross-port consistent -> must translate / mask bits
3454 if (bexptr_match->cptr == A_AddFlags || bexptr_match->cptr == A_RemoveFlags)
3455 {
3456 states[i].args[0] = deh_translate_bits(states[i].args[0], deh_mobjflags_standard);
3457 states[i].args[1] = deh_translate_bits(states[i].args[1], deh_mobjflags_mbf21);
3458 }
3459 else if (bexptr_match->cptr == A_JumpIfFlagsSet)
3460 {
3461 states[i].args[1] = deh_translate_bits(states[i].args[1], deh_mobjflags_standard);
3462 states[i].args[2] = deh_translate_bits(states[i].args[2], deh_mobjflags_mbf21);
3463 }
3464 }
3465 }
3466
3467 dsda_FreeDehStates();
3468 dsda_FreeDehSprites();
3469 dsda_FreeDehSFX();
3470 dsda_FreeDehMusic();
3471 dsda_FreeDehMobjInfo();
3472 }