]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/sv_main.qc
Merge branch 'master' of git://de.git.xonotic.org/xonotic/xonotic-data.pk3dir
[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                                                 if (self.watersound_finished < time)
51                                                 {
52                                                         self.watersound_finished = time + 0.5;
53                                                         sound (self, CH_PLAYER, "player/lava.wav", VOL_BASE, ATTN_NORM);
54                                                 }
55                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
56                                         }
57                                         else if (self.watertype == CONTENT_SLIME)
58                                         {
59                                                 if (self.watersound_finished < time)
60                                                 {
61                                                         self.watersound_finished = time + 0.5;
62                                                         sound (self, CH_PLAYER, "player/slime.wav", VOL_BASE, ATTN_NORM);
63                                                 }
64                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
65                                         }
66                                 }
67                                 else if ((self.watertype == CONTENT_LAVA) || (self.watertype == CONTENT_SLIME))
68                                 {
69                                         Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
70                                 }
71                         }
72                 }
73                 else
74                 {
75                         if (self.flags & FL_INWATER)
76                         {
77                                 // play leave water sound
78                                 self.flags &~= FL_INWATER;
79                                 self.dmgtime = 0;
80                         }
81                         self.air_finished = time + 12;
82                         self.dmg = 2;
83                 }
84
85                 if(!vehic && !projectile) // vehicles don't get falling damage
86                 {
87                         // check for falling damage
88                         float velocity_len = vlen(self.velocity);
89                         if(!self.hook.state && !g_ca && !(g_cts && !autocvar_g_cts_selfdamage))
90                         {
91                                 dm = vlen(self.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
92                                 if (self.deadflag)
93                                         dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
94                                 else
95                                         dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
96                                 if (dm > 0)
97                                         Damage (self, world, world, dm, DEATH_FALL, self.origin, '0 0 0');
98                         }
99
100                         if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
101                                 Damage (self, world, world, 100000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');
102                         // play stupid sounds
103                         if (g_footsteps)
104                         if (!gameover)
105                         if (self.flags & FL_ONGROUND)
106                         if (velocity_len > autocvar_sv_maxspeed * 0.6)
107                         if (!self.deadflag)
108                         if (time < self.lastground + 0.2)
109                         {
110                                 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
111                                 {
112                                         self.nextstep = time + 0.3 + random() * 0.1;
113                                         trace_dphitq3surfaceflags = 0;
114                                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
115                                         /*
116                                         if(trace_fraction == 1)
117                                                 dprint("nohit\n");
118                                         else
119                                                 dprint(ftos(trace_dphitq3surfaceflags), "\n");
120                                         */
121                                         if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
122                                         {
123                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
124                                                         GlobalSound(globalsound_metalstep, CH_PLAYER, VOICETYPE_PLAYERSOUND);
125                                                 else
126                                                         GlobalSound(globalsound_step, CH_PLAYER, VOICETYPE_PLAYERSOUND);
127                                         }
128                                 }
129                         }
130                 }
131                 
132         self.oldvelocity = self.velocity;
133         }
134         self = oldself;
135 }
136
137
138 /*
139 =============
140 StartFrame
141
142 Called before each frame by the server
143 =============
144 */
145
146 float game_delay;
147 float game_delay_last;
148
149 void RuneMatchGivePoints();
150 float RedirectionThink();
151 entity SelectSpawnPoint (float anypoint);
152 void StartFrame (void)
153 {
154         execute_next_frame();
155
156         remove = remove_unsafely; // not during spawning!
157         serverprevtime = servertime;
158         servertime = time;
159         serverframetime = frametime;
160
161 #ifdef PROFILING
162         if(time > client_cefc_accumulatortime + 1)
163         {
164                 float t, pp, c_seeing, c_seen;
165                 entity cl;
166                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
167                 print("CEFC time: ", ftos(t * 1000), "ms; ");
168                 c_seeing = 0;
169                 c_seen = 0;
170                 FOR_EACH_CLIENT(cl)
171                 {
172                         if(clienttype(cl) == CLIENTTYPE_REAL)
173                                 ++c_seeing;
174                         if(cl.classname == "player")
175                                 ++c_seen;
176                 }
177                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
178                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
179
180                 client_cefc_accumulatortime = time;
181                 client_cefc_accumulator = 0;
182         }
183 #endif
184
185         entity e;
186         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
187                 CSQCProjectile_Check(e);
188
189         if(RedirectionThink())
190                 return;
191
192         UncustomizeEntitiesRun();
193         InitializeEntitiesRun();
194
195         WarpZone_StartFrame();
196
197         sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
198         if(sys_frametime <= 0)
199                 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
200
201         if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
202                 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
203
204         skill = autocvar_skill;
205
206         Spawnqueue_Check();
207
208
209         // detect when the pre-game countdown (if any) has ended and the game has started
210         game_delay = (time < game_starttime) ? TRUE : FALSE;
211
212         if(game_delay_last == TRUE)
213         if(game_delay == FALSE)
214         if(autocvar_sv_eventlog)
215                         GameLogEcho(":startdelay_ended");
216
217         game_delay_last = game_delay;
218
219         // if in warmup stage and limit for warmup is hit start match
220         if (inWarmupStage)
221         if ((g_warmup_limit > 0 && time >= g_warmup_limit)
222          || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
223         {
224                 ReadyRestart();
225                 return;
226         }
227
228         CreatureFrame ();
229         CheckRules_World ();
230
231         AuditTeams();
232
233         RuneMatchGivePoints();
234         bot_serverframe();
235
236         FOR_EACH_PLAYER(self)
237                 self.porto_forbidden = max(0, self.porto_forbidden - 1);
238
239         MUTATOR_CALLHOOK(SV_StartFrame);
240 }
241
242 .vector originjitter;
243 .vector anglesjitter;
244 .float anglejitter;
245 .string gametypefilter;
246 .string cvarfilter;
247 float DoesQ3ARemoveThisEntity();
248 void SV_OnEntityPreSpawnFunction()
249 {
250         if (self)
251         if (self.gametypefilter != "")
252         if not(isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
253         {
254                 remove(self);
255                 return;
256         }
257         if(self.cvarfilter != "")
258         {
259                 float n, i, o, inv;
260                 string s, k, v;
261                 inv = 0;
262
263                 s = self.cvarfilter;
264                 if(substring(s, 0, 1) == "+")
265                 {
266                         s = substring(s, 1, -1);
267                 }
268                 else if(substring(s, 0, 1) == "-")
269                 {
270                         inv = 1;
271                         s = substring(s, 1, -1);
272                 }
273
274                 n = tokenize_console(s);
275                 for(i = 0; i < n; ++i)
276                 {
277                         s = argv(i);
278                         // syntax:
279                         // var>x
280                         // var<x
281                         // var>=x
282                         // var<=x
283                         // var==x
284                         // var!=x
285                         // var===x
286                         // var!==x
287                         if((o = strstrofs(s, ">=", 0)) >= 0)
288                         {
289                                 k = substring(s, 0, o);
290                                 v = substring(s, o+2, -1);
291                                 if(cvar(k) < stof(v))
292                                         goto cvar_fail;
293                         }
294                         else if((o = strstrofs(s, "<=", 0)) >= 0)
295                         {
296                                 k = substring(s, 0, o);
297                                 v = substring(s, o+2, -1);
298                                 if(cvar(k) > stof(v))
299                                         goto cvar_fail;
300                         }
301                         else if((o = strstrofs(s, ">", 0)) >= 0)
302                         {
303                                 k = substring(s, 0, o);
304                                 v = substring(s, o+1, -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+1, -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+2, -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+2, -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_string(k) != 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_string(k) == v)
341                                         goto cvar_fail;
342                         }
343                         else if(substring(s, 0, 1) == "!")
344                         {
345                                 k = substring(s, 1, -1);
346                                 if(cvar(k))
347                                         goto cvar_fail;
348                         }
349                         else
350                         {
351                                 k = s;
352                                 if not(cvar(k))
353                                         goto cvar_fail;
354                         }
355                 }
356                 inv = !inv;
357 :cvar_fail
358                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
359                 if not(inv)
360                 {
361                         //print("cvarfilter fail\n");
362                         remove(self);
363                         return;
364                 }
365         }
366
367         if(DoesQ3ARemoveThisEntity())
368         {
369                 remove(self);
370                 return;
371         }
372
373         // support special -1 and -2 angle from radiant
374         if (self.angles == '0 -1 0')
375                 self.angles = '-90 0 0';
376         else if (self.angles == '0 -2 0')
377                 self.angles = '+90 0 0';
378
379         if(self.originjitter_x != 0)
380                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;
381         if(self.originjitter_y != 0)
382                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;
383         if(self.originjitter_z != 0)
384                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;
385         if(self.anglesjitter_x != 0)
386                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;
387         if(self.anglesjitter_y != 0)
388                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;
389         if(self.anglesjitter_z != 0)
390                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;
391         if(self.anglejitter != 0)
392                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;
393
394         if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
395         {
396                 remove(self);
397                 return;
398         }
399 }
400
401 void WarpZone_PostInitialize_Callback(void)
402 {
403         // create waypoint links for warpzones
404         entity e;
405         for(e = world; (e = find(e, classname, "trigger_warpzone")); )
406         {
407                 vector src, dst;
408                 src = (e.absmin + e.absmax) * 0.5;
409                 makevectors(e.warpzone_angles);
410                 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
411                 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
412                 makevectors(e.enemy.warpzone_angles);
413                 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
414                 waypoint_spawnforteleporter_v(e, src, dst, 0);
415         }
416 }