Debian Codegraph @

prboom2/src/dsda/mapinfo.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
16 //
17
18 #include <stdio.h>
19 #include <string.h>
20
21 #include "doomstat.h"
22 #include "m_misc.h"
23
24 #include "dsda/args.h"
25 #include "dsda/episode.h"
26 #include "dsda/map_format.h"
27 #include "dsda/mapinfo/doom.h"
28 #include "dsda/mapinfo/hexen.h"
29 #include "dsda/mapinfo/u.h"
30 #include "dsda/mapinfo/legacy.h"
31
32 #include "mapinfo.h"
33
34 map_info_t map_info;
35
36 int dsda_NameToMap(const char* name, int* episode, int* map) {
37 int found;
38
39 if (dsda_DoomNameToMap(&found, name, episode, map))
40 return found;
41
42 if (dsda_HexenNameToMap(&found, name, episode, map))
43 return found;
44
45 if (dsda_UNameToMap(&found, name, episode, map))
46 return found;
47
48 dsda_LegacyNameToMap(&found, name, episode, map);
49
50 return found;
51 }
52
53 void dsda_FirstMap(int* episode, int* map) {
54 if (dsda_DoomFirstMap(episode, map))
55 return;
56
57 if (dsda_HexenFirstMap(episode, map))
58 return;
59
60 if (dsda_UFirstMap(episode, map))
61 return;
62
63 dsda_LegacyFirstMap(episode, map);
64 }
65
66 void dsda_NewGameMap(int* episode, int* map) {
67 if (dsda_DoomNewGameMap(episode, map))
68 return;
69
70 if (dsda_HexenNewGameMap(episode, map))
71 return;
72
73 if (dsda_UNewGameMap(episode, map))
74 return;
75
76 dsda_LegacyNewGameMap(episode, map);
77 }
78
79 void dsda_ResolveWarp(int* args, int arg_count, int* episode, int* map) {
80 if (dsda_DoomResolveWarp(args, arg_count, episode, map))
81 return;
82
83 if (dsda_HexenResolveWarp(args, arg_count, episode, map))
84 return;
85
86 if (dsda_UResolveWarp(args, arg_count, episode, map))
87 return;
88
89 dsda_LegacyResolveWarp(args, arg_count, episode, map);
90 }
91
92 void dsda_NextMap(int* episode, int* map) {
93 if (dsda_DoomNextMap(episode, map))
94 return;
95
96 if (dsda_HexenNextMap(episode, map))
97 return;
98
99 if (dsda_UNextMap(episode, map))
100 return;
101
102 dsda_LegacyNextMap(episode, map);
103 }
104
105 void dsda_PrevMap(int* episode, int* map) {
106 if (dsda_DoomPrevMap(episode, map))
107 return;
108
109 if (dsda_HexenPrevMap(episode, map))
110 return;
111
112 if (dsda_UPrevMap(episode, map))
113 return;
114
115 dsda_LegacyPrevMap(episode, map);
116 }
117
118 void dsda_ShowNextLocBehaviour(int* behaviour) {
119 if (dsda_DoomShowNextLocBehaviour(behaviour))
120 return;
121
122 if (dsda_HexenShowNextLocBehaviour(behaviour))
123 return;
124
125 if (dsda_UShowNextLocBehaviour(behaviour))
126 return;
127
128 dsda_LegacyShowNextLocBehaviour(behaviour);
129 }
130
131 int dsda_SkipDrawShowNextLoc(void) {
132 int skip;
133
134 if (dsda_DoomSkipDrawShowNextLoc(&skip))
135 return skip;
136
137 if (dsda_HexenSkipDrawShowNextLoc(&skip))
138 return skip;
139
140 if (dsda_USkipDrawShowNextLoc(&skip))
141 return skip;
142
143 dsda_LegacySkipDrawShowNextLoc(&skip);
144
145 return skip;
146 }
147
148 static fixed_t dsda_Gravity(void) {
149 fixed_t gravity;
150
151 if (dsda_DoomGravity(&gravity))
152 return gravity;
153
154 if (dsda_HexenGravity(&gravity))
155 return gravity;
156
157 if (dsda_UGravity(&gravity))
158 return gravity;
159
160 dsda_LegacyGravity(&gravity);
161
162 return gravity;
163 }
164
165 static fixed_t dsda_AirControl(void) {
166 fixed_t air_control;
167
168 if (dsda_DoomAirControl(&air_control))
169 return air_control;
170
171 if (dsda_HexenAirControl(&air_control))
172 return air_control;
173
174 if (dsda_UAirControl(&air_control))
175 return air_control;
176
177 dsda_LegacyAirControl(&air_control);
178
179 return air_control;
180 }
181
182 static map_info_flags_t dsda_MapFlags(void) {
183 map_info_flags_t flags;
184
185 if (dsda_DoomMapFlags(&flags))
186 return flags;
187
188 if (dsda_HexenMapFlags(&flags))
189 return flags;
190
191 if (dsda_UMapFlags(&flags))
192 return flags;
193
194 dsda_LegacyMapFlags(&flags);
195
196 return flags;
197 }
198
199 static int dsda_MapColorMap(void) {
200 int colormap;
201
202 if (dsda_DoomMapColorMap(&colormap))
203 return colormap;
204
205 if (dsda_HexenMapColorMap(&colormap))
206 return colormap;
207
208 if (dsda_UMapColorMap(&colormap))
209 return colormap;
210
211 dsda_LegacyMapColorMap(&colormap);
212
213 return colormap;
214 }
215
216 static void dsda_UpdateMapInfo(void) {
217 dsda_DoomUpdateMapInfo();
218 dsda_HexenUpdateMapInfo();
219 dsda_UUpdateMapInfo();
220 dsda_LegacyUpdateMapInfo();
221
222 map_info.flags = dsda_MapFlags();
223 map_info.default_colormap = dsda_MapColorMap();
224 map_info.gravity = dsda_Gravity();
225 map_info.air_control = dsda_AirControl();
226 // This formula is based on 256 -> 65536 (no friction) and 65536 -> 0xe800 (normal friction)
227 map_info.air_friction = map_info.air_control > 256 ?
228 65560 - FixedMul(map_info.air_control, 6168) :
229 FRACUNIT;
230 }
231
232 void dsda_UpdateGameMap(int episode, int map) {
233 gameepisode = episode;
234 gamemap = map;
235 dsda_UpdateMapInfo();
236 }
237
238 void dsda_ResetAirControl(void) {
239 map_info.air_control = dsda_AirControl();
240 }
241
242 void dsda_ResetLeaveData(void) {
243 memset(&leave_data, 0, sizeof(leave_data));
244 }
245
246 void dsda_UpdateLeaveData(int map, int position, int flags, angle_t angle) {
247 leave_data.map = map;
248 leave_data.position = position;
249 leave_data.flags = flags;
250 leave_data.angle = angle;
251 }
252
253 dboolean dsda_FinaleShortcut(void) {
254 return map_format.zdoom && leave_data.map == LEAVE_VICTORY;
255 }
256
257 void dsda_UpdateLastMapInfo(void) {
258 dsda_DoomUpdateLastMapInfo();
259 dsda_HexenUpdateLastMapInfo();
260 dsda_UUpdateLastMapInfo();
261 dsda_LegacyUpdateLastMapInfo();
262 }
263
264 void dsda_UpdateNextMapInfo(void) {
265 dsda_DoomUpdateNextMapInfo();
266 dsda_HexenUpdateNextMapInfo();
267 dsda_UUpdateNextMapInfo();
268 dsda_LegacyUpdateNextMapInfo();
269 }
270
271 int dsda_ResolveCLEV(int* episode, int* map) {
272 int clev;
273
274 if (dsda_DoomResolveCLEV(&clev, episode, map))
275 return clev;
276
277 if (dsda_HexenResolveCLEV(&clev, episode, map))
278 return clev;
279
280 if (dsda_UResolveCLEV(&clev, episode, map))
281 return clev;
282
283 dsda_LegacyResolveCLEV(&clev, episode, map);
284
285 return clev;
286 }
287
288 int dsda_ResolveINIT(void) {
289 int init;
290
291 if (dsda_DoomResolveINIT(&init))
292 return init;
293
294 if (dsda_HexenResolveINIT(&init))
295 return init;
296
297 if (dsda_UResolveINIT(&init))
298 return init;
299
300 dsda_LegacyResolveINIT(&init);
301
302 return init;
303 }
304
305 int dsda_MusicIndexToLumpNum(int music_index) {
306 int lump;
307
308 if (dsda_DoomMusicIndexToLumpNum(&lump, music_index))
309 return lump;
310
311 if (dsda_HexenMusicIndexToLumpNum(&lump, music_index))
312 return lump;
313
314 if (dsda_UMusicIndexToLumpNum(&lump, music_index))
315 return lump;
316
317 dsda_LegacyMusicIndexToLumpNum(&lump, music_index);
318
319 return lump;
320 }
321
322 void dsda_MapMusic(int* music_index, int* music_lump, int episode, int map) {
323 if (dsda_DoomMapMusic(music_index, music_lump, episode, map))
324 return;
325
326 if (dsda_HexenMapMusic(music_index, music_lump, episode, map))
327 return;
328
329 if (dsda_UMapMusic(music_index, music_lump, episode, map))
330 return;
331
332 dsda_LegacyMapMusic(music_index, music_lump, episode, map);
333 }
334
335 void dsda_IntermissionMusic(int* music_index, int* music_lump) {
336 if (dsda_DoomIntermissionMusic(music_index, music_lump))
337 return;
338
339 if (dsda_HexenIntermissionMusic(music_index, music_lump))
340 return;
341
342 if (dsda_UIntermissionMusic(music_index, music_lump))
343 return;
344
345 dsda_LegacyIntermissionMusic(music_index, music_lump);
346 }
347
348 void dsda_InterMusic(int* music_index, int* music_lump) {
349 if (dsda_DoomInterMusic(music_index, music_lump))
350 return;
351
352 if (dsda_HexenInterMusic(music_index, music_lump))
353 return;
354
355 if (dsda_UInterMusic(music_index, music_lump))
356 return;
357
358 dsda_LegacyInterMusic(music_index, music_lump);
359 }
360
361 typedef enum {
362 finale_owner_legacy,
363 finale_owner_u,
364 finale_owner_hexen,
365 finale_owner_doom,
366 } finale_owner_t;
367
368 static finale_owner_t finale_owner = finale_owner_legacy;
369
370 void dsda_StartFinale(void) {
371 if (dsda_DoomStartFinale()) {
372 finale_owner = finale_owner_doom;
373 return;
374 }
375
376 if (dsda_HexenStartFinale()) {
377 finale_owner = finale_owner_hexen;
378 return;
379 }
380
381 if (dsda_UStartFinale()) {
382 finale_owner = finale_owner_u;
383 return;
384 }
385
386 dsda_LegacyStartFinale();
387 finale_owner = finale_owner_legacy;
388 }
389
390 int dsda_FTicker(void) {
391 if (finale_owner == finale_owner_doom) {
392 if (!dsda_DoomFTicker())
393 finale_owner = finale_owner_legacy;
394
395 return true;
396 }
397
398 if (finale_owner == finale_owner_hexen) {
399 if (!dsda_HexenFTicker())
400 finale_owner = finale_owner_legacy;
401
402 return true;
403 }
404
405 if (finale_owner == finale_owner_u) {
406 if (!dsda_UFTicker())
407 finale_owner = finale_owner_legacy;
408
409 return true;
410 }
411
412 dsda_LegacyFTicker();
413 return false;
414 }
415
416 int dsda_FDrawer(void) {
417 if (finale_owner == finale_owner_doom) {
418 dsda_DoomFDrawer();
419
420 return true;
421 }
422
423 if (finale_owner == finale_owner_hexen) {
424 dsda_HexenFDrawer();
425
426 return true;
427 }
428
429 if (finale_owner == finale_owner_u) {
430 dsda_UFDrawer();
431
432 return true;
433 }
434
435 dsda_LegacyFDrawer();
436 return false;
437 }
438
439 int dsda_BossAction(mobj_t* mo) {
440 if (dsda_DoomBossAction(mo))
441 return true;
442
443 if (dsda_HexenBossAction(mo))
444 return true;
445
446 if (dsda_UBossAction(mo))
447 return true;
448
449 dsda_LegacyBossAction(mo);
450 return false;
451 }
452
453 const char* dsda_MapLumpName(int episode, int map) {
454 const char* name;
455
456 if (dsda_DoomMapLumpName(&name, episode, map))
457 return name;
458
459 if (dsda_HexenMapLumpName(&name, episode, map))
460 return name;
461
462 if (dsda_UMapLumpName(&name, episode, map))
463 return name;
464
465 dsda_LegacyMapLumpName(&name, episode, map);
466
467 return name;
468 }
469
470 void dsda_HUTitle(dsda_string_t* str) {
471 if (dsda_DoomHUTitle(str))
472 return;
473
474 if (dsda_HexenHUTitle(str))
475 return;
476
477 if (dsda_UHUTitle(str))
478 return;
479
480 dsda_LegacyHUTitle(str);
481 }
482
483 const char* dsda_MapAuthor(void) {
484 const char* author;
485
486 if (dsda_DoomMapAuthor(&author))
487 return author;
488
489 if (dsda_HexenMapAuthor(&author))
490 return author;
491
492 if (dsda_UMapAuthor(&author))
493 return author;
494
495 dsda_LegacyMapAuthor(&author);
496
497 return author;
498 }
499
500 int dsda_SkyTexture(void) {
501 int sky;
502
503 if (dsda_DoomSkyTexture(&sky))
504 return sky;
505
506 if (dsda_HexenSkyTexture(&sky))
507 return sky;
508
509 if (dsda_USkyTexture(&sky))
510 return sky;
511
512 dsda_LegacySkyTexture(&sky);
513
514 return sky;
515 }
516
517 void dsda_PrepareInitNew(void) {
518 if (dsda_DoomPrepareInitNew())
519 return;
520
521 if (dsda_HexenPrepareInitNew())
522 return;
523
524 if (dsda_UPrepareInitNew())
525 return;
526
527 dsda_LegacyPrepareInitNew();
528 }
529
530 void dsda_PrepareIntermission(int* behaviour) {
531 if (dsda_DoomPrepareIntermission(behaviour))
532 return;
533
534 if (dsda_HexenPrepareIntermission(behaviour))
535 return;
536
537 if (dsda_UPrepareIntermission(behaviour))
538 return;
539
540 dsda_LegacyPrepareIntermission(behaviour);
541 }
542
543 void dsda_PrepareFinale(int* behaviour) {
544 if (dsda_DoomPrepareFinale(behaviour))
545 return;
546
547 if (dsda_HexenPrepareFinale(behaviour))
548 return;
549
550 if (dsda_UPrepareFinale(behaviour))
551 return;
552
553 dsda_LegacyPrepareFinale(behaviour);
554 }
555
556 void dsda_LoadMapInfo(void) {
557 dsda_AddOriginalEpisodes();
558
559 dsda_DoomLoadMapInfo();
560 dsda_HexenLoadMapInfo();
561 dsda_ULoadMapInfo();
562 dsda_LegacyLoadMapInfo();
563
564 dsda_AddCustomEpisodes();
565 }
566
567 const char* dsda_ExitPic(void) {
568 const char* exit_pic;
569
570 if (dsda_DoomExitPic(&exit_pic))
571 return exit_pic;
572
573 if (dsda_HexenExitPic(&exit_pic))
574 return exit_pic;
575
576 if (dsda_UExitPic(&exit_pic))
577 return exit_pic;
578
579 dsda_LegacyExitPic(&exit_pic);
580 return exit_pic;
581 }
582
583 const char* dsda_EnterPic(void) {
584 const char* enter_pic;
585
586 if (dsda_DoomEnterPic(&enter_pic))
587 return enter_pic;
588
589 if (dsda_HexenEnterPic(&enter_pic))
590 return enter_pic;
591
592 if (dsda_UEnterPic(&enter_pic))
593 return enter_pic;
594
595 dsda_LegacyEnterPic(&enter_pic);
596 return enter_pic;
597 }
598
599 const char* dsda_BorderTexture(void) {
600 const char* border_texture;
601
602 if (dsda_DoomBorderTexture(&border_texture))
603 return border_texture;
604
605 if (dsda_HexenBorderTexture(&border_texture))
606 return border_texture;
607
608 if (dsda_UBorderTexture(&border_texture))
609 return border_texture;
610
611 dsda_LegacyBorderTexture(&border_texture);
612 return border_texture;
613 }
614
615 void dsda_PrepareEntering(void) {
616 if (dsda_DoomPrepareEntering())
617 return;
618
619 if (dsda_HexenPrepareEntering())
620 return;
621
622 if (dsda_UPrepareEntering())
623 return;
624
625 dsda_LegacyPrepareEntering();
626 }
627
628 void dsda_PrepareFinished(void) {
629 if (dsda_DoomPrepareFinished())
630 return;
631
632 if (dsda_HexenPrepareFinished())
633 return;
634
635 if (dsda_UPrepareFinished())
636 return;
637
638 dsda_LegacyPrepareFinished();
639 }
640
641 int dsda_MapLightning(void) {
642 int lightning;
643
644 if (dsda_DoomMapLightning(&lightning))
645 return lightning;
646
647 if (dsda_HexenMapLightning(&lightning))
648 return lightning;
649
650 if (dsda_UMapLightning(&lightning))
651 return lightning;
652
653 dsda_LegacyMapLightning(&lightning);
654
655 return lightning;
656 }
657
658 void dsda_ApplyFadeTable(void) {
659 if (dsda_DoomApplyFadeTable())
660 return;
661
662 if (dsda_HexenApplyFadeTable())
663 return;
664
665 if (dsda_UApplyFadeTable())
666 return;
667
668 dsda_LegacyApplyFadeTable();
669 }
670
671 int dsda_MapCluster(int map) {
672 int cluster;
673
674 if (dsda_DoomMapCluster(&cluster, map))
675 return cluster;
676
677 if (dsda_HexenMapCluster(&cluster, map))
678 return cluster;
679
680 if (dsda_UMapCluster(&cluster, map))
681 return cluster;
682
683 dsda_LegacyMapCluster(&cluster, map);
684
685 return cluster;
686 }
687
688 short dsda_Sky1Texture(void) {
689 short texture;
690
691 if (dsda_DoomSky1Texture(&texture))
692 return texture;
693
694 if (dsda_HexenSky1Texture(&texture))
695 return texture;
696
697 if (dsda_USky1Texture(&texture))
698 return texture;
699
700 dsda_LegacySky1Texture(&texture);
701
702 return texture;
703 }
704
705 short dsda_Sky2Texture(void) {
706 short texture;
707
708 if (dsda_DoomSky2Texture(&texture))
709 return texture;
710
711 if (dsda_HexenSky2Texture(&texture))
712 return texture;
713
714 if (dsda_USky2Texture(&texture))
715 return texture;
716
717 dsda_LegacySky2Texture(&texture);
718
719 return texture;
720 }
721
722 void dsda_InitSky(void) {
723 if (dsda_DoomInitSky())
724 return;
725
726 if (dsda_HexenInitSky())
727 return;
728
729 if (dsda_UInitSky())
730 return;
731
732 dsda_LegacyInitSky();
733 }