]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move networked wepent to a separate entity (fixes server side stuff like nades and...
authorMario <mario@smbclan.net>
Sun, 9 Oct 2016 02:59:33 +0000 (12:59 +1000)
committerMario <mario@smbclan.net>
Sun, 9 Oct 2016 02:59:33 +0000 (12:59 +1000)
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/wepent.qc
qcsrc/common/wepent.qh
qcsrc/server/player.qc
qcsrc/server/weapons/weaponsystem.qc

index edfe7f41fc1ad00756c226d02b8b6c2dcc0a85a1..c9b22a28289b0503138f8530c0132ac34a8ac5fe 100644 (file)
@@ -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;
index 886ff879633d2f2dd4e5d8c45c69e0fdf6f8bc34..b9bcb737dae14e2c6cd31b311eca0e067531d1a2 100644 (file)
@@ -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) { \
index ee420925692f9dcc9dfc3906c938b09e4c638b41..46180d7c0b4e2c82fe02ee5fb6f6e1e8b8234c0d 100644 (file)
@@ -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;
index 8aa67fc0643bc5c3734e74fb145cde4a8eac72bc..1656ff003b873e10d681b9baaf6370dec8aefbee 100644 (file)
@@ -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
index 3b51adb9986fa511b556321f36d7563ae1d8119c..0d26aaa403ca4c3d4b6a394846deb6b0a71c3944 100644 (file)
@@ -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 = "";