Pathfinder uses a MobileInfo instead of a specific actor
This commit is contained in:
@@ -49,11 +49,13 @@ namespace OpenRA
|
|||||||
cached.tick = Game.LocalTick;
|
cached.tick = Game.LocalTick;
|
||||||
return new List<int2>(cached.result);
|
return new List<int2>(cached.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||||
|
|
||||||
var pb = FindBidiPath(
|
var pb = FindBidiPath(
|
||||||
PathSearch.FromPoint(self, target, from, true)
|
PathSearch.FromPoint(world, mi, target, from, true)
|
||||||
.WithCustomBlocker(AvoidUnitsNear(from, 4, self)),
|
.WithCustomBlocker(AvoidUnitsNear(from, 4, self)),
|
||||||
PathSearch.FromPoint(self, from, target, true)
|
PathSearch.FromPoint(world, mi, from, target, true)
|
||||||
.WithCustomBlocker(AvoidUnitsNear(from, 4, self))
|
.WithCustomBlocker(AvoidUnitsNear(from, 4, self))
|
||||||
.InReverse());
|
.InReverse());
|
||||||
|
|
||||||
@@ -69,11 +71,11 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
||||||
{
|
{
|
||||||
var mobile = self.Trait<Mobile>();
|
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||||
var tilesInRange = world.FindTilesInCircle(target, range)
|
var tilesInRange = world.FindTilesInCircle(target, range)
|
||||||
.Where( t => mobile.CanEnterCell(t));
|
.Where( t => Mobile.CanEnterCell(self.World, mobileInfo, t, null, true));
|
||||||
|
|
||||||
var path = FindPath( PathSearch.FromPoints( self, tilesInRange, src, false )
|
var path = FindPath( PathSearch.FromPoints( world, mobileInfo, tilesInRange, src, false )
|
||||||
.WithCustomBlocker(AvoidUnitsNear(src, 4, self))
|
.WithCustomBlocker(AvoidUnitsNear(src, 4, self))
|
||||||
.InReverse());
|
.InReverse());
|
||||||
path.Reverse();
|
path.Reverse();
|
||||||
|
|||||||
@@ -24,16 +24,19 @@ namespace OpenRA
|
|||||||
Func<int2, bool> customBlock;
|
Func<int2, bool> customBlock;
|
||||||
public bool checkForBlocked;
|
public bool checkForBlocked;
|
||||||
public Actor ignoreBuilding;
|
public Actor ignoreBuilding;
|
||||||
Actor self;
|
|
||||||
public bool inReverse;
|
public bool inReverse;
|
||||||
Mobile mobile;
|
|
||||||
|
MobileInfo mobileInfo;
|
||||||
public PathSearch(Actor self)
|
BuildingInfluence bim;
|
||||||
|
UnitInfluence uim;
|
||||||
|
|
||||||
|
public PathSearch(World world, MobileInfo mobileInfo)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.world = world;
|
||||||
world = self.World;
|
bim = world.WorldActor.Trait<BuildingInfluence>();
|
||||||
|
uim = world.WorldActor.Trait<UnitInfluence>();
|
||||||
cellInfo = InitCellInfo();
|
cellInfo = InitCellInfo();
|
||||||
mobile = self.Trait<Mobile>();
|
this.mobileInfo = mobileInfo;
|
||||||
queue = new PriorityQueue<PathDistance>();
|
queue = new PriorityQueue<PathDistance>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +72,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public PathSearch FromPoint(int2 from)
|
public PathSearch FromPoint(int2 from)
|
||||||
{
|
{
|
||||||
AddInitialCell( self.World, from );
|
AddInitialCell( world, from );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +89,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
cellInfo[p.Location.X, p.Location.Y].Seen = true;
|
cellInfo[p.Location.X, p.Location.Y].Seen = true;
|
||||||
|
|
||||||
var thisCost = mobile.MovementCostForCell(self, p.Location);
|
var thisCost = Mobile.MovementCostForCell(mobileInfo, world, p.Location);
|
||||||
|
|
||||||
if (thisCost == float.PositiveInfinity)
|
if (thisCost == float.PositiveInfinity)
|
||||||
return p.Location;
|
return p.Location;
|
||||||
@@ -99,12 +102,12 @@ namespace OpenRA
|
|||||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var costHere = mobile.MovementCostForCell(self, newHere);
|
var costHere = Mobile.MovementCostForCell(mobileInfo, world, newHere);
|
||||||
|
|
||||||
if (costHere == float.PositiveInfinity)
|
if (costHere == float.PositiveInfinity)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!mobile.CanEnterCell(newHere, ignoreBuilding, checkForBlocked))
|
if (!Mobile.CanEnterCell(mobileInfo, world, uim, bim, newHere, ignoreBuilding, checkForBlocked))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (customBlock != null && customBlock(newHere))
|
if (customBlock != null && customBlock(newHere))
|
||||||
@@ -160,33 +163,33 @@ namespace OpenRA
|
|||||||
queue.Add( new PathDistance( heuristic( location ), location ) );
|
queue.Add( new PathDistance( heuristic( location ), location ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathSearch Search( Actor self, bool checkForBlocked )
|
public static PathSearch Search( World world, MobileInfo mi, bool checkForBlocked )
|
||||||
{
|
{
|
||||||
var search = new PathSearch(self) {
|
var search = new PathSearch(world, mi) {
|
||||||
checkForBlocked = checkForBlocked };
|
checkForBlocked = checkForBlocked };
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathSearch FromPoint( Actor self, int2 from, int2 target, bool checkForBlocked )
|
public static PathSearch FromPoint( World world, MobileInfo mi, int2 from, int2 target, bool checkForBlocked )
|
||||||
{
|
{
|
||||||
var search = new PathSearch(self) {
|
var search = new PathSearch(world, mi) {
|
||||||
heuristic = DefaultEstimator( target ),
|
heuristic = DefaultEstimator( target ),
|
||||||
checkForBlocked = checkForBlocked };
|
checkForBlocked = checkForBlocked };
|
||||||
|
|
||||||
search.AddInitialCell( self.World, from );
|
search.AddInitialCell( world, from );
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathSearch FromPoints(Actor self, IEnumerable<int2> froms, int2 target, bool checkForBlocked)
|
public static PathSearch FromPoints(World world, MobileInfo mi, IEnumerable<int2> froms, int2 target, bool checkForBlocked)
|
||||||
{
|
{
|
||||||
var search = new PathSearch(self)
|
var search = new PathSearch(world, mi)
|
||||||
{
|
{
|
||||||
heuristic = DefaultEstimator(target),
|
heuristic = DefaultEstimator(target),
|
||||||
checkForBlocked = checkForBlocked
|
checkForBlocked = checkForBlocked
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var sl in froms)
|
foreach (var sl in froms)
|
||||||
search.AddInitialCell(self.World, sl);
|
search.AddInitialCell(world, sl);
|
||||||
|
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
{
|
{
|
||||||
this.getPath = (self,mobile) =>
|
this.getPath = (self,mobile) =>
|
||||||
self.World.PathFinder.FindPath(
|
self.World.PathFinder.FindPath(
|
||||||
PathSearch.FromPoint( self, mobile.toCell, destination, false )
|
PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false )
|
||||||
.WithoutLaneBias());
|
.WithoutLaneBias());
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = 0;
|
this.nearEnough = 0;
|
||||||
@@ -55,8 +55,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
public Move( int2 destination, int nearEnough )
|
public Move( int2 destination, int nearEnough )
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath(
|
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( mobile.toCell, destination, self );
|
||||||
mobile.toCell, destination, self );
|
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = nearEnough;
|
this.nearEnough = nearEnough;
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ namespace OpenRA.Traits.Activities
|
|||||||
{
|
{
|
||||||
this.getPath = (self,mobile) =>
|
this.getPath = (self,mobile) =>
|
||||||
self.World.PathFinder.FindPath(
|
self.World.PathFinder.FindPath(
|
||||||
PathSearch.FromPoint( self, mobile.toCell, destination, false )
|
PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false )
|
||||||
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( mobile.toCell, 4, self ))
|
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( mobile.toCell, 4, self ))
|
||||||
.WithIgnoredBuilding( ignoreBuilding ));
|
.WithIgnoredBuilding( ignoreBuilding ));
|
||||||
|
|
||||||
|
|||||||
@@ -207,19 +207,25 @@ namespace OpenRA.Traits
|
|||||||
return CanEnterCell( p, null, true);
|
return CanEnterCell( p, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool CanEnterCell( World world, MobileInfo mi, int2 cell, Actor ignoreActor, bool checkTransientActors )
|
||||||
|
{
|
||||||
|
var bim = world.WorldActor.Trait<BuildingInfluence>();
|
||||||
|
var uim = world.WorldActor.Trait<UnitInfluence>();
|
||||||
|
return Mobile.CanEnterCell( mi, world, uim, bim, cell, ignoreActor, checkTransientActors );
|
||||||
|
}
|
||||||
|
|
||||||
public bool CanEnterCell( int2 cell, Actor ignoreActor, bool checkTransientActors )
|
public bool CanEnterCell( int2 cell, Actor ignoreActor, bool checkTransientActors )
|
||||||
{
|
{
|
||||||
return CanEnterCell( Info, self.World, cell, ignoreActor, checkTransientActors );
|
var bim = self.World.WorldActor.Trait<BuildingInfluence>();
|
||||||
|
var uim = self.World.WorldActor.Trait<UnitInfluence>();
|
||||||
|
return CanEnterCell( Info, self.World, uim, bim, cell, ignoreActor, checkTransientActors );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CanEnterCell( MobileInfo mobileInfo, World world, int2 cell, Actor ignoreActor, bool checkTransientActors )
|
public static bool CanEnterCell( MobileInfo mobileInfo, World world, UnitInfluence uim, BuildingInfluence bim, int2 cell, Actor ignoreActor, bool checkTransientActors )
|
||||||
{
|
{
|
||||||
if (MovementCostForCell(mobileInfo, world, cell) == float.PositiveInfinity)
|
if (MovementCostForCell(mobileInfo, world, cell) == float.PositiveInfinity)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var bim = world.WorldActor.Trait<BuildingInfluence>();
|
|
||||||
var uim = world.WorldActor.Trait<UnitInfluence>();
|
|
||||||
|
|
||||||
// Check for buildings
|
// Check for buildings
|
||||||
var building = bim.GetBuildingBlocking(cell);
|
var building = bim.GetBuildingBlocking(cell);
|
||||||
if (building != null && building != ignoreActor)
|
if (building != null && building != ignoreActor)
|
||||||
|
|||||||
@@ -95,11 +95,13 @@ namespace OpenRA.Traits
|
|||||||
// required for 3-arg CanEnterCell
|
// required for 3-arg CanEnterCell
|
||||||
//var mobile = newUnit.Trait<Mobile>();
|
//var mobile = newUnit.Trait<Mobile>();
|
||||||
var mobileInfo = producee.Traits.Get<MobileInfo>();
|
var mobileInfo = producee.Traits.Get<MobileInfo>();
|
||||||
|
var bim = self.World.WorldActor.Trait<BuildingInfluence>();
|
||||||
|
var uim = self.World.WorldActor.Trait<UnitInfluence>();
|
||||||
|
|
||||||
// Pick a spawn/exit point pair
|
// Pick a spawn/exit point pair
|
||||||
// Todo: Reorder in a synced random way
|
// Todo: Reorder in a synced random way
|
||||||
foreach (var s in self.Info.Traits.WithInterface<ExitInfo>())
|
foreach (var s in self.Info.Traits.WithInterface<ExitInfo>())
|
||||||
if( Mobile.CanEnterCell( mobileInfo, self.World, self.Location + s.ExitCell,self,true ) )
|
if( Mobile.CanEnterCell( mobileInfo, self.World, uim, bim, self.Location + s.ExitCell,self,true ) )
|
||||||
{
|
{
|
||||||
DoProduction(self, producee, s);
|
DoProduction(self, producee, s);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
{
|
{
|
||||||
var res = self.World.WorldActor.Trait<ResourceLayer>();
|
var res = self.World.WorldActor.Trait<ResourceLayer>();
|
||||||
var harv = self.Info.Traits.Get<HarvesterInfo>();
|
var harv = self.Info.Traits.Get<HarvesterInfo>();
|
||||||
|
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||||
self.QueueActivity(new Move(
|
self.QueueActivity(new Move(
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
return self.World.PathFinder.FindPath(PathSearch.Search(self, true)
|
return self.World.PathFinder.FindPath(PathSearch.Search(self.World, mobileInfo, true)
|
||||||
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
|
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
|
||||||
.FromPoint(self.Location));
|
.FromPoint(self.Location));
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ namespace OpenRA.Mods.RA
|
|||||||
var refs = self.World.Queries.OwnedBy[self.Owner]
|
var refs = self.World.Queries.OwnedBy[self.Owner]
|
||||||
.Where(x => x != ignore && x.HasTrait<IAcceptOre>())
|
.Where(x => x != ignore && x.HasTrait<IAcceptOre>())
|
||||||
.ToList();
|
.ToList();
|
||||||
|
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||||
var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self,
|
var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self.World, mi,
|
||||||
refs.Select(r => r.Location + r.Trait<IAcceptOre>().DeliverOffset),
|
refs.Select(r => r.Location + r.Trait<IAcceptOre>().DeliverOffset),
|
||||||
self.Location,
|
self.Location,
|
||||||
false));
|
false));
|
||||||
|
|||||||
Reference in New Issue
Block a user