]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/teamplay.qh
Improved MoveToTeam.
[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_ Team entity.
22 /// \return Score of the team.
23 float Team_GetTeamScore(entity team_);
24
25 /// \brief Sets the score of the team.
26 /// \param[in,out] team_ Team entity.
27 /// \param[in] score Score to set.
28 void Team_SetTeamScore(entity team_, float score);
29
30 /// \brief Returns the number of alive players in a team.
31 /// \param[in] team_ Team entity.
32 /// \return Number of alive players in a team.
33 int Team_GetNumberOfAlivePlayers(entity team_);
34
35 /// \brief Sets the number of alive players in a team.
36 /// \param[in,out] team_ Team entity.
37 /// \param[in] number Number of players to set.
38 void Team_SetNumberOfAlivePlayers(entity team_, 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_ Team entity.
46 /// \return Number of control points owned by a team.
47 int Team_GetNumberOfControlPoints(entity team_);
48
49 /// \brief Sets the number of control points owned by a team.
50 /// \param[in,out] team_ Team entity.
51 /// \param[in] number Number of control points to set.
52 void Team_SetNumberOfControlPoints(entity team_, 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 void TeamchangeFrags(entity e);
59
60 void LogTeamchange(float player_id, float team_number, float type);
61
62 // ======================= Entity specific API ================================
63
64 void setcolor(entity this, int clr);
65
66 /// \brief Returns whether the given entity belongs to a valid team.
67 /// \param[in] this Entity to check.
68 /// \return True if entity belongs to a valid team, false otherwise.
69 bool Entity_HasValidTeam(entity this);
70
71 /// \brief Returns the team index of the given entity.
72 /// \param[in] this Entity to check.
73 /// \return Team index of the entity.
74 int Entity_GetTeamIndex(entity this);
75
76 /// \brief Returns the team entity of the given entity.
77 /// \param[in] this Entity to check.
78 /// \return Team entity of the given entity.
79 entity Entity_GetTeam(entity this);
80
81 void SetPlayerColors(entity player, float _color);
82
83 /// \brief Sets the team of the player using its index.
84 /// \param[in,out] player Player to adjust.
85 /// \param[in] index Index of the team to set.
86 /// \return True if team switch was successful, false otherwise.
87 bool Player_SetTeamIndex(entity player, int index);
88
89 /// \brief Sets the team of the player.
90 /// \param[in,out] player Player to adjust.
91 /// \param[in] destination_team_index Index of the team to set.
92 /// \param[in] source_team_index Previous index of the team of the player.
93 /// \param[in] no_print Whether to print this event to players' console.
94 /// \return True if team switch was successful, false otherwise.
95 bool SetPlayerTeam(entity player, int destination_team_index,
96         int source_team_index, bool no_print);
97
98 /// \brief Moves player to the specified team.
99 /// \param[in,out] client Client to move.
100 /// \param[in] team_index Index of the team.
101 /// \param[in] type ???
102 /// \return True on success, false otherwise.
103 bool MoveToTeam(entity client, int team_index, float type);
104
105 /// \brief Kills player as a result of team change.
106 /// \param[in,out] player Player to kill.
107 void KillPlayerForTeamChange(entity player);
108
109 // ========================= Team balance API =================================
110
111 /// \brief Checks whether the player can join teams according to global
112 /// configuration and mutator settings.
113 /// \param[in] for_whom Player to check for. Pass NULL for global rules.
114 /// \return Team balance entity that holds information about teams. This entity
115 /// must be manually destroyed by calling TeamBalance_Destroy.
116 entity TeamBalance_CheckAllowedTeams(entity for_whom);
117
118 /// \brief Destroy the team balance entity.
119 /// \param[in,out] balance Team balance entity to destroy.
120 /// \note Team balance entity is allowed to be NULL.
121 void TeamBalance_Destroy(entity balance);
122
123 /// \brief Returns the bitmask of allowed teams.
124 /// \param[in] balance Team balance entity.
125 /// \return Bitmask of allowed teams.
126 int TeamBalance_GetAllowedTeams(entity balance);
127
128 /// \brief Returns whether the team change to the specified team is allowed.
129 /// \param[in] balance Team balance entity.
130 /// \param[in] index Index of the team.
131 /// \return True if team change to the specified team is allowed, false
132 /// otherwise.
133 bool TeamBalance_IsTeamAllowed(entity balance, int index);
134
135 /// \brief Counts the number of players and various other information about
136 /// each team.
137 /// \param[in,out] balance Team balance entity.
138 /// \param[in] ignore Player to ignore. This is useful if you plan to switch the
139 /// player's team. Pass NULL for global information.
140 /// \note This function updates the internal state of the team balance entity.
141 void TeamBalance_GetTeamCounts(entity balance, entity ignore);
142
143 /// \brief Returns the number of players (both humans and bots) in a team.
144 /// \param[in] balance Team balance entity.
145 /// \param[in] index Index of the team.
146 /// \return Number of player (both humans and bots) in a team.
147 /// \note You need to call TeamBalance_GetTeamCounts before calling this
148 /// function.
149 int TeamBalance_GetNumberOfPlayers(entity balance, int index);
150
151 /// \brief Finds the team that will make the game most balanced if the player
152 /// joins it.
153 /// \param[in] balance Team balance entity.
154 /// \param[in] player Player to check.
155 /// \param[in] ignore_player ???
156 /// \return Index of the team that will make the game most balanced if the
157 /// player joins it. If there are several equally good teams available, the
158 /// function will pick a random one.
159 int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player);
160
161 /// \brief Returns the bitmask of the teams that will make the game most
162 /// balanced if the player joins any of them.
163 /// \param[in] balance Team balance entity.
164 /// \param[in] player Player to check.
165 /// \param[in] use_score Whether to take into account team scores.
166 /// \return Bitmask of the teams that will make the game most balanced if the
167 /// player joins any of them.
168 /// \note You need to call TeamBalance_GetTeamCounts before calling this
169 /// function.
170 int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score);
171
172 void TeamBalance_JoinBestTeam(entity this, bool force_best_team);
173
174 /// \brief Describes the result of comparing teams.
175 enum
176 {
177         TEAMS_COMPARE_INVALID, ///< One or both teams are invalid.
178         TEAMS_COMPARE_LESS, ///< First team is less than the second one.
179         TEAMS_COMPARE_EQUAL, ///< Both teams are equal.
180         TEAMS_COMPARE_GREATER ///< First team the greater than the second one.
181 };
182
183 /// \brief Compares two teams for the purposes of game balance.
184 /// \param[in] balance Team balance entity.
185 /// \param[in] team_index_a Index of the first team.
186 /// \param[in] team_index_b Index of the second team.
187 /// \param[in] player Player to check.
188 /// \param[in] use_score Whether to take into account team scores.
189 /// \return TEAMS_COMPARE value. See above.
190 /// \note You need to call TeamBalance_GetTeamCounts before calling this
191 /// function.
192 int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
193         entity player, bool use_score);
194
195 /// \brief Auto balances bots in teams after the player has changed team.
196 /// \param[in] balance Team balance entity.
197 /// \param[in] source_team_index Previous index of the team of the player.
198 /// \param[in] destination_team_index Current index of the team of the player.
199 /// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
200 /// this function.
201 void TeamBalance_AutoBalanceBots(entity balance, int source_team_index,
202         int destination_team_index);
203
204 // ============================ Internal API ==================================
205
206 /// \brief Returns whether the team change to the specified team is allowed.
207 /// \param[in] balance Team balance entity.
208 /// \param[in] index Index of the team.
209 /// \return True if team change to the specified team is allowed, false
210 /// otherwise.
211 /// \note This function bypasses all the sanity checks.
212 bool TeamBalance_IsTeamAllowedInternal(entity balance, int index);
213
214 /// \brief Bans team change to all teams except the given one.
215 /// \param[in,out] balance Team balance entity.
216 /// \param[in] index Index of the team.
217 void TeamBalance_BanTeamsExcept(entity balance, int index);
218
219 /// \brief Returns the team entity of the team balance entity at the given
220 /// index.
221 /// \param[in] balance Team balance entity.
222 /// \param[in] index Index of the team.
223 /// \return Team entity of the team balance entity at the given index.
224 entity TeamBalance_GetTeamFromIndex(entity balance, int index);
225
226 /// \brief Returns the team entity of the team balance entity that corresponds
227 /// to the given TEAM_NUM value.
228 /// \param[in] balance Team balance entity.
229 /// \param[in] team_num Team value. See TEAM_NUM constants.
230 /// \return Team entity of the team balance entity that corresponds to the given
231 /// TEAM_NUM value.
232 entity TeamBalance_GetTeam(entity balance, int team_num);
233
234 /// \brief Returns whether the team is allowed.
235 /// \param[in] team_ Team entity.
236 /// \return True if team is allowed, false otherwise.
237 bool TeamBalanceTeam_IsAllowed(entity team_);
238
239 /// \brief Returns the number of players (both humans and bots) in a team.
240 /// \param[in] team_ Team entity.
241 /// \return Number of player (both humans and bots) in a team.
242 /// \note You need to call TeamBalance_GetTeamCounts before calling this
243 /// function.
244 int TeamBalanceTeam_GetNumberOfPlayers(entity team_);
245
246 /// \brief Returns the number of bots in a team.
247 /// \param[in] team_ Team entity.
248 /// \return Number of bots in a team.
249 /// \note You need to call TeamBalance_GetTeamCounts before calling this
250 /// function.
251 int TeamBalanceTeam_GetNumberOfBots(entity team_);
252
253 /// \brief Returns the human with the lowest score in a team or NULL if there is
254 /// none.
255 /// \param[in] team_ Team entity.
256 /// \return Human with the lowest score in a team or NULL if there is none.
257 /// \note You need to call TeamBalance_GetTeamCounts before calling this
258 /// function.
259 entity TeamBalanceTeam_GetLowestHuman(entity team_);
260
261 /// \brief Returns the bot with the lowest score in a team or NULL if there is
262 /// none.
263 /// \param[in] team_ Team entity.
264 /// \return Bot with the lowest score in a team or NULL if there is none.
265 /// \note You need to call TeamBalance_GetTeamCounts before calling this
266 /// function.
267 entity TeamBalanceTeam_GetLowestBot(entity team_);
268
269 /// \brief Compares two teams for the purposes of game balance.
270 /// \param[in] team_a First team.
271 /// \param[in] team_b Second team.
272 /// \param[in] player Player to check.
273 /// \param[in] use_score Whether to take into account team scores.
274 /// \return TEAMS_COMPARE value. See above.
275 /// \note You need to call TeamBalance_GetTeamCounts before calling this
276 /// function.
277 int TeamBalance_CompareTeamsInternal(entity team_a, entity team_index_b,
278         entity player, bool use_score);