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.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user