3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
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();
29 float redalive, bluealive, yellowalive, pinkalive;
30 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
31 float redspawned, bluespawned, yellowspawned, pinkspawned;
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 && cvar("g_arena_warmup"))
43 warmup = time + cvar("g_arena_warmup");
45 warmup = time + cvar("g_ca_warmup");
50 warmup = time + cvar("g_freezetag_warmup");
53 lms_lowest_lives = 999;
54 lms_next_place = player_count;
58 for(self = world; (self = nextent(self)); )
59 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
68 self.team = self.team_saved;
70 if(self.flags & FL_PROJECTILE) // remove any projectiles left
72 stopsound(self, CHAN_PAIN);
77 // Waypoints and assault start come LAST
78 for(self = world; (self = nextent(self)); )
79 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
88 // Moving the player reset code here since the player-reset depends
89 // on spawnpoint entities which have to be reset first --blub
91 FOR_EACH_CLIENT(self) {
92 if(self.flags & FL_CLIENT) // reset all players
99 PutObserverInServer();
101 else if(g_ca && self.caplayer) {
102 self.classname = "player";
107 if(self.classname == "player")
113 only reset players if a restart countdown is active
114 this can either be due to cvar sv_ready_restart_after_countdown having set
115 restart_mapalreadyrestarted to 1 after the countdown ended or when
116 sv_ready_restart_after_countdown is not used and countdown is still running
118 if (restart_mapalreadyrestarted || (time < game_starttime))
120 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
121 if (self.classname == "player") {
122 //PlayerScore_Clear(self);
124 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
126 //stop the player from moving so that he stands still once he gets respawned
127 self.velocity = '0 0 0';
128 self.avelocity = '0 0 0';
129 self.movement = '0 0 0';
138 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
141 if(champion && champion.classname == "player" && player_count > 1)
142 UpdateFrags(champion, +1);
147 void Spawnqueue_Insert(entity e)
151 dprint(strcat("Into queue: ", e.netname, "\n"));
152 e.spawnqueue_in = TRUE;
153 e.spawnqueue_prev = spawnqueue_last;
154 e.spawnqueue_next = world;
156 spawnqueue_last.spawnqueue_next = e;
158 if(!spawnqueue_first)
159 spawnqueue_first = e;
162 void Spawnqueue_Remove(entity e)
166 dprint(strcat("Out of queue: ", e.netname, "\n"));
167 e.spawnqueue_in = FALSE;
168 if(e == spawnqueue_first)
169 spawnqueue_first = e.spawnqueue_next;
170 if(e == spawnqueue_last)
171 spawnqueue_last = e.spawnqueue_prev;
172 if(e.spawnqueue_prev)
173 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
174 if(e.spawnqueue_next)
175 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
176 e.spawnqueue_next = world;
177 e.spawnqueue_prev = world;
180 void Spawnqueue_Unmark(entity e)
185 numspawned = numspawned - 1;
188 void Spawnqueue_Mark(entity e)
193 numspawned = numspawned + 1;
197 * If roundbased arena game mode is active, it centerprints the texts for the
198 * player when player is waiting for the countdown to finish.
199 * Blocks the players movement while countdown is active.
200 * Unblocks the player once the countdown is over.
202 * Called in PlayerPostThink()
204 float roundStartTime_prev; // prevent networkspam
210 if((!g_arena && !g_ca && !g_freezetag) || (g_arena && !arena_roundbased) || (time < game_starttime))
214 !((redspawned >= 1 && bluespawned >= 1)
215 || (redspawned >= 1 && yellowspawned >= 1)
216 || (redspawned >= 1 && pinkspawned >= 1)
217 || (bluespawned >= 1 && yellowspawned >= 1)
218 || (bluespawned >= 1 && pinkspawned >= 1)
219 || (yellowspawned >= 1 && pinkspawned >= 1)))
221 warmup = time + cvar("g_freezetag_warmup");
224 f = ceil(warmup - time);
226 champion = world; // this is done because a if(champion) will not execute if champion = world
228 allowed_to_spawn = 0;
231 allowed_to_spawn = 1;
232 if(ca_players < required_ca_players)
233 allowed_to_spawn = 1;
236 if(time < warmup && !inWarmupStage)
239 allowed_to_spawn = 1;
240 if(champion && g_arena)
241 msg = strcat("The Champion is ", champion_name, "^7\n");
242 //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));
244 if(f != roundStartTime_prev) {
245 msg = strcat(msg, "Round will start in ", ftos(f),"\n");
246 //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));
247 roundStartTime_prev = f;
249 Announce("prepareforbattle");
257 centerprint(self, msg);
261 if(self.spawned && self.classname == "player")
262 self.movetype = MOVETYPE_NONE;
264 self.velocity = '0 0 0';
265 self.avelocity = '0 0 0';
266 self.movement = '0 0 0';
267 //self.fixangle = TRUE;
271 else if(f > -1 && f != roundStartTime_prev)
273 roundStartTime_prev = f;
275 centerprint(self, "^1Begin!\n");
280 FOR_EACH_PLAYER(self)
285 if(self.classname == "player" && self.health > 0 && self.movetype == MOVETYPE_NONE)
286 self.movetype = MOVETYPE_WALK;
289 * This function finds out whether an arena round is over 1 player is left.
290 * It determines the last player who's still alive and saves it's entity reference
291 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
293 * Gets called in StartFrame()
295 void Spawnqueue_Check()
297 // check the amount of spawned players in each team
298 redspawned = bluespawned = yellowspawned = pinkspawned = 0;
299 FOR_EACH_PLAYER(self) {
300 if (self.team == COLOR_TEAM1) redspawned += 1;
301 else if (self.team == COLOR_TEAM2) bluespawned += 1;
302 else if (self.team == COLOR_TEAM3) yellowspawned += 1;
303 else if (self.team == COLOR_TEAM4) pinkspawned += 1;
306 if(g_ca) // we want to perform this before the return block below...
308 // this is STUPID to perform again, but has to be done so that we can give instant feedback when a round ends
309 // and so the code won't start searching for a champion using find() before all players are actually REMOVED
310 redalive = 0; bluealive = 0;
311 FOR_EACH_PLAYER(self) {
312 if (self.team == COLOR_TEAM1 && self.health >= 1) redalive += 1;
313 else if (self.team == COLOR_TEAM2 && self.health >= 1) bluealive += 1;
315 // as if the above stuff wasn't stupid enough, let's run it a third time! :D
316 // (so that we can send redalive/bluealive as a stat)
317 FOR_EACH_PLAYER(self) {
318 self.redalive_stat = redalive;
319 self.bluealive_stat = bluealive;
324 redalive = bluealive = yellowalive = pinkalive = 0;
325 FOR_EACH_PLAYER(self) {
326 if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1) redalive += 1;
327 else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1) bluealive += 1;
328 else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1) yellowalive += 1;
329 else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1) pinkalive += 1;
331 FOR_EACH_PLAYER(self) {
332 self.redalive_stat = redalive;
333 self.bluealive_stat = bluealive;
334 self.yellowalive_stat = yellowalive;
335 self.pinkalive_stat = pinkalive;
338 if(time < warmup + 1 || inWarmupStage)
342 required_ca_players = max(2, fabs(cvar("bot_vs_human") + 1));
344 if(ca_players < required_ca_players && (redspawned && bluespawned)) {
347 else if(ca_players < required_ca_players) {
348 FOR_EACH_PLAYER(self)
349 centerprint(self, strcat("^1Need at least 1 player in each team to play CA", "^7\n"));
352 else if(!next_round) {
353 if((redspawned && !bluespawned) || (bluespawned && !redspawned)) {
354 next_round = time + 5;
355 champion = find(world, classname, "player");
357 strunzone(champion_name);
358 champion_name = strzone(champion.netname);
360 else if((!redspawned && !bluespawned) || time - warmup > cvar("g_ca_round_timelimit")) {
361 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));
362 next_round = time + 5;
368 if(redalive && !bluealive)
370 play2all("ctf/red_capture.wav");
371 FOR_EACH_CLIENT(self) centerprint(self, "^1 RED ^7team wins the round.\n");
372 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, +1);
373 stopalivecheck = TRUE;
375 else if(bluealive && !redalive)
377 play2all("ctf/blue_capture.wav");
378 FOR_EACH_CLIENT(self) centerprint(self, "^4 BLUE ^7team wins the round.\n");
379 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, +1);
380 stopalivecheck = TRUE;
384 if((next_round && next_round < time))
386 stopalivecheck = FALSE;
390 } else if(g_freezetag) {
391 if((next_round && next_round < time))
397 //extend next_round if it isn't set yet and only 1 player is spawned
400 next_round = time + 3;
402 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
408 champion = find(world, classname, "player");
409 while(champion && champion.deadflag)
410 champion = find(champion, classname, "player");
414 while(numspawned < maxspawned && spawnqueue_first)
416 self = spawnqueue_first;
418 bprint ("^4", self.netname, "^4 is the next challenger\n");
420 Spawnqueue_Remove(self);
421 Spawnqueue_Mark(self);
423 self.classname = "player";