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