From 6a2553cf571301968a91668a62604df61dd9df7d Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 16 Sep 2022 22:51:02 +0100 Subject: [PATCH] Fix cups. * Required an adjustment of everywhere using G_MapNumber to return the raw header number, instead of off-by-one ala gamemap. * Fixing gamemap is a viable improvement for a future commit, but this commit is already pretty big. * Remove SCANTHINGS, since it used G_MapNumber and didn't work with long map names OR virtres anyways. * Support freeing new information in CLEAR LEVELS maincfg event, since I tried to use that to test cups. * Make Patch_Free's usability match Z_Free -- passing NULL is permitted and a no-op. --- src/d_main.cpp | 2 +- src/deh_soc.c | 221 ++++++++++++++++++++++++++----------------------- src/f_finale.c | 3 +- src/g_game.c | 12 +-- src/p_setup.c | 87 ++----------------- src/p_setup.h | 3 - src/r_patch.c | 2 +- src/w_wad.c | 16 ---- 8 files changed, 134 insertions(+), 212 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index c45ab030f..2a198bf34 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1792,7 +1792,7 @@ void D_SRB2Main(void) // rei/miru: bootmap (Idea: starts the game on a predefined map) if (bootmap && !(M_CheckParm("-warp") && M_IsNextParm())) { - const INT32 bootMapNum = G_MapNumber(bootmap); + const INT32 bootMapNum = G_MapNumber(bootmap)+1; if (mapheaderinfo[bootMapNum]) { diff --git a/src/deh_soc.c b/src/deh_soc.c index f5b2b11fa..4223b1733 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -161,12 +161,22 @@ void clear_levels(void) P_DeleteFlickies(i); P_DeleteGrades(i); + Patch_Free(mapheaderinfo[i]->thumbnailPic); + Patch_Free(mapheaderinfo[i]->minimapPic); + Z_Free(mapheaderinfo[i]->nextlevel); + Z_Free(mapheaderinfo[i]->marathonnext); + + Z_Free(mapheaderinfo[i]->lumpname); + Z_Free(mapheaderinfo[i]); mapheaderinfo[i] = NULL; } - // Realloc the one for the current gamemap as a safeguard - P_AllocMapHeader(gamemap-1); + nummapheaders = 0; + + // Realloc the one for the current gamemap as a safeguard -- TODO: BAD + if (Playing()) + P_AllocMapHeader(gamemap-1); } static boolean findFreeSlot(INT32 *num) @@ -1051,13 +1061,13 @@ static mapheader_lighting_t *usemaplighting(INT32 mapnum, const char *word) { if (fastncmp(word, "ENCORE", 6)) { - mapheaderinfo[mapnum-1]->use_encore_lighting = true; + mapheaderinfo[mapnum]->use_encore_lighting = true; - return &mapheaderinfo[mapnum-1]->lighting_encore; + return &mapheaderinfo[mapnum]->lighting_encore; } else { - return &mapheaderinfo[mapnum-1]->lighting; + return &mapheaderinfo[mapnum]->lighting; } } @@ -1074,14 +1084,14 @@ void readlevelheader(MYFILE *f, char * name) const INT32 num = G_MapNumber(name); - if (num > NUMMAPS) + if (num >= NUMMAPS) { I_Error("Too many maps!"); } if (num >= nummapheaders) { - P_AllocMapHeader((INT16)(num -1)); + P_AllocMapHeader((INT16)(num)); } else if (f->wad > mainwads) { @@ -1089,9 +1099,9 @@ void readlevelheader(MYFILE *f, char * name) G_SetGameModified(multiplayer, true); } - if (mapheaderinfo[num-1]->lumpname == NULL) + if (mapheaderinfo[num]->lumpname == NULL) { - mapheaderinfo[num-1]->lumpname = Z_StrDup(name); + mapheaderinfo[num]->lumpname = Z_StrDup(name); } do @@ -1130,16 +1140,16 @@ void readlevelheader(MYFILE *f, char * name) if (fastcmp(word, "LEVELNAME")) { - deh_strlcpy(mapheaderinfo[num-1]->lvlttl, word2, - sizeof(mapheaderinfo[num-1]->lvlttl), va("Level header %d: levelname", num)); - strlcpy(mapheaderinfo[num-1]->selectheading, word2, sizeof(mapheaderinfo[num-1]->selectheading)); // not deh_ so only complains once + deh_strlcpy(mapheaderinfo[num]->lvlttl, word2, + sizeof(mapheaderinfo[num]->lvlttl), va("Level header %d: levelname", num)); + strlcpy(mapheaderinfo[num]->selectheading, word2, sizeof(mapheaderinfo[num]->selectheading)); // not deh_ so only complains once continue; } // CHEAP HACK: move this over here for lowercase subtitles if (fastcmp(word, "SUBTITLE")) { - deh_strlcpy(mapheaderinfo[num-1]->subttl, word2, - sizeof(mapheaderinfo[num-1]->subttl), va("Level header %d: subtitle", num)); + deh_strlcpy(mapheaderinfo[num]->subttl, word2, + sizeof(mapheaderinfo[num]->subttl), va("Level header %d: subtitle", num)); continue; } @@ -1161,19 +1171,19 @@ void readlevelheader(MYFILE *f, char * name) } // Sanity limit of 128 params - if (mapheaderinfo[num-1]->numCustomOptions == 128) + if (mapheaderinfo[num]->numCustomOptions == 128) { deh_warning("Level header %d: too many custom parameters", num); continue; } - j = mapheaderinfo[num-1]->numCustomOptions++; + j = mapheaderinfo[num]->numCustomOptions++; - mapheaderinfo[num-1]->customopts = - Z_Realloc(mapheaderinfo[num-1]->customopts, - sizeof(customoption_t) * mapheaderinfo[num-1]->numCustomOptions, PU_STATIC, NULL); + mapheaderinfo[num]->customopts = + Z_Realloc(mapheaderinfo[num]->customopts, + sizeof(customoption_t) * mapheaderinfo[num]->numCustomOptions, PU_STATIC, NULL); // Newly allocated - modoption = &mapheaderinfo[num-1]->customopts[j]; + modoption = &mapheaderinfo[num]->customopts[j]; strncpy(modoption->option, word, 31); modoption->option[31] = '\0'; @@ -1189,33 +1199,33 @@ void readlevelheader(MYFILE *f, char * name) if (fastcmp(word, "FLICKYLIST") || fastcmp(word, "ANIMALLIST")) { if (fastcmp(word2, "NONE")) - P_DeleteFlickies(num-1); + P_DeleteFlickies(num); else if (fastcmp(word2, "DEMO")) - P_SetDemoFlickies(num-1); + P_SetDemoFlickies(num); else if (fastcmp(word2, "ALL")) { mobjtype_t tmpflickies[MAXFLICKIES]; - for (mapheaderinfo[num-1]->numFlickies = 0; - ((mapheaderinfo[num-1]->numFlickies < MAXFLICKIES) && FLICKYTYPES[mapheaderinfo[num-1]->numFlickies].type); - mapheaderinfo[num-1]->numFlickies++) - tmpflickies[mapheaderinfo[num-1]->numFlickies] = FLICKYTYPES[mapheaderinfo[num-1]->numFlickies].type; + for (mapheaderinfo[num]->numFlickies = 0; + ((mapheaderinfo[num]->numFlickies < MAXFLICKIES) && FLICKYTYPES[mapheaderinfo[num]->numFlickies].type); + mapheaderinfo[num]->numFlickies++) + tmpflickies[mapheaderinfo[num]->numFlickies] = FLICKYTYPES[mapheaderinfo[num]->numFlickies].type; - if (mapheaderinfo[num-1]->numFlickies) // just in case... + if (mapheaderinfo[num]->numFlickies) // just in case... { - size_t newsize = sizeof(mobjtype_t) * mapheaderinfo[num-1]->numFlickies; - mapheaderinfo[num-1]->flickies = Z_Realloc(mapheaderinfo[num-1]->flickies, newsize, PU_STATIC, NULL); - M_Memcpy(mapheaderinfo[num-1]->flickies, tmpflickies, newsize); + size_t newsize = sizeof(mobjtype_t) * mapheaderinfo[num]->numFlickies; + mapheaderinfo[num]->flickies = Z_Realloc(mapheaderinfo[num]->flickies, newsize, PU_STATIC, NULL); + M_Memcpy(mapheaderinfo[num]->flickies, tmpflickies, newsize); } } else { mobjtype_t tmpflickies[MAXFLICKIES]; - mapheaderinfo[num-1]->numFlickies = 0; + mapheaderinfo[num]->numFlickies = 0; tmp = strtok(word2,","); // get up to the first MAXFLICKIES flickies do { - if (mapheaderinfo[num-1]->numFlickies == MAXFLICKIES) // never going to get above that number + if (mapheaderinfo[num]->numFlickies == MAXFLICKIES) // never going to get above that number { deh_warning("Level header %d: too many flickies\n", num); break; @@ -1229,7 +1239,7 @@ void readlevelheader(MYFILE *f, char * name) //deh_warning("Level header %d: unknown flicky mobj type %s\n", num, tmp); -- no need for this line as get_mobjtype complains too continue; } - tmpflickies[mapheaderinfo[num-1]->numFlickies] = i; + tmpflickies[mapheaderinfo[num]->numFlickies] = i; } else // ...or a quick, limited selection of default flickies! { @@ -1242,17 +1252,17 @@ void readlevelheader(MYFILE *f, char * name) deh_warning("Level header %d: unknown flicky selection %s\n", num, tmp); continue; } - tmpflickies[mapheaderinfo[num-1]->numFlickies] = FLICKYTYPES[i].type; + tmpflickies[mapheaderinfo[num]->numFlickies] = FLICKYTYPES[i].type; } - mapheaderinfo[num-1]->numFlickies++; + mapheaderinfo[num]->numFlickies++; } while ((tmp = strtok(NULL,",")) != NULL); - if (mapheaderinfo[num-1]->numFlickies) + if (mapheaderinfo[num]->numFlickies) { - size_t newsize = sizeof(mobjtype_t) * mapheaderinfo[num-1]->numFlickies; - mapheaderinfo[num-1]->flickies = Z_Realloc(mapheaderinfo[num-1]->flickies, newsize, PU_STATIC, NULL); + size_t newsize = sizeof(mobjtype_t) * mapheaderinfo[num]->numFlickies; + mapheaderinfo[num]->flickies = Z_Realloc(mapheaderinfo[num]->flickies, newsize, PU_STATIC, NULL); // now we add them to the list! - M_Memcpy(mapheaderinfo[num-1]->flickies, tmpflickies, newsize); + M_Memcpy(mapheaderinfo[num]->flickies, tmpflickies, newsize); } else deh_warning("Level header %d: no valid flicky types found\n", num); @@ -1262,40 +1272,40 @@ void readlevelheader(MYFILE *f, char * name) // Strings that can be truncated else if (fastcmp(word, "NEXTLEVEL")) { - mapheaderinfo[num-1]->nextlevel = Z_StrDup(word2); + mapheaderinfo[num]->nextlevel = Z_StrDup(word2); } else if (fastcmp(word, "MARATHONNEXT")) { - mapheaderinfo[num-1]->marathonnext = Z_StrDup(word2); + mapheaderinfo[num]->marathonnext = Z_StrDup(word2); } else if (fastcmp(word, "ZONETITLE")) { - deh_strlcpy(mapheaderinfo[num-1]->zonttl, word2, - sizeof(mapheaderinfo[num-1]->zonttl), va("Level header %d: zonetitle", num)); + deh_strlcpy(mapheaderinfo[num]->zonttl, word2, + sizeof(mapheaderinfo[num]->zonttl), va("Level header %d: zonetitle", num)); } else if (fastcmp(word, "SCRIPTNAME")) { - deh_strlcpy(mapheaderinfo[num-1]->scriptname, word2, - sizeof(mapheaderinfo[num-1]->scriptname), va("Level header %d: scriptname", num)); + deh_strlcpy(mapheaderinfo[num]->scriptname, word2, + sizeof(mapheaderinfo[num]->scriptname), va("Level header %d: scriptname", num)); } else if (fastcmp(word, "RUNSOC")) { - deh_strlcpy(mapheaderinfo[num-1]->runsoc, word2, - sizeof(mapheaderinfo[num-1]->runsoc), va("Level header %d: runsoc", num)); + deh_strlcpy(mapheaderinfo[num]->runsoc, word2, + sizeof(mapheaderinfo[num]->runsoc), va("Level header %d: runsoc", num)); } else if (fastcmp(word, "ACT")) { /*if (i >= 0 && i < 20) // 0 for no act number, TTL1 through TTL19 - mapheaderinfo[num-1]->actnum = (UINT8)i; + mapheaderinfo[num]->actnum = (UINT8)i; else deh_warning("Level header %d: invalid act number %d", num, i);*/ - deh_strlcpy(mapheaderinfo[num-1]->actnum, word2, - sizeof(mapheaderinfo[num-1]->actnum), va("Level header %d: actnum", num)); + deh_strlcpy(mapheaderinfo[num]->actnum, word2, + sizeof(mapheaderinfo[num]->actnum), va("Level header %d: actnum", num)); } else if (fastcmp(word, "TYPEOFLEVEL")) { if (i) // it's just a number - mapheaderinfo[num-1]->typeoflevel = (UINT32)i; + mapheaderinfo[num]->typeoflevel = (UINT32)i; else { UINT32 tol = 0; @@ -1308,20 +1318,20 @@ void readlevelheader(MYFILE *f, char * name) deh_warning("Level header %d: unknown typeoflevel flag %s\n", num, tmp); tol |= TYPEOFLEVEL[i].flag; } while((tmp = strtok(NULL,",")) != NULL); - mapheaderinfo[num-1]->typeoflevel = tol; + mapheaderinfo[num]->typeoflevel = tol; } } else if (fastcmp(word, "KEYWORDS")) { - deh_strlcpy(mapheaderinfo[num-1]->keywords, word2, - sizeof(mapheaderinfo[num-1]->keywords), va("Level header %d: keywords", num)); + deh_strlcpy(mapheaderinfo[num]->keywords, word2, + sizeof(mapheaderinfo[num]->keywords), va("Level header %d: keywords", num)); } else if (fastcmp(word, "MUSIC")) { if (fastcmp(word2, "NONE")) { - mapheaderinfo[num-1]->musname[0][0] = 0; // becomes empty string - mapheaderinfo[num-1]->musname_size = 0; + mapheaderinfo[num]->musname[0][0] = 0; // becomes empty string + mapheaderinfo[num]->musname_size = 0; } else { @@ -1330,71 +1340,71 @@ void readlevelheader(MYFILE *f, char * name) do { if (j >= MAXMUSNAMES) break; - deh_strlcpy(mapheaderinfo[num-1]->musname[j], tmp, - sizeof(mapheaderinfo[num-1]->musname[j]), va("Level header %d: music", num)); + deh_strlcpy(mapheaderinfo[num]->musname[j], tmp, + sizeof(mapheaderinfo[num]->musname[j]), va("Level header %d: music", num)); j++; } while ((tmp = strtok(NULL,",")) != NULL); if (tmp != NULL) deh_warning("Level header %d: additional music slots past %d discarded", num, MAXMUSNAMES); - mapheaderinfo[num-1]->musname_size = j; + mapheaderinfo[num]->musname_size = j; } } else if (fastcmp(word, "MUSICSLOT")) deh_warning("Level header %d: MusicSlot parameter is deprecated and will be removed.\nUse \"Music\" instead.", num); else if (fastcmp(word, "MUSICTRACK")) - mapheaderinfo[num-1]->mustrack = ((UINT16)i - 1); + mapheaderinfo[num]->mustrack = ((UINT16)i - 1); else if (fastcmp(word, "MUSICPOS")) - mapheaderinfo[num-1]->muspos = (UINT32)get_number(word2); + mapheaderinfo[num]->muspos = (UINT32)get_number(word2); else if (fastcmp(word, "FORCECHARACTER")) { - strlcpy(mapheaderinfo[num-1]->forcecharacter, word2, SKINNAMESIZE+1); - strlwr(mapheaderinfo[num-1]->forcecharacter); // skin names are lowercase + strlcpy(mapheaderinfo[num]->forcecharacter, word2, SKINNAMESIZE+1); + strlwr(mapheaderinfo[num]->forcecharacter); // skin names are lowercase } else if (fastcmp(word, "WEATHER")) - mapheaderinfo[num-1]->weather = get_precip(word2); + mapheaderinfo[num]->weather = get_precip(word2); else if (fastcmp(word, "SKYTEXTURE")) - deh_strlcpy(mapheaderinfo[num-1]->skytexture, word2, - sizeof(mapheaderinfo[num-1]->skytexture), va("Level header %d: sky texture", num)); + deh_strlcpy(mapheaderinfo[num]->skytexture, word2, + sizeof(mapheaderinfo[num]->skytexture), va("Level header %d: sky texture", num)); else if (fastcmp(word, "SKYNUM")) - deh_strlcpy(mapheaderinfo[num-1]->skytexture, va("SKY%s", word2), - sizeof(mapheaderinfo[num-1]->skytexture), va("Level header %d: sky texture", num)); + deh_strlcpy(mapheaderinfo[num]->skytexture, va("SKY%s", word2), + sizeof(mapheaderinfo[num]->skytexture), va("Level header %d: sky texture", num)); else if (fastcmp(word, "PRECUTSCENENUM")) - mapheaderinfo[num-1]->precutscenenum = (UINT8)i; + mapheaderinfo[num]->precutscenenum = (UINT8)i; else if (fastcmp(word, "CUTSCENENUM")) - mapheaderinfo[num-1]->cutscenenum = (UINT8)i; + mapheaderinfo[num]->cutscenenum = (UINT8)i; else if (fastcmp(word, "PALETTE")) - mapheaderinfo[num-1]->palette = (UINT16)i; + mapheaderinfo[num]->palette = (UINT16)i; else if (fastcmp(word, "ENCOREPAL")) - mapheaderinfo[num-1]->encorepal = (UINT16)i; + mapheaderinfo[num]->encorepal = (UINT16)i; else if (fastcmp(word, "NUMLAPS")) - mapheaderinfo[num-1]->numlaps = (UINT8)i; + mapheaderinfo[num]->numlaps = (UINT8)i; else if (fastcmp(word, "UNLOCKABLE")) { if (i >= 0 && i <= MAXUNLOCKABLES) // 0 for no unlock required, anything else requires something - mapheaderinfo[num-1]->unlockrequired = (SINT8)i - 1; + mapheaderinfo[num]->unlockrequired = (SINT8)i - 1; else deh_warning("Level header %d: invalid unlockable number %d", num, i); } else if (fastcmp(word, "LEVELSELECT")) - mapheaderinfo[num-1]->levelselect = (UINT8)i; + mapheaderinfo[num]->levelselect = (UINT8)i; else if (fastcmp(word, "SKYBOXSCALE")) - mapheaderinfo[num-1]->skybox_scalex = mapheaderinfo[num-1]->skybox_scaley = mapheaderinfo[num-1]->skybox_scalez = (INT16)i; + mapheaderinfo[num]->skybox_scalex = mapheaderinfo[num]->skybox_scaley = mapheaderinfo[num]->skybox_scalez = (INT16)i; else if (fastcmp(word, "SKYBOXSCALEX")) - mapheaderinfo[num-1]->skybox_scalex = (INT16)i; + mapheaderinfo[num]->skybox_scalex = (INT16)i; else if (fastcmp(word, "SKYBOXSCALEY")) - mapheaderinfo[num-1]->skybox_scaley = (INT16)i; + mapheaderinfo[num]->skybox_scaley = (INT16)i; else if (fastcmp(word, "SKYBOXSCALEZ")) - mapheaderinfo[num-1]->skybox_scalez = (INT16)i; + mapheaderinfo[num]->skybox_scalez = (INT16)i; else if (fastcmp(word, "LEVELFLAGS")) - mapheaderinfo[num-1]->levelflags = get_number(word2); + mapheaderinfo[num]->levelflags = get_number(word2); else if (fastcmp(word, "MENUFLAGS")) - mapheaderinfo[num-1]->menuflags = get_number(word2); + mapheaderinfo[num]->menuflags = get_number(word2); // SRB2Kart else if (fastcmp(word, "MOBJSCALE")) - mapheaderinfo[num-1]->mobj_scale = get_number(word2); + mapheaderinfo[num]->mobj_scale = get_number(word2); else if (fastcmp(word, "DEFAULTWAYPOINTRADIUS")) - mapheaderinfo[num-1]->default_waypoint_radius = get_number(word2); + mapheaderinfo[num]->default_waypoint_radius = get_number(word2); else if (fastcmp(word, "LIGHTCONTRAST")) { usemaplighting(num, word)->light_contrast = (UINT8)i; @@ -1422,76 +1432,76 @@ void readlevelheader(MYFILE *f, char * name) else if (fastcmp(word, "SCRIPTISFILE")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->levelflags |= LF_SCRIPTISFILE; + mapheaderinfo[num]->levelflags |= LF_SCRIPTISFILE; else - mapheaderinfo[num-1]->levelflags &= ~LF_SCRIPTISFILE; + mapheaderinfo[num]->levelflags &= ~LF_SCRIPTISFILE; } else if (fastcmp(word, "NOZONE")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->levelflags |= LF_NOZONE; + mapheaderinfo[num]->levelflags |= LF_NOZONE; else - mapheaderinfo[num-1]->levelflags &= ~LF_NOZONE; + mapheaderinfo[num]->levelflags &= ~LF_NOZONE; } else if (fastcmp(word, "SECTIONRACE")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->levelflags |= LF_SECTIONRACE; + mapheaderinfo[num]->levelflags |= LF_SECTIONRACE; else - mapheaderinfo[num-1]->levelflags &= ~LF_SECTIONRACE; + mapheaderinfo[num]->levelflags &= ~LF_SECTIONRACE; } else if (fastcmp(word, "SUBTRACTNUM")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->levelflags |= LF_SUBTRACTNUM; + mapheaderinfo[num]->levelflags |= LF_SUBTRACTNUM; else - mapheaderinfo[num-1]->levelflags &= ~LF_SUBTRACTNUM; + mapheaderinfo[num]->levelflags &= ~LF_SUBTRACTNUM; } // Individual triggers for menu flags else if (fastcmp(word, "HIDDEN")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->menuflags |= LF2_HIDEINMENU; + mapheaderinfo[num]->menuflags |= LF2_HIDEINMENU; else - mapheaderinfo[num-1]->menuflags &= ~LF2_HIDEINMENU; + mapheaderinfo[num]->menuflags &= ~LF2_HIDEINMENU; } else if (fastcmp(word, "HIDEINSTATS")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->menuflags |= LF2_HIDEINSTATS; + mapheaderinfo[num]->menuflags |= LF2_HIDEINSTATS; else - mapheaderinfo[num-1]->menuflags &= ~LF2_HIDEINSTATS; + mapheaderinfo[num]->menuflags &= ~LF2_HIDEINSTATS; } else if (fastcmp(word, "TIMEATTACK") || fastcmp(word, "RECORDATTACK")) { // RECORDATTACK is an accepted alias if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->menuflags &= ~LF2_NOTIMEATTACK; + mapheaderinfo[num]->menuflags &= ~LF2_NOTIMEATTACK; else - mapheaderinfo[num-1]->menuflags |= LF2_NOTIMEATTACK; + mapheaderinfo[num]->menuflags |= LF2_NOTIMEATTACK; } else if (fastcmp(word, "VISITNEEDED")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->menuflags |= LF2_VISITNEEDED; + mapheaderinfo[num]->menuflags |= LF2_VISITNEEDED; else - mapheaderinfo[num-1]->menuflags &= ~LF2_VISITNEEDED; + mapheaderinfo[num]->menuflags &= ~LF2_VISITNEEDED; } else if (fastcmp(word, "NOVISITNEEDED")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->menuflags &= ~LF2_VISITNEEDED; + mapheaderinfo[num]->menuflags &= ~LF2_VISITNEEDED; else - mapheaderinfo[num-1]->menuflags |= LF2_VISITNEEDED; + mapheaderinfo[num]->menuflags |= LF2_VISITNEEDED; } else if (fastcmp(word, "GRAVITY")) - mapheaderinfo[num-1]->gravity = FLOAT_TO_FIXED(atof(word2)); + mapheaderinfo[num]->gravity = FLOAT_TO_FIXED(atof(word2)); else if (fastcmp(word, "WALLTRANSFER") || fastcmp(word, "WALLRUNNING")) { if (i || word2[0] == 'T' || word2[0] == 'Y') - mapheaderinfo[num-1]->use_walltransfer = true; + mapheaderinfo[num]->use_walltransfer = true; else - mapheaderinfo[num-1]->use_walltransfer = false; + mapheaderinfo[num]->use_walltransfer = false; } else deh_warning("Level header %d: unknown word '%s'", num, word); @@ -3534,8 +3544,9 @@ void readcupheader(MYFILE *f, cupheader_t *cup) break; } - cup->levellist[cup->numlevels] = Z_StrDup(word2); + cup->levellist[cup->numlevels] = Z_StrDup(tmp); cup->numlevels++; + CONS_Printf("tmp = %s\n", tmp); } while((tmp = strtok(NULL,",")) != NULL); } else if (fastcmp(word, "BONUSGAME")) diff --git a/src/f_finale.c b/src/f_finale.c index 7d8f26fee..c44515d45 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1118,7 +1118,7 @@ static void F_CacheTitleScreen(void) void F_StartTitleScreen(void) { - const INT32 titleMapNum = titlemap ? G_MapNumber(titlemap) : 0; + const INT32 titleMapNum = titlemap ? G_MapNumber(titlemap)+1 : 0; if (gamestate != GS_TITLESCREEN && gamestate != GS_WAITINGPLAYERS) { @@ -1133,6 +1133,7 @@ void F_StartTitleScreen(void) { mapthing_t *startpos; + const INT32 titleMapNum = G_MapNumber(titlemap)+1; gamestate_t prevwipegamestate = wipegamestate; titlemapinaction = TITLEMAP_LOADING; titlemapcameraref = NULL; diff --git a/src/g_game.c b/src/g_game.c index a498b7cd1..b835074de 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -734,7 +734,7 @@ INT32 G_MapNumber(const char * name) } } - return map + 1; + return map; } /** Clips the console player's mouse aiming to the current view. @@ -3791,7 +3791,7 @@ static void G_DoCompleted(void) if (mapheaderinfo[mNextNum]) { - nextmap = (INT16)(mNextNum-1); + nextmap = (INT16)mNextNum; } } else if (grandprixinfo.gp == true) @@ -3826,7 +3826,7 @@ static void G_DoCompleted(void) if (mapheaderinfo[nextNum]) { - nextmap = (INT16)(nextNum-1); + nextmap = (INT16)nextNum; if (marathonmode && nextmap == spmarathon_start-1) nextmap = 1100-1; // No infinite loop for you } @@ -3862,7 +3862,7 @@ static void G_DoCompleted(void) if (!mapheaderinfo[mNextNum]) cm = -1; // guarantee error execution else - cm = (INT16)(mNextNum-1); + cm = (INT16)mNextNum; } else { @@ -3871,7 +3871,7 @@ static void G_DoCompleted(void) if (!mapheaderinfo[nextNum]) cm = -1; // guarantee error execution else - cm = (INT16)(nextNum-1); + cm = (INT16)nextNum; } if (cm >= NUMMAPS || cm < 0) // out of range (either 1100ish or error) @@ -5070,7 +5070,7 @@ INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) } else { - newmapnum = G_MapNumber(mapname); + newmapnum = G_MapNumber(mapname)+1; if (newmapnum > nummapheaders) return G_FindMap(mapname, realmapnamep, NULL, NULL); diff --git a/src/p_setup.c b/src/p_setup.c index 703ce5949..9c4ef78e3 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -398,29 +398,17 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) const INT16 num = (INT16)(i-1); boolean exists = (mapheaderinfo[gamemap-1]->alreadyExists == true); - if (mapheaderinfo[num]->thumbnailPic) - { - Patch_Free(mapheaderinfo[num]->thumbnailPic); - mapheaderinfo[num]->thumbnailPic = NULL; - } + Patch_Free(mapheaderinfo[num]->thumbnailPic); + mapheaderinfo[num]->thumbnailPic = NULL; - if (mapheaderinfo[num]->minimapPic) - { - Patch_Free(mapheaderinfo[num]->minimapPic); - mapheaderinfo[num]->minimapPic = NULL; - } + Patch_Free(mapheaderinfo[num]->minimapPic); + mapheaderinfo[num]->minimapPic = NULL; - if (mapheaderinfo[num]->nextlevel) - { - Z_Free(mapheaderinfo[num]->nextlevel); - mapheaderinfo[num]->nextlevel = NULL; - } + Z_Free(mapheaderinfo[num]->nextlevel); + mapheaderinfo[num]->nextlevel = NULL; - if (mapheaderinfo[num]->marathonnext) - { - Z_Free(mapheaderinfo[num]->marathonnext); - mapheaderinfo[num]->marathonnext = NULL; - } + Z_Free(mapheaderinfo[num]->marathonnext); + mapheaderinfo[num]->marathonnext = NULL; mapheaderinfo[num]->lvlttl[0] = '\0'; mapheaderinfo[num]->selectheading[0] = '\0'; @@ -843,65 +831,6 @@ void P_ReloadRings(void) } } -#ifdef SCANTHINGS -void P_ScanThings(INT16 mapnum, INT16 wadnum, INT16 lumpnum) -{ - size_t i, n; - UINT8 *data, *datastart; - UINT16 type, maprings; - INT16 tol; - UINT32 flags; - - tol = mapheaderinfo[mapnum-1]->typeoflevel; - flags = mapheaderinfo[mapnum-1]->levelflags; - - n = W_LumpLengthPwad(wadnum, lumpnum) / (5 * sizeof (INT16)); - //CONS_Printf("%u map things found!\n", n); - - maprings = 0; - data = datastart = W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); - for (i = 0; i < n; i++) - { - data += 3 * sizeof (INT16); // skip x y position, angle - type = READUINT16(data) & 4095; - data += sizeof (INT16); // skip options - - if (mt->type == mobjinfo[MT_RANDOMITEM].doomednum) - { - nummapboxes++; - } - else if (mt->type == mobjinfo[MT_RING].doomednum) - { - maprings++; - } - else - { - switch (type) - { - case 603: // 10 diagonal rings - maprings += 10; - break; - case 600: // 5 vertical rings - case 601: // 5 vertical rings - case 602: // 5 diagonal rings - maprings += 5; - break; - case 604: // 8 circle rings - maprings += 8; - break; - case 605: // 16 circle rings - maprings += 16; - break; - } - } - } - Z_Free(datastart); - - if (maprings) - CONS_Printf("%s has %u rings\n", G_BuildMapName(mapnum), maprings); -} -#endif - static int cmp_loopends(const void *a, const void *b) { const mapthing_t diff --git a/src/p_setup.h b/src/p_setup.h index 590d1db87..22f6bdca1 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -103,9 +103,6 @@ extern size_t nummapthings; extern mapthing_t *mapthings; void P_SetupLevelSky(const char *skytexname, boolean global); -#ifdef SCANTHINGS -void P_ScanThings(INT16 mapnum, INT16 wadnum, INT16 lumpnum); -#endif void P_RespawnThings(void); boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate); void P_PostLoadLevel(void); diff --git a/src/r_patch.c b/src/r_patch.c index 544c15ae8..8cf89fa3d 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -101,7 +101,7 @@ static void Patch_FreeData(patch_t *patch) void Patch_Free(patch_t *patch) { - if (patch == missingpat) + if (!patch || patch == missingpat) return; Patch_FreeData(patch); Z_Free(patch); diff --git a/src/w_wad.c b/src/w_wad.c index 044fb1e35..6de1fe115 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -64,9 +64,6 @@ #include "i_system.h" #include "md5.h" #include "lua_script.h" -#ifdef SCANTHINGS -#include "p_setup.h" // P_ScanThings -#endif #include "g_game.h" // G_MapNumber #include "k_terrain.h" @@ -308,19 +305,6 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile) DEH_LoadDehackedLumpPwad(wadnum, lump, mainfile); } } - -#ifdef SCANTHINGS - // Scan maps for emblems 'n shit - { - lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo; - for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) - { - const char *name = lump_p->name; - INT16 mapnum = (INT16)G_MapNumber(name); - P_ScanThings(mapnum, wadnum, lump + ML_THINGS); - } - } -#endif } static inline boolean CheckCompatFilename(const char *filename)