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