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