3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
14 void PutObserverInServer();
15 void PutClientInServer();
18 float redalive, bluealive, yellowalive, pinkalive;
20 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
21 float red_players, blue_players, yellow_players, pink_players;
25 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
26 * Sets the 'warmup' global variable.
28 void reset_map(float dorespawn)
33 if(g_arena && autocvar_g_arena_warmup)
34 warmup = time + autocvar_g_arena_warmup;
36 warmup = time + autocvar_g_ca_warmup;
41 warmup = time + autocvar_g_freezetag_warmup;
44 lms_lowest_lives = 999;
45 lms_next_place = player_count;
49 for(self = world; (self = nextent(self)); )
50 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
59 self.team = self.team_saved;
61 if(self.flags & FL_PROJECTILE) // remove any projectiles left
65 // Waypoints and assault start come LAST
66 for(self = world; (self = nextent(self)); )
67 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
76 // Moving the player reset code here since the player-reset depends
77 // on spawnpoint entities which have to be reset first --blub
79 FOR_EACH_CLIENT(self) {
80 if(self.flags & FL_CLIENT) // reset all players
87 PutObserverInServer();
89 else if(g_ca && self.caplayer) {
90 self.classname = "player";
95 if(self.classname == "player")
101 only reset players if a restart countdown is active
102 this can either be due to cvar sv_ready_restart_after_countdown having set
103 restart_mapalreadyrestarted to 1 after the countdown ended or when
104 sv_ready_restart_after_countdown is not used and countdown is still running
106 if (restart_mapalreadyrestarted || (time < game_starttime))
108 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
109 if (self.classname == "player") {
110 //PlayerScore_Clear(self);
112 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
114 //stop the player from moving so that he stands still once he gets respawned
115 self.velocity = '0 0 0';
116 self.avelocity = '0 0 0';
117 self.movement = '0 0 0';
126 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
129 if(champion && champion.classname == "player" && player_count > 1)
130 UpdateFrags(champion, +1);
135 void Spawnqueue_Insert(entity e)
139 dprint(strcat("Into queue: ", e.netname, "\n"));
140 e.spawnqueue_in = TRUE;
141 e.spawnqueue_prev = spawnqueue_last;
142 e.spawnqueue_next = world;
144 spawnqueue_last.spawnqueue_next = e;
146 if(!spawnqueue_first)
147 spawnqueue_first = e;
150 void Spawnqueue_Remove(entity e)
154 dprint(strcat("Out of queue: ", e.netname, "\n"));
155 e.spawnqueue_in = FALSE;
156 if(e == spawnqueue_first)
157 spawnqueue_first = e.spawnqueue_next;
158 if(e == spawnqueue_last)
159 spawnqueue_last = e.spawnqueue_prev;
160 if(e.spawnqueue_prev)
161 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
162 if(e.spawnqueue_next)
163 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
164 e.spawnqueue_next = world;
165 e.spawnqueue_prev = world;
168 void Spawnqueue_Unmark(entity e)
173 numspawned = numspawned - 1;
176 void Spawnqueue_Mark(entity e)
181 numspawned = numspawned + 1;
185 * If roundbased arena game mode is active, it centerprints the texts for the
186 * player when player is waiting for the countdown to finish.
187 * Blocks the players movement while countdown is active.
188 * Unblocks the player once the countdown is over.
190 * Called in StartFrame()
192 float roundStartTime_prev; // prevent networkspam
200 if(warmup && time < warmup)
202 FOR_EACH_REALCLIENT(e)
203 Send_CSQC_Centerprint_Generic_Expire(e, CPID_ROUND_STARTING);
206 if(champion && g_arena)
208 FOR_EACH_REALCLIENT(e)
209 centerprint(e, strcat("The Champion is ", champion.netname));
214 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
217 f = ceil(warmup - time);
220 allowed_to_spawn = 1;
222 allowed_to_spawn = 0;
224 if(time < warmup && !inWarmupStage)
227 allowed_to_spawn = 1;
228 if(champion && g_arena)
230 FOR_EACH_REALCLIENT(e)
231 centerprint(e, strcat("The Champion is ", champion.netname));
234 if(f != roundStartTime_prev) {
235 roundStartTime_prev = f;
236 if(g_ca && !(red_players && blue_players)) {
237 FOR_EACH_REALCLIENT(self)
238 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
239 warmup = time + autocvar_g_ca_warmup;
242 Announce("prepareforbattle");
250 FOR_EACH_REALCLIENT(e)
251 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
258 if(e.spawned && e.classname == "player")
259 e.player_blocked = 1;
263 else if(f > -1 && f != roundStartTime_prev)
265 roundStartTime_prev = f;
267 if(red_players && blue_players)
268 allowed_to_spawn = 0;
273 FOR_EACH_REALCLIENT(e)
274 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
281 e.player_blocked = 0;
286 // clear champion to avoid centerprinting again the champion msg
293 // count amount of players in each team
294 total_players = red_players = blue_players = yellow_players = pink_players = 0;
295 FOR_EACH_PLAYER(self) {
296 if (self.team == COLOR_TEAM1)
301 else if (self.team == COLOR_TEAM2)
306 else if (self.team == COLOR_TEAM3)
311 else if (self.team == COLOR_TEAM4)
319 void count_alive_players()
321 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
324 FOR_EACH_PLAYER(self) {
325 if (self.team == COLOR_TEAM1 && self.health >= 1)
330 else if (self.team == COLOR_TEAM2 && self.health >= 1)
336 FOR_EACH_REALCLIENT(self) {
337 self.redalive_stat = redalive;
338 self.bluealive_stat = bluealive;
343 // count amount of alive players in each team
344 FOR_EACH_PLAYER(self) {
345 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
350 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
355 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
360 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
366 FOR_EACH_REALCLIENT(self) {
367 self.redalive_stat = redalive;
368 self.bluealive_stat = bluealive;
369 self.yellowalive_stat = yellowalive;
370 self.pinkalive_stat = pinkalive;
377 * This function finds out whether an arena round is over 1 player is left.
378 * It determines the last player who's still alive and saves it's entity reference
379 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
381 * Gets called in StartFrame()
383 void Spawnqueue_Check()
385 if(warmup == 0 && g_ca && !inWarmupStage)
387 if(red_players || blue_players)
391 if(time < warmup + 1 || inWarmupStage || intermission_running)
395 if(allowed_to_spawn) // round is not started yet
398 if(!(redalive && bluealive)) {
399 // every player of (at least) one team is dead, round ends here
401 play2all("ctf/red_capture.wav");
402 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
403 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
406 play2all("ctf/blue_capture.wav");
407 FOR_EACH_CLIENT(self) centerprint(self, "^4BLUE ^7team wins the round");
408 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
411 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
414 else if(time - warmup > autocvar_g_ca_round_timelimit) {
415 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
416 next_round = time + 5;
419 else if(next_round == -1) {
420 // wait for killed players to be put as spectators
421 if(!(red_players && blue_players))
422 next_round = time + 5;
424 else if((next_round > 0 && next_round < time))
429 } else if(g_freezetag) {
430 if((next_round && next_round < time))
436 //extend next_round if it isn't set yet and only 1 player is spawned
439 next_round = time + 3;
441 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
447 champion = find(world, classname, "player");
448 while(champion && champion.deadflag)
449 champion = find(champion, classname, "player");
453 while(numspawned < maxspawned && spawnqueue_first)
455 self = spawnqueue_first;
457 bprint ("^4", self.netname, "^4 is the next challenger\n");
459 Spawnqueue_Remove(self);
460 Spawnqueue_Mark(self);
462 self.classname = "player";