From 2c7e7b8aa8dc2eb9632e758822c2d39044db3547 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 14 Oct 2022 13:19:20 +0100 Subject: [PATCH] Fix replacing cups' map lists not properly reassigning the cachedlevels --- src/deh_soc.c | 2 ++ src/p_setup.c | 64 ++++++++++++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 91c9a5b4d..01f18c527 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -3539,10 +3539,12 @@ void readcupheader(MYFILE *f, cupheader_t *cup) else if (fastcmp(word, "BONUSGAME")) { cup->levellist[CUPCACHE_BONUS] = Z_StrDup(word2); + cup->cachedlevels[CUPCACHE_BONUS] = NEXTMAP_INVALID; } else if (fastcmp(word, "SPECIALSTAGE")) { cup->levellist[CUPCACHE_SPECIAL] = Z_StrDup(word2); + cup->cachedlevels[CUPCACHE_SPECIAL] = NEXTMAP_INVALID; } else if (fastcmp(word, "EMERALDNUM")) { diff --git a/src/p_setup.c b/src/p_setup.c index 40cc5250f..3a8661a08 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8646,6 +8646,39 @@ UINT8 P_InitMapData(boolean existingmapheaders) continue; } + // Always check for cup cache reassociations. + // (The core assumption is that cups < headers.) + { + cupheader_t *cup = kartcupheaders; + INT32 j; + + mapheaderinfo[i]->cup = NULL; + + while (cup) + { + for (j = 0; j < CUPCACHE_MAX; j++) + { + // Already discovered? + if (cup->cachedlevels[j] != NEXTMAP_INVALID) + continue; + + if (!cup->levellist[j] || strcasecmp(cup->levellist[j], name) != 0) + continue; + + // Only panic about back-reference for non-bonus material. + if (j < MAXLEVELLIST) + { + if (mapheaderinfo[i]->cup) + I_Error("P_InitMapData: Map %s cannot appear in cups multiple times! (First in %s, now in %s)", name, mapheaderinfo[i]->cup->name, cup->name); + mapheaderinfo[i]->cup = cup; + } + + cup->cachedlevels[j] = i; + } + cup = cup->next; + } + } + // No change? if (mapheaderinfo[i]->lumpnum == maplump) continue; @@ -8713,37 +8746,6 @@ UINT8 P_InitMapData(boolean existingmapheaders) } vres_Free(virtmap); - - // Now associate it with a cup cache. - // (The core assumption is that cups < headers.) - if (i >= numexistingmapheaders) - { - cupheader_t *cup = kartcupheaders; - INT32 j; - while (cup) - { - for (j = 0; j < CUPCACHE_MAX; j++) - { - // Already discovered? - if (cup->cachedlevels[j] != NEXTMAP_INVALID) - continue; - - if (!cup->levellist[j] || strcasecmp(cup->levellist[j], name) != 0) - continue; - - // Only panic about back-reference for non-bonus material. - if (j < MAXLEVELLIST || j == CUPCACHE_SPECIAL) - { - if (mapheaderinfo[i]->cup) - I_Error("P_InitMapData: Map %s cannot appear in cups multiple times! (First in %s, now in %s)", name, mapheaderinfo[i]->cup->name, cup->name); - mapheaderinfo[i]->cup = cup; - } - - cup->cachedlevels[j] = i; - } - cup = cup->next; - } - } } }