Skip to content

Commit

Permalink
Absolute ready timer (splewis#370)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rgoupil authored and splewis committed May 9, 2019
1 parent 1e71aef commit 61e2041
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
43 changes: 28 additions & 15 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -686,35 +686,48 @@ 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);

} else if (timeLeft < 300 && timeLeft % 30 == 0) {
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() {
Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/debug.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 61e2041

Please sign in to comment.