diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 4806593020..b86f2278cc 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -49,8 +49,9 @@ namespace OpenRA.Mods.RA.Move { this.getPath = (self,mobile) => self.World.WorldActor.Trait().FindPath( - PathSearch.FromPoint( self.World, mobile.Info, self, mobile.toCell, destination, false ) - .WithIgnoredBuilding( ignoreBuilding )); + PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false) + .WithIgnoredBuilding(ignoreBuilding) + ); this.destination = destination; this.nearEnough = 0; diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index d2eb745c0f..2a7556f1d8 100755 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -90,13 +90,29 @@ namespace OpenRA.Mods.RA.Move using (new PerfSample("Pathfinder")) { using (search) + { + List path = null; + while (!search.queue.Empty) { var p = search.Expand(world); if (search.heuristic(p) == 0) - return MakePath(search.cellInfo, p); + { + path = MakePath(search.cellInfo, p); + break; + } } + var dbg = world.WorldActor.TraitOrDefault(); + if (dbg != null) + { + dbg.AddLayer(search.considered.Select(p => new Pair(p, search.cellInfo[p.X, p.Y].MinCost)), search.maxCost, search.owner); + } + + if (path != null) + return path; + } + // no path exists return new List(0); } @@ -120,8 +136,7 @@ namespace OpenRA.Mods.RA.Move public List FindBidiPath( /* searches from both ends toward each other */ PathSearch fromSrc, - PathSearch fromDest, - Player onBehalfOf) + PathSearch fromDest) { using (new PerfSample("Pathfinder")) { @@ -156,8 +171,8 @@ namespace OpenRA.Mods.RA.Move var dbg = world.WorldActor.TraitOrDefault(); if (dbg != null) { - dbg.AddLayer(fromSrc.considered.Select(p => new Pair(p, fromSrc.cellInfo[p.X, p.Y].MinCost)), fromSrc.maxCost, onBehalfOf); - dbg.AddLayer(fromDest.considered.Select(p => new Pair(p, fromDest.cellInfo[p.X, p.Y].MinCost)), fromDest.maxCost, onBehalfOf); + dbg.AddLayer(fromSrc.considered.Select(p => new Pair(p, fromSrc.cellInfo[p.X, p.Y].MinCost)), fromSrc.maxCost, fromSrc.owner); + dbg.AddLayer(fromDest.considered.Select(p => new Pair(p, fromDest.cellInfo[p.X, p.Y].MinCost)), fromDest.maxCost, fromDest.owner); } if (path != null) diff --git a/OpenRA.Mods.RA/Move/PathSearch.cs b/OpenRA.Mods.RA/Move/PathSearch.cs index be8b3d6d45..308de78e8e 100755 --- a/OpenRA.Mods.RA/Move/PathSearch.cs +++ b/OpenRA.Mods.RA/Move/PathSearch.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.FileFormats; using OpenRA.Traits; @@ -28,6 +29,7 @@ namespace OpenRA.Mods.RA.Move public bool inReverse; public HashSet considered; public int maxCost; + Pair[] nextDirections; MobileInfo mobileInfo; Actor self; public Player owner { get { return self.Owner; } } @@ -42,6 +44,7 @@ namespace OpenRA.Mods.RA.Move queue = new PriorityQueue(); considered = new HashSet(); maxCost = 0; + nextDirections = directions.Select(d => new Pair(d, 0)).ToArray(); } public PathSearch InReverse() @@ -114,8 +117,11 @@ namespace OpenRA.Mods.RA.Move // This current cell is ok; check all immediate directions: considered.Add(p.Location); - foreach( CVec d in directions ) + for (int i = 0; i < nextDirections.Length; ++i) { + CVec d = nextDirections[i].First; + nextDirections[i].Second = int.MaxValue; + CPos newHere = p.Location + d; // Is this direction flat-out unusable or already seen? @@ -171,12 +177,16 @@ namespace OpenRA.Mods.RA.Move cellInfo[newHere.X, newHere.Y].Path = p.Location; cellInfo[newHere.X, newHere.Y].MinCost = newCost; + nextDirections[i].Second = newCost + est; queue.Add(new PathDistance(newCost + est, newHere)); if (newCost > maxCost) maxCost = newCost; considered.Add(newHere); } + // Sort to prefer the cheaper direction: + Array.Sort(nextDirections, (a, b) => a.Second.CompareTo(b.Second)); + return p.Location; } diff --git a/OpenRA.Mods.RA/World/DebugOverlay.cs b/OpenRA.Mods.RA/World/DebugOverlay.cs index 5af455f1e5..64ce23e844 100644 --- a/OpenRA.Mods.RA/World/DebugOverlay.cs +++ b/OpenRA.Mods.RA/World/DebugOverlay.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA var qr = Game.Renderer.WorldQuadRenderer; bool doDim = refreshTick - world.FrameNumber <= 0; - if (doDim) refreshTick = world.FrameNumber + 15; + if (doDim) refreshTick = world.FrameNumber + 25; foreach (var pair in layers) {