3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
12 float allowed_to_spawn;
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();
27 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
28 * Sets the 'warmup' global variable.
30 void reset_map(float dorespawn)
35 if(g_arena && cvar("g_arena_warmup"))
36 warmup = time + cvar("g_arena_warmup");
38 warmup = time + cvar("g_ca_warmup");
42 lms_lowest_lives = 999;
43 lms_next_place = player_count;
47 for(self = world; (self = nextent(self)); )
48 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
57 self.team = self.team_saved;
59 if(self.flags & FL_PROJECTILE) // remove any projectiles left
61 stopsound(self, CHAN_PAIN);
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";
97 only reset players if a restart countdown is active
98 this can either be due to cvar sv_ready_restart_after_countdown having set
99 restart_mapalreadyrestarted to 1 after the countdown ended or when
100 sv_ready_restart_after_countdown is not used and countdown is still running
102 if (restart_mapalreadyrestarted || (time < game_starttime))
104 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
105 if (self.classname == "player") {
106 //PlayerScore_Clear(self);
108 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
110 //stop the player from moving so that he stands still once he gets respawned
111 self.velocity = '0 0 0';
112 self.avelocity = '0 0 0';
113 self.movement = '0 0 0';
122 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
125 if(champion && champion.classname == "player" && player_cnt > 1)
126 UpdateFrags(champion, +1);
131 void Spawnqueue_Insert(entity e)
135 dprint(strcat("Into queue: ", e.netname, "\n"));
136 e.spawnqueue_in = TRUE;
137 e.spawnqueue_prev = spawnqueue_last;
138 e.spawnqueue_next = world;
140 spawnqueue_last.spawnqueue_next = e;
142 if(!spawnqueue_first)
143 spawnqueue_first = e;
146 void Spawnqueue_Remove(entity e)
150 dprint(strcat("Out of queue: ", e.netname, "\n"));
151 e.spawnqueue_in = FALSE;
152 if(e == spawnqueue_first)
153 spawnqueue_first = e.spawnqueue_next;
154 if(e == spawnqueue_last)
155 spawnqueue_last = e.spawnqueue_prev;
156 if(e.spawnqueue_prev)
157 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
158 if(e.spawnqueue_next)
159 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
160 e.spawnqueue_next = world;
161 e.spawnqueue_prev = world;
164 void Spawnqueue_Unmark(entity e)
169 numspawned = numspawned - 1;
172 void Spawnqueue_Mark(entity e)
177 numspawned = numspawned + 1;
181 * If roundbased arena game mode is active, it centerprints the texts for the
182 * player when player is waiting for the countdown to finish.
183 * Blocks the players movement while countdown is active.
184 * Unblocks the player once the countdown is over.
186 * Called in PlayerPostThink()
188 float roundStartTime_prev; // prevent networkspam
194 if((!g_arena && !g_ca) || (g_arena && !arena_roundbased) || (time < game_starttime))
197 f = floor(warmup - time + 1);
199 allowed_to_spawn = 0;
201 if(g_ca && (player_cnt < 2 || inWarmupStage))
202 allowed_to_spawn = 1;
205 if(time < warmup && !inWarmupStage)
208 allowed_to_spawn = 1;
209 if(champion && g_arena)
210 msg = strcat("The Champion is ", champion.netname, "^7\n");
211 //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
213 if(f != roundStartTime_prev) {
214 msg = strcat(msg, "Round will start in ", ftos(f),"\n");
215 //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
216 roundStartTime_prev = f;
218 Announce("prepareforbattle");
226 centerprint(self, msg);
230 if(self.spawned && self.classname == "player")
231 self.movetype = MOVETYPE_NONE;
233 self.velocity = '0 0 0';
234 self.avelocity = '0 0 0';
235 self.movement = '0 0 0';
236 //self.fixangle = TRUE;
240 else if(f > -1 && f != roundStartTime_prev)
242 roundStartTime_prev = f;
244 centerprint(self, "^1Begin!\n");
249 FOR_EACH_CLIENT(self) {
250 if (self.classname == "player")
256 if(self.classname == "player" && self.health > 0)
257 self.movetype = MOVETYPE_WALK;
262 * This function finds out whether an arena round is over 1 player is left.
263 * It determines the last player who's still alive and saves it's entity reference
264 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
266 * Gets called in StartFrame()
268 void Spawnqueue_Check()
270 if(time < warmup + 1 || inWarmupStage)
274 // check the amount of spawned players in each team
275 float redspawned, bluespawned;
276 FOR_EACH_CLIENT(self) {
277 if (self.classname == "player") {
278 if (self.team == COLOR_TEAM1) redspawned += 1;
279 else if (self.team == COLOR_TEAM2) bluespawned += 1;
283 if(player_cnt < 2 && (redspawned && bluespawned)) {
286 else if(player_cnt < 2) {
287 FOR_EACH_CLIENT(self)
288 if(self.classname == "player")
289 centerprint(self, strcat("^1Need at least 2 players to play CA", "^7\n"));
291 allowed_to_spawn = 1;
295 if((redspawned && bluespawned == 0) || (bluespawned && redspawned == 0)) {
296 next_round = time + 5;
298 champion = find(world, classname, "player");
299 string champion_team;
300 if(champion.team == COLOR_TEAM1) {
301 champion_team = "^1Red team";
302 play2all("ctf/red_capture.wav");
304 else if(champion.team == COLOR_TEAM2) {
305 champion_team = "^4Blue team";
306 play2all("ctf/blue_capture.wav");
308 FOR_EACH_CLIENT(self) centerprint(self, strcat(champion_team, "^7 wins the round.", "^7\n"));
309 else if(!redspawned && !bluespawned) {
310 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
311 next_round = time + 5;
315 if((next_round && next_round < time))
321 //extend next_round if it isn't set yet and only 1 player is spawned
324 next_round = time + 3;
326 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
332 champion = find(world, classname, "player");
333 while(champion && champion.deadflag)
334 champion = find(champion, classname, "player");
338 while(numspawned < maxspawned && spawnqueue_first)
340 self = spawnqueue_first;
342 bprint ("^4", self.netname, "^4 is the next challenger\n");
344 Spawnqueue_Remove(self);
345 Spawnqueue_Mark(self);
347 self.classname = "player";