]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
__FORCE_READY_RESTART: do not respawn players during that (so you can see if it reset...
[divverent/nexuiz.git] / data / qcsrc / server / arena.qc
1 float maxspawned;
2 float numspawned;
3 float arena_roundbased;
4 .float spawned;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
7 .float spawnqueue_in;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
10 entity champion;
11 float warmup;
12
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();
23
24 /**
25  * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.
26  * Sets the 'warmup' global variable.
27  */
28 void reset_map(float norespawn)
29 {
30         entity oldself;
31         oldself = self;
32
33         if(g_arena)
34         if(cvar("g_arena_warmup"))
35                 warmup = time + cvar("g_arena_warmup");
36
37         lms_lowest_lives = 999;
38         lms_next_place = player_count;
39
40         race_ReadyRestart();
41         
42         for(self = world; (self = nextent(self)); )
43         if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
44         {
45                 if(self.reset)
46                 {
47                         self.reset();
48                         continue;
49                 }
50
51                 if(self.team_saved)
52                         self.team = self.team_saved;
53
54                 if(self.classname == STR_ITEM_KH_KEY)
55                 {
56                         kh_Key_AssignTo(self, world);
57                         kh_Key_Remove(self);
58                 }
59                 else if(self.classname == "droppedweapon"               // cleanup
60                                 || self.classname == "gib"
61                                 || self.classname == "body")
62                 {
63                         remove(self);
64                 }
65                 else if(self.items & (IT_KEY1 | IT_KEY2))
66                 {
67                         DropFlag(self, world, world);
68                         ReturnFlag(self);
69                 }
70                 else if(self.classname == "rune")
71                 {
72                         if(self.owner)
73                         if(self.owner.classname != "runematch_spawn_point")
74                                 DropAllRunes(self.owner);
75                         rune_respawn();
76                 }
77                 else if(self.classname == "dom_controlpoint")
78                 {
79                         dom_controlpoint_setup();
80                 }
81                 else if(self.flags & FL_ITEM)                   // reset items
82                 {
83                         if(self.state == 1)
84                         {
85                                 self.model = string_null;
86                                 self.solid = SOLID_NOT;
87                         }
88                         else
89                         {
90                                 self.model = self.mdl;
91                                 self.solid = SOLID_TRIGGER;
92                         }
93                         setorigin (self, self.origin);
94                         self.think = SUB_Null;
95                         self.nextthink = 0;
96                 }
97                 else if(self.flags & FL_PROJECTILE)             // remove any projectiles left
98                 {
99                         stopsound(self, CHAN_PROJECTILE);
100                         remove(self);
101                 }
102                 else if(self.isdecor)
103                 {
104                         removedecor(self);
105                 }
106                 else if(self.classname == "onslaught_generator")
107                 {
108                         onslaught_generator_reset();
109                 }
110                 else if(self.classname == "onslaught_controlpoint")
111                 {
112                         onslaught_controlpoint_reset();
113                 }
114                 // TODO properly reset Assault
115                 // General teambased game modes
116                 else if(self.classname == "func_breakable")
117                 {
118                         func_breakable_reset();
119                 }
120                 else if(self.classname == "func_assault_destructible")
121                 {
122                         func_breakable_reset();
123                 }
124                 else if(self.classname == "target_objective")
125                 {
126                         assault_objective_reset();
127                 }
128                 else if(self.classname == "target_assault_roundend")
129                 {
130                         target_assault_roundend_reset();
131                 }
132         }
133
134         // Waypoints and assault start come LAST
135         for(self = world; (self = nextent(self)); )
136         if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
137         {
138                 if(self.classname == "sprite_waypoint")
139                 {
140                         if(self.health | g_keyhunt)
141                                 WaypointSprite_Kill(self);
142                 }
143                 else if(self.classname == "target_assault_roundstart")
144                 {
145                         self.use();
146                 }
147                 else if(self.classname == "trigger_gamestart")
148                 {
149                         if(self.wait)
150                         {
151                                 self.think = self.use;
152                                 self.nextthink = game_starttime + self.wait;
153                         }
154                         else
155                                 self.use();
156                 }
157         }
158
159         // Moving the player reset code here since the player-reset depends
160         // on spawnpoint entities which have to be reset first --blub
161         if(!norespawn)
162         FOR_EACH_CLIENT(self) {
163                 if(self.flags & FL_CLIENT)                              // reset all players
164                 {
165                         if(g_arena)
166                         {
167                                 if(self.spawned)
168                                         PutClientInServer();
169                                 else
170                                         PutObserverInServer();
171                         }
172                         else
173                         {
174                                 /*
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
179                                 */
180                                 if (restart_mapalreadyrestarted || (time < game_starttime))
181                                 {
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);
185                                                 if(g_lms)
186                                                         PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
187                                                 self.killcount = 0;
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';
192                                                 PutClientInServer();
193                                         }
194                                 }
195                         }
196                 }
197         }
198
199         if(g_keyhunt)
200                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
201
202         if(g_arena)
203         if(champion)
204                 UpdateFrags(champion, +1);
205
206         self = oldself;
207 }
208
209 void Spawnqueue_Insert(entity e)
210 {
211         if(e.spawnqueue_in)
212                 return;
213         dprint(strcat("Into queue: ", e.netname, "\n"));
214         e.spawnqueue_in = TRUE;
215         e.spawnqueue_prev = spawnqueue_last;
216         e.spawnqueue_next = world;
217         if(spawnqueue_last)
218                 spawnqueue_last.spawnqueue_next = e;
219         spawnqueue_last = e;
220         if(!spawnqueue_first)
221                 spawnqueue_first = e;
222 }
223
224 void Spawnqueue_Remove(entity e)
225 {
226         if(!e.spawnqueue_in)
227                 return;
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;
240 }
241
242 void Spawnqueue_Unmark(entity e)
243 {
244         if(!e.spawned)
245                 return;
246         e.spawned = FALSE;
247         numspawned = numspawned - 1;
248 }
249
250 void Spawnqueue_Mark(entity e)
251 {
252         if(e.spawned)
253                 return;
254         e.spawned = TRUE;
255         numspawned = numspawned + 1;
256 }
257
258 /**
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.
263  * 
264  * Called in PlayerPostThink()
265  */
266 void Arena_Warmup()
267 {
268         float f;
269         string msg;
270
271         if(!g_arena || !arena_roundbased || (time < game_starttime))
272                 return;
273
274         f = rint(warmup - time);
275
276         msg = NEWLINES;
277         if(time < warmup && self.spawned)
278         {
279                 if(champion)
280                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
281
282                 if(f)
283                         msg = strcat(msg, "Round will start in ", ftos(f));
284                 else
285                 {
286                         if(self.spawned)
287                                 msg = strcat(msg, "^1Fight!");
288                 }
289
290                 centerprint(self, msg);
291
292                 if(self.spawned)
293                         self.movetype = MOVETYPE_NONE;
294
295                 self.velocity = '0 0 0';
296                 self.avelocity = '0 0 0';
297                 self.movement = '0 0 0';
298                 //self.fixangle = TRUE;
299         }
300         else if(self.movetype == MOVETYPE_NONE)
301         {
302                 self.movetype = MOVETYPE_WALK;
303                 centerprint(self, "\n");
304         }
305
306 }
307
308 float next_round;
309
310 /**
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.
314  * 
315  * Gets called in StartFrame()
316  */
317 void Spawnqueue_Check()
318 {
319         if(time < warmup + 1)
320                 return;
321
322         //extend next_round if it isn't set yet and only 1 player is spawned
323         if(!next_round)
324         if(numspawned < 2)
325                 next_round = time + 3;
326
327         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
328         {
329                 next_round = 0;
330
331                 if(arena_roundbased)
332                 {
333                         champion = find(world, classname, "player");
334                         while(champion && champion.deadflag)
335                                 champion = find(champion, classname, "player");
336                         reset_map(TRUE);
337                 }
338
339                 while(numspawned < maxspawned && spawnqueue_first)
340                 {
341                         self = spawnqueue_first;
342
343                         bprint ("^4", self.netname, "^4 is the next challenger\n");
344
345                         Spawnqueue_Remove(self);
346                         Spawnqueue_Mark(self);
347
348                         self.classname = "player";
349                         PutClientInServer();
350                 }
351         }
352 }