]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
forgot this one
[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.state == 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                         stopsound(self, CHAN_PROJECTILE);
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         }
130
131         // Waypoints and assault start come LAST
132         for(self = world; (self = nextent(self)); )
133         if(clienttype(self) == CLIENTTYPE_NOTACLIENT)
134         {
135                 if(self.classname == "sprite_waypoint")
136                 {
137                         if(self.health | g_keyhunt)
138                                 WaypointSprite_Kill(self);
139                 }
140                 else if(self.classname == "target_assault_roundstart")
141                 {
142                         self.use();
143                 }
144         }
145
146         // Moving the player reset code here since the player-reset depends
147         // on spawnpoint entities which have to be reset first --blub
148         FOR_EACH_CLIENT(self) {
149                 if(self.flags & FL_CLIENT)                              // reset all players
150                 {
151                         if(g_arena)
152                         {
153                                 if(self.spawned)
154                                         PutClientInServer();
155                                 else
156                                         PutObserverInServer();
157                         }
158                         else
159                         {
160                                 /*
161                                 only reset players if a restart countdown is active
162                                 this can either be due to cvar sv_ready_restart_after_countdown having set
163                                 restart_mapalreadyrestarted to 1 after the countdown ended or when
164                                 sv_ready_restart_after_countdown is not used and countdown is still running
165                                 */
166                                 if (restart_mapalreadyrestarted || (time < game_starttime))
167                                 {
168                                         //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
169                                         if (self.classname == "player") {
170                                                 PlayerScore_Clear(self);
171                                                 if(g_lms)
172                                                         PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
173                                                 self.killcount = 0;
174                                                 //stop the player from moving so that he stands still once he gets respawned
175                                                 self.velocity = '0 0 0';
176                                                 self.avelocity = '0 0 0';
177                                                 self.movement = '0 0 0';
178                                                 PutClientInServer();
179                                         }
180                                 }
181                         }
182                 }
183         }
184
185         if(g_keyhunt)
186                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
187
188         if(g_arena)
189         if(champion)
190                 UpdateFrags(champion, +1);
191
192         self = oldself;
193 }
194
195 void Spawnqueue_Insert(entity e)
196 {
197         if(e.spawnqueue_in)
198                 return;
199         dprint(strcat("Into queue: ", e.netname, "\n"));
200         e.spawnqueue_in = TRUE;
201         e.spawnqueue_prev = spawnqueue_last;
202         e.spawnqueue_next = world;
203         if(spawnqueue_last)
204                 spawnqueue_last.spawnqueue_next = e;
205         spawnqueue_last = e;
206         if(!spawnqueue_first)
207                 spawnqueue_first = e;
208 }
209
210 void Spawnqueue_Remove(entity e)
211 {
212         if(!e.spawnqueue_in)
213                 return;
214         dprint(strcat("Out of queue: ", e.netname, "\n"));
215         e.spawnqueue_in = FALSE;
216         if(e == spawnqueue_first)
217                 spawnqueue_first = e.spawnqueue_next;
218         if(e == spawnqueue_last)
219                 spawnqueue_last = e.spawnqueue_prev;
220         if(e.spawnqueue_prev)
221                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
222         if(e.spawnqueue_next)
223                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
224         e.spawnqueue_next = world;
225         e.spawnqueue_prev = world;
226 }
227
228 void Spawnqueue_Unmark(entity e)
229 {
230         if(!e.spawned)
231                 return;
232         e.spawned = FALSE;
233         numspawned = numspawned - 1;
234 }
235
236 void Spawnqueue_Mark(entity e)
237 {
238         if(e.spawned)
239                 return;
240         e.spawned = TRUE;
241         numspawned = numspawned + 1;
242 }
243
244 /**
245  * If roundbased arena game mode is active, it centerprints the texts for the
246  * player when player is waiting for the countdown to finish.
247  * Blocks the players movement while countdown is active.
248  * Unblocks the player once the countdown is over.
249  * 
250  * Called in PlayerPostThink()
251  */
252 void Arena_Warmup()
253 {
254         float f;
255         string msg;
256
257         if(!g_arena || !arena_roundbased || (time < game_starttime))
258                 return;
259
260         f = rint(warmup - time);
261
262         msg = NEWLINES;
263         if(time < warmup && self.spawned)
264         {
265                 if(champion)
266                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
267
268                 if(f)
269                         msg = strcat(msg, "Round will start in ", ftos(f));
270                 else
271                 {
272                         if(self.spawned)
273                                 msg = strcat(msg, "^1Fight!");
274                 }
275
276                 centerprint(self, msg);
277
278                 if(self.spawned)
279                         self.movetype = MOVETYPE_NONE;
280
281                 self.velocity = '0 0 0';
282                 self.avelocity = '0 0 0';
283                 self.movement = '0 0 0';
284                 //self.fixangle = TRUE;
285         }
286         else if(self.movetype == MOVETYPE_NONE)
287         {
288                 self.movetype = MOVETYPE_WALK;
289                 centerprint(self, "\n");
290         }
291
292 }
293
294 float next_round;
295
296 /**
297  * This function finds out whether an arena round is over 1 player is left.
298  * It determines the last player who's still alive and saves it's entity reference
299  * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
300  * 
301  * Gets called in StartFrame()
302  */
303 void Spawnqueue_Check()
304 {
305         if(time < warmup + 1)
306                 return;
307
308         //extend next_round if it isn't set yet and only 1 player is spawned
309         if(!next_round)
310         if(numspawned < 2)
311                 next_round = time + 3;
312
313         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
314         {
315                 next_round = 0;
316
317                 if(arena_roundbased)
318                 {
319                         champion = find(world, classname, "player");
320                         while(champion && champion.deadflag)
321                                 champion = find(champion, classname, "player");
322                         reset_map();
323                 }
324
325                 while(numspawned < maxspawned && spawnqueue_first)
326                 {
327                         self = spawnqueue_first;
328
329                         bprint ("^4", self.netname, "^4 is the next challenger\n");
330
331                         Spawnqueue_Remove(self);
332                         Spawnqueue_Mark(self);
333
334                         self.classname = "player";
335                         PutClientInServer();
336                 }
337         }
338 }