Debian Codegraph @

prboom2/src/dsda/mapinfo/u.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 U
16 //
17
18 #include "doomstat.h"
19 #include "f_finale.h"
20 #include "g_game.h"
21 #include "lprintf.h"
22 #include "p_enemy.h"
23 #include "p_spec.h"
24 #include "p_tick.h"
25 #include "r_state.h"
26 #include "s_sound.h"
27 #include "sounds.h"
28 #include "umapinfo.h"
29 #include "v_video.h"
30 #include "w_wad.h"
31
32 #include "dsda/args.h"
33 #include "dsda/global.h"
34 #include "dsda/map_format.h"
35 #include "dsda/mapinfo.h"
36 #include "dsda/preferences.h"
37
38 #include "u.h"
39
40 static struct MapEntry* gamemapinfo;
41 static struct MapEntry* lastmapinfo;
42 static struct MapEntry* nextmapinfo;
43
44 static struct MapEntry* dsda_UMapEntry(int gameepisode, int gamemap)
45 {
46 char lumpname[9];
47 unsigned i;
48
49 snprintf(lumpname, sizeof(lumpname), "%s", VANILLA_MAP_LUMP_NAME(gameepisode, gamemap));
50
51 for (i = 0; i < Maps.mapcount; i++)
52 if (!stricmp(lumpname, Maps.maps[i].mapname))
53 return &Maps.maps[i];
54
55 return NULL;
56 }
57
58 int dsda_UNameToMap(int* found, const char* name, int* episode, int* map) {
59 return false;
60 }
61
62 int dsda_UFirstMap(int* episode, int* map) {
63 return false;
64 }
65
66 int dsda_UNewGameMap(int* episode, int* map) {
67 return false;
68 }
69
70 int dsda_UResolveWarp(int* args, int arg_count, int* episode, int* map) {
71 return false;
72 }
73
74 int dsda_UNextMap(int* episode, int* map) {
75 const char *name = NULL;
76
77 if (!gamemapinfo)
78 return false;
79
80 if (gamemapinfo->nextsecret[0])
81 name = gamemapinfo->nextsecret;
82 else if (gamemapinfo->nextmap[0])
83 name = gamemapinfo->nextmap;
84 else if (gamemapinfo->endpic[0] && gamemapinfo->endpic[0] != '-')
85 {
86 *episode = 1;
87 *map = 1;
88
89 return true;
90 }
91
92 if (name)
93 return dsda_NameToMap(name, episode, map);
94
95 return false;
96 }
97
98 int dsda_UPrevMap(int* episode, int* map) {
99 int i;
100
101 if (!gamemapinfo)
102 return false;
103
104 for (i = 0; i < Maps.mapcount; ++i)
105 if (
106 Maps.maps[i].nextsecret[0] &&
107 !stricmp(Maps.maps[i].nextsecret, gamemapinfo->mapname)
108 )
109 return dsda_NameToMap(Maps.maps[i].mapname, episode, map);
110
111 for (i = 0; i < Maps.mapcount; ++i)
112 if (
113 Maps.maps[i].nextmap[0] &&
114 !stricmp(Maps.maps[i].nextmap, gamemapinfo->mapname)
115 )
116 return dsda_NameToMap(Maps.maps[i].mapname, episode, map);
117
118 return dsda_NameToMap(gamemapinfo->mapname, episode, map);
119 }
120
121 int dsda_UShowNextLocBehaviour(int* behaviour) {
122 if (!gamemapinfo)
123 return false;
124
125 if (gamemapinfo->endpic[0])
126 *behaviour = WI_SHOW_NEXT_DONE;
127 else
128 *behaviour = WI_SHOW_NEXT_LOC | WI_SHOW_NEXT_EPISODAL;
129
130 return true;
131 }
132
133 int dsda_USkipDrawShowNextLoc(int* skip) {
134 if (!gamemapinfo)
135 return false;
136
137 *skip = (gamemapinfo->endpic[0] && strcmp(gamemapinfo->endpic, "-") != 0);
138
139 return true;
140 }
141
142 void dsda_UUpdateMapInfo(void) {
143 gamemapinfo = dsda_UMapEntry(gameepisode, gamemap);
144 }
145
146 void dsda_UUpdateLastMapInfo(void) {
147 lastmapinfo = gamemapinfo;
148 nextmapinfo = NULL;
149 }
150
151 void dsda_UUpdateNextMapInfo(void) {
152 nextmapinfo = dsda_UMapEntry(wminfo.nextep + 1, wminfo.next + 1);
153 }
154
155 int dsda_UResolveCLEV(int* clev, int* episode, int* map) {
156 if (dsda_UMapEntry(*episode, *map)) {
157 *clev = true;
158
159 return true;
160 }
161
162 return false;
163 }
164
165 int dsda_UResolveINIT(int* init) {
166 return false;
167 }
168
169 int dsda_UMusicIndexToLumpNum(int* lump, int music_index) {
170 return false;
171 }
172
173 int dsda_UMapMusic(int* music_index, int* music_lump, int episode, int map) {
174 int lump;
175 struct MapEntry* entry = dsda_UMapEntry(episode, map);
176
177 if (!entry || !entry->music[0])
178 return false;
179
180 lump = W_CheckNumForName(entry->music);
181
182 if (lump == LUMP_NOT_FOUND)
183 return false;
184
185 *music_index = -1;
186 *music_lump = lump;
187
188 return true;
189 }
190
191 int dsda_UIntermissionMusic(int* music_index, int* music_lump) {
192 return false;
193 }
194
195 int dsda_UInterMusic(int* music_index, int* music_lump) {
196 int lump;
197
198 if (!gamemapinfo)
199 return false;
200
201 if (!gamemapinfo->intermusic[0])
202 return false;
203
204 lump = W_CheckNumForName(gamemapinfo->intermusic);
205
206 if (lump == LUMP_NOT_FOUND)
207 return false;
208
209 *music_index = -1;
210 *music_lump = lump;
211
212 return true;
213 }
214
215 extern int finalestage;
216 extern int finalecount;
217 extern const char* finaletext;
218 extern const char* finaleflat;
219 extern const char* finalepatch;
220 extern int acceleratestage;
221 extern int midstage;
222
223 int dsda_UStartFinale(void) {
224 if (!gamemapinfo)
225 return false;
226
227 // '-' means that any default intermission was cleared.
228 if (gamemapinfo->intertextsecret && secretexit && gamemapinfo->intertextsecret[0] != '-')
229 finaletext = gamemapinfo->intertextsecret;
230 else if (gamemapinfo->intertext && !secretexit && gamemapinfo->intertext[0] != '-')
231 finaletext = gamemapinfo->intertext;
232
233 // this is to avoid a crash on a missing text in the last map.
234 if (!finaletext)
235 finaletext = "The End";
236
237 if (gamemapinfo->interbackdrop[0]) {
238 if (W_LumpNameExists(gamemapinfo->interbackdrop) &&
239 !W_LumpNameExists2(gamemapinfo->interbackdrop, ns_flats))
240 finalepatch = gamemapinfo->interbackdrop;
241 else
242 finaleflat = gamemapinfo->interbackdrop;
243 }
244
245 if (!finaleflat)
246 finaleflat = "FLOOR4_8"; // use a single fallback for all maps.
247
248 return true;
249 }
250
251 int dsda_UFTicker(void) {
252 void WI_checkForAccelerate(void);
253 float Get_TextSpeed(void);
254
255 int next_level = false;
256 const int TEXTSPEED = 3;
257 const int TEXTWAIT = 250;
258 const int NEWTEXTWAIT = 1000;
259
260 if (!demo_compatibility || allow_incompatibility)
261 WI_checkForAccelerate();
262 else {
263 int i;
264
265 for (i = 0; i < g_maxplayers; i++)
266 if (players[i].cmd.buttons)
267 next_level = true;
268 }
269
270 if (!next_level) {
271 // advance animation
272 finalecount++;
273
274 if (!finalestage) {
275 float speed = demo_compatibility ? TEXTSPEED : Get_TextSpeed();
276
277 if (
278 finalecount > strlen(finaletext) * speed + (midstage ? NEWTEXTWAIT : TEXTWAIT) ||
279 (midstage && acceleratestage)
280 )
281 next_level = true;
282 }
283 }
284
285 if (next_level) {
286 if (gamemapinfo->endpic[0] && (strcmp(gamemapinfo->endpic, "-") != 0)) {
287 if (!stricmp(gamemapinfo->endpic, "$CAST")) {
288 F_StartCast(NULL, NULL, true);
289 return false; // let go of finale ownership
290 }
291 else {
292 finalecount = 0;
293 finalestage = 1;
294 wipegamestate = -1; // force a wipe
295 if (!stricmp(gamemapinfo->endpic, "$BUNNY"))
296 F_StartScroll(NULL, NULL, NULL, true);
297 else if (!stricmp(gamemapinfo->endpic, "!"))
298 return false; // let go of finale ownership
299 }
300 }
301 else
302 gameaction = ga_worlddone; // next level, e.g. MAP07
303 }
304
305 return true; // keep finale ownership
306 }
307
308 void dsda_UFDrawer(void) {
309 void F_TextWrite(void);
310 void F_BunnyScroll(void);
311
312 if (!finalestage || !gamemapinfo->endpic[0] || (strcmp(gamemapinfo->endpic, "-") == 0))
313 F_TextWrite();
314 else if (strcmp(gamemapinfo->endpic, "$BUNNY") == 0)
315 F_BunnyScroll();
316 else {
317 // e6y: wide-res
318 V_ClearBorder();
319 V_DrawNamePatchFS(0, 0, 0, gamemapinfo->endpic, CR_DEFAULT, VPT_STRETCH);
320 }
321 }
322
323 // numbossactions == 0 means to use the defaults.
324 // numbossactions == -1 means to do nothing.
325 // positive values mean to check the list of boss actions and run all that apply.
326 int dsda_UBossAction(mobj_t* mo) {
327 int i;
328 line_t junk;
329
330 if (!gamemapinfo || !gamemapinfo->numbossactions)
331 return false;
332
333 if (gamemapinfo->numbossactions < 0)
334 return true;
335
336 for (i = 0; i < gamemapinfo->numbossactions; i++)
337 if (gamemapinfo->bossactions[i].type == mo->type)
338 break;
339
340 if (i >= gamemapinfo->numbossactions)
341 return true; // no matches found
342
343 if (!P_CheckBossDeath(mo))
344 return true;
345
346 if (map_format.zdoom)
347 I_Error("UMAPINFO boss actions are incompatible with this map format (use MAPINFO)");
348
349 for (i = 0; i < gamemapinfo->numbossactions; i++) {
350 if (gamemapinfo->bossactions[i].type == mo->type) {
351 junk = *lines;
352 junk.special = (short) gamemapinfo->bossactions[i].special;
353 junk.tag = (short) gamemapinfo->bossactions[i].tag;
354
355 // use special semantics for line activation to block problem types.
356 if (!P_UseSpecialLine(mo, &junk, 0, true))
357 map_format.cross_special_line(&junk, 0, mo, true);
358 }
359 }
360
361 return true;
362 }
363
364 int dsda_UMapLumpName(const char** name, int episode, int map) {
365 return false;
366 }
367
368 int dsda_UMapAuthor(const char** author) {
369 if (!gamemapinfo)
370 return false;
371
372 *author = gamemapinfo->author;
373
374 return true;
375 }
376
377 int dsda_UHUTitle(dsda_string_t* str) {
378 const char* s;
379
380 if (!gamemapinfo || !gamemapinfo->levelname)
381 return false;
382
383 if (gamemapinfo->label)
384 s = gamemapinfo->label;
385 else
386 s = gamemapinfo->mapname;
387
388 if (s == gamemapinfo->mapname || strcmp(s, "-") != 0)
389 dsda_StringPrintF(str, "%s: %s",s, gamemapinfo->levelname);
390 else
391 dsda_StringPrintF(str, "%s", gamemapinfo->levelname);
392
393 return true;
394 }
395
396 int dsda_USkyTexture(int* sky) {
397 if (!gamemapinfo || !gamemapinfo->skytexture[0])
398 return false;
399
400 *sky = R_TextureNumForName(gamemapinfo->skytexture);
401
402 return true;
403 }
404
405 int dsda_UPrepareInitNew(void) {
406 return false;
407 }
408 int dsda_UPrepareIntermission(int* result) {
409 const char *next = "";
410
411 if (!gamemapinfo)
412 return false;
413
414 if (
415 gamemapinfo->endpic[0] &&
416 strcmp(gamemapinfo->endpic, "-") != 0 &&
417 gamemapinfo->nointermission
418 ) {
419 *result = DC_VICTORY;
420
421 return true;
422 }
423
424 wminfo.partime = gamemapinfo->partime;
425 wminfo.modified_partime = true;
426
427 if (!wminfo.partime) {
428 extern void dsda_LegacyParTime(int* partime, dboolean* modified);
429
430 dsda_LegacyParTime(&wminfo.fake_partime, &wminfo.modified_partime);
431 }
432
433 if (map_format.zdoom && leave_data.map > 0)
434 I_Error("UMAPINFO maps are incompatible with this exit (use MAPINFO)");
435
436 if (secretexit)
437 next = gamemapinfo->nextsecret;
438
439 if (next[0] == 0)
440 next = gamemapinfo->nextmap;
441
442 if (next[0]) {
443 dsda_NameToMap(next, &wminfo.nextep, &wminfo.next);
444
445 wminfo.nextep--;
446 wminfo.next--;
447
448 if (wminfo.nextep != wminfo.epsd)
449 {
450 int i;
451
452 for (i = 0; i < g_maxplayers; i++)
453 players[i].didsecret = false;
454 }
455
456 wminfo.didsecret = players[consoleplayer].didsecret;
457
458 *result = 0;
459
460 return true;
461 }
462
463 return false;
464 }
465
466 int dsda_UPrepareFinale(int* result) {
467 if (!gamemapinfo)
468 return false;
469
470 if (gamemapinfo->intertextsecret && secretexit) {
471 if (gamemapinfo->intertextsecret[0] != '-') // '-' means that any default intermission was cleared.
472 *result = WD_START_FINALE;
473 else
474 *result = 0;
475
476 return true;
477 }
478 else if (gamemapinfo->intertext && !secretexit) {
479 if (gamemapinfo->intertext[0] != '-') // '-' means that any default intermission was cleared.
480 *result = WD_START_FINALE;
481 else
482 *result = 0;
483
484 return true;
485 }
486 else if (gamemapinfo->endpic[0] &&
487 gamemapinfo->endpic[0] != '-' &&
488 !secretexit) {
489 *result = WD_VICTORY;
490
491 return true;
492 }
493
494 return false;
495 }
496
497 void dsda_ULoadMapInfo(void) {
498 int p;
499
500 if (dsda_Flag(dsda_arg_nomapinfo) || dsda_UseMapinfo() || raven)
501 return;
502
503 p = -1;
504 while ((p = W_ListNumFromName("UMAPINFO", p)) >= 0) {
505 const unsigned char * lump = (const unsigned char *) W_LumpByNum(p);
506 ParseUMapInfo(lump, W_LumpLength(p), I_Error);
507 }
508 }
509
510 int dsda_UExitPic(const char** exit_pic) {
511 if (!lastmapinfo || !lastmapinfo->exitpic[0])
512 return false;
513
514 *exit_pic = lastmapinfo->exitpic;
515
516 return true;
517 }
518
519 int dsda_UEnterPic(const char** enter_pic) {
520 if (!nextmapinfo || !nextmapinfo->enterpic[0])
521 return false;
522
523 *enter_pic = nextmapinfo->enterpic;
524
525 return true;
526 }
527
528 int dsda_UBorderTexture(const char** border_texture) {
529 return false;
530 }
531
532 int dsda_UPrepareEntering(void) {
533 extern const char *el_levelname;
534 extern const char *el_levelpic;
535 extern const char *el_author;
536
537 if (!nextmapinfo)
538 return false;
539
540 if (nextmapinfo->levelname && nextmapinfo->levelpic[0] == 0) {
541 el_levelname = nextmapinfo->levelname;
542 el_levelpic = NULL;
543 el_author = nextmapinfo->author;
544
545 return true;
546 }
547 else if (nextmapinfo->levelpic[0]) {
548 el_levelname = NULL;
549 el_levelpic = nextmapinfo->levelpic;
550 el_author = NULL;
551
552 return true;
553 }
554
555 return false;
556 }
557
558 int dsda_UPrepareFinished(void) {
559 extern const char *lf_levelname;
560 extern const char *lf_levelpic;
561 extern const char *lf_author;
562
563 if (!lastmapinfo)
564 return false;
565
566 if (lastmapinfo->levelname && lastmapinfo->levelpic[0] == 0) {
567 lf_levelname = lastmapinfo->levelname;
568 lf_levelpic = NULL;
569 lf_author = lastmapinfo->author;
570
571 return true;
572 }
573 else if (lastmapinfo->levelpic[0]) {
574 lf_levelname = NULL;
575 lf_levelpic = lastmapinfo->levelpic;
576 lf_author = NULL;
577
578 return true;
579 }
580
581 return false;
582 }
583
584 int dsda_UMapLightning(int* lightning) {
585 return false;
586 }
587
588 int dsda_UApplyFadeTable(void) {
589 return false;
590 }
591
592 int dsda_UMapCluster(int* cluster, int map) {
593 return false;
594 }
595
596 int dsda_USky1Texture(short* texture) {
597 return false;
598 }
599
600 int dsda_USky2Texture(short* texture) {
601 return false;
602 }
603
604 int dsda_UGravity(fixed_t* gravity) {
605 return false;
606 }
607
608 int dsda_UAirControl(fixed_t* air_control) {
609 return false;
610 }
611
612 int dsda_UInitSky(void) {
613 return false;
614 }
615
616 int dsda_UMapFlags(map_info_flags_t* flags) {
617 return false;
618 }
619
620 int dsda_UMapColorMap(int* colormap) {
621 return false;
622 }