From: TimePath Date: Mon, 7 Dec 2015 10:03:52 +0000 (+1100) Subject: Weapons: require explicit `Weapons_from` call X-Git-Tag: xonotic-v0.8.2~1534 X-Git-Url: https://de.git.xonotic.org/?a=commitdiff_plain;h=eb6fabc8b16e23fcf0704ecf97685dffa7387bb7;p=xonotic%2Fxonotic-data.pk3dir.git Weapons: require explicit `Weapons_from` call --- diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index cc418df5e..2206df7c6 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -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'; } diff --git a/qcsrc/common/mutators/mutator/nix/nix.qc b/qcsrc/common/mutators/mutator/nix/nix.qc index a07ad44ca..68f4dfaa8 100644 --- a/qcsrc/common/mutators/mutator/nix/nix.qc +++ b/qcsrc/common/mutators/mutator/nix/nix.qc @@ -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) diff --git a/qcsrc/common/mutators/mutator/overkill/hmg.qc b/qcsrc/common/mutators/mutator/overkill/hmg.qc index 8341f7c71..6112f89dd 100644 --- a/qcsrc/common/mutators/mutator/overkill/hmg.qc +++ b/qcsrc/common/mutators/mutator/overkill/hmg.qc @@ -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; } diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index 7c9d64c01..4a15cc6c7 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -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; diff --git a/qcsrc/common/weapons/weapon/hlac.qc b/qcsrc/common/weapons/weapon/hlac.qc index f99c70073..3f5222489 100644 --- a/qcsrc/common/weapons/weapon/hlac.qc +++ b/qcsrc/common/weapons/weapon/hlac.qc @@ -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; } diff --git a/qcsrc/common/weapons/weapon/hook.qc b/qcsrc/common/weapons/weapon/hook.qc index 4e3722f13..3cc55e2ae 100644 --- a/qcsrc/common/weapons/weapon/hook.qc +++ b/qcsrc/common/weapons/weapon/hook.qc @@ -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))); } } } diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index 7e79bc929..1f8273748 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -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; } diff --git a/qcsrc/common/weapons/weapon/shotgun.qc b/qcsrc/common/weapons/weapon/shotgun.qc index c50eff100..27dfe4e4f 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qc +++ b/qcsrc/common/weapons/weapon/shotgun.qc @@ -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; } diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index 9a74d3841..8cb4a3168 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -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; diff --git a/qcsrc/server/bot/scripting.qc b/qcsrc/server/bot/scripting.qc index b0348125e..96f7af3a1 100644 --- a/qcsrc/server/bot/scripting.qc +++ b/qcsrc/server/bot/scripting.qc @@ -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; diff --git a/qcsrc/server/cl_impulse.qc b/qcsrc/server/cl_impulse.qc index 1b08bb571..6598039dc 100644 --- a/qcsrc/server/cl_impulse.qc +++ b/qcsrc/server/cl_impulse.qc @@ -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) diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 62fec55fe..4bebdbfc1 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -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) diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index dfabd9d3d..0e23d0828 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -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!) diff --git a/qcsrc/server/g_damage.qh b/qcsrc/server/g_damage.qh index cee65e164..fc8bf9c8f 100644 --- a/qcsrc/server/g_damage.qh +++ b/qcsrc/server/g_damage.qh @@ -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); diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 97f63fc29..8d66501cd 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -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; } diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index b301da6f2..737ddc8ad 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -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); } diff --git a/qcsrc/server/weapons/selection.qh b/qcsrc/server/weapons/selection.qh index d51addd7d..07d8383b1 100644 --- a/qcsrc/server/weapons/selection.qh +++ b/qcsrc/server/weapons/selection.qh @@ -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); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 652ec9200..829b6ed62 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -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; diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 7607ae18c..f5f279dff 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -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));