From: bones_was_here <bones_was_here@xonotic.au>
Date: Mon, 26 Sep 2022 05:21:46 +0000 (+1000)
Subject: Remove AvailableTeams(), instead store team number in existing teamplay global
X-Git-Tag: xonotic-v0.8.6~348^2~13
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ed5169c17519c5cbbccc03044fe76f0f99da5b00;p=xonotic%2Fxonotic-data.pk3dir.git

Remove AvailableTeams(), instead store team number in existing teamplay global
---

diff --git a/qcsrc/common/gamemodes/sv_rules.qc b/qcsrc/common/gamemodes/sv_rules.qc
index 84d89909f..d7f5006d4 100644
--- a/qcsrc/common/gamemodes/sv_rules.qc
+++ b/qcsrc/common/gamemodes/sv_rules.qc
@@ -7,7 +7,7 @@ void GameRules_teams(bool value)
 {
     if (value) {
         serverflags |= SERVERFLAG_TEAMPLAY;
-        teamplay = 1;
+        teamplay = 1;  // aka AVAILABLE_TEAMS, updated by ScoreRules_basics() after team ents spawn
         cvar_set("teamplay", "2");  // DP needs this for sending proper getstatus replies.
         Team_InitTeams();
         GameRules_spawning_teams(true);
diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc
index 79b3a9692..01a66b2c1 100644
--- a/qcsrc/server/bot/default/bot.qc
+++ b/qcsrc/server/bot/default/bot.qc
@@ -170,7 +170,7 @@ void bot_setnameandstuff(entity this)
 		int smallest_count = -1;
 		if (teamplay)
 		{
-			for (int i = 1; i <= AvailableTeams(); ++i)
+			for (int i = 1; i <= AVAILABLE_TEAMS; ++i)
 			{
 				// NOTE if (autocvar_g_campaign && autocvar_g_campaign_forceteam == i)
 				// TeamBalance_GetNumberOfPlayers(balance, i); returns the number of players + 1
@@ -210,7 +210,7 @@ void bot_setnameandstuff(entity this)
 			});
 			if (!conflict)
 				prio += 1;
-			if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+			if (teamplay && !(autocvar_bot_vs_human && AVAILABLE_TEAMS == 2))
 			{
 				int forced_team = stof(argv(5));
 				if (!Team_IsValidIndex(forced_team))
@@ -242,7 +242,7 @@ void bot_setnameandstuff(entity this)
 	if(argv(4) != "" && stof(argv(4)) >= 0) bot_pants = argv(4);
 	else bot_pants = ftos(floor(random() * 15));
 
-	if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+	if (teamplay && !(autocvar_bot_vs_human && AVAILABLE_TEAMS == 2))
 	{
 		this.bot_forced_team = stof(argv(5));
 		if (!Team_IsValidIndex(this.bot_forced_team))
@@ -611,13 +611,13 @@ bool bot_fixcount(bool multiple_per_frame)
 	// But don't remove bots immediately on level change, as the real players
 	// usually haven't rejoined yet
 	bots_would_leave = false;
-	if (teamplay && autocvar_bot_vs_human && AvailableTeams() == 2)
+	if (autocvar_bot_vs_human && AVAILABLE_TEAMS == 2)
 		bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
 	else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
 	{
 		int minplayers = max(0, floor(autocvar_minplayers));
 		if (teamplay)
-			minplayers = max(0, floor(autocvar_minplayers_per_team) * AvailableTeams());
+			minplayers = max(0, floor(autocvar_minplayers_per_team) * AVAILABLE_TEAMS);
 		int minbots = max(0, floor(autocvar_bot_number));
 
 		// add bots to reach minplayers if needed
diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc
index 5843e02a3..8c974b28a 100644
--- a/qcsrc/server/client.qc
+++ b/qcsrc/server/client.qc
@@ -1150,7 +1150,7 @@ void ClientConnect(entity this)
 	if (!autocvar_sv_foginterval && world.fog != "")
 		stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
 
-	if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+	if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && AVAILABLE_TEAMS == 2))
 		if(!MUTATOR_CALLHOOK(HideTeamNagger, this))
 			send_CSQC_teamnagger();
 
diff --git a/qcsrc/server/intermission.qc b/qcsrc/server/intermission.qc
index e9c622be4..b2652f7d8 100644
--- a/qcsrc/server/intermission.qc
+++ b/qcsrc/server/intermission.qc
@@ -54,7 +54,7 @@ bool MapHasRightSize(string map)
 {
 	int minplayers = max(0, floor(autocvar_minplayers));
 	if (teamplay)
-		minplayers = max(0, floor(autocvar_minplayers_per_team) * AvailableTeams());
+		minplayers = max(0, floor(autocvar_minplayers_per_team) * AVAILABLE_TEAMS);
 	if (autocvar_g_maplist_check_waypoints
 		&& (currentbots || autocvar_bot_number || player_count < minplayers))
 	{
diff --git a/qcsrc/server/scores_rules.qc b/qcsrc/server/scores_rules.qc
index 2749db38e..64dfbb03b 100644
--- a/qcsrc/server/scores_rules.qc
+++ b/qcsrc/server/scores_rules.qc
@@ -19,11 +19,6 @@ int NumTeams(int teams)
 	return boolean(teams & BIT(0)) + boolean(teams & BIT(1)) + boolean(teams & BIT(2)) + boolean(teams & BIT(3));
 }
 
-int AvailableTeams()
-{
-	return NumTeams(ScoreRules_teams);
-}
-
 // NOTE: ST_constants may not be >= MAX_TEAMSCORE
 // scores that should be in all modes:
 void ScoreRules_basics(int teams, float sprio, float stprio, float score_enabled)
@@ -35,6 +30,7 @@ void ScoreRules_basics(int teams, float sprio, float stprio, float score_enabled
 		ScoreInfo_SetLabel_TeamScore(i, "", 0);
 
 	ScoreRules_teams = teams;
+	AVAILABLE_TEAMS = NumTeams(teams);
 
 	if(score_enabled)
 		ScoreInfo_SetLabel_TeamScore(ST_SCORE, "score", stprio);
diff --git a/qcsrc/server/scores_rules.qh b/qcsrc/server/scores_rules.qh
index 921864d26..2978c217e 100644
--- a/qcsrc/server/scores_rules.qh
+++ b/qcsrc/server/scores_rules.qh
@@ -2,7 +2,8 @@
 
 bool IsTeamAvailable(int team_num);
 int NumTeams(int teams);
-int AvailableTeams();
 void ScoreRules_basics(int teams, float sprio, float stprio, float score_enabled);
 void ScoreRules_basics_end();
 void ScoreRules_generic();
+
+#define AVAILABLE_TEAMS teamplay
diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc
index 0d248ca13..c7c939d74 100644
--- a/qcsrc/server/teamplay.qc
+++ b/qcsrc/server/teamplay.qc
@@ -527,7 +527,7 @@ entity TeamBalance_CheckAllowedTeams(entity for_whom)
 	}
 
 	// TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
-	if (autocvar_bot_vs_human && AvailableTeams() == 2 && for_whom)
+	if (autocvar_bot_vs_human && AVAILABLE_TEAMS == 2 && for_whom)
 	{
 		if (autocvar_bot_vs_human > 0)
 		{