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