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();
21 void assault_objective_reset();
22 void target_assault_roundend_reset();
25 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
26 * Sets the 'warmup' global variable.
34 if(cvar("g_arena_warmup"))
35 warmup = time + cvar("g_arena_warmup");
37 lms_lowest_lives = 999;
38 lms_next_place = player_count;
42 for(self = world; (self = nextent(self)); )
43 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
46 self.team = self.team_saved;
48 if(self.use == SUB_DontUseTargets)
49 self.use = SUB_UseTargets;
51 if(self.classname == STR_ITEM_KH_KEY)
53 kh_Key_AssignTo(self, world);
55 // kh_Key_DropAll(self.owner, TRUE);
58 else if(self.classname == "droppedweapon" // cleanup
59 || self.classname == "gib"
60 || self.classname == "body")
64 else if(self.items & (IT_KEY1 | IT_KEY2))
66 DropFlag(self, world, world);
69 else if(self.classname == "rune")
72 if(self.owner.classname != "runematch_spawn_point")
73 DropAllRunes(self.owner);
76 else if(self.classname == "dom_controlpoint")
78 dom_controlpoint_setup();
80 else if(self.flags & FL_ITEM) // reset items
84 self.model = string_null;
85 self.solid = SOLID_NOT;
89 self.model = self.mdl;
90 self.solid = SOLID_TRIGGER;
92 setorigin (self, self.origin);
93 self.think = SUB_Null;
96 else if(self.flags & FL_PROJECTILE) // remove any projectiles left
98 stopsound(self, CHAN_PROJECTILE);
101 else if(self.isdecor)
105 else if(self.classname == "onslaught_generator")
107 onslaught_generator_reset();
109 else if(self.classname == "onslaught_controlpoint")
111 onslaught_controlpoint_reset();
113 // TODO properly reset Assault
114 // General teambased game modes
115 else if(self.classname == "func_breakable")
117 func_breakable_reset();
119 else if(self.classname == "func_assault_destructible")
121 func_breakable_reset();
123 else if(self.classname == "target_objective")
125 assault_objective_reset();
127 else if(self.classname == "target_assault_roundend")
129 target_assault_roundend_reset();
133 // Waypoints and assault start come LAST
134 for(self = world; (self = nextent(self)); )
135 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
137 if(self.classname == "sprite_waypoint")
139 if(self.health | g_keyhunt)
140 WaypointSprite_Kill(self);
142 else if(self.classname == "target_assault_roundstart")
146 else if(self.classname == "trigger_gamestart")
150 self.think = self.use;
151 self.nextthink = game_starttime + self.wait;
158 // Moving the player reset code here since the player-reset depends
159 // on spawnpoint entities which have to be reset first --blub
160 FOR_EACH_CLIENT(self) {
161 if(self.flags & FL_CLIENT) // reset all players
168 PutObserverInServer();
173 only reset players if a restart countdown is active
174 this can either be due to cvar sv_ready_restart_after_countdown having set
175 restart_mapalreadyrestarted to 1 after the countdown ended or when
176 sv_ready_restart_after_countdown is not used and countdown is still running
178 if (restart_mapalreadyrestarted || (time < game_starttime))
180 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
181 if (self.classname == "player") {
182 PlayerScore_Clear(self);
184 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
186 //stop the player from moving so that he stands still once he gets respawned
187 self.velocity = '0 0 0';
188 self.avelocity = '0 0 0';
189 self.movement = '0 0 0';
198 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
202 UpdateFrags(champion, +1);
207 void Spawnqueue_Insert(entity e)
211 dprint(strcat("Into queue: ", e.netname, "\n"));
212 e.spawnqueue_in = TRUE;
213 e.spawnqueue_prev = spawnqueue_last;
214 e.spawnqueue_next = world;
216 spawnqueue_last.spawnqueue_next = e;
218 if(!spawnqueue_first)
219 spawnqueue_first = e;
222 void Spawnqueue_Remove(entity e)
226 dprint(strcat("Out of queue: ", e.netname, "\n"));
227 e.spawnqueue_in = FALSE;
228 if(e == spawnqueue_first)
229 spawnqueue_first = e.spawnqueue_next;
230 if(e == spawnqueue_last)
231 spawnqueue_last = e.spawnqueue_prev;
232 if(e.spawnqueue_prev)
233 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
234 if(e.spawnqueue_next)
235 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
236 e.spawnqueue_next = world;
237 e.spawnqueue_prev = world;
240 void Spawnqueue_Unmark(entity e)
245 numspawned = numspawned - 1;
248 void Spawnqueue_Mark(entity e)
253 numspawned = numspawned + 1;
257 * If roundbased arena game mode is active, it centerprints the texts for the
258 * player when player is waiting for the countdown to finish.
259 * Blocks the players movement while countdown is active.
260 * Unblocks the player once the countdown is over.
262 * Called in PlayerPostThink()
269 if(!g_arena || !arena_roundbased || (time < game_starttime))
272 f = rint(warmup - time);
275 if(time < warmup && self.spawned)
278 msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
281 msg = strcat(msg, "Round will start in ", ftos(f));
285 msg = strcat(msg, "^1Fight!");
288 centerprint(self, msg);
291 self.movetype = MOVETYPE_NONE;
293 self.velocity = '0 0 0';
294 self.avelocity = '0 0 0';
295 self.movement = '0 0 0';
296 //self.fixangle = TRUE;
298 else if(self.movetype == MOVETYPE_NONE)
300 self.movetype = MOVETYPE_WALK;
301 centerprint(self, "\n");
309 * This function finds out whether an arena round is over 1 player is left.
310 * It determines the last player who's still alive and saves it's entity reference
311 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
313 * Gets called in StartFrame()
315 void Spawnqueue_Check()
317 if(time < warmup + 1)
320 //extend next_round if it isn't set yet and only 1 player is spawned
323 next_round = time + 3;
325 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
331 champion = find(world, classname, "player");
332 while(champion && champion.deadflag)
333 champion = find(champion, classname, "player");
337 while(numspawned < maxspawned && spawnqueue_first)
339 self = spawnqueue_first;
341 bprint ("^4", self.netname, "^4 is the next challenger\n");
343 Spawnqueue_Remove(self);
344 Spawnqueue_Mark(self);
346 self.classname = "player";