From 56ffca1d215be6ac999d019c3619b46fd099a281 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 19 Jul 2019 21:59:28 -0400 Subject: [PATCH] Use min() to keep the fraction <= 1 instead of a separate check. Added comments and improved indentation. --- qcsrc/common/weapons/weapon/machinegun.qc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index 3405b79fc..3340a1635 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -221,15 +221,16 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen w_ready(thiswep, actor, weaponentity, fire); return; } - - float burst_percent = actor.(weaponentity).clip_load / WEP_CVAR(machinegun, burst_ammo); - if (burst_percent > 1) - burst_percent = 1; - - W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity); - - actor.(weaponentity).misc_bulletcounter = floor(WEP_CVAR(machinegun, burst) * burst_percent) * -1; - W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire); + + // We don't want to shoot 3 rounds if there's 2 left in the mag. So calculate a fraction... + float burst_percent = min(1,actor.(weaponentity).clip_load / WEP_CVAR(machinegun, burst_ammo)); + + // ...before we decrease ammo. + W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity); + + // Then apply it to the bullet counter before firing. + actor.(weaponentity).misc_bulletcounter = floor(WEP_CVAR(machinegun, burst) * burst_percent) * -1; + W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire); } } else -- 2.39.5