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