Add "allowdemos" option to K_CanChangeRules()

It's been used interchangably as "this is a singleplayer gameplay context" and "This is a no cvar changing context". This addition repairs some behaviour which might have been inconsistent between netgame and netreplay.
This commit is contained in:
toaster 2022-10-15 15:15:22 +01:00
parent e7f111c25a
commit ca2ecf6e9f
10 changed files with 32 additions and 29 deletions

View file

@ -4032,7 +4032,7 @@ void Schedule_Run(void)
return; return;
} }
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
// Don't engage in automation while in a restricted context. // Don't engage in automation while in a restricted context.
return; return;
@ -4168,7 +4168,7 @@ void Automate_Run(automateEvents_t type)
return; return;
} }
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
// Don't engage in automation while in a restricted context. // Don't engage in automation while in a restricted context.
return; return;
@ -4963,7 +4963,7 @@ UINT32 secretextratime = 0;
*/ */
static void TimeLimit_OnChange(void) static void TimeLimit_OnChange(void)
{ {
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
return; return;
} }
@ -6570,7 +6570,7 @@ static void Command_ShowTime_f(void)
// SRB2Kart: On change messages // SRB2Kart: On change messages
static void NumLaps_OnChange(void) static void NumLaps_OnChange(void)
{ {
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
return; return;
} }
@ -6588,7 +6588,7 @@ static void NumLaps_OnChange(void)
static void KartFrantic_OnChange(void) static void KartFrantic_OnChange(void)
{ {
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
return; return;
} }
@ -6606,7 +6606,7 @@ static void KartFrantic_OnChange(void)
static void KartSpeed_OnChange(void) static void KartSpeed_OnChange(void)
{ {
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
return; return;
} }
@ -6624,7 +6624,7 @@ static void KartSpeed_OnChange(void)
static void KartEncore_OnChange(void) static void KartEncore_OnChange(void)
{ {
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
return; return;
} }
@ -6634,7 +6634,7 @@ static void KartEncore_OnChange(void)
static void KartEliminateLast_OnChange(void) static void KartEliminateLast_OnChange(void)
{ {
if (K_CanChangeRules() == false) if (K_CanChangeRules(false) == false)
{ {
CV_StealthSet(&cv_karteliminatelast, cv_karteliminatelast.defaultvalue); CV_StealthSet(&cv_karteliminatelast, cv_karteliminatelast.defaultvalue);
} }

View file

@ -3920,7 +3920,7 @@ static void G_GetNextMap(void)
nextmap = cm; nextmap = cm;
} }
if (K_CanChangeRules()) if (K_CanChangeRules(true))
{ {
switch (cv_advancemap.value) switch (cv_advancemap.value)
{ {
@ -4013,8 +4013,9 @@ static void G_DoCompleted(void)
} }
} }
// See Y_StartIntermission timer handling
if ((gametyperules & GTR_CIRCUIT) && ((multiplayer && demo.playback) || j == r_splitscreen+1) && (!K_CanChangeRules(false) || cv_inttime.value > 0))
// play some generic music if there's no win/cool/lose music going on (for exitlevel commands) // play some generic music if there's no win/cool/lose music going on (for exitlevel commands)
if ((gametyperules & GTR_CIRCUIT) && ((multiplayer && demo.playback) || j == r_splitscreen+1) && (!K_CanChangeRules() || cv_inttime.value > 0))
S_ChangeMusicInternal("racent", true); S_ChangeMusicInternal("racent", true);
if (automapactive) if (automapactive)

View file

@ -127,7 +127,7 @@ void K_CheckBumpers(void)
winnerscoreadd -= players[i].roundscore; winnerscoreadd -= players[i].roundscore;
} }
if (K_CanChangeRules() == false) if (K_CanChangeRules(true) == false)
{ {
if (nobumpers) if (nobumpers)
{ {

View file

@ -697,18 +697,12 @@ void K_PlayerLoseLife(player_t *player)
} }
/*-------------------------------------------------- /*--------------------------------------------------
boolean K_CanChangeRules(void) boolean K_CanChangeRules(boolean allowdemos)
See header file for description. See header file for description.
--------------------------------------------------*/ --------------------------------------------------*/
boolean K_CanChangeRules(void) boolean K_CanChangeRules(boolean allowdemos)
{ {
if (demo.playback)
{
// We've already got our important settings!
return false;
}
if (grandprixinfo.gp == true && grandprixinfo.roundnum > 0) if (grandprixinfo.gp == true && grandprixinfo.roundnum > 0)
{ {
// Don't cheat the rules of the GP! // Don't cheat the rules of the GP!
@ -739,5 +733,11 @@ boolean K_CanChangeRules(void)
return false; return false;
} }
if (!allowdemos && demo.playback)
{
// We've already got our important settings!
return false;
}
return true; return true;
} }

View file

@ -152,18 +152,18 @@ void K_PlayerLoseLife(player_t *player);
/*-------------------------------------------------- /*--------------------------------------------------
boolean K_CanChangeRules(void); boolean K_CanChangeRules(boolean allowdemos);
Returns whenver or not the server is allowed Returns whenver or not the server is allowed
to change the game rules. to change the game rules.
Input Arguments:- Input Arguments:-
None allowdemos - permits this behavior during demo playback
Return:- Return:-
true if can change important gameplay rules, otherwise false. true if can change important gameplay rules, otherwise false.
--------------------------------------------------*/ --------------------------------------------------*/
boolean K_CanChangeRules(void); boolean K_CanChangeRules(boolean allowdemos);
#endif #endif

View file

@ -4400,7 +4400,7 @@ void M_InitOptions(INT32 choice)
// enable gameplay & server options under the right circumstances. // enable gameplay & server options under the right circumstances.
if (gamestate == GS_MENU if (gamestate == GS_MENU
|| ((server || IsPlayerAdmin(consoleplayer)) && K_CanChangeRules())) || ((server || IsPlayerAdmin(consoleplayer)) && K_CanChangeRules(false)))
{ {
OPTIONS_MainDef.menuitems[mopt_gameplay].status = IT_STRING | IT_SUBMENU; OPTIONS_MainDef.menuitems[mopt_gameplay].status = IT_STRING | IT_SUBMENU;
OPTIONS_MainDef.menuitems[mopt_server].status = IT_STRING | IT_SUBMENU; OPTIONS_MainDef.menuitems[mopt_server].status = IT_STRING | IT_SUBMENU;
@ -5736,7 +5736,7 @@ void M_OpenPauseMenu(void)
Dummymenuplayer_OnChange(); // Make sure the consvar is within bounds of the amount of splitscreen players we have. Dummymenuplayer_OnChange(); // Make sure the consvar is within bounds of the amount of splitscreen players we have.
if (K_CanChangeRules()) if (K_CanChangeRules(false))
{ {
PAUSE_Main[mpause_psetup].status = IT_STRING | IT_CALL; PAUSE_Main[mpause_psetup].status = IT_STRING | IT_CALL;

View file

@ -726,7 +726,7 @@ void P_CheckPointLimit(void)
if (exitcountdown) if (exitcountdown)
return; return;
if (!K_CanChangeRules()) if (!K_CanChangeRules(true))
return; return;
if (!cv_pointlimit.value) if (!cv_pointlimit.value)
@ -898,7 +898,7 @@ boolean P_CheckRacers(void)
{ {
tic_t countdown = 30*TICRATE; // 30 seconds left to finish, get going! tic_t countdown = 30*TICRATE; // 30 seconds left to finish, get going!
if (K_CanChangeRules() == true) if (K_CanChangeRules(true) == true)
{ {
// Custom timer // Custom timer
countdown = cv_countdowntime.value * TICRATE; countdown = cv_countdowntime.value * TICRATE;

View file

@ -3853,7 +3853,7 @@ static void P_InitGametype(void)
if (gametyperules & GTR_CIRCUIT) if (gametyperules & GTR_CIRCUIT)
{ {
if (K_CanChangeRules() && cv_numlaps.value if (K_CanChangeRules(true) && cv_numlaps.value
&& (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE)
|| (mapheaderinfo[gamemap - 1]->numlaps > cv_numlaps.value))) || (mapheaderinfo[gamemap - 1]->numlaps > cv_numlaps.value)))
{ {

View file

@ -1288,7 +1288,8 @@ void P_DoPlayerExit(player_t *player)
} }
} }
if (!K_CanChangeRules() || cv_inttime.value > 0) // See Y_StartIntermission timer handling
if (!K_CanChangeRules(false) || cv_inttime.value > 0)
P_EndingMusic(player); P_EndingMusic(player);
if (P_CheckRacers() && !exitcountdown) if (P_CheckRacers() && !exitcountdown)

View file

@ -801,7 +801,8 @@ void Y_StartIntermission(void)
powertype = K_UsingPowerLevels(); powertype = K_UsingPowerLevels();
// determine the tic the intermission ends // determine the tic the intermission ends
if (!K_CanChangeRules()) // Technically cv_inttime is saved to demos... but this permits having extremely long timers for post-netgame chatting without stranding you on the intermission in netreplays.
if (!K_CanChangeRules(false))
{ {
timer = 10*TICRATE; timer = 10*TICRATE;
} }