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
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_NoMsg(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
208 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
211 f = ceil(warmup - time);
213 allowed_to_spawn = 0;
216 allowed_to_spawn = 1;
217 if(ca_players < required_ca_players)
218 allowed_to_spawn = 1;
220 if(time < warmup && !inWarmupStage)
223 allowed_to_spawn = 1;
224 if(champion && g_arena)
227 centerprint(e, strcat("The Champion is ", champion.netname));
230 if(f != roundStartTime_prev) {
231 roundStartTime_prev = f;
233 Announce("prepareforbattle");
242 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
246 if(self.spawned && self.classname == "player")
247 self.movetype = MOVETYPE_NONE;
249 self.velocity = '0 0 0';
250 self.avelocity = '0 0 0';
251 self.movement = '0 0 0';
254 else if(f > -1 && f != roundStartTime_prev)
256 roundStartTime_prev = f;
259 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
268 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
269 self.movetype = MOVETYPE_WALK;
273 // clear champion to avoid centerprinting again the champion msg
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()
375 void Spawnqueue_Check()
377 count_spawned_players();
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 required_ca_players = max(2, fabs(autocvar_bot_vs_human + 1));
388 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
391 else if(ca_players < required_ca_players) {
394 FOR_EACH_PLAYER(self)
395 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
400 else if(!next_round) {
401 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
402 next_round = time + 5;
404 else if((!redspawned && !bluespawned) || time - warmup > autocvar_g_ca_round_timelimit) {
405 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
406 next_round = time + 5;
412 if(redalive && !bluealive)
414 play2all("ctf/red_capture.wav");
415 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
416 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
417 stopalivecheck = TRUE;
419 else if(bluealive && !redalive)
421 play2all("ctf/blue_capture.wav");
422 FOR_EACH_CLIENT(self) centerprint(self, "^4BLUE ^7team wins the round");
423 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
424 stopalivecheck = TRUE;
428 if((next_round && next_round < time))
430 stopalivecheck = FALSE;
434 } else if(g_freezetag) {
435 if((next_round && next_round < time))
441 //extend next_round if it isn't set yet and only 1 player is spawned
444 next_round = time + 3;
446 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
452 champion = find(world, classname, "player");
453 while(champion && champion.deadflag)
454 champion = find(champion, classname, "player");
458 while(numspawned < maxspawned && spawnqueue_first)
460 self = spawnqueue_first;
462 bprint ("^4", self.netname, "^4 is the next challenger\n");
464 Spawnqueue_Remove(self);
465 Spawnqueue_Mark(self);
467 self.classname = "player";