]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/sv_main.qc
Merge remote-tracking branch 'origin/terencehill/reload_binds', closes #1360
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / sv_main.qc
1 void CreatureFrame (void)
2 {
3         entity oldself;
4         float dm;
5         
6         oldself = self;
7         for(self = world; (self = findfloat(self, damagedbycontents, TRUE)); )
8         {
9                 if (self.movetype == MOVETYPE_NOCLIP) { continue; }
10                 
11                 float vehic = (self.vehicle_flags & VHF_ISVEHICLE);
12                 float projectile = (self.flags & FL_PROJECTILE);
13                 
14                 if (self.watertype <= CONTENT_WATER && self.waterlevel > 0) // workaround a retarded bug made by id software :P (yes, it's that old of a bug)
15                 {
16                         if (!(self.flags & FL_INWATER))
17                         {
18                                 self.flags |= FL_INWATER;
19                                 self.dmgtime = 0;
20                         }
21
22                         if(!vehic && !projectile) // vehicles and projectiles don't drown
23                         {
24                                 if (self.waterlevel != WATERLEVEL_SUBMERGED)
25                                 {
26                                         if(self.air_finished < time)
27                                                 PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
28                                         self.air_finished = time + autocvar_g_balance_contents_drowndelay;
29                                         self.dmg = 2;
30                                 }
31                                 else if (self.air_finished < time)
32                                 {       // drown!
33                                         if (!self.deadflag)
34                                         if (self.pain_finished < time)
35                                         {
36                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN, self.origin, '0 0 0');
37                                                 self.pain_finished = time + 0.5;
38                                         }
39                                 }
40                         }
41                         
42                         if (self.dmgtime < time)
43                         {
44                                 self.dmgtime = time + autocvar_g_balance_contents_damagerate; 
45                                 
46                                 if (projectile)
47                                 {
48                                         if (self.watertype == CONTENT_LAVA)
49                                         {
50                                                 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
51                                         }
52                                         else if (self.watertype == CONTENT_SLIME)
53                                         {
54                                                 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
55                                         }
56                                 }
57                                 else
58                                 {
59                                         if (self.watertype == CONTENT_LAVA)
60                                         {
61                                                 if (self.watersound_finished < time)
62                                                 {
63                                                         self.watersound_finished = time + 0.5;
64                                                         sound (self, CH_PLAYER, "player/lava.wav", VOL_BASE, ATTN_NORM);
65                                                 }
66                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
67                                         }
68                                         else if (self.watertype == CONTENT_SLIME)
69                                         {
70                                                 if (self.watersound_finished < time)
71                                                 {
72                                                         self.watersound_finished = time + 0.5;
73                                                         sound (self, CH_PLAYER, "player/slime.wav", VOL_BASE, ATTN_NORM);
74                                                 }
75                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
76                                         }
77                                 }
78                         }
79                 }
80                 else
81                 {
82                         if (self.flags & FL_INWATER)
83                         {
84                                 // play leave water sound
85                                 self.flags &~= FL_INWATER;
86                                 self.dmgtime = 0;
87                         }
88                         self.air_finished = time + 12;
89                         self.dmg = 2;
90                 }
91
92                 if(!vehic && !projectile) // vehicles don't get falling damage
93                 {
94                         // check for falling damage
95                         float velocity_len = vlen(self.velocity);
96                         if(!self.hook.state && !g_ca && !(g_cts && !autocvar_g_cts_selfdamage))
97                         {
98                                 dm = vlen(self.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
99                                 if (self.deadflag)
100                                         dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
101                                 else
102                                         dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
103                                 if (dm > 0)
104                                         Damage (self, world, world, dm, DEATH_FALL, self.origin, '0 0 0');
105                         }
106
107                         if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
108                                 Damage (self, world, world, 100000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');
109                         // play stupid sounds
110                         if (g_footsteps)
111                         if (!gameover)
112                         if (self.flags & FL_ONGROUND)
113                         if (velocity_len > autocvar_sv_maxspeed * 0.6)
114                         if (!self.deadflag)
115                         if (time < self.lastground + 0.2)
116                         {
117                                 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
118                                 {
119                                         self.nextstep = time + 0.3 + random() * 0.1;
120                                         trace_dphitq3surfaceflags = 0;
121                                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
122                                         /*
123                                         if(trace_fraction == 1)
124                                                 dprint("nohit\n");
125                                         else
126                                                 dprint(ftos(trace_dphitq3surfaceflags), "\n");
127                                         */
128                                         if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
129                                         {
130                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
131                                                         GlobalSound(globalsound_metalstep, CH_PLAYER, VOICETYPE_PLAYERSOUND);
132                                                 else
133                                                         GlobalSound(globalsound_step, CH_PLAYER, VOICETYPE_PLAYERSOUND);
134                                         }
135                                 }
136                         }
137                 }
138                 
139         self.oldvelocity = self.velocity;
140         }
141         self = oldself;
142 }
143
144
145 /*
146 =============
147 StartFrame
148
149 Called before each frame by the server
150 =============
151 */
152
153 float game_delay;
154 float game_delay_last;
155
156 void RuneMatchGivePoints();
157 float RedirectionThink();
158 entity SelectSpawnPoint (float anypoint);
159 void StartFrame (void)
160 {
161         execute_next_frame();
162
163         remove = remove_unsafely; // not during spawning!
164         serverprevtime = servertime;
165         servertime = time;
166         serverframetime = frametime;
167
168 #ifdef PROFILING
169         if(time > client_cefc_accumulatortime + 1)
170         {
171                 float t, pp, c_seeing, c_seen;
172                 entity cl;
173                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
174                 print("CEFC time: ", ftos(t * 1000), "ms; ");
175                 c_seeing = 0;
176                 c_seen = 0;
177                 FOR_EACH_CLIENT(cl)
178                 {
179                         if(clienttype(cl) == CLIENTTYPE_REAL)
180                                 ++c_seeing;
181                         if(cl.classname == "player")
182                                 ++c_seen;
183                 }
184                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
185                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
186
187                 client_cefc_accumulatortime = time;
188                 client_cefc_accumulator = 0;
189         }
190 #endif
191
192         entity e;
193         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
194                 CSQCProjectile_Check(e);
195
196         if(RedirectionThink())
197                 return;
198
199         UncustomizeEntitiesRun();
200         InitializeEntitiesRun();
201
202         WarpZone_StartFrame();
203
204         sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
205         if(sys_frametime <= 0)
206                 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
207
208         if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
209                 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
210
211         skill = autocvar_skill;
212
213         count_players();
214         if(g_ca || g_freezetag)
215                 count_alive_players();
216         Arena_Warmup();
217         Spawnqueue_Check();
218
219         // detect when the pre-game countdown (if any) has ended and the game has started
220         game_delay = (time < game_starttime) ? TRUE : FALSE;
221
222         if(game_delay_last == TRUE)
223         if(game_delay == FALSE)
224         if(autocvar_sv_eventlog)
225                         GameLogEcho(":startdelay_ended");
226
227         game_delay_last = game_delay;
228
229         // if in warmup stage and limit for warmup is hit start match
230         if (inWarmupStage)
231         if ((g_warmup_limit > 0 && time >= g_warmup_limit)
232          || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
233         {
234                 ReadyRestart();
235                 return;
236         }
237
238         CreatureFrame ();
239         CheckRules_World ();
240
241         RuneMatchGivePoints();
242         bot_serverframe();
243
244         FOR_EACH_PLAYER(self)
245                 self.porto_forbidden = max(0, self.porto_forbidden - 1);
246
247         MUTATOR_CALLHOOK(SV_StartFrame);
248 }
249
250 .vector originjitter;
251 .vector anglesjitter;
252 .float anglejitter;
253 .string gametypefilter;
254 .string cvarfilter;
255 float DoesQ3ARemoveThisEntity();
256 void SV_OnEntityPreSpawnFunction()
257 {
258         if (self)
259         if (self.gametypefilter != "")
260         if not(isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
261         {
262                 remove(self);
263                 return;
264         }
265         if(self.cvarfilter != "")
266         {
267                 float n, i, o, inv;
268                 string s, k, v;
269                 inv = 0;
270
271                 s = self.cvarfilter;
272                 if(substring(s, 0, 1) == "+")
273                 {
274                         s = substring(s, 1, -1);
275                 }
276                 else if(substring(s, 0, 1) == "-")
277                 {
278                         inv = 1;
279                         s = substring(s, 1, -1);
280                 }
281
282                 n = tokenize_console(s);
283                 for(i = 0; i < n; ++i)
284                 {
285                         s = argv(i);
286                         // syntax:
287                         // var>x
288                         // var<x
289                         // var>=x
290                         // var<=x
291                         // var==x
292                         // var!=x
293                         // var===x
294                         // var!==x
295                         if((o = strstrofs(s, ">=", 0)) >= 0)
296                         {
297                                 k = substring(s, 0, o);
298                                 v = substring(s, o+2, -1);
299                                 if(cvar(k) < stof(v))
300                                         goto cvar_fail;
301                         }
302                         else if((o = strstrofs(s, "<=", 0)) >= 0)
303                         {
304                                 k = substring(s, 0, o);
305                                 v = substring(s, o+2, -1);
306                                 if(cvar(k) > stof(v))
307                                         goto cvar_fail;
308                         }
309                         else if((o = strstrofs(s, ">", 0)) >= 0)
310                         {
311                                 k = substring(s, 0, o);
312                                 v = substring(s, o+1, -1);
313                                 if(cvar(k) <= stof(v))
314                                         goto cvar_fail;
315                         }
316                         else if((o = strstrofs(s, "<", 0)) >= 0)
317                         {
318                                 k = substring(s, 0, o);
319                                 v = substring(s, o+1, -1);
320                                 if(cvar(k) >= stof(v))
321                                         goto cvar_fail;
322                         }
323                         else if((o = strstrofs(s, "==", 0)) >= 0)
324                         {
325                                 k = substring(s, 0, o);
326                                 v = substring(s, o+2, -1);
327                                 if(cvar(k) != stof(v))
328                                         goto cvar_fail;
329                         }
330                         else if((o = strstrofs(s, "!=", 0)) >= 0)
331                         {
332                                 k = substring(s, 0, o);
333                                 v = substring(s, o+2, -1);
334                                 if(cvar(k) == stof(v))
335                                         goto cvar_fail;
336                         }
337                         else if((o = strstrofs(s, "===", 0)) >= 0)
338                         {
339                                 k = substring(s, 0, o);
340                                 v = substring(s, o+2, -1);
341                                 if(cvar_string(k) != v)
342                                         goto cvar_fail;
343                         }
344                         else if((o = strstrofs(s, "!==", 0)) >= 0)
345                         {
346                                 k = substring(s, 0, o);
347                                 v = substring(s, o+2, -1);
348                                 if(cvar_string(k) == v)
349                                         goto cvar_fail;
350                         }
351                         else if(substring(s, 0, 1) == "!")
352                         {
353                                 k = substring(s, 1, -1);
354                                 if(cvar(k))
355                                         goto cvar_fail;
356                         }
357                         else
358                         {
359                                 k = s;
360                                 if not(cvar(k))
361                                         goto cvar_fail;
362                         }
363                 }
364                 inv = !inv;
365 :cvar_fail
366                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
367                 if not(inv)
368                 {
369                         //print("cvarfilter fail\n");
370                         remove(self);
371                         return;
372                 }
373         }
374
375         if(DoesQ3ARemoveThisEntity())
376         {
377                 remove(self);
378                 return;
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 }
408
409 void WarpZone_PostInitialize_Callback(void)
410 {
411         // create waypoint links for warpzones
412         entity e;
413         for(e = world; (e = find(e, classname, "trigger_warpzone")); )
414         {
415                 vector src, dst;
416                 src = (e.absmin + e.absmax) * 0.5;
417                 makevectors(e.warpzone_angles);
418                 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
419                 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
420                 makevectors(e.enemy.warpzone_angles);
421                 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
422                 waypoint_spawnforteleporter_v(e, src, dst, 0);
423         }
424 }