e49283c69874beb447c485321e50fe7b623cf609
[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 healthsize is enabled, play effects based on player size\r
110                                                 if(cvar("g_healthsize"))\r
111                                                 {\r
112                                                         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)\r
113                                                                 GlobalSound(globalsound_metalstep, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, bound(0, VOL_BASE * (1 - playersize_micro(self)), 1));\r
114                                                         else\r
115                                                                 GlobalSound(globalsound_step, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, bound(0, VOL_BASE * (1 - playersize_micro(self)), 1));\r
116                                                         sound(self, CHAN_AUTO, "misc/macro_footstep.wav", bound(0, VOL_BASE * playersize_macro(self), 1), ATTN_NORM);\r
117 \r
118                                                         // earthquake effect for nearby players when a macro walks by\r
119                                                         if(cvar("g_healthsize_quake_step"))\r
120                                                         {\r
121                                                                 entity head;\r
122                                                                 for(head = findradius(self.origin, cvar("g_healthsize_quake_step_radius")); head; head = head.chain)\r
123                                                                 {\r
124                                                                         if not(head.classname == "player" || head.classname == "spectator")\r
125                                                                                 continue;\r
126                                                                         if(head == self || head.spectatee_status == num_for_edict(self))\r
127                                                                                 continue; // not for self\r
128                                                                         if not(head.flags & FL_ONGROUND)\r
129                                                                                 continue; // we only feel the ground shaking if we are sitting on it\r
130                                                                         if(head.stat_eaten)\r
131                                                                                 continue; // not for prey\r
132 \r
133                                                                         float shake;\r
134                                                                         shake = vlen(head.origin - self.origin);\r
135                                                                         if(shake)\r
136                                                                                 shake = 1 - bound(0, shake / cvar("g_healthsize_quake_step_radius"), 1);\r
137                                                                         shake *= playersize_macro(self) * cvar("g_healthsize_quake_step");\r
138 \r
139                                                                         head.punchvector_x += crandom() * shake;\r
140                                                                         head.punchvector_y += crandom() * shake;\r
141                                                                         head.punchvector_z += crandom() * shake;\r
142                                                                 }\r
143                                                         }\r
144                                                 }\r
145                                                 else\r
146                                                 {\r
147                                                         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)\r
148                                                                 GlobalSound(globalsound_metalstep, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, VOL_BASE);\r
149                                                         else\r
150                                                                 GlobalSound(globalsound_step, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, VOL_BASE);\r
151                                                 }\r
152                                         }\r
153                                 }\r
154                         }\r
155                         self.oldvelocity = self.velocity;\r
156                 }\r
157                 self = findfloat(self, iscreature, TRUE);\r
158         }\r
159         self = oldself;\r
160 }\r
161 \r
162 \r
163 /*\r
164 =============\r
165 StartFrame\r
166 \r
167 Called before each frame by the server\r
168 =============\r
169 */\r
170 \r
171 float game_delay;\r
172 float game_delay_last;\r
173 \r
174 float RedirectionThink();\r
175 entity SelectSpawnPoint (float anypoint);\r
176 void StartFrame (void)\r
177 {\r
178         remove = remove_unsafely; // not during spawning!\r
179         serverprevtime = servertime;\r
180         servertime = time;\r
181         serverframetime = frametime;\r
182 \r
183 #ifdef PROFILING\r
184         if(time > client_cefc_accumulatortime + 1)\r
185         {\r
186                 float t, pp, c_seeing, c_seen;\r
187                 entity cl;\r
188                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);\r
189                 print("CEFC time: ", ftos(t * 1000), "ms; ");\r
190                 c_seeing = 0;\r
191                 c_seen = 0;\r
192                 FOR_EACH_CLIENT(cl)\r
193                 {\r
194                         if(clienttype(cl) == CLIENTTYPE_REAL)\r
195                                 ++c_seeing;\r
196                         if(cl.classname == "player")\r
197                                 ++c_seen;\r
198                 }\r
199                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");\r
200                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");\r
201 \r
202                 client_cefc_accumulatortime = time;\r
203                 client_cefc_accumulator = 0;\r
204         }\r
205 #endif\r
206 \r
207         entity e;\r
208         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )\r
209                 CSQCProjectile_Check(e);\r
210 \r
211         if(RedirectionThink())\r
212                 return;\r
213 \r
214         UncustomizeEntitiesRun();\r
215         InitializeEntitiesRun();\r
216 \r
217         WarpZone_StartFrame();\r
218 \r
219         sv_gravity = cvar("sv_gravity");\r
220         sv_maxairspeed = cvar("sv_maxairspeed");\r
221         sv_maxspeed = cvar ("sv_maxspeed");\r
222         sv_friction = cvar ("sv_friction");\r
223         sv_accelerate = cvar ("sv_accelerate");\r
224         sv_airaccelerate = cvar("sv_airaccelerate");\r
225         sv_airaccel_sideways_friction = cvar("sv_airaccel_sideways_friction");\r
226         sv_airaccel_qw = cvar("sv_airaccel_qw");\r
227         sv_stopspeed = cvar ("sv_stopspeed");\r
228         sv_airstopaccelerate = cvar("sv_airstopaccelerate");\r
229         sv_airstrafeaccelerate = cvar("sv_airstrafeaccelerate");\r
230         sv_maxairstrafespeed = cvar("sv_maxairstrafespeed");\r
231         sv_aircontrol = cvar("sv_aircontrol");\r
232         sv_warsowbunny_airforwardaccel = cvar("sv_warsowbunny_airforwardaccel");\r
233         sv_warsowbunny_accel = cvar("sv_warsowbunny_accel");\r
234         sv_warsowbunny_topspeed = cvar("sv_warsowbunny_topspeed");\r
235         sv_warsowbunny_turnaccel = cvar("sv_warsowbunny_turnaccel");\r
236         sv_warsowbunny_backtosideratio = cvar("sv_warsowbunny_backtosideratio");\r
237         teamplay = cvar ("teamplay");\r
238         sys_frametime = cvar("sys_ticrate") * cvar("slowmo");\r
239 \r
240         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)\r
241                 orig_slowmo = cvar("slowmo"); // slowmo will be restored after the timeout\r
242 \r
243         if(teams_matter && !teamplay)\r
244                 teamplay = 3;\r
245         if(!teams_matter && teamplay)\r
246                 teamplay = 0;\r
247 \r
248         skill = cvar("skill");\r
249 \r
250         Spawnqueue_Check();\r
251 \r
252 \r
253         // detect when the pre-game countdown (if any) has ended and the game has started\r
254         game_delay = (time < game_starttime) ? TRUE : FALSE;\r
255 \r
256         if(game_delay_last == TRUE)\r
257         if(game_delay == FALSE)\r
258         if(cvar("sv_eventlog"))\r
259                         GameLogEcho(":startdelay_ended");\r
260 \r
261         game_delay_last = game_delay;\r
262 \r
263         // if in warmup stage and limit for warmup is hit start match\r
264         if (inWarmupStage)\r
265         if ((g_warmup_limit > 0 && time >= g_warmup_limit)\r
266          || (g_warmup_limit == 0 && cvar("timelimit") != 0 && time >= cvar("timelimit") * 60))\r
267         {\r
268                 ReadyRestart();\r
269                 return;\r
270         }\r
271 \r
272         CreatureFrame ();\r
273         CheckRules_World ();\r
274 \r
275         AuditTeams();\r
276 \r
277         bot_serverframe();\r
278 \r
279         if(cvar("spawn_debugview"))\r
280         {\r
281                 RandomSelection_Init();\r
282                 for(self = world; (self = find(self, classname, "player")); )\r
283                         RandomSelection_Add(self, 0, string_null, 1, 0);\r
284                 self = RandomSelection_chosen_ent;\r
285                 SelectSpawnPoint(0);\r
286         }\r
287 \r
288         FOR_EACH_PLAYER(self)\r
289                 self.porto_forbidden = max(0, self.porto_forbidden - 1);\r
290 }\r
291 \r
292 .vector originjitter;\r
293 .vector anglesjitter;\r
294 .float anglejitter;\r
295 .string gametypefilter;\r
296 .string cvarfilter;\r
297 void SV_OnEntityPreSpawnFunction()\r
298 {\r
299         if(self.gametypefilter != "")\r
300         if not(isGametypeInFilter(game, teams_matter, self.gametypefilter))\r
301         {\r
302                 remove(self);\r
303                 return;\r
304         }\r
305         if(self.cvarfilter != "")\r
306         {\r
307                 float n, i, o, inv;\r
308                 string s, k, v;\r
309                 inv = 0;\r
310 \r
311                 s = self.cvarfilter;\r
312                 if(substring(s, 0, 1) == "+")\r
313                 {\r
314                         s = substring(s, 1, -1);\r
315                 }\r
316                 else if(substring(s, 0, 1) == "-")\r
317                 {\r
318                         inv = 1;\r
319                         s = substring(s, 1, -1);\r
320                 }\r
321 \r
322                 n = tokenize(s);\r
323                 for(i = 0; i < n; ++i)\r
324                 {\r
325                         s = argv(i);\r
326                         // syntax:\r
327                         // var>x\r
328                         // var<x\r
329                         // var>=x\r
330                         // var<=x\r
331                         // var==x\r
332                         // var!=x\r
333                         // var===x\r
334                         // var!==x\r
335                         if((o = strstrofs(s, ">=", 0)) >= 0)\r
336                         {\r
337                                 k = substring(s, 0, o);\r
338                                 v = substring(s, o+2, -1);\r
339                                 if(cvar(k) < stof(v))\r
340                                         goto cvar_fail;\r
341                         }\r
342                         else if((o = strstrofs(s, "<=", 0)) >= 0)\r
343                         {\r
344                                 k = substring(s, 0, o);\r
345                                 v = substring(s, o+2, -1);\r
346                                 if(cvar(k) > stof(v))\r
347                                         goto cvar_fail;\r
348                         }\r
349                         else if((o = strstrofs(s, ">", 0)) >= 0)\r
350                         {\r
351                                 k = substring(s, 0, o);\r
352                                 v = substring(s, o+1, -1);\r
353                                 if(cvar(k) <= stof(v))\r
354                                         goto cvar_fail;\r
355                         }\r
356                         else if((o = strstrofs(s, "<", 0)) >= 0)\r
357                         {\r
358                                 k = substring(s, 0, o);\r
359                                 v = substring(s, o+1, -1);\r
360                                 if(cvar(k) >= stof(v))\r
361                                         goto cvar_fail;\r
362                         }\r
363                         else if((o = strstrofs(s, "==", 0)) >= 0)\r
364                         {\r
365                                 k = substring(s, 0, o);\r
366                                 v = substring(s, o+2, -1);\r
367                                 if(cvar(k) != stof(v))\r
368                                         goto cvar_fail;\r
369                         }\r
370                         else if((o = strstrofs(s, "!=", 0)) >= 0)\r
371                         {\r
372                                 k = substring(s, 0, o);\r
373                                 v = substring(s, o+2, -1);\r
374                                 if(cvar(k) == stof(v))\r
375                                         goto cvar_fail;\r
376                         }\r
377                         else if((o = strstrofs(s, "===", 0)) >= 0)\r
378                         {\r
379                                 k = substring(s, 0, o);\r
380                                 v = substring(s, o+2, -1);\r
381                                 if(cvar_string(k) != v)\r
382                                         goto cvar_fail;\r
383                         }\r
384                         else if((o = strstrofs(s, "!==", 0)) >= 0)\r
385                         {\r
386                                 k = substring(s, 0, o);\r
387                                 v = substring(s, o+2, -1);\r
388                                 if(cvar_string(k) == v)\r
389                                         goto cvar_fail;\r
390                         }\r
391                         else if(substring(s, 0, 1) == "!")\r
392                         {\r
393                                 k = substring(s, 1, -1);\r
394                                 if(cvar(k))\r
395                                         goto cvar_fail;\r
396                         }\r
397                         else\r
398                         {\r
399                                 k = s;\r
400                                 if not(cvar(k))\r
401                                         goto cvar_fail;\r
402                         }\r
403                 }\r
404                 inv = !inv;\r
405 :cvar_fail\r
406                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it\r
407                 if not(inv)\r
408                 {\r
409                         //print("cvarfilter fail\n");\r
410                         remove(self);\r
411                         return;\r
412                 }\r
413         }\r
414 \r
415         // support special -1 and -2 angle from radiant\r
416         if (self.angles == '0 -1 0')\r
417                 self.angles = '-90 0 0';\r
418         else if (self.angles == '0 -2 0')\r
419                 self.angles = '+90 0 0';\r
420 \r
421         if(self.originjitter_x != 0)\r
422                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;\r
423         if(self.originjitter_y != 0)\r
424                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;\r
425         if(self.originjitter_z != 0)\r
426                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;\r
427         if(self.anglesjitter_x != 0)\r
428                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;\r
429         if(self.anglesjitter_y != 0)\r
430                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;\r
431         if(self.anglesjitter_z != 0)\r
432                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;\r
433         if(self.anglejitter != 0)\r
434                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;\r
435 }\r