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)