3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
14 float required_ca_players;
17 void PutObserverInServer();
18 void PutClientInServer();
19 void(entity e) ReturnFlag;
20 void dom_controlpoint_setup();
21 void onslaught_generator_reset();
22 void onslaught_controlpoint_reset();
23 void func_breakable_reset();
24 void assault_objective_reset();
25 void target_assault_roundend_reset();
29 float redalive, bluealive, yellowalive, pinkalive;
31 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
32 float redspawned, bluespawned, yellowspawned, pinkspawned;
36 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
37 * Sets the 'warmup' global variable.
39 void reset_map(float dorespawn)
44 if(g_arena && autocvar_g_arena_warmup)
45 warmup = time + autocvar_g_arena_warmup;
47 warmup = time + autocvar_g_ca_warmup;
52 warmup = time + autocvar_g_freezetag_warmup;
55 lms_lowest_lives = 999;
56 lms_next_place = player_count;
60 for(self = world; (self = nextent(self)); )
61 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
70 self.team = self.team_saved;
72 if(self.flags & FL_PROJECTILE) // remove any projectiles left
76 // Waypoints and assault start come LAST
77 for(self = world; (self = nextent(self)); )
78 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
87 // Moving the player reset code here since the player-reset depends
88 // on spawnpoint entities which have to be reset first --blub
90 FOR_EACH_CLIENT(self) {
91 if(self.flags & FL_CLIENT) // reset all players
98 PutObserverInServer();
100 else if(g_ca && self.caplayer) {
101 self.classname = "player";
106 if(self.classname == "player")
112 only reset players if a restart countdown is active
113 this can either be due to cvar sv_ready_restart_after_countdown having set
114 restart_mapalreadyrestarted to 1 after the countdown ended or when
115 sv_ready_restart_after_countdown is not used and countdown is still running
117 if (restart_mapalreadyrestarted || (time < game_starttime))
119 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
120 if (self.classname == "player") {
121 //PlayerScore_Clear(self);
123 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
125 //stop the player from moving so that he stands still once he gets respawned
126 self.velocity = '0 0 0';
127 self.avelocity = '0 0 0';
128 self.movement = '0 0 0';
137 kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), "", kh_StartRound);
140 if(champion && champion.classname == "player" && player_count > 1)
141 UpdateFrags(champion, +1);
146 void Spawnqueue_Insert(entity e)
150 dprint(strcat("Into queue: ", e.netname, "\n"));
151 e.spawnqueue_in = TRUE;
152 e.spawnqueue_prev = spawnqueue_last;
153 e.spawnqueue_next = world;
155 spawnqueue_last.spawnqueue_next = e;
157 if(!spawnqueue_first)
158 spawnqueue_first = e;
161 void Spawnqueue_Remove(entity e)
165 dprint(strcat("Out of queue: ", e.netname, "\n"));
166 e.spawnqueue_in = FALSE;
167 if(e == spawnqueue_first)
168 spawnqueue_first = e.spawnqueue_next;
169 if(e == spawnqueue_last)
170 spawnqueue_last = e.spawnqueue_prev;
171 if(e.spawnqueue_prev)
172 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
173 if(e.spawnqueue_next)
174 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
175 e.spawnqueue_next = world;
176 e.spawnqueue_prev = world;
179 void Spawnqueue_Unmark(entity e)
184 numspawned = numspawned - 1;
187 void Spawnqueue_Mark(entity e)
192 numspawned = numspawned + 1;
196 * If roundbased arena game mode is active, it centerprints the texts for the
197 * player when player is waiting for the countdown to finish.
198 * Blocks the players movement while countdown is active.
199 * Unblocks the player once the countdown is over.
201 * Called in PlayerPostThink()
203 float roundStartTime_prev; // prevent networkspam
210 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
213 f = ceil(warmup - time);
215 champion = world; // this is done because a if(champion) will not execute if champion = world
217 allowed_to_spawn = 0;
220 allowed_to_spawn = 1;
221 if(ca_players < required_ca_players)
222 allowed_to_spawn = 1;
225 if(time < warmup && !inWarmupStage)
228 allowed_to_spawn = 1;
229 if(champion && g_arena)
230 msg = strcat("The Champion is ", champion_name, "^7\n");
231 //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
233 if(f != roundStartTime_prev) {
234 msg = strcat(msg, "Round will start in ", ftos(f),"\n");
235 //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
236 roundStartTime_prev = f;
238 Announce("prepareforbattle");
251 if(self.spawned && self.classname == "player")
252 self.movetype = MOVETYPE_NONE;
254 self.velocity = '0 0 0';
255 self.avelocity = '0 0 0';
256 self.movement = '0 0 0';
260 else if(f > -1 && f != roundStartTime_prev)
262 roundStartTime_prev = f;
264 centerprint(self, "^1Begin!\n");
273 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
274 self.movetype = MOVETYPE_WALK;
278 void count_spawned_players()
280 // TODO fix "*spawned" name, it should rather be "*players" or so
281 // not doing this now to prevent merge hell with Tag
282 // fix after merging with Tag
284 // count amount of players in each team
285 totalspawned = redspawned = bluespawned = yellowspawned = pinkspawned = 0;
286 FOR_EACH_PLAYER(self) {
287 if (self.team == COLOR_TEAM1)
292 else if (self.team == COLOR_TEAM2)
297 else if (self.team == COLOR_TEAM3)
302 else if (self.team == COLOR_TEAM4)
310 void count_alive_players()
312 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
315 FOR_EACH_PLAYER(self) {
316 if (self.team == COLOR_TEAM1 && self.health >= 1)
321 else if (self.team == COLOR_TEAM2 && self.health >= 1)
327 FOR_EACH_REALCLIENT(self) {
328 self.redalive_stat = redalive;
329 self.bluealive_stat = bluealive;
334 // count amount of alive players in each team
335 FOR_EACH_PLAYER(self) {
336 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
341 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
346 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
351 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
357 FOR_EACH_REALCLIENT(self) {
358 self.redalive_stat = redalive;
359 self.bluealive_stat = bluealive;
360 self.yellowalive_stat = yellowalive;
361 self.pinkalive_stat = pinkalive;
368 * This function finds out whether an arena round is over 1 player is left.
369 * It determines the last player who's still alive and saves it's entity reference
370 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
372 * Gets called in StartFrame()
374 void Spawnqueue_Check()
376 count_spawned_players();
377 if(g_ca || g_freezetag) // we want to perform this before the return block below (CA)...
379 count_alive_players();
381 if(time < warmup + 1 || inWarmupStage || intermission_running)
385 required_ca_players = max(2, fabs(autocvar_bot_vs_human + 1));
387 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
390 else if(ca_players < required_ca_players) {
391 FOR_EACH_PLAYER(self)
392 centerprint(self, strcat("^1Need at least 1 player in each team to play CA", "^7\n"));
395 else if(!next_round) {
396 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
397 next_round = time + 5;
398 champion = find(world, classname, "player");
400 strunzone(champion_name);
401 champion_name = strzone(champion.netname);
403 else if((!redspawned && !bluespawned) || time - warmup > autocvar_g_ca_round_timelimit) {
404 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
405 next_round = time + 5;
411 if(redalive && !bluealive)
413 play2all("ctf/red_capture.wav");
414 FOR_EACH_CLIENT(self) centerprint(self, "^1 RED ^7team wins the round.\n");
415 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
416 stopalivecheck = TRUE;
418 else if(bluealive && !redalive)
420 play2all("ctf/blue_capture.wav");
421 FOR_EACH_CLIENT(self) centerprint(self, "^4 BLUE ^7team wins the round.\n");
422 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
423 stopalivecheck = TRUE;
427 if((next_round && next_round < time))
429 stopalivecheck = FALSE;
433 } else if(g_freezetag) {
434 if((next_round && next_round < time))
440 //extend next_round if it isn't set yet and only 1 player is spawned
443 next_round = time + 3;
445 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
451 champion = find(world, classname, "player");
452 while(champion && champion.deadflag)
453 champion = find(champion, classname, "player");
457 while(numspawned < maxspawned && spawnqueue_first)
459 self = spawnqueue_first;
461 bprint ("^4", self.netname, "^4 is the next challenger\n");
463 Spawnqueue_Remove(self);
464 Spawnqueue_Mark(self);
466 self.classname = "player";