Cache activeAttackBases query in AutoTarget.
This commit is contained in:
@@ -53,6 +53,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class AutoTarget : ConditionalTrait<AutoTargetInfo>, INotifyIdle, INotifyDamage, ITick, IResolveOrder, ISync
|
public class AutoTarget : ConditionalTrait<AutoTargetInfo>, INotifyIdle, INotifyDamage, ITick, IResolveOrder, ISync
|
||||||
{
|
{
|
||||||
readonly AttackBase[] attackBases;
|
readonly AttackBase[] attackBases;
|
||||||
|
readonly IEnumerable<AttackBase> activeAttackBases;
|
||||||
readonly AttackFollow[] attackFollows;
|
readonly AttackFollow[] attackFollows;
|
||||||
[Sync] int nextScanTime = 0;
|
[Sync] int nextScanTime = 0;
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var self = init.Self;
|
var self = init.Self;
|
||||||
attackBases = self.TraitsImplementing<AttackBase>().ToArray();
|
attackBases = self.TraitsImplementing<AttackBase>().ToArray();
|
||||||
|
activeAttackBases = attackBases.Where(Exts.IsTraitEnabled);
|
||||||
|
|
||||||
if (init.Contains<StanceInit>())
|
if (init.Contains<StanceInit>())
|
||||||
Stance = init.Get<StanceInit, UnitStance>();
|
Stance = init.Get<StanceInit, UnitStance>();
|
||||||
@@ -146,8 +148,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public Actor ScanForTarget(Actor self, bool allowMove)
|
public Actor ScanForTarget(Actor self, bool allowMove)
|
||||||
{
|
{
|
||||||
var activeAttackBases = attackBases.Where(Exts.IsTraitEnabled);
|
if (nextScanTime <= 0 && activeAttackBases.Any())
|
||||||
if (activeAttackBases.Any() && nextScanTime <= 0)
|
|
||||||
{
|
{
|
||||||
nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval);
|
nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval);
|
||||||
|
|
||||||
@@ -160,8 +161,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var range = Info.ScanRadius > 0 ? WDist.FromCells(Info.ScanRadius) : ab.GetMaximumRange();
|
var range = Info.ScanRadius > 0 ? WDist.FromCells(Info.ScanRadius) : ab.GetMaximumRange();
|
||||||
return ChooseTarget(self, ab, attackStances, range, allowMove);
|
return ChooseTarget(self, ab, attackStances, range, allowMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +180,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var target = Target.FromActor(targetActor);
|
var target = Target.FromActor(targetActor);
|
||||||
self.SetTargetLine(target, Color.Red, false);
|
self.SetTargetLine(target, Color.Red, false);
|
||||||
|
|
||||||
var activeAttackBases = attackBases.Where(Exts.IsTraitEnabled);
|
|
||||||
foreach (var ab in activeAttackBases)
|
foreach (var ab in activeAttackBases)
|
||||||
ab.AttackTarget(target, false, allowMove);
|
ab.AttackTarget(target, false, allowMove);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user