Use pow() for all scale differences, which should make them much more correct, and...
[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(cvar("g_healthsize")) // if we are smaller or larger, we take more or less falling damage\r
78                                         dm *= (1 + cvar("g_healthsize_movementfactor")) - cvar("g_healthsize_movementfactor") * self.scale; \r
79                                 if (dm > 0)\r
80                                         Damage (self, world, world, dm, DEATH_FALL, self.origin, '0 0 0');\r
81                                 else if(vlen(self.velocity) > 100000 && cvar("developer"))\r
82                                 {\r
83                                         dprint(strcat(self.netname, " became too fast, please investigate: ", vtos(self.spawnorigin), "\n"));\r
84                                         Damage (self, world, world, 50000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');\r
85                                 }\r
86                         }\r
87 \r
88                         // play stupid sounds\r
89                         if (g_footsteps)\r
90                         if (!gameover)\r
91                         if (self.flags & FL_ONGROUND)\r
92                         if (vlen(self.velocity) > sv_maxspeed * 0.6)\r
93                         if (!self.deadflag)\r
94                         if (time < self.lastground + 0.2)\r
95                         {\r
96                                 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))\r
97                                 {\r
98                                         self.nextstep = time + 0.3 + random() * 0.1;\r
99                                         trace_dphitq3surfaceflags = 0;\r
100                                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);\r
101                                         /*\r
102                                         if(trace_fraction == 1)\r
103                                                 dprint("nohit\n");\r
104                                         else\r
105                                                 dprint(ftos(trace_dphitq3surfaceflags), "\n");\r
106                                         */\r
107                                         if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)\r
108                                         {\r
109                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)\r
110                                                         GlobalSound(globalsound_metalstep, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
111                                                 else\r
112                                                         GlobalSound(globalsound_step, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
113                                         }\r
114                                 }\r
115                         }\r
116                         self.oldvelocity = self.velocity;\r
117                 }\r
118                 self = findfloat(self, iscreature, TRUE);\r
119         }\r
120         self = oldself;\r
121 }\r
122 \r
123 \r
124 /*\r
125 =============\r
126 StartFrame\r
127 \r
128 Called before each frame by the server\r
129 =============\r
130 */\r
131 \r
132 float game_delay;\r
133 float game_delay_last;\r
134 \r
135 float RedirectionThink();\r
136 entity SelectSpawnPoint (float anypoint);\r
137 void StartFrame (void)\r
138 {\r
139         remove = remove_unsafely; // not during spawning!\r
140         serverprevtime = servertime;\r
141         servertime = time;\r
142         serverframetime = frametime;\r
143 \r
144 #ifdef PROFILING\r
145         if(time > client_cefc_accumulatortime + 1)\r
146         {\r
147                 float t, pp, c_seeing, c_seen;\r
148                 entity cl;\r
149                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);\r
150                 print("CEFC time: ", ftos(t * 1000), "ms; ");\r
151                 c_seeing = 0;\r
152                 c_seen = 0;\r
153                 FOR_EACH_CLIENT(cl)\r
154                 {\r
155                         if(clienttype(cl) == CLIENTTYPE_REAL)\r
156                                 ++c_seeing;\r
157                         if(cl.classname == "player")\r
158                                 ++c_seen;\r
159                 }\r
160                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");\r
161                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");\r
162 \r
163                 client_cefc_accumulatortime = time;\r
164                 client_cefc_accumulator = 0;\r
165         }\r
166 #endif\r
167 \r
168         entity e;\r
169         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )\r
170                 CSQCProjectile_Check(e);\r
171 \r
172         if(RedirectionThink())\r
173                 return;\r
174 \r
175         UncustomizeEntitiesRun();\r
176         InitializeEntitiesRun();\r
177 \r
178         WarpZone_StartFrame();\r
179 \r
180         sv_gravity = cvar("sv_gravity");\r
181         sv_maxairspeed = cvar("sv_maxairspeed");\r
182         sv_maxspeed = cvar ("sv_maxspeed");\r
183         sv_friction = cvar ("sv_friction");\r
184         sv_accelerate = cvar ("sv_accelerate");\r
185         sv_airaccelerate = cvar("sv_airaccelerate");\r
186         sv_airaccel_sideways_friction = cvar("sv_airaccel_sideways_friction");\r
187         sv_airaccel_qw = cvar("sv_airaccel_qw");\r
188         sv_stopspeed = cvar ("sv_stopspeed");\r
189         sv_airstopaccelerate = cvar("sv_airstopaccelerate");\r
190         sv_airstrafeaccelerate = cvar("sv_airstrafeaccelerate");\r
191         sv_maxairstrafespeed = cvar("sv_maxairstrafespeed");\r
192         sv_aircontrol = cvar("sv_aircontrol");\r
193         sv_warsowbunny_airforwardaccel = cvar("sv_warsowbunny_airforwardaccel");\r
194         sv_warsowbunny_accel = cvar("sv_warsowbunny_accel");\r
195         sv_warsowbunny_topspeed = cvar("sv_warsowbunny_topspeed");\r
196         sv_warsowbunny_turnaccel = cvar("sv_warsowbunny_turnaccel");\r
197         sv_warsowbunny_backtosideratio = cvar("sv_warsowbunny_backtosideratio");\r
198         teamplay = cvar ("teamplay");\r
199         sys_frametime = cvar("sys_ticrate") * cvar("slowmo");\r
200 \r
201         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)\r
202                 orig_slowmo = cvar("slowmo"); // slowmo will be restored after the timeout\r
203 \r
204         if(teams_matter && !teamplay)\r
205                 teamplay = 3;\r
206         if(!teams_matter && teamplay)\r
207                 teamplay = 0;\r
208 \r
209         skill = cvar("skill");\r
210 \r
211         Spawnqueue_Check();\r
212 \r
213 \r
214         // detect when the pre-game countdown (if any) has ended and the game has started\r
215         game_delay = (time < game_starttime) ? TRUE : FALSE;\r
216 \r
217         if(game_delay_last == TRUE)\r
218         if(game_delay == FALSE)\r
219         if(cvar("sv_eventlog"))\r
220                         GameLogEcho(":startdelay_ended");\r
221 \r
222         game_delay_last = game_delay;\r
223 \r
224         // if in warmup stage and limit for warmup is hit start match\r
225         if (inWarmupStage)\r
226         if ((g_warmup_limit > 0 && time >= g_warmup_limit)\r
227          || (g_warmup_limit == 0 && cvar("timelimit") != 0 && time >= cvar("timelimit") * 60))\r
228         {\r
229                 ReadyRestart();\r
230                 return;\r
231         }\r
232 \r
233         CreatureFrame ();\r
234         CheckRules_World ();\r
235 \r
236         AuditTeams();\r
237 \r
238         bot_serverframe();\r
239 \r
240         if(cvar("spawn_debugview"))\r
241         {\r
242                 RandomSelection_Init();\r
243                 for(self = world; (self = find(self, classname, "player")); )\r
244                         RandomSelection_Add(self, 0, string_null, 1, 0);\r
245                 self = RandomSelection_chosen_ent;\r
246                 SelectSpawnPoint(0);\r
247         }\r
248 \r
249         FOR_EACH_PLAYER(self)\r
250                 self.porto_forbidden = max(0, self.porto_forbidden - 1);\r
251 }\r
252 \r
253 .vector originjitter;\r
254 .vector anglesjitter;\r
255 .float anglejitter;\r
256 .string gametypefilter;\r
257 .string cvarfilter;\r
258 void SV_OnEntityPreSpawnFunction()\r
259 {\r
260         if(self.gametypefilter != "")\r
261         if not(isGametypeInFilter(game, teams_matter, self.gametypefilter))\r
262         {\r
263                 remove(self);\r
264                 return;\r
265         }\r
266         if(self.cvarfilter != "")\r
267         {\r
268                 float n, i, o, inv;\r
269                 string s, k, v;\r
270                 inv = 0;\r
271 \r
272                 s = self.cvarfilter;\r
273                 if(substring(s, 0, 1) == "+")\r
274                 {\r
275                         s = substring(s, 1, -1);\r
276                 }\r
277                 else if(substring(s, 0, 1) == "-")\r
278                 {\r
279                         inv = 1;\r
280                         s = substring(s, 1, -1);\r
281                 }\r
282 \r
283                 n = tokenize(s);\r
284                 for(i = 0; i < n; ++i)\r
285                 {\r
286                         s = argv(i);\r
287                         // syntax:\r
288                         // var>x\r
289                         // var<x\r
290                         // var>=x\r
291                         // var<=x\r
292                         // var==x\r
293                         // var!=x\r
294                         // var===x\r
295                         // var!==x\r
296                         if((o = strstrofs(s, ">=", 0)) >= 0)\r
297                         {\r
298                                 k = substring(s, 0, o);\r
299                                 v = substring(s, o+2, -1);\r
300                                 if(cvar(k) < stof(v))\r
301                                         goto cvar_fail;\r
302                         }\r
303                         else if((o = strstrofs(s, "<=", 0)) >= 0)\r
304                         {\r
305                                 k = substring(s, 0, o);\r
306                                 v = substring(s, o+2, -1);\r
307                                 if(cvar(k) > stof(v))\r
308                                         goto cvar_fail;\r
309                         }\r
310                         else if((o = strstrofs(s, ">", 0)) >= 0)\r
311                         {\r
312                                 k = substring(s, 0, o);\r
313                                 v = substring(s, o+1, -1);\r
314                                 if(cvar(k) <= stof(v))\r
315                                         goto cvar_fail;\r
316                         }\r
317                         else if((o = strstrofs(s, "<", 0)) >= 0)\r
318                         {\r
319                                 k = substring(s, 0, o);\r
320                                 v = substring(s, o+1, -1);\r
321                                 if(cvar(k) >= stof(v))\r
322                                         goto cvar_fail;\r
323                         }\r
324                         else if((o = strstrofs(s, "==", 0)) >= 0)\r
325                         {\r
326                                 k = substring(s, 0, o);\r
327                                 v = substring(s, o+2, -1);\r
328                                 if(cvar(k) != stof(v))\r
329                                         goto cvar_fail;\r
330                         }\r
331                         else if((o = strstrofs(s, "!=", 0)) >= 0)\r
332                         {\r
333                                 k = substring(s, 0, o);\r
334                                 v = substring(s, o+2, -1);\r
335                                 if(cvar(k) == stof(v))\r
336                                         goto cvar_fail;\r
337                         }\r
338                         else if((o = strstrofs(s, "===", 0)) >= 0)\r
339                         {\r
340                                 k = substring(s, 0, o);\r
341                                 v = substring(s, o+2, -1);\r
342                                 if(cvar_string(k) != v)\r
343                                         goto cvar_fail;\r
344                         }\r
345                         else if((o = strstrofs(s, "!==", 0)) >= 0)\r
346                         {\r
347                                 k = substring(s, 0, o);\r
348                                 v = substring(s, o+2, -1);\r
349                                 if(cvar_string(k) == v)\r
350                                         goto cvar_fail;\r
351                         }\r
352                         else if(substring(s, 0, 1) == "!")\r
353                         {\r
354                                 k = substring(s, 1, -1);\r
355                                 if(cvar(k))\r
356                                         goto cvar_fail;\r
357                         }\r
358                         else\r
359                         {\r
360                                 k = s;\r
361                                 if not(cvar(k))\r
362                                         goto cvar_fail;\r
363                         }\r
364                 }\r
365                 inv = !inv;\r
366 :cvar_fail\r
367                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it\r
368                 if not(inv)\r
369                 {\r
370                         //print("cvarfilter fail\n");\r
371                         remove(self);\r
372                         return;\r
373                 }\r
374         }\r
375 \r
376         // support special -1 and -2 angle from radiant\r
377         if (self.angles == '0 -1 0')\r
378                 self.angles = '-90 0 0';\r
379         else if (self.angles == '0 -2 0')\r
380                 self.angles = '+90 0 0';\r
381 \r
382         if(self.originjitter_x != 0)\r
383                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;\r
384         if(self.originjitter_y != 0)\r
385                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;\r
386         if(self.originjitter_z != 0)\r
387                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;\r
388         if(self.anglesjitter_x != 0)\r
389                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;\r
390         if(self.anglesjitter_y != 0)\r
391                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;\r
392         if(self.anglesjitter_z != 0)\r
393                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;\r
394         if(self.anglejitter != 0)\r
395                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;\r
396 }\r