]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Weapons: require explicit `Weapons_from` call
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 7 Dec 2015 10:03:52 +0000 (21:03 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 7 Dec 2015 10:03:52 +0000 (21:03 +1100)
19 files changed:
qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
qcsrc/common/mutators/mutator/nix/nix.qc
qcsrc/common/mutators/mutator/overkill/hmg.qc
qcsrc/common/weapons/weapon/arc.qc
qcsrc/common/weapons/weapon/hlac.qc
qcsrc/common/weapons/weapon/hook.qc
qcsrc/common/weapons/weapon/machinegun.qc
qcsrc/common/weapons/weapon/shotgun.qc
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/bot/scripting.qc
qcsrc/server/cl_impulse.qc
qcsrc/server/defs.qh
qcsrc/server/g_damage.qc
qcsrc/server/g_damage.qh
qcsrc/server/t_items.qc
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/selection.qh
qcsrc/server/weapons/throwing.qc
qcsrc/server/weapons/weaponsystem.qc

index cc418df5e4da015f0a5600a41c6b66f5232ed58d..2206df7c695d00ae25f493fbdd9f4eadeacf6121 100644 (file)
@@ -186,7 +186,7 @@ void GiveBall(entity plyr, entity ball)
        Weapon w = WEP_NEXBALL;
        w.wr_resetplayer(w);
        plyr.switchweapon = WEP_NEXBALL.m_id;
-       W_SwitchWeapon(WEP_NEXBALL.m_id);
+       W_SwitchWeapon(WEP_NEXBALL);
        setself(this);
 }
 
@@ -972,7 +972,7 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                                Weapon w = WEP_NEXBALL;
                                w.wr_resetplayer(w);
                                self.switchweapon = self.(weaponentity).switchweapon;
-                               W_SwitchWeapon(self.switchweapon);
+                               W_SwitchWeapon(Weapons_from(self.switchweapon));
 
                                self.(weaponentity).weapons = '0 0 0';
                        }
index a07ad44cac4a25d6d96959810a5324c4f9d5b077..68f4dfaa875236a01d1203d0377852720af3dbed 100644 (file)
@@ -68,7 +68,7 @@ REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill"
                        e.ammo_rockets = start_ammo_rockets;
                        e.ammo_fuel = start_ammo_fuel;
                        e.weapons = start_weapons;
-                       if(!client_hasweapon(e, e.weapon, true, false))
+                       if(!client_hasweapon(e, Weapons_from(e.weapon), true, false))
                                e.switchweapon = w_getbestweapon(self);
                }
        }
@@ -211,9 +211,12 @@ void NIX_GiveCurrentWeapon()
        self.weapons |= e.m_wepset;
 
        if(self.switchweapon != nix_weapon)
-               if(!client_hasweapon(self, self.switchweapon, true, false))
-                       if(client_hasweapon(self, nix_weapon, true, false))
-                               W_SwitchWeapon(nix_weapon);
+               if(!client_hasweapon(self, Weapons_from(self.switchweapon), true, false))
+               {
+                       Weapon w = Weapons_from(nix_weapon);
+                       if(client_hasweapon(self, w, true, false))
+                               W_SwitchWeapon(w);
+               }
 }
 
 MUTATOR_HOOKFUNCTION(nix, ForbidThrowCurrentWeapon)
index 8341f7c71d4230faa24cf86286e3f29a742f7c7b..6112f89ddfe17e29098150044d4094fe3da8235d 100644 (file)
@@ -64,7 +64,7 @@ void W_HeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weapone
        if(!thiswep.wr_checkammo1(thiswep))
        if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
        {
-               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+               W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                w_ready(thiswep, actor, weaponentity, fire);
                return;
        }
index 7c9d64c01abed4d09077f4a29d2e0546dee57ac2..4a15cc6c7f1a90bc0af1fd2bfccd8cafda7db1d5 100644 (file)
@@ -749,7 +749,7 @@ void Arc_Smoke()
                }
                METHOD(Arc, wr_pickup, void(entity thiswep))
                {
-                       if ( !client_hasweapon(self, WEP_ARC.m_id, false, false) &&
+                       if ( !client_hasweapon(self, thiswep, false, false) &&
                                weapon_dropevent_item.arc_overheat > time )
                        {
                                self.arc_overheat = weapon_dropevent_item.arc_overheat;
index f99c700735d358e79d089f11c1b0f2c8fc66cdc2..3f52224897196c305fd57c956f8586b575d7f692 100644 (file)
@@ -172,7 +172,7 @@ void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int
                if(!thiswep.wr_checkammo1(thiswep))
                if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                {
-                       W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+                       W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                        w_ready(thiswep, actor, weaponentity, fire);
                        return;
                }
index 4e3722f138032c5aefbe1512923864901c48bbf7..3cc55e2ae31363058062379191415df3dc5caef9 100644 (file)
@@ -240,7 +240,7 @@ void W_Hook_Attack2(Weapon thiswep, entity actor)
                                                        {
                                                                actor.ammo_fuel = 0;
                                                                actor.hook_state |= HOOK_REMOVING;
-                                                               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+                                                               W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                                                        }
                                                }
                                        }
index 7e79bc929f4c4538d0d7e9c8f89c93ef8e4f01ef..1f8273748c47b1145bcd5c148b5d0df817193715 100644 (file)
@@ -149,7 +149,7 @@ void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentit
                if(!thiswep.wr_checkammo2(thiswep))
                if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                {
-                       W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+                       W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                        w_ready(thiswep, actor, weaponentity, fire);
                        return;
                }
@@ -175,7 +175,7 @@ void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity
        if(!thiswep.wr_checkammo1(thiswep))
        if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
        {
-               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+               W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                w_ready(thiswep, actor, weaponentity, fire);
                return;
        }
@@ -267,7 +267,7 @@ void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentit
                                        if(!thiswep.wr_checkammo2(thiswep))
                                        if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                                        {
-                                               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+                                               W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                                                w_ready(thiswep, actor, weaponentity, fire);
                                                return;
                                        }
index c50eff100e81f04bb69551bc54d1eae0c6bc3af6..27dfe4e4f6e096b0e191198c2cddb104eefb496a 100644 (file)
@@ -200,7 +200,7 @@ void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity
        if (!thiswep.wr_checkammo2(thiswep))
        if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
        {
-               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+               W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                w_ready(thiswep, actor, weaponentity, fire);
                return;
        }
@@ -214,7 +214,7 @@ void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity
        if (!thiswep.wr_checkammo2(thiswep))
        if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
        {
-               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+               W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                w_ready(thiswep, actor, weaponentity, fire);
                return;
        }
index 9a74d38415aa6b545fcb646b8f1ed25da238be0b..8cb4a31689626b812f9fe6b6ade9d437a1eaf8ea 100644 (file)
@@ -603,7 +603,7 @@ void havocbot_movetogoal()
                else if(self.health>WEP_CVAR(devastator, damage)*0.5)
                {
                        if(self.velocity.z < 0)
-                       if(client_hasweapon(self, WEP_DEVASTATOR.m_id, true, false))
+                       if(client_hasweapon(self, WEP_DEVASTATOR, true, false))
                        {
                                self.movement_x = maxspeed;
 
@@ -1025,7 +1025,7 @@ void havocbot_chooseweapon()
                if(self.weapon==0)
                for(i = WEP_FIRST; i <= WEP_LAST; ++i) if(i != WEP_BLASTER.m_id)
                {
-                       if(client_hasweapon(self, i, true, false))
+                       if(client_hasweapon(self, Weapons_from(i), true, false))
                        {
                                self.switchweapon = i;
                                return;
@@ -1071,7 +1071,7 @@ void havocbot_chooseweapon()
                if ( distance > bot_distance_far ) {
                        for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
                                w = bot_weapons_far[i];
-                               if ( client_hasweapon(self, w, true, false) )
+                               if ( client_hasweapon(self, Weapons_from(w), true, false) )
                                {
                                        if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
                                                continue;
@@ -1085,7 +1085,7 @@ void havocbot_chooseweapon()
                if ( distance > bot_distance_close) {
                        for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
                                w = bot_weapons_mid[i];
-                               if ( client_hasweapon(self, w, true, false) )
+                               if ( client_hasweapon(self, Weapons_from(w), true, false) )
                                {
                                        if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
                                                continue;
@@ -1098,7 +1098,7 @@ void havocbot_chooseweapon()
                // Choose weapons for close distance
                for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
                        w = bot_weapons_close[i];
-                       if ( client_hasweapon(self, w, true, false) )
+                       if ( client_hasweapon(self, Weapons_from(w), true, false) )
                        {
                                if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
                                        continue;
index b0348125e6cbb9a0ee05d573f045cd0e93bbaad4..96f7af3a1715f1702ec022aedc8baaf0122e6da3 100644 (file)
@@ -570,14 +570,12 @@ float bot_cmd_turn()
 
 float bot_cmd_select_weapon()
 {SELFPARAM();
-       float id;
-
-       id = bot_cmd.bot_cmd_parm_float;
+       float id = bot_cmd.bot_cmd_parm_float;
 
        if(id < WEP_FIRST || id > WEP_LAST)
                return CMD_STATUS_ERROR;
 
-       if(client_hasweapon(self, id, true, false))
+       if(client_hasweapon(self, Weapons_from(id), true, false))
                self.switchweapon = id;
        else
                return CMD_STATUS_ERROR;
index 1b08bb5716d7fc34adff38c4600c262d1ec64ad3..6598039dc7e85c695edfd5d8693c5bff0baad7d2 100644 (file)
@@ -121,7 +121,7 @@ X(9, next)
        { \
                if (this.vehicle) return; \
                if (this.deadflag != DEAD_NO) return; \
-               W_SwitchWeapon(WEP_FIRST + i); \
+               W_SwitchWeapon(Weapons_from(WEP_FIRST + i)); \
        }
 X(0)
 X(1)
@@ -202,7 +202,7 @@ IMPULSE(weapon_best)
 {
        if (this.vehicle) return;
        if (this.deadflag != DEAD_NO) return;
-       W_SwitchWeapon(w_getbestweapon(this));
+       W_SwitchWeapon(Weapons_from(w_getbestweapon(this)));
 }
 
 IMPULSE(weapon_drop)
index 62fec55feee4890ecd8b100eaa9b51ebb38ff5af..4bebdbfc14b5989ff92c96b41e247edd2da033d9 100644 (file)
@@ -144,7 +144,7 @@ const float MAX_DAMAGEEXTRARADIUS = 16;
 
 // WEAPONTODO
 .float autoswitch;
-float client_hasweapon(entity cl, float wpn, float andammo, float complain);
+bool client_hasweapon(entity cl, 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 dfabd9d3dc9758b24fbbe9b0a843c581685bfe4c..0e23d0828bcab192ddcb421af3834058b8ede882 100644 (file)
@@ -96,7 +96,7 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype)
 
                // after a frag, choose another random weapon set
                if (!(attacker.weapons & WepSet_FromWeapon(Weapons_from(attacker.weapon))))
-                       W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
+                       W_SwitchWeapon_Force(attacker, Weapons_from(w_getbestweapon(attacker)));
        }
 
        // FIXME fix the mess this is (we have REAL points now!)
index cee65e1643ad76bb00787468eeccb980d7115f14..fc8bf9c8f72b8e0d0d894721b8f5cbb6270963d3 100644 (file)
@@ -56,7 +56,7 @@ float IsFlying(entity a);
 void UpdateFrags(entity player, float f);
 
 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
-void W_SwitchWeapon_Force(entity e, float w);
+void W_SwitchWeapon_Force(entity e, Weapon w);
 entity GiveFrags_randomweapons;
 void GiveFrags (entity attacker, entity targ, float f, int deathtype);
 
index 97f63fc298db513777a5c84201a3e0738ede88b6..8d66501cd38cbb122e09d70ea667e95610d956ce 100644 (file)
@@ -710,13 +710,13 @@ float Item_GiveTo(entity item, entity player)
        // crude hack to enforce switching weapons
        if(g_cts && item.itemdef.instanceOfWeaponPickup)
        {
-               W_SwitchWeapon_Force(player, item.weapon);
+               W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
                return 1;
        }
 
        if (_switchweapon)
                if (player.switchweapon != w_getbestweapon(player))
-                       W_SwitchWeapon_Force(player, w_getbestweapon(player));
+                       W_SwitchWeapon_Force(player, Weapons_from(w_getbestweapon(player)));
 
        return 1;
 }
@@ -1816,7 +1816,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        if (!(e.weapons & WepSet_FromWeapon(Weapons_from(e.switchweapon))))
                _switchweapon = true;
        if(_switchweapon)
-               W_SwitchWeapon_Force(e, w_getbestweapon(e));
+               W_SwitchWeapon_Force(e, Weapons_from(w_getbestweapon(e)));
 
        return got;
 }
index b301da6f2e46ff7eb44cf0929fbce458b0537deb..737ddc8adcbf8e2c25ad3e14a1644f9bde97d450 100644 (file)
@@ -17,28 +17,28 @@ void Send_WeaponComplain(entity e, float wpn, float type)
        WriteByte(MSG_ONE, type);
 }
 
-float client_hasweapon(entity cl, float wpn, float andammo, float complain)
-{SELFPARAM();
+bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain)
+{
        float f;
 
-       if(time < self.hasweapon_complain_spam)
+       if (time < cl.hasweapon_complain_spam)
                complain = 0;
 
        // ignore hook button when using other offhand equipment
        if (cl.offhand != OFFHAND_HOOK)
-       if (wpn == WEP_HOOK.m_id && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(Weapons_from(wpn))))
+       if (wpn == WEP_HOOK && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
            complain = 0;
 
-       if(complain)
-               self.hasweapon_complain_spam = time + 0.2;
+       if (complain)
+               cl.hasweapon_complain_spam = time + 0.2;
 
-       if (wpn < WEP_FIRST || wpn > WEP_LAST)
+       if (wpn == WEP_Null)
        {
                if (complain)
-                       sprint(self, "Invalid weapon\n");
+                       sprint(cl, "Invalid weapon\n");
                return false;
        }
-       if (cl.weapons & WepSet_FromWeapon(Weapons_from(wpn)))
+       if (cl.weapons & WepSet_FromWeapon(wpn))
        {
                if (andammo)
                {
@@ -48,17 +48,14 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        }
                        else
                        {
-                               setself(cl);
-                               Weapon w = Weapons_from(wpn);
-                               f = w.wr_checkammo1(w) + w.wr_checkammo2(w);
+                               WITH(entity, self, cl, 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
                                entity mine;
-                               if(wpn == WEP_MINE_LAYER.m_id)
-                               for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
+                               if(wpn == WEP_MINE_LAYER)
+                               for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == cl)
                                        f = 1;
 
-                               setself(this);
                        }
                        if (!f)
                        {
@@ -66,7 +63,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                if(IS_REAL_CLIENT(cl))
                                {
                                        play2(cl, SND(UNAVAILABLE));
-                                       Send_WeaponComplain (cl, wpn, 0);
+                                       Send_WeaponComplain (cl, wpn.m_id, 0);
                                }
                                return false;
                        }
@@ -77,15 +74,15 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
        {
                // DRESK - 3/16/07
                // Report Proper Weapon Status / Modified Weapon Ownership Message
-               if (weaponsInMap & WepSet_FromWeapon(Weapons_from(wpn)))
+               if (weaponsInMap & WepSet_FromWeapon(wpn))
                {
-                       Send_WeaponComplain(cl, wpn, 1);
+                       Send_WeaponComplain(cl, wpn.m_id, 1);
 
                        if(autocvar_g_showweaponspawns)
                        {
                                entity e;
 
-                               for(e = world; (e = findfloat(e, weapon, wpn)); )
+                               for(e = world; (e = findfloat(e, weapon, wpn.m_id)); )
                                {
                                        if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
                                                continue;
@@ -95,18 +92,18 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                                WP_Weapon,
                                                1, 0,
                                                world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
-                                               self, 0,
+                                               cl, 0,
                                                world, enemy,
                                                0,
                                                RADARICON_NONE
                                        );
-                                       wp.wp_extra = wpn;
+                                       wp.wp_extra = wpn.m_id;
                                }
                        }
                }
                else
                {
-                       Send_WeaponComplain (cl, wpn, 2);
+                       Send_WeaponComplain (cl, wpn.m_id, 2);
                }
 
                play2(cl, SND(UNAVAILABLE));
@@ -145,15 +142,13 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                if(wep.impulse != imp)
                        continue;
 
-               float i, have_other = false;
-               for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-               {
-                       Weapon e = Weapons_from(i);
+               bool have_other = false;
+               FOREACH(Weapons, it != WEP_Null, {
                        if(i != weaponwant)
-                       if(e.impulse == imp || imp < 0)
-                       if((pl.weapons & (e.m_wepset)) || (weaponsInMap & (e.m_wepset)))
+                       if(it.impulse == imp || imp < 0)
+                       if((pl.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))
@@ -163,7 +158,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
 
                ++c;
 
-               if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
+               if(!skipmissing || client_hasweapon(pl, wep, true, false))
                {
                        if(switchtonext)
                                return weaponwant;
@@ -203,15 +198,13 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                                if(wep.impulse != imp)
                                        continue;
 
-                       float i, have_other = false;
-                       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-                       {
-                               Weapon w = Weapons_from(i);
+                       bool have_other = false;
+                       FOREACH(Weapons, it != WEP_Null, {
                                if(i != weaponwant)
-                               if(w.impulse == imp || imp < 0)
-                               if((pl.weapons & (w.m_wepset)) || (weaponsInMap & (w.m_wepset)))
+                               if(it.impulse == imp || imp < 0)
+                               if((pl.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))
@@ -222,7 +215,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                        --c;
                        if(c == 0)
                        {
-                               client_hasweapon(pl, weaponwant, true, true);
+                               client_hasweapon(pl, wep, true, true);
                                break;
                        }
                }
@@ -230,8 +223,9 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
        return 0;
 }
 
-void W_SwitchWeapon_Force(entity e, float w)
+void W_SwitchWeapon_Force(entity e, Weapon wep)
 {
+       int w = wep.m_id;
        e.cnt = e.switchweapon;
        e.switchweapon = w;
        e.selectweapon = w;
@@ -252,20 +246,20 @@ void W_SwitchToOtherWeapon(entity pl)
        else
                ww = w_getbestweapon(pl);
        if(ww)
-               W_SwitchWeapon_Force(pl, ww);
+               W_SwitchWeapon_Force(pl, Weapons_from(ww));
 }
 
-void W_SwitchWeapon(float imp)
+void W_SwitchWeapon(Weapon w)
 {SELFPARAM();
+       int imp = w.m_id;
        if (self.switchweapon != imp)
        {
-               if (client_hasweapon(self, imp, true, true))
-                       W_SwitchWeapon_Force(self, imp);
+               if (client_hasweapon(self, w, true, true))
+                       W_SwitchWeapon_Force(self, w);
                else
                        self.selectweapon = imp; // update selectweapon ANYWAY
        }
        else if(!forbidWeaponUse(self)) {
-               Weapon w = Weapons_from(self.weapon);
                w.wr_reload(w);
        }
 }
@@ -275,7 +269,7 @@ void W_CycleWeapon(string weaponorder, float dir)
        float w;
        w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
        if(w > 0)
-               W_SwitchWeapon(w);
+               W_SwitchWeapon(Weapons_from(w));
 }
 
 void W_NextWeaponOnImpulse(float imp)
@@ -283,7 +277,7 @@ void W_NextWeaponOnImpulse(float imp)
        float w;
        w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
        if(w > 0)
-               W_SwitchWeapon(w);
+               W_SwitchWeapon(Weapons_from(w));
 }
 
 // next weapon
@@ -311,8 +305,9 @@ void W_PreviousWeapon(float list)
 // previously used if exists and has ammo, (second) best otherwise
 void W_LastWeapon()
 {SELFPARAM();
-       if(client_hasweapon(self, self.cnt, true, false))
-               W_SwitchWeapon(self.cnt);
+       Weapon wep = Weapons_from(self.cnt);
+       if(client_hasweapon(self, wep, true, false))
+               W_SwitchWeapon(wep);
        else
                W_SwitchToOtherWeapon(self);
 }
index d51addd7d9ab729b5d9517982f038bb09bd0dee9..07d8383b11b3a922a0636bd49d1a76175802b780 100644 (file)
@@ -5,18 +5,18 @@
 void Send_WeaponComplain(entity e, float wpn, float type);
 
 .float hasweapon_complain_spam;
-float client_hasweapon(entity cl, float wpn, float andammo, float complain);
+bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain);
 
 .int weaponcomplainindex;
 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing);
 
 #define w_getbestweapon(ent) W_GetCycleWeapon(ent, ent.cvar_cl_weaponpriority, 0, -1, false, true)
 
-void W_SwitchWeapon_Force(entity e, float w);
+void W_SwitchWeapon_Force(entity e, Weapon w);
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
 void W_SwitchToOtherWeapon(entity pl);
-void W_SwitchWeapon(float imp);
+void W_SwitchWeapon(Weapon imp);
 
 void W_CycleWeapon(string weaponorder, float dir);
 
index 652ec92005aba884ea26c3955b42644fb33a6726..829b6ed62e772fc250c0847bd84dc6b5fcd26308 100644 (file)
@@ -182,7 +182,7 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce)
        if(!(self.weapons & set)) return;
        self.weapons &= ~set;
 
-       W_SwitchWeapon_Force(self, w_getbestweapon(self));
+       W_SwitchWeapon_Force(self, Weapons_from(w_getbestweapon(self)));
        string a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
 
        if(!a) return;
index 7607ae18c57ce2a1a7f8386173abe3eb55ba1cb7..f5f279dff00a9d9d30134dadfbb8ba8848b7117d 100644 (file)
@@ -520,7 +520,7 @@ void W_WeaponFrame(entity actor)
        {
                if (w && !(actor.weapons & WepSet_FromWeapon(Weapons_from(w))))
                {
-                       if (actor.weapon == actor.switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+                       if (actor.weapon == actor.switchweapon) W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
                        w = 0;
                }
 
@@ -538,8 +538,8 @@ void W_WeaponFrame(entity actor)
                        }
                        else
                        {
-                               if (key_pressed && actor.switchweapon != WEP_HOOK.m_id && !actor.hook_switchweapon) W_SwitchWeapon(
-                                               WEP_HOOK.m_id);
+                               if (key_pressed && actor.switchweapon != WEP_HOOK.m_id && !actor.hook_switchweapon)
+                                       W_SwitchWeapon(WEP_HOOK);
                                actor.hook_switchweapon = key_pressed;
                                Weapon h = WEP_HOOK;
                                block_weapon = (actor.weapon == h.m_id && (actor.BUTTON_ATCK || key_pressed));