]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/teamplay.qh
Merge branch 'master' into Lyberta/TeamplayOverhaul
[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 /// \brief Sets the team of the player.
87 /// \param[in,out] player Player to adjust.
88 /// \param[in] team_index Index of the team to set.
89 /// \param[in] type ???
90 /// \return True if team switch was successful, false otherwise.
91 bool SetPlayerTeam(entity player, int team_index, int type);
92
93 /// \brief Moves player to the specified team.
94 /// \param[in,out] client Client to move.
95 /// \param[in] team_index Index of the team.
96 /// \param[in] type ???
97 /// \return True on success, false otherwise.
98 bool MoveToTeam(entity client, int team_index, int type);
99
100 /// \brief Kills player as a result of team change.
101 /// \param[in,out] player Player to kill.
102 void KillPlayerForTeamChange(entity player);
103
104 enum
105 {
106         TEAM_CHANGE_CONNECT = 1,
107         TEAM_CHANGE_AUTO = 2,
108         TEAM_CHANGE_MANUAL = 3,
109         TEAM_CHANGE_SPECTATOR = 4,
110         TEAM_CHANGE_AUTO_RELAXED = 99
111 };
112
113 void LogTeamchange(float player_id, float team_number, int type);
114
115 // ========================= Team balance API =================================
116
117 /// \brief Checks whether the player can join teams according to global
118 /// configuration and mutator settings.
119 /// \param[in] for_whom Player to check for. Pass NULL for global rules.
120 /// \return Team balance entity that holds information about teams. This entity
121 /// must be manually destroyed by calling TeamBalance_Destroy.
122 entity TeamBalance_CheckAllowedTeams(entity for_whom);
123
124 /// \brief Destroy the team balance entity.
125 /// \param[in,out] balance Team balance entity to destroy.
126 /// \note Team balance entity is allowed to be NULL.
127 void TeamBalance_Destroy(entity balance);
128
129 /// \brief Returns the bitmask of allowed teams.
130 /// \param[in] balance Team balance entity.
131 /// \return Bitmask of allowed teams.
132 int TeamBalance_GetAllowedTeams(entity balance);
133
134 /// \brief Returns whether the team change to the specified team is allowed.
135 /// \param[in] balance Team balance entity.
136 /// \param[in] index Index of the team.
137 /// \return True if team change to the specified team is allowed, false
138 /// otherwise.
139 bool TeamBalance_IsTeamAllowed(entity balance, int index);
140
141 /// \brief Counts the number of players and various other information about
142 /// each team.
143 /// \param[in,out] balance Team balance entity.
144 /// \param[in] ignore Player to ignore. This is useful if you plan to switch the
145 /// player's team. Pass NULL for global information.
146 /// \note This function updates the internal state of the team balance entity.
147 void TeamBalance_GetTeamCounts(entity balance, entity ignore);
148
149 /// \brief Returns the number of players (both humans and bots) in a team.
150 /// \param[in] balance Team balance entity.
151 /// \param[in] index Index of the team.
152 /// \return Number of player (both humans and bots) in a team.
153 /// \note You need to call TeamBalance_GetTeamCounts before calling this
154 /// function.
155 int TeamBalance_GetNumberOfPlayers(entity balance, int index);
156
157 /// \brief Finds the team that will make the game most balanced if the player
158 /// joins it.
159 /// \param[in] balance Team balance entity.
160 /// \param[in] player Player to check.
161 /// \param[in] ignore_player ???
162 /// \return Index of the team that will make the game most balanced if the
163 /// player joins it. If there are several equally good teams available, the
164 /// function will pick a random one.
165 int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player);
166
167 /// \brief Returns the bitmask of the teams that will make the game most
168 /// balanced if the player joins any of them.
169 /// \param[in] balance Team balance entity.
170 /// \param[in] player Player to check.
171 /// \param[in] use_score Whether to take into account team scores.
172 /// \return Bitmask of the teams that will make the game most balanced if the
173 /// player joins any of them.
174 /// \note You need to call TeamBalance_GetTeamCounts before calling this
175 /// function.
176 int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score);
177
178 void TeamBalance_JoinBestTeam(entity this, bool force_best_team);
179
180 /// \brief Describes the result of comparing teams.
181 enum
182 {
183         TEAMS_COMPARE_INVALID, ///< One or both teams are invalid.
184         TEAMS_COMPARE_LESS, ///< First team is less than the second one.
185         TEAMS_COMPARE_EQUAL, ///< Both teams are equal.
186         TEAMS_COMPARE_GREATER ///< First team the greater than the second one.
187 };
188
189 /// \brief Compares two teams for the purposes of game balance.
190 /// \param[in] balance Team balance entity.
191 /// \param[in] team_index_a Index of the first team.
192 /// \param[in] team_index_b Index of the second team.
193 /// \param[in] player Player to check.
194 /// \param[in] use_score Whether to take into account team scores.
195 /// \return TEAMS_COMPARE value. See above.
196 /// \note You need to call TeamBalance_GetTeamCounts before calling this
197 /// function.
198 int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
199         entity player, bool use_score);
200
201 /// \brief Switches a bot from one team to another if teams are not balanced.
202 /// \param[in] source_team_index Index of the team to switch from.
203 /// \param[in] destination_team_index Index of the team to switch to.
204 void TeamBalance_AutoBalanceBots(int source_team_index,
205         int destination_team_index);
206
207 // ============================ Internal API ==================================
208
209 /// \brief Returns whether the team change to the specified team is allowed.
210 /// \param[in] balance Team balance entity.
211 /// \param[in] index Index of the team.
212 /// \return True if team change to the specified team is allowed, false
213 /// otherwise.
214 /// \note This function bypasses all the sanity checks.
215 bool TeamBalance_IsTeamAllowedInternal(entity balance, int index);
216
217 /// \brief Bans team change to all teams except the given one.
218 /// \param[in,out] balance Team balance entity.
219 /// \param[in] index Index of the team.
220 void TeamBalance_BanTeamsExcept(entity balance, int index);
221
222 /// \brief Returns the team entity of the team balance entity at the given
223 /// index.
224 /// \param[in] balance Team balance entity.
225 /// \param[in] index Index of the team.
226 /// \return Team entity of the team balance entity at the given index.
227 entity TeamBalance_GetTeamFromIndex(entity balance, int index);
228
229 /// \brief Returns the team entity of the team balance entity that corresponds
230 /// to the given TEAM_NUM value.
231 /// \param[in] balance Team balance entity.
232 /// \param[in] team_num Team value. See TEAM_NUM constants.
233 /// \return Team entity of the team balance entity that corresponds to the given
234 /// TEAM_NUM value.
235 entity TeamBalance_GetTeam(entity balance, int team_num);
236
237 /// \brief Returns whether the team is allowed.
238 /// \param[in] team_ent Team entity.
239 /// \return True if team is allowed, false otherwise.
240 bool TeamBalanceTeam_IsAllowed(entity team_ent);
241
242 /// \brief Returns the number of players (both humans and bots) in a team.
243 /// \param[in] team_ent Team entity.
244 /// \return Number of player (both humans and bots) in a team.
245 /// \note You need to call TeamBalance_GetTeamCounts before calling this
246 /// function.
247 int TeamBalanceTeam_GetNumberOfPlayers(entity team_ent);
248
249 /// \brief Returns the number of bots in a team.
250 /// \param[in] team_ent Team entity.
251 /// \return Number of bots in a team.
252 /// \note You need to call TeamBalance_GetTeamCounts before calling this
253 /// function.
254 int TeamBalanceTeam_GetNumberOfBots(entity team_ent);
255
256 /// \brief Compares two teams for the purposes of game balance.
257 /// \param[in] team_a First team.
258 /// \param[in] team_b Second team.
259 /// \param[in] player Player to check.
260 /// \param[in] use_score Whether to take into account team scores.
261 /// \return TEAMS_COMPARE value. See above.
262 /// \note You need to call TeamBalance_GetTeamCounts before calling this
263 /// function.
264 int TeamBalance_CompareTeamsInternal(entity team_a, entity team_index_b,
265         entity player, bool use_score);