From: Martin Taibr Date: Thu, 12 Sep 2019 19:21:25 +0000 (+0200) Subject: Merge branch 'master' into cloudwalk9/mgburstfix X-Git-Tag: xonotic-v0.8.5~1287^2~2 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=139a594d29f65508e5d6001e90d4ee4fad82ca66;hp=65f8f7b31f6c7f9928d729c4110304efe3406858 Merge branch 'master' into cloudwalk9/mgburstfix --- diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index aaf4900fe2..d219f6beda 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -190,10 +190,14 @@ METHOD(MachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponenti } METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if(WEP_CVAR(machinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo))) { // forced reload + // forced reload - wait until the bulletcounter is 0 so a burst loop can finish + if(WEP_CVAR(machinegun, reload_ammo) + && actor.(weaponentity).clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)) + && actor.(weaponentity).misc_bulletcounter >= 0) + { thiswep.wr_reload(thiswep, actor, weaponentity); - } else - if(WEP_CVAR(machinegun, mode) == 1) + } + else if(WEP_CVAR(machinegun, mode) == 1) { if(fire & 1) if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0)) @@ -202,6 +206,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)) { @@ -212,10 +217,18 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen w_ready(thiswep, actor, weaponentity, fire); return; } - - W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity); - - actor.(weaponentity).misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1; + + // 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); + + // 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); } } @@ -275,6 +288,8 @@ METHOD(MachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity wea } METHOD(MachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity)) { + if(actor.(weaponentity).misc_bulletcounter < 0) + return; W_Reload(actor, weaponentity, min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND_RELOAD); } METHOD(MachineGun, wr_suicidemessage, Notification(entity thiswep)) diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 19ba40aa0b..f1655b6322 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -809,7 +809,6 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen } } } - if (this) { if (this.wframe == WFRAME_RELOAD) return;