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