]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/machinegun.qc
Merge branch 'master' into cloudwalk9/mgburstfix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / machinegun.qc
index 04f20e0c206d53a79a89551d872f1018d9dfa3a4..d219f6beda8cc393eb5b83fc683659934415ff08 100644 (file)
@@ -2,15 +2,6 @@
 
 #ifdef SVQC
 
-METHOD(MachineGun, m_spawnfunc_hookreplace, Weapon(MachineGun this, entity e))
-{
-       if (autocvar_sv_q3acompat_machineshotgunswap && !Item_IsLoot(e))
-       {
-               return WEP_SHOCKWAVE;
-       }
-       return this;
-}
-
 void W_MachineGun_MuzzleFlash_Think(entity this)
 {
        this.frame += 2;
@@ -164,7 +155,7 @@ void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentit
                actor.punchangle_y = random() - 0.5;
        }
 
-       fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, burst_speed), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), thiswep.m_id, EFFECT_BULLET);
+       fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, burst_spread), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), thiswep.m_id, EFFECT_BULLET);
 
        Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
 
@@ -199,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)) && actor.(weaponentity).misc_bulletcounter >= 0) { // forced reload - wait until the bulletcounter is 0 so a burst loop can finish
+    // 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))
@@ -211,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))
         {
@@ -221,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);
         }
     }