From 12150869d71c8ff952778108e82f665530d60778 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 3 Oct 2016 17:31:23 +1000 Subject: [PATCH] Clean up ammo_field handling --- qcsrc/common/weapons/weapon/blaster.qc | 5 ----- qcsrc/common/weapons/weapon/fireball.qc | 4 ---- qcsrc/common/weapons/weapon/porto.qc | 4 ---- qcsrc/common/weapons/weapon/shotgun.qc | 4 ---- qcsrc/common/weapons/weapon/tuba.qc | 1 - qcsrc/common/weapons/weapon/vaporizer.qc | 1 - qcsrc/server/weapons/weaponsystem.qc | 21 ++++++++++----------- 7 files changed, 10 insertions(+), 30 deletions(-) diff --git a/qcsrc/common/weapons/weapon/blaster.qc b/qcsrc/common/weapons/weapon/blaster.qc index c1be1fe76..29e9c2a57 100644 --- a/qcsrc/common/weapons/weapon/blaster.qc +++ b/qcsrc/common/weapons/weapon/blaster.qc @@ -228,11 +228,6 @@ METHOD(Blaster, wr_think, void(Blaster thiswep, entity actor, .entity weaponenti } } -METHOD(Blaster, wr_setup, void(entity thiswep, entity actor)) -{ - actor.ammo_field = ammo_none; -} - METHOD(Blaster, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) { return true; // infinite ammo diff --git a/qcsrc/common/weapons/weapon/fireball.qc b/qcsrc/common/weapons/weapon/fireball.qc index 703162fd8..4010def84 100644 --- a/qcsrc/common/weapons/weapon/fireball.qc +++ b/qcsrc/common/weapons/weapon/fireball.qc @@ -406,10 +406,6 @@ METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponenti } } } -METHOD(Fireball, wr_setup, void(entity thiswep, entity actor)) -{ - actor.ammo_field = ammo_none; -} METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) { return true; // infinite ammo diff --git a/qcsrc/common/weapons/weapon/porto.qc b/qcsrc/common/weapons/weapon/porto.qc index 6fdedd0d1..782cb0e3e 100644 --- a/qcsrc/common/weapons/weapon/porto.qc +++ b/qcsrc/common/weapons/weapon/porto.qc @@ -372,10 +372,6 @@ METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity wea // always allow infinite ammo return true; } -METHOD(PortoLaunch, wr_setup, void(entity thiswep, entity actor)) -{ - actor.ammo_field = ammo_none; -} METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor)) { actor.porto_current = NULL; diff --git a/qcsrc/common/weapons/weapon/shotgun.qc b/qcsrc/common/weapons/weapon/shotgun.qc index 3dee669c4..26784db88 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qc +++ b/qcsrc/common/weapons/weapon/shotgun.qc @@ -281,10 +281,6 @@ METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentit weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shotgun_Attack2); } } -METHOD(Shotgun, wr_setup, void(entity thiswep, entity actor)) -{ - actor.ammo_field = ammo_none; -} METHOD(Shotgun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) { float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(shotgun, ammo); diff --git a/qcsrc/common/weapons/weapon/tuba.qc b/qcsrc/common/weapons/weapon/tuba.qc index b3cae67a6..26025a0ca 100644 --- a/qcsrc/common/weapons/weapon/tuba.qc +++ b/qcsrc/common/weapons/weapon/tuba.qc @@ -398,7 +398,6 @@ METHOD(Tuba, wr_think, void(Tuba this, entity actor, .entity weaponentity, int f METHOD(Tuba, wr_setup, void(Tuba this, entity actor)) { - actor.ammo_field = ammo_none; actor.tuba_instrument = 0; } #endif diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index c16371bea..77595290b 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -436,7 +436,6 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent } METHOD(Vaporizer, wr_setup, void(entity thiswep, entity actor)) { - actor.ammo_field = (thiswep.ammo_field); actor.vaporizer_lasthit = 0; } METHOD(Vaporizer, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index f02c8f981..01d505298 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -484,7 +484,6 @@ void W_WeaponFrame(Player actor, .entity weaponentity) this.m_weapon = newwep; this.weaponname = newwep.mdl; this.bulletcounter = 0; - actor.ammo_field = newwep.ammo_field; newwep.wr_setup(newwep, actor); this.state = WS_RAISE; @@ -673,19 +672,21 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int { // finish the reloading process, and do the ammo transfer + Weapon wpn = actor.(weaponentity).m_weapon; + actor.(weaponentity).clip_load = actor.(weaponentity).old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load - if (!actor.(weaponentity).reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || actor.ammo_field == ammo_none) + if (!actor.(weaponentity).reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_field == ammo_none) { actor.(weaponentity).clip_load = actor.(weaponentity).reload_ammo_amount; } else { // make sure we don't add more ammo than we have - float load = min(actor.(weaponentity).reload_ammo_amount - actor.(weaponentity).clip_load, actor.(actor.ammo_field)); + float load = min(actor.(weaponentity).reload_ammo_amount - actor.(weaponentity).clip_load, actor.(wpn.ammo_field)); actor.(weaponentity).clip_load += load; - actor.(actor.ammo_field) -= load; + actor.(wpn.ammo_field) -= load; } actor.(weaponentity).(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).clip_load; @@ -695,7 +696,6 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int // ATTACK_FINISHED(actor, slot) -= actor.(weaponentity).reload_time - 1; - Weapon wpn = Weapons_from(actor.(weaponentity).m_weapon.m_id); w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1)); } @@ -728,9 +728,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen if (actor.(weaponentity).clip_load >= actor.(weaponentity).reload_ammo_amount) return; // no ammo, so nothing to load - if (actor.ammo_field != ammo_none) + if (e.ammo_field != ammo_none) { - if (!actor.(actor.ammo_field) && actor.(weaponentity).reload_ammo_min) + if (!actor.(e.ammo_field) && actor.(weaponentity).reload_ammo_min) { if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { @@ -741,8 +741,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen actor.reload_complain = time + 1; } // switch away if the amount of ammo is not enough to keep using this weapon - Weapon w = actor.(weaponentity).m_weapon; - if (!(w.wr_checkammo1(w, actor, weaponentity) + w.wr_checkammo2(w, actor, weaponentity))) + if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity))) { actor.(weaponentity).clip_load = -1; // reload later W_SwitchToOtherWeapon(actor, weaponentity); @@ -771,11 +770,11 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + actor.(weaponentity).reload_time + 1; - weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, actor.(weaponentity).reload_time, W_ReloadedAndReady); + weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady); if (this.clip_load < 0) this.clip_load = 0; this.old_clip_load = this.clip_load; - this.clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_weapon.m_id]) = -1; + this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1; } void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity) -- 2.39.2