customBlocker support in PathSearch; local unit avoidance in normal unit pathing
This commit is contained in:
@@ -46,16 +46,14 @@ namespace OpenRa.Game
|
||||
using (new PerfSample("find_unit_path"))
|
||||
{
|
||||
var pb = FindBidiPath(
|
||||
PathSearch.FromPoint(target, from, umt, false),
|
||||
PathSearch.FromPoint(from, target, umt, false));
|
||||
PathSearch.FromPoint(target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)),
|
||||
PathSearch.FromPoint(from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)));
|
||||
|
||||
CheckSanePath2(pb, from, target);
|
||||
return pb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<int2> FindUnitPathToRange( int2 src, int2 target, UnitMovementType umt, int range )
|
||||
{
|
||||
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
||||
@@ -69,15 +67,11 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
public List<int2> FindPathToPath( int2 from, List<int2> path, UnitMovementType umt )
|
||||
Func<int2, bool> AvoidUnitsNear(int2 p, int dist)
|
||||
{
|
||||
if( IsBlocked( from, umt ) )
|
||||
return new List<int2>();
|
||||
|
||||
using (new PerfSample("find_path_to_path"))
|
||||
return FindBidiPath(
|
||||
PathSearch.FromPath(path, from, umt, true),
|
||||
PathSearch.FromPoint(from, path[0], umt, true));
|
||||
return q =>
|
||||
((p - q).LengthSquared < dist * dist) &&
|
||||
(Game.UnitInfluence.GetUnitAt(q) != null);
|
||||
}
|
||||
|
||||
public List<int2> FindPath( PathSearch search )
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace OpenRa.Game
|
||||
public PriorityQueue<PathDistance> queue;
|
||||
public Func<int2, float> heuristic;
|
||||
public UnitMovementType umt;
|
||||
Func<int2, bool> customBlock;
|
||||
public bool checkForBlocked;
|
||||
|
||||
public PathSearch()
|
||||
@@ -21,6 +22,12 @@ namespace OpenRa.Game
|
||||
queue = new PriorityQueue<PathDistance>();
|
||||
}
|
||||
|
||||
public PathSearch WithCustomBlocker(Func<int2, bool> customBlock)
|
||||
{
|
||||
this.customBlock = customBlock;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int2 Expand( float[][ , ] passableCost )
|
||||
{
|
||||
var p = queue.Pop();
|
||||
@@ -38,6 +45,9 @@ namespace OpenRa.Game
|
||||
continue;
|
||||
if( checkForBlocked && Game.UnitInfluence.GetUnitAt( newHere ) != null )
|
||||
continue;
|
||||
if (customBlock != null && customBlock(newHere))
|
||||
continue;
|
||||
|
||||
var est = heuristic( newHere );
|
||||
if( est == float.PositiveInfinity )
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user