]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Use min() to keep the fraction <= 1 instead of a separate check.
authorDavid Knapp <mazecraze96@gmail.com>
Sat, 20 Jul 2019 01:59:28 +0000 (21:59 -0400)
committerDavid Knapp <mazecraze96@gmail.com>
Sat, 20 Jul 2019 01:59:28 +0000 (21:59 -0400)
Added comments and improved indentation.

qcsrc/common/weapons/weapon/machinegun.qc

index 3405b79fc0f050c80c7b56f3f3888689a1a20319..3340a1635fc9bb9bb68c7ab5328be1789ee466eb 100644 (file)
@@ -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