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/mapinfo.qh"
17 #include "../common/util.qh"
19 #include "../common/vehicles/all.qh"
20 #include "../common/weapons/all.qh"
22 #include "../lib/csqcmodel/sv_model.qh"
24 #include "../lib/warpzone/common.qh"
25 #include "../lib/warpzone/server.qh"
30 void CreatureFrame (void)
34 for(entity e = world; (e = findfloat(e, damagedbycontents, true)); )
37 if (self.movetype == MOVETYPE_NOCLIP) { continue; }
39 float vehic = IS_VEHICLE(self);
40 float projectile = (self.flags & FL_PROJECTILE);
41 float monster = IS_MONSTER(self);
43 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)
45 if (!(self.flags & FL_INWATER))
47 self.flags |= FL_INWATER;
51 if(!vehic && !projectile && !monster) // vehicles, monsters and projectiles don't drown
53 if (self.waterlevel != WATERLEVEL_SUBMERGED)
55 if(self.air_finished < time)
56 PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
57 self.air_finished = time + autocvar_g_balance_contents_drowndelay;
60 else if (self.air_finished < time)
63 if (self.pain_finished < time)
65 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, self.origin, '0 0 0');
66 self.pain_finished = time + 0.5;
71 if (self.dmgtime < time)
73 self.dmgtime = time + autocvar_g_balance_contents_damagerate;
77 if (self.watertype == CONTENT_LAVA)
79 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');
81 else if (self.watertype == CONTENT_SLIME)
83 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');
88 if (self.watertype == CONTENT_LAVA)
90 if (self.watersound_finished < time)
92 self.watersound_finished = time + 0.5;
93 sound (self, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
95 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 else if (self.watertype == CONTENT_SLIME)
99 if (self.watersound_finished < time)
101 self.watersound_finished = time + 0.5;
102 sound (self, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
104 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');
111 if (self.flags & FL_INWATER)
113 // play leave water sound
114 self.flags &= ~FL_INWATER;
117 self.air_finished = time + 12;
121 if(!vehic && !projectile) // vehicles don't get falling damage
123 // check for falling damage
124 float velocity_len = vlen(self.velocity);
127 dm = vlen(self.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
129 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
131 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
133 Damage (self, world, world, dm, DEATH_FALL.m_id, self.origin, '0 0 0');
136 if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
137 Damage (self, world, world, 100000, DEATH_SHOOTING_STAR.m_id, self.origin, '0 0 0');
138 // play stupid sounds
141 if (self.flags & FL_ONGROUND)
143 if (velocity_len > autocvar_sv_maxspeed * 0.6)
145 if (time < self.lastground + 0.2)
147 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
149 self.nextstep = time + 0.3 + random() * 0.1;
150 trace_dphitq3surfaceflags = 0;
151 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
153 if(trace_fraction == 1)
156 dprint(ftos(trace_dphitq3surfaceflags), "\n");
158 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
160 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
161 GlobalSound(globalsound_metalstep, CH_PLAYER, VOICETYPE_PLAYERSOUND);
163 GlobalSound(globalsound_step, CH_PLAYER, VOICETYPE_PLAYERSOUND);
169 self.oldvelocity = self.velocity;
179 Called before each frame by the server
184 float game_delay_last;
186 float RedirectionThink();
187 void StartFrame (void)
189 execute_next_frame();
191 remove = remove_unsafely; // not during spawning!
192 serverprevtime = servertime;
194 serverframetime = frametime;
197 if(time > client_cefc_accumulatortime + 1)
199 float t, pp, c_seeing, c_seen;
201 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
202 LOG_INFO("CEFC time: ", ftos(t * 1000), "ms; ");
207 if(IS_REAL_CLIENT(cl))
212 LOG_INFO("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
213 LOG_INFO("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
215 client_cefc_accumulatortime = time;
216 client_cefc_accumulator = 0;
220 for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
221 CSQCProjectile_Check(e);
223 if(RedirectionThink())
226 UncustomizeEntitiesRun();
227 InitializeEntitiesRun();
229 WarpZone_StartFrame();
231 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
232 if(sys_frametime <= 0)
233 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
235 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
236 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
238 skill = autocvar_skill;
240 // detect when the pre-game countdown (if any) has ended and the game has started
241 game_delay = (time < game_starttime) ? true : false;
243 if(game_delay_last == true)
244 if(game_delay == false)
245 if(autocvar_sv_eventlog)
246 GameLogEcho(":startdelay_ended");
248 game_delay_last = game_delay;
253 // if in warmup stage and limit for warmup is hit start match
256 if((g_warmup_limit > 0 && time >= g_warmup_limit)
257 || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
267 e.porto_forbidden = max(0, e.porto_forbidden - 1);
269 anticheat_startframe();
271 MUTATOR_CALLHOOK(SV_StartFrame);
274 .vector originjitter;
275 .vector anglesjitter;
277 .string gametypefilter;
279 float DoesQ3ARemoveThisEntity();
280 void SV_OnEntityPreSpawnFunction()
283 if (self.gametypefilter != "")
284 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
289 if(self.cvarfilter != "")
296 if(substring(s, 0, 1) == "+")
298 s = substring(s, 1, -1);
300 else if(substring(s, 0, 1) == "-")
303 s = substring(s, 1, -1);
306 n = tokenize_console(s);
307 for(i = 0; i < n; ++i)
319 if((o = strstrofs(s, ">=", 0)) >= 0)
321 k = substring(s, 0, o);
322 v = substring(s, o+2, -1);
323 if(cvar(k) < stof(v))
326 else if((o = strstrofs(s, "<=", 0)) >= 0)
328 k = substring(s, 0, o);
329 v = substring(s, o+2, -1);
330 if(cvar(k) > stof(v))
333 else if((o = strstrofs(s, ">", 0)) >= 0)
335 k = substring(s, 0, o);
336 v = substring(s, o+1, -1);
337 if(cvar(k) <= stof(v))
340 else if((o = strstrofs(s, "<", 0)) >= 0)
342 k = substring(s, 0, o);
343 v = substring(s, o+1, -1);
344 if(cvar(k) >= stof(v))
347 else if((o = strstrofs(s, "==", 0)) >= 0)
349 k = substring(s, 0, o);
350 v = substring(s, o+2, -1);
351 if(cvar(k) != stof(v))
354 else if((o = strstrofs(s, "!=", 0)) >= 0)
356 k = substring(s, 0, o);
357 v = substring(s, o+2, -1);
358 if(cvar(k) == stof(v))
361 else if((o = strstrofs(s, "===", 0)) >= 0)
363 k = substring(s, 0, o);
364 v = substring(s, o+2, -1);
365 if(cvar_string(k) != v)
368 else if((o = strstrofs(s, "!==", 0)) >= 0)
370 k = substring(s, 0, o);
371 v = substring(s, o+2, -1);
372 if(cvar_string(k) == v)
375 else if(substring(s, 0, 1) == "!")
377 k = substring(s, 1, -1);
390 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
393 //print("cvarfilter fail\n");
399 if(DoesQ3ARemoveThisEntity())
405 // support special -1 and -2 angle from radiant
406 if (self.angles == '0 -1 0')
407 self.angles = '-90 0 0';
408 else if (self.angles == '0 -2 0')
409 self.angles = '+90 0 0';
411 if(self.originjitter.x != 0)
412 self.origin_x = self.origin.x + (random() * 2 - 1) * self.originjitter.x;
413 if(self.originjitter.y != 0)
414 self.origin_y = self.origin.y + (random() * 2 - 1) * self.originjitter.y;
415 if(self.originjitter.z != 0)
416 self.origin_z = self.origin.z + (random() * 2 - 1) * self.originjitter.z;
417 if(self.anglesjitter.x != 0)
418 self.angles_x = self.angles.x + (random() * 2 - 1) * self.anglesjitter.x;
419 if(self.anglesjitter.y != 0)
420 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglesjitter.y;
421 if(self.anglesjitter.z != 0)
422 self.angles_z = self.angles.z + (random() * 2 - 1) * self.anglesjitter.z;
423 if(self.anglejitter != 0)
424 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglejitter;
426 if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
433 void WarpZone_PostInitialize_Callback(void)
435 // create waypoint links for warpzones
437 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
440 src = (e.absmin + e.absmax) * 0.5;
441 makevectors(e.warpzone_angles);
442 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
443 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
444 makevectors(e.enemy.warpzone_angles);
445 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
446 waypoint_spawnforteleporter_v(e, src, dst, 0);