Skip to content

Commit

Permalink
Add series clinch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdnk committed Aug 10, 2022
1 parent ef41e0f commit 225b2a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion documentation/docs/match_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ interface Get5Match {
"favored_percentage_text": string, // (15)
"team1": Get5MatchTeam | Get5MatchTeamFromFile, // (20)
"team2": Get5MatchTeam | Get5MatchTeamFromFile, // (21)
"cvars": { [key: string]: string } // (22)
"cvars": { [key: string]: string }, // (22)
"clinch_series": boolean // (32)
}
```

Expand Down Expand Up @@ -124,6 +125,8 @@ interface Get5Match {
31. _Optional_<br>Determines the starting sides for each map. If this array is shorter than `num_maps`, `side_type` will
determine the side-behavior of the remaining maps. Ignored if `skip_veto` is `false`.
<br><br>**`Default: undefined`**
32. _Optional_<br>If `false`, the entire map list will be played, regardless of score. If `true`, a series will be won
when the series score for a team exceeds the number of maps divided by two.<br><br>**`Default: true`**

!!! warning "SteamID64 in `.cfg` files"

Expand Down
12 changes: 9 additions & 3 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ ConVar g_CoachingEnabledCvar;
/** Series config game-state **/
int g_MapsToWin = 1; // Maps needed to win the series.
bool g_BO2Match = false;
bool g_SeriesCanClinch = true;
int g_RoundNumber = -1; // The round number, 0-indexed. -1 if the match is not live.
// The active map number, used by stats. Required as the calculated round number changes immediately
// as a map ends, but before the map changes to the next.
Expand Down Expand Up @@ -1175,17 +1176,18 @@ public Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast
int t1maps = g_TeamSeriesScores[Get5Team_1];
int t2maps = g_TeamSeriesScores[Get5Team_2];
int tiedMaps = g_TeamSeriesScores[Get5Team_None];
int remainingMaps = g_MapsToPlay.Length - t1maps - t2maps - tiedMaps;

float minDelay = float(GetTvDelay()) + MATCH_END_DELAY_AFTER_TV;

if (t1maps == t2maps) {
// As long as team scores are equal, we play until there are no maps left.
if (t1maps + t2maps + tiedMaps == g_MapsToPlay.Length) {
// As long as team scores are equal, we play until there are no maps left, regardless of clinch config.
if (remainingMaps <= 0) {
SeriesEndMessage(Get5Team_None);
DelayFunction(minDelay, EndSeries);
return Plugin_Continue;
}
} else {
} else if (g_SeriesCanClinch) {
// This adjusts for ties!
int actualMapsToWin = ((g_MapsToPlay.Length - tiedMaps) / 2) + 1;
if (t1maps == actualMapsToWin) {
Expand All @@ -1199,6 +1201,10 @@ public Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast
DelayFunction(minDelay, EndSeries);
return Plugin_Continue;
}
} else if (remainingMaps <= 0) {
SeriesEndMessage(t1maps > t2maps ? Get5Team_1 : Get5Team_2); // Tie handled in first if-block
DelayFunction(minDelay, EndSeries);
return Plugin_Continue;
}

if (t1maps > t2maps) {
Expand Down
1 change: 1 addition & 0 deletions scripting/get5/debug.sp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static void AddGlobalStateInfo(File f) {
f.WriteLine("g_SkipVeto = %d", g_SkipVeto);
f.WriteLine("g_MatchSideType = %d", g_MatchSideType);
f.WriteLine("g_InScrimMode = %d", g_InScrimMode);
f.WriteLine("g_SeriesCanClinch = %d", g_SeriesCanClinch);
f.WriteLine("g_HasKnifeRoundStarted = %d", g_HasKnifeRoundStarted);

f.WriteLine("g_MapChangePending = %d", g_MapChangePending);
Expand Down
5 changes: 5 additions & 0 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define CONFIG_SPECTATORSNAME_DEFAULT "casters"
#define CONFIG_NUM_MAPSDEFAULT 3
#define CONFIG_SKIPVETO_DEFAULT false
#define CONFIG_CLINCH_SERIES_DEFAULT true
#define CONFIG_VETOFIRST_DEFAULT "team1"
#define CONFIG_SIDETYPE_DEFAULT "standard"

Expand Down Expand Up @@ -305,6 +306,7 @@ public void WriteMatchToKv(KeyValues kv) {
kv.SetNum("min_players_to_ready", g_MinPlayersToReady);
kv.SetNum("min_spectators_to_ready", g_MinSpectatorsToReady);
kv.SetString("match_title", g_MatchTitle);
kv.SetNum("clinch_series", g_SeriesCanClinch);

kv.SetNum("favored_percentage_team1", g_FavoredTeamPercentage);
kv.SetString("favored_percentage_text", g_FavoredTeamText);
Expand Down Expand Up @@ -380,6 +382,7 @@ static bool LoadMatchFromKv(KeyValues kv) {
g_InScrimMode = kv.GetNum("scrim") != 0;
kv.GetString("match_title", g_MatchTitle, sizeof(g_MatchTitle), CONFIG_MATCHTITLE_DEFAULT);
g_PlayersPerTeam = kv.GetNum("players_per_team", CONFIG_PLAYERSPERTEAM_DEFAULT);
g_SeriesCanClinch = kv.GetNum("clinch_series", CONFIG_CLINCH_SERIES_DEFAULT) != 0;
g_CoachesPerTeam = kv.GetNum("coaches_per_team", CONFIG_COACHESPERTEAM_DEFAULT);
g_MinPlayersToReady = kv.GetNum("min_players_to_ready", CONFIG_MINPLAYERSTOREADY_DEFAULT);
g_MinSpectatorsToReady =
Expand Down Expand Up @@ -487,6 +490,7 @@ static bool LoadMatchFromJson(JSON_Object json) {
json_object_get_string_safe(json, "matchid", g_MatchID, sizeof(g_MatchID),
CONFIG_MATCHID_DEFAULT);
g_InScrimMode = json_object_get_bool_safe(json, "scrim", false);
g_SeriesCanClinch = json_object_get_bool_safe(json, "clinch_series", true);
json_object_get_string_safe(json, "match_title", g_MatchTitle, sizeof(g_MatchTitle),
CONFIG_MATCHTITLE_DEFAULT);

Expand Down Expand Up @@ -1042,6 +1046,7 @@ public Action Command_CreateMatch(int client, int args) {
kv.SetNum("maps_to_win", 1);
kv.SetNum("skip_veto", 1);
kv.SetNum("players_per_team", 5);
kv.SetNum("clinch_series", 1);

kv.JumpToKey("maplist", true);
kv.SetString(matchMap, KEYVALUE_STRING_PLACEHOLDER);
Expand Down

0 comments on commit 225b2a6

Please sign in to comment.