3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
13 float required_ca_players;
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 redspawned, bluespawned, yellowspawned, pinkspawned;
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
73 stopsound(self, CHAN_PAIN);
78 // Waypoints and assault start come LAST
79 for(self = world; (self = nextent(self)); )
80 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
89 // Moving the player reset code here since the player-reset depends
90 // on spawnpoint entities which have to be reset first --blub
92 FOR_EACH_CLIENT(self) {
93 if(self.flags & FL_CLIENT) // reset all players
100 PutObserverInServer();
102 else if(g_ca && self.caplayer) {
103 self.classname = "player";
108 if(self.classname == "player")
114 only reset players if a restart countdown is active
115 this can either be due to cvar sv_ready_restart_after_countdown having set
116 restart_mapalreadyrestarted to 1 after the countdown ended or when
117 sv_ready_restart_after_countdown is not used and countdown is still running
119 if (restart_mapalreadyrestarted || (time < game_starttime))
121 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
122 if (self.classname == "player") {
123 //PlayerScore_Clear(self);
125 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
127 //stop the player from moving so that he stands still once he gets respawned
128 self.velocity = '0 0 0';
129 self.avelocity = '0 0 0';
130 self.movement = '0 0 0';
139 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
142 if(champion && champion.classname == "player" && player_count > 1)
143 UpdateFrags(champion, +1);
148 void Spawnqueue_Insert(entity e)
152 dprint(strcat("Into queue: ", e.netname, "\n"));
153 e.spawnqueue_in = TRUE;
154 e.spawnqueue_prev = spawnqueue_last;
155 e.spawnqueue_next = world;
157 spawnqueue_last.spawnqueue_next = e;
159 if(!spawnqueue_first)
160 spawnqueue_first = e;
163 void Spawnqueue_Remove(entity e)
167 dprint(strcat("Out of queue: ", e.netname, "\n"));
168 e.spawnqueue_in = FALSE;
169 if(e == spawnqueue_first)
170 spawnqueue_first = e.spawnqueue_next;
171 if(e == spawnqueue_last)
172 spawnqueue_last = e.spawnqueue_prev;
173 if(e.spawnqueue_prev)
174 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
175 if(e.spawnqueue_next)
176 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
177 e.spawnqueue_next = world;
178 e.spawnqueue_prev = world;
181 void Spawnqueue_Unmark(entity e)
186 numspawned = numspawned - 1;
189 void Spawnqueue_Mark(entity e)
194 numspawned = numspawned + 1;
198 * If roundbased arena game mode is active, it centerprints the texts for the
199 * player when player is waiting for the countdown to finish.
200 * Blocks the players movement while countdown is active.
201 * Unblocks the player once the countdown is over.
203 * Called in PlayerPostThink()
205 float roundStartTime_prev; // prevent networkspam
211 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
214 f = ceil(warmup - time);
216 allowed_to_spawn = 0;
219 allowed_to_spawn = 1;
220 if(ca_players < required_ca_players)
221 allowed_to_spawn = 1;
223 if(time < warmup && !inWarmupStage)
226 allowed_to_spawn = 1;
227 if(champion && g_arena)
230 centerprint(e, strcat("The Champion is ", champion.netname));
233 if(f != roundStartTime_prev) {
234 roundStartTime_prev = f;
236 Announce("prepareforbattle");
245 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
249 if(self.spawned && self.classname == "player")
250 self.movetype = MOVETYPE_NONE;
252 self.velocity = '0 0 0';
253 self.avelocity = '0 0 0';
254 self.movement = '0 0 0';
257 else if(f > -1 && f != roundStartTime_prev)
259 roundStartTime_prev = f;
262 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
271 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
272 self.movetype = MOVETYPE_WALK;
276 // clear champion to avoid centerprinting again the champion msg
281 void count_spawned_players()
283 // TODO fix "*spawned" name, it should rather be "*players" or so
284 // not doing this now to prevent merge hell with Tag
285 // fix after merging with Tag
287 // count amount of players in each team
288 totalspawned = redspawned = bluespawned = yellowspawned = pinkspawned = 0;
289 FOR_EACH_PLAYER(self) {
290 if (self.team == COLOR_TEAM1)
295 else if (self.team == COLOR_TEAM2)
300 else if (self.team == COLOR_TEAM3)
305 else if (self.team == COLOR_TEAM4)
313 void count_alive_players()
315 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
318 FOR_EACH_PLAYER(self) {
319 if (self.team == COLOR_TEAM1 && self.health >= 1)
324 else if (self.team == COLOR_TEAM2 && self.health >= 1)
330 FOR_EACH_REALCLIENT(self) {
331 self.redalive_stat = redalive;
332 self.bluealive_stat = bluealive;
337 // count amount of alive players in each team
338 FOR_EACH_PLAYER(self) {
339 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
344 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
349 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
354 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
360 FOR_EACH_REALCLIENT(self) {
361 self.redalive_stat = redalive;
362 self.bluealive_stat = bluealive;
363 self.yellowalive_stat = yellowalive;
364 self.pinkalive_stat = pinkalive;
371 * This function finds out whether an arena round is over 1 player is left.
372 * It determines the last player who's still alive and saves it's entity reference
373 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
375 * Gets called in StartFrame()
378 void Spawnqueue_Check()
380 count_spawned_players();
381 if(g_ca || g_freezetag) // we want to perform this before the return block below (CA)...
383 count_alive_players();
385 if(time < warmup + 1 || inWarmupStage || intermission_running)
389 required_ca_players = max(2, fabs(autocvar_bot_vs_human + 1));
391 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
394 else if(ca_players < required_ca_players) {
397 FOR_EACH_PLAYER(self)
398 centerprint(self, "^1Need at least 1 player in each team to play CA");
403 else if(!next_round) {
404 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
405 next_round = time + 5;
407 else if((!redspawned && !bluespawned) || time - warmup > autocvar_g_ca_round_timelimit) {
408 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
409 next_round = time + 5;
415 if(redalive && !bluealive)
417 play2all("ctf/red_capture.wav");
418 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
419 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
420 stopalivecheck = TRUE;
422 else if(bluealive && !redalive)
424 play2all("ctf/blue_capture.wav");
425 FOR_EACH_CLIENT(self) centerprint(self, "^4BLUE ^7team wins the round");
426 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
427 stopalivecheck = TRUE;
431 if((next_round && next_round < time))
433 stopalivecheck = FALSE;
437 } else if(g_freezetag) {
438 if((next_round && next_round < time))
444 //extend next_round if it isn't set yet and only 1 player is spawned
447 next_round = time + 3;
449 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
455 champion = find(world, classname, "player");
456 while(champion && champion.deadflag)
457 champion = find(champion, classname, "player");
461 while(numspawned < maxspawned && spawnqueue_first)
463 self = spawnqueue_first;
465 bprint ("^4", self.netname, "^4 is the next challenger\n");
467 Spawnqueue_Remove(self);
468 Spawnqueue_Mark(self);
470 self.classname = "player";