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