Skip to content

Commit

Permalink
Handle ties correctly (splewis#129)
Browse files Browse the repository at this point in the history
Turns out it was not just a matter of sending none through the api. Once
that was done, the tied map was no longer counted, and thus, the map
number never increased, and the series never ended.

This fixes that.
  • Loading branch information
miped authored and splewis committed Mar 23, 2017
1 parent b2747f8 commit f2a083b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
72 changes: 45 additions & 27 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -776,20 +776,22 @@ public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadca

public Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast) {
if (g_GameState == GameState_Live) {
// Figure out who won
int t1score = CS_GetTeamScore(MatchTeamToCSTeam(MatchTeam_Team1));
int t2score = CS_GetTeamScore(MatchTeamToCSTeam(MatchTeam_Team2));

MatchTeam winningTeam = MatchTeam_TeamNone;
if (t1score > t2score) {
winningTeam = MatchTeam_Team1;
} else if (t2score > t1score) {
winningTeam = MatchTeam_Team2;
}

// Update series scores
Stats_UpdateMapScore(winningTeam);
AddMapScore();
g_TeamSeriesScores[winningTeam]++;

// Handle map end
g_MapChangePending = true;
WriteBackup();

Expand All @@ -806,36 +808,44 @@ public Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast
Call_PushCell(GetMapNumber() - 1);
Call_Finish();

int t1maps = g_TeamSeriesScores[MatchTeam_Team1];
int t2maps = g_TeamSeriesScores[MatchTeam_Team2];
int tiedMaps = g_TeamSeriesScores[MatchTeam_TeamNone];

float minDelay = float(GetTvDelay()) + MATCH_END_DELAY_AFTER_TV;
if (g_TeamSeriesScores[MatchTeam_Team1] == g_MapsToWin) {
SeriesWonMessage(MatchTeam_Team1);

if (t1maps == g_MapsToWin) {
// Team 1 won
SeriesEndMessage(MatchTeam_Team1);
DelayFunction(minDelay, EndSeries);

} else if (g_TeamSeriesScores[MatchTeam_Team2] == g_MapsToWin) {
SeriesWonMessage(MatchTeam_Team2);
} else if (t2maps == g_MapsToWin) {
// Team 2 won
SeriesEndMessage(MatchTeam_Team2);
DelayFunction(minDelay, EndSeries);

} else if (t1maps == t2maps && t1maps + tiedMaps == g_MapsToWin) {
// The whole series was a tie
SeriesEndMessage(MatchTeam_TeamNone);
DelayFunction(minDelay, EndSeries);

} else if (g_BO2Match && GetMapNumber() == 2) {
SeriesWonMessage(MatchTeam_TeamNone);
// It was a bo2, and none of the teams got to 2
SeriesEndMessage(MatchTeam_TeamNone);
DelayFunction(minDelay, EndSeries);

} else {
if (g_TeamSeriesScores[MatchTeam_Team1] > g_TeamSeriesScores[MatchTeam_Team2]) {
Get5_MessageToAll("%t", "TeamWinningSeriesInfoMessage",
g_FormattedTeamNames[MatchTeam_Team1],
g_TeamSeriesScores[MatchTeam_Team1], g_TeamSeriesScores[MatchTeam_Team2]);
if (t1maps > t2maps) {
Get5_MessageToAll("%t", "TeamWinningSeriesInfoMessage", g_FormattedTeamNames[MatchTeam_Team1], t1maps, t2maps);

} else if (g_TeamSeriesScores[MatchTeam_Team2] > g_TeamSeriesScores[MatchTeam_Team1]) {
Get5_MessageToAll("%t", "TeamWinningSeriesInfoMessage",
g_FormattedTeamNames[MatchTeam_Team2],
g_TeamSeriesScores[MatchTeam_Team2], g_TeamSeriesScores[MatchTeam_Team1]);
} else if (t2maps > t1maps) {
Get5_MessageToAll("%t", "TeamWinningSeriesInfoMessage", g_FormattedTeamNames[MatchTeam_Team2], t2maps, t1maps);

} else {
Get5_MessageToAll("%t", "SeriesTiedInfoMessage", g_TeamSeriesScores[MatchTeam_Team1],
g_TeamSeriesScores[MatchTeam_Team1]);
Get5_MessageToAll("%t", "SeriesTiedInfoMessage", t1maps, t2maps);
}

int index = g_TeamSeriesScores[MatchTeam_Team1] + g_TeamSeriesScores[MatchTeam_Team2];
int index = GetMapNumber();
char nextMap[PLATFORM_MAX_PATH];
g_MapsToPlay.GetString(index, nextMap, sizeof(nextMap));

Expand All @@ -849,9 +859,14 @@ public Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast
return Plugin_Continue;
}

static void SeriesWonMessage(MatchTeam team) {
static void SeriesEndMessage(MatchTeam team) {
if (g_MapsToWin == 1) {
Get5_MessageToAll("%t", "TeamWonMatchInfoMessage", g_FormattedTeamNames[team]);
if (team == MatchTeam_TeamNone) {
Get5_MessageToAll("%t", "TeamTiedMatchInfoMessage", g_FormattedTeamNames[MatchTeam_Team1],
g_FormattedTeamNames[MatchTeam_Team2]);
} else {
Get5_MessageToAll("%t", "TeamWonMatchInfoMessage", g_FormattedTeamNames[team]);
}
} else {
if (team == MatchTeam_TeamNone) {
// BO2 split.
Expand Down Expand Up @@ -890,21 +905,24 @@ public void EndSeries() {
DelayFunction(10.0, KickClientsOnEnd);
StopRecording();

MatchTeam winningTeam = MatchTeam_Team1;
if (g_TeamSeriesScores[MatchTeam_Team2] > g_TeamSeriesScores[MatchTeam_Team1]) {
// Figure out who won
int t1maps = g_TeamSeriesScores[MatchTeam_Team1];
int t2maps = g_TeamSeriesScores[MatchTeam_Team2];

MatchTeam winningTeam = MatchTeam_TeamNone;
if (t1maps > t2maps) {
winningTeam = MatchTeam_Team1;
} else if (t2maps > t1maps) {
winningTeam = MatchTeam_Team2;
} else if (g_TeamSeriesScores[MatchTeam_Team1] == g_TeamSeriesScores[MatchTeam_Team2]) {
winningTeam = MatchTeam_TeamNone;
}

Stats_SeriesEnd(winningTeam);
EventLogger_SeriesEnd(winningTeam, g_TeamSeriesScores[MatchTeam_Team1],
g_TeamSeriesScores[MatchTeam_Team2]);
EventLogger_SeriesEnd(winningTeam, t1maps, t2maps);

Call_StartForward(g_OnSeriesResult);
Call_PushCell(winningTeam);
Call_PushCell(g_TeamSeriesScores[MatchTeam_Team1]);
Call_PushCell(g_TeamSeriesScores[MatchTeam_Team2]);
Call_PushCell(t1maps);
Call_PushCell(t2maps);
Call_Finish();

RestoreCvars(g_MatchConfigChangedCvars);
Expand Down
4 changes: 2 additions & 2 deletions scripting/get5/teamlogic.sp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ public int GetMapScore(int mapNumber, MatchTeam team) {
}

public bool HasMapScore(int mapNumber) {
return GetMapScore(mapNumber, MatchTeam_Team1) != 0 || GetMapScore(mapNumber, MatchTeam_Team2);
return GetMapScore(mapNumber, MatchTeam_Team1) != 0 || GetMapScore(mapNumber, MatchTeam_Team2) != 0;
}

public int GetMapNumber() {
return g_TeamSeriesScores[MatchTeam_Team1] + g_TeamSeriesScores[MatchTeam_Team2];
return g_TeamSeriesScores[MatchTeam_Team1] + g_TeamSeriesScores[MatchTeam_Team2] + g_TeamSeriesScores[MatchTeam_TeamNone];
}

public bool AddPlayerToTeam(const char[] auth, MatchTeam team) {
Expand Down
5 changes: 3 additions & 2 deletions scripting/get5_apistats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ public void Get5_OnRoundStatsUpdated() {
}

static int MapNumber() {
int t1, t2;
int t1, t2, n;
int buf;
Get5_GetTeamScores(MatchTeam_Team1, t1, buf);
Get5_GetTeamScores(MatchTeam_Team2, t2, buf);
return t1 + t2;
Get5_GetTeamScores(MatchTeam_TeamNone, n, buf);
return t1 + t2 + n;
}
5 changes: 5 additions & 0 deletions translations/get5.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
"#format" "{1:s}"
"en" "{1} has won the match."
}
"TeamTiedMatchInfoMessage"
{
"#format" "{1:s},{2:s}"
"en" "{1} and {2} have tied the match."
}
"TeamsSplitSeriesBO2InfoMessage"
{
"#format" "{1:s},{2:s}"
Expand Down

0 comments on commit f2a083b

Please sign in to comment.