From b1c51cc9108c27e2dc29074c9514e44dc767e84f Mon Sep 17 00:00:00 2001 From: atimoschenkow Date: Sun, 2 Aug 2015 12:29:35 +0200 Subject: [PATCH] Fix for #6161 queue commands for Plane/Heli (do not ignore Order.Queued in ResolveOrder()) --- OpenRA.Mods.Common/Activities/Air/Fly.cs | 22 +++++++ OpenRA.Mods.Common/Activities/Air/HeliFly.cs | 26 ++++++++ OpenRA.Mods.Common/Activities/Air/TakeOff.cs | 8 ++- OpenRA.Mods.Common/Traits/Air/Helicopter.cs | 65 +++++++++----------- OpenRA.Mods.Common/Traits/Air/Plane.cs | 15 ++--- 5 files changed, 89 insertions(+), 47 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index 8673e69413..07fd021b00 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -84,4 +84,26 @@ namespace OpenRA.Mods.Common.Activities yield return target; } } + + public class FlyAndContinueWithCirclesWhenIdle : Fly + { + public FlyAndContinueWithCirclesWhenIdle(Actor self, Target t) + : base(self, t) { } + + public FlyAndContinueWithCirclesWhenIdle(Actor self, Target t, WDist minRange, WDist maxRange) + : base(self, t, minRange, maxRange) { } + + public override Activity Tick(Actor self) + { + var activity = base.Tick(self); + + if (activity == null && !IsCanceled) + { + self.QueueActivity(new FlyCircle(self)); + activity = NextActivity; + } + + return activity; + } + } } diff --git a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs index 8c71abf7e1..1de1df70aa 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs @@ -92,4 +92,30 @@ namespace OpenRA.Mods.Common.Activities yield return target; } } + + public class HeliFlyAndLandWhenIdle : HeliFly + { + private readonly HelicopterInfo info; + + public HeliFlyAndLandWhenIdle(Actor self, Target t, HelicopterInfo info) + : base(self, t) + { + this.info = info; + } + + public override Activity Tick(Actor self) + { + var activity = base.Tick(self); + + if (activity == null && !IsCanceled && info.LandWhenIdle) + { + if (info.TurnToLand) + self.QueueActivity(new Turn(self, info.InitialFacing)); + self.QueueActivity(new HeliLand(self, true)); + activity = NextActivity; + } + + return activity; + } + } } diff --git a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs index e12e259b27..24de372431 100644 --- a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs +++ b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs @@ -27,7 +27,8 @@ namespace OpenRA.Mods.Common.Activities public override Activity Tick(Actor self) { - self.CancelActivity(); + if (NextActivity == null) + self.CancelActivity(); var reservation = aircraft.Reservation; if (reservation != null) @@ -43,7 +44,10 @@ namespace OpenRA.Mods.Common.Activities var destination = rp != null ? rp.Location : (hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location); - return new AttackMoveActivity(self, move.MoveTo(destination, 1)); + if (NextActivity == null) + return new AttackMoveActivity(self, move.MoveTo(destination, 1)); + else + return NextActivity; } } } diff --git a/OpenRA.Mods.Common/Traits/Air/Helicopter.cs b/OpenRA.Mods.Common/Traits/Air/Helicopter.cs index bcea3cbba0..99bebad797 100644 --- a/OpenRA.Mods.Common/Traits/Air/Helicopter.cs +++ b/OpenRA.Mods.Common/Traits/Air/Helicopter.cs @@ -49,12 +49,6 @@ namespace OpenRA.Mods.Common.Traits public void ResolveOrder(Actor self, Order order) { - if (Reservation != null) - { - Reservation.Dispose(); - Reservation = null; - } - if (order.OrderString == "Move") { var cell = self.World.Map.Clamp(order.TargetLocation); @@ -64,46 +58,45 @@ namespace OpenRA.Mods.Common.Traits return; var target = Target.FromCell(self.World, cell); - self.SetTargetLine(target, Color.Green); - self.CancelActivity(); - self.QueueActivity(new HeliFly(self, target)); - if (Info.LandWhenIdle) - { - if (Info.TurnToLand) - self.QueueActivity(new Turn(self, Info.InitialFacing)); + if (!order.Queued) + UnReserve(); - self.QueueActivity(new HeliLand(self, true)); - } + self.QueueActivity(order.Queued, new HeliFlyAndLandWhenIdle(self, target, Info)); } - - if (order.OrderString == "Enter") + else if (order.OrderString == "Enter") { - if (Reservable.IsReserved(order.TargetActor)) + Action enter = () => { - self.CancelActivity(); - self.QueueActivity(new HeliReturn(self)); - } - else - { - var res = order.TargetActor.TraitOrDefault(); - if (res != null) - Reservation = res.Reserve(order.TargetActor, self, this); + if (Reservable.IsReserved(order.TargetActor)) + self.QueueActivity(order.Queued, new HeliReturn(self)); + else + { + var res = order.TargetActor.TraitOrDefault(); + if (res != null) + Reservation = res.Reserve(order.TargetActor, self, this); - var exit = order.TargetActor.Info.Traits.WithInterface().FirstOrDefault(); - var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero; + var exit = order.TargetActor.Info.Traits.WithInterface().FirstOrDefault(); + var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero; - self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green); + self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green); - self.CancelActivity(); - self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset))); - self.QueueActivity(new Turn(self, Info.InitialFacing)); - self.QueueActivity(new HeliLand(self, false)); - self.QueueActivity(new ResupplyAircraft(self)); - self.QueueActivity(new TakeOff(self)); - } + self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset))); + self.QueueActivity(new Turn(self, Info.InitialFacing)); + self.QueueActivity(new HeliLand(self, false)); + self.QueueActivity(new ResupplyAircraft(self)); + self.QueueActivity(new TakeOff(self)); + } + }; + + self.QueueActivity(order.Queued, new CallFunc(enter)); + + if (!order.Queued) + UnReserve(); } + else + UnReserve(); if (order.OrderString == "ReturnToBase") { diff --git a/OpenRA.Mods.Common/Traits/Air/Plane.cs b/OpenRA.Mods.Common/Traits/Air/Plane.cs index b993cefe03..2764216969 100644 --- a/OpenRA.Mods.Common/Traits/Air/Plane.cs +++ b/OpenRA.Mods.Common/Traits/Air/Plane.cs @@ -83,25 +83,22 @@ namespace OpenRA.Mods.Common.Traits if (!explored && !Info.MoveIntoShroud) return; - UnReserve(); + if (!order.Queued) + UnReserve(); var target = Target.FromCell(self.World, cell); self.SetTargetLine(target, Color.Green); - self.CancelActivity(); - self.QueueActivity(new Fly(self, target)); - self.QueueActivity(new FlyCircle(self)); + self.QueueActivity(order.Queued, new FlyAndContinueWithCirclesWhenIdle(self, target)); } else if (order.OrderString == "Enter") { if (Reservable.IsReserved(order.TargetActor)) return; - UnReserve(); + if (!order.Queued) + UnReserve(); self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green); - - self.CancelActivity(); - self.QueueActivity(new ReturnToBase(self, order.TargetActor)); - self.QueueActivity(new ResupplyAircraft(self)); + self.QueueActivity(order.Queued, Util.SequenceActivities(new ReturnToBase(self, order.TargetActor), new ResupplyAircraft(self))); } else if (order.OrderString == "Stop") {