]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/calculations.qc
Merge branch 'terencehill/eraseable_functions'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / calculations.qc
index 77b6cba260b63b77e28f38c72ec1197cdd781f68..513af5209d670cac485f046342922c5e003c0bf3 100644 (file)
@@ -90,15 +90,11 @@ vector solve_cubic_pq(float p, float q)
                // cos(a)
                // cos(a + 2pi/3)
                // cos(a + 4pi/3)
-               return
-                       u *
-                       (
-                               '1 0 0' * cos(a + 2.0/3.0*M_PI)
-                               +
-                               '0 1 0' * cos(a + 4.0/3.0*M_PI)
-                               +
-                               '0 0 1' * cos(a)
-                       );
+               return u * vec3(
+                       cos(a + 2.0/3.0*M_PI),
+                       cos(a + 4.0/3.0*M_PI),
+                       cos(a)
+               );
        }
        else if(D == 0)
        {
@@ -107,17 +103,15 @@ vector solve_cubic_pq(float p, float q)
                        return '0 0 0';
                u = 3*q/p;
                v = -u/2;
-               if(u >= v)
-                       return '1 1 0' * v + '0 0 1' * u;
-               else
-                       return '0 1 1' * v + '1 0 0' * u;
+               return (u >= v) ? vec3(v, v, u) : vec3(u, v, v);
        }
        else
        {
                // cardano
-               u = cbrt(-q/2.0 + sqrt(D));
-               v = cbrt(-q/2.0 - sqrt(D));
-               return '1 1 1' * (u + v);
+               //u = cbrt(-q/2.0 + sqrt(D));
+               //v = cbrt(-q/2.0 - sqrt(D));
+               a = cbrt(-q/2.0 + sqrt(D)) + cbrt(-q/2.0 - sqrt(D));
+               return vec3(a, a, a);
        }
 }
 vector solve_cubic_abcd(float a, float b, float c, float d)
@@ -137,35 +131,39 @@ vector solve_cubic_abcd(float a, float b, float c, float d)
 
 vector findperpendicular(vector v)
 {
-       vector p;
-       p.x = v.z;
-       p.y = -v.x;
-       p.z = v.y;
-       return normalize(cliptoplane(p, v));
+       return normalize(cliptoplane(vec3(v.z, -v.x, v.y), 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;
-               // 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(preferred_align < 1 || preferred_align > 4)
+                       preferred_align = 3; // default
+
+               for(int j = 4; j > 1; --j) // > 1 as 1 is just center again
                {
-                       if(!own.gunaligns[j] || wasfreed(own.gunaligns[j]) || own.gunaligns[j] == this)
+                       int taken = 0;
+                       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
                        {
-                               own.gunaligns[j] = this;
-                               return j;
+                               .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
                }
 
-               own.gunaligns[preferred_align] = this;
-               return preferred_align; // no other choice
+               return preferred_align; // return it anyway
        }
 #else
        int W_GunAlign(entity this, int preferred_align)