Enable falling sounds
[voretournament/voretournament.git] / data / qcsrc / server / sv_main.qc
1 \r
2 void CreatureFrame (void)\r
3 {\r
4         local entity oldself;\r
5         local float dm;\r
6         oldself = self;\r
7         self = findfloat(world, iscreature, TRUE);\r
8         while (self)\r
9         {\r
10                 if (self.movetype != MOVETYPE_NOCLIP)\r
11                 {\r
12                         if (self.waterlevel)\r
13                         {\r
14                                 if (!(self.flags & FL_INWATER))\r
15                                 {\r
16                                         self.flags |= FL_INWATER;\r
17                                         self.dmgtime = 0;\r
18                                 }\r
19                                 if (self.waterlevel != WATERLEVEL_SUBMERGED)\r
20                                 {\r
21                                         if(self.air_finished < time + 9)\r
22                                                 PlayerSound(self, playersound_gasp, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
23                                         self.air_finished = time + 12;\r
24                                         self.dmg = 2;\r
25                                 }\r
26                                 else if (self.air_finished < time)\r
27                                 {       // drown!\r
28                                         if (!self.deadflag)\r
29                                         if (self.pain_finished < time)\r
30                                         {\r
31                                                 Damage (self, world, world, 5, DEATH_DROWN, self.origin, '0 0 0');\r
32                                                 self.pain_finished = time + 0.5;\r
33                                         }\r
34                                 }\r
35                                 if (self.dmgtime < time)\r
36                                 {\r
37                                         self.dmgtime = time + 0.1;\r
38                                         if (self.watertype == CONTENT_LAVA)\r
39                                         {\r
40                                                 if (self.watersound_finished < time)\r
41                                                 {\r
42                                                         self.watersound_finished = time + 0.5;\r
43                                                         sound (self, CHAN_PLAYER, "player/lava.wav", VOL_BASE, ATTN_NORM);\r
44                                                 }\r
45                                                 Damage (self, world, world, 6 * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');\r
46                                         }\r
47                                         else if (self.watertype == CONTENT_SLIME)\r
48                                         {\r
49                                                 if (self.watersound_finished < time)\r
50                                                 {\r
51                                                         self.watersound_finished = time + 0.5;\r
52                                                         sound (self, CHAN_PLAYER, "player/slime.wav", VOL_BASE, ATTN_NORM);\r
53                                                 }\r
54                                                 Damage (self, world, world, 2 * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');\r
55                                         }\r
56                                 }\r
57                         }\r
58                         else\r
59                         {\r
60                                 if (self.flags & FL_INWATER)\r
61                                 {\r
62                                         // play leave water sound\r
63                                         self.flags &~= FL_INWATER;\r
64                                         self.dmgtime = 0;\r
65                                 }\r
66                                 self.air_finished = time + 12;\r
67                                 self.dmg = 2;\r
68                         }\r
69                         // check for falling damage\r
70                         if(!(g_cts && !cvar("g_cts_selfdamage")))\r
71                         {\r
72                                 dm = vlen(self.oldvelocity) - vlen(self.velocity); // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.\r
73                                 if (self.deadflag)\r
74                                         dm = (dm - cvar("g_balance_falldamage_deadminspeed")) * cvar("g_balance_falldamage_factor");\r
75                                 else\r
76                                         dm = min((dm - cvar("g_balance_falldamage_minspeed")) * cvar("g_balance_falldamage_factor"), cvar("g_balance_falldamage_maxdamage"));\r
77                                 if (dm > 0)\r
78                                 {\r
79                                         Damage (self, world, world, dm, DEATH_FALL, self.origin, '0 0 0');\r
80                                         // this must be allowed to cut the normal pain sounds (played after them and on the same channel)\r
81                                         // there's no way to detect falling damage and prevent the pain sounds for this to be played instead\r
82                                         PlayerSound(self, playersound_fall, CHAN_PAIN, VOICETYPE_PLAYERSOUND);\r
83                                 }\r
84                                 else if(vlen(self.velocity) > 100000 && cvar("developer"))\r
85                                 {\r
86                                         dprint(strcat(self.netname, " became too fast, please investigate: ", vtos(self.spawnorigin), "\n"));\r
87                                         Damage (self, world, world, 50000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');\r
88                                 }\r
89                         }\r
90 \r
91                         // play stupid sounds\r
92                         if (g_footsteps)\r
93                         if (!gameover)\r
94                         if (self.flags & FL_ONGROUND)\r
95                         if (vlen(self.velocity) > sv_maxspeed * 0.6)\r
96                         if (!self.deadflag)\r
97                         if (time < self.lastground + 0.2)\r
98                         {\r
99                                 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))\r
100                                 {\r
101                                         self.nextstep = time + 0.3 + random() * 0.1;\r
102                                         trace_dphitq3surfaceflags = 0;\r
103                                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);\r
104                                         /*\r
105                                         if(trace_fraction == 1)\r
106                                                 dprint("nohit\n");\r
107                                         else\r
108                                                 dprint(ftos(trace_dphitq3surfaceflags), "\n");\r
109                                         */\r
110                                         if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)\r
111                                         {\r
112                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)\r
113                                                         GlobalSound(globalsound_metalstep, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
114                                                 else\r
115                                                         GlobalSound(globalsound_step, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
116                                         }\r
117                                 }\r
118                         }\r
119                         self.oldvelocity = self.velocity;\r
120                 }\r
121                 self = findfloat(self, iscreature, TRUE);\r
122         }\r
123         self = oldself;\r
124 }\r
125 \r
126 \r
127 /*\r
128 =============\r
129 StartFrame\r
130 \r
131 Called before each frame by the server\r
132 =============\r
133 */\r
134 \r
135 float game_delay;\r
136 float game_delay_last;\r
137 \r
138 float RedirectionThink();\r
139 entity SelectSpawnPoint (float anypoint);\r
140 void StartFrame (void)\r
141 {\r
142         remove = remove_unsafely; // not during spawning!\r
143         serverprevtime = servertime;\r
144         servertime = time;\r
145         serverframetime = frametime;\r
146 \r
147 #ifdef PROFILING\r
148         if(time > client_cefc_accumulatortime + 1)\r
149         {\r
150                 float t, pp, c_seeing, c_seen;\r
151                 entity cl;\r
152                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);\r
153                 print("CEFC time: ", ftos(t * 1000), "ms; ");\r
154                 c_seeing = 0;\r
155                 c_seen = 0;\r
156                 FOR_EACH_CLIENT(cl)\r
157                 {\r
158                         if(clienttype(cl) == CLIENTTYPE_REAL)\r
159                                 ++c_seeing;\r
160                         if(cl.classname == "player")\r
161                                 ++c_seen;\r
162                 }\r
163                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");\r
164                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");\r
165 \r
166                 client_cefc_accumulatortime = time;\r
167                 client_cefc_accumulator = 0;\r
168         }\r
169 #endif\r
170 \r
171         entity e;\r
172         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )\r
173                 CSQCProjectile_Check(e);\r
174 \r
175         if(RedirectionThink())\r
176                 return;\r
177 \r
178         UncustomizeEntitiesRun();\r
179         InitializeEntitiesRun();\r
180 \r
181         WarpZone_StartFrame();\r
182 \r
183         sv_gravity = cvar("sv_gravity");\r
184         sv_maxairspeed = cvar("sv_maxairspeed");\r
185         sv_maxspeed = cvar ("sv_maxspeed");\r
186         sv_friction = cvar ("sv_friction");\r
187         sv_accelerate = cvar ("sv_accelerate");\r
188         sv_airaccelerate = cvar("sv_airaccelerate");\r
189         sv_airaccel_sideways_friction = cvar("sv_airaccel_sideways_friction");\r
190         sv_airaccel_qw = cvar("sv_airaccel_qw");\r
191         sv_stopspeed = cvar ("sv_stopspeed");\r
192         sv_airstopaccelerate = cvar("sv_airstopaccelerate");\r
193         sv_airstrafeaccelerate = cvar("sv_airstrafeaccelerate");\r
194         sv_maxairstrafespeed = cvar("sv_maxairstrafespeed");\r
195         sv_aircontrol = cvar("sv_aircontrol");\r
196         sv_warsowbunny_airforwardaccel = cvar("sv_warsowbunny_airforwardaccel");\r
197         sv_warsowbunny_accel = cvar("sv_warsowbunny_accel");\r
198         sv_warsowbunny_topspeed = cvar("sv_warsowbunny_topspeed");\r
199         sv_warsowbunny_turnaccel = cvar("sv_warsowbunny_turnaccel");\r
200         sv_warsowbunny_backtosideratio = cvar("sv_warsowbunny_backtosideratio");\r
201         teamplay = cvar ("teamplay");\r
202         sys_frametime = cvar("sys_ticrate") * cvar("slowmo");\r
203 \r
204         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)\r
205                 orig_slowmo = cvar("slowmo"); // slowmo will be restored after the timeout\r
206 \r
207         if(teams_matter && !teamplay)\r
208                 teamplay = 3;\r
209         if(!teams_matter && teamplay)\r
210                 teamplay = 0;\r
211 \r
212         skill = cvar("skill");\r
213 \r
214         Spawnqueue_Check();\r
215 \r
216 \r
217         // detect when the pre-game countdown (if any) has ended and the game has started\r
218         game_delay = (time < game_starttime) ? TRUE : FALSE;\r
219 \r
220         if(game_delay_last == TRUE)\r
221         if(game_delay == FALSE)\r
222         if(cvar("sv_eventlog"))\r
223                         GameLogEcho(":startdelay_ended");\r
224 \r
225         game_delay_last = game_delay;\r
226 \r
227         // if in warmup stage and limit for warmup is hit start match\r
228         if (inWarmupStage)\r
229         if ((g_warmup_limit > 0 && time >= g_warmup_limit)\r
230          || (g_warmup_limit == 0 && cvar("timelimit") != 0 && time >= cvar("timelimit") * 60))\r
231         {\r
232                 ReadyRestart();\r
233                 return;\r
234         }\r
235 \r
236         CreatureFrame ();\r
237         CheckRules_World ();\r
238 \r
239         AuditTeams();\r
240 \r
241         bot_serverframe();\r
242 \r
243         if(cvar("spawn_debugview"))\r
244         {\r
245                 RandomSelection_Init();\r
246                 for(self = world; (self = find(self, classname, "player")); )\r
247                         RandomSelection_Add(self, 0, string_null, 1, 0);\r
248                 self = RandomSelection_chosen_ent;\r
249                 SelectSpawnPoint(0);\r
250         }\r
251 \r
252         FOR_EACH_PLAYER(self)\r
253                 self.porto_forbidden = max(0, self.porto_forbidden - 1);\r
254 }\r
255 \r
256 .vector originjitter;\r
257 .vector anglesjitter;\r
258 .float anglejitter;\r
259 .string gametypefilter;\r
260 .string cvarfilter;\r
261 void SV_OnEntityPreSpawnFunction()\r
262 {\r
263         if(self.gametypefilter != "")\r
264         if not(isGametypeInFilter(game, teams_matter, self.gametypefilter))\r
265         {\r
266                 remove(self);\r
267                 return;\r
268         }\r
269         if(self.cvarfilter != "")\r
270         {\r
271                 float n, i, o, inv;\r
272                 string s, k, v;\r
273                 inv = 0;\r
274 \r
275                 s = self.cvarfilter;\r
276                 if(substring(s, 0, 1) == "+")\r
277                 {\r
278                         s = substring(s, 1, -1);\r
279                 }\r
280                 else if(substring(s, 0, 1) == "-")\r
281                 {\r
282                         inv = 1;\r
283                         s = substring(s, 1, -1);\r
284                 }\r
285 \r
286                 n = tokenize(s);\r
287                 for(i = 0; i < n; ++i)\r
288                 {\r
289                         s = argv(i);\r
290                         // syntax:\r
291                         // var>x\r
292                         // var<x\r
293                         // var>=x\r
294                         // var<=x\r
295                         // var==x\r
296                         // var!=x\r
297                         // var===x\r
298                         // var!==x\r
299                         if((o = strstrofs(s, ">=", 0)) >= 0)\r
300                         {\r
301                                 k = substring(s, 0, o);\r
302                                 v = substring(s, o+2, -1);\r
303                                 if(cvar(k) < stof(v))\r
304                                         goto cvar_fail;\r
305                         }\r
306                         else if((o = strstrofs(s, "<=", 0)) >= 0)\r
307                         {\r
308                                 k = substring(s, 0, o);\r
309                                 v = substring(s, o+2, -1);\r
310                                 if(cvar(k) > stof(v))\r
311                                         goto cvar_fail;\r
312                         }\r
313                         else if((o = strstrofs(s, ">", 0)) >= 0)\r
314                         {\r
315                                 k = substring(s, 0, o);\r
316                                 v = substring(s, o+1, -1);\r
317                                 if(cvar(k) <= stof(v))\r
318                                         goto cvar_fail;\r
319                         }\r
320                         else if((o = strstrofs(s, "<", 0)) >= 0)\r
321                         {\r
322                                 k = substring(s, 0, o);\r
323                                 v = substring(s, o+1, -1);\r
324                                 if(cvar(k) >= stof(v))\r
325                                         goto cvar_fail;\r
326                         }\r
327                         else if((o = strstrofs(s, "==", 0)) >= 0)\r
328                         {\r
329                                 k = substring(s, 0, o);\r
330                                 v = substring(s, o+2, -1);\r
331                                 if(cvar(k) != stof(v))\r
332                                         goto cvar_fail;\r
333                         }\r
334                         else if((o = strstrofs(s, "!=", 0)) >= 0)\r
335                         {\r
336                                 k = substring(s, 0, o);\r
337                                 v = substring(s, o+2, -1);\r
338                                 if(cvar(k) == stof(v))\r
339                                         goto cvar_fail;\r
340                         }\r
341                         else if((o = strstrofs(s, "===", 0)) >= 0)\r
342                         {\r
343                                 k = substring(s, 0, o);\r
344                                 v = substring(s, o+2, -1);\r
345                                 if(cvar_string(k) != v)\r
346                                         goto cvar_fail;\r
347                         }\r
348                         else if((o = strstrofs(s, "!==", 0)) >= 0)\r
349                         {\r
350                                 k = substring(s, 0, o);\r
351                                 v = substring(s, o+2, -1);\r
352                                 if(cvar_string(k) == v)\r
353                                         goto cvar_fail;\r
354                         }\r
355                         else if(substring(s, 0, 1) == "!")\r
356                         {\r
357                                 k = substring(s, 1, -1);\r
358                                 if(cvar(k))\r
359                                         goto cvar_fail;\r
360                         }\r
361                         else\r
362                         {\r
363                                 k = s;\r
364                                 if not(cvar(k))\r
365                                         goto cvar_fail;\r
366                         }\r
367                 }\r
368                 inv = !inv;\r
369 :cvar_fail\r
370                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it\r
371                 if not(inv)\r
372                 {\r
373                         //print("cvarfilter fail\n");\r
374                         remove(self);\r
375                         return;\r
376                 }\r
377         }\r
378 \r
379         // support special -1 and -2 angle from radiant\r
380         if (self.angles == '0 -1 0')\r
381                 self.angles = '-90 0 0';\r
382         else if (self.angles == '0 -2 0')\r
383                 self.angles = '+90 0 0';\r
384 \r
385         if(self.originjitter_x != 0)\r
386                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;\r
387         if(self.originjitter_y != 0)\r
388                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;\r
389         if(self.originjitter_z != 0)\r
390                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;\r
391         if(self.anglesjitter_x != 0)\r
392                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;\r
393         if(self.anglesjitter_y != 0)\r
394                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;\r
395         if(self.anglesjitter_z != 0)\r
396                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;\r
397         if(self.anglejitter != 0)\r
398                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;\r
399 }\r