]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
add much more stuff. REALLY need to initialize the scoring for the other game modes...
[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         self = nextent(world);
36         while(self)
37         {
38                 if(self.classname == STR_ITEM_KH_KEY)
39                 {
40                         kh_Key_AssignTo(self, world);
41                         //if(self.owner)
42                         //      kh_Key_DropAll(self.owner, TRUE);
43                         kh_Key_Remove(self);
44                 }
45                 else if(self.classname == "droppedweapon"               // cleanup
46                                 || self.classname == "gib"
47                                 || self.classname == "body")
48                 {
49                         remove(self);
50                 }
51                 else if(self.items & (IT_KEY1 | IT_KEY2))
52                 {
53                         DropFlag(self);
54                         ReturnFlag(self);
55                 }
56                 else if(self.classname == "rune")
57                 {
58                         if(self.owner)
59                         if(self.owner.classname != "runematch_spawn_point")
60                                 DropAllRunes(self.owner);
61                         rune_respawn();
62                 }
63                 else if(self.classname == "sprite_waypoint")
64                 {
65                         if(self.health | g_keyhunt)
66                                 WaypointSprite_Kill(self);
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                         self.model = self.mdl;
75                         self.solid = SOLID_TRIGGER;
76                         setorigin (self, self.origin);
77                         self.think = SUB_Null;
78                         self.nextthink = 0;
79                 }
80                 else if(self.flags & FL_PROJECTILE)             // remove any projectiles left
81                 {
82                         sound(self, CHAN_BODY, "misc/null.wav", 1, ATTN_NORM);
83                         remove(self);
84                 }
85                 else if(self.isdecor)
86                 {
87                         removedecor(self);
88                 }
89                 // TODO properly reset Onslaught
90                 else if(self.classname == "onslaught_generator")
91                 {
92                         onslaught_generator_reset();
93                 }
94                 else if(self.classname == "onslaught_controlpoint")
95                 {
96                         onslaught_controlpoint_reset();
97                 }
98                 // TODO properly reset Assault
99                 // General teambased game modes
100                 else if(self.classname == "info_player_deathmatch")
101                 {
102                         self.team = self.team_saved;
103                 }
104                 self = nextent(self);
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                                                 // FIXME decide what LMS does in the new scoring system!
133                                                 self.frags = (g_lms)?LMS_NewPlayerLives():0;
134                                                 self.deaths = 0;
135                                                 self.killcount = 0;
136                                                 //stop the player from moving so that he stands still once he gets respawned
137                                                 self.velocity = '0 0 0';
138                                                 self.avelocity = '0 0 0';
139                                                 self.movement = '0 0 0';
140                                                 PutClientInServer();
141                                         }
142                                 }
143                         }
144                 }
145         }
146
147         if(g_keyhunt)
148                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+RESTART_COUNTDOWN, "", kh_StartRound);
149
150         if(g_arena)
151         if(champion)
152                 UpdateFrags(champion, +1);
153 }
154
155 void Spawnqueue_Insert(entity e)
156 {
157         if(e.spawnqueue_in)
158                 return;
159         dprint(strcat("Into queue: ", e.netname, "\n"));
160         e.spawnqueue_in = TRUE;
161         e.spawnqueue_prev = spawnqueue_last;
162         e.spawnqueue_next = world;
163         if(spawnqueue_last)
164                 spawnqueue_last.spawnqueue_next = e;
165         spawnqueue_last = e;
166         if(!spawnqueue_first)
167                 spawnqueue_first = e;
168 }
169
170 void Spawnqueue_Remove(entity e)
171 {
172         if(!e.spawnqueue_in)
173                 return;
174         dprint(strcat("Out of queue: ", e.netname, "\n"));
175         e.spawnqueue_in = FALSE;
176         if(e == spawnqueue_first)
177                 spawnqueue_first = e.spawnqueue_next;
178         if(e == spawnqueue_last)
179                 spawnqueue_last = e.spawnqueue_prev;
180         if(e.spawnqueue_prev)
181                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
182         if(e.spawnqueue_next)
183                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
184         e.spawnqueue_next = world;
185         e.spawnqueue_prev = world;
186 }
187
188 void Spawnqueue_Unmark(entity e)
189 {
190         if(!e.spawned)
191                 return;
192         e.spawned = FALSE;
193         numspawned = numspawned - 1;
194 }
195
196 void Spawnqueue_Mark(entity e)
197 {
198         if(e.spawned)
199                 return;
200         e.spawned = TRUE;
201         numspawned = numspawned + 1;
202 }
203
204 /**
205  * If roundbased arena game mode is active, it centerprints the texts for the
206  * player when player is waiting for the countdown to finish.
207  * Blocks the players movement while countdown is active.
208  * Unblocks the player once the countdown is over.
209  * 
210  * Called in PlayerPostThink()
211  */
212 void Arena_Warmup()
213 {
214         float f;
215         string msg;
216
217         if(!g_arena || !arena_roundbased || (time < restart_countdown))
218                 return;
219
220         f = rint(warmup - time);
221
222         msg = NEWLINES;
223         if(time < warmup && self.spawned)
224         {
225                 if(champion)
226                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
227
228                 if(f)
229                         msg = strcat(msg, "Round will start in ", ftos(f));
230                 else
231                 {
232                         if(self.spawned)
233                                 msg = strcat(msg, "^1Fight!");
234                 }
235
236                 centerprint(self, msg);
237
238                 if(self.spawned)
239                         self.movetype = MOVETYPE_NONE;
240
241                 self.velocity = '0 0 0';
242                 self.avelocity = '0 0 0';
243                 self.movement = '0 0 0';
244                 //self.fixangle = TRUE;
245         }
246         else if(self.movetype == MOVETYPE_NONE)
247         {
248                 self.movetype = MOVETYPE_WALK;
249                 centerprint(self, "\n");
250         }
251
252 }
253
254 float next_round;
255
256 /**
257  * This function finds out whether an arena round is over 1 player is left.
258  * It determines the last player who's still alive and saves it's entity reference
259  * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
260  * 
261  * Gets called in StartFrame()
262  */
263 void Spawnqueue_Check()
264 {
265         if(time < warmup + 1)
266                 return;
267
268         //extend next_round if it isn't set yet and only 1 player is spawned
269         if(!next_round)
270         if(numspawned < 2)
271                 next_round = time + 3;
272
273         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
274         {
275                 next_round = 0;
276
277                 if(arena_roundbased)
278                 {
279                         champion = find(world, classname, "player");
280                         while(champion && champion.deadflag)
281                                 champion = find(champion, classname, "player");
282                         reset_map();
283                 }
284
285                 while(numspawned < maxspawned && spawnqueue_first)
286                 {
287                         self = spawnqueue_first;
288
289                         bprint ("^4", self.netname, "^4 is the next challenger\n");
290
291                         Spawnqueue_Remove(self);
292                         Spawnqueue_Mark(self);
293
294                         self.classname = "player";
295                         PutClientInServer();
296                 }
297         }
298 }