diff --git a/OpenRA.Mods.Cnc/Traits/Disguise.cs b/OpenRA.Mods.Cnc/Traits/Disguise.cs index 10201b20b2..bb6c0cd625 100644 --- a/OpenRA.Mods.Cnc/Traits/Disguise.cs +++ b/OpenRA.Mods.Cnc/Traits/Disguise.cs @@ -79,6 +79,12 @@ namespace OpenRA.Mods.Cnc.Traits [Desc("The condition to grant to self while disguised.")] public readonly string DisguisedCondition = null; + [Desc("What diplomatic stances can this actor disguise as.")] + public readonly Stance ValidStances = Stance.Ally | Stance.Neutral | Stance.Enemy; + + [Desc("Target types of actors that this actor disguise as.")] + public readonly HashSet TargetTypes = new HashSet { "Disguise" }; + [Desc("Triggers which cause the actor to drop it's disguise. Possible values: None, Attack, Damaged,", "Unload, Infiltrate, Demolish.")] public readonly RevealDisguiseType RevealDisguiseOn = RevealDisguiseType.Attack; @@ -117,7 +123,7 @@ namespace OpenRA.Mods.Cnc.Traits { get { - yield return new TargetTypeOrderTargeter(new HashSet { "Disguise" }, "Disguise", 7, "ability", true, true) { ForceAttack = false }; + yield return new DisguiseOrderTargeter(info); } } @@ -244,4 +250,36 @@ namespace OpenRA.Mods.Cnc.Traits DisguiseAs(null); } } + + class DisguiseOrderTargeter : UnitOrderTargeter + { + readonly DisguiseInfo info; + + public DisguiseOrderTargeter(DisguiseInfo info) + : base("Disguise", 7, "ability", true, true) + { + this.info = info; + ForceAttack = false; + } + + public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) + { + var stance = self.Owner.Stances[target.Owner]; + + if (!info.ValidStances.HasStance(stance)) + return false; + + return info.TargetTypes.Overlaps(target.GetAllTargetTypes()); + } + + public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) + { + var stance = self.Owner.Stances[target.Owner]; + + if (!info.ValidStances.HasStance(stance)) + return false; + + return info.TargetTypes.Overlaps(target.Info.TraitInfos().SelectMany(ti => ti.GetTargetTypes())); + } + } }