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)
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
161 FOR_EACH_CLIENT(self) {
162 if(self.flags & FL_CLIENT) // reset all players
169 PutObserverInServer();
174 only reset players if a restart countdown is active
175 this can either be due to cvar sv_ready_restart_after_countdown having set
176 restart_mapalreadyrestarted to 1 after the countdown ended or when
177 sv_ready_restart_after_countdown is not used and countdown is still running
179 if (restart_mapalreadyrestarted || (time < game_starttime))
181 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
182 if (self.classname == "player") {
183 PlayerScore_Clear(self);
185 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
187 //stop the player from moving so that he stands still once he gets respawned
188 self.velocity = '0 0 0';
189 self.avelocity = '0 0 0';
190 self.movement = '0 0 0';
199 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
203 UpdateFrags(champion, +1);
208 void Spawnqueue_Insert(entity e)
212 dprint(strcat("Into queue: ", e.netname, "\n"));
213 e.spawnqueue_in = TRUE;
214 e.spawnqueue_prev = spawnqueue_last;
215 e.spawnqueue_next = world;
217 spawnqueue_last.spawnqueue_next = e;
219 if(!spawnqueue_first)
220 spawnqueue_first = e;
223 void Spawnqueue_Remove(entity e)
227 dprint(strcat("Out of queue: ", e.netname, "\n"));
228 e.spawnqueue_in = FALSE;
229 if(e == spawnqueue_first)
230 spawnqueue_first = e.spawnqueue_next;
231 if(e == spawnqueue_last)
232 spawnqueue_last = e.spawnqueue_prev;
233 if(e.spawnqueue_prev)
234 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
235 if(e.spawnqueue_next)
236 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
237 e.spawnqueue_next = world;
238 e.spawnqueue_prev = world;
241 void Spawnqueue_Unmark(entity e)
246 numspawned = numspawned - 1;
249 void Spawnqueue_Mark(entity e)
254 numspawned = numspawned + 1;
258 * If roundbased arena game mode is active, it centerprints the texts for the
259 * player when player is waiting for the countdown to finish.
260 * Blocks the players movement while countdown is active.
261 * Unblocks the player once the countdown is over.
263 * Called in PlayerPostThink()
270 if(!g_arena || !arena_roundbased || (time < game_starttime))
273 f = rint(warmup - time);
276 if(time < warmup && self.spawned)
279 msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
282 msg = strcat(msg, "Round will start in ", ftos(f));
286 msg = strcat(msg, "^1Fight!");
289 centerprint(self, msg);
292 self.movetype = MOVETYPE_NONE;
294 self.velocity = '0 0 0';
295 self.avelocity = '0 0 0';
296 self.movement = '0 0 0';
297 //self.fixangle = TRUE;
299 else if(self.movetype == MOVETYPE_NONE)
301 self.movetype = MOVETYPE_WALK;
302 centerprint(self, "\n");
310 * This function finds out whether an arena round is over 1 player is left.
311 * It determines the last player who's still alive and saves it's entity reference
312 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
314 * Gets called in StartFrame()
316 void Spawnqueue_Check()
318 if(time < warmup + 1)
321 //extend next_round if it isn't set yet and only 1 player is spawned
324 next_round = time + 3;
326 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
332 champion = find(world, classname, "player");
333 while(champion && champion.deadflag)
334 champion = find(champion, classname, "player");
338 while(numspawned < maxspawned && spawnqueue_first)
340 self = spawnqueue_first;
342 bprint ("^4", self.netname, "^4 is the next challenger\n");
344 Spawnqueue_Remove(self);
345 Spawnqueue_Mark(self);
347 self.classname = "player";