From 0e5ea959aa2411038b1a0bf8a861eda7d1a624fc Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 6 Dec 2015 03:08:31 +0100 Subject: [PATCH] Perform faster checks in AB.CanAttack much earlier Move self.IsDisabled right after IsInWorld and IsTraitDisabled checks. This should skip/avoid a lot of the following checks when actors are disabled by low power, EMP or similar, potentially saving some performance when there are many disabled actors with attack trait. Move IsValidFor before HasAnyValidWeapons because the latter is more expensive. --- OpenRA.Mods.Common/Traits/Attack/AttackBase.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 615575fd14..55fa16cb62 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -70,7 +70,10 @@ namespace OpenRA.Mods.Common.Traits protected virtual bool CanAttack(Actor self, Target target) { - if (!self.IsInWorld || IsTraitDisabled) + if (!self.IsInWorld || IsTraitDisabled || self.IsDisabled()) + return false; + + if (!target.IsValidFor(self)) return false; if (!HasAnyValidWeapons(target)) @@ -80,15 +83,9 @@ namespace OpenRA.Mods.Common.Traits if (building.Value != null && !building.Value.BuildComplete) return false; - if (!target.IsValidFor(self)) - return false; - if (Armaments.All(a => a.IsReloading)) return false; - if (self.IsDisabled()) - return false; - if (target.Type == TargetType.Actor && !self.Owner.CanTargetActor(target.Actor)) return false;