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) =>
|
||||
self.World.WorldActor.Trait<PathFinder>().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;
|
||||
|
||||
@@ -90,13 +90,29 @@ namespace OpenRA.Mods.RA.Move
|
||||
using (new PerfSample("Pathfinder"))
|
||||
{
|
||||
using (search)
|
||||
{
|
||||
List<CPos> 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<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
|
||||
return new List<CPos>(0);
|
||||
}
|
||||
@@ -120,8 +136,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public List<CPos> 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<DebugOverlay>();
|
||||
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(fromDest.considered.Select(p => new Pair<CPos, int>(p, fromDest.cellInfo[p.X, p.Y].MinCost)), fromDest.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, fromDest.owner);
|
||||
}
|
||||
|
||||
if (path != null)
|
||||
|
||||
@@ -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<CPos> considered;
|
||||
public int maxCost;
|
||||
Pair<CVec, int>[] nextDirections;
|
||||
MobileInfo mobileInfo;
|
||||
Actor self;
|
||||
public Player owner { get { return self.Owner; } }
|
||||
@@ -42,6 +44,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
queue = new PriorityQueue<PathDistance>();
|
||||
considered = new HashSet<CPos>();
|
||||
maxCost = 0;
|
||||
nextDirections = directions.Select(d => new Pair<CVec, int>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user