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