From bdfa8a361b41484eaa786f89d29c86dbf975b104 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Wed, 5 Jul 2017 23:46:39 +0200 Subject: [PATCH] Split Barrel can-fire checks to separate CanFire method --- OpenRA.Mods.Common/Traits/Armament.cs | 40 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index c31c0bfad0..6f3cdc302b 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -204,26 +204,34 @@ namespace OpenRA.Mods.Common.Traits a(); } + protected virtual bool CanFire(Actor self, Target target) + { + if (IsReloading) + return false; + + if (ammoPool != null && !ammoPool.HasAmmo()) + return false; + + if (turret != null && !turret.HasAchievedDesiredFacing) + return false; + + if (!target.IsInRange(self.CenterPosition, MaxRange())) + return false; + + if (Weapon.MinRange != WDist.Zero && target.IsInRange(self.CenterPosition, Weapon.MinRange)) + return false; + + if (!Weapon.IsValidAgainst(target, self.World, self)) + return false; + + return true; + } + // Note: facing is only used by the legacy positioning code // The world coordinate model uses Actor.Orientation public virtual Barrel CheckFire(Actor self, IFacing facing, Target target) { - if (IsReloading) - return null; - - if (ammoPool != null && !ammoPool.HasAmmo()) - return null; - - if (turret != null && !turret.HasAchievedDesiredFacing) - return null; - - if (!target.IsInRange(self.CenterPosition, MaxRange())) - return null; - - if (Weapon.MinRange != WDist.Zero && target.IsInRange(self.CenterPosition, Weapon.MinRange)) - return null; - - if (!Weapon.IsValidAgainst(target, self.World, self)) + if (!CanFire(self, target)) return null; if (ticksSinceLastShot >= Weapon.ReloadDelay)