]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
assault: fix lots of bugs, initial waypointsprites support
[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()
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.classname == STR_ITEM_KH_KEY)
46                 {
47                         kh_Key_AssignTo(self, world);
48                         //if(self.owner)
49                         //      kh_Key_DropAll(self.owner, TRUE);
50                         kh_Key_Remove(self);
51                 }
52                 else if(self.classname == "droppedweapon"               // cleanup
53                                 || self.classname == "gib"
54                                 || self.classname == "body")
55                 {
56                         remove(self);
57                 }
58                 else if(self.items & (IT_KEY1 | IT_KEY2))
59                 {
60                         DropFlag(self, world, world);
61                         ReturnFlag(self);
62                 }
63                 else if(self.classname == "rune")
64                 {
65                         if(self.owner)
66                         if(self.owner.classname != "runematch_spawn_point")
67                                 DropAllRunes(self.owner);
68                         rune_respawn();
69                 }
70                 else if(self.classname == "dom_controlpoint")
71                 {
72                         dom_controlpoint_setup();
73                 }
74                 else if(self.flags & FL_ITEM)                   // reset items
75                 {
76                         if(self.cnt == 1)
77                         {
78                                 self.model = string_null;
79                                 self.solid = SOLID_NOT;
80                         }
81                         else
82                         {
83                                 self.model = self.mdl;
84                                 self.solid = SOLID_TRIGGER;
85                         }
86                         setorigin (self, self.origin);
87                         self.think = SUB_Null;
88                         self.nextthink = 0;
89                 }
90                 else if(self.flags & FL_PROJECTILE)             // remove any projectiles left
91                 {
92                         sound(self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
93                         remove(self);
94                 }
95                 else if(self.isdecor)
96                 {
97                         removedecor(self);
98                 }
99                 else if(self.classname == "onslaught_generator")
100                 {
101                         onslaught_generator_reset();
102                 }
103                 else if(self.classname == "onslaught_controlpoint")
104                 {
105                         onslaught_controlpoint_reset();
106                 }
107                 // TODO properly reset Assault
108                 // General teambased game modes
109                 else if(self.classname == "info_player_deathmatch")
110                 {
111                         self.team = self.team_saved;
112                 }
113                 else if(self.classname == "func_breakable")
114                 {
115                         func_breakable_reset();
116                 }
117                 else if(self.classname == "func_assault_destructible")
118                 {
119                         func_breakable_reset();
120                 }
121                 else if(self.classname == "target_objective")
122                 {
123                         assault_objective_reset();
124                 }
125                 else if(self.classname == "target_assault_roundend")
126                 {
127                         target_assault_roundend_reset();
128                 }
129                 else if(self.classname == "target_assault_roundstart")
130                 {
131                         self.use();
132                 }
133         }
134
135         // Waypoints come LAST (keyhunt keys reference them)
136         for(self = world; (self = nextent(self)); )
137                 if(self.classname == "sprite_waypoint")
138                 {
139                         if(self.health | g_keyhunt)
140                                 WaypointSprite_Kill(self);
141                 }
142
143         // Moving the player reset code here since the player-reset depends
144         // on spawnpoint entities which have to be reset first --blub
145         FOR_EACH_CLIENT(self) {
146                 if(self.flags & FL_CLIENT)                              // reset all players
147                 {
148                         if(g_arena)
149                         {
150                                 if(self.spawned)
151                                         PutClientInServer();
152                                 else
153                                         PutObserverInServer();
154                         }
155                         else
156                         {
157                                 /*
158                                 only reset players if a restart countdown is active
159                                 this can either be due to cvar sv_ready_restart_after_countdown having set
160                                 restart_mapalreadyrestarted to 1 after the countdown ended or when
161                                 sv_ready_restart_after_countdown is not used and countdown is still running
162                                 */
163                                 if (restart_mapalreadyrestarted || (time < game_starttime))
164                                 {
165                                         //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
166                                         if (self.classname == "player") {
167                                                 PlayerScore_Clear(self);
168                                                 if(g_lms)
169                                                         PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
170                                                 self.killcount = 0;
171                                                 //stop the player from moving so that he stands still once he gets respawned
172                                                 self.velocity = '0 0 0';
173                                                 self.avelocity = '0 0 0';
174                                                 self.movement = '0 0 0';
175                                                 PutClientInServer();
176                                         }
177                                 }
178                         }
179                 }
180         }
181
182         if(g_keyhunt)
183                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
184
185         if(g_arena)
186         if(champion)
187                 UpdateFrags(champion, +1);
188
189         self = oldself;
190 }
191
192 void Spawnqueue_Insert(entity e)
193 {
194         if(e.spawnqueue_in)
195                 return;
196         dprint(strcat("Into queue: ", e.netname, "\n"));
197         e.spawnqueue_in = TRUE;
198         e.spawnqueue_prev = spawnqueue_last;
199         e.spawnqueue_next = world;
200         if(spawnqueue_last)
201                 spawnqueue_last.spawnqueue_next = e;
202         spawnqueue_last = e;
203         if(!spawnqueue_first)
204                 spawnqueue_first = e;
205 }
206
207 void Spawnqueue_Remove(entity e)
208 {
209         if(!e.spawnqueue_in)
210                 return;
211         dprint(strcat("Out of queue: ", e.netname, "\n"));
212         e.spawnqueue_in = FALSE;
213         if(e == spawnqueue_first)
214                 spawnqueue_first = e.spawnqueue_next;
215         if(e == spawnqueue_last)
216                 spawnqueue_last = e.spawnqueue_prev;
217         if(e.spawnqueue_prev)
218                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
219         if(e.spawnqueue_next)
220                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
221         e.spawnqueue_next = world;
222         e.spawnqueue_prev = world;
223 }
224
225 void Spawnqueue_Unmark(entity e)
226 {
227         if(!e.spawned)
228                 return;
229         e.spawned = FALSE;
230         numspawned = numspawned - 1;
231 }
232
233 void Spawnqueue_Mark(entity e)
234 {
235         if(e.spawned)
236                 return;
237         e.spawned = TRUE;
238         numspawned = numspawned + 1;
239 }
240
241 /**
242  * If roundbased arena game mode is active, it centerprints the texts for the
243  * player when player is waiting for the countdown to finish.
244  * Blocks the players movement while countdown is active.
245  * Unblocks the player once the countdown is over.
246  * 
247  * Called in PlayerPostThink()
248  */
249 void Arena_Warmup()
250 {
251         float f;
252         string msg;
253
254         if(!g_arena || !arena_roundbased || (time < game_starttime))
255                 return;
256
257         f = rint(warmup - time);
258
259         msg = NEWLINES;
260         if(time < warmup && self.spawned)
261         {
262                 if(champion)
263                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
264
265                 if(f)
266                         msg = strcat(msg, "Round will start in ", ftos(f));
267                 else
268                 {
269                         if(self.spawned)
270                                 msg = strcat(msg, "^1Fight!");
271                 }
272
273                 centerprint(self, msg);
274
275                 if(self.spawned)
276                         self.movetype = MOVETYPE_NONE;
277
278                 self.velocity = '0 0 0';
279                 self.avelocity = '0 0 0';
280                 self.movement = '0 0 0';
281                 //self.fixangle = TRUE;
282         }
283         else if(self.movetype == MOVETYPE_NONE)
284         {
285                 self.movetype = MOVETYPE_WALK;
286                 centerprint(self, "\n");
287         }
288
289 }
290
291 float next_round;
292
293 /**
294  * This function finds out whether an arena round is over 1 player is left.
295  * It determines the last player who's still alive and saves it's entity reference
296  * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
297  * 
298  * Gets called in StartFrame()
299  */
300 void Spawnqueue_Check()
301 {
302         if(time < warmup + 1)
303                 return;
304
305         //extend next_round if it isn't set yet and only 1 player is spawned
306         if(!next_round)
307         if(numspawned < 2)
308                 next_round = time + 3;
309
310         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
311         {
312                 next_round = 0;
313
314                 if(arena_roundbased)
315                 {
316                         champion = find(world, classname, "player");
317                         while(champion && champion.deadflag)
318                                 champion = find(champion, classname, "player");
319                         reset_map();
320                 }
321
322                 while(numspawned < maxspawned && spawnqueue_first)
323                 {
324                         self = spawnqueue_first;
325
326                         bprint ("^4", self.netname, "^4 is the next challenger\n");
327
328                         Spawnqueue_Remove(self);
329                         Spawnqueue_Mark(self);
330
331                         self.classname = "player";
332                         PutClientInServer();
333                 }
334         }
335 }