Debian Codegraph @

prboom2/src/dsda/mapinfo/legacy.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 Legacy
16 //
17
18 #include "doomstat.h"
19 #include "g_game.h"
20 #include "m_misc.h"
21 #include "p_setup.h"
22 #include "r_data.h"
23 #include "s_sound.h"
24 #include "sounds.h"
25 #include "w_wad.h"
26
27 #include "dsda/map_format.h"
28 #include "dsda/mapinfo.h"
29
30 #include "legacy.h"
31
32 int dsda_LegacyNameToMap(int* found, const char* name, int* episode, int* map) {
33 char name_upper[9];
34 int episode_from_name = -1;
35 int map_from_name = -1;
36
37 if (strlen(name) > 8) {
38 *found = false;
39
40 return true;
41 }
42
43 strncpy(name_upper, name, 8);
44 name_upper[8] = 0;
45 M_Strupr(name_upper);
46
47 if (gamemode != commercial) {
48 if (sscanf(name_upper, "E%dM%d", &episode_from_name, &map_from_name) != 2) {
49 *found = false;
50
51 return true;
52 }
53 }
54 else {
55 if (sscanf(name_upper, "MAP%d", &map_from_name) != 1) {
56 *found = false;
57
58 return true;
59 }
60
61 episode_from_name = 1;
62 }
63
64 *found = true;
65
66 *episode = episode_from_name;
67 *map = map_from_name;
68
69 return true;
70 }
71
72 int dsda_LegacyFirstMap(int* episode, int* map) {
73 int i, j, lump;
74
75 *episode = 1;
76 *map = 1;
77
78 if (gamemode == commercial) {
79 for (i = 1; i < 33; i++) {
80 lump = W_CheckNumForName(VANILLA_MAP_LUMP_NAME(1, i));
81
82 if (lump != LUMP_NOT_FOUND && lumpinfo[lump].source == source_pwad) {
83 *map = i;
84
85 return true;
86 }
87 }
88 }
89 else
90 for (i = 1; i < 5; i++)
91 for (j = 1; j < 10; j++) {
92 lump = W_CheckNumForName(VANILLA_MAP_LUMP_NAME(i, j));
93
94 if (lump != LUMP_NOT_FOUND && lumpinfo[lump].source == source_pwad) {
95 *episode = i;
96 *map = j;
97
98 return true;
99 }
100 }
101
102 return true;
103 }
104
105 int dsda_LegacyNewGameMap(int* episode, int* map) {
106 return true;
107 }
108
109 int dsda_LegacyResolveWarp(int* args, int arg_count, int* episode, int* map) {
110 if (gamemode == commercial)
111 {
112 if (arg_count) {
113 *episode = 1;
114 *map = args[0];
115 }
116 }
117 else if (arg_count) {
118 *episode = args[0];
119
120 if (arg_count > 1)
121 *map = args[1];
122 else
123 *map = 1;
124 }
125
126 return true;
127 }
128
129 int dsda_LegacyNextMap(int* episode, int* map) {
130 static byte doom2_next[33] = {
131 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
132 12, 13, 14, 15, 31, 17, 18, 19, 20, 21,
133 22, 23, 24, 25, 26, 27, 28, 29, 30, 1,
134 32, 16, 3
135 };
136 static byte doom_next[4][9] = {
137 { 12, 13, 19, 15, 16, 17, 18, 21, 14 },
138 { 22, 23, 24, 25, 29, 27, 28, 31, 26 },
139 { 32, 33, 34, 35, 36, 39, 38, 41, 37 },
140 { 42, 49, 44, 45, 46, 47, 48, 11, 43 }
141 };
142 static byte heretic_next[6][9] = {
143 { 12, 13, 14, 15, 16, 19, 18, 21, 17 },
144 { 22, 23, 24, 29, 26, 27, 28, 31, 25 },
145 { 32, 33, 34, 39, 36, 37, 38, 41, 35 },
146 { 42, 43, 44, 49, 46, 47, 48, 51, 45 },
147 { 52, 53, 59, 55, 56, 57, 58, 61, 54 },
148 { 62, 63, 11, 11, 11, 11, 11, 11, 11 }, // E6M4-E6M9 shouldn't be accessible
149 };
150
151 // next arrays are 0-based, unlike gameepisode and gamemap
152 *episode = gameepisode - 1;
153 *map = gamemap - 1;
154
155 if (heretic) {
156 int next;
157
158 if (gamemode == shareware)
159 heretic_next[0][7] = 11;
160
161 if (gamemode == registered)
162 heretic_next[2][7] = 11;
163
164 next = heretic_next[BETWEEN(0, 5, *episode)][BETWEEN(0, 8, *map)];
165 *episode = next / 10;
166 *map = next % 10;
167 }
168 else if (gamemode == commercial) {
169 // secret level
170 doom2_next[14] = (haswolflevels ? 31 : 16);
171
172 if (bfgedition && allow_incompatibility) {
173 if (gamemission == pack_nerve) {
174 doom2_next[3] = 9;
175 doom2_next[7] = 1;
176 doom2_next[8] = 5;
177 }
178 else
179 doom2_next[1] = 33;
180 }
181
182 *episode = 1;
183 *map = doom2_next[BETWEEN(0, 32, *map)];
184 }
185 else {
186 int next;
187
188 // shareware doom has only episode 1
189 doom_next[0][7] = (gamemode == shareware ? 11 : 21);
190
191 doom_next[2][7] = // the fourth episode for pre-ultimate complevels is not allowed
192 ((gamemode == registered) || (compatibility_level < ultdoom_compatibility) ? 11 : 41);
193
194 next = doom_next[BETWEEN(0, 3, *episode)][BETWEEN(0, 9, *map)];
195 *episode = next / 10;
196 *map = next % 10;
197 }
198
199 return true;
200 }
201
202 int dsda_LegacyPrevMap(int* episode, int* map) {
203 static byte doom2_prev[33] = {
204 1, 1, 2, 3, 4, 5, 6, 7, 8, 9,
205 10, 11, 12, 13, 14, 32, 16, 17, 18, 19,
206 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
207 15, 31, 2
208 };
209 static byte doom_prev[4][9] = {
210 { 11, 11, 12, 19, 14, 15, 16, 17, 13 },
211 { 18, 21, 22, 23, 24, 29, 26, 27, 25 },
212 { 28, 31, 32, 33, 34, 35, 39, 37, 36 },
213 { 38, 41, 49, 43, 44, 45, 46, 47, 42 }
214 };
215 static byte heretic_prev[6][9] = {
216 { 11, 11, 12, 13, 14, 15, 19, 17, 16 },
217 { 18, 21, 22, 23, 29, 25, 26, 27, 24 },
218 { 28, 31, 32, 33, 39, 35, 36, 37, 34 },
219 { 38, 41, 42, 43, 49, 45, 46, 47, 44 },
220 { 48, 51, 52, 59, 54, 55, 56, 57, 53 },
221 { 58, 61, 62, 63, 63, 63, 63, 63, 63 }, // E6M4-E6M9 shouldn't be accessible
222 };
223
224 // next arrays are 0-based, unlike gameepisode and gamemap
225 *episode = gameepisode - 1;
226 *map = gamemap - 1;
227
228 if (heretic) {
229 int prev;
230
231 prev = heretic_prev[BETWEEN(0, 5, *episode)][BETWEEN(0, 8, *map)];
232 *episode = prev / 10;
233 *map = prev % 10;
234 }
235 else if (gamemode == commercial) {
236 // secret level
237 doom2_prev[15] = (haswolflevels ? 32 : 15);
238
239 if (bfgedition && allow_incompatibility) {
240 if (gamemission == pack_nerve) {
241 doom2_prev[4] = 9;
242 doom2_prev[8] = 4;
243 }
244 else
245 doom2_prev[2] = 33;
246 }
247
248 *episode = 1;
249 *map = doom2_prev[BETWEEN(0, 32, *map)];
250 }
251 else {
252 int prev;
253
254 prev = doom_prev[BETWEEN(0, 3, *episode)][BETWEEN(0, 9, *map)];
255 *episode = prev / 10;
256 *map = prev % 10;
257 }
258
259 return true;
260 }
261
262 int dsda_LegacyShowNextLocBehaviour(int* behaviour) {
263 if (
264 gamemode != commercial &&
265 (gamemap == 8 || (gamemission == tc_chex && gamemap == 5))
266 )
267 *behaviour = WI_SHOW_NEXT_DONE;
268 else
269 *behaviour = WI_SHOW_NEXT_LOC;
270
271 if (dsda_FinaleShortcut())
272 *behaviour = WI_SHOW_NEXT_DONE;
273
274 return true;
275 }
276
277 int dsda_LegacySkipDrawShowNextLoc(int* skip) {
278 *skip = false;
279
280 if (dsda_FinaleShortcut())
281 *skip = true;
282
283 return true;
284 }
285
286 void dsda_LegacyUpdateMapInfo(void) {
287 // nothing to do right now
288 }
289
290 void dsda_LegacyUpdateLastMapInfo(void) {
291 // nothing to do right now
292 }
293
294 void dsda_LegacyUpdateNextMapInfo(void) {
295 // nothing to do right now
296 }
297
298 static int dsda_CannotCLEV(int episode, int map) {
299 char* next;
300
301 if (
302 episode < 1 ||
303 map < 0 ||
304 ((gamemode == retail || gamemode == registered) && (episode > 9 || map > 9)) ||
305 (gamemode == shareware && (episode > 1 || map > 9)) ||
306 (gamemode == commercial && (episode > 1 || map > 99)) ||
307 (gamemission == pack_nerve && map > 9)
308 ) return true;
309
310 // Catch invalid maps
311 next = VANILLA_MAP_LUMP_NAME(episode, map);
312 if (!W_LumpNameExists(next)) {
313 doom_printf("IDCLEV target not found: %s", next);
314 return true;
315 }
316
317 return false;
318 }
319
320 int dsda_LegacyResolveCLEV(int* clev, int* episode, int* map) {
321 if (dsda_CannotCLEV(*episode, *map))
322 *clev = false;
323 else {
324 if (gamemission == tc_chex)
325 *episode = 1;
326
327 *clev = true;
328 }
329
330 return true;
331 }
332
333 int dsda_LegacyResolveINIT(int* init) {
334 *init = false;
335
336 return true;
337 }
338
339 int dsda_LegacyMusicIndexToLumpNum(int* lump, int music_index) {
340 char name[9];
341 const char* format;
342
343 format = raven ? "%s" : "d_%s";
344
345 snprintf(name, sizeof(name), format, S_music[music_index].name);
346
347 *lump = W_GetNumForName(name);
348
349 return true;
350 }
351
352 static inline int WRAP(int i, int w)
353 {
354 while (i < 0)
355 i += w;
356
357 return i % w;
358 }
359
360 int dsda_LegacyMapMusic(int* music_index, int* music_lump, int episode, int map) {
361 *music_lump = -1;
362
363 if (idmusnum != -1)
364 *music_index = idmusnum; //jff 3/17/98 reload IDMUS music if not -1
365 else {
366 if (gamemode == commercial)
367 *music_index = mus_runnin + WRAP(map - 1, DOOM_MUSINFO - mus_runnin);
368 else {
369 static const int spmus[] = {
370 mus_e3m4,
371 mus_e3m2,
372 mus_e3m3,
373 mus_e1m5,
374 mus_e2m7,
375 mus_e2m4,
376 mus_e2m6,
377 mus_e2m5,
378 mus_e1m9
379 };
380
381 if (heretic)
382 *music_index = heretic_mus_e1m1 +
383 WRAP((episode - 1) * 9 + map - 1,
384 HERETIC_NUMMUSIC - heretic_mus_e1m1);
385 else if (episode < 4)
386 *music_index = mus_e1m1 +
387 WRAP((episode - 1) * 9 + map - 1, mus_runnin - mus_e1m1);
388 else
389 *music_index = spmus[WRAP(map - 1, 9)];
390 }
391 }
392
393 return true;
394 }
395
396 int dsda_LegacyIntermissionMusic(int* music_index, int* music_lump) {
397 *music_lump = -1;
398
399 if (gamemode == commercial)
400 *music_index = mus_dm2int;
401 else
402 *music_index = mus_inter;
403
404 return true;
405 }
406
407 int dsda_LegacyInterMusic(int* music_index, int* music_lump) {
408 *music_lump = -1;
409
410 switch (gamemode) {
411 case shareware:
412 case registered:
413 case retail:
414 *music_index = mus_victor;
415 break;
416 default:
417 *music_index = mus_read_m;
418 break;
419 }
420
421 return true;
422 }
423
424 int dsda_LegacyStartFinale(void) {
425 return true;
426 }
427
428 int dsda_LegacyFTicker(void) {
429 return true;
430 }
431
432 void dsda_LegacyFDrawer(void) {
433 return;
434 }
435
436 int dsda_LegacyBossAction(mobj_t* mo) {
437 return false;
438 }
439
440 int dsda_LegacyMapLumpName(const char** name, int episode, int map) {
441 *name = VANILLA_MAP_LUMP_NAME(episode, map);
442
443 return true;
444 }
445
446 int dsda_LegacyMapAuthor(const char** author) {
447 *author = NULL;
448
449 return true;
450 }
451
452 int dsda_LegacyHUTitle(dsda_string_t* str) {
453 extern char** mapnames[];
454 extern char** mapnames2[];
455 extern char** mapnamesp[];
456 extern char** mapnamest[];
457 extern const char* LevelNames[];
458
459 dsda_InitString(str, NULL);
460
461 if (gamestate == GS_LEVEL && gamemap > 0 && gameepisode > 0) {
462 if (heretic) {
463 if (gameepisode < 6 && gamemap < 10)
464 dsda_StringCat(str, LevelNames[(gameepisode - 1) * 9 + gamemap - 1]);
465 }
466 else {
467 switch (gamemode) {
468 case shareware:
469 case registered:
470 case retail:
471 // Chex.exe always uses the episode 1 level title
472 // eg. E2M1 gives the title for E1M1
473 if (gamemission == tc_chex && gamemap < 10)
474 dsda_StringCat(str, *mapnames[gamemap - 1]);
475 else if (gameepisode < 6 && gamemap < 10)
476 dsda_StringCat(str, *mapnames[(gameepisode - 1) * 9 + gamemap - 1]);
477 break;
478
479 default: // Ty 08/27/98 - modified to check mission for TNT/Plutonia
480 if (gamemission == pack_tnt && gamemap < 33)
481 dsda_StringCat(str, *mapnamest[gamemap - 1]);
482 else if (gamemission == pack_plut && gamemap < 33)
483 dsda_StringCat(str, *mapnamesp[gamemap - 1]);
484 else if (gamemap < 34)
485 dsda_StringCat(str, *mapnames2[gamemap - 1]);
486 break;
487 }
488 }
489 }
490
491 if (!str->string)
492 dsda_StringCat(str, VANILLA_MAP_LUMP_NAME(gameepisode, gamemap));
493
494 return true;
495 }
496
497 int dsda_LegacySkyTexture(int* sky) {
498 if (map_format.doublesky)
499 *sky = Sky1Texture;
500 else if (heretic) {
501 static const char *sky_lump_names[5] = {
502 "SKY1", "SKY2", "SKY3", "SKY1", "SKY3"
503 };
504
505 if (gameepisode < 6)
506 *sky = R_TextureNumForName(sky_lump_names[gameepisode - 1]);
507 else
508 *sky = R_TextureNumForName("SKY1");
509 }
510 else if (gamemode == commercial) {
511 *sky = R_TextureNumForName ("SKY3");
512 if (gamemap < 12)
513 *sky = R_TextureNumForName ("SKY1");
514 else
515 if (gamemap < 21)
516 *sky = R_TextureNumForName ("SKY2");
517 }
518 else {
519 switch (gameepisode) {
520 case 1:
521 *sky = R_TextureNumForName ("SKY1");
522 break;
523 case 2:
524 *sky = R_TextureNumForName ("SKY2");
525 break;
526 case 3:
527 *sky = R_TextureNumForName ("SKY3");
528 break;
529 case 4: // Special Edition sky
530 *sky = R_TextureNumForName ("SKY4");
531 break;
532 default:
533 *sky = R_TextureNumForName ("SKY1");
534 break;
535 }
536 }
537
538 return true;
539 }
540
541 int dsda_LegacyPrepareInitNew(void) {
542 return true;
543 }
544
545 void dsda_LegacyParTime(int* partime, dboolean* modified) {
546 extern int deh_pars;
547
548 if (gamemode == commercial) {
549 if (gamemap >= 1 && gamemap <= 34) {
550 *partime = TICRATE * cpars[gamemap - 1];
551 *modified = deh_pars;
552 }
553 }
554 else {
555 if (gameepisode >= 1 && gameepisode <= 4 && gamemap >= 1 && gamemap <= 9) {
556 *partime = TICRATE * pars[gameepisode][gamemap];
557 *modified = deh_pars;
558 }
559 }
560 }
561
562 int dsda_LegacyPrepareIntermission(int* result) {
563 if (gamemode != commercial)
564 if (gamemap == 9) {
565 int i;
566
567 for (i = 0; i < g_maxplayers; i++)
568 players[i].didsecret = true;
569 }
570
571 wminfo.didsecret = players[consoleplayer].didsecret;
572
573 // wminfo.next is 0 biased, unlike gamemap
574 if (gamemode == commercial) {
575 if (secretexit)
576 switch(gamemap) {
577 case 15:
578 wminfo.next = 30;
579 break;
580 case 31:
581 wminfo.next = 31;
582 break;
583 case 2:
584 if (bfgedition && allow_incompatibility)
585 wminfo.next = 32;
586 break;
587 case 4:
588 if (gamemission == pack_nerve && allow_incompatibility)
589 wminfo.next = 8;
590 break;
591 }
592 else
593 switch(gamemap) {
594 case 31:
595 case 32:
596 wminfo.next = 15;
597 break;
598 case 33:
599 if (bfgedition && allow_incompatibility)
600 {
601 wminfo.next = 2;
602 break;
603 }
604 // fallthrough
605 default:
606 wminfo.next = gamemap;
607 }
608
609 if (gamemission == pack_nerve && allow_incompatibility && gamemap == 9)
610 wminfo.next = 4;
611 }
612 else {
613 if (secretexit)
614 wminfo.next = 8; // go to secret level
615 else if (gamemap == 9) {
616 // returning from secret level
617 if (heretic)
618 {
619 static int after_secret[5] = { 6, 4, 4, 4, 3 };
620 wminfo.next = after_secret[gameepisode - 1];
621 }
622 else
623 switch (gameepisode) {
624 case 1:
625 wminfo.next = 3;
626 break;
627 case 2:
628 wminfo.next = 5;
629 break;
630 case 3:
631 wminfo.next = 6;
632 break;
633 case 4:
634 wminfo.next = 2;
635 break;
636 }
637 }
638 else
639 wminfo.next = gamemap; // go to next level
640 }
641
642 dsda_LegacyParTime(&wminfo.partime, &wminfo.modified_partime);
643
644 if (map_format.zdoom)
645 if (leave_data.map > 0)
646 wminfo.next = leave_data.map - 1;
647
648 *result = 0;
649
650 return true;
651 }
652
653 int dsda_LegacyPrepareFinale(int* result) {
654 *result = 0;
655
656 if (gamemode == commercial && gamemission != pack_nerve) {
657 switch (gamemap) {
658 case 15:
659 case 31:
660 if (!secretexit)
661 break;
662 // fallthrough
663 case 6:
664 case 11:
665 case 20:
666 case 30:
667 *result = WD_START_FINALE;
668 break;
669 }
670 }
671 else if (gamemission == pack_nerve && allow_incompatibility && gamemap == 8)
672 *result = WD_START_FINALE;
673 else if (gamemap == 8)
674 *result = WD_VICTORY;
675 else if (gamemap == 5 && gamemission == tc_chex)
676 *result = WD_VICTORY;
677
678 if (dsda_FinaleShortcut())
679 *result = WD_START_FINALE;
680
681 return true;
682 }
683
684 void dsda_LegacyLoadMapInfo(void) {
685 return;
686 }
687
688 int dsda_LegacyExitPic(const char** exit_pic) {
689 *exit_pic = NULL;
690
691 return true;
692 }
693
694 int dsda_LegacyEnterPic(const char** enter_pic) {
695 *enter_pic = NULL;
696
697 return true;
698 }
699
700 int dsda_LegacyBorderTexture(const char** border_texture) {
701 *border_texture = heretic ? "FLOOR30" :
702 gamemode == commercial ? "GRNROCK" : "FLOOR7_2";
703
704 return true;
705 }
706
707 int dsda_LegacyPrepareEntering(void) {
708 extern const char *el_levelname;
709 extern const char *el_levelpic;
710 extern const char *el_author;
711
712 el_levelname = NULL;
713 el_levelpic = NULL;
714 el_author = NULL;
715
716 return true;
717 }
718
719 int dsda_LegacyPrepareFinished(void) {
720 extern const char *lf_levelname;
721 extern const char *lf_levelpic;
722 extern const char *lf_author;
723
724 lf_levelname = NULL;
725 lf_levelpic = NULL;
726 lf_author = NULL;
727
728 return true;
729 }
730
731 int dsda_LegacyMapLightning(int* lightning) {
732 *lightning = false;
733
734 return true;
735 }
736
737 int dsda_LegacyApplyFadeTable(void) {
738 return true;
739 }
740
741 int dsda_LegacyMapCluster(int* cluster, int map) {
742 *cluster = -1;
743
744 return true;
745 }
746
747 int dsda_LegacySky1Texture(short* texture) {
748 *texture = -1;
749
750 return true;
751 }
752
753 int dsda_LegacySky2Texture(short* texture) {
754 *texture = -1;
755
756 return true;
757 }
758
759 int dsda_LegacyGravity(fixed_t* gravity) {
760 *gravity = FRACUNIT;
761
762 return true;
763 }
764
765 int dsda_LegacyAirControl(fixed_t* air_control) {
766 dboolean dsda_AllowJumping(void);
767
768 *air_control = dsda_AllowJumping() ? (FRACUNIT >> 8) : 0;
769
770 return true;
771 }
772
773 int dsda_LegacyInitSky(void) {
774 return true;
775 }
776
777 int dsda_LegacyMapFlags(map_info_flags_t* flags) {
778 *flags = MI_INTERMISSION |
779 MI_ACTIVATE_OWN_DEATH_SPECIALS |
780 MI_LAX_MONSTER_ACTIVATION |
781 MI_MISSILES_ACTIVATE_IMPACT_LINES |
782 MI_SHOW_AUTHOR;
783
784 return true;
785 }
786
787 int dsda_LegacyMapColorMap(int* colormap) {
788 *colormap = 0;
789
790 return true;
791 }