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.
28 void reset_map(float norespawn)
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)
52 self.team = self.team_saved;
54 if(self.classname == STR_ITEM_KH_KEY)
56 kh_Key_AssignTo(self, world);
59 else if(self.classname == "droppedweapon" // cleanup
60 || self.classname == "gib"
61 || self.classname == "body")
65 else if(self.items & (IT_KEY1 | IT_KEY2))
67 DropFlag(self, world, world);
70 else if(self.classname == "rune")
73 if(self.owner.classname != "runematch_spawn_point")
74 DropAllRunes(self.owner);
77 else if(self.classname == "dom_controlpoint")
79 dom_controlpoint_setup();
81 else if(self.flags & FL_ITEM) // reset items
85 self.model = string_null;
86 self.solid = SOLID_NOT;
90 self.model = self.mdl;
91 self.solid = SOLID_TRIGGER;
93 setorigin (self, self.origin);
94 self.think = SUB_Null;
97 else if(self.flags & FL_PROJECTILE) // remove any projectiles left
99 stopsound(self, CHAN_PROJECTILE);
102 else if(self.isdecor)
106 else if(self.classname == "onslaught_generator")
108 onslaught_generator_reset();
110 else if(self.classname == "onslaught_controlpoint")
112 onslaught_controlpoint_reset();
114 // TODO properly reset Assault
115 // General teambased game modes
116 else if(self.classname == "func_breakable")
118 func_breakable_reset();
120 else if(self.classname == "func_assault_destructible")
122 func_breakable_reset();
124 else if(self.classname == "target_objective")
126 assault_objective_reset();
128 else if(self.classname == "target_assault_roundend")
130 target_assault_roundend_reset();
134 // Waypoints and assault start come LAST
135 for(self = world; (self = nextent(self)); )
136 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
138 if(self.classname == "sprite_waypoint")
140 if(self.health | g_keyhunt)
141 WaypointSprite_Kill(self);
143 else if(self.classname == "target_assault_roundstart")
147 else if(self.classname == "trigger_gamestart")
151 self.think = self.use;
152 self.nextthink = game_starttime + self.wait;
159 // Moving the player reset code here since the player-reset depends
160 // on spawnpoint entities which have to be reset first --blub
162 FOR_EACH_CLIENT(self) {
163 if(self.flags & FL_CLIENT) // reset all players
170 PutObserverInServer();
175 only reset players if a restart countdown is active
176 this can either be due to cvar sv_ready_restart_after_countdown having set
177 restart_mapalreadyrestarted to 1 after the countdown ended or when
178 sv_ready_restart_after_countdown is not used and countdown is still running
180 if (restart_mapalreadyrestarted || (time < game_starttime))
182 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
183 if (self.classname == "player") {
184 PlayerScore_Clear(self);
186 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
188 //stop the player from moving so that he stands still once he gets respawned
189 self.velocity = '0 0 0';
190 self.avelocity = '0 0 0';
191 self.movement = '0 0 0';
200 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
204 UpdateFrags(champion, +1);
209 void Spawnqueue_Insert(entity e)
213 dprint(strcat("Into queue: ", e.netname, "\n"));
214 e.spawnqueue_in = TRUE;
215 e.spawnqueue_prev = spawnqueue_last;
216 e.spawnqueue_next = world;
218 spawnqueue_last.spawnqueue_next = e;
220 if(!spawnqueue_first)
221 spawnqueue_first = e;
224 void Spawnqueue_Remove(entity e)
228 dprint(strcat("Out of queue: ", e.netname, "\n"));
229 e.spawnqueue_in = FALSE;
230 if(e == spawnqueue_first)
231 spawnqueue_first = e.spawnqueue_next;
232 if(e == spawnqueue_last)
233 spawnqueue_last = e.spawnqueue_prev;
234 if(e.spawnqueue_prev)
235 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
236 if(e.spawnqueue_next)
237 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
238 e.spawnqueue_next = world;
239 e.spawnqueue_prev = world;
242 void Spawnqueue_Unmark(entity e)
247 numspawned = numspawned - 1;
250 void Spawnqueue_Mark(entity e)
255 numspawned = numspawned + 1;
259 * If roundbased arena game mode is active, it centerprints the texts for the
260 * player when player is waiting for the countdown to finish.
261 * Blocks the players movement while countdown is active.
262 * Unblocks the player once the countdown is over.
264 * Called in PlayerPostThink()
271 if(!g_arena || !arena_roundbased || (time < game_starttime))
274 f = rint(warmup - time);
277 if(time < warmup && self.spawned)
280 msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
283 msg = strcat(msg, "Round will start in ", ftos(f));
287 msg = strcat(msg, "^1Fight!");
290 centerprint(self, msg);
293 self.movetype = MOVETYPE_NONE;
295 self.velocity = '0 0 0';
296 self.avelocity = '0 0 0';
297 self.movement = '0 0 0';
298 //self.fixangle = TRUE;
300 else if(self.movetype == MOVETYPE_NONE)
302 self.movetype = MOVETYPE_WALK;
303 centerprint(self, "\n");
311 * This function finds out whether an arena round is over 1 player is left.
312 * It determines the last player who's still alive and saves it's entity reference
313 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
315 * Gets called in StartFrame()
317 void Spawnqueue_Check()
319 if(time < warmup + 1)
322 //extend next_round if it isn't set yet and only 1 player is spawned
325 next_round = time + 3;
327 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
333 champion = find(world, classname, "player");
334 while(champion && champion.deadflag)
335 champion = find(champion, classname, "player");
339 while(numspawned < maxspawned && spawnqueue_first)
341 self = spawnqueue_first;
343 bprint ("^4", self.netname, "^4 is the next challenger\n");
345 Spawnqueue_Remove(self);
346 Spawnqueue_Mark(self);
348 self.classname = "player";