3 float arena_roundbased;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
13 void PutObserverInServer();
14 void PutClientInServer();
15 void(entity e) ReturnFlag;
16 void(entity e) removedecor;
17 void dom_controlpoint_setup();
18 void onslaught_generator_reset();
19 void onslaught_controlpoint_reset();
20 void func_breakable_reset();
23 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
24 * Sets the 'warmup' global variable.
32 if(cvar("g_arena_warmup"))
33 warmup = time + cvar("g_arena_warmup");
35 lms_lowest_lives = 999;
36 lms_next_place = player_count;
40 for(self = world; (self = nextent(self)); )
41 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
43 if(self.classname == STR_ITEM_KH_KEY)
45 kh_Key_AssignTo(self, world);
47 // kh_Key_DropAll(self.owner, TRUE);
50 else if(self.classname == "droppedweapon" // cleanup
51 || self.classname == "gib"
52 || self.classname == "body")
56 else if(self.items & (IT_KEY1 | IT_KEY2))
58 DropFlag(self, world, world);
61 else if(self.classname == "rune")
64 if(self.owner.classname != "runematch_spawn_point")
65 DropAllRunes(self.owner);
68 else if(self.classname == "dom_controlpoint")
70 dom_controlpoint_setup();
72 else if(self.flags & FL_ITEM) // reset items
76 self.model = string_null;
77 self.solid = SOLID_NOT;
81 self.model = self.mdl;
82 self.solid = SOLID_TRIGGER;
84 setorigin (self, self.origin);
85 self.think = SUB_Null;
88 else if(self.flags & FL_PROJECTILE) // remove any projectiles left
90 sound(self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
97 else if(self.classname == "onslaught_generator")
99 onslaught_generator_reset();
101 else if(self.classname == "onslaught_controlpoint")
103 onslaught_controlpoint_reset();
105 // TODO properly reset Assault
106 // General teambased game modes
107 else if(self.classname == "info_player_deathmatch")
109 self.team = self.team_saved;
111 else if(self.classname == "func_breakable" || self.classname == "func_assault_destructible")
113 func_breakable_reset();
117 // Waypoints come LAST (keyhunt keys reference them)
118 for(self = world; (self = nextent(self)); )
119 if(self.classname == "sprite_waypoint")
121 if(self.health | g_keyhunt)
122 WaypointSprite_Kill(self);
125 // Moving the player reset code here since the player-reset depends
126 // on spawnpoint entities which have to be reset first --blub
127 FOR_EACH_CLIENT(self) {
128 if(self.flags & FL_CLIENT) // reset all players
135 PutObserverInServer();
140 only reset players if a restart countdown is active
141 this can either be due to cvar sv_ready_restart_after_countdown having set
142 restart_mapalreadyrestarted to 1 after the countdown ended or when
143 sv_ready_restart_after_countdown is not used and countdown is still running
145 if (restart_mapalreadyrestarted || (time < game_starttime))
147 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
148 if (self.classname == "player") {
149 PlayerScore_Clear(self);
151 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
153 //stop the player from moving so that he stands still once he gets respawned
154 self.velocity = '0 0 0';
155 self.avelocity = '0 0 0';
156 self.movement = '0 0 0';
165 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
169 UpdateFrags(champion, +1);
174 void Spawnqueue_Insert(entity e)
178 dprint(strcat("Into queue: ", e.netname, "\n"));
179 e.spawnqueue_in = TRUE;
180 e.spawnqueue_prev = spawnqueue_last;
181 e.spawnqueue_next = world;
183 spawnqueue_last.spawnqueue_next = e;
185 if(!spawnqueue_first)
186 spawnqueue_first = e;
189 void Spawnqueue_Remove(entity e)
193 dprint(strcat("Out of queue: ", e.netname, "\n"));
194 e.spawnqueue_in = FALSE;
195 if(e == spawnqueue_first)
196 spawnqueue_first = e.spawnqueue_next;
197 if(e == spawnqueue_last)
198 spawnqueue_last = e.spawnqueue_prev;
199 if(e.spawnqueue_prev)
200 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
201 if(e.spawnqueue_next)
202 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
203 e.spawnqueue_next = world;
204 e.spawnqueue_prev = world;
207 void Spawnqueue_Unmark(entity e)
212 numspawned = numspawned - 1;
215 void Spawnqueue_Mark(entity e)
220 numspawned = numspawned + 1;
224 * If roundbased arena game mode is active, it centerprints the texts for the
225 * player when player is waiting for the countdown to finish.
226 * Blocks the players movement while countdown is active.
227 * Unblocks the player once the countdown is over.
229 * Called in PlayerPostThink()
236 if(!g_arena || !arena_roundbased || (time < game_starttime))
239 f = rint(warmup - time);
242 if(time < warmup && self.spawned)
245 msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
248 msg = strcat(msg, "Round will start in ", ftos(f));
252 msg = strcat(msg, "^1Fight!");
255 centerprint(self, msg);
258 self.movetype = MOVETYPE_NONE;
260 self.velocity = '0 0 0';
261 self.avelocity = '0 0 0';
262 self.movement = '0 0 0';
263 //self.fixangle = TRUE;
265 else if(self.movetype == MOVETYPE_NONE)
267 self.movetype = MOVETYPE_WALK;
268 centerprint(self, "\n");
276 * This function finds out whether an arena round is over 1 player is left.
277 * It determines the last player who's still alive and saves it's entity reference
278 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
280 * Gets called in StartFrame()
282 void Spawnqueue_Check()
284 if(time < warmup + 1)
287 //extend next_round if it isn't set yet and only 1 player is spawned
290 next_round = time + 3;
292 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
298 champion = find(world, classname, "player");
299 while(champion && champion.deadflag)
300 champion = find(champion, classname, "player");
304 while(numspawned < maxspawned && spawnqueue_first)
306 self = spawnqueue_first;
308 bprint ("^4", self.netname, "^4 is the next challenger\n");
310 Spawnqueue_Remove(self);
311 Spawnqueue_Mark(self);
313 self.classname = "player";