From: Mario Date: Mon, 3 Oct 2016 10:33:32 +0000 (+1000) Subject: Rewrite gun alignment setting to be more reliable X-Git-Tag: xonotic-v0.8.2~326^2~70^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d1bc5c72b3a71bcceffcec2ce0343f4f0f7901d1;p=xonotic%2Fxonotic-data.pk3dir.git Rewrite gun alignment setting to be more reliable --- diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 0e9aae262..287963ed6 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -333,10 +333,6 @@ vector weaponentity_glowmod(Weapon wep, entity actor, int c, entity wepent) return g; } -#ifdef SVQC -.entity gunaligns[5]; -#endif - .int m_gunalign; //.int weapon; // current weapon diff --git a/qcsrc/common/weapons/calculations.qc b/qcsrc/common/weapons/calculations.qc index 77b6cba26..258b83f08 100644 --- a/qcsrc/common/weapons/calculations.qc +++ b/qcsrc/common/weapons/calculations.qc @@ -147,25 +147,30 @@ vector findperpendicular(vector 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 + 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)