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