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