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)
202 allowed_to_spawn = 1;
208 allowed_to_spawn = 1;
209 if(champion && !(g_ca))
210 centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
212 if(f != roundStartTime_prev) {
213 centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
214 roundStartTime_prev = f;
216 play2all("announcer/robotic/prepareforbattle.wav");
218 play2all("announcer/robotic/3.wav");
220 play2all("announcer/robotic/2.wav");
222 play2all("announcer/robotic/1.wav");
227 self.movetype = MOVETYPE_NONE;
229 self.velocity = '0 0 0';
230 self.avelocity = '0 0 0';
231 self.movement = '0 0 0';
232 //self.fixangle = TRUE;
236 else if((!g_ca && self.movetype == MOVETYPE_NONE) || ((g_ca && f > -1 && f != roundStartTime_prev)))
238 if(self.classname == "player")
239 self.movetype = MOVETYPE_WALK;
240 centerprint(self, "^1Fight!\n");
241 roundStartTime_prev = f;
242 play2all("announcer/robotic/begin.wav");
246 FOR_EACH_CLIENT(self) {
247 if (self.classname == "player") {
256 * This function finds out whether an arena round is over 1 player is left.
257 * It determines the last player who's still alive and saves it's entity reference
258 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
260 * Gets called in StartFrame()
262 void Spawnqueue_Check()
264 if(time < warmup + 1)
268 // check the amount of spawned players in each team
269 float redspawned, bluespawned;
270 FOR_EACH_CLIENT(self) {
271 if (self.classname == "player") {
272 if (self.team == COLOR_TEAM1) redspawned += 1;
273 else if (self.team == COLOR_TEAM2) bluespawned += 1;
277 if(player_cnt < 2 && (redspawned && bluespawned)) {
280 else if(player_cnt < 2) {
281 FOR_EACH_CLIENT(self)
282 if(self.classname == "player")
283 centerprint(self, strcat("^1Need at least 2 players to play CA", "^7\n"));
285 allowed_to_spawn = 1;
289 if((redspawned && bluespawned == 0) || (bluespawned && redspawned == 0)) {
290 next_round = time + 5;
292 champion = find(world, classname, "player");
293 string champion_team;
294 if(champion.team == COLOR_TEAM1) {
295 champion_team = "^1Red team";
296 play2all("ctf/red_capture.wav");
298 else if(champion.team == COLOR_TEAM2) {
299 champion_team = "^4Blue team";
300 play2all("ctf/blue_capture.wav");
302 FOR_EACH_CLIENT(self) centerprint(self, strcat(champion_team, "^7 wins the round.", "^7\n"));
303 else if(!redspawned && !bluespawned) {
304 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
305 next_round = time + 5;
309 if((next_round && next_round < time))
315 //extend next_round if it isn't set yet and only 1 player is spawned
318 next_round = time + 3;
320 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
326 champion = find(world, classname, "player");
327 while(champion && champion.deadflag)
328 champion = find(champion, classname, "player");
332 while(numspawned < maxspawned && spawnqueue_first)
334 self = spawnqueue_first;
336 bprint ("^4", self.netname, "^4 is the next challenger\n");
338 Spawnqueue_Remove(self);
339 Spawnqueue_Mark(self);
341 self.classname = "player";