3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
13 float allowed_to_spawn;
15 float required_ca_players;
18 void PutObserverInServer();
19 void PutClientInServer();
20 void(entity e) ReturnFlag;
21 void dom_controlpoint_setup();
22 void onslaught_generator_reset();
23 void onslaught_controlpoint_reset();
24 void func_breakable_reset();
25 void assault_objective_reset();
26 void target_assault_roundend_reset();
29 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
30 * Sets the 'warmup' global variable.
32 void reset_map(float dorespawn)
37 if(g_arena && cvar("g_arena_warmup"))
38 warmup = time + cvar("g_arena_warmup");
40 warmup = time + cvar("g_ca_warmup");
44 lms_lowest_lives = 999;
45 lms_next_place = player_count;
49 for(self = world; (self = nextent(self)); )
50 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
59 self.team = self.team_saved;
61 if(self.flags & FL_PROJECTILE) // remove any projectiles left
63 stopsound(self, CHAN_PAIN);
68 // Waypoints and assault start come LAST
69 for(self = world; (self = nextent(self)); )
70 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
79 // Moving the player reset code here since the player-reset depends
80 // on spawnpoint entities which have to be reset first --blub
82 FOR_EACH_CLIENT(self) {
83 if(self.flags & FL_CLIENT) // reset all players
90 PutObserverInServer();
92 else if(g_ca && self.caplayer) {
93 self.classname = "player";
99 only reset players if a restart countdown is active
100 this can either be due to cvar sv_ready_restart_after_countdown having set
101 restart_mapalreadyrestarted to 1 after the countdown ended or when
102 sv_ready_restart_after_countdown is not used and countdown is still running
104 if (restart_mapalreadyrestarted || (time < game_starttime))
106 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
107 if (self.classname == "player") {
108 //PlayerScore_Clear(self);
110 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
112 //stop the player from moving so that he stands still once he gets respawned
113 self.velocity = '0 0 0';
114 self.avelocity = '0 0 0';
115 self.movement = '0 0 0';
124 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
127 if(champion && champion.classname == "player" && player_count > 1)
128 UpdateFrags(champion, +1);
131 if(champion && champion.classname == "player" && player_count > 1)
132 TeamScore_AddToTeam(champion.team, ST_SCORE, +1);
137 void Spawnqueue_Insert(entity e)
141 dprint(strcat("Into queue: ", e.netname, "\n"));
142 e.spawnqueue_in = TRUE;
143 e.spawnqueue_prev = spawnqueue_last;
144 e.spawnqueue_next = world;
146 spawnqueue_last.spawnqueue_next = e;
148 if(!spawnqueue_first)
149 spawnqueue_first = e;
152 void Spawnqueue_Remove(entity e)
156 dprint(strcat("Out of queue: ", e.netname, "\n"));
157 e.spawnqueue_in = FALSE;
158 if(e == spawnqueue_first)
159 spawnqueue_first = e.spawnqueue_next;
160 if(e == spawnqueue_last)
161 spawnqueue_last = e.spawnqueue_prev;
162 if(e.spawnqueue_prev)
163 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
164 if(e.spawnqueue_next)
165 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
166 e.spawnqueue_next = world;
167 e.spawnqueue_prev = world;
170 void Spawnqueue_Unmark(entity e)
175 numspawned = numspawned - 1;
178 void Spawnqueue_Mark(entity e)
183 numspawned = numspawned + 1;
187 * If roundbased arena game mode is active, it centerprints the texts for the
188 * player when player is waiting for the countdown to finish.
189 * Blocks the players movement while countdown is active.
190 * Unblocks the player once the countdown is over.
192 * Called in PlayerPostThink()
194 float roundStartTime_prev; // prevent networkspam
200 if((!g_arena && !g_ca) || (g_arena && !arena_roundbased) || (time < game_starttime))
203 f = ceil(warmup - time);
205 champion = world; // this is done because a if(champion) will not execute if champion = world
207 allowed_to_spawn = 0;
210 allowed_to_spawn = 1;
211 if(ca_players < required_ca_players)
212 allowed_to_spawn = 1;
215 if(time < warmup && !inWarmupStage)
218 allowed_to_spawn = 1;
219 if(champion && g_arena)
220 msg = strcat("The Champion is ", champion_name, "^7\n");
221 //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
223 if(f != roundStartTime_prev) {
224 msg = strcat(msg, "Round will start in ", ftos(f),"\n");
225 //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
226 roundStartTime_prev = f;
228 Announce("prepareforbattle");
236 centerprint(self, msg);
240 if(self.spawned && self.classname == "player")
241 self.movetype = MOVETYPE_NONE;
243 self.velocity = '0 0 0';
244 self.avelocity = '0 0 0';
245 self.movement = '0 0 0';
246 //self.fixangle = TRUE;
250 else if(f > -1 && f != roundStartTime_prev)
252 roundStartTime_prev = f;
254 centerprint(self, "^1Begin!\n");
259 FOR_EACH_PLAYER(self)
264 if(self.classname == "player" && self.health > 0)
265 self.movetype = MOVETYPE_WALK;
270 * This function finds out whether an arena round is over 1 player is left.
271 * It determines the last player who's still alive and saves it's entity reference
272 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
274 * Gets called in StartFrame()
276 void Spawnqueue_Check()
278 if(time < warmup + 1 || inWarmupStage)
282 // check the amount of spawned players in each team
283 float redspawned, bluespawned;
284 FOR_EACH_PLAYER(self) {
285 if (self.team == COLOR_TEAM1) redspawned += 1;
286 else if (self.team == COLOR_TEAM2) bluespawned += 1;
289 required_ca_players = max(2, fabs(cvar("bot_vs_human") + 1));
291 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
294 else if(ca_players < required_ca_players) {
295 FOR_EACH_PLAYER(self)
296 centerprint(self, strcat("^1Need at least 1 player in each team to play CA", "^7\n"));
299 else if(!next_round) {
300 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
301 next_round = time + 5;
303 champion = find(world, classname, "player");
305 strunzone(champion_name);
306 champion_name = strzone(champion.netname);
307 string champion_team;
308 if(champion.team == COLOR_TEAM1) {
309 champion_team = "^1Red team";
310 play2all("ctf/red_capture.wav");
312 else if(champion.team == COLOR_TEAM2) {
313 champion_team = "^4Blue team";
314 play2all("ctf/blue_capture.wav");
316 FOR_EACH_CLIENT(self) centerprint(self, strcat(champion_team, "^7 wins the round.", "^7\n"));
318 else if(!redspawned && !bluespawned) {
319 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
320 next_round = time + 5;
324 if((next_round && next_round < time))
330 //extend next_round if it isn't set yet and only 1 player is spawned
333 next_round = time + 3;
335 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
341 champion = find(world, classname, "player");
342 while(champion && champion.deadflag)
343 champion = find(champion, classname, "player");
347 while(numspawned < maxspawned && spawnqueue_first)
349 self = spawnqueue_first;
351 bprint ("^4", self.netname, "^4 is the next challenger\n");
353 Spawnqueue_Remove(self);
354 Spawnqueue_Mark(self);
356 self.classname = "player";