Debian Codegraph @

prboom2/src/dsda/mapinfo/hexen.c

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA MapInfo Hexen
16 //
17
18 #include "doomstat.h"
19 #include "g_game.h"
20 #include "lprintf.h"
21 #include "m_misc.h"
22 #include "p_setup.h"
23 #include "r_data.h"
24 #include "s_sound.h"
25 #include "sc_man.h"
26 #include "sounds.h"
27 #include "w_wad.h"
28
29 #include "hexen/p_acs.h"
30 #include "hexen/sv_save.h"
31
32 #include "dsda/map_format.h"
33 #include "dsda/mapinfo.h"
34 #include "dsda/sndinfo.h"
35
36 #include "hexen.h"
37
38 #define MAPINFO_SCRIPT_NAME "MAPINFO"
39 #define MCMD_SKY1 1
40 #define MCMD_SKY2 2
41 #define MCMD_LIGHTNING 3
42 #define MCMD_FADETABLE 4
43 #define MCMD_DOUBLESKY 5
44 #define MCMD_CLUSTER 6
45 #define MCMD_WARPTRANS 7
46 #define MCMD_NEXT 8
47 #define MCMD_CDTRACK 9
48 #define MCMD_CD_STARTTRACK 10
49 #define MCMD_CD_END1TRACK 11
50 #define MCMD_CD_END2TRACK 12
51 #define MCMD_CD_END3TRACK 13
52 #define MCMD_CD_INTERTRACK 14
53 #define MCMD_CD_TITLETRACK 15
54
55 #define UNKNOWN_MAP_NAME "DEVELOPMENT MAP"
56 #define DEFAULT_SKY_NAME "SKY1"
57 #define DEFAULT_FADE_TABLE "COLORMAP"
58
59 typedef struct mapInfo_s {
60 short cluster;
61 short warpTrans;
62 short nextMap;
63 char name[32];
64 short sky1Texture;
65 short sky2Texture;
66 fixed_t sky1ScrollDelta;
67 fixed_t sky2ScrollDelta;
68 dboolean doubleSky;
69 dboolean lightning;
70 int fadetable;
71 char songLump[10];
72 } mapInfo_t;
73
74 static int MapCount = 98;
75
76 static mapInfo_t MapInfo[99];
77
78 static mapInfo_t *CurrentMap = MapInfo;
79
80 static const char *MapCmdNames[] = {
81 "SKY1",
82 "SKY2",
83 "DOUBLESKY",
84 "LIGHTNING",
85 "FADETABLE",
86 "CLUSTER",
87 "WARPTRANS",
88 "NEXT",
89 "CDTRACK",
90 "CD_START_TRACK",
91 "CD_END1_TRACK",
92 "CD_END2_TRACK",
93 "CD_END3_TRACK",
94 "CD_INTERMISSION_TRACK",
95 "CD_TITLE_TRACK",
96 NULL
97 };
98
99 static int MapCmdIDs[] = {
100 MCMD_SKY1,
101 MCMD_SKY2,
102 MCMD_DOUBLESKY,
103 MCMD_LIGHTNING,
104 MCMD_FADETABLE,
105 MCMD_CLUSTER,
106 MCMD_WARPTRANS,
107 MCMD_NEXT,
108 MCMD_CDTRACK,
109 MCMD_CD_STARTTRACK,
110 MCMD_CD_END1TRACK,
111 MCMD_CD_END2TRACK,
112 MCMD_CD_END3TRACK,
113 MCMD_CD_INTERTRACK,
114 MCMD_CD_TITLETRACK
115 };
116
117 static int QualifyMap(int map) {
118 return (map < 1 || map > MapCount) ? 0 : map;
119 }
120
121 static int P_TranslateMap(int map) {
122 int i;
123
124 for (i = 1; i < 99; i++)
125 if (MapInfo[i].warpTrans == map)
126 return i;
127
128 return -1;
129 }
130
131 int dsda_HexenNameToMap(int* found, const char* name, int* episode, int* map) {
132 return false;
133 }
134
135 int dsda_HexenFirstMap(int* episode, int* map) {
136 if (!hexen)
137 return false;
138
139 *episode = 1;
140 *map = P_TranslateMap(1);
141
142 if (*map == -1)
143 I_Error("Unable to detect default first map");
144
145 return true;
146 }
147
148 int dsda_HexenNewGameMap(int* episode, int* map) {
149 if (!hexen)
150 return false;
151
152 *episode = 1;
153 *map = P_TranslateMap(*map);
154
155 if (*map == -1)
156 *map = 1;
157
158 return true;
159 }
160
161 int dsda_HexenResolveWarp(int* args, int arg_count, int* episode, int* map) {
162 if (!hexen)
163 return false;
164
165 *episode = 1;
166
167 if (arg_count)
168 *map = P_TranslateMap(args[0]);
169 else
170 *map = P_TranslateMap(1);
171
172 if (*map == -1)
173 I_Error("-warp: Invalid map number.\n");
174
175 return true;
176 }
177
178 int dsda_HexenNextMap(int* episode, int* map) {
179 if (!hexen)
180 return false;
181
182 *episode = 1;
183 *map = CurrentMap->nextMap;
184
185 return true;
186 }
187
188 int dsda_HexenPrevMap(int* episode, int* map) {
189 int i;
190 int current_map;
191
192 if (!hexen)
193 return false;
194
195 current_map = QualifyMap(gamemap);
196
197 for (i = 1; i < 99; ++i)
198 if (MapInfo[i].nextMap == current_map) {
199 *episode = 1;
200 *map = i;
201
202 return true;
203 }
204
205 *episode = 1;
206 *map = current_map;
207
208 return true;
209 }
210
211 int dsda_HexenShowNextLocBehaviour(int* behaviour) {
212 return false; // TODO
213 }
214
215 int dsda_HexenSkipDrawShowNextLoc(int* skip) {
216 return false; // TODO
217 }
218
219 void dsda_HexenUpdateMapInfo(void) {
220 CurrentMap = &MapInfo[QualifyMap(gamemap)];
221 }
222
223 void dsda_HexenUpdateLastMapInfo(void) {
224 // TODO
225 }
226
227 void dsda_HexenUpdateNextMapInfo(void) {
228 // TODO
229 }
230
231 int dsda_HexenResolveCLEV(int* clev, int* episode, int* map) {
232 char* next;
233
234 if (!hexen)
235 return false;
236
237 // Catch invalid maps
238 next = VANILLA_MAP_LUMP_NAME(*episode, P_TranslateMap(*map));
239 if (!W_LumpNameExists(next)) {
240 doom_printf("IDCLEV target not found: %s", next);
241 *clev = false;
242 }
243 else
244 *clev = true;
245
246 return true;
247 }
248
249 dboolean partial_reset = false;
250
251 int dsda_HexenResolveINIT(int* init) {
252 if (!hexen)
253 return false;
254
255 partial_reset = true;
256
257 G_DeferedInitNew(gameskill, gameepisode, CurrentMap->warpTrans);
258
259 *init = true;
260
261 return true;
262 }
263
264 int dsda_HexenMusicIndexToLumpNum(int* lump, int music_index) {
265 const char* lump_name;
266
267 if (!hexen)
268 return false;
269
270 if (music_index >= hexen_mus_hub)
271 return false;
272
273 lump_name = dsda_SndInfoMapSongLumpName(music_index);
274 if (!*lump_name)
275 switch (music_index)
276 {
277 case hexen_mus_hexen:
278 case hexen_mus_hub:
279 case hexen_mus_hall:
280 case hexen_mus_orb:
281 case hexen_mus_chess:
282 lump_name = S_music[music_index].name;
283 break;
284 }
285
286 if (!*lump_name)
287 *lump = 0;
288 else
289 *lump = W_GetNumForName(lump_name);
290
291 return true;
292 }
293
294 int dsda_HexenMapMusic(int* music_index, int* music_lump, int episode, int map) {
295 if (!hexen)
296 return false;
297
298 *music_lump = -1;
299 *music_index = map;
300
301 return true;
302 }
303
304 int dsda_HexenIntermissionMusic(int* music_index, int* music_lump) {
305 return false; // TODO
306 }
307
308 int dsda_HexenInterMusic(int* music_index, int* music_lump) {
309 return false; // TODO
310 }
311
312 int dsda_HexenStartFinale(void) {
313 return false; // TODO
314 }
315
316 int dsda_HexenFTicker(void) {
317 return false; // TODO
318 }
319
320 void dsda_HexenFDrawer(void) {
321 return; // TODO
322 }
323
324 int dsda_HexenBossAction(mobj_t* mo) {
325 return false; // TODO
326 }
327
328 int dsda_HexenMapLumpName(const char** name, int episode, int map) {
329 return false; // TODO
330 }
331
332 int dsda_HexenMapAuthor(const char** author) {
333 return false;
334 }
335
336 int dsda_HexenHUTitle(dsda_string_t* str) {
337 if (!hexen)
338 return false;
339
340 dsda_InitString(str, NULL);
341
342 if (gamestate == GS_LEVEL && gamemap > 0 && gameepisode > 0)
343 dsda_StringCat(str, CurrentMap->name);
344
345 if (!str->string)
346 dsda_StringCat(str, VANILLA_MAP_LUMP_NAME(gameepisode, gamemap));
347
348 return true;
349 }
350
351 int dsda_HexenSkyTexture(int* sky) {
352 return false; // TODO
353 }
354
355 int dsda_HexenPrepareInitNew(void) {
356 extern int RebornPosition;
357
358 if (!hexen)
359 return false;
360
361 SV_Init();
362
363 if (partial_reset) {
364 partial_reset = false;
365 return true;
366 }
367
368 if (map_format.acs)
369 P_ACSInitNewGame();
370
371 // Default the player start spot group to 0
372 RebornPosition = 0;
373
374 return true;
375 }
376
377 int dsda_HexenPrepareIntermission(int* result) {
378 if (!hexen)
379 return false;
380
381 if (leave_data.map == LEAVE_VICTORY && leave_data.position == LEAVE_VICTORY)
382 *result = DC_VICTORY;
383 else
384 *result = 0;
385
386 return true;
387 }
388
389 int dsda_HexenPrepareFinale(int* result) {
390 return false; // TODO
391 }
392
393 void dsda_HexenLoadMapInfo(void) {
394 int map;
395 int mapMax;
396 int mcmdValue;
397 mapInfo_t* info;
398 const char* default_sky_name = DEFAULT_SKY_NAME;
399
400 if (!hexen)
401 return;
402
403 mapMax = 1;
404
405 if (gamemode == shareware)
406 default_sky_name = "SKY2";
407
408 // Put defaults into MapInfo[0]
409 info = MapInfo;
410 info->cluster = 0;
411 info->warpTrans = 0;
412 info->nextMap = 1; // Always go to map 1 if not specified
413 info->sky1Texture = R_TextureNumForName(default_sky_name);
414 info->sky2Texture = info->sky1Texture;
415 info->sky1ScrollDelta = 0;
416 info->sky2ScrollDelta = 0;
417 info->doubleSky = false;
418 info->lightning = false;
419 info->fadetable = W_GetNumForName(DEFAULT_FADE_TABLE);
420 M_StringCopy(info->name, UNKNOWN_MAP_NAME, sizeof(info->name));
421
422 SC_OpenLump(MAPINFO_SCRIPT_NAME);
423 while (SC_GetString()) {
424 if (SC_Compare("MAP") == false)
425 SC_ScriptError(NULL);
426
427 SC_MustGetNumber();
428 if (sc_Number < 1 || sc_Number > 99)
429 SC_ScriptError(NULL);
430
431 map = sc_Number;
432
433 info = &MapInfo[map];
434
435 // Copy defaults to current map definition
436 memcpy(info, &MapInfo[0], sizeof(*info));
437
438 // The warp translation defaults to the map number
439 info->warpTrans = map;
440
441 // Map name must follow the number
442 SC_MustGetString();
443 M_StringCopy(info->name, sc_String, sizeof(info->name));
444
445 // Process optional tokens
446 while (SC_GetString()) {
447 if (SC_Compare("MAP")) { // Start next map definition
448 SC_UnGet();
449 break;
450 }
451
452 mcmdValue = MapCmdIDs[SC_MustMatchString(MapCmdNames)];
453 switch (mcmdValue) {
454 case MCMD_CLUSTER:
455 SC_MustGetNumber();
456 info->cluster = sc_Number;
457 break;
458 case MCMD_WARPTRANS:
459 SC_MustGetNumber();
460 info->warpTrans = sc_Number;
461 break;
462 case MCMD_NEXT:
463 SC_MustGetNumber();
464 info->nextMap = sc_Number;
465 break;
466 case MCMD_CDTRACK:
467 SC_MustGetNumber();
468 // not used
469 break;
470 case MCMD_SKY1:
471 SC_MustGetString();
472 info->sky1Texture = R_TextureNumForName(sc_String);
473 SC_MustGetNumber();
474 info->sky1ScrollDelta = sc_Number << 8;
475 break;
476 case MCMD_SKY2:
477 SC_MustGetString();
478 info->sky2Texture = R_TextureNumForName(sc_String);
479 SC_MustGetNumber();
480 info->sky2ScrollDelta = sc_Number << 8;
481 break;
482 case MCMD_DOUBLESKY:
483 info->doubleSky = true;
484 break;
485 case MCMD_LIGHTNING:
486 info->lightning = true;
487 break;
488 case MCMD_FADETABLE:
489 SC_MustGetString();
490 info->fadetable = W_GetNumForName(sc_String);
491 break;
492 case MCMD_CD_STARTTRACK:
493 case MCMD_CD_END1TRACK:
494 case MCMD_CD_END2TRACK:
495 case MCMD_CD_END3TRACK:
496 case MCMD_CD_INTERTRACK:
497 case MCMD_CD_TITLETRACK:
498 SC_MustGetNumber();
499 // not used
500 break;
501 }
502 }
503 mapMax = map > mapMax ? map : mapMax;
504 }
505
506 SC_Close();
507
508 MapCount = mapMax;
509 }
510
511 int dsda_HexenExitPic(const char** exit_pic) {
512 return false; // TODO
513 }
514
515 int dsda_HexenEnterPic(const char** enter_pic) {
516 return false; // TODO
517 }
518
519 int dsda_HexenBorderTexture(const char** border_texture) {
520 if (!hexen)
521 return false;
522
523 *border_texture = "F_022";
524
525 return true;
526 }
527
528 int dsda_HexenPrepareEntering(void) {
529 return false; // TODO
530 }
531
532 int dsda_HexenPrepareFinished(void) {
533 return false; // TODO
534 }
535
536 int dsda_HexenMapLightning(int* lightning) {
537 if (!hexen)
538 return false;
539
540 *lightning = CurrentMap->lightning;
541
542 return true;
543 }
544
545 int dsda_HexenApplyFadeTable(void) {
546 extern dboolean LevelUseFullBright;
547 extern const lighttable_t** colormaps;
548
549 int fade_lump;
550
551 if (!hexen)
552 return false;
553
554 fade_lump = CurrentMap->fadetable;
555
556 colormaps[0] = (const lighttable_t *) W_LumpByNum(fade_lump);
557
558 if (fade_lump == W_GetNumForName("COLORMAP"))
559 LevelUseFullBright = true;
560 else
561 LevelUseFullBright = false; // Probably fog ... don't use fullbright sprites
562
563 return true;
564 }
565
566 int dsda_HexenMapCluster(int* cluster, int map) {
567 if (!hexen)
568 return false;
569
570 *cluster = MapInfo[QualifyMap(map)].cluster;
571
572 return true;
573 }
574
575 int dsda_HexenSky1Texture(short* texture) {
576 if (!hexen)
577 return false;
578
579 *texture = CurrentMap->sky1Texture;
580
581 return true;
582 }
583
584 int dsda_HexenSky2Texture(short* texture) {
585 if (!hexen)
586 return false;
587
588 *texture = CurrentMap->sky2Texture;
589
590 return true;
591 }
592
593 int dsda_HexenGravity(fixed_t* gravity) {
594 return false;
595 }
596
597 int dsda_HexenAirControl(fixed_t* air_control) {
598 if (!hexen)
599 return false;
600
601 *air_control = (FRACUNIT >> 8);
602
603 return true;
604 }
605
606 int dsda_HexenInitSky(void) {
607 extern fixed_t Sky1ScrollDelta;
608 extern fixed_t Sky2ScrollDelta;
609
610 if (!hexen)
611 return false;
612
613 Sky1Texture = CurrentMap->sky1Texture;
614 Sky2Texture = CurrentMap->sky2Texture;
615 Sky1ScrollDelta = CurrentMap->sky1ScrollDelta;
616 Sky2ScrollDelta = CurrentMap->sky2ScrollDelta;
617 Sky1ColumnOffset = 0;
618 Sky2ColumnOffset = 0;
619 DoubleSky = CurrentMap->doubleSky;
620
621 return true;
622 }
623
624 int dsda_HexenMapFlags(map_info_flags_t* flags) {
625 if (!hexen)
626 return false;
627
628 *flags = MI_INTERMISSION |
629 MI_ACTIVATE_OWN_DEATH_SPECIALS |
630 MI_MISSILES_ACTIVATE_IMPACT_LINES |
631 MI_SHOW_AUTHOR;
632
633 return true;
634 }
635
636 int dsda_HexenMapColorMap(int* colormap) {
637 return false;
638 }