Fix cup level list behaviour

- Frees existing string data
- Unbinds cup backreference here instead of in p_setup
This commit is contained in:
toaster 2022-10-15 15:43:11 +01:00
parent 19e427f5db
commit 21be55e924
2 changed files with 17 additions and 4 deletions

View file

@ -3052,7 +3052,15 @@ void readcupheader(MYFILE *f, cupheader_t *cup)
}
else if (fastcmp(word, "LEVELLIST"))
{
cup->numlevels = 0;
while (cup->numlevels > 0)
{
cup->numlevels--;
Z_Free(cup->levellist[cup->numlevels]);
cup->levellist[cup->numlevels] = NULL;
if (cup->cachedlevels[cup->numlevels] == NEXTMAP_INVALID)
continue;
mapheaderinfo[cup->cachedlevels[cup->numlevels]]->cup = NULL;
}
tmp = strtok(word2,",");
do {
@ -3069,11 +3077,13 @@ void readcupheader(MYFILE *f, cupheader_t *cup)
}
else if (fastcmp(word, "BONUSGAME"))
{
Z_Free(cup->levellist[CUPCACHE_BONUS]);
cup->levellist[CUPCACHE_BONUS] = Z_StrDup(word2);
cup->cachedlevels[CUPCACHE_BONUS] = NEXTMAP_INVALID;
}
else if (fastcmp(word, "SPECIALSTAGE"))
{
Z_Free(cup->levellist[CUPCACHE_SPECIAL]);
cup->levellist[CUPCACHE_SPECIAL] = Z_StrDup(word2);
cup->cachedlevels[CUPCACHE_SPECIAL] = NEXTMAP_INVALID;
}

View file

@ -4487,17 +4487,20 @@ UINT8 P_InitMapData(INT32 numexistingmapheaders)
cupheader_t *cup = kartcupheaders;
INT32 j;
mapheaderinfo[i]->cup = NULL;
while (cup)
{
for (j = 0; j < CUPCACHE_MAX; j++)
{
// No level in this slot?
if (!cup->levellist[j])
continue;
// Already discovered?
if (cup->cachedlevels[j] != NEXTMAP_INVALID)
continue;
if (!cup->levellist[j] || strcasecmp(cup->levellist[j], name) != 0)
// Not your name?
if (strcasecmp(cup->levellist[j], name) != 0)
continue;
// Only panic about back-reference for non-bonus material.