WITH(entity, self, this, vehicles_exit(VHEF_RELEASE));
- antilag_clear(this);
+ antilag_clear(this, this);
Vehicle info = Vehicles_from(this.vehicleid);
info.vr_death(info, this);
info.vr_enter(info, veh);
setself(this);
- antilag_clear(pl);
+ antilag_clear(pl, CS(pl));
}
void vehicles_think()
self.owner.velocity_z += 10;
setorigin(self.owner, spot);
- antilag_clear(self.owner);
+ antilag_clear(self.owner, CS(self.owner));
self.owner = world;
}
self.owner.oldvelocity = self.owner.velocity;
setorigin(self.owner , spot);
}
- antilag_clear(self.owner);
+ antilag_clear(self.owner, CS(self.owner));
self.owner = world;
}
setorigin(self.owner , spot);
}
- antilag_clear(self.owner);
+ antilag_clear(self.owner, CS(self.owner));
self.owner = world;
}
setorigin(self.owner , spot);
}
- antilag_clear(self.owner);
+ antilag_clear(self.owner, CS(self.owner));
self.owner = world;
}
.float antilag_debug;
-void antilag_record(entity e, float t)
+void antilag_record(entity e, entity store, float t)
{
- if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
- return;
-
- if(e.vehicle)
- antilag_record(e.vehicle, t);
-
- if(time < CS(e).antilag_times[CS(e).antilag_index])
- return;
- CS(e).antilag_index += 1;
- if(CS(e).antilag_index >= ANTILAG_MAX_ORIGINS)
- CS(e).antilag_index = 0;
- CS(e).antilag_times[CS(e).antilag_index] = t;
- CS(e).antilag_origins[CS(e).antilag_index] = e.origin;
-
- if(CS(e).antilag_debug)
- te_spark(antilag_takebackorigin(e, t - CS(e).antilag_debug), '0 0 0', 32);
-
+ 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;
+ if (store.antilag_index >= ANTILAG_MAX_ORIGINS)
+ store.antilag_index = 0;
+ store.antilag_times[store.antilag_index] = t;
+ store.antilag_origins[store.antilag_index] = e.origin;
+
+ if (store.antilag_debug)
+ te_spark(antilag_takebackorigin(e, store, t - store.antilag_debug), '0 0 0', 32);
}
// finds the index BEFORE t
-float antilag_find(entity e, float t)
+float antilag_find(entity e, entity store, float t)
{
- for(int i = CS(e).antilag_index; i > 0; --i)
- if(CS(e).antilag_times[i] >= t)
- if(CS(e).antilag_times[i - 1] < t)
+ for(int i = store.antilag_index; i > 0; --i)
+ if(store.antilag_times[i] >= t)
+ if(store.antilag_times[i - 1] < t)
return i - 1;
- if(CS(e).antilag_times[0] >= t)
- if(CS(e).antilag_times[ANTILAG_MAX_ORIGINS - 1] < t)
+ if(store.antilag_times[0] >= t)
+ if(store.antilag_times[ANTILAG_MAX_ORIGINS - 1] < t)
return ANTILAG_MAX_ORIGINS - 1;
- for(int i = ANTILAG_MAX_ORIGINS - 1; i > CS(e).antilag_index + 1; --i)
- if(CS(e).antilag_times[i] >= t)
- if(CS(e).antilag_times[i - 1] < t)
+ for(int i = ANTILAG_MAX_ORIGINS - 1; i > store.antilag_index + 1; --i)
+ if(store.antilag_times[i] >= t)
+ if(store.antilag_times[i - 1] < t)
return i - 1;
// if we get here, t is sandwiched nowhere, so let's assume it's in the present
return -1;
}
-vector antilag_takebackorigin(entity e, float t)
+vector antilag_takebackorigin(entity e, entity store, float t)
{
- int i0 = antilag_find(e, t);
+ int i0 = antilag_find(e, store, t);
if (i0 < 0)
{
// IN THE PRESENT
- if(CS(e).antilag_takenback)
- return CS(e).antilag_saved_origin;
+ if(store.antilag_takenback)
+ return store.antilag_saved_origin;
else
return e.origin;
}
if (i1 >= ANTILAG_MAX_ORIGINS)
i1 = 0;
- return lerpv(CS(e).antilag_times[i0], CS(e).antilag_origins[i0], CS(e).antilag_times[i1], CS(e).antilag_origins[i1], t);
+ return lerpv(store.antilag_times[i0], store.antilag_origins[i0], store.antilag_times[i1], store.antilag_origins[i1], t);
}
-vector antilag_takebackavgvelocity(entity e, float t0, float t1)
+vector antilag_takebackavgvelocity(entity e, entity store, float t0, float t1)
{
- vector o0, o1;
-
- if(t0 >= t1)
- return '0 0 0';
- o0 = antilag_takebackorigin(e, t0);
- o1 = antilag_takebackorigin(e, t1);
+ if (t0 >= t1) return '0 0 0';
+ vector o0 = antilag_takebackorigin(e, store, t0);
+ vector o1 = antilag_takebackorigin(e, store, t1);
return (o1 - o0) * (1 / (t1 - t0));
}
-void antilag_takeback(entity e, float t)
+void antilag_takeback(entity e, entity store, float t)
{
+ if (e.vehicle) {
+ if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+ antilag_takeback(e.vehicle, store, t);
+ }
- if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
- return;
+ if (!store.antilag_takenback)
+ store.antilag_saved_origin = e.origin;
- if(e.vehicle)
- antilag_takeback(e.vehicle, t);
-
- if(!CS(e).antilag_takenback)
- CS(e).antilag_saved_origin = e.origin;
-
- vector org = antilag_takebackorigin(e, t);
+ vector org = antilag_takebackorigin(e, store, t);
setorigin(e, org);
- CS(e).antilag_takenback = true;
+ store.antilag_takenback = true;
}
-void antilag_restore(entity e)
+void antilag_restore(entity e, entity store)
{
- if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
- return;
-
- if(e.vehicle)
- antilag_restore(e.vehicle);
+ if (e.vehicle) {
+ if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+ antilag_restore(e.vehicle, e.vehicle);
+ }
- if(!CS(e).antilag_takenback)
- return;
+ if (!store.antilag_takenback) return;
- setorigin(e, CS(e).antilag_saved_origin);
- CS(e).antilag_takenback = false;
+ setorigin(e, store.antilag_saved_origin);
+ store.antilag_takenback = false;
}
-void antilag_clear(entity e)
+void antilag_clear(entity e, entity store)
{
- antilag_restore(e);
- for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i)
- {
- CS(e).antilag_times[i] = -2342;
- CS(e).antilag_origins[i] = e.origin;
+ antilag_restore(e, store);
+ for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i) {
+ store.antilag_times[i] = -2342;
+ store.antilag_origins[i] = e.origin;
}
- CS(e).antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0
+ store.antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0
}
#ifndef ANTILAG_H
#define ANTILAG_H
-void antilag_record(entity e, float t);
-vector antilag_takebackorigin(entity e, float t);
-vector antilag_takebackavgvelocity(entity e, float t0, float t1);
-void antilag_takeback(entity e, float t);
-void antilag_restore(entity e);
-void antilag_clear(entity e);
+void antilag_record(entity e, entity store, float t);
+vector antilag_takebackorigin(entity e, entity store, float t);
+void antilag_takeback(entity e, entity store, float t);
+void antilag_restore(entity e, entity store);
+void antilag_clear(entity e, entity store);
.float antilag_debug;
}
t = (tmin + tmax) * 0.5;
- o = antilag_takebackorigin(p, time - t);
+ o = antilag_takebackorigin(p, CS(p), time - t);
if(!botframe_autowaypoints_fixdown(o))
return -2;
o = trace_endpos;
if (!warmup_stage && !this.alivetime)
this.alivetime = time;
- antilag_clear(this);
+ antilag_clear(this, CS(this));
}
}
if (lag)
{
// take players back into the past
- FOREACH_CLIENT(IS_PLAYER(it) && it != forent, LAMBDA(antilag_takeback(it, time - lag)));
- FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+ FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_takeback(it, CS(it), time - lag));
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
if(it != forent)
- antilag_takeback(it, time - lag);
- ));
+ antilag_takeback(it, it, time - lag);
+ });
}
// do the trace
// restore players to current positions
if (lag)
{
- FOREACH_CLIENT(IS_PLAYER(it) && it != forent, LAMBDA(antilag_restore(it)));
- FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
- if(it != forent)
- antilag_restore(it);
- ));
+ FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_restore(it, CS(it)));
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+ if (it != forent)
+ antilag_restore(it, it);
+ });
}
// restore shooter solid type
void EndFrame()
-{SELFPARAM();
+{
anticheat_endframe();
- float altime;
- FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+ FOREACH_CLIENT(IS_REAL_CLIENT(it), {
entity e = IS_SPEC(it) ? it.enemy : it;
- if(e.typehitsound)
+ if (e.typehitsound) {
it.typehit_time = time;
- else if(e.damage_dealt)
- {
+ } else if (e.damage_dealt) {
it.hit_time = time;
it.damage_dealt_total += ceil(e.damage_dealt);
}
- ));
- altime = time + frametime * (1 + autocvar_g_antilag_nudge);
+ });
// add 1 frametime because after this, engine SV_Physics
// increases time by a frametime and then networks the frame
// add another frametime because client shows everything with
// 1 frame of lag (cl_nolerp 0). The last +1 however should not be
// needed!
- FOREACH_CLIENT(true, LAMBDA(
+ float altime = time + frametime * (1 + autocvar_g_antilag_nudge);
+ FOREACH_CLIENT(true, {
it.typehitsound = false;
it.damage_dealt = 0;
- setself(it);
- antilag_record(it, altime);
- ));
- FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
- setself(it);
- antilag_record(it, altime);
- ));
- FOREACH_CLIENT(PS(it), LAMBDA(
+ antilag_record(it, CS(it), altime);
+ });
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+ antilag_record(it, it, altime);
+ });
+ FOREACH_CLIENT(PS(it), {
PlayerState s = PS(it);
s.ps_push(s, it);
- ));
+ });
}
traceline_antilag_force(player, org, org + screenforward * MAX_SHOT_DISTANCE, MOVE_NORMAL, player, lag);
if(IS_CLIENT(trace_ent) || IS_MONSTER(trace_ent))
{
- antilag_takeback(trace_ent, time - lag);
+ entity store = IS_CLIENT(trace_ent) ? CS(trace_ent) : trace_ent;
+ antilag_takeback(trace_ent, store, time - lag);
hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);
- antilag_restore(trace_ent);
+ antilag_restore(trace_ent, store);
fputs(player.hitplotfh, strcat(ftos(hitplot.x), " ", ftos(hitplot.y), " ", ftos(hitplot.z), " ", ftos(PS(player).m_switchweapon.m_id), "\n"));
//print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n"));
}
lag = 0; // only do hitscan, but no antilag
if(lag)
{
- FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(antilag_takeback(it, time - lag)));
- FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
- if(it != self)
- antilag_takeback(it, time - lag);
- ));
+ FOREACH_CLIENT(IS_PLAYER(it) && it != self, antilag_takeback(it, CS(it), time - lag));
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+ if (it != self)
+ antilag_takeback(it, it, time - lag);
+ });
}
// change shooter to SOLID_BBOX so the shot can hit corpses
if(lag)
{
- FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(antilag_restore(it)));
- FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
- if(it != self)
- antilag_restore(it);
- ));
+ FOREACH_CLIENT(IS_PLAYER(it) && it != self, antilag_restore(it, CS(it)));
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+ if (it != self)
+ antilag_restore(it, it);
+ });
}
// restore shooter solid type