]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/calculations.qc
Unhardcode a few more weapon entity checks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / calculations.qc
index e8307f39d20068151236b4e26d9155c820d61d2f..a8587b1ab3167ea24242590a35b714b8ace98fe4 100644 (file)
@@ -1,3 +1,5 @@
+#include "calculations.qh"
+
 // =============================
 //  Explosion Force Calculation
 // =============================
@@ -142,6 +144,54 @@ vector findperpendicular(vector v)
        return normalize(cliptoplane(p, v));
 }
 
+#ifdef SVQC
+       int W_GunAlign(entity this, int preferred_align)
+       {
+               entity own = this.owner;
+               // using wasfreed, as we don't actually clear .gunaligns yet
+               if(!own.gunaligns[preferred_align] || wasfreed(own.gunaligns[preferred_align]) || own.gunaligns[preferred_align] == this)
+               {
+                       own.gunaligns[preferred_align] = this;
+                       return preferred_align; // fall back if the good one is already choosable
+               }
+
+               for(int j = 4; j > 0; --j) // start from left and try the others
+               {
+                       if(!own.gunaligns[j] || wasfreed(own.gunaligns[j]) || own.gunaligns[j] == this)
+                       {
+                               own.gunaligns[j] = this;
+                               return j;
+                       }
+               }
+
+               own.gunaligns[preferred_align] = this;
+               return preferred_align; // no other choice
+       }
+#else
+       int W_GunAlign(entity this, int preferred_align)
+       {
+               // using wasfreed, as we don't actually clear gunaligns yet
+               if(!gunaligns[preferred_align] || wasfreed(gunaligns[preferred_align]) || gunaligns[preferred_align] == this)
+               {
+                       gunaligns[preferred_align] = this;
+                       return preferred_align; // fall back if the good one is already choosable
+               }
+
+               for(int j = 4; j > 0; --j)
+               {
+                       if(!gunaligns[j] || wasfreed(gunaligns[j]) || gunaligns[j] == this)
+                       {
+                               gunaligns[j] = this;
+                               return j;
+                       }
+               }
+
+               gunaligns[preferred_align] = this;
+               return preferred_align; // no other choice
+       }
+#endif
+
+#if 0
 int W_GetGunAlignment(entity player)
 {
        int gunalign = STAT(GUNALIGN, player);
@@ -151,6 +201,7 @@ int W_GetGunAlignment(entity player)
 
        return gunalign;
 }
+#endif
 
 vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float spreadstyle)
 {
@@ -256,7 +307,7 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float
                default:
                        error("g_projectiles_spread_style must be 0 (sphere), 1 (flattened sphere), 2 (circle), 3 (gauss 3D), 4 (gauss plane), 5 (linear falloff), 6 (quadratic falloff), 7 (stronger falloff)!");
        }
-               
+
        return '0 0 0';
        /*
         * how to derive falloff functions: