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();
17 void(entity e) ReturnFlag;
18 void dom_controlpoint_setup();
19 void onslaught_generator_reset();
20 void onslaught_controlpoint_reset();
21 void func_breakable_reset();
22 void assault_objective_reset();
23 void target_assault_roundend_reset();
27 float redalive, bluealive, yellowalive, pinkalive;
29 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
30 float red_players, blue_players, yellow_players, pink_players;
34 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
35 * Sets the 'warmup' global variable.
37 void reset_map(float dorespawn)
42 if(g_arena && autocvar_g_arena_warmup)
43 warmup = time + autocvar_g_arena_warmup;
45 warmup = time + autocvar_g_ca_warmup;
50 warmup = time + autocvar_g_freezetag_warmup;
53 lms_lowest_lives = 999;
54 lms_next_place = player_count;
58 FOR_EACH_CLIENT(self) {
59 // just to make sure, as the FL_PROJECTILE handling is bad for
61 RemoveGrapplingHook();
64 for(self = world; (self = nextent(self)); )
65 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
74 self.team = self.team_saved;
76 if(self.flags & FL_PROJECTILE) // remove any projectiles left
80 // Waypoints and assault start come LAST
81 for(self = world; (self = nextent(self)); )
82 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
91 // Moving the player reset code here since the player-reset depends
92 // on spawnpoint entities which have to be reset first --blub
94 FOR_EACH_CLIENT(self) {
95 if(self.flags & FL_CLIENT) // reset all players
102 PutObserverInServer();
104 else if(g_ca && self.caplayer) {
105 self.classname = "player";
110 if(self.classname == "player")
116 only reset players if a restart countdown is active
117 this can either be due to cvar sv_ready_restart_after_countdown having set
118 restart_mapalreadyrestarted to 1 after the countdown ended or when
119 sv_ready_restart_after_countdown is not used and countdown is still running
121 if (restart_mapalreadyrestarted || (time < game_starttime))
123 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
124 if (self.classname == "player") {
125 //PlayerScore_Clear(self);
127 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
129 //stop the player from moving so that he stands still once he gets respawned
130 self.velocity = '0 0 0';
131 self.avelocity = '0 0 0';
132 self.movement = '0 0 0';
141 kh_Controller_SetThink_NoMsg(autocvar_g_balance_keyhunt_delay_round+(game_starttime - time), kh_StartRound);
144 if(champion && champion.classname == "player" && player_count > 1)
145 UpdateFrags(champion, +1);
150 void Spawnqueue_Insert(entity e)
154 dprint(strcat("Into queue: ", e.netname, "\n"));
155 e.spawnqueue_in = TRUE;
156 e.spawnqueue_prev = spawnqueue_last;
157 e.spawnqueue_next = world;
159 spawnqueue_last.spawnqueue_next = e;
161 if(!spawnqueue_first)
162 spawnqueue_first = e;
165 void Spawnqueue_Remove(entity e)
169 dprint(strcat("Out of queue: ", e.netname, "\n"));
170 e.spawnqueue_in = FALSE;
171 if(e == spawnqueue_first)
172 spawnqueue_first = e.spawnqueue_next;
173 if(e == spawnqueue_last)
174 spawnqueue_last = e.spawnqueue_prev;
175 if(e.spawnqueue_prev)
176 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
177 if(e.spawnqueue_next)
178 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
179 e.spawnqueue_next = world;
180 e.spawnqueue_prev = world;
183 void Spawnqueue_Unmark(entity e)
188 numspawned = numspawned - 1;
191 void Spawnqueue_Mark(entity e)
196 numspawned = numspawned + 1;
200 * If roundbased arena game mode is active, it centerprints the texts for the
201 * player when player is waiting for the countdown to finish.
202 * Blocks the players movement while countdown is active.
203 * Unblocks the player once the countdown is over.
205 * Called in PlayerPostThink()
207 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 allowed_to_spawn = 0;
221 allowed_to_spawn = 1;
222 if(g_ca && !ca_teams_ok)
223 allowed_to_spawn = 1;
225 if(time < warmup && !inWarmupStage)
228 allowed_to_spawn = 1;
229 if(champion && g_arena)
232 centerprint(e, strcat("The Champion is ", champion.netname));
235 if(f != roundStartTime_prev) {
236 roundStartTime_prev = f;
238 Announce("prepareforbattle");
247 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
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';
259 else if(f > -1 && f != roundStartTime_prev)
261 roundStartTime_prev = f;
264 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
267 float start_red_ca_players, start_blue_ca_players;
270 if (e.team == COLOR_TEAM1)
271 start_red_ca_players += 1;
272 else if (e.team == COLOR_TEAM2)
273 start_blue_ca_players += 1;
275 // teams are ok if there's at least 1 player in each team
276 ca_teams_ok = (start_red_ca_players && start_blue_ca_players);
279 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
280 self.movetype = MOVETYPE_WALK;
284 // clear champion to avoid centerprinting again the champion msg
291 // count amount of players in each team
292 total_players = red_players = blue_players = yellow_players = pink_players = 0;
293 FOR_EACH_PLAYER(self) {
294 if (self.team == COLOR_TEAM1)
299 else if (self.team == COLOR_TEAM2)
304 else if (self.team == COLOR_TEAM3)
309 else if (self.team == COLOR_TEAM4)
317 void count_alive_players()
319 totalalive = redalive = bluealive = yellowalive = pinkalive = 0;
322 FOR_EACH_PLAYER(self) {
323 if (self.team == COLOR_TEAM1 && self.health >= 1)
328 else if (self.team == COLOR_TEAM2 && self.health >= 1)
334 FOR_EACH_REALCLIENT(self) {
335 self.redalive_stat = redalive;
336 self.bluealive_stat = bluealive;
341 // count amount of alive players in each team
342 FOR_EACH_PLAYER(self) {
343 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1)
348 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1)
353 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1)
358 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1)
364 FOR_EACH_REALCLIENT(self) {
365 self.redalive_stat = redalive;
366 self.bluealive_stat = bluealive;
367 self.yellowalive_stat = yellowalive;
368 self.pinkalive_stat = pinkalive;
375 * This function finds out whether an arena round is over 1 player is left.
376 * It determines the last player who's still alive and saves it's entity reference
377 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
379 * Gets called in StartFrame()
382 void Spawnqueue_Check()
385 if(g_ca || g_freezetag) // we want to perform this before the return block below (CA)...
387 count_alive_players();
389 if(time < warmup + 1 || inWarmupStage || intermission_running)
393 if(!ca_teams_ok && (red_players && blue_players)) {
396 else if(!ca_teams_ok) {
399 FOR_EACH_PLAYER(self)
400 Send_CSQC_Centerprint_Generic(self, CPID_ROUND_STARTING, "^1Need at least 1 player in each team to play CA", 2, 0);
405 else if(!next_round) {
406 if((red_players && !blue_players) || (blue_players && !red_players)) {
407 next_round = time + 5;
409 else if((!red_players && !blue_players) || time - warmup > autocvar_g_ca_round_timelimit) {
410 FOR_EACH_CLIENT(self) centerprint(self, "^7Round tied");
411 next_round = time + 5;
417 if(redalive && !bluealive)
419 play2all("ctf/red_capture.wav");
420 FOR_EACH_CLIENT(self) centerprint(self, "^1RED ^7team wins the round");
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, "^4BLUE ^7team wins the round");
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";