]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'Mario/wepgroup_switch' into 'master'
authorMario <zacjardine@y7mail.com>
Wed, 17 Oct 2018 14:55:39 +0000 (14:55 +0000)
committerMario <zacjardine@y7mail.com>
Wed, 17 Oct 2018 14:55:39 +0000 (14:55 +0000)
Merge branch Mario/wepgroup_switch

See merge request xonotic/xonotic-data.pk3dir!611

qcsrc/server/impulse.qc
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/selection.qh

index cce5963990893d7a4178e8b7d5e0ddd7895b886e..8a17ef6a1dd44abfca2b064b20434285a5df1054 100644 (file)
@@ -149,7 +149,7 @@ X(9, next)
                for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) \
                { \
                        .entity weaponentity = weaponentities[slot]; \
-                       W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i), weaponentity); \
+                       W_SwitchWeapon_TryOthers(this, Weapons_from(WEP_FIRST + i), weaponentity); \
                        if(slot == 0 && autocvar_g_weaponswitch_debug != 1) \
                                break; \
                } \
index 4af13e10228d101f414d61feae9ad9b4adb9b132..5912261dbf68cf6bca6a47ce8e86db480c2cd2b9 100644 (file)
@@ -266,20 +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(!W_SwitchWeapon(this, w, weaponentity))
+               W_NextWeaponOnImpulse(this, w.impulse, weaponentity);
 }
 
 void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity)
index eea33ddb7b98e71c762a7fc09f9d7f41856c7558..dd21e6419da58f6772f3f541f18c588e782b71d1 100644 (file)
@@ -18,7 +18,8 @@ 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);