From 1eeba9501a6787736e333ede5a2256fa741bf272 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 3 Oct 2016 20:19:05 +1000 Subject: [PATCH] Set gun alignment on the server (hopefully more reliable) --- qcsrc/common/weapons/all.qc | 2 ++ qcsrc/common/weapons/all.qh | 2 -- qcsrc/common/weapons/calculations.qc | 19 +------------------ qcsrc/common/weapons/weapon/arc.qc | 12 ++---------- qcsrc/common/wepent.qc | 5 +++++ 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 6139d41b4..f4a4de7f3 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -527,7 +527,9 @@ void CL_WeaponEntity_SetModel(entity this, string name, bool _anim) { //int algn = STAT(GUNALIGN, this.owner); int algn = W_GunAlign(this, STAT(GUNALIGN, this.owner)); + #ifdef SVQC this.m_gunalign = algn; + #endif vector v = this.movedir; this.movedir = shotorg_adjust(v, false, false, algn); this.view_ofs = shotorg_adjust(v, false, true, algn) - v; diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 071ac4c56..0e9aae262 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -335,8 +335,6 @@ vector weaponentity_glowmod(Weapon wep, entity actor, int c, entity wepent) #ifdef SVQC .entity gunaligns[5]; -#else -entity gunaligns[5]; #endif .int m_gunalign; diff --git a/qcsrc/common/weapons/calculations.qc b/qcsrc/common/weapons/calculations.qc index a8587b1ab..77b6cba26 100644 --- a/qcsrc/common/weapons/calculations.qc +++ b/qcsrc/common/weapons/calculations.qc @@ -170,24 +170,7 @@ vector findperpendicular(vector v) #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 + return this.m_gunalign > 0 ? this.m_gunalign : preferred_align; } #endif diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index 06d784af2..6f8b6691a 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -1304,17 +1304,9 @@ NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew) if(isnew) { - int gunalign = W_GunAlign(NULL, STAT(GUNALIGN)); + int gunalign = W_GunAlign(viewmodels[slot], STAT(GUNALIGN)); - this.beam_shotorigin = arc_shotorigin[gunalign]; // quick - for(int j = 1; j < 5; ++j) - { - if(gunaligns[j] == viewmodels[slot]) - { - this.beam_shotorigin = arc_shotorigin[j - 1]; // accurate - break; - } - } + this.beam_shotorigin = arc_shotorigin[gunalign]; // set other main attributes of the beam this.draw = Draw_ArcBeam; diff --git a/qcsrc/common/wepent.qc b/qcsrc/common/wepent.qc index 0d18908c4..44a9d71f8 100644 --- a/qcsrc/common/wepent.qc +++ b/qcsrc/common/wepent.qc @@ -17,6 +17,7 @@ MACRO_END //.float w_weapon_nextthink; .float w_m_alpha; .float w_vortex_charge; +.int w_m_gunalign; // #define PROP(public, fld, set, sv, cl) #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \ @@ -39,6 +40,10 @@ MACRO_END PROP(false, vortex_charge, WEPENT_SET_NORMAL, \ { WriteByte(chan, this.vortex_charge * 16); }, \ { (viewmodels[this.m_wepent_slot]).vortex_charge = ReadByte() / 16; }) \ + \ + PROP(false, m_gunalign, WEPENT_SET_NORMAL, \ + { WriteByte(chan, this.m_gunalign); }, \ + { (viewmodels[this.m_wepent_slot]).m_gunalign = ReadByte(); }) \ \ /**/ -- 2.39.2