Replace IPreventsAutoTarget with IDisable(Enemy)AutoTarget.

This allows traits on the attacking unit to suppress auto targeting
and makes the distinction between the two interfaces clear.
This commit is contained in:
Paul Chote
2019-05-17 19:51:35 +00:00
committed by abcdefg30
parent f9fe7486b3
commit 55f6744cf3
3 changed files with 23 additions and 6 deletions

View File

@@ -125,6 +125,7 @@ namespace OpenRA.Mods.Common.Traits
UnitStance stance;
ConditionManager conditionManager;
IDisableAutoTarget[] disableAutoTarget;
IEnumerable<AutoTargetPriorityInfo> activeTargetPriorities;
int conditionToken = ConditionManager.InvalidConditionToken;
@@ -174,6 +175,7 @@ namespace OpenRA.Mods.Common.Traits
.Where(Exts.IsTraitEnabled).Select(atp => atp.Info);
conditionManager = self.TraitOrDefault<ConditionManager>();
disableAutoTarget = self.TraitsImplementing<IDisableAutoTarget>().ToArray();
ApplyStanceCondition(self);
}
@@ -202,6 +204,10 @@ namespace OpenRA.Mods.Common.Traits
if (attacker.Disposed)
return;
foreach (var dat in disableAutoTarget)
if (dat.DisableAutoTarget(self))
return;
if (!attacker.IsInWorld)
{
// If the aggressor is in a transport, then attack the transport instead
@@ -250,6 +256,10 @@ namespace OpenRA.Mods.Common.Traits
{
nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval);
foreach (var dat in disableAutoTarget)
if (dat.DisableAutoTarget(self))
return Target.Invalid;
foreach (var ab in ActiveAttackBases)
{
// If we can't attack right now, there's no need to try and find a target.
@@ -379,8 +389,8 @@ namespace OpenRA.Mods.Common.Traits
bool PreventsAutoTarget(Actor attacker, Actor target)
{
foreach (var pat in target.TraitsImplementing<IPreventsAutoTarget>())
if (pat.PreventsAutoTarget(target, attacker))
foreach (var deat in target.TraitsImplementing<IDisableEnemyAutoTarget>())
if (deat.DisableEnemyAutoTarget(target, attacker))
return true;
return false;