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