]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean out self use from the weapon selection code
authorMario <mario@smbclan.net>
Sat, 21 May 2016 22:37:00 +0000 (08:37 +1000)
committerMario <mario@smbclan.net>
Sat, 21 May 2016 22:37:00 +0000 (08:37 +1000)
qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
qcsrc/common/mutators/mutator/nix/nix.qc
qcsrc/server/cl_impulse.qc
qcsrc/server/defs.qh
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/selection.qh
qcsrc/server/weapons/throwing.qc
qcsrc/server/weapons/weaponsystem.qc

index dd844e77ea5231a5e01172c53ec6198ff196366c..184055d55b23ec670939a763b842cf3c354a25ca 100644 (file)
@@ -188,7 +188,7 @@ void GiveBall(entity plyr, entity ball)
        Weapon w = WEP_NEXBALL;
        w.wr_resetplayer(w);
        PS(plyr).m_switchweapon = WEP_NEXBALL;
-       W_SwitchWeapon(WEP_NEXBALL);
+       W_SwitchWeapon(plyr, WEP_NEXBALL);
        setself(this);
 }
 
@@ -985,7 +985,7 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                                Weapon w = WEP_NEXBALL;
                                w.wr_resetplayer(w);
                                PS(self).m_switchweapon = self.(weaponentity).m_switchweapon;
-                               W_SwitchWeapon(PS(self).m_switchweapon);
+                               W_SwitchWeapon(self, PS(self).m_switchweapon);
 
                                self.(weaponentity).weapons = '0 0 0';
                        }
index 0b6908a8b31ed512f35330ea13c85110cf712b0b..0c18993db0514b574a4759b219c919d2c55bec85 100644 (file)
@@ -209,7 +209,7 @@ void NIX_GiveCurrentWeapon()
                if(!client_hasweapon(self, PS(self).m_switchweapon, true, false))
                {
                        if(client_hasweapon(self, w, true, false))
-                               W_SwitchWeapon(w);
+                               W_SwitchWeapon(self, w);
                }
 }
 
index 3d0ab995c91582681c553da87525cf7fa7b2212b..251c6921e423b2fbc0f5bc78f97ab12a999864fb 100644 (file)
@@ -61,7 +61,7 @@
                        this.impulse = IMP_weapon_group_##slot.impulse; \
                        return; \
                } \
-               W_NextWeaponOnImpulse(slot); \
+               W_NextWeaponOnImpulse(this, slot); \
        }
 X(1)
 X(2)
@@ -89,7 +89,7 @@ X(0)
                noref int prev = -1; \
                noref int best =  0; \
                noref int next = +1; \
-               W_CycleWeapon(this.cvar_cl_weaponpriorities[slot], dir); \
+               W_CycleWeapon(this, this.cvar_cl_weaponpriorities[slot], dir); \
        }
 X(0, prev)
 X(1, prev)
@@ -136,7 +136,7 @@ X(9, next)
                        this.impulse = IMP_weapon_byid_##i.impulse; \
                        return; \
                } \
-               W_SwitchWeapon(Weapons_from(WEP_FIRST + i)); \
+               W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i)); \
        }
 X(0)
 X(1)
@@ -172,7 +172,7 @@ IMPULSE(weapon_next_byid)
                this.impulse = IMP_weapon_next_byid.impulse;
                return;
        }
-       W_NextWeapon(0);
+       W_NextWeapon(this, 0);
 }
 
 IMPULSE(weapon_prev_byid)
@@ -183,7 +183,7 @@ IMPULSE(weapon_prev_byid)
                this.impulse = IMP_weapon_prev_byid.impulse;
                return;
        }
-       W_PreviousWeapon(0);
+       W_PreviousWeapon(this, 0);
 }
 
 IMPULSE(weapon_next_bygroup)
@@ -194,7 +194,7 @@ IMPULSE(weapon_next_bygroup)
                this.impulse = IMP_weapon_next_bygroup.impulse;
                return;
        }
-       W_NextWeapon(1);
+       W_NextWeapon(this, 1);
 }
 
 IMPULSE(weapon_prev_bygroup)
@@ -205,7 +205,7 @@ IMPULSE(weapon_prev_bygroup)
                this.impulse = IMP_weapon_prev_bygroup.impulse;
                return;
        }
-       W_PreviousWeapon(1);
+       W_PreviousWeapon(this, 1);
 }
 
 IMPULSE(weapon_next_bypriority)
@@ -216,7 +216,7 @@ IMPULSE(weapon_next_bypriority)
                this.impulse = IMP_weapon_next_bypriority.impulse;
                return;
        }
-       W_NextWeapon(2);
+       W_NextWeapon(this, 2);
 }
 
 IMPULSE(weapon_prev_bypriority)
@@ -227,7 +227,7 @@ IMPULSE(weapon_prev_bypriority)
                this.impulse = IMP_weapon_prev_bypriority.impulse;
                return;
        }
-       W_PreviousWeapon(2);
+       W_PreviousWeapon(this, 2);
 }
 
 IMPULSE(weapon_last)
@@ -241,7 +241,7 @@ IMPULSE(weapon_best)
 {
        if (this.vehicle) return;
        if (IS_DEAD(this)) return;
-       W_SwitchWeapon(w_getbestweapon(this));
+       W_SwitchWeapon(this, w_getbestweapon(this));
 }
 
 IMPULSE(weapon_drop)
index 1ad60e8685c844bf7a7980e1635c4a3d7cd22d6c..fd6bf729366cbe628798e20eaf3bcc01bc57cb2f 100644 (file)
@@ -130,7 +130,7 @@ const float MAX_DAMAGEEXTRARADIUS = 16;
 
 // WEAPONTODO
 .float autoswitch;
-bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain);
+bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain);
 void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire);
 void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire);
 // VorteX: standalone think for weapons, so normal think on weaponentity can be reserved by weaponflashes (which needs update even player dies)
index 27d35643de1415f389a6ed61819ce3f22983e69c..18dc4001a9683999d41015a59c18fef931c4077e 100644 (file)
@@ -40,43 +40,42 @@ void Weapon_whereis(Weapon this, entity cl)
        }
 }
 
-bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain)
+bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain)
 {
-    SELFPARAM();
        float f = 0;
 
-       if (time < cl.hasweapon_complain_spam)
+       if (time < this.hasweapon_complain_spam)
                complain = 0;
 
        // ignore hook button when using other offhand equipment
-       if (cl.offhand != OFFHAND_HOOK)
-       if (wpn == WEP_HOOK && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
+       if (this.offhand != OFFHAND_HOOK)
+       if (wpn == WEP_HOOK && !((this.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
            complain = 0;
 
        if (complain)
-               cl.hasweapon_complain_spam = time + 0.2;
+               this.hasweapon_complain_spam = time + 0.2;
 
        if (wpn == WEP_Null)
        {
                if (complain)
-                       sprint(cl, "Invalid weapon\n");
+                       sprint(this, "Invalid weapon\n");
                return false;
        }
-       if (cl.weapons & WepSet_FromWeapon(wpn))
+       if (this.weapons & WepSet_FromWeapon(wpn))
        {
                if (andammo)
                {
-                       if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
+                       if(this.items & IT_UNLIMITED_WEAPON_AMMO)
                        {
                                f = 1;
                        }
                        else
                        {
-                               WITHSELF(cl, f = wpn.wr_checkammo1(wpn) + wpn.wr_checkammo2(wpn));
+                               WITHSELF(this, f = wpn.wr_checkammo1(wpn) + wpn.wr_checkammo2(wpn));
 
                                // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
                                if(wpn == WEP_MINE_LAYER)
-                                       FOREACH_ENTITY_CLASS("mine", it.owner == cl,
+                                       FOREACH_ENTITY_CLASS("mine", it.owner == this,
                                        {
                                                f = 1;
                                                break; // no need to continue
@@ -85,10 +84,10 @@ bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain)
                        if (!f)
                        {
                                if (complain)
-                               if(IS_REAL_CLIENT(cl))
+                               if(IS_REAL_CLIENT(this))
                                {
-                                       play2(cl, SND(UNAVAILABLE));
-                                       Send_WeaponComplain (cl, wpn.m_id, 0);
+                                       play2(this, SND(UNAVAILABLE));
+                                       Send_WeaponComplain (this, wpn.m_id, 0);
                                }
                                return false;
                        }
@@ -101,21 +100,21 @@ bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain)
                // Report Proper Weapon Status / Modified Weapon Ownership Message
                if (weaponsInMap & WepSet_FromWeapon(wpn))
                {
-                       Send_WeaponComplain(cl, wpn.m_id, 1);
-                       Weapon_whereis(wpn, cl);
+                       Send_WeaponComplain(this, wpn.m_id, 1);
+                       Weapon_whereis(wpn, this);
                }
                else
                {
-                       Send_WeaponComplain (cl, wpn.m_id, 2);
+                       Send_WeaponComplain (this, wpn.m_id, 2);
                }
 
-               play2(cl, SND(UNAVAILABLE));
+               play2(this, SND(UNAVAILABLE));
        }
        return false;
 }
 
-float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
-{SELFPARAM();
+float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing)
+{
        // We cannot tokenize in this function, as GiveItems calls this
        // function. Thus we must use car/cdr.
        float weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
@@ -125,10 +124,10 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
        float weaponcur;
        entity wep;
 
-       if(skipmissing || pl.selectweapon == 0)
-               weaponcur = PS(pl).m_switchweapon.m_id;
+       if(skipmissing || this.selectweapon == 0)
+               weaponcur = PS(this).m_switchweapon.m_id;
        else
-               weaponcur = pl.selectweapon;
+               weaponcur = this.selectweapon;
 
        if(dir == 0)
                switchtonext = 1;
@@ -149,19 +148,19 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                FOREACH(Weapons, it != WEP_Null, {
                        if(i != weaponwant)
                        if(it.impulse == imp || imp < 0)
-                       if((pl.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset)))
+                       if((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset)))
                                have_other = true;
                });
 
                // skip weapons we don't own that aren't normal and aren't in the map
-               if(!(pl.weapons & wepset))
+               if(!(this.weapons & wepset))
                if(!(weaponsInMap & wepset))
                if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
                        continue;
 
                ++c;
 
-               if(!skipmissing || client_hasweapon(pl, wep, true, false))
+               if(!skipmissing || client_hasweapon(this, wep, true, false))
                {
                        if(switchtonext)
                                return weaponwant;
@@ -189,8 +188,8 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
        // complain (but only for one weapon on the button that has been pressed)
        if(complain)
        {
-               self.weaponcomplainindex += 1;
-               c = (self.weaponcomplainindex % c) + 1;
+               this.weaponcomplainindex += 1;
+               c = (this.weaponcomplainindex % c) + 1;
                rest = weaponorder;
                while(rest != "")
                {
@@ -205,12 +204,12 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                        FOREACH(Weapons, it != WEP_Null, {
                                if(i != weaponwant)
                                if(it.impulse == imp || imp < 0)
-                               if((pl.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset)))
+                               if((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset)))
                                        have_other = true;
                        });
 
                        // skip weapons we don't own that aren't normal and aren't in the map
-                       if(!(pl.weapons & wepset))
+                       if(!(this.weapons & wepset))
                        if(!(weaponsInMap & wepset))
                        if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
                                continue;
@@ -218,7 +217,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                        --c;
                        if(c == 0)
                        {
-                               client_hasweapon(pl, wep, true, true);
+                               client_hasweapon(this, wep, true, true);
                                break;
                        }
                }
@@ -235,77 +234,77 @@ void W_SwitchWeapon_Force(Player this, Weapon wep)
 }
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
-void W_SwitchToOtherWeapon(entity pl)
+void W_SwitchToOtherWeapon(entity this)
 {
        // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
        Weapon ww;
-       WepSet set = WepSet_FromWeapon(PS(pl).m_weapon);
-       if (pl.weapons & set)
+       WepSet set = WepSet_FromWeapon(PS(this).m_weapon);
+       if (this.weapons & set)
        {
-               pl.weapons &= ~set;
-               ww = w_getbestweapon(pl);
-               pl.weapons |= set;
+               this.weapons &= ~set;
+               ww = w_getbestweapon(this);
+               this.weapons |= set;
        }
        else
        {
-               ww = w_getbestweapon(pl);
+               ww = w_getbestweapon(this);
        }
        if (ww == WEP_Null) return;
-       W_SwitchWeapon_Force(pl, ww);
+       W_SwitchWeapon_Force(this, ww);
 }
 
-void W_SwitchWeapon(Weapon w)
-{SELFPARAM();
-       if (PS(self).m_switchweapon != w)
+void W_SwitchWeapon(entity this, Weapon w)
+{
+       if (PS(this).m_switchweapon != w)
        {
-               if (client_hasweapon(self, w, true, true))
-                       W_SwitchWeapon_Force(self, w);
+               if (client_hasweapon(this, w, true, true))
+                       W_SwitchWeapon_Force(this, w);
                else
-                       self.selectweapon = w.m_id; // update selectweapon ANYWAY
+                       this.selectweapon = w.m_id; // update selectweapon ANYWAY
        }
-       else if(!forbidWeaponUse(self)) {
+       else if(!forbidWeaponUse(this)) {
                entity actor = this;
                .entity weaponentity = weaponentities[0]; // TODO: unhardcode
                w.wr_reload(w, actor, weaponentity);
        }
 }
 
-void W_CycleWeapon(string weaponorder, float dir)
-{SELFPARAM();
+void W_CycleWeapon(entity this, string weaponorder, float dir)
+{
        float w;
-       w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
+       w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true);
        if(w > 0)
-               W_SwitchWeapon(Weapons_from(w));
+               W_SwitchWeapon(this, Weapons_from(w));
 }
 
-void W_NextWeaponOnImpulse(float imp)
-{SELFPARAM();
+void W_NextWeaponOnImpulse(entity this, float imp)
+{
        float w;
-       w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
+       w = W_GetCycleWeapon(this, this.cvar_cl_weaponpriority, +1, imp, 1, (this.cvar_cl_weaponimpulsemode == 0));
        if(w > 0)
-               W_SwitchWeapon(Weapons_from(w));
+               W_SwitchWeapon(this, Weapons_from(w));
 }
 
 // next weapon
-void W_NextWeapon(float list)
-{SELFPARAM();
+void W_NextWeapon(entity this, int list)
+{
        if(list == 0)
-               W_CycleWeapon(weaponorder_byid, -1);
+               W_CycleWeapon(this, weaponorder_byid, -1);
        else if(list == 1)
-               W_CycleWeapon(self.weaponorder_byimpulse, -1);
+               W_CycleWeapon(this, this.weaponorder_byimpulse, -1);
        else if(list == 2)
-               W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
+               W_CycleWeapon(this, this.cvar_cl_weaponpriority, -1);
 }
 
 // prev weapon
-void W_PreviousWeapon(float list)
-{SELFPARAM();
+void W_PreviousWeapon(entity this, float list)
+{
        if(list == 0)
-               W_CycleWeapon(weaponorder_byid, +1);
+               W_CycleWeapon(this, weaponorder_byid, +1);
        else if(list == 1)
-               W_CycleWeapon(self.weaponorder_byimpulse, +1);
+               W_CycleWeapon(this, this.weaponorder_byimpulse, +1);
        else if(list == 2)
-               W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
+               W_CycleWeapon(this, this.cvar_cl_weaponpriority, +1);
 }
 
 // previously used if exists and has ammo, (second) best otherwise
@@ -313,7 +312,7 @@ void W_LastWeapon(entity this)
 {
        Weapon wep = Weapons_from(this.cnt);
        if (client_hasweapon(this, wep, true, false))
-               W_SwitchWeapon(wep);
+               W_SwitchWeapon(this, wep);
        else
                W_SwitchToOtherWeapon(this);
 }
index 07f27f5b5d2f17e4c99f298caf3552090130beaa..0c30b7c1215040fd7bc2de7256f0dcd67b6095fc 100644 (file)
@@ -4,28 +4,28 @@
 void Send_WeaponComplain(entity e, float wpn, float type);
 
 .float hasweapon_complain_spam;
-bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain);
+bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain);
 
 .int weaponcomplainindex;
-float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing);
+float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing);
 
 #define w_getbestweapon(ent) Weapons_from(W_GetCycleWeapon(ent, ent.cvar_cl_weaponpriority, 0, -1, false, true))
 
 void W_SwitchWeapon_Force(Player this, Weapon w);
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
-void W_SwitchToOtherWeapon(entity pl);
-void W_SwitchWeapon(Weapon imp);
+void W_SwitchToOtherWeapon(entity this);
+void W_SwitchWeapon(entity this, Weapon imp);
 
-void W_CycleWeapon(string weaponorder, float dir);
+void W_CycleWeapon(entity this, string weaponorder, float dir);
 
-void W_NextWeaponOnImpulse(float imp);
+void W_NextWeaponOnImpulse(entity this, float imp);
 
 // next weapon
-void W_NextWeapon(float list);
+void W_NextWeapon(entity this, float list);
 
 // prev weapon
-void W_PreviousWeapon(float list);
+void W_PreviousWeapon(entity this, float list);
 
 // previously used if exists and has ammo, (second) best otherwise
 void W_LastWeapon(entity this);
index 43285fb6a32c74e5dbe588026aa9c405069f16a0..b05405de4006b54d7c161d9dadb3f921a2f50205 100644 (file)
 
 void thrown_wep_think()
 {SELFPARAM();
-       self.nextthink = time;
-       if(self.oldorigin != self.origin)
+       this.nextthink = time;
+       if(this.oldorigin != this.origin)
        {
-               self.SendFlags |= ISF_LOCATION;
-               self.oldorigin = self.origin;
+               this.SendFlags |= ISF_LOCATION;
+               this.oldorigin = this.origin;
        }
-       self.owner = world;
-       float timeleft = self.savenextthink - time;
+       this.owner = world;
+       float timeleft = this.savenextthink - time;
        if(timeleft > 1)
-               SUB_SetFade(self, self.savenextthink - 1, 1);
+               SUB_SetFade(this, this.savenextthink - 1, 1);
        else if(timeleft > 0)
-               SUB_SetFade(self, time, timeleft);
+               SUB_SetFade(this, time, timeleft);
        else
-               SUB_VanishOrRemove(self);
+               SUB_VanishOrRemove(this);
 }
 
 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
index 53d421ab6fdfcd3a47dfb7e79a65057a61d31983..94805a59b36cfaf0cbe2b522ac143ff6f900a0fb 100644 (file)
@@ -545,7 +545,7 @@ void W_WeaponFrame(Player actor)
                        else
                        {
                                if (key_pressed && PS(actor).m_switchweapon != WEP_HOOK && !actor.hook_switchweapon)
-                                       W_SwitchWeapon(WEP_HOOK);
+                                       W_SwitchWeapon(actor, WEP_HOOK);
                                actor.hook_switchweapon = key_pressed;
                                Weapon h = WEP_HOOK;
                                block_weapon = (PS(actor).m_weapon == h && (PHYS_INPUT_BUTTON_ATCK(actor) || key_pressed));