more refs to Game.world (PathSearch)
This commit is contained in:
@@ -31,8 +31,8 @@ namespace OpenRa
|
||||
using (new PerfSample("find_unit_path"))
|
||||
{
|
||||
var pb = FindBidiPath(
|
||||
PathSearch.FromPoint(target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)),
|
||||
PathSearch.FromPoint(from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)));
|
||||
PathSearch.FromPoint(world, target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)),
|
||||
PathSearch.FromPoint(world, from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)));
|
||||
|
||||
CheckSanePath2(pb, from, target);
|
||||
return pb;
|
||||
@@ -46,7 +46,7 @@ namespace OpenRa
|
||||
var tilesInRange = world.FindTilesInCircle(target, range)
|
||||
.Where( t => world.IsCellBuildable( t, umt ) );
|
||||
|
||||
var path = FindPath( PathSearch.FromPoints( tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4)));
|
||||
var path = FindPath( PathSearch.FromPoints( world, tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4)));
|
||||
path.Reverse();
|
||||
return path;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace OpenRa
|
||||
{
|
||||
while (!search.queue.Empty)
|
||||
{
|
||||
var p = search.Expand( passableCost );
|
||||
var p = search.Expand( world, passableCost );
|
||||
PerfHistory.Increment("nodes_expanded", .01);
|
||||
|
||||
if (search.heuristic(p) == 0)
|
||||
@@ -103,13 +103,13 @@ namespace OpenRa
|
||||
while (!fromSrc.queue.Empty && !fromDest.queue.Empty)
|
||||
{
|
||||
/* make some progress on the first search */
|
||||
var p = fromSrc.Expand( passableCost );
|
||||
var p = fromSrc.Expand( world, passableCost );
|
||||
|
||||
if (fromDest.cellInfo[p.X, p.Y].Seen && fromDest.cellInfo[p.X, p.Y].MinCost < float.PositiveInfinity)
|
||||
return MakeBidiPath(fromSrc, fromDest, p);
|
||||
|
||||
/* make some progress on the second search */
|
||||
var q = fromDest.Expand( passableCost );
|
||||
var q = fromDest.Expand( world, passableCost );
|
||||
|
||||
if (fromSrc.cellInfo[q.X, q.Y].Seen && fromSrc.cellInfo[q.X, q.Y].MinCost < float.PositiveInfinity)
|
||||
return MakeBidiPath(fromSrc, fromDest, q);
|
||||
|
||||
@@ -34,12 +34,12 @@ namespace OpenRa
|
||||
return this;
|
||||
}
|
||||
|
||||
public int2 Expand( float[][ , ] passableCost )
|
||||
public int2 Expand( World world, float[][ , ] passableCost )
|
||||
{
|
||||
var p = queue.Pop();
|
||||
cellInfo[ p.Location.X, p.Location.Y ].Seen = true;
|
||||
|
||||
var custom2 = Game.world.customTerrain[p.Location.X, p.Location.Y];
|
||||
var custom2 = world.customTerrain[p.Location.X, p.Location.Y];
|
||||
var thisCost = (custom2 != null)
|
||||
? custom2.GetCost(p.Location, umt)
|
||||
: passableCost[(int)umt][p.Location.X, p.Location.Y];
|
||||
@@ -51,24 +51,24 @@ namespace OpenRa
|
||||
{
|
||||
int2 newHere = p.Location + d;
|
||||
|
||||
if (!Game.world.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||
if (!world.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||
continue;
|
||||
|
||||
var custom = Game.world.customTerrain[newHere.X, newHere.Y];
|
||||
var custom = world.customTerrain[newHere.X, newHere.Y];
|
||||
var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y];
|
||||
|
||||
if (costHere == float.PositiveInfinity)
|
||||
continue;
|
||||
|
||||
if (!Game.world.BuildingInfluence.CanMoveHere(newHere) &&
|
||||
Game.world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding)
|
||||
if (!world.BuildingInfluence.CanMoveHere(newHere) &&
|
||||
world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding)
|
||||
continue;
|
||||
if (Game.world.Map.IsOverlaySolid(newHere))
|
||||
if (world.Map.IsOverlaySolid(newHere))
|
||||
continue;
|
||||
|
||||
// Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units
|
||||
if (checkForBlocked && (Game.world.UnitInfluence.GetUnitsAt(newHere).Any(a => !Game.world.IsActorPathableToCrush(a, umt))))
|
||||
if (checkForBlocked && (world.UnitInfluence.GetUnitsAt(newHere).Any(a => !world.IsActorPathableToCrush(a, umt))))
|
||||
continue;
|
||||
|
||||
if (customBlock != null && customBlock(newHere))
|
||||
@@ -93,27 +93,27 @@ namespace OpenRa
|
||||
return p.Location;
|
||||
}
|
||||
|
||||
public void AddInitialCell( int2 location )
|
||||
public void AddInitialCell( World world, int2 location )
|
||||
{
|
||||
if (!Game.world.Map.IsInMap(location.X, location.Y))
|
||||
if (!world.Map.IsInMap(location.X, location.Y))
|
||||
return;
|
||||
|
||||
cellInfo[ location.X, location.Y ] = new CellInfo( 0, location, false );
|
||||
queue.Add( new PathDistance( heuristic( location ), location ) );
|
||||
}
|
||||
|
||||
public static PathSearch FromPoint( int2 from, int2 target, UnitMovementType umt, bool checkForBlocked )
|
||||
public static PathSearch FromPoint( World world, int2 from, int2 target, UnitMovementType umt, bool checkForBlocked )
|
||||
{
|
||||
var search = new PathSearch {
|
||||
heuristic = DefaultEstimator( target ),
|
||||
umt = umt,
|
||||
checkForBlocked = checkForBlocked };
|
||||
|
||||
search.AddInitialCell( from );
|
||||
search.AddInitialCell( world, from );
|
||||
return search;
|
||||
}
|
||||
|
||||
public static PathSearch FromPoints(IEnumerable<int2> froms, int2 target, UnitMovementType umt, bool checkForBlocked)
|
||||
public static PathSearch FromPoints(World world, IEnumerable<int2> froms, int2 target, UnitMovementType umt, bool checkForBlocked)
|
||||
{
|
||||
var search = new PathSearch
|
||||
{
|
||||
@@ -123,7 +123,7 @@ namespace OpenRa
|
||||
};
|
||||
|
||||
foreach (var sl in froms)
|
||||
search.AddInitialCell(sl);
|
||||
search.AddInitialCell(world, sl);
|
||||
|
||||
return search;
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ namespace OpenRa.Traits.Activities
|
||||
var refineries = self.World.Actors.Where( x => x.traits.Contains<AcceptsOre>()
|
||||
&& x.Owner == self.Owner ).ToList();
|
||||
if( refinery != null )
|
||||
search.AddInitialCell( refinery.Location + refineryDeliverOffset );
|
||||
search.AddInitialCell( self.World, refinery.Location + refineryDeliverOffset );
|
||||
else
|
||||
foreach( var r in refineries )
|
||||
search.AddInitialCell( r.Location + refineryDeliverOffset );
|
||||
search.AddInitialCell( self.World, r.Location + refineryDeliverOffset );
|
||||
|
||||
var path = self.World.PathFinder.FindPath( search );
|
||||
path.Reverse();
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRa.Traits.Activities
|
||||
umt = UnitMovementType.Wheel,
|
||||
checkForBlocked = true
|
||||
};
|
||||
search.AddInitialCell(self.Location);
|
||||
search.AddInitialCell(self.World, self.Location);
|
||||
return self.World.PathFinder.FindPath(search);
|
||||
}));
|
||||
self.QueueActivity(new Harvest());
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRa.Traits.Activities
|
||||
{
|
||||
this.getPath = (self, mobile) =>
|
||||
self.World.PathFinder.FindPath(
|
||||
PathSearch.FromPoint( self.Location, destination, mobile.GetMovementType(), false )
|
||||
PathSearch.FromPoint( self.World, self.Location, destination, mobile.GetMovementType(), false )
|
||||
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( self.Location, 4 )).WithIgnoredBuilding( ignoreBuilding ));
|
||||
|
||||
this.destination = destination;
|
||||
|
||||
Reference in New Issue
Block a user