This commit is contained in:
Chris Forbes
2010-03-28 16:54:53 +13:00
parent b677f3cb56
commit c6804dff9c

View File

@@ -36,10 +36,17 @@ namespace OpenRA
public bool checkForBlocked; public bool checkForBlocked;
public Actor ignoreBuilding; public Actor ignoreBuilding;
BuildingInfluence buildingInfluence;
UnitInfluence unitInfluence;
public PathSearch() public PathSearch()
{ {
cellInfo = InitCellInfo(); cellInfo = InitCellInfo();
queue = new PriorityQueue<PathDistance>(); queue = new PriorityQueue<PathDistance>();
// hack: should be passing in World, not using Game.world.
buildingInfluence = Game.world.WorldActor.traits.Get<BuildingInfluence>();
unitInfluence = Game.world.WorldActor.traits.Get<UnitInfluence>();
} }
public PathSearch WithCustomBlocker(Func<int2, bool> customBlock) public PathSearch WithCustomBlocker(Func<int2, bool> customBlock)
@@ -67,8 +74,6 @@ namespace OpenRA
if (thisCost == float.PositiveInfinity) if (thisCost == float.PositiveInfinity)
return p.Location; return p.Location;
var bi = world.WorldActor.traits.Get<BuildingInfluence>();
foreach( int2 d in directions ) foreach( int2 d in directions )
{ {
int2 newHere = p.Location + d; int2 newHere = p.Location + d;
@@ -83,11 +88,11 @@ namespace OpenRA
if (costHere == float.PositiveInfinity) if (costHere == float.PositiveInfinity)
continue; continue;
if (!bi.CanMoveHere(newHere, ignoreBuilding)) if (!buildingInfluence.CanMoveHere(newHere, ignoreBuilding))
continue; continue;
// Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units // Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units
if (checkForBlocked && (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(newHere).Any(a => !world.IsActorPathableToCrush(a, umt)))) if (checkForBlocked && (unitInfluence.GetUnitsAt(newHere).Any(a => !world.IsActorPathableToCrush(a, umt))))
continue; continue;
if (customBlock != null && customBlock(newHere)) if (customBlock != null && customBlock(newHere))