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