From c096fbde962a7e36aaaf77e1a0889fa3d90dff29 Mon Sep 17 00:00:00 2001 From: tovl Date: Sun, 27 Jan 2019 18:13:55 +0100 Subject: [PATCH] make portable chrono queueable give PortableChrono fallback movement style fix add chrono target line require and cache IMove --- OpenRA.Mods.Cnc/Activities/Teleport.cs | 2 +- OpenRA.Mods.Cnc/Traits/PortableChrono.cs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Cnc/Activities/Teleport.cs b/OpenRA.Mods.Cnc/Activities/Teleport.cs index a7c21de000..33b1d8b16f 100644 --- a/OpenRA.Mods.Cnc/Activities/Teleport.cs +++ b/OpenRA.Mods.Cnc/Activities/Teleport.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Cnc.Activities public override Activity Tick(Actor self) { var pc = self.TraitOrDefault(); - if (teleporter == self && pc != null && !pc.CanTeleport) + if (teleporter == self && pc != null && (!pc.CanTeleport || IsCanceling)) { if (killOnFailure) self.Kill(teleporter, killDamageTypes); diff --git a/OpenRA.Mods.Cnc/Traits/PortableChrono.cs b/OpenRA.Mods.Cnc/Traits/PortableChrono.cs index fb8b6263b0..02441da3cf 100644 --- a/OpenRA.Mods.Cnc/Traits/PortableChrono.cs +++ b/OpenRA.Mods.Cnc/Traits/PortableChrono.cs @@ -14,12 +14,13 @@ using OpenRA.Graphics; using OpenRA.Mods.Cnc.Activities; using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Orders; +using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Traits { - class PortableChronoInfo : ITraitInfo + class PortableChronoInfo : ITraitInfo, Requires { [Desc("Cooldown in ticks until the unit can teleport.")] public readonly int ChargeDelay = 500; @@ -53,17 +54,19 @@ namespace OpenRA.Mods.Cnc.Traits [VoiceReference] public readonly string Voice = "Action"; - public object Create(ActorInitializer init) { return new PortableChrono(this); } + public object Create(ActorInitializer init) { return new PortableChrono(init.Self, this); } } class PortableChrono : IIssueOrder, IResolveOrder, ITick, ISelectionBar, IOrderVoice, ISync { - [Sync] int chargeTick = 0; public readonly PortableChronoInfo Info; + readonly IMove move; + [Sync] int chargeTick = 0; - public PortableChrono(PortableChronoInfo info) + public PortableChrono(Actor self, PortableChronoInfo info) { Info = info; + move = self.Trait(); } void ITick.Tick(Actor self) @@ -102,19 +105,25 @@ namespace OpenRA.Mods.Cnc.Traits public void ResolveOrder(Actor self, Order order) { - if (order.OrderString == "PortableChronoTeleport" && CanTeleport && order.Target.Type != TargetType.Invalid) + if (order.OrderString == "PortableChronoTeleport" && order.Target.Type != TargetType.Invalid) { var maxDistance = Info.HasDistanceLimit ? Info.MaxDistance : (int?)null; - self.CancelActivity(); + if (!order.Queued) + self.CancelActivity(); var cell = self.World.Map.CellContaining(order.Target.CenterPosition); + self.SetTargetLine(order.Target, Color.LawnGreen); + if (maxDistance != null) + self.QueueActivity(move.MoveWithinRange(order.Target, WDist.FromCells(maxDistance.Value))); + self.QueueActivity(new Teleport(self, cell, maxDistance, Info.KillCargo, Info.FlashScreen, Info.ChronoshiftSound)); + self.QueueActivity(move.MoveTo(cell, 5)); } } string IOrderVoice.VoicePhraseForOrder(Actor self, Order order) { - return order.OrderString == "PortableChronoTeleport" && CanTeleport ? Info.Voice : null; + return order.OrderString == "PortableChronoTeleport" ? Info.Voice : null; } public void ResetChargeTime()