#pragma once

#include <lib/warpzone/common.qh>

int autocvar_g_antilag;
float autocvar_g_antilag_nudge;

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);

void antilag_takeback_all(entity ignore, float lag);
void antilag_restore_all(entity ignore);

float antilag_getlag(entity e); // returns antilag latency for clients, plus any modifiers (such as noantilag)

.float antilag_debug;

#define ANTILAG_LATENCY(e) min(0.4, CS(e).ping * 0.001)
// add one ticrate?


/// 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 nomonsters, entity forent, float lag, bool wz, WarpZone_trace_callback_t cb);

void traceline_antilag(entity source, vector v1, vector v2, float nomonsters, entity forent, float lag);
void WarpZone_traceline_antilag(entity source, vector v1, vector v2, float nomonsters, entity forent, float lag);
#define traceline_antilag_force(source, v1, v2, nomonsters, forent, lag) \
	tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonsters, forent, lag, false, func_null)
#define WarpZone_traceline_antilag_force(source, v1, v2, nomonsters, forent, lag) \
	tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonsters, forent, lag, true,  func_null)

void tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float lag);
void WarpZone_tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float lag);
