3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
16 void PutObserverInServer();
17 void PutClientInServer();
18 void(entity e) ReturnFlag;
19 void dom_controlpoint_setup();
20 void onslaught_generator_reset();
21 void onslaught_controlpoint_reset();
22 void func_breakable_reset();
23 void assault_objective_reset();
24 void target_assault_roundend_reset();
28 float redalive, bluealive, yellowalive, pinkalive;
30 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
31 float red_players, blue_players, yellow_players, pink_players;
35 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
36 * Sets the 'warmup' global variable.
38 void reset_map(float dorespawn)
43 if(g_arena && autocvar_g_arena_warmup)
44 warmup = time + autocvar_g_arena_warmup;
46 warmup = time + autocvar_g_ca_warmup;
51 warmup = time + autocvar_g_freezetag_warmup;
54 lms_lowest_lives = 999;
55 lms_next_place = player_count;
59 for(self = world; (self = nextent(self)); )
60 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
69 self.team = self.team_saved;
71 if(self.flags & FL_PROJECTILE) // remove any projectiles left
75 // Waypoints and assault start come LAST
76 for(self = world; (self = nextent(self)); )
77 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
86 // Moving the player reset code here since the player-reset depends
87 // on spawnpoint entities which have to be reset first --blub
89 FOR_EACH_CLIENT(self) {
90 if(self.flags & FL_CLIENT) // reset all players
97 PutObserverInServer();
99 else if(g_ca && self.caplayer) {
100 self.classname = "player";
105 if(self.classname == "player")
111 only reset players if a restart countdown is active
112 this can either be due to cvar sv_ready_restart_after_countdown having set
113 restart_mapalreadyrestarted to 1 after the countdown ended or when
114 sv_ready_restart_after_countdown is not used and countdown is still running
116 if (restart_mapalreadyrestarted || (time < game_starttime))
118 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
119 if (self.classname == "player") {
120 //PlayerScore_Clear(self);
122 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
124 //stop the player from moving so that he stands still once he gets respawned
125 self.velocity = '0 0 0';
126 self.avelocity = '0 0 0';
127 self.movement = '0 0 0';
136 kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), "", kh_StartRound);
139 if(champion && champion.classname == "player" && player_count > 1)
140 UpdateFrags(champion, +1);
145 void Spawnqueue_Insert(entity e)
149 dprint(strcat("Into queue: ", e.netname, "\n"));
150 e.spawnqueue_in = TRUE;
151 e.spawnqueue_prev = spawnqueue_last;
152 e.spawnqueue_next = world;
154 spawnqueue_last.spawnqueue_next = e;
156 if(!spawnqueue_first)
157 spawnqueue_first = e;
160 void Spawnqueue_Remove(entity e)
164 dprint(strcat("Out of queue: ", e.netname, "\n"));
165 e.spawnqueue_in = FALSE;
166 if(e == spawnqueue_first)
167 spawnqueue_first = e.spawnqueue_next;
168 if(e == spawnqueue_last)
169 spawnqueue_last = e.spawnqueue_prev;
170 if(e.spawnqueue_prev)
171 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
172 if(e.spawnqueue_next)
173 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
174 e.spawnqueue_next = world;
175 e.spawnqueue_prev = world;
178 void Spawnqueue_Unmark(entity e)
183 numspawned = numspawned - 1;
186 void Spawnqueue_Mark(entity e)
191 numspawned = numspawned + 1;
195 * If roundbased arena game mode is active, it centerprints the texts for the
196 * player when player is waiting for the countdown to finish.
197 * Blocks the players movement while countdown is active.
198 * Unblocks the player once the countdown is over.
200 * Called in PlayerPostThink()
202 float roundStartTime_prev; // prevent networkspam
209 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
212 f = ceil(warmup - time);
214 champion = world; // this is done because a if(champion) will not execute if champion = world
216 allowed_to_spawn = 0;
219 allowed_to_spawn = 1;
220 if(g_ca && !ca_teams_ok)
221 allowed_to_spawn = 1;
224 if(time < warmup && !inWarmupStage)
227 allowed_to_spawn = 1;
228 if(champion && g_arena)
229 msg = strcat("The Champion is ", champion_name, "^7\n");
230 //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
232 if(f != roundStartTime_prev) {
233 msg = strcat(msg, "Round will start in ", ftos(f),"\n");
234 //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
235 roundStartTime_prev = f;
237 Announce("prepareforbattle");
250 if(self.spawned && self.classname == "player")
251 self.movetype = MOVETYPE_NONE;
253 self.velocity = '0 0 0';
254 self.avelocity = '0 0 0';
255 self.movement = '0 0 0';
259 else if(f > -1 && f != roundStartTime_prev)
261 roundStartTime_prev = f;
263 centerprint(self, "^1Begin!\n");
266 float start_red_ca_players, start_blue_ca_players;
269 if (e.team == COLOR_TEAM1)
270 start_red_ca_players += 1;
271 else if (e.team == COLOR_TEAM2)
272 start_blue_ca_players += 1;
274 // teams are ok if there's at least 1 player in each team
275 ca_teams_ok = (start_red_ca_players && start_blue_ca_players);
278 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
279 self.movetype = MOVETYPE_WALK;
285 // count amount of players in each team
286 total_players = red_players = blue_players = yellow_players = pink_players = 0;
287 FOR_EACH_PLAYER(self) {
288 if (self.team == COLOR_TEAM1)
293 else if (self.team == COLOR_TEAM2)
298 else if (self.team == COLOR_TEAM3)
303 else if (self.team == COLOR_TEAM4)
311 void count_alive_players()
313 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
316 FOR_EACH_PLAYER(self) {
317 if (self.team == COLOR_TEAM1 && self.health >= 1)
322 else if (self.team == COLOR_TEAM2 && self.health >= 1)
328 FOR_EACH_REALCLIENT(self) {
329 self.redalive_stat = redalive;
330 self.bluealive_stat = bluealive;
335 // count amount of alive players in each team
336 FOR_EACH_PLAYER(self) {
337 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
342 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
347 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
352 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
358 FOR_EACH_REALCLIENT(self) {
359 self.redalive_stat = redalive;
360 self.bluealive_stat = bluealive;
361 self.yellowalive_stat = yellowalive;
362 self.pinkalive_stat = pinkalive;
369 * This function finds out whether an arena round is over 1 player is left.
370 * It determines the last player who's still alive and saves it's entity reference
371 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
373 * Gets called in StartFrame()
375 void Spawnqueue_Check()
378 if(g_ca || g_freezetag) // we want to perform this before the return block below (CA)...
380 count_alive_players();
382 if(time < warmup + 1 || inWarmupStage || intermission_running)
386 if(!ca_teams_ok && (red_players && blue_players)) {
389 else if(!ca_teams_ok) {
390 FOR_EACH_PLAYER(self)
391 centerprint(self, strcat("^1Need at least 1 player in each team to play CA", "^7\n"));
394 else if(!next_round) {
395 if((red_players && !blue_players) || (blue_players && !red_players)) {
396 next_round = time + 5;
397 champion = find(world, classname, "player");
399 strunzone(champion_name);
400 champion_name = strzone(champion.netname);
402 else if((!red_players && !blue_players) || time - warmup > autocvar_g_ca_round_timelimit) {
403 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
404 next_round = time + 5;
410 if(redalive && !bluealive)
412 play2all("ctf/red_capture.wav");
413 FOR_EACH_CLIENT(self) centerprint(self, "^1 RED ^7team wins the round.\n");
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, "^4 BLUE ^7team wins the round.\n");
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";