Using Locomotor instead of Info for pathfinding

This commit is contained in:
teinarss
2019-07-07 19:44:39 +02:00
committed by reaperrr
parent c00b13a18e
commit 2ddf9fa826
9 changed files with 41 additions and 29 deletions

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Pathfinder
public Actor IgnoreActor { get; set; }
readonly CellConditions checkConditions;
readonly LocomotorInfo locomotorInfo;
readonly Locomotor locomotor;
readonly LocomotorInfo.WorldMovementInfo worldMovementInfo;
readonly CellInfoLayerPool.PooledCellInfoLayer pooledLayer;
readonly bool checkTerrainHeight;
@@ -92,11 +92,12 @@ namespace OpenRA.Mods.Common.Pathfinder
readonly Dictionary<byte, Pair<ICustomMovementLayer, CellLayer<CellInfo>>> customLayerInfo =
new Dictionary<byte, Pair<ICustomMovementLayer, CellLayer<CellInfo>>>();
public PathGraph(CellInfoLayerPool layerPool, LocomotorInfo li, Actor actor, World world, bool checkForBlocked)
public PathGraph(CellInfoLayerPool layerPool, Locomotor locomotor, Actor actor, World world, bool checkForBlocked)
{
pooledLayer = layerPool.Get();
groundInfo = pooledLayer.GetLayer();
locomotorInfo = li;
var locomotorInfo = locomotor.Info;
this.locomotor = locomotor;
var layers = world.GetCustomMovementLayers().Values
.Where(cml => cml.EnabledForActor(actor.Info, locomotorInfo));
@@ -153,7 +154,7 @@ namespace OpenRA.Mods.Common.Pathfinder
foreach (var cli in customLayerInfo.Values)
{
var layerPosition = new CPos(position.X, position.Y, cli.First.Index);
var entryCost = cli.First.EntryMovementCost(Actor.Info, locomotorInfo, layerPosition);
var entryCost = cli.First.EntryMovementCost(Actor.Info, locomotor.Info, layerPosition);
if (entryCost != Constants.InvalidNode)
validNeighbors.Add(new GraphConnection(layerPosition, entryCost));
}
@@ -161,7 +162,7 @@ namespace OpenRA.Mods.Common.Pathfinder
else
{
var layerPosition = new CPos(position.X, position.Y, 0);
var exitCost = customLayerInfo[position.Layer].First.ExitMovementCost(Actor.Info, locomotorInfo, layerPosition);
var exitCost = customLayerInfo[position.Layer].First.ExitMovementCost(Actor.Info, locomotor.Info, layerPosition);
if (exitCost != Constants.InvalidNode)
validNeighbors.Add(new GraphConnection(layerPosition, exitCost));
}

View File

@@ -45,18 +45,18 @@ namespace OpenRA.Mods.Common.Pathfinder
considered = new LinkedList<Pair<CPos, int>>();
}
public static IPathSearch Search(World world, LocomotorInfo li, Actor self, bool checkForBlocked, Func<CPos, bool> goalCondition)
public static IPathSearch Search(World world, Locomotor locomotor, Actor self, bool checkForBlocked, Func<CPos, bool> goalCondition)
{
var graph = new PathGraph(LayerPoolForWorld(world), li, self, world, checkForBlocked);
var graph = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, checkForBlocked);
var search = new PathSearch(graph);
search.isGoal = goalCondition;
search.heuristic = loc => 0;
return search;
}
public static IPathSearch FromPoint(World world, LocomotorInfo li, Actor self, CPos from, CPos target, bool checkForBlocked)
public static IPathSearch FromPoint(World world, Locomotor locomotor, Actor self, CPos @from, CPos target, bool checkForBlocked)
{
var graph = new PathGraph(LayerPoolForWorld(world), li, self, world, checkForBlocked);
var graph = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, checkForBlocked);
var search = new PathSearch(graph)
{
heuristic = DefaultEstimator(target)
@@ -74,9 +74,9 @@ namespace OpenRA.Mods.Common.Pathfinder
return search;
}
public static IPathSearch FromPoints(World world, LocomotorInfo li, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
public static IPathSearch FromPoints(World world, Locomotor locomotor, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
{
var graph = new PathGraph(LayerPoolForWorld(world), li, self, world, checkForBlocked);
var graph = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, checkForBlocked);
var search = new PathSearch(graph)
{
heuristic = DefaultEstimator(target)