2 #include "anticheat.qh"
7 #include "bot/waypoints.qh"
9 #include "command/common.qh"
11 #include "mutators/all.qh"
12 #include "weapons/csqcprojectile.qh"
14 #include "../common/constants.qh"
15 #include "../common/deathtypes/all.qh"
16 #include "../common/debug.qh"
17 #include "../common/mapinfo.qh"
18 #include "../common/util.qh"
20 #include "../common/vehicles/all.qh"
21 #include "../common/weapons/all.qh"
23 #include "../lib/csqcmodel/sv_model.qh"
25 #include "../lib/warpzone/common.qh"
26 #include "../lib/warpzone/server.qh"
35 for(entity e = world; (e = findfloat(e, damagedbycontents, true)); )
38 if (self.movetype == MOVETYPE_NOCLIP) { continue; }
40 float vehic = IS_VEHICLE(self);
41 float projectile = (self.flags & FL_PROJECTILE);
42 float monster = IS_MONSTER(self);
44 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)
46 if (!(self.flags & FL_INWATER))
48 self.flags |= FL_INWATER;
52 if(!vehic && !projectile && !monster) // vehicles, monsters and projectiles don't drown
54 if (self.waterlevel != WATERLEVEL_SUBMERGED)
56 if(self.air_finished < time)
57 PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
58 self.air_finished = time + autocvar_g_balance_contents_drowndelay;
61 else if (self.air_finished < time)
64 if (self.pain_finished < time)
66 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, self.origin, '0 0 0');
67 self.pain_finished = time + 0.5;
72 if (self.dmgtime < time)
74 self.dmgtime = time + autocvar_g_balance_contents_damagerate;
78 if (self.watertype == CONTENT_LAVA)
80 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA.m_id, self.origin, '0 0 0');
82 else if (self.watertype == CONTENT_SLIME)
84 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME.m_id, self.origin, '0 0 0');
89 if (self.watertype == CONTENT_LAVA)
91 if (self.watersound_finished < time)
93 self.watersound_finished = time + 0.5;
94 sound (self, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
96 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA.m_id, self.origin, '0 0 0');
97 if(autocvar_g_balance_contents_playerdamage_lava_burn)
98 Fire_AddDamage(self, world, autocvar_g_balance_contents_playerdamage_lava_burn * self.waterlevel, autocvar_g_balance_contents_playerdamage_lava_burn_time * self.waterlevel, DEATH_LAVA.m_id);
100 else if (self.watertype == CONTENT_SLIME)
102 if (self.watersound_finished < time)
104 self.watersound_finished = time + 0.5;
105 sound (self, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
107 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME.m_id, self.origin, '0 0 0');
114 if (self.flags & FL_INWATER)
116 // play leave water sound
117 self.flags &= ~FL_INWATER;
120 self.air_finished = time + 12;
124 if(!vehic && !projectile) // vehicles don't get falling damage
126 // check for falling damage
127 float velocity_len = vlen(self.velocity);
130 dm = vlen(self.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
132 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
134 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
136 Damage (self, world, world, dm, DEATH_FALL.m_id, self.origin, '0 0 0');
139 if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
140 Damage (self, world, world, 100000, DEATH_SHOOTING_STAR.m_id, self.origin, '0 0 0');
141 // play stupid sounds
144 if (self.flags & FL_ONGROUND)
146 if (velocity_len > autocvar_sv_maxspeed * 0.6)
148 if (time < self.lastground + 0.2)
150 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
152 self.nextstep = time + 0.3 + random() * 0.1;
153 trace_dphitq3surfaceflags = 0;
154 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
156 if(trace_fraction == 1)
159 dprint(ftos(trace_dphitq3surfaceflags), "\n");
161 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
163 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
164 GlobalSound(GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND);
166 GlobalSound(GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND);
172 self.oldvelocity = self.velocity;
182 Called before each frame by the server
187 float game_delay_last;
189 float RedirectionThink();
193 execute_next_frame();
195 remove = remove_unsafely; // not during spawning!
196 serverprevtime = servertime;
198 serverframetime = frametime;
201 if(time > client_cefc_accumulatortime + 1)
203 float t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
204 LOG_INFO("CEFC time: ", ftos(t * 1000), "ms; ");
210 if(IS_REAL_CLIENT(cl))
215 LOG_INFO("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
216 LOG_INFO("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
218 client_cefc_accumulatortime = time;
219 client_cefc_accumulator = 0;
223 for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
224 CSQCProjectile_Check(e);
226 if(RedirectionThink())
229 UncustomizeEntitiesRun();
230 InitializeEntitiesRun();
232 WarpZone_StartFrame();
234 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
235 if(sys_frametime <= 0)
236 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
238 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
239 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
241 skill = autocvar_skill;
243 // detect when the pre-game countdown (if any) has ended and the game has started
244 game_delay = (time < game_starttime);
246 if(autocvar_sv_eventlog && game_delay_last && !game_delay)
247 GameLogEcho(":startdelay_ended");
249 game_delay_last = game_delay;
254 // if in warmup stage and limit for warmup is hit start match
257 if((g_warmup_limit > 0 && time >= g_warmup_limit)
258 || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
265 anticheat_startframe();
266 MUTATOR_CALLHOOK(SV_StartFrame);
269 .vector originjitter;
270 .vector anglesjitter;
272 .string gametypefilter;
274 float DoesQ3ARemoveThisEntity();
275 void SV_OnEntityPreSpawnFunction()
278 if (self.gametypefilter != "")
279 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
284 if(self.cvarfilter != "")
291 if(substring(s, 0, 1) == "+")
293 s = substring(s, 1, -1);
295 else if(substring(s, 0, 1) == "-")
298 s = substring(s, 1, -1);
301 n = tokenize_console(s);
302 for(i = 0; i < n; ++i)
314 if((o = strstrofs(s, ">=", 0)) >= 0)
316 k = substring(s, 0, o);
317 v = substring(s, o+2, -1);
318 if(cvar(k) < stof(v))
321 else if((o = strstrofs(s, "<=", 0)) >= 0)
323 k = substring(s, 0, o);
324 v = substring(s, o+2, -1);
325 if(cvar(k) > stof(v))
328 else if((o = strstrofs(s, ">", 0)) >= 0)
330 k = substring(s, 0, o);
331 v = substring(s, o+1, -1);
332 if(cvar(k) <= stof(v))
335 else if((o = strstrofs(s, "<", 0)) >= 0)
337 k = substring(s, 0, o);
338 v = substring(s, o+1, -1);
339 if(cvar(k) >= stof(v))
342 else if((o = strstrofs(s, "==", 0)) >= 0)
344 k = substring(s, 0, o);
345 v = substring(s, o+2, -1);
346 if(cvar(k) != stof(v))
349 else if((o = strstrofs(s, "!=", 0)) >= 0)
351 k = substring(s, 0, o);
352 v = substring(s, o+2, -1);
353 if(cvar(k) == stof(v))
356 else if((o = strstrofs(s, "===", 0)) >= 0)
358 k = substring(s, 0, o);
359 v = substring(s, o+2, -1);
360 if(cvar_string(k) != v)
363 else if((o = strstrofs(s, "!==", 0)) >= 0)
365 k = substring(s, 0, o);
366 v = substring(s, o+2, -1);
367 if(cvar_string(k) == v)
370 else if(substring(s, 0, 1) == "!")
372 k = substring(s, 1, -1);
385 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
388 //print("cvarfilter fail\n");
394 if(DoesQ3ARemoveThisEntity())
400 // support special -1 and -2 angle from radiant
401 if (self.angles == '0 -1 0')
402 self.angles = '-90 0 0';
403 else if (self.angles == '0 -2 0')
404 self.angles = '+90 0 0';
406 if(self.originjitter.x != 0)
407 self.origin_x = self.origin.x + (random() * 2 - 1) * self.originjitter.x;
408 if(self.originjitter.y != 0)
409 self.origin_y = self.origin.y + (random() * 2 - 1) * self.originjitter.y;
410 if(self.originjitter.z != 0)
411 self.origin_z = self.origin.z + (random() * 2 - 1) * self.originjitter.z;
412 if(self.anglesjitter.x != 0)
413 self.angles_x = self.angles.x + (random() * 2 - 1) * self.anglesjitter.x;
414 if(self.anglesjitter.y != 0)
415 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglesjitter.y;
416 if(self.anglesjitter.z != 0)
417 self.angles_z = self.angles.z + (random() * 2 - 1) * self.anglesjitter.z;
418 if(self.anglejitter != 0)
419 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglejitter;
421 if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
428 void WarpZone_PostInitialize_Callback()
430 // create waypoint links for warpzones
432 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
435 src = (e.absmin + e.absmax) * 0.5;
436 makevectors(e.warpzone_angles);
437 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
438 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
439 makevectors(e.enemy.warpzone_angles);
440 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
441 waypoint_spawnforteleporter_v(e, src, dst, 0);