]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/teamplay.qh
Don't attempt to network more than the maximum number of shown spectators, fixes...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qh
1 #pragma once
2
3 int autocvar_teamplay_mode;
4
5 bool autocvar_g_changeteam_banned;
6 bool autocvar_teamplay_lockonrestart;
7
8 bool autocvar_g_balance_teams;
9 bool autocvar_g_balance_teams_prevent_imbalance;
10
11 bool lockteams;
12
13 // ========================== Global teams API ================================
14
15 /// \brief Returns the global team entity at the given index.
16 /// \param[in] index Index of the team.
17 /// \return Global team entity at the given index.
18 entity Team_GetTeamFromIndex(int index);
19
20 /// \brief Returns the global team entity that corresponds to the given TEAM_NUM
21 /// value.
22 /// \param[in] team_num Team value. See TEAM_NUM constants.
23 /// \return Global team entity that corresponds to the given TEAM_NUM value.
24 entity Team_GetTeam(int team_num);
25
26 // ========================= Team specific API ================================
27
28 /// \brief Returns the score of the team.
29 /// \param[in] team_ent Team entity.
30 /// \return Score of the team.
31 float Team_GetTeamScore(entity team_ent);
32
33 /// \brief Sets the score of the team.
34 /// \param[in,out] team_ent Team entity.
35 /// \param[in] score Score to set.
36 void Team_SetTeamScore(entity team_ent, float score);
37
38 /// \brief Returns the number of alive players in a team.
39 /// \param[in] team_ent Team entity.
40 /// \return Number of alive players in a team.
41 int Team_GetNumberOfAlivePlayers(entity team_ent);
42
43 /// \brief Sets the number of alive players in a team.
44 /// \param[in,out] team_ent Team entity.
45 /// \param[in] number Number of players to set.
46 void Team_SetNumberOfAlivePlayers(entity team_ent, int number);
47
48 /// \brief Returns the number of alive teams.
49 /// \return Number of alive teams.
50 int Team_GetNumberOfAliveTeams();
51
52 /// \brief Returns the number of control points owned by a team.
53 /// \param[in] team_ent Team entity.
54 /// \return Number of control points owned by a team.
55 int Team_GetNumberOfControlPoints(entity team_ent);
56
57 /// \brief Sets the number of control points owned by a team.
58 /// \param[in,out] team_ent Team entity.
59 /// \param[in] number Number of control points to set.
60 void Team_SetNumberOfControlPoints(entity team_ent, int number);
61
62 /// \brief Returns the number of teams that own control points.
63 /// \return Number of teams that own control points.
64 int Team_GetNumberOfTeamsWithControlPoints();
65
66 // ======================= Entity specific API ================================
67
68 void setcolor(entity this, int clr);
69
70 /// \brief Returns whether the given entity belongs to a valid team.
71 /// \param[in] this Entity to check.
72 /// \return True if entity belongs to a valid team, false otherwise.
73 bool Entity_HasValidTeam(entity this);
74
75 /// \brief Returns the team index of the given entity.
76 /// \param[in] this Entity to check.
77 /// \return Team index of the entity.
78 int Entity_GetTeamIndex(entity this);
79
80 /// \brief Returns the team entity of the given entity.
81 /// \param[in] this Entity to check.
82 /// \return Team entity of the given entity or NULL if the entity doesn't belong
83 /// to any team.
84 entity Entity_GetTeam(entity this);
85
86 void SetPlayerColors(entity player, float _color);
87
88 /// \brief Sets the team of the player using its index.
89 /// \param[in,out] player Player to adjust.
90 /// \param[in] index Index of the team to set.
91 /// \return True if team switch was successful, false otherwise.
92 bool Player_SetTeamIndex(entity player, int index);
93
94 enum
95 {
96         TEAM_CHANGE_AUTO = 2, ///< The team was selected by autobalance.
97         TEAM_CHANGE_MANUAL = 3, ///< Player has manually selected their team.
98         TEAM_CHANGE_SPECTATOR = 4 ///< Player is joining spectators. //TODO: Remove?
99 };
100
101 /// \brief Sets the team of the player.
102 /// \param[in,out] player Player to adjust.
103 /// \param[in] team_index Index of the team to set.
104 /// \param[in] type Type of the team change. See TEAM_CHANGE constants.
105 /// \return True if team switch was successful, false otherwise.
106 bool SetPlayerTeam(entity player, int team_index, int type);
107
108 /// \brief Sets the team of the player with all sanity checks.
109 /// \param[in,out] player Player to adjust.
110 /// \param[in] team_index Index of the team to set.
111 void Player_SetTeamIndexChecked(entity player, int team_index);
112
113 /// \brief Moves player to the specified team.
114 /// \param[in,out] client Client to move.
115 /// \param[in] team_index Index of the team.
116 /// \param[in] type ???
117 /// \return True on success, false otherwise.
118 bool MoveToTeam(entity client, int team_index, int type);
119
120 enum
121 {
122         TEAM_FORCE_SPECTATOR = -1, ///< Force the player to spectator team.
123         TEAM_FORCE_DEFAULT = 0 ///< Don't force any team.
124 };
125
126 /// \brief Returns whether player has real forced team. Spectator team is
127 /// ignored.
128 /// \param[in] player Player to check.
129 /// \return True if player has real forced team, false otherwise.
130 bool Player_HasRealForcedTeam(entity player);
131
132 /// \brief Returns the index of the forced team of the given player.
133 /// \param[in] player Player to check.
134 /// \return Index of the forced team.
135 int Player_GetForcedTeamIndex(entity player);
136
137 /// \brief Sets the index of the forced team of the given player.
138 /// \param[in,out] player Player to adjust.
139 /// \param[in] team_index Index of the team to set.
140 void Player_SetForcedTeamIndex(entity player, int team_index);
141
142 /// \brief Determines the forced team of the player using current global config.
143 /// \param[in,out] player Player to adjust.
144 void Player_DetermineForcedTeam(entity player);
145
146 // ========================= Team balance API =================================
147
148 /// \brief Assigns the given player to a team that will make the game most
149 /// balanced.
150 /// \param[in,out] player Player to assign.
151 void TeamBalance_JoinBestTeam(entity player);
152
153 /// \brief Checks whether the player can join teams according to global
154 /// configuration and mutator settings.
155 /// \param[in] for_whom Player to check for. Pass NULL for global rules.
156 /// \return Team balance entity that holds information about teams. This entity
157 /// will be automatically destroyed on the next frame but you are encouraged to
158 /// manually destroy it by calling TeamBalance_Destroy for performance reasons.
159 entity TeamBalance_CheckAllowedTeams(entity for_whom);
160
161 /// \brief Destroy the team balance entity.
162 /// \param[in,out] balance Team balance entity to destroy.
163 /// \note Team balance entity is allowed to be NULL.
164 void TeamBalance_Destroy(entity balance);
165
166 /// \brief Returns the bitmask of allowed teams.
167 /// \param[in] balance Team balance entity.
168 /// \return Bitmask of allowed teams.
169 int TeamBalance_GetAllowedTeams(entity balance);
170
171 /// \brief Returns whether the team change to the specified team is allowed.
172 /// \param[in] balance Team balance entity.
173 /// \param[in] index Index of the team.
174 /// \return True if team change to the specified team is allowed, false
175 /// otherwise.
176 bool TeamBalance_IsTeamAllowed(entity balance, int index);
177
178 /// \brief Counts the number of players and various other information about
179 /// each team.
180 /// \param[in,out] balance Team balance entity.
181 /// \param[in] ignore Player to ignore. This is useful if you plan to switch the
182 /// player's team. Pass NULL for global information.
183 /// \note This function updates the internal state of the team balance entity.
184 void TeamBalance_GetTeamCounts(entity balance, entity ignore);
185
186 /// \brief Returns the number of players (both humans and bots) in a team.
187 /// \param[in] balance Team balance entity.
188 /// \param[in] index Index of the team.
189 /// \return Number of player (both humans and bots) in a team.
190 /// \note You need to call TeamBalance_GetTeamCounts before calling this
191 /// function.
192 int TeamBalance_GetNumberOfPlayers(entity balance, int index);
193
194 /// \brief Finds the team that will make the game most balanced if the player
195 /// joins it.
196 /// \param[in] balance Team balance entity.
197 /// \param[in] player Player to check.
198 /// \param[in] ignore_player ???
199 /// \return Index of the team that will make the game most balanced if the
200 /// player joins it. If there are several equally good teams available, the
201 /// function will pick a random one.
202 int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player);
203
204 /// \brief Returns the bitmask of the teams that will make the game most
205 /// balanced if the player joins any of them.
206 /// \param[in] balance Team balance entity.
207 /// \param[in] player Player to check.
208 /// \param[in] use_score Whether to take into account team scores.
209 /// \return Bitmask of the teams that will make the game most balanced if the
210 /// player joins any of them.
211 /// \note You need to call TeamBalance_GetTeamCounts before calling this
212 /// function.
213 int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score);
214
215 /// \brief Describes the result of comparing teams.
216 enum
217 {
218         TEAMS_COMPARE_INVALID, ///< One or both teams are invalid.
219         TEAMS_COMPARE_LESS, ///< First team is less than the second one.
220         TEAMS_COMPARE_EQUAL, ///< Both teams are equal.
221         TEAMS_COMPARE_GREATER ///< First team the greater than the second one.
222 };
223
224 /// \brief Compares two teams for the purposes of game balance.
225 /// \param[in] balance Team balance entity.
226 /// \param[in] team_index_a Index of the first team.
227 /// \param[in] team_index_b Index of the second team.
228 /// \param[in] player Player to check.
229 /// \param[in] use_score Whether to take into account team scores.
230 /// \return TEAMS_COMPARE value. See above.
231 /// \note You need to call TeamBalance_GetTeamCounts before calling this
232 /// function.
233 int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
234         entity player, bool use_score);
235
236 /// \brief Switches a bot from one team to another if teams are not balanced.
237 void TeamBalance_AutoBalanceBots();
238
239 /// \brief Returns the index of the team with most players that is contained in
240 /// the given bitmask of teams.
241 /// \param[in] balance Team balance entity.
242 /// \param[in] teams Bitmask of teams to search in.
243 /// \return Index of the team with most players.
244 int TeamBalance_GetLargestTeamIndex(entity balance, int teams);
245
246 /// \brief Returns the player who is the most suitable for switching between
247 /// the given teams.
248 /// \param[in] source_team_index Index of the team to search in.
249 /// \param[in] destination_team_index Index of the team to switch to.
250 /// \param[in] is_bot True to search for bot, false for human.
251 /// \return Player who is the most suitable for switching between the given
252 /// teams or NULL if not found.
253 entity TeamBalance_GetPlayerForTeamSwitch(int source_team_index,
254         int destination_team_index, bool is_bot);
255
256 // ============================ Internal API ==================================
257
258 void LogTeamChange(float player_id, float team_number, int type);
259
260 /// \brief Kills player as a result of team change.
261 /// \param[in,out] player Player to kill.
262 void KillPlayerForTeamChange(entity player);
263
264 /// \brief Returns whether the team change to the specified team is allowed.
265 /// \param[in] balance Team balance entity.
266 /// \param[in] index Index of the team.
267 /// \return True if team change to the specified team is allowed, false
268 /// otherwise.
269 /// \note This function bypasses all the sanity checks.
270 bool TeamBalance_IsTeamAllowedInternal(entity balance, int index);
271
272 /// \brief Bans team change to all teams except the given one.
273 /// \param[in,out] balance Team balance entity.
274 /// \param[in] index Index of the team.
275 void TeamBalance_BanTeamsExcept(entity balance, int index);
276
277 /// \brief Returns the team entity of the team balance entity at the given
278 /// index.
279 /// \param[in] balance Team balance entity.
280 /// \param[in] index Index of the team.
281 /// \return Team entity of the team balance entity at the given index.
282 entity TeamBalance_GetTeamFromIndex(entity balance, int index);
283
284 /// \brief Returns the team entity of the team balance entity that corresponds
285 /// to the given TEAM_NUM value.
286 /// \param[in] balance Team balance entity.
287 /// \param[in] team_num Team value. See TEAM_NUM constants.
288 /// \return Team entity of the team balance entity that corresponds to the given
289 /// TEAM_NUM value.
290 entity TeamBalance_GetTeam(entity balance, int team_num);
291
292 /// \brief Returns whether the team is allowed.
293 /// \param[in] team_ent Team entity.
294 /// \return True if team is allowed, false otherwise.
295 bool TeamBalanceTeam_IsAllowed(entity team_ent);
296
297 /// \brief Returns the number of players (both humans and bots) in a team.
298 /// \param[in] team_ent Team entity.
299 /// \return Number of player (both humans and bots) in a team.
300 /// \note You need to call TeamBalance_GetTeamCounts before calling this
301 /// function.
302 int TeamBalanceTeam_GetNumberOfPlayers(entity team_ent);
303
304 /// \brief Returns the number of bots in a team.
305 /// \param[in] team_ent Team entity.
306 /// \return Number of bots in a team.
307 /// \note You need to call TeamBalance_GetTeamCounts before calling this
308 /// function.
309 int TeamBalanceTeam_GetNumberOfBots(entity team_ent);
310
311 /// \brief Compares two teams for the purposes of game balance.
312 /// \param[in] team_a First team.
313 /// \param[in] team_b Second team.
314 /// \param[in] player Player to check.
315 /// \param[in] use_score Whether to take into account team scores.
316 /// \return TEAMS_COMPARE value. See above.
317 /// \note You need to call TeamBalance_GetTeamCounts before calling this
318 /// function.
319 int TeamBalance_CompareTeamsInternal(entity team_a, entity team_index_b,
320         entity player, bool use_score);
321
322 /// \brief Called when the player connects or when they change their color with
323 /// the "color" command.
324 /// \param[in,out] player Player that requested a new color.
325 /// \param[in] new_color Requested color.
326 void SV_ChangeTeam(entity player, int new_color);