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"
31 void CreatureFrame_drowning(entity this)
33 if(!IS_VEHICLE(this) && !(this.flags & FL_PROJECTILE) && !IS_MONSTER(this)) // vehicles, monsters and projectiles don't drown
35 if (this.waterlevel != WATERLEVEL_SUBMERGED)
37 if(this.air_finished < time)
38 PlayerSound(this, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
39 this.air_finished = time + autocvar_g_balance_contents_drowndelay;
42 else if (this.air_finished < time)
45 if (this.pain_finished < time)
47 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
48 this.pain_finished = time + 0.5;
54 void CreatureFrame_hotliquids(entity this)
56 if (this.dmgtime < time)
58 this.dmgtime = time + autocvar_g_balance_contents_damagerate;
60 if (this.flags & FL_PROJECTILE)
62 if (this.watertype == CONTENT_LAVA)
63 Damage (this, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_LAVA.m_id, this.origin, '0 0 0');
64 else if (this.watertype == CONTENT_SLIME)
65 Damage (this, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_SLIME.m_id, this.origin, '0 0 0');
69 if (this.watertype == CONTENT_LAVA)
71 if (this.watersound_finished < time)
73 this.watersound_finished = time + 0.5;
74 sound (this, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
76 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_LAVA.m_id, this.origin, '0 0 0');
77 if(autocvar_g_balance_contents_playerdamage_lava_burn)
78 Fire_AddDamage(this, world, autocvar_g_balance_contents_playerdamage_lava_burn * this.waterlevel, autocvar_g_balance_contents_playerdamage_lava_burn_time * this.waterlevel, DEATH_LAVA.m_id);
80 else if (this.watertype == CONTENT_SLIME)
82 if (this.watersound_finished < time)
84 this.watersound_finished = time + 0.5;
85 sound (this, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
87 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_SLIME.m_id, this.origin, '0 0 0');
93 void CreatureFrame_Liquids(entity this)
95 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)
97 if (!(this.flags & FL_INWATER))
99 this.flags |= FL_INWATER;
103 CreatureFrame_drowning(this);
105 CreatureFrame_hotliquids(this);
109 if (this.flags & FL_INWATER)
111 // play leave water sound
112 this.flags &= ~FL_INWATER;
115 this.air_finished = time + 12;
120 void CreatureFrame_FallDamage(entity this)
122 if(!IS_VEHICLE(this) && !(this.flags & FL_PROJECTILE)) // vehicles don't get falling damage
124 // check for falling damage
125 float velocity_len = vlen(this.velocity);
128 float dm = vlen(this.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
130 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
132 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
134 Damage (this, world, world, dm, DEATH_FALL.m_id, this.origin, '0 0 0');
137 if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
138 Damage (this, world, world, 100000, DEATH_SHOOTING_STAR.m_id, this.origin, '0 0 0');
142 void CreatureFrame_Footsteps(entity this)
144 // play stupid sounds
145 if (g_footsteps && !gameover && (this.flags & FL_ONGROUND))
146 if (!IS_VEHICLE(this) && !(this.flags & FL_PROJECTILE))
147 if (!this.crouch && (vlen(this.velocity) > autocvar_sv_maxspeed * 0.6) && !this.deadflag && time < this.lastground + 0.2)
149 if((time > this.nextstep) || (time < (this.nextstep - 10.0)))
151 this.nextstep = time + 0.3 + random() * 0.1;
152 trace_dphitq3surfaceflags = 0;
153 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
155 if(trace_fraction == 1)
158 dprint(ftos(trace_dphitq3surfaceflags), "\n");
160 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
162 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
163 GlobalSound(this, GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND);
165 GlobalSound(this, GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND);
171 void CreatureFrame_All()
173 for(entity e = world; (e = findfloat(e, damagedbycontents, true)); )
175 if (e.movetype == MOVETYPE_NOCLIP) { continue; }
177 CreatureFrame_Liquids(e);
178 CreatureFrame_FallDamage(e);
179 CreatureFrame_Footsteps(e);
181 e.oldvelocity = e.velocity;
190 Called before each frame by the server
195 float game_delay_last;
197 float RedirectionThink();
201 execute_next_frame();
203 remove = remove_unsafely; // not during spawning!
204 serverprevtime = servertime;
206 serverframetime = frametime;
209 if(time > client_cefc_accumulatortime + 1)
211 float t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
212 LOG_INFO("CEFC time: ", ftos(t * 1000), "ms; ");
218 if(IS_REAL_CLIENT(cl))
223 LOG_INFO("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
224 LOG_INFO("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
226 client_cefc_accumulatortime = time;
227 client_cefc_accumulator = 0;
231 for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
232 CSQCProjectile_Check(e);
234 if(RedirectionThink())
237 UncustomizeEntitiesRun();
238 InitializeEntitiesRun();
240 WarpZone_StartFrame();
242 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
243 if(sys_frametime <= 0)
244 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
246 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
247 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
249 skill = autocvar_skill;
251 // detect when the pre-game countdown (if any) has ended and the game has started
252 game_delay = (time < game_starttime);
254 if(autocvar_sv_eventlog && game_delay_last && !game_delay)
255 GameLogEcho(":startdelay_ended");
257 game_delay_last = game_delay;
262 // if in warmup stage and limit for warmup is hit start match
265 if((g_warmup_limit > 0 && time >= g_warmup_limit)
266 || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
273 anticheat_startframe();
274 MUTATOR_CALLHOOK(SV_StartFrame);
279 GlobalStats_update(e);
284 .vector originjitter;
285 .vector anglesjitter;
287 .string gametypefilter;
289 float DoesQ3ARemoveThisEntity();
290 void SV_OnEntityPreSpawnFunction()
293 if (self.gametypefilter != "")
294 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
299 if(self.cvarfilter != "")
306 if(substring(s, 0, 1) == "+")
308 s = substring(s, 1, -1);
310 else if(substring(s, 0, 1) == "-")
313 s = substring(s, 1, -1);
316 n = tokenize_console(s);
317 for(i = 0; i < n; ++i)
329 if((o = strstrofs(s, ">=", 0)) >= 0)
331 k = substring(s, 0, o);
332 v = substring(s, o+2, -1);
333 if(cvar(k) < stof(v))
336 else if((o = strstrofs(s, "<=", 0)) >= 0)
338 k = substring(s, 0, o);
339 v = substring(s, o+2, -1);
340 if(cvar(k) > stof(v))
343 else if((o = strstrofs(s, ">", 0)) >= 0)
345 k = substring(s, 0, o);
346 v = substring(s, o+1, -1);
347 if(cvar(k) <= stof(v))
350 else if((o = strstrofs(s, "<", 0)) >= 0)
352 k = substring(s, 0, o);
353 v = substring(s, o+1, -1);
354 if(cvar(k) >= stof(v))
357 else if((o = strstrofs(s, "==", 0)) >= 0)
359 k = substring(s, 0, o);
360 v = substring(s, o+2, -1);
361 if(cvar(k) != stof(v))
364 else if((o = strstrofs(s, "!=", 0)) >= 0)
366 k = substring(s, 0, o);
367 v = substring(s, o+2, -1);
368 if(cvar(k) == stof(v))
371 else if((o = strstrofs(s, "===", 0)) >= 0)
373 k = substring(s, 0, o);
374 v = substring(s, o+2, -1);
375 if(cvar_string(k) != v)
378 else if((o = strstrofs(s, "!==", 0)) >= 0)
380 k = substring(s, 0, o);
381 v = substring(s, o+2, -1);
382 if(cvar_string(k) == v)
385 else if(substring(s, 0, 1) == "!")
387 k = substring(s, 1, -1);
400 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
403 //print("cvarfilter fail\n");
409 if(DoesQ3ARemoveThisEntity())
415 // support special -1 and -2 angle from radiant
416 if (self.angles == '0 -1 0')
417 self.angles = '-90 0 0';
418 else if (self.angles == '0 -2 0')
419 self.angles = '+90 0 0';
421 if(self.originjitter.x != 0)
422 self.origin_x = self.origin.x + (random() * 2 - 1) * self.originjitter.x;
423 if(self.originjitter.y != 0)
424 self.origin_y = self.origin.y + (random() * 2 - 1) * self.originjitter.y;
425 if(self.originjitter.z != 0)
426 self.origin_z = self.origin.z + (random() * 2 - 1) * self.originjitter.z;
427 if(self.anglesjitter.x != 0)
428 self.angles_x = self.angles.x + (random() * 2 - 1) * self.anglesjitter.x;
429 if(self.anglesjitter.y != 0)
430 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglesjitter.y;
431 if(self.anglesjitter.z != 0)
432 self.angles_z = self.angles.z + (random() * 2 - 1) * self.anglesjitter.z;
433 if(self.anglejitter != 0)
434 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglejitter;
436 if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
443 void WarpZone_PostInitialize_Callback()
445 // create waypoint links for warpzones
447 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
450 src = (e.absmin + e.absmax) * 0.5;
451 makevectors(e.warpzone_angles);
452 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
453 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
454 makevectors(e.enemy.warpzone_angles);
455 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
456 waypoint_spawnforteleporter_v(e, src, dst, 0);