From: David Knapp Date: Sat, 27 Jul 2019 19:10:19 +0000 (-0400) Subject: Only decrease by what's left in the mag. Also improve commenting. X-Git-Tag: xonotic-v0.8.5~1287^2~4 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b8503644fb89586cf502675f3266e7af32b1bc5b;p=xonotic%2Fxonotic-data.pk3dir.git Only decrease by what's left in the mag. Also improve commenting. --- diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index 9ddde91ae..fe45176cc 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -215,6 +215,7 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen W_MachineGun_Attack_Auto(thiswep, actor, weaponentity, fire); } + // You can "shoot" more rounds than what's "used", and vice versa. if(fire & 2) if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0)) { @@ -226,14 +227,16 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen return; } - // We don't want to shoot 3 rounds if there's 2 left in the mag. So calculate a fraction. + // We don't want to shoot 3 rounds if there's 2 left in the mag, so we'll use a fraction. + // Also keep the fraction <= 1 otherwise we'd mag dump in one burst. float burst_fraction = min(1, actor.(weaponentity).clip_load / WEP_CVAR(machinegun, burst_ammo)); int to_shoot = floor(WEP_CVAR(machinegun, burst) * burst_fraction); - - // Apply it here to take the right amount of ammo. - W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity); - - // Then apply it to the bullet counter before firing. + + // We also don't want to use 3 rounds if there's only 2 left. + int to_use = min(WEP_CVAR(machinegun, burst_ammo), actor.(weaponentity).clip_load); + W_DecreaseAmmo(thiswep, actor, to_use, weaponentity); + + // Bursting counts up to 0 from a negative. actor.(weaponentity).misc_bulletcounter = -to_shoot; W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire); }