From: David Knapp Date: Sat, 20 Jul 2019 01:59:28 +0000 (-0400) Subject: Use min() to keep the fraction <= 1 instead of a separate check. X-Git-Tag: xonotic-v0.8.5~1287^2~9 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=56ffca1d215be6ac999d019c3619b46fd099a281;p=xonotic%2Fxonotic-data.pk3dir.git Use min() to keep the fraction <= 1 instead of a separate check. Added comments and improved indentation. --- 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