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;
14 float required_ca_players;
17 void PutObserverInServer();
18 void PutClientInServer();
19 void(entity e) ReturnFlag;
20 void dom_controlpoint_setup();
21 void onslaught_generator_reset();
22 void onslaught_controlpoint_reset();
23 void func_breakable_reset();
24 void assault_objective_reset();
25 void target_assault_roundend_reset();
28 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
29 * Sets the 'warmup' global variable.
31 void reset_map(float dorespawn)
36 if(g_arena && cvar("g_arena_warmup"))
37 warmup = time + cvar("g_arena_warmup");
39 warmup = time + cvar("g_ca_warmup");
43 lms_lowest_lives = 999;
44 lms_next_place = player_count;
48 for(self = world; (self = nextent(self)); )
49 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
58 self.team = self.team_saved;
60 if(self.flags & FL_PROJECTILE) // remove any projectiles left
62 stopsound(self, CHAN_PAIN);
67 // Waypoints and assault start come LAST
68 for(self = world; (self = nextent(self)); )
69 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
78 // Moving the player reset code here since the player-reset depends
79 // on spawnpoint entities which have to be reset first --blub
81 FOR_EACH_CLIENT(self) {
82 if(self.flags & FL_CLIENT) // reset all players
89 PutObserverInServer();
91 else if(g_ca && self.caplayer) {
92 self.classname = "player";
98 only reset players if a restart countdown is active
99 this can either be due to cvar sv_ready_restart_after_countdown having set
100 restart_mapalreadyrestarted to 1 after the countdown ended or when
101 sv_ready_restart_after_countdown is not used and countdown is still running
103 if (restart_mapalreadyrestarted || (time < game_starttime))
105 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
106 if (self.classname == "player") {
107 //PlayerScore_Clear(self);
109 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
111 //stop the player from moving so that he stands still once he gets respawned
112 self.velocity = '0 0 0';
113 self.avelocity = '0 0 0';
114 self.movement = '0 0 0';
123 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
126 if(champion && champion.classname == "player" && player_count > 1)
127 UpdateFrags(champion, +1);
130 if(champion && champion.classname == "player" && player_count > 1)
131 TeamScore_AddToTeam(champion.team, SP_SCORE, 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 PlayerPostThink()
193 float roundStartTime_prev; // prevent networkspam
199 if((!g_arena && !g_ca) || (g_arena && !arena_roundbased) || (time < game_starttime))
202 f = floor(warmup - time + 1);
204 allowed_to_spawn = 0;
207 allowed_to_spawn = 1;
210 if(time < warmup && !inWarmupStage)
213 allowed_to_spawn = 1;
214 if(champion && g_arena)
215 msg = strcat("The Champion is ", champion.netname, "^7\n");
216 //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
218 if(f != roundStartTime_prev) {
219 msg = strcat(msg, "Round will start in ", ftos(f),"\n");
220 //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
221 roundStartTime_prev = f;
223 Announce("prepareforbattle");
231 centerprint(self, msg);
235 if(self.spawned && self.classname == "player")
236 self.movetype = MOVETYPE_NONE;
238 self.velocity = '0 0 0';
239 self.avelocity = '0 0 0';
240 self.movement = '0 0 0';
241 //self.fixangle = TRUE;
245 else if(f > -1 && f != roundStartTime_prev)
247 roundStartTime_prev = f;
249 centerprint(self, "^1Begin!\n");
254 FOR_EACH_PLAYER(self)
259 if(self.classname == "player" && self.health > 0)
260 self.movetype = MOVETYPE_WALK;
265 * This function finds out whether an arena round is over 1 player is left.
266 * It determines the last player who's still alive and saves it's entity reference
267 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
269 * Gets called in StartFrame()
271 void Spawnqueue_Check()
273 if(time < warmup + 1 || inWarmupStage)
277 // check the amount of spawned players in each team
278 float redspawned, bluespawned;
279 FOR_EACH_PLAYER(self) {
280 if (self.team == COLOR_TEAM1) redspawned += 1;
281 else if (self.team == COLOR_TEAM2) bluespawned += 1;
284 required_ca_players = max(2, fabs(cvar("bot_vs_human") + 1));
286 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
289 else if(ca_players < required_ca_players) {
290 FOR_EACH_PLAYER(self)
291 centerprint(self, strcat("^1Need at least 1 player in each team to play CA", "^7\n"));
293 allowed_to_spawn = 1;
296 else if(!next_round) {
297 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
298 next_round = time + 5;
300 champion = find(world, classname, "player");
301 string champion_team;
302 if(champion.team == COLOR_TEAM1) {
303 champion_team = "^1Red team";
304 play2all("ctf/red_capture.wav");
306 else if(champion.team == COLOR_TEAM2) {
307 champion_team = "^4Blue team";
308 play2all("ctf/blue_capture.wav");
310 FOR_EACH_CLIENT(self) centerprint(self, strcat(champion_team, "^7 wins the round.", "^7\n"));
312 else if(!redspawned && !bluespawned) {
313 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
314 next_round = time + 5;
318 if((next_round && next_round < time))
324 //extend next_round if it isn't set yet and only 1 player is spawned
327 next_round = time + 3;
329 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
335 champion = find(world, classname, "player");
336 while(champion && champion.deadflag)
337 champion = find(champion, classname, "player");
341 while(numspawned < maxspawned && spawnqueue_first)
343 self = spawnqueue_first;
345 bprint ("^4", self.netname, "^4 is the next challenger\n");
347 Spawnqueue_Remove(self);
348 Spawnqueue_Mark(self);
350 self.classname = "player";