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