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
74 stopsound(self, CHAN_PAIN);
79 // Waypoints and assault start come LAST
80 for(self = world; (self = nextent(self)); )
81 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
90 // Moving the player reset code here since the player-reset depends
91 // on spawnpoint entities which have to be reset first --blub
93 FOR_EACH_CLIENT(self) {
94 if(self.flags & FL_CLIENT) // reset all players
101 PutObserverInServer();
103 else if(g_ca && self.caplayer) {
104 self.classname = "player";
109 if(self.classname == "player")
115 only reset players if a restart countdown is active
116 this can either be due to cvar sv_ready_restart_after_countdown having set
117 restart_mapalreadyrestarted to 1 after the countdown ended or when
118 sv_ready_restart_after_countdown is not used and countdown is still running
120 if (restart_mapalreadyrestarted || (time < game_starttime))
122 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
123 if (self.classname == "player") {
124 //PlayerScore_Clear(self);
126 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
128 //stop the player from moving so that he stands still once he gets respawned
129 self.velocity = '0 0 0';
130 self.avelocity = '0 0 0';
131 self.movement = '0 0 0';
140 kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), "", kh_StartRound);
143 if(champion && champion.classname == "player" && player_count > 1)
144 UpdateFrags(champion, +1);
149 void Spawnqueue_Insert(entity e)
153 dprint(strcat("Into queue: ", e.netname, "\n"));
154 e.spawnqueue_in = TRUE;
155 e.spawnqueue_prev = spawnqueue_last;
156 e.spawnqueue_next = world;
158 spawnqueue_last.spawnqueue_next = e;
160 if(!spawnqueue_first)
161 spawnqueue_first = e;
164 void Spawnqueue_Remove(entity e)
168 dprint(strcat("Out of queue: ", e.netname, "\n"));
169 e.spawnqueue_in = FALSE;
170 if(e == spawnqueue_first)
171 spawnqueue_first = e.spawnqueue_next;
172 if(e == spawnqueue_last)
173 spawnqueue_last = e.spawnqueue_prev;
174 if(e.spawnqueue_prev)
175 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
176 if(e.spawnqueue_next)
177 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
178 e.spawnqueue_next = world;
179 e.spawnqueue_prev = world;
182 void Spawnqueue_Unmark(entity e)
187 numspawned = numspawned - 1;
190 void Spawnqueue_Mark(entity e)
195 numspawned = numspawned + 1;
199 * If roundbased arena game mode is active, it centerprints the texts for the
200 * player when player is waiting for the countdown to finish.
201 * Blocks the players movement while countdown is active.
202 * Unblocks the player once the countdown is over.
204 * Called in PlayerPostThink()
206 float roundStartTime_prev; // prevent networkspam
213 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
216 f = ceil(warmup - time);
218 champion = world; // this is done because a if(champion) will not execute if champion = world
220 allowed_to_spawn = 0;
223 allowed_to_spawn = 1;
224 if(ca_players < required_ca_players)
225 allowed_to_spawn = 1;
227 if(time < warmup && !inWarmupStage)
230 allowed_to_spawn = 1;
231 if(champion && g_arena)
232 msg = strcat("The Champion is ", champion_name, "^7\n");
234 if(f != roundStartTime_prev) {
235 msg = strcat(CPID_ROUND_STARTING, msg, "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';
257 //self.fixangle = TRUE;
261 else if(f > -1 && f != roundStartTime_prev)
263 roundStartTime_prev = f;
265 centerprint(self, strcat(CPID_ROUND_STARTING, "^1Begin!\n"));
274 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
275 self.movetype = MOVETYPE_WALK;
279 void count_spawned_players()
281 // TODO fix "*spawned" name, it should rather be "*players" or so
282 // not doing this now to prevent merge hell with Tag
283 // fix after merging with Tag
285 // count amount of players in each team
286 totalspawned = redspawned = bluespawned = yellowspawned = pinkspawned = 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()
376 void Spawnqueue_Check()
378 count_spawned_players();
379 if(g_ca || g_freezetag) // we want to perform this before the return block below (CA)...
381 count_alive_players();
383 if(time < warmup + 1 || inWarmupStage || intermission_running)
387 required_ca_players = max(2, fabs(autocvar_bot_vs_human + 1));
389 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
392 else if(ca_players < required_ca_players) {
395 FOR_EACH_PLAYER(self)
396 centerprint(self, strcat("^1Need at least 1 player in each team to play CA", "^7\n"));
401 else if(!next_round) {
402 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
403 next_round = time + 5;
404 champion = find(world, classname, "player");
406 strunzone(champion_name);
407 champion_name = strzone(champion.netname);
409 else if((!redspawned && !bluespawned) || time - warmup > autocvar_g_ca_round_timelimit) {
410 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
411 next_round = time + 5;
417 if(redalive && !bluealive)
419 play2all("ctf/red_capture.wav");
420 FOR_EACH_CLIENT(self) centerprint(self, "^1 RED ^7team wins the round.\n");
421 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
422 stopalivecheck = TRUE;
424 else if(bluealive && !redalive)
426 play2all("ctf/blue_capture.wav");
427 FOR_EACH_CLIENT(self) centerprint(self, "^4 BLUE ^7team wins the round.\n");
428 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
429 stopalivecheck = TRUE;
433 if((next_round && next_round < time))
435 stopalivecheck = FALSE;
439 } else if(g_freezetag) {
440 if((next_round && next_round < time))
446 //extend next_round if it isn't set yet and only 1 player is spawned
449 next_round = time + 3;
451 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
457 champion = find(world, classname, "player");
458 while(champion && champion.deadflag)
459 champion = find(champion, classname, "player");
463 while(numspawned < maxspawned && spawnqueue_first)
465 self = spawnqueue_first;
467 bprint ("^4", self.netname, "^4 is the next challenger\n");
469 Spawnqueue_Remove(self);
470 Spawnqueue_Mark(self);
472 self.classname = "player";