From d55be0f6d1070c6ca0a75c7b340a4673c401a91c Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Mon, 10 Mar 2008 18:22:17 +0000 Subject: [PATCH] replaced traceline_hitcorpse with traceline_antilag, added an additional parameter for this, does the same as traceline_hitcorpse if given 0 as the lag parameter, OR if g_antilag is not 2 changed the aiming-based g_antilag check to use 1 git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3496 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/cl_weaponsystem.qc | 12 ++++----- data/qcsrc/server/g_subs.qc | 40 +++++++++++++++++++++++++--- data/qcsrc/server/w_common.qc | 5 ++-- data/qcsrc/server/w_crylink.qc | 3 +-- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/data/qcsrc/server/cl_weaponsystem.qc b/data/qcsrc/server/cl_weaponsystem.qc index 434d41b03..0274cd8bf 100644 --- a/data/qcsrc/server/cl_weaponsystem.qc +++ b/data/qcsrc/server/cl_weaponsystem.qc @@ -26,7 +26,7 @@ void(entity ent, vector vecs, float antilag, float recoil, string snd) W_SetupSh { float nudge = 1; // added to traceline target and subtracted from result local vector trueaimpoint; - traceline_hitcorpse(self, self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NOMONSTERS, self); + traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NOMONSTERS, self); trueaimpoint = trace_endpos; if (cvar("g_shootfromeye")) @@ -36,7 +36,7 @@ void(entity ent, vector vecs, float antilag, float recoil, string snd) W_SetupSh else w_shotorg = ent.origin + ent.view_ofs + v_right * vecs_y + v_up * vecs_z; // now move the shotorg forward as much as requested if possible - traceline_hitcorpse(self, w_shotorg, w_shotorg + v_forward * (vecs_x + nudge), MOVE_NORMAL, self); + traceline(w_shotorg, w_shotorg + v_forward * (vecs_x + nudge), MOVE_NORMAL, self); w_shotorg = trace_endpos - v_forward * nudge; // calculate the shotdir from the chosen shotorg w_shotdir = normalize(trueaimpoint - w_shotorg); @@ -55,15 +55,15 @@ void(entity ent, vector vecs, float antilag, float recoil, string snd) W_SetupSh if (self.cursor_trace_ent != self) // just to make sure if (self.cursor_trace_ent.takedamage) // and that person is killable if (self.cursor_trace_ent.classname == "player") // and actually a player - if (cvar("g_antilag")) + if (cvar("g_antilag") == 1) { // verify that the shot would miss without antilag // (avoids an issue where guns would always shoot at their origin) - traceline_hitcorpse(self, w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self); + traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self); if (!trace_ent.takedamage) { // verify that the shot would hit if altered - traceline_hitcorpse(self, w_shotorg, self.cursor_trace_ent.origin, MOVE_NORMAL, self); + traceline(w_shotorg, self.cursor_trace_ent.origin, MOVE_NORMAL, self); if (trace_ent == self.cursor_trace_ent) { // verify that the shot would hit in the past @@ -72,7 +72,7 @@ void(entity ent, vector vecs, float antilag, float recoil, string snd) W_SetupSh else antilag_takeback(self.cursor_trace_ent, time - self.ping * 0.001); - traceline_hitcorpse(self, self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, self); + traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, self); antilag_restore(self.cursor_trace_ent); if(trace_ent == self.cursor_trace_ent) diff --git a/data/qcsrc/server/g_subs.qc b/data/qcsrc/server/g_subs.qc index 1882faeb7..09310f41f 100644 --- a/data/qcsrc/server/g_subs.qc +++ b/data/qcsrc/server/g_subs.qc @@ -226,20 +226,54 @@ void PointSound (vector org, string snd, float vol, float attn) /* ================== -traceline_hitcorpse +traceline_antilag A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack +Additionally it moves players back into the past before the trace and restores them afterward. ================== */ -void traceline_hitcorpse (entity source, vector v1, vector v2, float nomonst, entity forent) +void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag) { - float oldsolid; + local entity player; + local float oldsolid; + // check whether antilagged traces are enabled + if (lag < 0.001) + lag = 0; + if (lag) + if (cvar("g_antilag") != 2) + lag = 0; + + // change shooter to SOLID_BBOX so the shot can hit corpses oldsolid = source.solid; source.solid = SOLID_BBOX; + if (lag) + { + // take players back into the past + player = player_list; + while (player) + { + antilag_takeback(player, time - lag); + player = player.nextplayer; + } + } + + // do the trace traceline (v1, v2, nomonst, forent); + // restore players to current positions + if (lag) + { + player = player_list; + while (player) + { + antilag_restore(player); + player = player.nextplayer; + } + } + + // restore shooter solid type source.solid = oldsolid; } diff --git a/data/qcsrc/server/w_common.qc b/data/qcsrc/server/w_common.qc index 6629002b5..9b2923a31 100644 --- a/data/qcsrc/server/w_common.qc +++ b/data/qcsrc/server/w_common.qc @@ -39,7 +39,7 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f // note down which entities were hit so we can damage them later while (1) { - traceline_hitcorpse (self, start, end, FALSE, self); + traceline_antilag (self, start, end, FALSE, self, self.ping); // if it is world we can't hurt it so stop now if (trace_ent == world || trace_fraction == 1) @@ -105,10 +105,9 @@ void fireBullet (vector start, vector dir, float spread, float damage, float for vector end; local entity e; - // use traceline_hitcorpse to make sure it can hit gibs and corpses too dir = dir + randomvec() * spread; end = start + dir * MAX_SHOT_DISTANCE; - traceline_hitcorpse (self, start, end, FALSE, self); + traceline_antilag (self, start, end, FALSE, self, self.ping); if (tracer) { diff --git a/data/qcsrc/server/w_crylink.qc b/data/qcsrc/server/w_crylink.qc index 613dd2daf..641349c97 100644 --- a/data/qcsrc/server/w_crylink.qc +++ b/data/qcsrc/server/w_crylink.qc @@ -126,8 +126,7 @@ void W_Crylink_Attack3 (void) self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo"); W_SetupShot (self, '25 8 -8', TRUE, 0, "weapons/crylink_fire.wav"); - // use traceline_hitcorpse to make sure it can hit gibs and corpses too - traceline_hitcorpse(self, w_shotorg, w_shotorg + w_shotdir * 1000, FALSE, self); + traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * 1000, FALSE, self, self.ping); pointparticles(particleeffectnum("lightning_muzzleflash", w_shotorg, w_shotdir * 1000, 1); pointparticles(particleeffectnum("lightning_impact", trace_endpos, trace_plane_normal * 1000, 1); -- 2.39.2