]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/antilag.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / antilag.qc
index 46c871876108005a0a69978681454bf1a9446f09..8d7fbad52db948bdd49813ce8c03200a30417396 100644 (file)
@@ -2,10 +2,10 @@
 #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"
+#include <server/defs.qh>
+#include <common/state.qh>
+#include <common/vehicles/all.qh>
+#include "antilag.qh"
 #endif
 
 const int ANTILAG_MAX_ORIGINS = 64;
@@ -19,38 +19,48 @@ 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;
+       if (time < store.antilag_times[store.antilag_index]) { return; }
        store.antilag_index += 1;
-       if (store.antilag_index >= ANTILAG_MAX_ORIGINS)
+       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)
+       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, entity store, float t)
 {
-       for(int i = store.antilag_index; i > 0; --i)
-               if(store.antilag_times[i] >= t)
-                       if(store.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(store.antilag_times[0] >= t)
-               if(store.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 > store.antilag_index + 1; --i)
-               if(store.antilag_times[i] >= t)
-                       if(store.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;
@@ -59,24 +69,25 @@ float antilag_find(entity e, entity store, float t)
 vector antilag_takebackorigin(entity e, entity store, float t)
 {
        int i0 = antilag_find(e, store, t);
-       if (i0 < 0)
-       {
+       if (i0 < 0) {
                // IN THE PRESENT
-               if(store.antilag_takenback)
+               if (store.antilag_takenback) {
                        return store.antilag_saved_origin;
-               else
+               } else {
                        return e.origin;
+               }
        }
        int i1 = i0 + 1;
-       if (i1 >= ANTILAG_MAX_ORIGINS)
+       if (i1 >= ANTILAG_MAX_ORIGINS) {
                i1 = 0;
+       }
 
        return lerpv(store.antilag_times[i0], store.antilag_origins[i0], store.antilag_times[i1], store.antilag_origins[i1], t);
 }
 
 vector antilag_takebackavgvelocity(entity e, entity store, float t0, float t1)
 {
-       if (t0 >= t1) return '0 0 0';
+       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));
@@ -85,12 +96,13 @@ 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)
+       if (!store.antilag_takenback) {
                store.antilag_saved_origin = e.origin;
+       }
 
        vector org = antilag_takebackorigin(e, store, t);
        setorigin(e, org);
@@ -100,11 +112,11 @@ 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);
        }
 
-       if (!store.antilag_takenback) return;
+       if (!store.antilag_takenback) { return; }
 
        setorigin(e, store.antilag_saved_origin);
        store.antilag_takenback = false;