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