Fix vote buffer for G_RandMap being broken

This commit is contained in:
Sally Coolatta 2023-04-11 01:19:30 -04:00
parent 16df36b65b
commit 198672c845
8 changed files with 33 additions and 30 deletions

View file

@ -2622,8 +2622,8 @@ void D_SetupVote(void)
INT32 i; INT32 i;
INT16 votebuffer[VOTE_NUM_LEVELS + 1] = {-1}; UINT16 votebuffer[VOTE_NUM_LEVELS + 1];
votebuffer[VOTE_NUM_LEVELS] = 0; // End marker for G_RandMap memset(votebuffer, UINT16_MAX, sizeof(votebuffer));
WRITEUINT8(p, ((cv_kartencore.value == 1) && (gametyperules & GTR_ENCORE))); WRITEUINT8(p, ((cv_kartencore.value == 1) && (gametyperules & GTR_ENCORE)));
WRITEUINT8(p, G_SometimesGetDifferentEncore()); WRITEUINT8(p, G_SometimesGetDifferentEncore());

View file

@ -737,7 +737,7 @@ extern tic_t curlap, bestlap;
#define VOTE_SPECIAL (MAXPLAYERS) #define VOTE_SPECIAL (MAXPLAYERS)
#define VOTE_TOTAL (MAXPLAYERS+1) #define VOTE_TOTAL (MAXPLAYERS+1)
extern INT16 g_voteLevels[4][2]; extern UINT16 g_voteLevels[4][2];
extern SINT8 g_votes[VOTE_TOTAL]; extern SINT8 g_votes[VOTE_TOTAL];
extern SINT8 g_pickedVote; extern SINT8 g_pickedVote;

View file

@ -2250,7 +2250,7 @@ void F_TitleScreenTicker(boolean run)
// prevent console spam if failed // prevent console spam if failed
demoIdleLeft = demoIdleTime; demoIdleLeft = demoIdleTime;
mapnum = G_RandMap(TOL_RACE|TOL_BATTLE, -2, true, false, NULL); mapnum = G_RandMap(TOL_RACE|TOL_BATTLE, UINT16_MAX-1, true, false, NULL);
if (mapnum == 0) // gotta have ONE if (mapnum == 0) // gotta have ONE
{ {
return; return;

View file

@ -298,7 +298,7 @@ boolean prevencoremode;
boolean franticitems; // Frantic items currently enabled? boolean franticitems; // Frantic items currently enabled?
// Voting system // Voting system
INT16 g_voteLevels[4][2]; // Levels that were rolled by the host UINT16 g_voteLevels[4][2]; // Levels that were rolled by the host
SINT8 g_votes[VOTE_TOTAL]; // Each player's vote SINT8 g_votes[VOTE_TOTAL]; // Each player's vote
SINT8 g_pickedVote; // What vote the host rolls SINT8 g_pickedVote; // What vote the host rolls
@ -3728,17 +3728,17 @@ static INT32 TOLMaps(UINT8 pgametype)
* has those flags. * has those flags.
* \author Graue <graue@oceanbase.org> * \author Graue <graue@oceanbase.org>
*/ */
static INT16 *g_allowedMaps = NULL; static UINT16 *g_allowedMaps = NULL;
#ifdef PARANOIA #ifdef PARANOIA
static INT32 g_randMapStack = 0; static size_t g_randMapStack = 0;
#endif #endif
INT16 G_RandMap(UINT32 tolflags, INT16 pprevmap, boolean ignoreBuffers, boolean callAgainSoon, INT16 *extBuffer) UINT16 G_RandMap(UINT32 tolflags, UINT16 pprevmap, boolean ignoreBuffers, boolean callAgainSoon, UINT16 *extBuffer)
{ {
INT32 allowedMapsCount = 0; INT32 allowedMapsCount = 0;
INT32 extBufferCount = 0; INT32 extBufferCount = 0;
INT16 ret = 0; UINT16 ret = 0;
INT32 i, j; INT32 i, j;
#ifdef PARANOIA #ifdef PARANOIA
@ -3747,12 +3747,12 @@ INT16 G_RandMap(UINT32 tolflags, INT16 pprevmap, boolean ignoreBuffers, boolean
if (g_allowedMaps == NULL) if (g_allowedMaps == NULL)
{ {
g_allowedMaps = Z_Malloc(nummapheaders * sizeof(INT16), PU_STATIC, NULL); g_allowedMaps = Z_Malloc(nummapheaders * sizeof(UINT16), PU_STATIC, NULL);
} }
if (extBuffer != NULL) if (extBuffer != NULL)
{ {
for (i = 0; extBuffer[i] != 0; i++) for (i = 0; extBuffer[i] != UINT16_MAX; i++)
{ {
extBufferCount++; extBufferCount++;
} }
@ -3780,7 +3780,7 @@ tryAgain:
continue; continue;
} }
if (pprevmap == -2 // title demo hack if (pprevmap == UINT16_MAX-1 // title demo hack (FUCK YOU, MAKE IT A BOOL)
&& mapheaderinfo[i]->ghostCount == 0) && mapheaderinfo[i]->ghostCount == 0)
{ {
// Doesn't have any ghosts, so it's not suitable for title demos. // Doesn't have any ghosts, so it's not suitable for title demos.
@ -3809,11 +3809,13 @@ tryAgain:
if (extBufferCount > 0) if (extBufferCount > 0)
{ {
boolean inExt = false;
// An optional additional buffer, // An optional additional buffer,
// to avoid duplicates on the voting screen. // to avoid duplicates on the voting screen.
for (j = 0; j < extBufferCount; j++) for (j = 0; j < extBufferCount; j++)
{ {
if (extBuffer[j] < 0 || extBuffer[j] >= nummapheaders) if (extBuffer[j] >= nummapheaders)
{ {
// Rest of buffer SHOULD be empty. // Rest of buffer SHOULD be empty.
break; break;
@ -3822,11 +3824,12 @@ tryAgain:
if (i == extBuffer[j]) if (i == extBuffer[j])
{ {
// Map is in this other buffer, don't duplicate. // Map is in this other buffer, don't duplicate.
inExt = true;
break; break;
} }
} }
if (j < extBufferCount) if (inExt == true)
{ {
// Didn't make it out of this buffer, so don't add this map. // Didn't make it out of this buffer, so don't add this map.
continue; continue;
@ -3875,7 +3878,7 @@ tryAgain:
return ret; return ret;
} }
void G_AddMapToBuffer(INT16 map) void G_AddMapToBuffer(UINT16 map)
{ {
if (mapheaderinfo[map]->justPlayed == 0) // Started playing a new map. if (mapheaderinfo[map]->justPlayed == 0) // Started playing a new map.
{ {
@ -5507,6 +5510,8 @@ void G_InitNew(UINT8 pencoremode, INT32 map, boolean resetplayer, boolean skippr
} }
CON_LogMessage("\"\n"); CON_LogMessage("\"\n");
} }
G_AddMapToBuffer(gamemap - 1);
} }

View file

@ -255,8 +255,8 @@ FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics);
UINT32 G_TOLFlag(INT32 pgametype); UINT32 G_TOLFlag(INT32 pgametype);
INT16 G_GetFirstMapOfGametype(UINT8 pgametype); INT16 G_GetFirstMapOfGametype(UINT8 pgametype);
INT16 G_RandMap(UINT32 tolflags, INT16 pprevmap, boolean ignoreBuffers, boolean callAgainSoon, INT16 *extBuffer); UINT16 G_RandMap(UINT32 tolflags, UINT16 pprevmap, boolean ignoreBuffers, boolean callAgainSoon, UINT16 *extBuffer);
void G_AddMapToBuffer(INT16 map); void G_AddMapToBuffer(UINT16 map);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -5282,7 +5282,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 encoremapcache = NEXTMAP_INVALID; static UINT16 encoremapcache = NEXTMAP_INVALID;
if (encoremapcache > nummapheaders) if (encoremapcache > nummapheaders)
{ {
encoremapcache = G_RandMap(G_TOLFlag(GT_RACE), -1, true, false, NULL); encoremapcache = G_RandMap(G_TOLFlag(GT_RACE), UINT16_MAX, true, false, NULL);
} }
specialmap = encoremapcache; specialmap = encoremapcache;
break; break;
@ -5292,7 +5292,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 tamapcache = NEXTMAP_INVALID; static UINT16 tamapcache = NEXTMAP_INVALID;
if (tamapcache > nummapheaders) if (tamapcache > nummapheaders)
{ {
tamapcache = G_RandMap(G_TOLFlag(GT_RACE), -1, true, false, NULL); tamapcache = G_RandMap(G_TOLFlag(GT_RACE), UINT16_MAX, true, false, NULL);
} }
specialmap = tamapcache; specialmap = tamapcache;
break; break;
@ -5302,7 +5302,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 btcmapcache = NEXTMAP_INVALID; static UINT16 btcmapcache = NEXTMAP_INVALID;
if (btcmapcache > nummapheaders) if (btcmapcache > nummapheaders)
{ {
btcmapcache = G_RandMap(G_TOLFlag(GT_BATTLE), -1, true, false, NULL); btcmapcache = G_RandMap(G_TOLFlag(GT_BATTLE), UINT16_MAX, true, false, NULL);
} }
specialmap = btcmapcache; specialmap = btcmapcache;
break; break;
@ -5312,7 +5312,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 sscmapcache = NEXTMAP_INVALID; static UINT16 sscmapcache = NEXTMAP_INVALID;
if (sscmapcache > nummapheaders) if (sscmapcache > nummapheaders)
{ {
sscmapcache = G_RandMap(G_TOLFlag(GT_SPECIAL), -1, true, false, NULL); sscmapcache = G_RandMap(G_TOLFlag(GT_SPECIAL), UINT16_MAX, true, false, NULL);
} }
specialmap = sscmapcache; specialmap = sscmapcache;
break; break;
@ -5322,7 +5322,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 spbmapcache = NEXTMAP_INVALID; static UINT16 spbmapcache = NEXTMAP_INVALID;
if (spbmapcache > nummapheaders) if (spbmapcache > nummapheaders)
{ {
spbmapcache = G_RandMap(G_TOLFlag(GT_RACE), -1, true, false, NULL); spbmapcache = G_RandMap(G_TOLFlag(GT_RACE), UINT16_MAX, true, false, NULL);
} }
specialmap = spbmapcache; specialmap = spbmapcache;
break; break;
@ -5332,7 +5332,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 hardmapcache = NEXTMAP_INVALID; static UINT16 hardmapcache = NEXTMAP_INVALID;
if (hardmapcache > nummapheaders) if (hardmapcache > nummapheaders)
{ {
hardmapcache = G_RandMap(G_TOLFlag(GT_RACE), -1, true, false, NULL); hardmapcache = G_RandMap(G_TOLFlag(GT_RACE), UINT16_MAX, true, false, NULL);
} }
specialmap = hardmapcache; specialmap = hardmapcache;
break; break;
@ -5342,7 +5342,7 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
static UINT16 mastermapcache = NEXTMAP_INVALID; static UINT16 mastermapcache = NEXTMAP_INVALID;
if (mastermapcache > nummapheaders) if (mastermapcache > nummapheaders)
{ {
mastermapcache = G_RandMap(G_TOLFlag(GT_RACE), -1, true, false, NULL); mastermapcache = G_RandMap(G_TOLFlag(GT_RACE), UINT16_MAX, true, false, NULL);
} }
specialmap = mastermapcache; specialmap = mastermapcache;
break; break;

View file

@ -4999,8 +4999,8 @@ static void P_NetArchiveMisc(savebuffer_t *save, boolean resending)
for (i = 0; i < VOTE_NUM_LEVELS; i++) for (i = 0; i < VOTE_NUM_LEVELS; i++)
{ {
WRITEINT16(save->p, g_voteLevels[i][0]); WRITEUINT16(save->p, g_voteLevels[i][0]);
WRITEINT16(save->p, g_voteLevels[i][1]); WRITEUINT16(save->p, g_voteLevels[i][1]);
} }
for (i = 0; i < VOTE_TOTAL; i++) for (i = 0; i < VOTE_TOTAL; i++)
@ -5173,8 +5173,8 @@ static inline boolean P_NetUnArchiveMisc(savebuffer_t *save, boolean reloading)
for (i = 0; i < VOTE_NUM_LEVELS; i++) for (i = 0; i < VOTE_NUM_LEVELS; i++)
{ {
g_voteLevels[i][0] = READINT16(save->p); g_voteLevels[i][0] = READUINT16(save->p);
g_voteLevels[i][1] = READINT16(save->p); g_voteLevels[i][1] = READUINT16(save->p);
} }
for (i = 0; i < VOTE_TOTAL; i++) for (i = 0; i < VOTE_TOTAL; i++)

View file

@ -8045,8 +8045,6 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
G_SaveGameData(); G_SaveGameData();
} }
G_AddMapToBuffer(gamemap-1);
P_MapEnd(); // tm.thing is no longer needed from this point onwards P_MapEnd(); // tm.thing is no longer needed from this point onwards
// Took me 3 hours to figure out why my progression kept on getting overwritten with the titlemap... // Took me 3 hours to figure out why my progression kept on getting overwritten with the titlemap...