3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
15 void PutObserverInServer();
16 void PutClientInServer();
19 float redalive, bluealive, yellowalive, pinkalive;
21 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
22 float red_players, blue_players, yellow_players, pink_players;
26 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
27 * Sets the 'warmup' global variable.
29 void reset_map(float dorespawn)
34 if(g_arena && autocvar_g_arena_warmup)
35 warmup = time + autocvar_g_arena_warmup;
37 warmup = time + autocvar_g_ca_warmup;
42 warmup = time + autocvar_g_freezetag_warmup;
45 lms_lowest_lives = 999;
46 lms_next_place = player_count;
50 for(self = world; (self = nextent(self)); )
51 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
60 self.team = self.team_saved;
62 if(self.flags & FL_PROJECTILE) // remove any projectiles left
66 // Waypoints and assault start come LAST
67 for(self = world; (self = nextent(self)); )
68 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
77 // Moving the player reset code here since the player-reset depends
78 // on spawnpoint entities which have to be reset first --blub
80 FOR_EACH_CLIENT(self) {
81 if(self.flags & FL_CLIENT) // reset all players
88 PutObserverInServer();
90 else if(g_ca && self.caplayer) {
91 self.classname = "player";
96 if(self.classname == "player")
102 only reset players if a restart countdown is active
103 this can either be due to cvar sv_ready_restart_after_countdown having set
104 restart_mapalreadyrestarted to 1 after the countdown ended or when
105 sv_ready_restart_after_countdown is not used and countdown is still running
107 if (restart_mapalreadyrestarted || (time < game_starttime))
109 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
110 if (self.classname == "player") {
111 //PlayerScore_Clear(self);
113 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
115 //stop the player from moving so that he stands still once he gets respawned
116 self.velocity = '0 0 0';
117 self.avelocity = '0 0 0';
118 self.movement = '0 0 0';
127 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
130 if(champion && champion.classname == "player" && player_count > 1)
131 UpdateFrags(champion, +1);
136 void Spawnqueue_Insert(entity e)
140 dprint(strcat("Into queue: ", e.netname, "\n"));
141 e.spawnqueue_in = TRUE;
142 e.spawnqueue_prev = spawnqueue_last;
143 e.spawnqueue_next = world;
145 spawnqueue_last.spawnqueue_next = e;
147 if(!spawnqueue_first)
148 spawnqueue_first = e;
151 void Spawnqueue_Remove(entity e)
155 dprint(strcat("Out of queue: ", e.netname, "\n"));
156 e.spawnqueue_in = FALSE;
157 if(e == spawnqueue_first)
158 spawnqueue_first = e.spawnqueue_next;
159 if(e == spawnqueue_last)
160 spawnqueue_last = e.spawnqueue_prev;
161 if(e.spawnqueue_prev)
162 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
163 if(e.spawnqueue_next)
164 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
165 e.spawnqueue_next = world;
166 e.spawnqueue_prev = world;
169 void Spawnqueue_Unmark(entity e)
174 numspawned = numspawned - 1;
177 void Spawnqueue_Mark(entity e)
182 numspawned = numspawned + 1;
186 * If roundbased arena game mode is active, it centerprints the texts for the
187 * player when player is waiting for the countdown to finish.
188 * Blocks the players movement while countdown is active.
189 * Unblocks the player once the countdown is over.
191 * Called in StartFrame()
193 float roundStartTime_prev; // prevent networkspam
201 if(champion && g_arena)
204 centerprint(e, strcat("The Champion is ", champion.netname));
209 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
212 f = ceil(warmup - time);
214 allowed_to_spawn = 0;
217 allowed_to_spawn = 1;
218 if(g_ca && !ca_teams_ok)
219 allowed_to_spawn = 1;
221 if(time < warmup && !inWarmupStage)
224 allowed_to_spawn = 1;
225 if(champion && g_arena)
228 centerprint(e, strcat("The Champion is ", champion.netname));
231 if(f != roundStartTime_prev) {
232 roundStartTime_prev = f;
234 Announce("prepareforbattle");
243 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
249 if(e.spawned && e.classname == "player")
250 e.movetype = MOVETYPE_NONE;
251 e.velocity = '0 0 0';
252 e.avelocity = '0 0 0';
253 e.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);
265 ca_teams_ok = (red_players && blue_players); // teams are ok if there's at least 1 player in each team
270 if(e.health > 0 && e.movetype == MOVETYPE_NONE)
271 e.movetype = MOVETYPE_WALK;
276 // clear champion to avoid centerprinting again the champion msg
283 // count amount of players in each team
284 total_players = red_players = blue_players = yellow_players = pink_players = 0;
285 FOR_EACH_PLAYER(self) {
286 if (self.team == COLOR_TEAM1)
291 else if (self.team == COLOR_TEAM2)
296 else if (self.team == COLOR_TEAM3)
301 else if (self.team == COLOR_TEAM4)
309 void count_alive_players()
311 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
314 FOR_EACH_PLAYER(self) {
315 if (self.team == COLOR_TEAM1 && self.health >= 1)
320 else if (self.team == COLOR_TEAM2 && self.health >= 1)
326 FOR_EACH_REALCLIENT(self) {
327 self.redalive_stat = redalive;
328 self.bluealive_stat = bluealive;
333 // count amount of alive players in each team
334 FOR_EACH_PLAYER(self) {
335 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
340 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
345 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
350 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
356 FOR_EACH_REALCLIENT(self) {
357 self.redalive_stat = redalive;
358 self.bluealive_stat = bluealive;
359 self.yellowalive_stat = yellowalive;
360 self.pinkalive_stat = pinkalive;
367 * This function finds out whether an arena round is over 1 player is left.
368 * It determines the last player who's still alive and saves it's entity reference
369 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
371 * Gets called in StartFrame()
374 void Spawnqueue_Check()
376 if(time < warmup + 1 || inWarmupStage || intermission_running)
380 if(!ca_teams_ok && (red_players && blue_players)) {
383 else if(!ca_teams_ok) {
386 FOR_EACH_PLAYER(self)
387 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
392 else if(!next_round) {
393 if(!(redalive && bluealive)) {
394 // every player of (at least) one team is dead, round ends here
396 play2all("ctf/red_capture.wav");
397 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
398 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
401 play2all("ctf/blue_capture.wav");
402 FOR_EACH_CLIENT(self) centerprint(self, "^4BLUE ^7team wins the round");
403 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
406 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
409 else if(time - warmup > autocvar_g_ca_round_timelimit) {
410 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
411 next_round = time + 5;
414 else if(next_round == -1) {
415 // wait for killed players to be put as spectators
416 if(!(red_players && blue_players))
417 next_round = time + 5;
419 else if((next_round > 0 && next_round < time))
424 } else if(g_freezetag) {
425 if((next_round && next_round < time))
431 //extend next_round if it isn't set yet and only 1 player is spawned
434 next_round = time + 3;
436 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
442 champion = find(world, classname, "player");
443 while(champion && champion.deadflag)
444 champion = find(champion, classname, "player");
448 while(numspawned < maxspawned && spawnqueue_first)
450 self = spawnqueue_first;
452 bprint ("^4", self.netname, "^4 is the next challenger\n");
454 Spawnqueue_Remove(self);
455 Spawnqueue_Mark(self);
457 self.classname = "player";