3 #include "anticheat.qh"
7 #include "command/common.qh"
9 #include "mutators/mutators_include.qh"
10 #include "weapons/csqcprojectile.qh"
12 #include "../common/constants.qh"
13 #include "../common/deathtypes.qh"
14 #include "../common/mapinfo.qh"
15 #include "../common/util.qh"
17 #include "../common/vehicles/all.qh"
18 #include "../common/weapons/all.qh"
20 #include "../csqcmodellib/sv_model.qh"
22 #include "../warpzonelib/common.qh"
23 #include "../warpzonelib/server.qh"
27 void CreatureFrame (void)
31 for(entity e = world; (e = findfloat(e, damagedbycontents, true)); )
34 if (self.movetype == MOVETYPE_NOCLIP) { continue; }
36 float vehic = IS_VEHICLE(self);
37 float projectile = (self.flags & FL_PROJECTILE);
38 float monster = IS_MONSTER(self);
40 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)
42 if (!(self.flags & FL_INWATER))
44 self.flags |= FL_INWATER;
48 if(!vehic && !projectile && !monster) // vehicles, monsters and projectiles don't drown
50 if (self.waterlevel != WATERLEVEL_SUBMERGED)
52 if(self.air_finished < time)
53 PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
54 self.air_finished = time + autocvar_g_balance_contents_drowndelay;
57 else if (self.air_finished < time)
60 if (self.pain_finished < time)
62 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN, self.origin, '0 0 0');
63 self.pain_finished = time + 0.5;
68 if (self.dmgtime < time)
70 self.dmgtime = time + autocvar_g_balance_contents_damagerate;
74 if (self.watertype == CONTENT_LAVA)
76 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
78 else if (self.watertype == CONTENT_SLIME)
80 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
85 if (self.watertype == CONTENT_LAVA)
87 if (self.watersound_finished < time)
89 self.watersound_finished = time + 0.5;
90 sound (self, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
92 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
94 else if (self.watertype == CONTENT_SLIME)
96 if (self.watersound_finished < time)
98 self.watersound_finished = time + 0.5;
99 sound (self, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
101 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
108 if (self.flags & FL_INWATER)
110 // play leave water sound
111 self.flags &= ~FL_INWATER;
114 self.air_finished = time + 12;
118 if(!vehic && !projectile) // vehicles don't get falling damage
120 // check for falling damage
121 float velocity_len = vlen(self.velocity);
124 dm = vlen(self.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
126 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
128 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
130 Damage (self, world, world, dm, DEATH_FALL, self.origin, '0 0 0');
133 if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
134 Damage (self, world, world, 100000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');
135 // play stupid sounds
138 if (self.flags & FL_ONGROUND)
140 if (velocity_len > autocvar_sv_maxspeed * 0.6)
142 if (time < self.lastground + 0.2)
144 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
146 self.nextstep = time + 0.3 + random() * 0.1;
147 trace_dphitq3surfaceflags = 0;
148 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
150 if(trace_fraction == 1)
153 dprint(ftos(trace_dphitq3surfaceflags), "\n");
155 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
157 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
158 GlobalSound(globalsound_metalstep, CH_PLAYER, VOICETYPE_PLAYERSOUND);
160 GlobalSound(globalsound_step, CH_PLAYER, VOICETYPE_PLAYERSOUND);
166 self.oldvelocity = self.velocity;
176 Called before each frame by the server
181 float game_delay_last;
183 float RedirectionThink();
184 void StartFrame (void)
186 execute_next_frame();
188 remove = remove_unsafely; // not during spawning!
189 serverprevtime = servertime;
191 serverframetime = frametime;
194 if(time > client_cefc_accumulatortime + 1)
196 float t, pp, c_seeing, c_seen;
198 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
199 LOG_INFO("CEFC time: ", ftos(t * 1000), "ms; ");
204 if(IS_REAL_CLIENT(cl))
209 LOG_INFO("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
210 LOG_INFO("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
212 client_cefc_accumulatortime = time;
213 client_cefc_accumulator = 0;
217 for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
218 CSQCProjectile_Check(e);
220 if(RedirectionThink())
223 UncustomizeEntitiesRun();
224 InitializeEntitiesRun();
226 WarpZone_StartFrame();
228 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
229 if(sys_frametime <= 0)
230 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
232 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
233 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
235 skill = autocvar_skill;
237 // detect when the pre-game countdown (if any) has ended and the game has started
238 game_delay = (time < game_starttime) ? true : false;
240 if(game_delay_last == true)
241 if(game_delay == false)
242 if(autocvar_sv_eventlog)
243 GameLogEcho(":startdelay_ended");
245 game_delay_last = game_delay;
250 // if in warmup stage and limit for warmup is hit start match
253 if((g_warmup_limit > 0 && time >= g_warmup_limit)
254 || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
264 e.porto_forbidden = max(0, e.porto_forbidden - 1);
266 anticheat_startframe();
268 MUTATOR_CALLHOOK(SV_StartFrame);
271 .vector originjitter;
272 .vector anglesjitter;
274 .string gametypefilter;
276 float DoesQ3ARemoveThisEntity();
277 void SV_OnEntityPreSpawnFunction()
280 if (self.gametypefilter != "")
281 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
286 if(self.cvarfilter != "")
293 if(substring(s, 0, 1) == "+")
295 s = substring(s, 1, -1);
297 else if(substring(s, 0, 1) == "-")
300 s = substring(s, 1, -1);
303 n = tokenize_console(s);
304 for(i = 0; i < n; ++i)
316 if((o = strstrofs(s, ">=", 0)) >= 0)
318 k = substring(s, 0, o);
319 v = substring(s, o+2, -1);
320 if(cvar(k) < stof(v))
323 else if((o = strstrofs(s, "<=", 0)) >= 0)
325 k = substring(s, 0, o);
326 v = substring(s, o+2, -1);
327 if(cvar(k) > stof(v))
330 else if((o = strstrofs(s, ">", 0)) >= 0)
332 k = substring(s, 0, o);
333 v = substring(s, o+1, -1);
334 if(cvar(k) <= stof(v))
337 else if((o = strstrofs(s, "<", 0)) >= 0)
339 k = substring(s, 0, o);
340 v = substring(s, o+1, -1);
341 if(cvar(k) >= stof(v))
344 else if((o = strstrofs(s, "==", 0)) >= 0)
346 k = substring(s, 0, o);
347 v = substring(s, o+2, -1);
348 if(cvar(k) != stof(v))
351 else if((o = strstrofs(s, "!=", 0)) >= 0)
353 k = substring(s, 0, o);
354 v = substring(s, o+2, -1);
355 if(cvar(k) == stof(v))
358 else if((o = strstrofs(s, "===", 0)) >= 0)
360 k = substring(s, 0, o);
361 v = substring(s, o+2, -1);
362 if(cvar_string(k) != v)
365 else if((o = strstrofs(s, "!==", 0)) >= 0)
367 k = substring(s, 0, o);
368 v = substring(s, o+2, -1);
369 if(cvar_string(k) == v)
372 else if(substring(s, 0, 1) == "!")
374 k = substring(s, 1, -1);
387 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
390 //print("cvarfilter fail\n");
396 if(DoesQ3ARemoveThisEntity())
402 // support special -1 and -2 angle from radiant
403 if (self.angles == '0 -1 0')
404 self.angles = '-90 0 0';
405 else if (self.angles == '0 -2 0')
406 self.angles = '+90 0 0';
408 if(self.originjitter.x != 0)
409 self.origin_x = self.origin.x + (random() * 2 - 1) * self.originjitter.x;
410 if(self.originjitter.y != 0)
411 self.origin_y = self.origin.y + (random() * 2 - 1) * self.originjitter.y;
412 if(self.originjitter.z != 0)
413 self.origin_z = self.origin.z + (random() * 2 - 1) * self.originjitter.z;
414 if(self.anglesjitter.x != 0)
415 self.angles_x = self.angles.x + (random() * 2 - 1) * self.anglesjitter.x;
416 if(self.anglesjitter.y != 0)
417 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglesjitter.y;
418 if(self.anglesjitter.z != 0)
419 self.angles_z = self.angles.z + (random() * 2 - 1) * self.anglesjitter.z;
420 if(self.anglejitter != 0)
421 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglejitter;
423 if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
430 void WarpZone_PostInitialize_Callback(void)
432 // create waypoint links for warpzones
434 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
437 src = (e.absmin + e.absmax) * 0.5;
438 makevectors(e.warpzone_angles);
439 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
440 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
441 makevectors(e.enemy.warpzone_angles);
442 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
443 waypoint_spawnforteleporter_v(e, src, dst, 0);