4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../common/vehicles/all.qh"
10 const int ANTILAG_MAX_ORIGINS = 64;
11 .vector antilag_origins[ANTILAG_MAX_ORIGINS];
12 .float antilag_times[ANTILAG_MAX_ORIGINS];
14 .vector antilag_saved_origin;
15 .float antilag_takenback;
19 void antilag_record(entity e, float t)
21 if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
25 antilag_record(e.vehicle, t);
27 if(time < e.(antilag_times[e.antilag_index]))
29 e.antilag_index = e.antilag_index + 1;
30 if(e.antilag_index >= ANTILAG_MAX_ORIGINS)
32 e.(antilag_times[e.antilag_index]) = t;
33 e.(antilag_origins[e.antilag_index]) = e.origin;
36 te_spark(antilag_takebackorigin(e, t - e.antilag_debug), '0 0 0', 32);
40 // finds the index BEFORE t
41 float antilag_find(entity e, float t)
43 for(int i = e.antilag_index; i > 0; --i)
44 if(e.(antilag_times[i]) >= t)
45 if(e.(antilag_times[i - 1]) < t)
48 if(e.(antilag_times[0]) >= t)
49 if(e.(antilag_times[ANTILAG_MAX_ORIGINS - 1]) < t)
50 return ANTILAG_MAX_ORIGINS - 1;
52 for(int i = ANTILAG_MAX_ORIGINS - 1; i > e.antilag_index + 1; --i)
53 if(e.(antilag_times[i]) >= t)
54 if(e.(antilag_times[i - 1]) < t)
57 // if we get here, t is sandwiched nowhere, so let's assume it's in the present
61 vector antilag_takebackorigin(entity e, float t)
63 int i0 = antilag_find(e, t);
67 if(e.antilag_takenback)
68 return e.antilag_saved_origin;
73 if (i1 >= ANTILAG_MAX_ORIGINS)
76 return lerpv(e.(antilag_times[i0]), e.(antilag_origins[i0]), e.(antilag_times[i1]), e.(antilag_origins[i1]), t);
79 vector antilag_takebackavgvelocity(entity e, float t0, float t1)
85 o0 = antilag_takebackorigin(e, t0);
86 o1 = antilag_takebackorigin(e, t1);
87 return (o1 - o0) * (1 / (t1 - t0));
90 void antilag_takeback(entity e, float t)
93 if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
97 antilag_takeback(e.vehicle, t);
99 if(!e.antilag_takenback)
100 e.antilag_saved_origin = e.origin;
102 setorigin(e, antilag_takebackorigin(e, t));
103 e.antilag_takenback = true;
106 void antilag_restore(entity e)
108 if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
112 antilag_restore(e.vehicle);
114 if(!e.antilag_takenback)
117 setorigin(e, e.antilag_saved_origin);
118 e.antilag_takenback = false;
121 void antilag_clear(entity e)
124 for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i)
126 e.(antilag_times[i]) = -2342;
127 e.(antilag_origins[i]) = e.origin;
129 e.antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0