]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/calculations.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / calculations.qc
index 73d9b938efac9bdcc4917352b3833665a1dae105..367bab6afb26c5aba16179d96fae28096b765827 100644 (file)
@@ -1,3 +1,5 @@
+#include "calculations.qh"
+
 // =============================
 //  Explosion Force Calculation
 // =============================
@@ -142,6 +144,45 @@ vector findperpendicular(vector v)
        return normalize(cliptoplane(p, v));
 }
 
+#ifdef SVQC
+       int W_GunAlign(entity this, int preferred_align)
+       {
+               if(this.m_gunalign)
+                       return this.m_gunalign; // no adjustment needed
+
+               entity own = this.owner;
+
+               if(preferred_align < 1 || preferred_align > 4)
+                       preferred_align = 3; // default
+
+               for(int j = 4; j > 1; --j) // > 1 as 1 is just center again
+               {
+                       int taken = 0;
+                       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+                       {
+                               .entity weaponentity = weaponentities[slot];
+                               if(own.(weaponentity).m_gunalign == j) // we know it can't be ours thanks to the above check
+                                       taken |= BIT(j);
+                               if(own.(weaponentity).m_gunalign == preferred_align)
+                                       taken |= BIT(preferred_align);
+                       }
+
+                       if(!(taken & BIT(preferred_align)))
+                               return preferred_align; // prefer the recommended
+                       if(!(taken & BIT(j)))
+                               return j; // or fall back if it's not available
+               }
+
+               return preferred_align; // return it anyway
+       }
+#else
+       int W_GunAlign(entity this, int preferred_align)
+       {
+               return this.m_gunalign > 0 ? this.m_gunalign : preferred_align;
+       }
+#endif
+
+#if 0
 int W_GetGunAlignment(entity player)
 {
        int gunalign = STAT(GUNALIGN, player);
@@ -151,6 +192,7 @@ int W_GetGunAlignment(entity player)
 
        return gunalign;
 }
+#endif
 
 vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float spreadstyle)
 {