From 61e20414aeb56b846050a1012249d3fde20e7eca Mon Sep 17 00:00:00 2001 From: rgoupil Date: Thu, 9 May 2019 06:15:48 +0200 Subject: [PATCH] Absolute ready timer (#370) * Ready timer is now shared by all teams and cannot be stalled by players * Styling changes * Put MatchTeam_None for stats forfeit to indicate that both team did not forfeit * Stats_Forfeit to MatchTeam_TeamNone to indicate that both team did not forfeit --- scripting/get5.sp | 43 +++++++++++++++++++++++------------ scripting/get5/debug.sp | 2 +- scripting/get5/matchconfig.sp | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/scripting/get5.sp b/scripting/get5.sp index 0a9f093b8..00636e32a 100644 --- a/scripting/get5.sp +++ b/scripting/get5.sp @@ -158,7 +158,7 @@ bool g_TeamGivenStopCommand[MatchTeam_Count]; bool g_InExtendedPause; int g_TeamPauseTimeUsed[MatchTeam_Count]; int g_TeamPausesUsed[MatchTeam_Count]; -int g_ReadyTimeWaitingUsed[MatchTeam_Count]; +int g_ReadyTimeWaitingUsed = 0; char g_DefaultTeamColors[][] = { TEAM1_COLOR, TEAM2_COLOR, "{NORMAL}", "{NORMAL}", }; @@ -607,7 +607,7 @@ public void OnMapStart() { g_TeamReadyForUnpause[team] = false; g_TeamPauseTimeUsed[team] = 0; g_TeamPausesUsed[team] = 0; - g_ReadyTimeWaitingUsed[team] = 0; + g_ReadyTimeWaitingUsed = 0; } if (g_WaitingForRoundBackup) { @@ -686,24 +686,37 @@ public Action Timer_CheckReady(Handle timer) { static void CheckReadyWaitingTimes() { if (g_TeamTimeToStartCvar.IntValue > 0) { - CheckReadyWaitingTime(MatchTeam_Team1); - CheckReadyWaitingTime(MatchTeam_Team2); + g_ReadyTimeWaitingUsed++; + + bool team1Forfeited = CheckReadyWaitingTime(MatchTeam_Team1); + bool team2Forfeited = CheckReadyWaitingTime(MatchTeam_Team2); + + if (team1Forfeited && team2Forfeited) { + g_ForcedWinner = MatchTeam_TeamNone; + Stats_Forfeit(MatchTeam_TeamNone); + } else if (team1Forfeited) { + g_ForcedWinner = MatchTeam_Team2; + Stats_Forfeit(MatchTeam_Team1); + } else if (team2Forfeited) { + g_ForcedWinner = MatchTeam_Team1; + Stats_Forfeit(MatchTeam_Team2); + } + + if (team1Forfeited || team2Forfeited) { + g_ForceWinnerSignal = true; + ChangeState(Get5State_None); + EndSeries(); + } } } -static void CheckReadyWaitingTime(MatchTeam team) { +static bool CheckReadyWaitingTime(MatchTeam team) { if (!IsTeamReady(team) && g_GameState != Get5State_None) { - g_ReadyTimeWaitingUsed[team]++; - int timeLeft = g_TeamTimeToStartCvar.IntValue - g_ReadyTimeWaitingUsed[team]; + int timeLeft = g_TeamTimeToStartCvar.IntValue - g_ReadyTimeWaitingUsed; if (timeLeft <= 0) { - g_ForceWinnerSignal = true; - g_ForcedWinner = (team == MatchTeam_Team1) ? MatchTeam_Team2 : MatchTeam_Team1; Get5_MessageToAll("%t", "TeamForfeitInfoMessage", g_FormattedTeamNames[team]); - ChangeState(Get5State_None); - Stats_Forfeit(team); - EndSeries(); - + return true; } else if (timeLeft >= 300 && timeLeft % 60 == 0) { Get5_MessageToAll("%t", "MinutesToForfeitMessage", g_FormattedTeamNames[team], timeLeft / 60); @@ -711,10 +724,10 @@ static void CheckReadyWaitingTime(MatchTeam team) { Get5_MessageToAll("%t", "SecondsToForfeitInfoMessage", g_FormattedTeamNames[team], timeLeft); } else if (timeLeft == 10) { - Get5_MessageToAll("%t", "10SecondsToForfeitInfoMessage", g_FormattedTeamNames[team], - timeLeft); + Get5_MessageToAll("%t", "10SecondsToForfeitInfoMessage", g_FormattedTeamNames[team], timeLeft); } } + return false; } static void CheckAutoLoadConfig() { diff --git a/scripting/get5/debug.sp b/scripting/get5/debug.sp index 9b247c170..5c710f412 100644 --- a/scripting/get5/debug.sp +++ b/scripting/get5/debug.sp @@ -114,6 +114,7 @@ static void AddGlobalStateInfo(File f) { f.WriteLine("g_WaitingForRoundBackup = %d", g_WaitingForRoundBackup); f.WriteLine("g_SavedValveBackup = %d", g_SavedValveBackup); f.WriteLine("g_DoingBackupRestoreNow = %d", g_DoingBackupRestoreNow); + f.WriteLine("g_ReadyTimeWaitingUsed = %d", g_ReadyTimeWaitingUsed); LOOP_TEAMS(team) { GetTeamString(team, buffer, sizeof(buffer)); @@ -133,7 +134,6 @@ static void AddGlobalStateInfo(File f) { f.WriteLine("g_TeamStartingSide = %d", g_TeamStartingSide[team]); f.WriteLine("g_TeamPauseTimeUsed = %d", g_TeamPauseTimeUsed[team]); f.WriteLine("g_TeamPausesUsed = %d", g_TeamPausesUsed[team]); - f.WriteLine("g_ReadyTimeWaitingUsed = %d", g_ReadyTimeWaitingUsed[team]); } } diff --git a/scripting/get5/matchconfig.sp b/scripting/get5/matchconfig.sp index 18c9e386e..7a0994989 100644 --- a/scripting/get5/matchconfig.sp +++ b/scripting/get5/matchconfig.sp @@ -22,10 +22,10 @@ stock bool LoadMatchConfig(const char[] config, bool restoreBackup = false) { g_TeamGivenStopCommand[team] = false; g_TeamPauseTimeUsed[team] = 0; g_TeamPausesUsed[team] = 0; - g_ReadyTimeWaitingUsed[team] = 0; ClearArray(GetTeamAuths(team)); } + g_ReadyTimeWaitingUsed = 0; g_ForceWinnerSignal = false; g_ForcedWinner = MatchTeam_TeamNone;