From 2e19dfd740b97117c5e6a4f122f3346ead396a99 Mon Sep 17 00:00:00 2001 From: z411 Date: Thu, 18 Nov 2021 12:40:12 -0300 Subject: [PATCH] Soft reset: Fix warmup limit and repeatable restart --- qcsrc/client/hud/panel/timer.qc | 2 +- qcsrc/server/command/sv_cmd.qc | 6 ++---- qcsrc/server/command/vote.qc | 25 ++++++++++++++++--------- qcsrc/server/main.qc | 4 ++-- qcsrc/server/world.qc | 2 +- qcsrc/server/world.qh | 2 +- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/qcsrc/client/hud/panel/timer.qc b/qcsrc/client/hud/panel/timer.qc index 0cdfefa78..f1c4dcfe8 100644 --- a/qcsrc/client/hud/panel/timer.qc +++ b/qcsrc/client/hud/panel/timer.qc @@ -51,7 +51,7 @@ void HUD_Timer() { float warmup_timelimit = STAT(WARMUP_TIMELIMIT); if(warmup_timelimit > 0) - warmup_timeleft = max(0, warmup_timelimit - time); + warmup_timeleft = max(0, warmup_timelimit - time + STAT(GAMESTARTTIME)); else if(warmup_timelimit == 0) warmup_timeleft = timeleft; warmup_timeleft = ceil(warmup_timeleft); diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index e1070ad9a..3e4195e50 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -163,8 +163,7 @@ void GameCommand_allready(int request) { if(warmup_stage) { - warmup_stage = 0; - ReadyRestart(); + ReadyRestart(true); } else LOG_INFO("Not in warmup."); @@ -1313,8 +1312,7 @@ void GameCommand_reset(int request) { case CMD_REQUEST_COMMAND: { - warmup_stage = cvar("g_warmup"); - ReadyRestart(); + ReadyRestart(false); return; } diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 6276d2e3c..ec8011a8f 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -437,10 +437,15 @@ void ReadyRestart_force() cvar_set("timelimit", ftos(autocvar_timelimit - (checkrules_overtimesadded * autocvar_timelimit_overtime))); checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0; - if(!warmup_stage) + if(warmup_stage) { + // Warmup: No countdown in warmup + game_starttime = time; + readyrestart_happened = false; + } else { + // Go into match mode + readyrestart_happened = true; game_starttime = time + RESTART_COUNTDOWN; - else - game_starttime = time; // No countdown in warmup + } // clear player attributes FOREACH_CLIENT(IS_PLAYER(it), { @@ -483,7 +488,7 @@ void ReadyRestart_force() if (autocvar_sv_eventlog) GameLogEcho(":restart"); } -void ReadyRestart() +void ReadyRestart(bool endWarmup) { if (MUTATOR_CALLHOOK(ReadyRestart_Deny) || intermission_running || race_completing) localcmd("restart\n"); else localcmd("\nsv_hook_readyrestart\n"); @@ -491,6 +496,12 @@ void ReadyRestart() // Reset ALL scores, but only do that at the beginning of the countdown if sv_ready_restart_after_countdown is off! // Otherwise scores could be manipulated during the countdown. if (!sv_ready_restart_after_countdown) Score_ClearAll(); + + if(endWarmup) + warmup_stage = 0; // forcefully end warmup and go to match stage + else + warmup_stage = cvar("g_warmup"); // go into warmup if it's enabled, otherwise restart into match stage anyway + ReadyRestart_force(); } @@ -512,11 +523,7 @@ void ReadyCount() ready_needed_factor = bound(0.5, cvar("g_warmup_majority_factor"), 0.999); ready_needed_count = floor(t_players * ready_needed_factor) + 1; - if (readycount >= ready_needed_count) - { - warmup_stage = 0; - ReadyRestart(); - } + if (readycount >= ready_needed_count) ReadyRestart(true); } diff --git a/qcsrc/server/main.qc b/qcsrc/server/main.qc index cf91b9de4..2b29422b8 100644 --- a/qcsrc/server/main.qc +++ b/qcsrc/server/main.qc @@ -331,8 +331,8 @@ void StartFrame() CreatureFrame_All(); CheckRules_World(); - if (warmup_stage && !game_stopped && warmup_limit > 0 && time >= warmup_limit) { - ReadyRestart(); + if (warmup_stage && !game_stopped && warmup_limit > 0 && time - game_starttime >= warmup_limit) { + ReadyRestart(true); return; } diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 02c059ea8..e2f2fd32b 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -1644,7 +1644,7 @@ void CheckRules_World() if(readyplayers || playerswithlaps >= 2) { checkrules_suddendeathend = 0; - ReadyRestart(); // go to race + ReadyRestart(true); // go to race return; } else diff --git a/qcsrc/server/world.qh b/qcsrc/server/world.qh index bdaac8c27..e87edd6af 100644 --- a/qcsrc/server/world.qh +++ b/qcsrc/server/world.qh @@ -134,7 +134,7 @@ const int WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath float WinningCondition_Scores(float limit, float leadlimit); void SetWinners(.float field, float value); -void ReadyRestart(); +void ReadyRestart(bool endWarmup); void DumpStats(float final); -- 2.39.2