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