From fccc8baa9f35ff2d7ec7aa4ecab6d348a53a180e Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 9 Oct 2016 12:59:33 +1000 Subject: [PATCH] Move networked wepent to a separate entity (fixes server side stuff like nades and flashes) --- qcsrc/common/mutators/mutator/nades/nades.qc | 7 +++- qcsrc/common/wepent.qc | 41 +++++++++++--------- qcsrc/common/wepent.qh | 2 - qcsrc/server/player.qc | 8 ++-- qcsrc/server/weapons/weaponsystem.qc | 18 ++++----- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index edfe7f41f..c9b22a282 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -891,7 +891,7 @@ void toss_nade(entity e, bool set_owner, vector _velocity, float _time) makevectors(e.v_angle); // NOTE: always throw from first weapon entity? - W_SetupShot(e, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0); + W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0); Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES); @@ -1033,6 +1033,8 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin if(Nades_from(n.nade_type) == NADE_TYPE_Null) n.nade_type = NADE_TYPE_NORMAL.m_id; + .entity weaponentity = weaponentities[0]; // TODO: unhardcode + setmodel(n, MDL_PROJECTILE_NADE); //setattachment(n, player, "bip01 l hand"); n.exteriormodeltoclient = player; @@ -1047,9 +1049,9 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin setthink(n, nade_beep); n.nextthink = max(n.wait - 3, time); n.projectiledeathtype = DEATH_NADE.m_id; + n.weaponentity_fld = weaponentity; setmodel(fn, MDL_NADE_VIEW); - .entity weaponentity = weaponentities[0]; // TODO: unhardcode setattachment(fn, player.(weaponentity), ""); fn.realowner = fn.owner = player; fn.colormod = Nades_from(n.nade_type).m_color; @@ -1057,6 +1059,7 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin fn.glowmod = player.glowmod; setthink(fn, SUB_Remove); fn.nextthink = n.wait; + fn.weaponentity_fld = weaponentity; player.nade = n; player.fake_nade = fn; diff --git a/qcsrc/common/wepent.qc b/qcsrc/common/wepent.qc index 886ff8796..b9bcb737d 100644 --- a/qcsrc/common/wepent.qc +++ b/qcsrc/common/wepent.qc @@ -10,19 +10,6 @@ MACRO_END var = strzone(x); \ MACRO_END -#ifdef SVQC - .int w_sv_entnum; - .Weapon w_m_switchweapon; - .Weapon w_m_switchingweapon; - .Weapon w_m_weapon; - //.float w_weapon_nextthink; - .float w_m_alpha; - .float w_vortex_charge; - .int w_m_gunalign; - .bool w_porto_v_angle_held; - .int w_tuba_instrument; -#endif - // #define PROP(public, fld, set, sv, cl) #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \ PROP(false, m_switchweapon, WEPENT_SET_NORMAL, \ @@ -88,7 +75,7 @@ MACRO_END WriteHeader(chan, ENT_CLIENT_WEPENT); else WriteHeader(chan, CLIENT_WEPENT); - .entity weaponentity = this.weaponentity_fld; + .entity weaponentity = this.owner.weaponentity_fld; WriteByte(chan, weaponslot(weaponentity)); WriteShort(chan, sf); int i = 0; @@ -108,12 +95,22 @@ MACRO_END return _wepent_send(this, to, sf, MSG_ENTITY); } - void wepent_update(entity this) + void wepent_think(entity this) { + if(wasfreed(this.owner) || !this.owner) + { + delete(this); + return; + } + + this.nextthink = time; + + entity o = this.owner; + int i = 0; #define X(public, fld, set, sv, cl) { \ - if (this.w_##fld != this.fld) { \ - set(this.w_##fld, this.fld); \ + if (this.fld != o.fld) { \ + set(this.fld, o.fld); \ this.SendFlags |= BIT(i); \ } \ i += 1; \ @@ -124,7 +121,11 @@ MACRO_END void wepent_link(entity wep) { - Net_LinkEntity(wep, false, 0, wepent_send); + entity e = new(wepent_sender); + e.owner = wep; + setthink(e, wepent_think); + e.nextthink = time; + Net_LinkEntity(e, false, 0, wepent_send); } #endif @@ -133,7 +134,9 @@ MACRO_END bool ReadWepent(entity this) { - this.m_wepent_slot = ReadByte(); + int slot = ReadByte(); + this.m_wepent_slot = slot; + viewmodels[slot].m_wepent_slot = slot; int sf = ReadShort(); int i = 0; #define X(public, fld, set, sv, cl) { \ diff --git a/qcsrc/common/wepent.qh b/qcsrc/common/wepent.qh index ee4209256..46180d7c0 100644 --- a/qcsrc/common/wepent.qh +++ b/qcsrc/common/wepent.qh @@ -10,8 +10,6 @@ REGISTER_NET_TEMP(CLIENT_WEPENT) bool wepent_send(entity this, entity to, int sf); - void wepent_update(entity this); - void wepent_link(entity wep); .int m_forceupdate; diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index 8aa67fc06..1656ff003 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -566,8 +566,8 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, Weapon wep = this.(weaponentity).m_weapon; for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { - .entity wepent = weaponentities[slot]; - wep.wr_playerdeath(wep, this, wepent); + .entity went = weaponentities[slot]; + wep.wr_playerdeath(wep, this, went); } RemoveGrapplingHooks(this); @@ -594,8 +594,8 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, // throw a weapon for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { - .entity wepent = weaponentities[slot]; - SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, this.(wepent).m_switchweapon.m_id, wepent); + .entity went = weaponentities[slot]; + SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, this.(went).m_switchweapon.m_id, went); } // become fully visible diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 3b51adb99..0d26aaa40 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -108,15 +108,13 @@ void CL_Weaponentity_Think(entity this) this.weaponchild.alpha = this.alpha; this.weaponchild.effects = this.effects; } - - wepent_update(this); } void CL_ExteriorWeaponentity_Think(entity this) { this.nextthink = time; .entity weaponentity = this.weaponentity_fld; - entity wepent = this.owner.(weaponentity); + entity w_ent = this.owner.(weaponentity); if (this.owner.exteriorweaponentity != this) { delete(this); @@ -127,15 +125,15 @@ void CL_ExteriorWeaponentity_Think(entity this) this.model = ""; return; } - if (this.weaponname != wepent.weaponname || this.dmg != wepent.modelindex - || this.deadflag != wepent.deadflag) + if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex + || this.deadflag != w_ent.deadflag) { - this.weaponname = wepent.weaponname; - this.dmg = wepent.modelindex; - this.deadflag = wepent.deadflag; - if (wepent.weaponname != "") + this.weaponname = w_ent.weaponname; + this.dmg = w_ent.modelindex; + this.deadflag = w_ent.deadflag; + if (w_ent.weaponname != "") { - _setmodel(this, W_Model(strcat("v_", wepent.weaponname, ".md3"))); + _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3"))); setsize(this, '0 0 0', '0 0 0'); } else this.model = ""; -- 2.39.2