From e805461be7e6414b1d72ee0a048fa05892081cb4 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 18 Jul 2014 23:17:50 +1200 Subject: [PATCH 1/3] =?UTF-8?q?Don=E2=80=99t=20cancel=20MoveAdjacentTo=20/?= =?UTF-8?q?=20MoveWithinRange=20when=20target=20becomes=20invalid.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move to the last known position instead. Fixes #5968. --- OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs index b488b5ce90..373f719ac2 100755 --- a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs +++ b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs @@ -17,12 +17,12 @@ namespace OpenRA.Mods.RA.Activities { public class MoveAdjacentTo : Activity { - protected readonly Target target; readonly Mobile mobile; readonly PathFinder pathFinder; readonly DomainIndex domainIndex; readonly uint movementClass; + protected Target target { get; private set; } protected CPos targetPosition; Activity inner; bool repath; @@ -87,10 +87,8 @@ namespace OpenRA.Mods.RA.Activities } else { - // Target became invalid. Cancel the inner order, - // and then wait for it to move into the next cell - // before finishing this order (handled above). - inner.Cancel(self); + // Target became invalid. Move to its last known position. + target = Target.FromCell(self.World, targetPosition); } // Ticks the inner move activity to actually move the actor. From 5b0cee78cf2b71e2de6ffa1fedd3b53118f77f11 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 19 Jul 2014 16:17:08 +1200 Subject: [PATCH 2/3] Calculate a new path (and possibly new target cell) if the original path is blocked. --- OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs index 373f719ac2..23b0206a57 100755 --- a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs +++ b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.RA.Move; @@ -17,6 +18,8 @@ namespace OpenRA.Mods.RA.Activities { public class MoveAdjacentTo : Activity { + static readonly List NoPath = new List(); + readonly Mobile mobile; readonly PathFinder pathFinder; readonly DomainIndex domainIndex; @@ -52,6 +55,11 @@ namespace OpenRA.Mods.RA.Activities return targetPosition != oldTargetPosition; } + protected virtual IEnumerable CandidateMovementCells(Actor self) + { + return Util.AdjacentCells(self.World, target); + } + public override Activity Tick(Actor self) { var targetIsValid = target.IsValidFor(self); @@ -65,7 +73,7 @@ namespace OpenRA.Mods.RA.Activities return NextActivity; // Target has moved, and MoveAdjacentTo is still valid. - UpdateInnerPath(self); + inner = mobile.MoveTo(() => CalculatePathToTarget(self)); repath = false; } @@ -97,12 +105,7 @@ namespace OpenRA.Mods.RA.Activities return this; } - protected virtual IEnumerable CandidateMovementCells(Actor self) - { - return Util.AdjacentCells(self.World, target); - } - - void UpdateInnerPath(Actor self) + List CalculatePathToTarget(Actor self) { var targetCells = CandidateMovementCells(self); var searchCells = new List(); @@ -113,14 +116,12 @@ namespace OpenRA.Mods.RA.Activities searchCells.Add(cell); if (!searchCells.Any()) - return; + return NoPath; - var path = pathFinder.FindBidiPath( - PathSearch.FromPoints(self.World, mobile.Info, self, searchCells, loc, true), - PathSearch.FromPoint(self.World, mobile.Info, self, loc, targetPosition, true).Reverse() - ); + var fromSrc = PathSearch.FromPoints(self.World, mobile.Info, self, searchCells, loc, true); + var fromDest = PathSearch.FromPoint(self.World, mobile.Info, self, loc, targetPosition, true).Reverse(); - inner = mobile.MoveTo(() => path); + return pathFinder.FindBidiPath(fromSrc, fromDest); } public override IEnumerable GetTargets(Actor self) From 850fcd5100ff3b8e6d91f365237c93554441a767 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 19 Jul 2014 16:17:30 +1200 Subject: [PATCH 3/3] Fix a typo. --- OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs index 23b0206a57..6e6c31eced 100755 --- a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs +++ b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs @@ -83,14 +83,14 @@ namespace OpenRA.Mods.RA.Activities var oldTargetPosition = targetPosition; targetPosition = self.World.Map.CellContaining(target.CenterPosition); - var shroudStop = ShouldStop(self, oldTargetPosition); - if (shroudStop || (!repath && ShouldRepath(self, oldTargetPosition))) + var shouldStop = ShouldStop(self, oldTargetPosition); + if (shouldStop || (!repath && ShouldRepath(self, oldTargetPosition))) { // Finish moving into the next cell and then repath. if (inner != null) inner.Cancel(self); - repath = !shroudStop; + repath = !shouldStop; } } else