X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fserver%2Fweapons%2Fselection.qc;h=b4c13851bf47514c57a0212e5d2df0e0a4bcc627;hb=c2afbf519433fb56c9b8b807ca3ab12c62575ec8;hp=c2a9c32acdef778fac3191045753e8ee80032c60;hpb=073cc17f87486bec59ac2b6f9c26bf1155dbd7d8;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index c2a9c32ac..b4c13851b 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -240,7 +240,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl void W_SwitchWeapon_Force(Player this, Weapon wep, .entity weaponentity) { - TC(Weapon, wep); + TC(Weapon, wep); this.(weaponentity).cnt = this.(weaponentity).m_switchweapon.m_id; this.(weaponentity).m_switchweapon = wep; this.(weaponentity).selectweapon = wep.m_id; @@ -266,20 +266,36 @@ void W_SwitchToOtherWeapon(entity this, .entity weaponentity) W_SwitchWeapon_Force(this, ww, weaponentity); } -void W_SwitchWeapon(entity this, Weapon w, .entity weaponentity) +AUTOCVAR_SAVE(cl_weapon_switch_reload, bool, true, "When trying to switch to the currently held weapon, reload it"); +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)) + else if(!forbidWeaponUse(this) && autocvar_cl_weapon_switch_reload) { entity actor = this; w.wr_reload(w, actor, weaponentity); } + + return true; // player already has the weapon out or needs to reload +} + +AUTOCVAR_SAVE(cl_weapon_switch_fallback_to_impulse, bool, true, "When trying to switch to a weapon that is not available, switch to an alternative from the same impulse"); +void W_SwitchWeapon_TryOthers(entity this, Weapon w, .entity weaponentity) +{ + if(!W_SwitchWeapon(this, w, weaponentity) && autocvar_cl_weapon_switch_fallback_to_impulse) + W_NextWeaponOnImpulse(this, w.impulse, weaponentity); } void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity)