From 478f895ea0aab1120cc260809613f26c32253ee7 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Mon, 26 Nov 2018 04:27:31 -0500 Subject: [PATCH] Remove previous commit's votebuffer, allow an external optional buffer to be passed into G_RandMap I meant to fix the previous method, but I didn't even understand how it knew it was in a vote or not... so I just did it my own way :V (Shouldn't FLUSHMAPBUFFEREARLY be on now...?) --- src/d_netcmd.c | 11 ++++++++--- src/doomstat.h | 1 + src/f_finale.c | 2 +- src/g_game.c | 38 ++++++++++---------------------------- src/g_game.h | 2 +- src/m_menu.c | 2 +- 6 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4a08a1af..fc545763 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2076,6 +2076,7 @@ void D_SetupVote(void) UINT8 *p = buf; INT32 i; UINT8 secondgt = G_SometimesGetDifferentGametype(); + INT16 votebuffer[3] = {-1,-1,-1}; if (cv_kartencore.value && G_RaceGametype()) WRITEUINT8(p, (gametype|0x80)); @@ -2086,12 +2087,16 @@ void D_SetupVote(void) for (i = 0; i < 5; i++) { + UINT16 m; if (i == 2) // sometimes a different gametype - WRITEUINT16(p, G_RandMap(G_TOLFlag(secondgt), prevmap, false, 0, true)); + m = G_RandMap(G_TOLFlag(secondgt), prevmap, false, 0, true, votebuffer); else if (i >= 3) // unknown-random and force-unknown MAP HELL - WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, (i-2), (i < 4))); + m = G_RandMap(G_TOLFlag(gametype), prevmap, false, (i-2), (i < 4), votebuffer); else - WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, true)); + m = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, true, votebuffer); + if (i < 3) + votebuffer[i] = m; + WRITEUINT16(p, m); } SendNetXCmd(XD_SETUPVOTE, buf, p - buf); diff --git a/src/doomstat.h b/src/doomstat.h index 34456b32..3784145f 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -467,6 +467,7 @@ extern boolean comebackshowninfo; extern tic_t curlap, bestlap; extern INT16 votelevels[5][2]; +extern INT16 votebuffer[5]; extern SINT8 votes[MAXPLAYERS]; extern SINT8 pickedvote; diff --git a/src/f_finale.c b/src/f_finale.c index b84289be..eb6adae1 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1068,7 +1068,7 @@ void F_TitleScreenTicker(boolean run) return; }*/ - mapname = G_BuildMapName(G_RandMap(TOL_RACE, -2, false, 0, false)+1); + mapname = G_BuildMapName(G_RandMap(TOL_RACE, -2, false, 0, false, NULL)+1); numstaff = 1; while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",mapname,numstaff+1))) != LUMPERROR) diff --git a/src/g_game.c b/src/g_game.c index f9f156a8..04a540b8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -779,7 +779,7 @@ const char *G_BuildMapName(INT32 map) map = gamemap-1; else map = prevmap; - map = G_RandMap(G_TOLFlag(cv_newgametype.value), map, false, 0, false)+1; + map = G_RandMap(G_TOLFlag(cv_newgametype.value), map, false, 0, false, NULL)+1; } if (map < 100) @@ -3269,8 +3269,7 @@ static INT32 TOLMaps(INT16 tolflags) * \author Graue */ static INT16 *okmaps = NULL; -static INT16 votebuffer[3] = {-1, -1, -1}; -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon) +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 *extbuffer) { INT32 numokmaps = 0; INT16 ix, bufx; @@ -3299,24 +3298,18 @@ tryagain: if (!ignorebuffer) { - if (votebuffer[0] != -1) + if (extbuffer != NULL) { - if (ix == votebuffer[0]) - continue; - - for (bufx = 1; bufx < 3; bufx++) + for (bufx = 0; bufx < (INT16)(sizeof extbuffer); bufx++) { - if (votebuffer[bufx] == -1) // Rest of buffer SHOULD be empty + if (extbuffer[bufx] == -1) // Rest of buffer SHOULD be empty break; - if (ix == votebuffer[bufx]) + if (ix == extbuffer[bufx]) { isokmap = false; break; } } - - if (!isokmap) - continue; } for (bufx = 0; bufx < (maphell ? 3 : NUMMAPS); bufx++) @@ -3351,18 +3344,18 @@ tryagain: if (randmapbuffer[3] == -1) // Is the buffer basically empty? { ignorebuffer = true; // This will probably only help in situations where there's very few maps, but it's folly not to at least try it - goto tryagain; //return G_RandMap(tolflags, pprevmap, true, maphell, callagainsoon); + goto tryagain; } for (bufx = 3; bufx < NUMMAPS; bufx++) // Let's clear all but the three most recent maps... randmapbuffer[bufx] = -1; - goto tryagain; //return G_RandMap(tolflags, pprevmap, ignorebuffer, maphell, callagainsoon); + goto tryagain; } if (maphell) // Any wiggle room to loosen our restrictions here? { maphell--; - goto tryagain; //return G_RandMap(tolflags, pprevmap, true, maphell-1, callagainsoon); + goto tryagain; } ix = 0; // Sorry, none match. You get MAP01. @@ -3376,17 +3369,6 @@ tryagain: { Z_Free(okmaps); okmaps = NULL; - for (bufx = 0; bufx < 3; bufx++) - votebuffer[bufx] = -1; - } - else if (votebuffer[2] == -1) - { - for (bufx = 0; bufx < 3; bufx++) - if (votebuffer[bufx] == -1) - { - votebuffer[bufx] = ix; - break; - } } return ix; @@ -3548,7 +3530,7 @@ static void G_DoCompleted(void) if (cv_advancemap.value == 0) // Stay on same map. nextmap = prevmap; else if (cv_advancemap.value == 2) // Go to random map. - nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false); + nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false, NULL); } // We are committed to this map now. diff --git a/src/g_game.h b/src/g_game.h index 27f961d3..e29d4bbe 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -255,7 +255,7 @@ FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon); +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 votebuffer[5]); void G_AddMapToBuffer(INT16 map); #endif diff --git a/src/m_menu.c b/src/m_menu.c index 9b1eb62c..c9792948 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7454,7 +7454,7 @@ static void M_StartServer(INT32 choice) G_StopMetalDemo(); if (!cv_nextmap.value) - CV_SetValue(&cv_nextmap, G_RandMap(G_TOLFlag(cv_newgametype.value), -1, false, 0, false)+1); + CV_SetValue(&cv_nextmap, G_RandMap(G_TOLFlag(cv_newgametype.value), -1, false, 0, false, NULL)+1); if (cv_maxplayers.value < ssplayers+1) CV_SetValue(&cv_maxplayers, ssplayers+1);