]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
remove some trailing newlines from centerprints ([ 2555673 ] centerprint / overlap...
[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 dorespawn)
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
71         // Moving the player reset code here since the player-reset depends
72         // on spawnpoint entities which have to be reset first --blub
73         if(dorespawn)
74         FOR_EACH_CLIENT(self) {
75                 if(self.flags & FL_CLIENT)                              // reset all players
76                 {
77                         if(g_arena)
78                         {
79                                 if(self.spawned)
80                                         PutClientInServer();
81                                 else
82                                         PutObserverInServer();
83                         }
84                         else
85                         {
86                                 /*
87                                 only reset players if a restart countdown is active
88                                 this can either be due to cvar sv_ready_restart_after_countdown having set
89                                 restart_mapalreadyrestarted to 1 after the countdown ended or when
90                                 sv_ready_restart_after_countdown is not used and countdown is still running
91                                 */
92                                 if (restart_mapalreadyrestarted || (time < game_starttime))
93                                 {
94                                         //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players
95                                         if (self.classname == "player") {
96                                                 PlayerScore_Clear(self);
97                                                 if(g_lms)
98                                                         PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
99                                                 self.killcount = 0;
100                                                 //stop the player from moving so that he stands still once he gets respawned
101                                                 self.velocity = '0 0 0';
102                                                 self.avelocity = '0 0 0';
103                                                 self.movement = '0 0 0';
104                                                 PutClientInServer();
105                                         }
106                                 }
107                         }
108                 }
109         }
110
111         if(g_keyhunt)
112                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);
113
114         if(g_arena)
115         if(champion)
116                 UpdateFrags(champion, +1);
117
118         self = oldself;
119 }
120
121 void Spawnqueue_Insert(entity e)
122 {
123         if(e.spawnqueue_in)
124                 return;
125         dprint(strcat("Into queue: ", e.netname, "\n"));
126         e.spawnqueue_in = TRUE;
127         e.spawnqueue_prev = spawnqueue_last;
128         e.spawnqueue_next = world;
129         if(spawnqueue_last)
130                 spawnqueue_last.spawnqueue_next = e;
131         spawnqueue_last = e;
132         if(!spawnqueue_first)
133                 spawnqueue_first = e;
134 }
135
136 void Spawnqueue_Remove(entity e)
137 {
138         if(!e.spawnqueue_in)
139                 return;
140         dprint(strcat("Out of queue: ", e.netname, "\n"));
141         e.spawnqueue_in = FALSE;
142         if(e == spawnqueue_first)
143                 spawnqueue_first = e.spawnqueue_next;
144         if(e == spawnqueue_last)
145                 spawnqueue_last = e.spawnqueue_prev;
146         if(e.spawnqueue_prev)
147                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
148         if(e.spawnqueue_next)
149                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
150         e.spawnqueue_next = world;
151         e.spawnqueue_prev = world;
152 }
153
154 void Spawnqueue_Unmark(entity e)
155 {
156         if(!e.spawned)
157                 return;
158         e.spawned = FALSE;
159         numspawned = numspawned - 1;
160 }
161
162 void Spawnqueue_Mark(entity e)
163 {
164         if(e.spawned)
165                 return;
166         e.spawned = TRUE;
167         numspawned = numspawned + 1;
168 }
169
170 /**
171  * If roundbased arena game mode is active, it centerprints the texts for the
172  * player when player is waiting for the countdown to finish.
173  * Blocks the players movement while countdown is active.
174  * Unblocks the player once the countdown is over.
175  * 
176  * Called in PlayerPostThink()
177  */
178 void Arena_Warmup()
179 {
180         float f;
181         string msg;
182
183         if(!g_arena || !arena_roundbased || (time < game_starttime))
184                 return;
185
186         f = rint(warmup - time);
187
188         msg = NEWLINES;
189         if(time < warmup && self.spawned)
190         {
191                 if(champion)
192                         msg = strcat(msg, "The Champion is ", champion.netname, "^7");
193
194                 if(f)
195                         msg = strcat(msg, "Round will start in ", ftos(f));
196                 else
197                 {
198                         if(self.spawned)
199                                 msg = strcat(msg, "^1Fight!");
200                 }
201
202                 centerprint(self, msg);
203
204                 if(self.spawned)
205                         self.movetype = MOVETYPE_NONE;
206
207                 self.velocity = '0 0 0';
208                 self.avelocity = '0 0 0';
209                 self.movement = '0 0 0';
210                 //self.fixangle = TRUE;
211         }
212         else if(self.movetype == MOVETYPE_NONE)
213         {
214                 self.movetype = MOVETYPE_WALK;
215                 centerprint(self, "\n");
216         }
217
218 }
219
220 float next_round;
221
222 /**
223  * This function finds out whether an arena round is over 1 player is left.
224  * It determines the last player who's still alive and saves it's entity reference
225  * in the global variable 'champion'. Then the new enemy/enemies are put into the server.
226  * 
227  * Gets called in StartFrame()
228  */
229 void Spawnqueue_Check()
230 {
231         if(time < warmup + 1)
232                 return;
233
234         //extend next_round if it isn't set yet and only 1 player is spawned
235         if(!next_round)
236         if(numspawned < 2)
237                 next_round = time + 3;
238
239         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
240         {
241                 next_round = 0;
242
243                 if(arena_roundbased)
244                 {
245                         champion = find(world, classname, "player");
246                         while(champion && champion.deadflag)
247                                 champion = find(champion, classname, "player");
248                         reset_map(TRUE);
249                 }
250
251                 while(numspawned < maxspawned && spawnqueue_first)
252                 {
253                         self = spawnqueue_first;
254
255                         bprint ("^4", self.netname, "^4 is the next challenger\n");
256
257                         Spawnqueue_Remove(self);
258                         Spawnqueue_Mark(self);
259
260                         self.classname = "player";
261                         PutClientInServer();
262                 }
263         }
264 }