diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index ec8aedeca3..bd4e391a21 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -294,6 +294,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var target in targetsInRange) { BitSet targetTypes; + Player owner; if (target.Type == TargetType.Actor) { // PERF: Most units can only attack enemy units. If this is the case but the target is not an enemy, we @@ -308,6 +309,8 @@ namespace OpenRA.Mods.Common.Traits if (PreventsAutoTarget(self, target.Actor) || !target.Actor.CanBeViewedByPlayer(self.Owner)) continue; + + owner = target.Actor.Owner; } else if (target.Type == TargetType.FrozenActor) { @@ -315,6 +318,7 @@ namespace OpenRA.Mods.Common.Traits continue; targetTypes = target.FrozenActor.TargetTypes; + owner = target.FrozenActor.Owner; } else continue; @@ -325,6 +329,10 @@ namespace OpenRA.Mods.Common.Traits if (ati.Priority < chosenTargetPriority) return false; + // Incompatible stances + if (!ati.ValidStances.HasStance(self.Owner.Stances[owner])) + return false; + // Incompatible target types if (!ati.ValidTargets.Overlaps(targetTypes) || ati.InvalidTargets.Overlaps(targetTypes)) return false; diff --git a/OpenRA.Mods.Common/Traits/AutoTargetPriority.cs b/OpenRA.Mods.Common/Traits/AutoTargetPriority.cs index 1deb843a9c..75fc3be7f1 100644 --- a/OpenRA.Mods.Common/Traits/AutoTargetPriority.cs +++ b/OpenRA.Mods.Common/Traits/AutoTargetPriority.cs @@ -23,6 +23,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Target types that can't be AutoTargeted.", "Overrules ValidTargets.")] public readonly BitSet InvalidTargets; + [Desc("Stances between actor's and target's owner which can be AutoTargeted.")] + public readonly Stance ValidStances = Stance.Ally | Stance.Neutral | Stance.Enemy; + [Desc("ValidTargets with larger priorities will be AutoTargeted before lower priorities.")] public readonly int Priority = 1;