]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reuse W_SwitchWeapon to reduce code duplication 611/head
authorMario <mario@smbclan.net>
Fri, 12 Oct 2018 19:52:06 +0000 (05:52 +1000)
committerMario <mario@smbclan.net>
Fri, 12 Oct 2018 19:52:06 +0000 (05:52 +1000)
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/selection.qh

index baee4ac532888599a7e3ff786bbeceb8363e6a60..5912261dbf68cf6bca6a47ce8e86db480c2cd2b9 100644 (file)
@@ -266,39 +266,34 @@ void W_SwitchToOtherWeapon(entity this, .entity weaponentity)
        W_SwitchWeapon_Force(this, ww, weaponentity);
 }
 
-void W_SwitchWeapon(entity this, Weapon w, .entity weaponentity)
+bool W_SwitchWeapon(entity this, Weapon w, .entity weaponentity)
 {
        if(this.(weaponentity).m_switchweapon != w)
        {
                if(client_hasweapon(this, w, weaponentity, true, true))
+               {
                        W_SwitchWeapon_Force(this, w, weaponentity);
+                       return true;
+               }
                else
+               {
                        this.(weaponentity).selectweapon = w.m_id; // update selectweapon anyway
+                       return false;
+               }
        }
        else if(!forbidWeaponUse(this))
        {
                entity actor = this;
                w.wr_reload(w, actor, weaponentity);
        }
+
+       return true; // player already has the weapon out or needs to reload
 }
 
 void W_SwitchWeapon_TryOthers(entity this, Weapon w, .entity weaponentity)
 {
-       if(this.(weaponentity).m_switchweapon != w)
-       {
-               if(client_hasweapon(this, w, weaponentity, true, true)) // NOTE: still complains
-                       W_SwitchWeapon_Force(this, w, weaponentity);
-               else
-               {
-                       this.(weaponentity).selectweapon = w.m_id; // update selectweapon anyway
-                       W_NextWeaponOnImpulse(this, w.impulse, weaponentity);
-               }
-       }
-       else if(!forbidWeaponUse(this))
-       {
-               entity actor = this;
-               w.wr_reload(w, actor, weaponentity);
-       }
+       if(!W_SwitchWeapon(this, w, weaponentity))
+               W_NextWeaponOnImpulse(this, w.impulse, weaponentity);
 }
 
 void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity)
index 156c37f2629528f91e750303eecad20d34cd87e6..dd21e6419da58f6772f3f541f18c588e782b71d1 100644 (file)
@@ -18,7 +18,7 @@ void W_SwitchWeapon_Force(Player this, Weapon w, .entity weaponentity);
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
 void W_SwitchToOtherWeapon(entity this, .entity weaponentity);
-void W_SwitchWeapon(entity this, Weapon imp, .entity weaponentity);
+bool W_SwitchWeapon(entity this, Weapon imp, .entity weaponentity); // returns false if the player does not have the weapon
 void W_SwitchWeapon_TryOthers(entity this, Weapon imp, .entity weaponentity);
 
 void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity);