3 #include "anticheat.qh"
10 #include "command/common.qh"
12 #include <server/mutators/_mod.qh>
13 #include "weapons/csqcprojectile.qh"
14 #include <server/compat/quake3.qh>
16 #include "../common/constants.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/debug.qh"
19 #include "../common/mapinfo.qh"
20 #include "../common/util.qh"
22 #include "../common/vehicles/all.qh"
23 #include <common/monsters/sv_monsters.qh>
24 #include <common/weapons/_all.qh>
26 #include "../lib/csqcmodel/sv_model.qh"
28 #include "../lib/warpzone/common.qh"
29 #include "../lib/warpzone/server.qh"
31 void CreatureFrame_hotliquids(entity this)
33 if (this.dmgtime >= time)
38 this.dmgtime = time + autocvar_g_balance_contents_damagerate;
40 if (this.flags & FL_PROJECTILE)
42 if (this.watertype == CONTENT_LAVA)
43 Damage (this, NULL, NULL, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
44 else if (this.watertype == CONTENT_SLIME)
45 Damage (this, NULL, NULL, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
49 if (STAT(FROZEN, this))
51 if (this.watertype == CONTENT_LAVA)
52 Damage(this, NULL, NULL, 10000, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
53 else if (this.watertype == CONTENT_SLIME)
54 Damage(this, NULL, NULL, 10000, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
56 else if (this.watertype == CONTENT_LAVA)
58 if (this.watersound_finished < time)
60 this.watersound_finished = time + 0.5;
61 sound (this, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
63 Damage (this, NULL, NULL, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
64 if(autocvar_g_balance_contents_playerdamage_lava_burn)
65 Fire_AddDamage(this, NULL, autocvar_g_balance_contents_playerdamage_lava_burn * this.waterlevel, autocvar_g_balance_contents_playerdamage_lava_burn_time * this.waterlevel, DEATH_LAVA.m_id);
67 else if (this.watertype == CONTENT_SLIME)
69 if (this.watersound_finished < time)
71 this.watersound_finished = time + 0.5;
72 sound (this, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
74 Damage (this, NULL, NULL, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
79 void CreatureFrame_Liquids(entity this)
81 if (this.watertype <= CONTENT_WATER && this.waterlevel > 0) // workaround a retarded bug made by id software :P (yes, it's that old of a bug)
83 if (!(this.flags & FL_INWATER))
85 this.flags |= FL_INWATER;
89 CreatureFrame_hotliquids(this);
93 if (this.flags & FL_INWATER)
95 // play leave water sound
96 this.flags &= ~FL_INWATER;
102 void CreatureFrame_FallDamage(entity this)
104 if(IS_VEHICLE(this) || (this.flags & FL_PROJECTILE))
105 return; // vehicles and projectiles don't receive fall damage
106 if(!(this.velocity || this.oldvelocity))
107 return; // if the entity hasn't moved and isn't moving, then don't do anything
109 // check for falling damage
110 bool have_hook = false;
111 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
113 .entity weaponentity = weaponentities[slot];
114 if(this.(weaponentity).hook && this.(weaponentity).hook.state)
122 float dm; // dm is the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
123 if(autocvar_g_balance_falldamage_onlyvertical)
124 dm = fabs(this.oldvelocity.z) - vlen(this.velocity);
126 dm = vlen(this.oldvelocity) - vlen(this.velocity);
128 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
130 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
133 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
134 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODAMAGE))
135 Damage (this, NULL, NULL, dm, DEATH_FALL.m_id, DMG_NOWEP, this.origin, '0 0 0');
139 if(autocvar_g_maxspeed > 0 && vdist(this.velocity, >, autocvar_g_maxspeed))
140 Damage (this, NULL, NULL, 100000, DEATH_SHOOTING_STAR.m_id, DMG_NOWEP, this.origin, '0 0 0');
143 void CreatureFrame_All()
145 if(game_stopped || time < game_starttime)
148 IL_EACH(g_damagedbycontents, it.damagedbycontents,
150 if (it.move_movetype == MOVETYPE_NOCLIP) continue;
151 CreatureFrame_Liquids(it);
152 CreatureFrame_FallDamage(it);
153 it.oldvelocity = it.velocity;
157 void Pause_TryPause(bool ispaused)
160 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
161 if (PHYS_INPUT_BUTTON_CHAT(it) != ispaused) return;
168 void SV_PausedTic(float elapsedtime)
170 if (!server_is_dedicated) Pause_TryPause(false);
177 Called before each frame by the server
181 bool game_delay_last;
183 bool autocvar_sv_autopause = false;
184 void systems_update();
185 void sys_phys_update(entity this, float dt);
188 // TODO: if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction)
189 IL_EACH(g_players, IS_FAKE_CLIENT(it), sys_phys_update(it, frametime));
190 IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPreThink(it));
192 execute_next_frame();
193 if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(true);
195 delete_fn = 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);
206 FOREACH_CLIENT(true, {
207 if(IS_REAL_CLIENT(it))
213 "CEFC time: ", ftos(t * 1000), "ms; ",
214 "CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ",
215 "CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0')
217 client_cefc_accumulatortime = time;
218 client_cefc_accumulator = 0;
222 IL_EACH(g_projectiles, it.csqcprojectile_clientanimate, CSQCProjectile_Check(it));
224 if (RedirectionThink()) return;
226 UncustomizeEntitiesRun();
227 InitializeEntitiesRun();
229 WarpZone_StartFrame();
231 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
232 if (sys_frametime <= 0) sys_frametime = 1.0 / 60.0; // somewhat safe fallback
234 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
235 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
237 // detect when the pre-game countdown (if any) has ended and the game has started
238 bool game_delay = (time < game_starttime);
239 if (autocvar_sv_eventlog && game_delay_last && !game_delay)
240 GameLogEcho(":startdelay_ended");
241 game_delay_last = game_delay;
246 if (warmup_stage && !game_stopped && warmup_limit > 0 && time >= warmup_limit) {
252 anticheat_startframe();
253 MUTATOR_CALLHOOK(SV_StartFrame);
255 GlobalStats_updateglobal();
256 FOREACH_CLIENT(true, GlobalStats_update(it));
257 IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPostThink(it));
260 .vector originjitter;
261 .vector anglesjitter;
263 .string gametypefilter;
267 * Evaluate an expression of the form: [+ | -]? [var[op]val | [op]var | val | var] ...
268 * +: all must match. this is the default
269 * -: one must NOT match
280 bool expr_evaluate(string s)
283 if (str2chr(s, 0) == '+') {
284 s = substring(s, 1, -1);
285 } else if (str2chr(s, 0) == '-') {
287 s = substring(s, 1, -1);
289 bool expr_fail = false;
290 for (int i = 0, n = tokenize_console(s); i < n; ++i) {
300 #define BINOP(op, len, expr) \
301 if ((o = strstrofs(s, op, 0)) >= 0) { \
302 k = substring(s, 0, o); \
303 v = substring(s, o + len, -1); \
306 BINOP(">=", 2, cvar(k) >= stof(v));
307 BINOP("<=", 2, cvar(k) <= stof(v));
308 BINOP(">", 1, cvar(k) > stof(v));
309 BINOP("<", 1, cvar(k) < stof(v));
310 BINOP("==", 2, cvar(k) == stof(v));
311 BINOP("!=", 2, cvar(k) != stof(v));
312 BINOP("===", 3, cvar_string(k) == v);
313 BINOP("!==", 3, cvar_string(k) != v);
317 if (str2chr(k, 0) == '!') {
318 k = substring(s, 1, -1);
322 bool isnum = ftos(f) == k;
323 X(boolean(isnum ? f : cvar(k)) == b);
331 // now ret is true if we want to keep the item, and false if we want to get rid of it
335 void SV_OnEntityPreSpawnFunction(entity this)
338 if (this.gametypefilter != "")
339 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, this.gametypefilter))
344 if (this.cvarfilter != "" && !expr_evaluate(this.cvarfilter)) {
349 if (DoesQ3ARemoveThisEntity(this)) {
354 set_movetype(this, this.movetype);
356 if (this.monster_attack) {
357 IL_PUSH(g_monster_targets, this);
360 // support special -1 and -2 angle from radiant
361 if (this.angles == '0 -1 0') {
362 this.angles = '-90 0 0';
363 } else if (this.angles == '0 -2 0') {
364 this.angles = '+90 0 0';
367 #define X(out, in) MACRO_BEGIN \
368 if (in != 0) { out = out + (random() * 2 - 1) * in; } \
370 X(this.origin.x, this.originjitter.x); X(this.origin.y, this.originjitter.y); X(this.origin.z, this.originjitter.z);
371 X(this.angles.x, this.anglesjitter.x); X(this.angles.y, this.anglesjitter.y); X(this.angles.z, this.anglesjitter.z);
372 X(this.angles.y, this.anglejitter);
375 if (MUTATOR_CALLHOOK(OnEntityPreSpawn, this)) {
381 void WarpZone_PostInitialize_Callback()
383 // create waypoint links for warpzones
384 entity tracetest_ent = spawn();
385 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
386 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
387 //for(entity e = warpzone_first; e; e = e.warpzone_next)
388 for(entity e = NULL; (e = find(e, classname, "trigger_warpzone")); )
389 waypoint_spawnforteleporter_wz(e, tracetest_ent);
390 delete(tracetest_ent);
397 unused but required by the engine