3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
15 void PutObserverInServer();
16 void PutClientInServer();
17 void(entity e) ReturnFlag;
18 void dom_controlpoint_setup();
19 void onslaught_generator_reset();
20 void onslaught_controlpoint_reset();
21 void func_breakable_reset();
22 void assault_objective_reset();
23 void target_assault_roundend_reset();
27 float redalive, bluealive, yellowalive, pinkalive;
29 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
30 float red_players, blue_players, yellow_players, pink_players;
34 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
35 * Sets the 'warmup' global variable.
37 void reset_map(float dorespawn)
42 if(g_arena && autocvar_g_arena_warmup)
43 warmup = time + autocvar_g_arena_warmup;
45 warmup = time + autocvar_g_ca_warmup;
50 warmup = time + autocvar_g_freezetag_warmup;
53 lms_lowest_lives = 999;
54 lms_next_place = player_count;
58 for(self = world; (self = nextent(self)); )
59 if(clienttype(self) == CLIENTTYPE_NOTACLIENT && self.items != IT_STRENGTH && self.items != IT_INVINCIBLE) // don't respawn strength or shield, that will only lead to them spawning very early each match
68 self.team = self.team_saved;
70 if(self.flags & FL_PROJECTILE) // remove any projectiles left
74 // Waypoints and assault start come LAST
75 for(self = world; (self = nextent(self)); )
76 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
85 // Moving the player reset code here since the player-reset depends
86 // on spawnpoint entities which have to be reset first --blub
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";
104 if(self.classname == "player")
110 only reset players if a restart countdown is active
111 this can either be due to cvar sv_ready_restart_after_countdown having set
112 restart_mapalreadyrestarted to 1 after the countdown ended or when
113 sv_ready_restart_after_countdown is not used and countdown is still running
115 if (restart_mapalreadyrestarted || (time < game_starttime))
117 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
118 if (self.classname == "player") {
119 //PlayerScore_Clear(self);
121 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
123 //stop the player from moving so that he stands still once he gets respawned
124 self.velocity = '0 0 0';
125 self.avelocity = '0 0 0';
126 self.movement = '0 0 0';
135 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
138 if(champion && champion.classname == "player" && player_count > 1)
139 UpdateFrags(champion, +1);
144 void Spawnqueue_Insert(entity e)
148 dprint(strcat("Into queue: ", e.netname, "\n"));
149 e.spawnqueue_in = TRUE;
150 e.spawnqueue_prev = spawnqueue_last;
151 e.spawnqueue_next = world;
153 spawnqueue_last.spawnqueue_next = e;
155 if(!spawnqueue_first)
156 spawnqueue_first = e;
159 void Spawnqueue_Remove(entity e)
163 dprint(strcat("Out of queue: ", e.netname, "\n"));
164 e.spawnqueue_in = FALSE;
165 if(e == spawnqueue_first)
166 spawnqueue_first = e.spawnqueue_next;
167 if(e == spawnqueue_last)
168 spawnqueue_last = e.spawnqueue_prev;
169 if(e.spawnqueue_prev)
170 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
171 if(e.spawnqueue_next)
172 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
173 e.spawnqueue_next = world;
174 e.spawnqueue_prev = world;
177 void Spawnqueue_Unmark(entity e)
182 numspawned = numspawned - 1;
185 void Spawnqueue_Mark(entity e)
190 numspawned = numspawned + 1;
194 * If roundbased arena game mode is active, it centerprints the texts for the
195 * player when player is waiting for the countdown to finish.
196 * Blocks the players movement while countdown is active.
197 * Unblocks the player once the countdown is over.
199 * Called in StartFrame()
201 float roundStartTime_prev; // prevent networkspam
209 if(champion && g_arena)
212 centerprint(e, strcat("The Champion is ", champion.netname));
217 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
220 f = ceil(warmup - time);
222 allowed_to_spawn = 0;
225 allowed_to_spawn = 1;
226 if(g_ca && !ca_teams_ok)
227 allowed_to_spawn = 1;
229 if(time < warmup && !inWarmupStage)
232 allowed_to_spawn = 1;
233 if(champion && g_arena)
236 centerprint(e, strcat("The Champion is ", champion.netname));
239 if(f != roundStartTime_prev) {
240 roundStartTime_prev = f;
242 Announce("prepareforbattle");
251 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
257 if(e.spawned && e.classname == "player")
258 e.movetype = MOVETYPE_NONE;
259 e.velocity = '0 0 0';
260 e.avelocity = '0 0 0';
261 e.movement = '0 0 0';
265 else if(f > -1 && f != roundStartTime_prev)
267 roundStartTime_prev = f;
270 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
273 ca_teams_ok = (red_players && blue_players); // teams are ok if there's at least 1 player in each team
277 if(e.health > 0 && e.movetype == MOVETYPE_NONE)
278 e.movetype = MOVETYPE_WALK;
282 // clear champion to avoid centerprinting again the champion msg
289 // count amount of players in each team
290 total_players = red_players = blue_players = yellow_players = pink_players = 0;
291 FOR_EACH_PLAYER(self) {
292 if (self.team == COLOR_TEAM1)
297 else if (self.team == COLOR_TEAM2)
302 else if (self.team == COLOR_TEAM3)
307 else if (self.team == COLOR_TEAM4)
315 void count_alive_players()
317 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
320 FOR_EACH_PLAYER(self) {
321 if (self.team == COLOR_TEAM1 && self.health >= 1)
326 else if (self.team == COLOR_TEAM2 && self.health >= 1)
332 FOR_EACH_REALCLIENT(self) {
333 self.redalive_stat = redalive;
334 self.bluealive_stat = bluealive;
339 // count amount of alive players in each team
340 FOR_EACH_PLAYER(self) {
341 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
346 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
351 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
356 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
362 FOR_EACH_REALCLIENT(self) {
363 self.redalive_stat = redalive;
364 self.bluealive_stat = bluealive;
365 self.yellowalive_stat = yellowalive;
366 self.pinkalive_stat = pinkalive;
373 * This function finds out whether an arena round is over 1 player is left.
374 * It determines the last player who's still alive and saves it's entity reference
375 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
377 * Gets called in StartFrame()
380 void Spawnqueue_Check()
382 if(time < warmup + 1 || inWarmupStage || intermission_running)
386 if(!ca_teams_ok && (red_players && blue_players)) {
389 else if(!ca_teams_ok) {
392 FOR_EACH_PLAYER(self)
393 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
398 else if(!next_round) {
399 if((red_players && !blue_players) || (blue_players && !red_players)) {
400 next_round = time + 5;
402 else if((!red_players && !blue_players) || time - warmup > autocvar_g_ca_round_timelimit) {
403 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
404 next_round = time + 5;
410 if(redalive && !bluealive)
412 play2all("ctf/red_capture.wav");
413 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
414 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
415 stopalivecheck = TRUE;
417 else if(bluealive && !redalive)
419 play2all("ctf/blue_capture.wav");
420 FOR_EACH_CLIENT(self) centerprint(self, "^4BLUE ^7team wins the round");
421 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
422 stopalivecheck = TRUE;
426 if((next_round && next_round < time))
428 stopalivecheck = FALSE;
432 } else if(g_freezetag) {
433 if((next_round && next_round < time))
439 //extend next_round if it isn't set yet and only 1 player is spawned
442 next_round = time + 3;
444 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
450 champion = find(world, classname, "player");
451 while(champion && champion.deadflag)
452 champion = find(champion, classname, "player");
456 while(numspawned < maxspawned && spawnqueue_first)
458 self = spawnqueue_first;
460 bprint ("^4", self.netname, "^4 is the next challenger\n");
462 Spawnqueue_Remove(self);
463 Spawnqueue_Mark(self);
465 self.classname = "player";