]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/arena.qc
Better Grabber impact effects
[voretournament/voretournament.git] / data / qcsrc / server / arena.qc
1 float maxspawned;\r
2 float numspawned;\r
3 float arena_roundbased;\r
4 .float spawned;\r
5 .entity spawnqueue_next;\r
6 .entity spawnqueue_prev;\r
7 .float spawnqueue_in;\r
8 entity spawnqueue_first;\r
9 entity spawnqueue_last;\r
10 entity champion;\r
11 float warmup;\r
12 float allowed_to_spawn;\r
13 float player_cnt;\r
14 .float caplayer;\r
15 \r
16 void PutObserverInServer();\r
17 void PutClientInServer();\r
18 void(entity e) ReturnFlag;\r
19 void dom_controlpoint_setup();\r
20 void onslaught_generator_reset();\r
21 void onslaught_controlpoint_reset();\r
22 void func_breakable_reset();\r
23 void assault_objective_reset();\r
24 void target_assault_roundend_reset();\r
25 \r
26 /**\r
27  * Resets the state of all clients, items, flags, runes, keys, weapons, waypoints, ... of the map.\r
28  * Sets the 'warmup' global variable.\r
29  */\r
30 void reset_map(float dorespawn)\r
31 {\r
32         entity oldself;\r
33         oldself = self;\r
34 \r
35         if(g_arena && cvar("g_arena_warmup"))\r
36                 warmup = time + cvar("g_arena_warmup");\r
37         else if(g_ca) {\r
38                 warmup = time + cvar("g_ca_warmup");\r
39                 allowed_to_spawn = 1;\r
40         }\r
41 \r
42         lms_lowest_lives = 999;\r
43         lms_next_place = player_count;\r
44 \r
45         race_ReadyRestart();\r
46         \r
47         for(self = world; (self = nextent(self)); )\r
48         if(clienttype(self) == CLIENTTYPE_NOTACLIENT)\r
49         {\r
50                 if(self.reset)\r
51                 {\r
52                         self.reset();\r
53                         continue;\r
54                 }\r
55 \r
56                 if(self.team_saved)\r
57                         self.team = self.team_saved;\r
58 \r
59                 if(self.flags & FL_PROJECTILE) // remove any projectiles left\r
60                 {\r
61                         stopsound(self, CHAN_PAIN);\r
62                         remove(self);\r
63                 }\r
64         }\r
65 \r
66         // Waypoints and assault start come LAST\r
67         for(self = world; (self = nextent(self)); )\r
68         if(clienttype(self) == CLIENTTYPE_NOTACLIENT)\r
69         {\r
70                 if(self.reset2)\r
71                 {\r
72                         self.reset2();\r
73                         continue;\r
74                 }\r
75         }\r
76 \r
77         // Moving the player reset code here since the player-reset depends\r
78         // on spawnpoint entities which have to be reset first --blub\r
79         if(dorespawn)\r
80         FOR_EACH_CLIENT(self) {\r
81                 if(self.flags & FL_CLIENT)                              // reset all players\r
82                 {\r
83                         if(g_arena)\r
84                         {\r
85                                 if(self.spawned)\r
86                                         PutClientInServer();\r
87                                 else\r
88                                         PutObserverInServer();\r
89                         }\r
90                         else if(g_ca && self.caplayer) {\r
91                                 self.classname = "player";\r
92                                 PutClientInServer();\r
93                         }\r
94                         else\r
95                         {\r
96                                 /*\r
97                                 only reset players if a restart countdown is active\r
98                                 this can either be due to cvar sv_ready_restart_after_countdown having set\r
99                                 restart_mapalreadyrestarted to 1 after the countdown ended or when\r
100                                 sv_ready_restart_after_countdown is not used and countdown is still running\r
101                                 */\r
102                                 if (restart_mapalreadyrestarted || (time < game_starttime))\r
103                                 {\r
104                                         //NEW: changed behaviour so that it prevents that previous spectators/observers suddenly spawn as players\r
105                                         if (self.classname == "player") {\r
106                                                 //PlayerScore_Clear(self);\r
107                                                 if(g_lms)\r
108                                                         PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());\r
109                                                 self.killcount = 0;\r
110                                                 //stop the player from moving so that he stands still once he gets respawned\r
111                                                 self.velocity = '0 0 0';\r
112                                                 self.avelocity = '0 0 0';\r
113                                                 self.movement = '0 0 0';\r
114                                                 PutClientInServer();\r
115                                         }\r
116                                 }\r
117                         }\r
118                 }\r
119         }\r
120 \r
121         if(g_keyhunt)\r
122                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+(game_starttime - time), "", kh_StartRound);\r
123 \r
124         if(g_arena || g_ca)\r
125         if(champion && champion.classname == "player" && player_cnt > 1)\r
126                 UpdateFrags(champion, +1);\r
127 \r
128         self = oldself;\r
129 }\r
130 \r
131 void Spawnqueue_Insert(entity e)\r
132 {\r
133         if(e.spawnqueue_in)\r
134                 return;\r
135         dprint(strcat("Into queue: ", e.netname, "\n"));\r
136         e.spawnqueue_in = TRUE;\r
137         e.spawnqueue_prev = spawnqueue_last;\r
138         e.spawnqueue_next = world;\r
139         if(spawnqueue_last)\r
140                 spawnqueue_last.spawnqueue_next = e;\r
141         spawnqueue_last = e;\r
142         if(!spawnqueue_first)\r
143                 spawnqueue_first = e;\r
144 }\r
145 \r
146 void Spawnqueue_Remove(entity e)\r
147 {\r
148         if(!e.spawnqueue_in)\r
149                 return;\r
150         dprint(strcat("Out of queue: ", e.netname, "\n"));\r
151         e.spawnqueue_in = FALSE;\r
152         if(e == spawnqueue_first)\r
153                 spawnqueue_first = e.spawnqueue_next;\r
154         if(e == spawnqueue_last)\r
155                 spawnqueue_last = e.spawnqueue_prev;\r
156         if(e.spawnqueue_prev)\r
157                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;\r
158         if(e.spawnqueue_next)\r
159                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;\r
160         e.spawnqueue_next = world;\r
161         e.spawnqueue_prev = world;\r
162 }\r
163 \r
164 void Spawnqueue_Unmark(entity e)\r
165 {\r
166         if(!e.spawned)\r
167                 return;\r
168         e.spawned = FALSE;\r
169         numspawned = numspawned - 1;\r
170 }\r
171 \r
172 void Spawnqueue_Mark(entity e)\r
173 {\r
174         if(e.spawned)\r
175                 return;\r
176         e.spawned = TRUE;\r
177         numspawned = numspawned + 1;\r
178 }\r
179 \r
180 /**\r
181  * If roundbased arena game mode is active, it centerprints the texts for the\r
182  * player when player is waiting for the countdown to finish.\r
183  * Blocks the players movement while countdown is active.\r
184  * Unblocks the player once the countdown is over.\r
185  * \r
186  * Called in PlayerPostThink()\r
187  */\r
188 float roundStartTime_prev; // prevent networkspam\r
189 void Arena_Warmup()\r
190 {\r
191         float f;\r
192         string msg;\r
193 \r
194         if((!g_arena && !g_ca) || (g_arena && !arena_roundbased) || (time < game_starttime))\r
195                 return;\r
196 \r
197         f = floor(warmup - time + 1);\r
198 \r
199         allowed_to_spawn = 0;\r
200 \r
201         if(g_ca && (player_cnt < 2 || inWarmupStage))\r
202                 allowed_to_spawn = 1;\r
203 \r
204         msg = NEWLINES;\r
205         if(time < warmup && !inWarmupStage)\r
206         {\r
207                 if (g_ca)\r
208                         allowed_to_spawn = 1;\r
209                 if(champion && g_arena)\r
210                         msg = strcat("The Champion is ", champion.netname, "^7\n");\r
211                         //centerprint(self, strcat(msg, "The Champion is ", champion.netname, "^7\n"));\r
212 \r
213                 if(f != roundStartTime_prev) {\r
214                         msg = strcat(msg, "Round will start in ", ftos(f),"\n");\r
215                         //centerprint(self, strcat("Round will start in ", ftos(f),"\n"));\r
216                         roundStartTime_prev = f;\r
217                         if(f == 5)\r
218                                 Announce("prepareforbattle");\r
219                         else if(f == 3)\r
220                                 Announce("3");\r
221                         else if(f == 2)\r
222                                 Announce("2");\r
223                         else if(f == 1)\r
224                                 Announce("1");\r
225 \r
226                         centerprint(self, msg);\r
227                 }\r
228 \r
229                 if (g_arena)\r
230                 if (self.spawned && self.classname == "player")\r
231                         self.movetype = MOVETYPE_NONE;\r
232         }\r
233 \r
234         else if(f > -1 && f != roundStartTime_prev)\r
235         {\r
236                 roundStartTime_prev = f;\r
237                 Announce("begin");\r
238                 centerprint(self, "^1Begin!\n");\r
239 \r
240                 FOR_EACH_PLAYER(self)\r
241                         self.movetype = MOVETYPE_WALK;\r
242 \r
243                 if(g_ca) {\r
244                         player_cnt = 0;\r
245 \r
246                         FOR_EACH_CLIENT(self) {\r
247                         if (self.classname == "player")\r
248                                 player_cnt += 1;\r
249                         }               \r
250                 }\r
251         }\r
252 }\r
253 \r
254 float next_round;\r
255 /**\r
256  * This function finds out whether an arena round is over 1 player is left.\r
257  * It determines the last player who's still alive and saves it's entity reference\r
258  * in the global variable 'champion'. Then the new enemy/enemies are put into the server.\r
259  * \r
260  * Gets called in StartFrame()\r
261  */\r
262 void Spawnqueue_Check()\r
263 {\r
264         if(time < warmup + 1 || inWarmupStage)\r
265                 return;\r
266 \r
267         if(g_ca) {\r
268                 // check the amount of spawned players in each team\r
269                 float redspawned, bluespawned;\r
270                 FOR_EACH_CLIENT(self) {\r
271                         if (self.classname == "player") {\r
272                                 if (self.team == COLOR_TEAM1) redspawned += 1;\r
273                                 else if (self.team == COLOR_TEAM2) bluespawned += 1;\r
274                         }\r
275                 }\r
276 \r
277                 if(player_cnt < 2 && (redspawned && bluespawned)) {\r
278                         reset_map(TRUE);\r
279                 }\r
280                 else if(player_cnt < 2) {\r
281                         FOR_EACH_CLIENT(self) \r
282                         if(self.classname == "player")\r
283                                 centerprint(self, strcat("^1Need at least 2 players to play CA", "^7\n"));\r
284 \r
285                         allowed_to_spawn = 1;\r
286                         return;\r
287                 }\r
288                 else if(!next_round)\r
289                         if((redspawned && bluespawned == 0) || (bluespawned && redspawned == 0)) {\r
290                                 next_round = time + 5;\r
291 \r
292                                 champion = find(world, classname, "player");\r
293                                 string champion_team;\r
294                                 if(champion.team == COLOR_TEAM1) {\r
295                                         champion_team = "^1Red team";\r
296                                         play2all("ctf/red_capture.wav");\r
297                                 }\r
298                                 else if(champion.team == COLOR_TEAM2) {\r
299                                         champion_team = "^4Blue team";\r
300                                         play2all("ctf/blue_capture.wav");\r
301                                 }\r
302                                 FOR_EACH_CLIENT(self) centerprint(self, strcat(champion_team, "^7 wins the round.", "^7\n"));   \r
303                         else if(!redspawned && !bluespawned) {\r
304                                 FOR_EACH_CLIENT(self) centerprint(self, strcat("^7Round tied.", "^7\n"));\r
305                                 next_round = time + 5;\r
306                         }\r
307                 }\r
308 \r
309                 if((next_round && next_round < time))\r
310                 {\r
311                         next_round = 0;\r
312                         reset_map(TRUE);\r
313                 }\r
314         } else { // arena\r
315                 //extend next_round if it isn't set yet and only 1 player is spawned\r
316                 if(!next_round)\r
317                 if(numspawned < 2)\r
318                         next_round = time + 3;\r
319 \r
320                 if(!arena_roundbased || (next_round && next_round < time && player_count > 1))\r
321                 {\r
322                         next_round = 0;\r
323 \r
324                         if(arena_roundbased)\r
325                         {\r
326                                 champion = find(world, classname, "player");\r
327                                 while(champion && champion.deadflag)\r
328                                         champion = find(champion, classname, "player");\r
329                                 reset_map(TRUE);\r
330                         }\r
331 \r
332                         while(numspawned < maxspawned && spawnqueue_first)\r
333                         {\r
334                                 self = spawnqueue_first;\r
335 \r
336                                 bprint ("^4", self.netname, "^4 is the next challenger\n");\r
337 \r
338                                 Spawnqueue_Remove(self);\r
339                                 Spawnqueue_Mark(self);\r
340 \r
341                                 self.classname = "player";\r
342                                 PutClientInServer();\r
343                         }\r
344                 }\r
345         }\r
346 }\r