3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
14 void PutObserverInServer();
15 void PutClientInServer();
18 float redalive, bluealive, yellowalive, pinkalive;
19 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
20 float red_players, blue_players, yellow_players, pink_players;
22 #define CA_TEAMS() ((red_players > 0) + (blue_players > 0) + (yellow_players > 0) + (pink_players > 0))
23 #define CA_TEAMS_OK() (CA_TEAMS() == ca_teams)
26 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
27 * Sets the 'warmup' global variable.
29 void reset_map(float dorespawn)
34 if(time <= game_starttime && round_handler_IsActive())
35 round_handler_Reset(game_starttime + 1);
39 warmup = max(time, game_starttime);
40 if(autocvar_g_arena_warmup > 0)
41 warmup += autocvar_g_arena_warmup;
45 warmup = max(time, game_starttime);
46 if(autocvar_g_ca_warmup > 0)
47 warmup += autocvar_g_ca_warmup;
50 else if(g_race || g_cts)
52 else MUTATOR_CALLHOOK(reset_map_global);
54 lms_lowest_lives = 999;
55 lms_next_place = player_count;
57 for(self = world; (self = nextent(self)); )
58 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
67 self.team = self.team_saved;
69 if(self.flags & FL_PROJECTILE) // remove any projectiles left
73 // Waypoints and assault start come LAST
74 for(self = world; (self = nextent(self)); )
75 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
84 // Moving the player reset code here since the player-reset depends
85 // on spawnpoint entities which have to be reset first --blub
87 if(!MUTATOR_CALLHOOK(reset_map_players))
88 FOR_EACH_CLIENT(self) {
89 if(self.flags & FL_CLIENT) // reset all players
96 PutObserverInServer();
98 else if(g_ca && self.caplayer) {
99 self.classname = "player";
105 only reset players if a restart countdown is active
106 this can either be due to cvar sv_ready_restart_after_countdown having set
107 restart_mapalreadyrestarted to 1 after the countdown ended or when
108 sv_ready_restart_after_countdown is not used and countdown is still running
110 if (restart_mapalreadyrestarted || (time < game_starttime))
112 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
113 if (self.classname == "player") {
114 //PlayerScore_Clear(self);
116 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
118 //stop the player from moving so that he stands still once he gets respawned
119 self.velocity = '0 0 0';
120 self.avelocity = '0 0 0';
121 self.movement = '0 0 0';
130 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
133 if(champion && champion.classname == "player" && player_count > 1)
134 UpdateFrags(champion, +1);
139 void Spawnqueue_Insert(entity e)
143 dprint(strcat("Into queue: ", e.netname, "\n"));
144 e.spawnqueue_in = TRUE;
145 e.spawnqueue_prev = spawnqueue_last;
146 e.spawnqueue_next = world;
148 spawnqueue_last.spawnqueue_next = e;
150 if(!spawnqueue_first)
151 spawnqueue_first = e;
154 void Spawnqueue_Remove(entity e)
158 dprint(strcat("Out of queue: ", e.netname, "\n"));
159 e.spawnqueue_in = FALSE;
160 if(e == spawnqueue_first)
161 spawnqueue_first = e.spawnqueue_next;
162 if(e == spawnqueue_last)
163 spawnqueue_last = e.spawnqueue_prev;
164 if(e.spawnqueue_prev)
165 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
166 if(e.spawnqueue_next)
167 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
168 e.spawnqueue_next = world;
169 e.spawnqueue_prev = world;
172 void Spawnqueue_Unmark(entity e)
177 numspawned = numspawned - 1;
180 void Spawnqueue_Mark(entity e)
185 numspawned = numspawned + 1;
189 * If roundbased arena game mode is active, it centerprints the texts for the
190 * player when player is waiting for the countdown to finish.
191 * Blocks the players movement while countdown is active.
192 * Unblocks the player once the countdown is over.
194 * Called in StartFrame()
196 float roundStartTime_prev; // prevent networkspam
204 if(warmup && time < warmup)
206 FOR_EACH_REALCLIENT(e)
207 Send_CSQC_Centerprint_Generic_Expire(e, CPID_ROUND_STARTING);
210 if(champion && g_arena)
212 FOR_EACH_REALCLIENT(e)
213 centerprint(e, strcat("The Champion is ", champion.netname));
218 if(time < game_starttime)
221 f = ceil(warmup - time);
226 allowed_to_spawn = 1;
227 else if (warmup == 0) //first warmup or warmup cleared
231 else if(f != roundStartTime_prev)
233 if(roundStartTime_prev & 1) // msg every 2 seconds
234 if(roundStartTime_prev - f == 1) // block sudden msg
235 FOR_EACH_REALCLIENT(self)
236 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
237 roundStartTime_prev = f;
243 if(time < warmup && !inWarmupStage)
246 allowed_to_spawn = 1;
247 else if(champion && g_arena)
249 FOR_EACH_REALCLIENT(e)
250 centerprint(e, strcat("The Champion is ", champion.netname));
253 if(f != roundStartTime_prev) {
254 roundStartTime_prev = f;
256 if(g_ca && !CA_TEAMS_OK()) {
262 Announce("prepareforbattle");
270 FOR_EACH_REALCLIENT(e)
271 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
277 if(e.spawned && e.classname == "player")
278 e.player_blocked = 1;
282 else if(f > -1 && f != roundStartTime_prev && !inWarmupStage)
284 roundStartTime_prev = f;
287 allowed_to_spawn = 0;
295 FOR_EACH_REALCLIENT(e)
296 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
302 e.player_blocked = 0;
307 // clear champion to avoid centerprinting again the champion msg
314 // count amount of players in each team
315 total_players = red_players = blue_players = yellow_players = pink_players = 0;
316 FOR_EACH_PLAYER(self) {
317 if (self.team == COLOR_TEAM1)
322 else if (self.team == COLOR_TEAM2)
327 else if (self.team == COLOR_TEAM3)
332 else if (self.team == COLOR_TEAM4)
340 void count_alive_players()
342 redalive = bluealive = yellowalive = pinkalive = 0;
343 FOR_EACH_PLAYER(self) {
344 if (self.team == COLOR_TEAM1 && self.health >= 1)
346 else if (self.team == COLOR_TEAM2 && self.health >= 1)
348 else if (self.team == COLOR_TEAM3 && self.health >= 1)
350 else if (self.team == COLOR_TEAM4 && self.health >= 1)
353 FOR_EACH_REALCLIENT(self) {
354 self.redalive_stat = redalive;
355 self.bluealive_stat = bluealive;
356 self.yellowalive_stat = yellowalive;
357 self.pinkalive_stat = pinkalive;
361 float CA_GetWinnerTeam()
365 winner_team = COLOR_TEAM1;
368 if(winner_team) return 0;
369 winner_team = COLOR_TEAM2;
373 if(winner_team) return 0;
374 winner_team = COLOR_TEAM3;
378 if(winner_team) return 0;
379 winner_team = COLOR_TEAM4;
383 return -1; // no player left
387 * This function finds out whether an arena round is over 1 player is left.
388 * It determines the last player who's still alive and saves it's entity reference
389 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
391 * Gets called in StartFrame()
393 void Spawnqueue_Check()
395 if(time < warmup + 1 || inWarmupStage || intermission_running)
400 if(allowed_to_spawn) // round is not started yet
403 winner_team = CA_GetWinnerTeam();
405 if(winner_team > 0) {
406 FOR_EACH_CLIENT(self)
407 centerprint(self, strcat(ColoredTeamName(winner_team), " wins the round"));
408 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
410 else //if(winner_team == -1) // no player left
411 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
414 else if(time - warmup > autocvar_g_ca_round_timelimit) {
415 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
416 next_round = time + 5;
419 else if(next_round == -1) {
420 // wait for killed players to be put as spectators
422 next_round = time + 5;
424 else if((next_round > 0 && next_round < time))
430 //extend next_round if it isn't set yet and only 1 player is spawned
433 next_round = time + 3;
435 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
441 champion = find(world, classname, "player");
442 while(champion && champion.deadflag)
443 champion = find(champion, classname, "player");
447 while(numspawned < maxspawned && spawnqueue_first)
449 self = spawnqueue_first;
451 bprint ("^4", self.netname, "^4 is the next challenger\n");
453 Spawnqueue_Remove(self);
454 Spawnqueue_Mark(self);
456 self.classname = "player";
465 if(!(g_ca || g_arena))
471 count_alive_players();
473 if(!g_arena || arena_roundbased)