]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/machinegun.qc
Merge branch 'martin-t/AMMO' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / machinegun.qc
index 5a55b7e8b51257d1a1e3fec9c941f3fd33c2172f..86de79f600603d02f84bab06858b5dc533b42508 100644 (file)
@@ -84,7 +84,7 @@ void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentit
        if(PHYS_INPUT_BUTTON_ATCK(actor))
        {
                if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
-               if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
+               if(!(actor.items & IT_UNLIMITED_AMMO))
                {
                        W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
                        w_ready(thiswep, actor, weaponentity, fire);
@@ -110,7 +110,7 @@ void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity
        }
 
        if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
-       if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
+       if(!(actor.items & IT_UNLIMITED_AMMO))
        {
                W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
                w_ready(thiswep, actor, weaponentity, fire);
@@ -211,20 +211,30 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen
         if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
         {
             if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
-            if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
+            if(!(actor.items & IT_UNLIMITED_AMMO))
             {
                 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
                 w_ready(thiswep, actor, weaponentity, fire);
                 return;
             }
+
+            float ammo_available;
+            if (WEP_CVAR(machinegun, reload_ammo) > 0)
+            {
+                ammo_available = actor.(weaponentity).clip_load;
+            }
+            else
+            {
+                ammo_available = GetResource(actor, thiswep.ammo_type);
+            }
+
             // 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));
+            float burst_fraction = min(1, ammo_available / 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);
+            int to_use = min(WEP_CVAR(machinegun, burst_ammo), ammo_available);
             W_DecreaseAmmo(thiswep, actor, to_use, weaponentity);
 
             // Bursting counts up to 0 from a negative.