From 7de4aabaa02b98879bb4d7435c794ac79d1291fa Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 29 Nov 2017 17:18:39 +1000 Subject: [PATCH] Antilag nades so they can be shot at high ping --- qcsrc/common/weapons/weapon/shockwave.qc | 16 ++------------ qcsrc/server/antilag.qc | 27 ++++++++++++++++++++++++ qcsrc/server/antilag.qh | 3 +++ qcsrc/server/g_subs.qc | 17 ++------------- qcsrc/server/g_world.qc | 4 ++++ qcsrc/server/weapons/tracing.qc | 16 ++------------ 6 files changed, 40 insertions(+), 43 deletions(-) diff --git a/qcsrc/common/weapons/weapon/shockwave.qc b/qcsrc/common/weapons/weapon/shockwave.qc index 990bc29ee..0ca4d528f 100644 --- a/qcsrc/common/weapons/weapon/shockwave.qc +++ b/qcsrc/common/weapons/weapon/shockwave.qc @@ -316,13 +316,7 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) if(autocvar_g_antilag == 0 || noantilag) lag = 0; // only do hitscan, but no antilag if(lag) - { - FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_takeback(it, CS(it), time - lag)); - IL_EACH(g_monsters, it != actor, - { - antilag_takeback(it, it, time - lag); - }); - } + antilag_takeback_all(actor, lag); while(head) { @@ -596,13 +590,7 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) } if(lag) - { - FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_restore(it, CS(it))); - IL_EACH(g_monsters, it != actor, - { - antilag_restore(it, it); - }); - } + antilag_restore_all(actor); } METHOD(Shockwave, wr_aim, void(entity thiswep, entity actor, .entity weaponentity)) diff --git a/qcsrc/server/antilag.qc b/qcsrc/server/antilag.qc index 46c871876..4062f7f66 100644 --- a/qcsrc/server/antilag.qc +++ b/qcsrc/server/antilag.qc @@ -119,3 +119,30 @@ void antilag_clear(entity e, entity store) } store.antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0 } + +// TODO: use a single intrusive list across all antilagged entities +void antilag_takeback_all(entity ignore, float lag) +{ + FOREACH_CLIENT(IS_PLAYER(it) && it != ignore, antilag_takeback(it, CS(it), time - lag)); + IL_EACH(g_monsters, it != ignore, + { + antilag_takeback(it, it, time - lag); + }); + IL_EACH(g_projectiles, it != ignore && it.classname == "nade", + { + antilag_takeback(it, it, time - lag); + }); +} + +void antilag_restore_all(entity ignore) +{ + FOREACH_CLIENT(IS_PLAYER(it) && it != ignore, antilag_restore(it, CS(it))); + IL_EACH(g_monsters, it != ignore, + { + antilag_restore(it, it); + }); + IL_EACH(g_projectiles, it != ignore && it.classname == "nade", + { + antilag_restore(it, it); + }); +} diff --git a/qcsrc/server/antilag.qh b/qcsrc/server/antilag.qh index 6cf392eed..d57762ccd 100644 --- a/qcsrc/server/antilag.qh +++ b/qcsrc/server/antilag.qh @@ -6,6 +6,9 @@ void antilag_takeback(entity e, entity store, float t); void antilag_restore(entity e, entity store); void antilag_clear(entity e, entity store); +void antilag_takeback_all(entity ignore, float lag); +void antilag_restore_all(entity ignore); + .float antilag_debug; #define ANTILAG_LATENCY(e) min(0.4, CS(e).ping * 0.001) diff --git a/qcsrc/server/g_subs.qc b/qcsrc/server/g_subs.qc index 713577fad..d9372e0aa 100644 --- a/qcsrc/server/g_subs.qc +++ b/qcsrc/server/g_subs.qc @@ -50,14 +50,7 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE; if (lag) - { - // take players back into the past - FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_takeback(it, CS(it), time - lag)); - IL_EACH(g_monsters, it != forent, - { - antilag_takeback(it, it, time - lag); - }); - } + antilag_takeback_all(forent, lag); // do the trace if(wz) @@ -67,13 +60,7 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, // restore players to current positions if (lag) - { - FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_restore(it, CS(it))); - IL_EACH(g_monsters, it != forent, - { - antilag_restore(it, it); - }); - } + antilag_restore_all(forent); // restore shooter solid type if(source) diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index ce25dfa52..2eda8584e 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -2093,6 +2093,10 @@ void EndFrame() { antilag_record(it, it, altime); }); + IL_EACH(g_projectiles, it.classname == "nade", + { + antilag_record(it, it, altime); + }); systems_update(); IL_ENDFRAME(); } diff --git a/qcsrc/server/weapons/tracing.qc b/qcsrc/server/weapons/tracing.qc index bf272a01a..157adb5d3 100644 --- a/qcsrc/server/weapons/tracing.qc +++ b/qcsrc/server/weapons/tracing.qc @@ -357,13 +357,7 @@ void fireBullet(entity this, .entity weaponentity, vector start, vector dir, flo if(autocvar_g_antilag == 0 || noantilag) lag = 0; // only do hitscan, but no antilag if(lag) - { - FOREACH_CLIENT(IS_PLAYER(it) && it != this, antilag_takeback(it, CS(it), time - lag)); - IL_EACH(g_monsters, it != this, - { - antilag_takeback(it, it, time - lag); - }); - } + antilag_takeback_all(this, lag); // change shooter to SOLID_BBOX so the shot can hit corpses int oldsolid = this.dphitcontentsmask; @@ -480,13 +474,7 @@ void fireBullet(entity this, .entity weaponentity, vector start, vector dir, flo } if(lag) - { - FOREACH_CLIENT(IS_PLAYER(it) && it != this, antilag_restore(it, CS(it))); - IL_EACH(g_monsters, it != this, - { - antilag_restore(it, it); - }); - } + antilag_restore_all(this); // restore shooter solid type if(this) -- 2.39.2