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;
24 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
25 * Sets the 'warmup' global variable.
27 void reset_map(float dorespawn)
32 if(time <= game_starttime && round_handler_IsActive())
33 round_handler_Reset(game_starttime + 1);
37 warmup = max(time, game_starttime);
38 if(autocvar_g_arena_warmup > 0)
39 warmup += autocvar_g_arena_warmup;
43 warmup = max(time, game_starttime);
44 if(autocvar_g_ca_warmup > 0)
45 warmup += autocvar_g_ca_warmup;
48 else if(g_race || g_cts)
50 else MUTATOR_CALLHOOK(reset_map_global);
52 lms_lowest_lives = 999;
53 lms_next_place = player_count;
55 for(self = world; (self = nextent(self)); )
56 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
65 self.team = self.team_saved;
67 if(self.flags & FL_PROJECTILE) // remove any projectiles left
71 // Waypoints and assault start come LAST
72 for(self = world; (self = nextent(self)); )
73 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
82 // Moving the player reset code here since the player-reset depends
83 // on spawnpoint entities which have to be reset first --blub
85 if(!MUTATOR_CALLHOOK(reset_map_players))
86 FOR_EACH_CLIENT(self) {
87 if(self.flags & FL_CLIENT) // reset all players
94 PutObserverInServer();
96 else if(g_ca && self.caplayer) {
97 self.classname = "player";
103 only reset players if a restart countdown is active
104 this can either be due to cvar sv_ready_restart_after_countdown having set
105 restart_mapalreadyrestarted to 1 after the countdown ended or when
106 sv_ready_restart_after_countdown is not used and countdown is still running
108 if (restart_mapalreadyrestarted || (time < game_starttime))
110 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
111 if (self.classname == "player") {
112 //PlayerScore_Clear(self);
114 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
116 //stop the player from moving so that he stands still once he gets respawned
117 self.velocity = '0 0 0';
118 self.avelocity = '0 0 0';
119 self.movement = '0 0 0';
128 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
131 if(champion && champion.classname == "player" && player_count > 1)
132 UpdateFrags(champion, +1);
137 void Spawnqueue_Insert(entity e)
141 dprint(strcat("Into queue: ", e.netname, "\n"));
142 e.spawnqueue_in = TRUE;
143 e.spawnqueue_prev = spawnqueue_last;
144 e.spawnqueue_next = world;
146 spawnqueue_last.spawnqueue_next = e;
148 if(!spawnqueue_first)
149 spawnqueue_first = e;
152 void Spawnqueue_Remove(entity e)
156 dprint(strcat("Out of queue: ", e.netname, "\n"));
157 e.spawnqueue_in = FALSE;
158 if(e == spawnqueue_first)
159 spawnqueue_first = e.spawnqueue_next;
160 if(e == spawnqueue_last)
161 spawnqueue_last = e.spawnqueue_prev;
162 if(e.spawnqueue_prev)
163 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
164 if(e.spawnqueue_next)
165 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
166 e.spawnqueue_next = world;
167 e.spawnqueue_prev = world;
170 void Spawnqueue_Unmark(entity e)
175 numspawned = numspawned - 1;
178 void Spawnqueue_Mark(entity e)
183 numspawned = numspawned + 1;
187 * If roundbased arena game mode is active, it centerprints the texts for the
188 * player when player is waiting for the countdown to finish.
189 * Blocks the players movement while countdown is active.
190 * Unblocks the player once the countdown is over.
192 * Called in StartFrame()
194 float roundStartTime_prev; // prevent networkspam
202 if(warmup && time < warmup)
204 FOR_EACH_REALCLIENT(e)
205 Send_CSQC_Centerprint_Generic_Expire(e, CPID_ROUND_STARTING);
208 if(champion && g_arena)
210 FOR_EACH_REALCLIENT(e)
211 centerprint(e, strcat("The Champion is ", champion.netname));
216 if(time < game_starttime)
219 f = ceil(warmup - time);
224 allowed_to_spawn = 1;
225 else if (warmup == 0) //first warmup or warmup cleared
227 if (red_players && blue_players)
229 else if(f != roundStartTime_prev)
231 if(roundStartTime_prev & 1) // msg every 2 seconds
232 if(roundStartTime_prev - f == 1) // block sudden msg
233 FOR_EACH_REALCLIENT(self)
234 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
235 roundStartTime_prev = f;
241 if(time < warmup && !inWarmupStage)
244 allowed_to_spawn = 1;
245 else if(champion && g_arena)
247 FOR_EACH_REALCLIENT(e)
248 centerprint(e, strcat("The Champion is ", champion.netname));
251 if(f != roundStartTime_prev) {
252 roundStartTime_prev = f;
254 if(g_ca && !(red_players && blue_players)) {
260 Announce("prepareforbattle");
268 FOR_EACH_REALCLIENT(e)
269 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
275 if(e.spawned && e.classname == "player")
276 e.player_blocked = 1;
280 else if(f > -1 && f != roundStartTime_prev && !inWarmupStage)
282 roundStartTime_prev = f;
284 if(red_players && blue_players)
285 allowed_to_spawn = 0;
293 FOR_EACH_REALCLIENT(e)
294 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
300 e.player_blocked = 0;
305 // clear champion to avoid centerprinting again the champion msg
312 // count amount of players in each team
313 total_players = red_players = blue_players = yellow_players = pink_players = 0;
314 FOR_EACH_PLAYER(self) {
315 if (self.team == COLOR_TEAM1)
320 else if (self.team == COLOR_TEAM2)
325 else if (self.team == COLOR_TEAM3)
330 else if (self.team == COLOR_TEAM4)
338 void count_alive_players()
340 redalive = bluealive = yellowalive = pinkalive = 0;
341 FOR_EACH_PLAYER(self) {
342 if (self.team == COLOR_TEAM1 && self.health >= 1)
344 else if (self.team == COLOR_TEAM2 && self.health >= 1)
347 FOR_EACH_REALCLIENT(self) {
348 self.redalive_stat = redalive;
349 self.bluealive_stat = bluealive;
354 * This function finds out whether an arena round is over 1 player is left.
355 * It determines the last player who's still alive and saves it's entity reference
356 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
358 * Gets called in StartFrame()
360 void Spawnqueue_Check()
362 if(time < warmup + 1 || inWarmupStage || intermission_running)
366 if(allowed_to_spawn) // round is not started yet
369 if(!(redalive && bluealive)) {
370 // every player of (at least) one team is dead, round ends here
372 play2all("ctf/red_capture.wav");
373 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
374 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
377 play2all("ctf/blue_capture.wav");
378 FOR_EACH_CLIENT(self) centerprint(self, "^4BLUE ^7team wins the round");
379 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
382 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
385 else if(time - warmup > autocvar_g_ca_round_timelimit) {
386 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
387 next_round = time + 5;
390 else if(next_round == -1) {
391 // wait for killed players to be put as spectators
392 if(!(red_players && blue_players))
393 next_round = time + 5;
395 else if((next_round > 0 && next_round < time))
401 //extend next_round if it isn't set yet and only 1 player is spawned
404 next_round = time + 3;
406 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
412 champion = find(world, classname, "player");
413 while(champion && champion.deadflag)
414 champion = find(champion, classname, "player");
418 while(numspawned < maxspawned && spawnqueue_first)
420 self = spawnqueue_first;
422 bprint ("^4", self.netname, "^4 is the next challenger\n");
424 Spawnqueue_Remove(self);
425 Spawnqueue_Mark(self);
427 self.classname = "player";
436 if(!(g_ca || g_arena))
442 count_alive_players();
444 if(!g_arena || arena_roundbased)