]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/sv_main.qc
Merge branch 'master' into divVerent/csqcmodel
[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         remove = remove_unsafely; // not during spawning!
155         serverprevtime = servertime;
156         servertime = time;
157         serverframetime = frametime;
158
159 #ifdef PROFILING
160         if(time > client_cefc_accumulatortime + 1)
161         {
162                 float t, pp, c_seeing, c_seen;
163                 entity cl;
164                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
165                 print("CEFC time: ", ftos(t * 1000), "ms; ");
166                 c_seeing = 0;
167                 c_seen = 0;
168                 FOR_EACH_CLIENT(cl)
169                 {
170                         if(clienttype(cl) == CLIENTTYPE_REAL)
171                                 ++c_seeing;
172                         if(cl.classname == "player")
173                                 ++c_seen;
174                 }
175                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
176                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
177
178                 client_cefc_accumulatortime = time;
179                 client_cefc_accumulator = 0;
180         }
181 #endif
182
183         entity e;
184         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
185                 CSQCProjectile_Check(e);
186
187         if(RedirectionThink())
188                 return;
189
190         UncustomizeEntitiesRun();
191         InitializeEntitiesRun();
192
193         WarpZone_StartFrame();
194
195         sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
196         if(sys_frametime <= 0)
197                 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
198
199         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)
200                 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
201
202         skill = autocvar_skill;
203
204         Spawnqueue_Check();
205
206
207         // detect when the pre-game countdown (if any) has ended and the game has started
208         game_delay = (time < game_starttime) ? TRUE : FALSE;
209
210         if(game_delay_last == TRUE)
211         if(game_delay == FALSE)
212         if(autocvar_sv_eventlog)
213                         GameLogEcho(":startdelay_ended");
214
215         game_delay_last = game_delay;
216
217         // if in warmup stage and limit for warmup is hit start match
218         if (inWarmupStage)
219         if ((g_warmup_limit > 0 && time >= g_warmup_limit)
220          || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
221         {
222                 ReadyRestart();
223                 return;
224         }
225
226         CreatureFrame ();
227         CheckRules_World ();
228
229         AuditTeams();
230
231         RuneMatchGivePoints();
232         bot_serverframe();
233
234         FOR_EACH_PLAYER(self)
235                 self.porto_forbidden = max(0, self.porto_forbidden - 1);
236 }
237
238 .vector originjitter;
239 .vector anglesjitter;
240 .float anglejitter;
241 .string gametypefilter;
242 .string cvarfilter;
243 float DoesQ3ARemoveThisEntity();
244 void SV_OnEntityPreSpawnFunction()
245 {
246         if(self.gametypefilter != "")
247         if not(isGametypeInFilter(game, teamplay, have_team_spawns, self.gametypefilter))
248         {
249                 remove(self);
250                 return;
251         }
252         if(self.cvarfilter != "")
253         {
254                 float n, i, o, inv;
255                 string s, k, v;
256                 inv = 0;
257
258                 s = self.cvarfilter;
259                 if(substring(s, 0, 1) == "+")
260                 {
261                         s = substring(s, 1, -1);
262                 }
263                 else if(substring(s, 0, 1) == "-")
264                 {
265                         inv = 1;
266                         s = substring(s, 1, -1);
267                 }
268
269                 n = tokenize_console(s);
270                 for(i = 0; i < n; ++i)
271                 {
272                         s = argv(i);
273                         // syntax:
274                         // var>x
275                         // var<x
276                         // var>=x
277                         // var<=x
278                         // var==x
279                         // var!=x
280                         // var===x
281                         // var!==x
282                         if((o = strstrofs(s, ">=", 0)) >= 0)
283                         {
284                                 k = substring(s, 0, o);
285                                 v = substring(s, o+2, -1);
286                                 if(cvar(k) < stof(v))
287                                         goto cvar_fail;
288                         }
289                         else if((o = strstrofs(s, "<=", 0)) >= 0)
290                         {
291                                 k = substring(s, 0, o);
292                                 v = substring(s, o+2, -1);
293                                 if(cvar(k) > stof(v))
294                                         goto cvar_fail;
295                         }
296                         else if((o = strstrofs(s, ">", 0)) >= 0)
297                         {
298                                 k = substring(s, 0, o);
299                                 v = substring(s, o+1, -1);
300                                 if(cvar(k) <= stof(v))
301                                         goto cvar_fail;
302                         }
303                         else if((o = strstrofs(s, "<", 0)) >= 0)
304                         {
305                                 k = substring(s, 0, o);
306                                 v = substring(s, o+1, -1);
307                                 if(cvar(k) >= stof(v))
308                                         goto cvar_fail;
309                         }
310                         else if((o = strstrofs(s, "==", 0)) >= 0)
311                         {
312                                 k = substring(s, 0, o);
313                                 v = substring(s, o+2, -1);
314                                 if(cvar(k) != stof(v))
315                                         goto cvar_fail;
316                         }
317                         else if((o = strstrofs(s, "!=", 0)) >= 0)
318                         {
319                                 k = substring(s, 0, o);
320                                 v = substring(s, o+2, -1);
321                                 if(cvar(k) == stof(v))
322                                         goto cvar_fail;
323                         }
324                         else if((o = strstrofs(s, "===", 0)) >= 0)
325                         {
326                                 k = substring(s, 0, o);
327                                 v = substring(s, o+2, -1);
328                                 if(cvar_string(k) != v)
329                                         goto cvar_fail;
330                         }
331                         else if((o = strstrofs(s, "!==", 0)) >= 0)
332                         {
333                                 k = substring(s, 0, o);
334                                 v = substring(s, o+2, -1);
335                                 if(cvar_string(k) == v)
336                                         goto cvar_fail;
337                         }
338                         else if(substring(s, 0, 1) == "!")
339                         {
340                                 k = substring(s, 1, -1);
341                                 if(cvar(k))
342                                         goto cvar_fail;
343                         }
344                         else
345                         {
346                                 k = s;
347                                 if not(cvar(k))
348                                         goto cvar_fail;
349                         }
350                 }
351                 inv = !inv;
352 :cvar_fail
353                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
354                 if not(inv)
355                 {
356                         //print("cvarfilter fail\n");
357                         remove(self);
358                         return;
359                 }
360         }
361
362         if(DoesQ3ARemoveThisEntity())
363         {
364                 remove(self);
365                 return;
366         }
367
368         // support special -1 and -2 angle from radiant
369         if (self.angles == '0 -1 0')
370                 self.angles = '-90 0 0';
371         else if (self.angles == '0 -2 0')
372                 self.angles = '+90 0 0';
373
374         if(self.originjitter_x != 0)
375                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;
376         if(self.originjitter_y != 0)
377                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;
378         if(self.originjitter_z != 0)
379                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;
380         if(self.anglesjitter_x != 0)
381                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;
382         if(self.anglesjitter_y != 0)
383                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;
384         if(self.anglesjitter_z != 0)
385                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;
386         if(self.anglejitter != 0)
387                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;
388
389         if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
390         {
391                 remove(self);
392                 return;
393         }
394 }
395
396 void WarpZone_PostInitialize_Callback(void)
397 {
398         // create waypoint links for warpzones
399         entity e;
400         for(e = world; (e = find(e, classname, "trigger_warpzone")); )
401         {
402                 vector src, dst;
403                 src = (e.absmin + e.absmax) * 0.5;
404                 makevectors(e.warpzone_angles);
405                 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
406                 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
407                 makevectors(e.enemy.warpzone_angles);
408                 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
409                 waypoint_spawnforteleporter_v(e, src, dst, 0);
410         }
411 }