diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs index 042196c94c..68c35a9074 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs @@ -184,12 +184,12 @@ namespace OpenRA.Mods.Common.Traits var location = self.World.Map.CellContaining(target.CenterPosition); var explored = self.Owner.Shroud.IsExplored(location); cursor = self.World.Map.Contains(location) ? - (self.World.Map.GetTerrainInfo(location).CustomCursor ?? "move") : - "move-blocked"; + self.World.Map.GetTerrainInfo(location).CustomCursor ?? "move" : "move-blocked"; IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); - if (!explored && !aircraft.Info.MoveIntoShroud) + if (!(self.CurrentActivity is Transform || aircraft.transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused)) + || (!explored && !aircraft.Info.MoveIntoShroud)) cursor = "move-blocked"; return true; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs index cb58aa5742..1a2d15d5e2 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs @@ -32,15 +32,19 @@ namespace OpenRA.Mods.Common.Traits [Desc("Require the force-move modifier to display the enter cursor.")] public readonly bool RequiresForceMove = false; - public override object Create(ActorInitializer init) { return new TransformsIntoEntersTunnels(this); } + public override object Create(ActorInitializer init) { return new TransformsIntoEntersTunnels(init.Self, this); } } public class TransformsIntoEntersTunnels : ConditionalTrait, IIssueOrder, IResolveOrder, IOrderVoice { + readonly Actor self; Transforms[] transforms; - public TransformsIntoEntersTunnels(TransformsIntoEntersTunnelsInfo info) - : base(info) { } + public TransformsIntoEntersTunnels(Actor self, TransformsIntoEntersTunnelsInfo info) + : base(info) + { + this.self = self; + } protected override void Created(Actor self) { @@ -53,10 +57,20 @@ namespace OpenRA.Mods.Common.Traits get { if (!IsTraitDisabled) - yield return new EntersTunnels.EnterTunnelOrderTargeter(Info.EnterCursor, Info.EnterBlockedCursor, () => Info.RequiresForceMove); + yield return new EntersTunnels.EnterTunnelOrderTargeter(Info.EnterCursor, Info.EnterBlockedCursor, CanEnterTunnel, UseEnterCursor); } } + bool CanEnterTunnel(Actor target, TargetModifiers modifiers) + { + return !Info.RequiresForceMove || modifiers.HasModifier(TargetModifiers.ForceMove); + } + + bool UseEnterCursor(Actor target) + { + return self.CurrentActivity is Transform || transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused); + } + Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) { if (order.OrderID == "EnterTunnel") diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs index e97c7d06b9..a948906d82 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs @@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits (self.World.Map.GetTerrainInfo(location).CustomCursor ?? mobile.Info.Cursor) : mobile.Info.BlockedCursor; var locomotor = mobile.Info.LocomotorInfo; - if (!mobile.transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused) + if (!(self.CurrentActivity is Transform || mobile.transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused)) || (!explored && !locomotor.MoveIntoShroud) || (explored && !CanEnterCell(self.World, self, location))) cursor = mobile.Info.BlockedCursor; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs index 0890c38695..cc77a4e414 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs @@ -32,15 +32,19 @@ namespace OpenRA.Mods.Common.Traits [Desc("Require the force-move modifier to display the enter cursor.")] public readonly bool RequiresForceMove = false; - public override object Create(ActorInitializer init) { return new TransformsIntoPassenger(this); } + public override object Create(ActorInitializer init) { return new TransformsIntoPassenger(init.Self, this); } } public class TransformsIntoPassenger : ConditionalTrait, IIssueOrder, IResolveOrder, IOrderVoice { + readonly Actor self; Transforms[] transforms; - public TransformsIntoPassenger(TransformsIntoPassengerInfo info) - : base(info) { } + public TransformsIntoPassenger(Actor self, TransformsIntoPassengerInfo info) + : base(info) + { + this.self = self; + } protected override void Created(Actor self) { @@ -81,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits bool CanEnter(Actor target) { - if (!transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused)) + if (!(self.CurrentActivity is Transform || transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused))) return false; var cargo = target.TraitOrDefault(); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs index ac1eeda8bd..c8a358fbf8 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs @@ -33,16 +33,20 @@ namespace OpenRA.Mods.Common.Traits [Desc("Require the force-move modifier to display the enter cursor.")] public readonly bool RequiresForceMove = false; - public override object Create(ActorInitializer init) { return new TransformsIntoRepairable(this); } + public override object Create(ActorInitializer init) { return new TransformsIntoRepairable(init.Self, this); } } public class TransformsIntoRepairable : ConditionalTrait, IIssueOrder, IResolveOrder, IOrderVoice { + readonly Actor self; Transforms[] transforms; IHealth health; - public TransformsIntoRepairable(TransformsIntoRepairableInfo info) - : base(info) { } + public TransformsIntoRepairable(Actor self, TransformsIntoRepairableInfo info) + : base(info) + { + this.self = self; + } protected override void Created(Actor self) { @@ -62,7 +66,10 @@ namespace OpenRA.Mods.Common.Traits bool CanRepair() { - return health.DamageState > DamageState.Undamaged && transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused); + if (!(self.CurrentActivity is Transform || transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused))) + return false; + + return health.DamageState > DamageState.Undamaged; } bool CanRepairAt(Actor target, TargetModifiers modifiers) diff --git a/OpenRA.Mods.Common/Traits/EntersTunnels.cs b/OpenRA.Mods.Common/Traits/EntersTunnels.cs index 7c08674455..1cd37d0480 100644 --- a/OpenRA.Mods.Common/Traits/EntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/EntersTunnels.cs @@ -51,10 +51,15 @@ namespace OpenRA.Mods.Common.Traits { get { - yield return new EnterTunnelOrderTargeter(info.EnterCursor, info.EnterBlockedCursor, () => requireForceMove); + yield return new EnterTunnelOrderTargeter(info.EnterCursor, info.EnterBlockedCursor, CanEnterTunnel, _ => true); } } + bool CanEnterTunnel(Actor target, TargetModifiers modifiers) + { + return !requireForceMove || modifiers.HasModifier(TargetModifiers.ForceMove); + } + public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) { if (order.OrderID != "EnterTunnel") @@ -100,19 +105,22 @@ namespace OpenRA.Mods.Common.Traits { readonly string enterCursor; readonly string enterBlockedCursor; - readonly Func requireForceMove; + readonly Func canTarget; + readonly Func useEnterCursor; - public EnterTunnelOrderTargeter(string enterCursor, string enterBlockedCursor, Func requireForceMove) + public EnterTunnelOrderTargeter(string enterCursor, string enterBlockedCursor, + Func canTarget, Func useEnterCursor) : base("EnterTunnel", 6, enterCursor, true, true) { this.enterCursor = enterCursor; this.enterBlockedCursor = enterBlockedCursor; - this.requireForceMove = requireForceMove; + this.canTarget = canTarget; + this.useEnterCursor = useEnterCursor; } public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) { - if (target == null || target.IsDead || (requireForceMove() && !modifiers.HasModifier(TargetModifiers.ForceMove))) + if (target == null || target.IsDead || !canTarget(target, modifiers)) return false; var tunnel = target.TraitOrDefault(); @@ -135,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits return false; } - cursor = enterCursor; + cursor = useEnterCursor(target) ? enterCursor : enterBlockedCursor; return true; }