From 6892abcb8c7851beb729d9c4fe918d306da5d2d3 Mon Sep 17 00:00:00 2001 From: JugadorXEI Date: Mon, 13 Oct 2025 20:20:37 +0200 Subject: [PATCH] Fix off-by-one error when setting justPlayed on a map header (plus debug code) This is because although the map value per gametype is decreased by 4 (VOTE_NUM_LEVELS) to account for 4 vote selections, it doesn't account for the prevmap being one of those four levels, so we decrease by one to account for that also. --- src/g_game.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index c3a04fbc1..9cdc2f95a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4787,6 +4787,71 @@ tryAgain: void G_AddMapToBuffer(mapnum_t map) { +#if 0 + // DEBUG: make nearly everything but four race levels full justPlayed + // to look into what happens when a dedicated runs for seven million years. + INT32 justplayedvalue = TOLMaps(gametype) - VOTE_NUM_LEVELS; + UINT32 tolflag = G_TOLFlag(gametype); + + // Find all the maps that are ok + INT32 i; + for (i = 0; i < nummapheaders; i++) + { + if (mapheaderinfo[i] == NULL) + { + continue; + } + + if (mapheaderinfo[i]->lumpnum == LUMPERROR) + { + continue; + } + + if ((mapheaderinfo[i]->typeoflevel & tolflag) == 0) + { + continue; + } + + if (mapheaderinfo[i]->menuflags & LF2_HIDEINMENU) + { + // Don't include hidden + continue; + } + + // Only care about restrictions if the host is a listen server. + if (!dedicated) + { + if (!(mapheaderinfo[i]->menuflags & LF2_NOVISITNEEDED) + && !(mapheaderinfo[i]->records.mapvisited & MV_VISITED) + && !( + mapheaderinfo[i]->cup + && mapheaderinfo[i]->cup->cachedlevels[0] == i + )) + { + // Not visited OR head of cup + continue; + } + + if ((mapheaderinfo[i]->menuflags & LF2_FINISHNEEDED) + && !(mapheaderinfo[i]->records.mapvisited & MV_BEATEN)) + { + // Not completed + continue; + } + } + + if (M_MapLocked(i + 1) == true) + { + // We haven't earned this one. + continue; + } + + mapheaderinfo[i]->justPlayed = justplayedvalue; + justplayedvalue -= 1; + if (justplayedvalue <= 0) + break; + } +#else if (mapheaderinfo[map]->justPlayed == 0) // Started playing a new map. { // Decrement every maps' justPlayed value. @@ -4801,7 +4866,8 @@ void G_AddMapToBuffer(mapnum_t map) } // Set our map's justPlayed value. - mapheaderinfo[map]->justPlayed = TOLMaps(gametype) - VOTEROWSADDSONE; + mapheaderinfo[map]->justPlayed = TOLMaps(gametype) - VOTEROWSADDSONE - 1; +#endif } #undef VOTEROWSADDSONE