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