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