]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Refactor code
authorterencehill <piuntn@gmail.com>
Fri, 4 Oct 2024 22:07:00 +0000 (00:07 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 4 Oct 2024 22:07:00 +0000 (00:07 +0200)
qcsrc/common/weapons/weapon/machinegun.qc

index 672ccc80cd205c2a58e3f25f7297d337a8232d32..46a490ff90e0bbb7a17358964c638dc9b03a03fe 100644 (file)
@@ -5,11 +5,6 @@
 .float machinegun_spread_accumulation;
 .float spreadUpdateTime;
 
-//float spreadSpectrumMin; // localized to Auto and Burst
-//float spreadSpectrumMax; // localized to Auto and Burst
-//bool inversedSpread; // localized to Auto
-
-
 ERASEABLE
 void MachineGun_Update_Spread(entity actor, .entity weaponentity, float spreadSpectrumMin, float spreadSpectrumMax)
 {
@@ -18,7 +13,7 @@ void MachineGun_Update_Spread(entity actor, .entity weaponentity, float spreadSp
        // time based spread decay
        if (WEP_CVAR(WEP_MACHINEGUN, spread_decay))
        {
-               float spreadSpectrumDistance = spreadSpectrumMax - spreadSpectrumMin;
+               float spreadSpectrumDistance = fabs(spreadSpectrumMax - spreadSpectrumMin);
                float timediff = time - actor.(weaponentity).spreadUpdateTime;
                spread_accum = bound(0,
                        spread_accum - (timediff * WEP_CVAR(WEP_MACHINEGUN, spread_decay)),
@@ -139,33 +134,15 @@ void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity
                actor.punchangle_y = random() - 0.5;
        }
 
-       float spreadSpectrumMin;
-       float spreadSpectrumMax;
-       bool inversedSpread;
-       // check if max is lower or higher than min so it can be used invertedly,
-       // accurate with more firing, like Hyperion weapons from Borderlands
-       if (WEP_CVAR(WEP_MACHINEGUN, spread_min) < WEP_CVAR(WEP_MACHINEGUN, spread_max))
-       {
-               spreadSpectrumMin = WEP_CVAR(WEP_MACHINEGUN, spread_min);
-               spreadSpectrumMax = WEP_CVAR(WEP_MACHINEGUN, spread_max);
-               inversedSpread = false;
-       }
-       else
-       {
-               spreadSpectrumMin = WEP_CVAR(WEP_MACHINEGUN, spread_max);
-               spreadSpectrumMax = WEP_CVAR(WEP_MACHINEGUN, spread_min);
-               inversedSpread = true;
-       }
-
-       MachineGun_Update_Spread(actor, weaponentity, spreadSpectrumMin, spreadSpectrumMax);
+       MachineGun_Update_Spread(actor, weaponentity, WEP_CVAR(WEP_MACHINEGUN, spread_min), WEP_CVAR(WEP_MACHINEGUN, spread_max));
 
        float spread_accum = actor.(weaponentity).machinegun_spread_accumulation;
 
        float spread_accuracy;
-       if (!inversedSpread)
-               spread_accuracy = spreadSpectrumMin + spread_accum;
-       else
-               spread_accuracy = spreadSpectrumMax - spread_accum;
+       if (WEP_CVAR(WEP_MACHINEGUN, spread_min) < WEP_CVAR(WEP_MACHINEGUN, spread_max))
+               spread_accuracy = WEP_CVAR(WEP_MACHINEGUN, spread_min) + spread_accum;
+       else // inverted
+               spread_accuracy = WEP_CVAR(WEP_MACHINEGUN, spread_min) - spread_accum;
 
        fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
                           spread_accuracy,
@@ -206,24 +183,7 @@ void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentit
                actor.punchangle_y = random() - 0.5;
        }
 
-       float spreadSpectrumMin;
-       float spreadSpectrumMax;
-       // check if max is lower or higher than min so it can be used invertedly,
-       // accurate with more firing, like Hyperion weapons from Borderlands
-       if (WEP_CVAR(WEP_MACHINEGUN, spread_min) < WEP_CVAR(WEP_MACHINEGUN, spread_max))
-       {
-               spreadSpectrumMin = WEP_CVAR(WEP_MACHINEGUN, spread_min);
-               spreadSpectrumMax = WEP_CVAR(WEP_MACHINEGUN, spread_max);
-               //inversedSpread = false;
-       }
-       else
-       {
-               spreadSpectrumMin = WEP_CVAR(WEP_MACHINEGUN, spread_max);
-               spreadSpectrumMax = WEP_CVAR(WEP_MACHINEGUN, spread_min);
-               //inversedSpread = true;
-       }
-
-       MachineGun_Update_Spread(actor, weaponentity, spreadSpectrumMin, spreadSpectrumMax);
+       MachineGun_Update_Spread(actor, weaponentity, WEP_CVAR(WEP_MACHINEGUN, spread_min), WEP_CVAR(WEP_MACHINEGUN, spread_max));
 
        float spread_accum = actor.(weaponentity).machinegun_spread_accumulation;