Set sv_doublejump global every frame
[xonotic/xonotic-data.pk3dir.git] / 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         WarpZone_StartFrame();
180
181         sv_gravity = cvar("sv_gravity");
182         sv_maxairspeed = cvar("sv_maxairspeed");
183         sv_maxspeed = cvar ("sv_maxspeed");
184         sv_friction = cvar ("sv_friction");
185         sv_accelerate = cvar ("sv_accelerate");
186         sv_airaccelerate = cvar("sv_airaccelerate");
187         sv_airaccel_sideways_friction = cvar("sv_airaccel_sideways_friction");
188         sv_airaccel_qw = cvar("sv_airaccel_qw");
189         sv_stopspeed = cvar ("sv_stopspeed");
190         sv_airstopaccelerate = cvar("sv_airstopaccelerate");
191         sv_airstrafeaccelerate = cvar("sv_airstrafeaccelerate");
192         sv_maxairstrafespeed = cvar("sv_maxairstrafespeed");
193         sv_airstrafeaccel_qw = cvar("sv_airstrafeaccel_qw");
194         sv_aircontrol = cvar("sv_aircontrol");
195         sv_aircontrol_power = cvar("sv_aircontrol_power");
196         sv_warsowbunny_airforwardaccel = cvar("sv_warsowbunny_airforwardaccel");
197         sv_warsowbunny_accel = cvar("sv_warsowbunny_accel");
198         sv_warsowbunny_topspeed = cvar("sv_warsowbunny_topspeed");
199         sv_warsowbunny_turnaccel = cvar("sv_warsowbunny_turnaccel");
200         sv_warsowbunny_backtosideratio = cvar("sv_warsowbunny_backtosideratio");
201         teamplay = cvar ("teamplay");
202         sys_frametime = cvar("sys_ticrate") * cvar("slowmo");
203         sv_doublejump = cvar("sv_doublejump");
204
205         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)
206                 orig_slowmo = cvar("slowmo"); // slowmo will be restored after the timeout
207
208         if(teams_matter && !teamplay)
209                 teamplay = 3;
210         if(!teams_matter && teamplay)
211                 teamplay = 0;
212
213         skill = cvar("skill");
214
215         Spawnqueue_Check();
216
217
218         // detect when the pre-game countdown (if any) has ended and the game has started
219         game_delay = (time < game_starttime) ? TRUE : FALSE;
220
221         if(game_delay_last == TRUE)
222         if(game_delay == FALSE)
223         if(cvar("sv_eventlog"))
224                         GameLogEcho(":startdelay_ended");
225
226         game_delay_last = game_delay;
227
228         // if in warmup stage and limit for warmup is hit start match
229         if (inWarmupStage)
230         if ((g_warmup_limit > 0 && time >= g_warmup_limit)
231          || (g_warmup_limit == 0 && cvar("timelimit") != 0 && time >= cvar("timelimit") * 60))
232         {
233                 ReadyRestart();
234                 return;
235         }
236
237         CreatureFrame ();
238         CheckRules_World ();
239
240         AuditTeams();
241
242         RuneMatchGivePoints();
243         bot_serverframe();
244
245         if(cvar("spawn_debugview"))
246         {
247                 RandomSelection_Init();
248                 for(self = world; (self = find(self, classname, "player")); )
249                         RandomSelection_Add(self, 0, string_null, 1, 0);
250                 self = RandomSelection_chosen_ent;
251                 SelectSpawnPoint(0);
252         }
253
254         FOR_EACH_PLAYER(self)
255                 self.porto_forbidden = max(0, self.porto_forbidden - 1);
256 }
257
258 .vector originjitter;
259 .vector anglesjitter;
260 .float anglejitter;
261 .string gametypefilter;
262 .string cvarfilter;
263 void SV_OnEntityPreSpawnFunction()
264 {
265         if(self.gametypefilter != "")
266         if not(isGametypeInFilter(game, teams_matter, self.gametypefilter))
267         {
268                 remove(self);
269                 return;
270         }
271         if(self.cvarfilter != "")
272         {
273                 float n, i, o, inv;
274                 string s, k, v;
275                 inv = 0;
276
277                 s = self.cvarfilter;
278                 if(substring(s, 0, 1) == "+")
279                 {
280                         s = substring(s, 1, -1);
281                 }
282                 else if(substring(s, 0, 1) == "-")
283                 {
284                         inv = 1;
285                         s = substring(s, 1, -1);
286                 }
287
288                 n = tokenize(s);
289                 for(i = 0; i < n; ++i)
290                 {
291                         s = argv(i);
292                         // syntax:
293                         // var>x
294                         // var<x
295                         // var>=x
296                         // var<=x
297                         // var==x
298                         // var!=x
299                         // var===x
300                         // var!==x
301                         if((o = strstrofs(s, ">=", 0)) >= 0)
302                         {
303                                 k = substring(s, 0, o);
304                                 v = substring(s, o+2, -1);
305                                 if(cvar(k) < stof(v))
306                                         goto cvar_fail;
307                         }
308                         else if((o = strstrofs(s, "<=", 0)) >= 0)
309                         {
310                                 k = substring(s, 0, o);
311                                 v = substring(s, o+2, -1);
312                                 if(cvar(k) > stof(v))
313                                         goto cvar_fail;
314                         }
315                         else if((o = strstrofs(s, ">", 0)) >= 0)
316                         {
317                                 k = substring(s, 0, o);
318                                 v = substring(s, o+1, -1);
319                                 if(cvar(k) <= stof(v))
320                                         goto cvar_fail;
321                         }
322                         else if((o = strstrofs(s, "<", 0)) >= 0)
323                         {
324                                 k = substring(s, 0, o);
325                                 v = substring(s, o+1, -1);
326                                 if(cvar(k) >= stof(v))
327                                         goto cvar_fail;
328                         }
329                         else if((o = strstrofs(s, "==", 0)) >= 0)
330                         {
331                                 k = substring(s, 0, o);
332                                 v = substring(s, o+2, -1);
333                                 if(cvar(k) != stof(v))
334                                         goto cvar_fail;
335                         }
336                         else if((o = strstrofs(s, "!=", 0)) >= 0)
337                         {
338                                 k = substring(s, 0, o);
339                                 v = substring(s, o+2, -1);
340                                 if(cvar(k) == stof(v))
341                                         goto cvar_fail;
342                         }
343                         else if((o = strstrofs(s, "===", 0)) >= 0)
344                         {
345                                 k = substring(s, 0, o);
346                                 v = substring(s, o+2, -1);
347                                 if(cvar_string(k) != v)
348                                         goto cvar_fail;
349                         }
350                         else if((o = strstrofs(s, "!==", 0)) >= 0)
351                         {
352                                 k = substring(s, 0, o);
353                                 v = substring(s, o+2, -1);
354                                 if(cvar_string(k) == v)
355                                         goto cvar_fail;
356                         }
357                         else if(substring(s, 0, 1) == "!")
358                         {
359                                 k = substring(s, 1, -1);
360                                 if(cvar(k))
361                                         goto cvar_fail;
362                         }
363                         else
364                         {
365                                 k = s;
366                                 if not(cvar(k))
367                                         goto cvar_fail;
368                         }
369                 }
370                 inv = !inv;
371 :cvar_fail
372                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
373                 if not(inv)
374                 {
375                         //print("cvarfilter fail\n");
376                         remove(self);
377                         return;
378                 }
379         }
380
381         // support special -1 and -2 angle from radiant
382         if (self.angles == '0 -1 0')
383                 self.angles = '-90 0 0';
384         else if (self.angles == '0 -2 0')
385                 self.angles = '+90 0 0';
386
387         if(self.originjitter_x != 0)
388                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;
389         if(self.originjitter_y != 0)
390                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;
391         if(self.originjitter_z != 0)
392                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;
393         if(self.anglesjitter_x != 0)
394                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;
395         if(self.anglesjitter_y != 0)
396                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;
397         if(self.anglesjitter_z != 0)
398                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;
399         if(self.anglejitter != 0)
400                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;
401
402         if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
403         {
404                 remove(self);
405                 return;
406         }
407 }