diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index afcada806a..a6efcff4cb 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -285,7 +285,7 @@ namespace OpenRA.Traits public interface IMove { Activity MoveTo(CPos cell, int nearEnough); - Activity MoveTo(CPos cell, Actor ignoredActor); + Activity MoveTo(CPos cell, Actor ignoreActor); Activity MoveWithinRange(Target target, WDist range); Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange); Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange); diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 6d728670c5..153d81e68a 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities readonly Mobile mobile; readonly WDist nearEnough; readonly Func> getPath; - readonly Actor ignoredActor; + readonly Actor ignoreActor; List path; CPos? destination; @@ -57,14 +57,15 @@ namespace OpenRA.Mods.Common.Activities nearEnough = WDist.Zero; } - public Move(Actor self, CPos destination, WDist nearEnough) + public Move(Actor self, CPos destination, WDist nearEnough, Actor ignoreActor = null) { mobile = self.Trait(); getPath = () => self.World.WorldActor.Trait() - .FindUnitPath(mobile.ToCell, destination, self); + .FindUnitPath(mobile.ToCell, destination, self, ignoreActor); this.destination = destination; this.nearEnough = nearEnough; + this.ignoreActor = ignoreActor; } public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough) @@ -77,25 +78,6 @@ namespace OpenRA.Mods.Common.Activities this.nearEnough = nearEnough; } - public Move(Actor self, CPos destination, Actor ignoredActor) - { - mobile = self.Trait(); - - getPath = () => - { - List path; - using (var search = - PathSearch.FromPoint(self.World, mobile.Info, self, mobile.ToCell, destination, false) - .WithIgnoredActor(ignoredActor)) - path = self.World.WorldActor.Trait().FindPath(search); - return path; - }; - - this.destination = destination; - nearEnough = WDist.Zero; - this.ignoredActor = ignoredActor; - } - public Move(Actor self, Target target, WDist range) { mobile = self.Trait(); @@ -227,7 +209,7 @@ namespace OpenRA.Mods.Common.Activities var containsTemporaryBlocker = WorldUtils.ContainsTemporaryBlocker(self.World, nextCell, self); // Next cell in the move is blocked by another actor - if (containsTemporaryBlocker || !mobile.CanEnterCell(nextCell, ignoredActor, true)) + if (containsTemporaryBlocker || !mobile.CanEnterCell(nextCell, ignoreActor, true)) { // Are we close enough? var cellRange = nearEnough.Length / 1024; @@ -275,7 +257,7 @@ namespace OpenRA.Mods.Common.Activities hasWaited = false; path.RemoveAt(path.Count - 1); - var subCell = mobile.GetAvailableSubCell(nextCell, SubCell.Any, ignoredActor); + var subCell = mobile.GetAvailableSubCell(nextCell, SubCell.Any, ignoreActor); return Pair.New(nextCell, subCell); } diff --git a/OpenRA.Mods.Common/Pathfinder/BasePathSearch.cs b/OpenRA.Mods.Common/Pathfinder/BasePathSearch.cs index d3f909ebea..e600b55bf1 100644 --- a/OpenRA.Mods.Common/Pathfinder/BasePathSearch.cs +++ b/OpenRA.Mods.Common/Pathfinder/BasePathSearch.cs @@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Pathfinder public IPathSearch WithIgnoredActor(Actor b) { - Graph.IgnoredActor = b; + Graph.IgnoreActor = b; return this; } diff --git a/OpenRA.Mods.Common/Pathfinder/PathFinderUnitPathCacheDecorator.cs b/OpenRA.Mods.Common/Pathfinder/PathFinderUnitPathCacheDecorator.cs index 77a1a076ea..dcaed0aa74 100644 --- a/OpenRA.Mods.Common/Pathfinder/PathFinderUnitPathCacheDecorator.cs +++ b/OpenRA.Mods.Common/Pathfinder/PathFinderUnitPathCacheDecorator.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Pathfinder this.cacheStorage = cacheStorage; } - public List FindUnitPath(CPos source, CPos target, Actor self) + public List FindUnitPath(CPos source, CPos target, Actor self, Actor ignoreActor) { using (new PerfSample("Pathfinder")) { @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Pathfinder if (cachedPath != null) return cachedPath; - var pb = pathFinder.FindUnitPath(source, target, self); + var pb = pathFinder.FindUnitPath(source, target, self, ignoreActor); cacheStorage.Store(key, pb); diff --git a/OpenRA.Mods.Common/Pathfinder/PathGraph.cs b/OpenRA.Mods.Common/Pathfinder/PathGraph.cs index e8225088d9..81c2be510a 100644 --- a/OpenRA.Mods.Common/Pathfinder/PathGraph.cs +++ b/OpenRA.Mods.Common/Pathfinder/PathGraph.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Pathfinder bool InReverse { get; set; } - Actor IgnoredActor { get; set; } + Actor IgnoreActor { get; set; } World World { get; } @@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Pathfinder public Func CustomCost { get; set; } public int LaneBias { get; set; } public bool InReverse { get; set; } - public Actor IgnoredActor { get; set; } + public Actor IgnoreActor { get; set; } readonly CellConditions checkConditions; readonly MobileInfo mobileInfo; @@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Pathfinder int GetCostToNode(CPos destNode, CVec direction) { - var movementCost = mobileInfo.MovementCostToEnterCell(worldMovementInfo, Actor, destNode, IgnoredActor, checkConditions); + var movementCost = mobileInfo.MovementCostToEnterCell(worldMovementInfo, Actor, destNode, IgnoreActor, checkConditions); if (movementCost != int.MaxValue && !(CustomBlock != null && CustomBlock(destNode))) return CalculateCellCost(destNode, direction, movementCost); diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 389eb3007c..87f15baaca 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -453,7 +453,7 @@ namespace OpenRA.Mods.Common.Traits return new HeliFly(self, Target.FromCell(self.World, cell)); } - public Activity MoveTo(CPos cell, Actor ignoredActor) + public Activity MoveTo(CPos cell, Actor ignoreActor) { if (IsPlane) return new FlyAndContinueWithCirclesWhenIdle(self, Target.FromCell(self.World, cell)); diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index c3d62c08e9..12395a9590 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -914,7 +914,7 @@ namespace OpenRA.Mods.Common.Traits public Activity ScriptedMove(CPos cell) { return new Move(self, cell); } public Activity MoveTo(CPos cell, int nearEnough) { return new Move(self, cell, WDist.FromCells(nearEnough)); } - public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(self, cell, ignoredActor); } + public Activity MoveTo(CPos cell, Actor ignoreActor) { return new Move(self, cell, WDist.Zero, ignoreActor); } public Activity MoveWithinRange(Target target, WDist range) { return new MoveWithinRange(self, target, WDist.Zero, range); } public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange) { return new MoveWithinRange(self, target, minRange, maxRange); } public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange) { return new Follow(self, target, minRange, maxRange); } diff --git a/OpenRA.Mods.Common/Traits/World/PathFinder.cs b/OpenRA.Mods.Common/Traits/World/PathFinder.cs index d6906ff34c..ee19f8089e 100644 --- a/OpenRA.Mods.Common/Traits/World/PathFinder.cs +++ b/OpenRA.Mods.Common/Traits/World/PathFinder.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits /// Calculates a path for the actor from source to destination /// /// A path from start to target - List FindUnitPath(CPos source, CPos target, Actor self); + List FindUnitPath(CPos source, CPos target, Actor self, Actor ignoreActor); List FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WDist range, Actor self); @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits this.world = world; } - public List FindUnitPath(CPos source, CPos target, Actor self) + public List FindUnitPath(CPos source, CPos target, Actor self, Actor ignoreActor) { var mi = self.Info.TraitInfo(); @@ -74,8 +74,8 @@ namespace OpenRA.Mods.Common.Traits } List pb; - using (var fromSrc = PathSearch.FromPoint(world, mi, self, target, source, true)) - using (var fromDest = PathSearch.FromPoint(world, mi, self, source, target, true).Reverse()) + using (var fromSrc = PathSearch.FromPoint(world, mi, self, target, source, true).WithIgnoredActor(ignoreActor)) + using (var fromDest = PathSearch.FromPoint(world, mi, self, source, target, true).WithIgnoredActor(ignoreActor).Reverse()) pb = FindBidiPath(fromSrc, fromDest); CheckSanePath2(pb, source, target);