diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 4e37f57b44..53afc27fda 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -52,9 +52,10 @@ namespace OpenRA.Mods.Common.Activities using (var search = PathSearch.FromPoint(self.World, mobile.Locomotor, self, mobile.ToCell, destination, check) .WithoutLaneBias()) - path = self.World.WorldActor.Trait().FindPath(search); + path = mobile.Pathfinder.FindPath(search); return path; }; + this.destination = destination; this.targetLineColor = targetLineColor; nearEnough = WDist.Zero; @@ -70,8 +71,7 @@ namespace OpenRA.Mods.Common.Activities if (!this.destination.HasValue) return NoPath; - return self.World.WorldActor.Trait() - .FindUnitPath(mobile.ToCell, this.destination.Value, self, ignoreActor, check); + return mobile.Pathfinder.FindUnitPath(mobile.ToCell, this.destination.Value, self, ignoreActor, check); }; // Note: Will be recalculated from OnFirstRun if evaluateNearestMovableCell is true @@ -87,8 +87,9 @@ namespace OpenRA.Mods.Common.Activities { mobile = self.Trait(); - getPath = check => self.World.WorldActor.Trait() - .FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self, check); + getPath = check => mobile.Pathfinder.FindUnitPathToRange( + mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self, check); + this.destination = destination; this.nearEnough = nearEnough; this.targetLineColor = targetLineColor; @@ -103,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities if (!target.IsValidFor(self)) return NoPath; - return self.World.WorldActor.Trait().FindUnitPathToRange( + return mobile.Pathfinder.FindUnitPathToRange( mobile.ToCell, mobile.ToSubCell, target.CenterPosition, range, self, check); }; diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index b325e1d2d3..0180f2e82f 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -217,6 +217,8 @@ namespace OpenRA.Mods.Common.Traits public Locomotor Locomotor { get; private set; } + public IPathFinder Pathfinder { get; private set; } + #region IOccupySpace [Sync] @@ -279,6 +281,7 @@ namespace OpenRA.Mods.Common.Traits notifyMoving = self.TraitsImplementing().ToArray(); notifyFinishedMoving = self.TraitsImplementing().ToArray(); moveWrappers = self.TraitsImplementing().ToArray(); + Pathfinder = self.World.WorldActor.Trait(); Locomotor = self.World.WorldActor.TraitsImplementing() .Single(l => l.Info.Name == Info.Locomotor);