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:
@@ -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;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class CaptureManager : INotifyCreated, INotifyCapture, ITick, IPreventsAutoTarget
|
||||
public class CaptureManager : INotifyCreated, INotifyCapture, ITick, IDisableEnemyAutoTarget
|
||||
{
|
||||
readonly CaptureManagerInfo info;
|
||||
ConditionManager conditionManager;
|
||||
@@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
w.Update(currentTarget, self, currentTarget, currentTargetDelay, currentTargetTotal);
|
||||
}
|
||||
|
||||
bool IPreventsAutoTarget.PreventsAutoTarget(Actor self, Actor attacker)
|
||||
bool IDisableEnemyAutoTarget.DisableEnemyAutoTarget(Actor self, Actor attacker)
|
||||
{
|
||||
return info.PreventsAutoTarget && currentCaptors.Any(c => attacker.AppearsFriendlyTo(c));
|
||||
}
|
||||
|
||||
@@ -297,9 +297,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void ModifyTransformActorInit(Actor self, TypeDictionary init);
|
||||
}
|
||||
|
||||
public interface IPreventsAutoTarget
|
||||
[RequireExplicitImplementation]
|
||||
public interface IDisableEnemyAutoTarget
|
||||
{
|
||||
bool PreventsAutoTarget(Actor self, Actor attacker);
|
||||
bool DisableEnemyAutoTarget(Actor self, Actor attacker);
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IDisableAutoTarget
|
||||
{
|
||||
bool DisableAutoTarget(Actor self);
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
|
||||
Reference in New Issue
Block a user