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