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 dom_controlpoint_setup();
17 void onslaught_generator_reset();
18 void onslaught_controlpoint_reset();
19 void func_breakable_reset();
20 void assault_objective_reset();
21 void target_assault_roundend_reset();
24 * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
25 * Sets the 'warmup' global variable.
27 void reset_map(float norespawn)
33 if(cvar("g_arena_warmup"))
34 warmup = time + cvar("g_arena_warmup");
36 lms_lowest_lives = 999;
37 lms_next_place = player_count;
41 for(self = world; (self = nextent(self)); )
42 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
51 self.team = self.team_saved;
53 if(self.classname == STR_ITEM_KH_KEY)
55 kh_Key_AssignTo(self, world);
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.classname == "onslaught_generator")
103 onslaught_generator_reset();
105 else if(self.classname == "onslaught_controlpoint")
107 onslaught_controlpoint_reset();
109 // TODO properly reset Assault
110 // General teambased game modes
111 else if(self.classname == "func_breakable")
113 func_breakable_reset();
115 else if(self.classname == "func_assault_destructible")
117 func_breakable_reset();
119 else if(self.classname == "target_objective")
121 assault_objective_reset();
123 else if(self.classname == "target_assault_roundend")
125 target_assault_roundend_reset();
129 // Waypoints and assault start come LAST
130 for(self = world; (self = nextent(self)); )
131 if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
133 if(self.classname == "sprite_waypoint")
135 if(self.health | g_keyhunt)
136 WaypointSprite_Kill(self);
138 else if(self.classname == "target_assault_roundstart")
142 else if(self.classname == "trigger_gamestart")
146 self.think = self.use;
147 self.nextthink = game_starttime + self.wait;
154 // Moving the player reset code here since the player-reset depends
155 // on spawnpoint entities which have to be reset first --blub
157 FOR_EACH_CLIENT(self) {
158 if(self.flags & FL_CLIENT) // reset all players
165 PutObserverInServer();
170 only reset players if a restart countdown is active
171 this can either be due to cvar sv_ready_restart_after_countdown having set
172 restart_mapalreadyrestarted to 1 after the countdown ended or when
173 sv_ready_restart_after_countdown is not used and countdown is still running
175 if (restart_mapalreadyrestarted || (time < game_starttime))
177 //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
178 if (self.classname == "player") {
179 PlayerScore_Clear(self);
181 PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
183 //stop the player from moving so that he stands still once he gets respawned
184 self.velocity = '0 0 0';
185 self.avelocity = '0 0 0';
186 self.movement = '0 0 0';
195 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
199 UpdateFrags(champion, +1);
204 void Spawnqueue_Insert(entity e)
208 dprint(strcat("Into queue: ", e.netname, "\n"));
209 e.spawnqueue_in = TRUE;
210 e.spawnqueue_prev = spawnqueue_last;
211 e.spawnqueue_next = world;
213 spawnqueue_last.spawnqueue_next = e;
215 if(!spawnqueue_first)
216 spawnqueue_first = e;
219 void Spawnqueue_Remove(entity e)
223 dprint(strcat("Out of queue: ", e.netname, "\n"));
224 e.spawnqueue_in = FALSE;
225 if(e == spawnqueue_first)
226 spawnqueue_first = e.spawnqueue_next;
227 if(e == spawnqueue_last)
228 spawnqueue_last = e.spawnqueue_prev;
229 if(e.spawnqueue_prev)
230 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
231 if(e.spawnqueue_next)
232 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
233 e.spawnqueue_next = world;
234 e.spawnqueue_prev = world;
237 void Spawnqueue_Unmark(entity e)
242 numspawned = numspawned - 1;
245 void Spawnqueue_Mark(entity e)
250 numspawned = numspawned + 1;
254 * If roundbased arena game mode is active, it centerprints the texts for the
255 * player when player is waiting for the countdown to finish.
256 * Blocks the players movement while countdown is active.
257 * Unblocks the player once the countdown is over.
259 * Called in PlayerPostThink()
266 if(!g_arena || !arena_roundbased || (time < game_starttime))
269 f = rint(warmup - time);
272 if(time < warmup && self.spawned)
275 msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
278 msg = strcat(msg, "Round will start in ", ftos(f));
282 msg = strcat(msg, "^1Fight!");
285 centerprint(self, msg);
288 self.movetype = MOVETYPE_NONE;
290 self.velocity = '0 0 0';
291 self.avelocity = '0 0 0';
292 self.movement = '0 0 0';
293 //self.fixangle = TRUE;
295 else if(self.movetype == MOVETYPE_NONE)
297 self.movetype = MOVETYPE_WALK;
298 centerprint(self, "\n");
306 * This function finds out whether an arena round is over 1 player is left.
307 * It determines the last player who's still alive and saves it's entity reference
308 * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
310 * Gets called in StartFrame()
312 void Spawnqueue_Check()
314 if(time < warmup + 1)
317 //extend next_round if it isn't set yet and only 1 player is spawned
320 next_round = time + 3;
322 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
328 champion = find(world, classname, "player");
329 while(champion && champion.deadflag)
330 champion = find(champion, classname, "player");
334 while(numspawned < maxspawned && spawnqueue_first)
336 self = spawnqueue_first;
338 bprint ("^4", self.netname, "^4 is the next challenger\n");
340 Spawnqueue_Remove(self);
341 Spawnqueue_Mark(self);
343 self.classname = "player";