]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/antilag.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / antilag.qc
index 46c871876108005a0a69978681454bf1a9446f09..858e0ef8b152b433b6e92c896953cfe648f65801 100644 (file)
@@ -1,12 +1,13 @@
 #include "antilag.qh"
-#if defined(CSQC)
-#elif defined(MENUQC)
-#elif defined(SVQC)
-    #include <server/defs.qh>
-    #include <common/state.qh>
-    #include <common/vehicles/all.qh>
-    #include "antilag.qh"
-#endif
+
+#include <common/monsters/sv_monsters.qh>
+#include <common/state.qh>
+#include <common/stats.qh>
+#include <common/vehicles/all.qh>
+#include <common/weapons/_all.qh>
+#include <lib/warpzone/common.qh>
+#include <server/antilag.qh>
+#include <server/weapons/common.qh>
 
 const int ANTILAG_MAX_ORIGINS = 64;
 .vector antilag_origins[ANTILAG_MAX_ORIGINS];
@@ -19,10 +20,10 @@ const int ANTILAG_MAX_ORIGINS = 64;
 
 void antilag_record(entity e, entity store, float t)
 {
-    if (e.vehicle) {
-        if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
-        antilag_record(e.vehicle, e.vehicle, t);
-    }
+       if (e.vehicle) {
+               if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+               antilag_record(e.vehicle, e.vehicle, t);
+       }
 
        if (time < store.antilag_times[store.antilag_index]) return;
        store.antilag_index += 1;
@@ -85,9 +86,9 @@ vector antilag_takebackavgvelocity(entity e, entity store, float t0, float t1)
 void antilag_takeback(entity e, entity store, float t)
 {
        if (e.vehicle) {
-           if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+               if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
                antilag_takeback(e.vehicle, e.vehicle, t);
-    }
+       }
 
        if (!store.antilag_takenback)
                store.antilag_saved_origin = e.origin;
@@ -100,7 +101,7 @@ void antilag_takeback(entity e, entity store, float t)
 void antilag_restore(entity e, entity store)
 {
        if (e.vehicle) {
-           if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+               if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
                antilag_restore(e.vehicle, e.vehicle);
        }
 
@@ -119,3 +120,115 @@ 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);
+       });
+}
+
+float antilag_getlag(entity e)
+{
+       float lag = ((IS_REAL_CLIENT(e)) ? ANTILAG_LATENCY(e) : 0);
+       bool noantilag = ((IS_CLIENT(e)) ? CS_CVAR(e).cvar_cl_noantilag : false);
+       if(autocvar_g_antilag == 0 || noantilag || lag < 0.001)
+               lag = 0;
+
+       return lag;
+}
+
+/*
+==================
+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 tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
+{
+       // check whether antilagged traces are enabled
+       if (lag < 0.001)
+               lag = 0;
+       if (!IS_REAL_CLIENT(forent))
+               lag = 0; // only antilag for clients
+
+       // change shooter to SOLID_BBOX so the shot can hit corpses
+       int oldsolid = source.dphitcontentsmask;
+       if(source)
+               source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
+
+       if (lag)
+               antilag_takeback_all(forent, lag);
+
+       // do the trace
+       if(wz)
+               WarpZone_TraceBox (v1, mi, ma, v2, nomonst, forent);
+       else
+               tracebox (v1, mi, ma, v2, nomonst, forent);
+
+       // restore players to current positions
+       if (lag)
+               antilag_restore_all(forent);
+
+       // restore shooter solid type
+       if(source)
+               source.dphitcontentsmask = oldsolid;
+}
+void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+{
+       tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, false);
+}
+void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+{
+       bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
+       if (autocvar_g_antilag != 2 || noantilag)
+               lag = 0;
+       traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
+}
+void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
+{
+       bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
+       if (autocvar_g_antilag != 2 || noantilag)
+               lag = 0;
+       tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, false);
+}
+void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+{
+       tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, true);
+}
+void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+{
+       bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
+       if (autocvar_g_antilag != 2 || noantilag)
+               lag = 0;
+       WarpZone_traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
+}
+void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
+{
+       bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
+       if (autocvar_g_antilag != 2 || noantilag)
+               lag = 0;
+       tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, true);
+}