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