]> 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
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, CHAN_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, CHAN_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, CHAN_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
89                 if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
90                         Damage (self, world, world, 100000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');
91
92                 // play stupid sounds
93                 if (!vehic) // vehicles don't get footsteps
94                 if (g_footsteps)
95                 if (!gameover)
96                 if (self.flags & FL_ONGROUND)
97                 if (velocity_len > autocvar_sv_maxspeed * 0.6)
98                 if (!self.deadflag)
99                 if (time < self.lastground + 0.2)
100                 {
101                         if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
102                         {
103                                 self.nextstep = time + 0.3 + random() * 0.1;
104                                 trace_dphitq3surfaceflags = 0;
105                                 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
106                                 /*
107                                 if(trace_fraction == 1)
108                                         dprint("nohit\n");
109                                 else
110                                         dprint(ftos(trace_dphitq3surfaceflags), "\n");
111                                 */
112                                 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
113                                 {
114                                         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
115                                                 GlobalSound(globalsound_metalstep, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
116                                         else
117                                                 GlobalSound(globalsound_step, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
118                                 }
119                         }
120                 }
121                 self.oldvelocity = self.velocity;
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         sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
185         if(sys_frametime <= 0)
186                 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
187
188         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)
189                 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
190
191         skill = autocvar_skill;
192
193         Spawnqueue_Check();
194
195
196         // detect when the pre-game countdown (if any) has ended and the game has started
197         game_delay = (time < game_starttime) ? TRUE : FALSE;
198
199         if(game_delay_last == TRUE)
200         if(game_delay == FALSE)
201         if(autocvar_sv_eventlog)
202                         GameLogEcho(":startdelay_ended");
203
204         game_delay_last = game_delay;
205
206         // if in warmup stage and limit for warmup is hit start match
207         if (inWarmupStage)
208         if ((g_warmup_limit > 0 && time >= g_warmup_limit)
209          || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
210         {
211                 ReadyRestart();
212                 return;
213         }
214
215         CreatureFrame ();
216         CheckRules_World ();
217
218         AuditTeams();
219
220         RuneMatchGivePoints();
221         bot_serverframe();
222
223         if(autocvar_spawn_debugview)
224         {
225                 RandomSelection_Init();
226                 for(self = world; (self = find(self, classname, "player")); )
227                         RandomSelection_Add(self, 0, string_null, 1, 0);
228                 self = RandomSelection_chosen_ent;
229                 SelectSpawnPoint(0);
230         }
231
232         FOR_EACH_PLAYER(self)
233                 self.porto_forbidden = max(0, self.porto_forbidden - 1);
234 }
235
236 .vector originjitter;
237 .vector anglesjitter;
238 .float anglejitter;
239 .string gametypefilter;
240 .string cvarfilter;
241 float DoesQ3ARemoveThisEntity();
242 void SV_OnEntityPreSpawnFunction()
243 {
244         if(self.gametypefilter != "")
245         if not(isGametypeInFilter(game, teamplay, have_team_spawns, self.gametypefilter))
246         {
247                 remove(self);
248                 return;
249         }
250         if(self.cvarfilter != "")
251         {
252                 float n, i, o, inv;
253                 string s, k, v;
254                 inv = 0;
255
256                 s = self.cvarfilter;
257                 if(substring(s, 0, 1) == "+")
258                 {
259                         s = substring(s, 1, -1);
260                 }
261                 else if(substring(s, 0, 1) == "-")
262                 {
263                         inv = 1;
264                         s = substring(s, 1, -1);
265                 }
266
267                 n = tokenize(s);
268                 for(i = 0; i < n; ++i)
269                 {
270                         s = argv(i);
271                         // syntax:
272                         // var>x
273                         // var<x
274                         // var>=x
275                         // var<=x
276                         // var==x
277                         // var!=x
278                         // var===x
279                         // var!==x
280                         if((o = strstrofs(s, ">=", 0)) >= 0)
281                         {
282                                 k = substring(s, 0, o);
283                                 v = substring(s, o+2, -1);
284                                 if(cvar(k) < stof(v))
285                                         goto cvar_fail;
286                         }
287                         else 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+1, -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+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+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_string(k) != 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(substring(s, 0, 1) == "!")
337                         {
338                                 k = substring(s, 1, -1);
339                                 if(cvar(k))
340                                         goto cvar_fail;
341                         }
342                         else
343                         {
344                                 k = s;
345                                 if not(cvar(k))
346                                         goto cvar_fail;
347                         }
348                 }
349                 inv = !inv;
350 :cvar_fail
351                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
352                 if not(inv)
353                 {
354                         //print("cvarfilter fail\n");
355                         remove(self);
356                         return;
357                 }
358         }
359
360         if(DoesQ3ARemoveThisEntity())
361         {
362                 remove(self);
363                 return;
364         }
365
366         // support special -1 and -2 angle from radiant
367         if (self.angles == '0 -1 0')
368                 self.angles = '-90 0 0';
369         else if (self.angles == '0 -2 0')
370                 self.angles = '+90 0 0';
371
372         if(self.originjitter_x != 0)
373                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;
374         if(self.originjitter_y != 0)
375                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;
376         if(self.originjitter_z != 0)
377                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;
378         if(self.anglesjitter_x != 0)
379                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;
380         if(self.anglesjitter_y != 0)
381                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;
382         if(self.anglesjitter_z != 0)
383                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;
384         if(self.anglejitter != 0)
385                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;
386
387         if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
388         {
389                 remove(self);
390                 return;
391         }
392 }