diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index f582f70dcd..2acb47f6f5 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -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 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 FindPathToPath( int2 from, List path, UnitMovementType umt ) + Func AvoidUnitsNear(int2 p, int dist) { - if( IsBlocked( from, umt ) ) - return new List(); - - 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 FindPath( PathSearch search ) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index fcf140e490..9db1a97464 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -13,6 +13,7 @@ namespace OpenRa.Game public PriorityQueue queue; public Func heuristic; public UnitMovementType umt; + Func customBlock; public bool checkForBlocked; public PathSearch() @@ -21,6 +22,12 @@ namespace OpenRa.Game queue = new PriorityQueue(); } + public PathSearch WithCustomBlocker(Func 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;