Make knowledge of height discontinuities live in Locomotor not PathGraph.

This commit is contained in:
RoosterDragon
2021-11-14 09:40:35 +00:00
committed by abcdefg30
parent 8c627aa185
commit f0e24f6d21
2 changed files with 22 additions and 21 deletions

View File

@@ -174,7 +174,7 @@ namespace OpenRA.Mods.Common.Pathfinder
{
var dir = directions[i];
var neighbor = position + dir;
var pathCost = GetPathCostToNode(neighbor, dir);
var pathCost = GetPathCostToNode(position, neighbor, dir);
// PERF: Skip closed cells already, 15% of all cells
if (pathCost != PathCostForInvalidPath && info[neighbor].Status != CellStatus.Closed)
@@ -192,7 +192,7 @@ namespace OpenRA.Mods.Common.Pathfinder
var layerPosition = new CPos(position.X, position.Y, cml.Index);
var entryCost = cml.EntryMovementCost(locomotor.Info, layerPosition);
if (entryCost != MovementCostForUnreachableCell &&
CanEnterNode(layerPosition) &&
CanEnterNode(position, layerPosition) &&
this[layerPosition].Status != CellStatus.Closed)
validNeighbors.Add(new GraphConnection(layerPosition, entryCost));
}
@@ -202,7 +202,7 @@ namespace OpenRA.Mods.Common.Pathfinder
var layerPosition = new CPos(position.X, position.Y, 0);
var exitCost = cmls[layer].ExitMovementCost(locomotor.Info, layerPosition);
if (exitCost != MovementCostForUnreachableCell &&
CanEnterNode(layerPosition) &&
CanEnterNode(position, layerPosition) &&
this[layerPosition].Status != CellStatus.Closed)
validNeighbors.Add(new GraphConnection(layerPosition, exitCost));
}
@@ -210,16 +210,16 @@ namespace OpenRA.Mods.Common.Pathfinder
return validNeighbors;
}
bool CanEnterNode(CPos destNode)
bool CanEnterNode(CPos srcNode, CPos destNode)
{
return
locomotor.MovementCostToEnterCell(Actor, destNode, checkConditions, IgnoreActor)
locomotor.MovementCostToEnterCell(Actor, srcNode, destNode, checkConditions, IgnoreActor)
!= MovementCostForUnreachableCell;
}
int GetPathCostToNode(CPos destNode, CVec direction)
int GetPathCostToNode(CPos srcNode, CPos destNode, CVec direction)
{
var movementCost = locomotor.MovementCostToEnterCell(Actor, destNode, checkConditions, IgnoreActor);
var movementCost = locomotor.MovementCostToEnterCell(Actor, srcNode, destNode, checkConditions, IgnoreActor);
if (movementCost != MovementCostForUnreachableCell && !(CustomBlock != null && CustomBlock(destNode)))
return CalculateCellPathCost(destNode, direction, movementCost);
@@ -242,15 +242,6 @@ namespace OpenRA.Mods.Common.Pathfinder
cellCost += customCost;
}
// Prevent units from jumping over height discontinuities
if (checkTerrainHeight && neighborCPos.Layer == 0)
{
var heightLayer = World.Map.Height;
var from = neighborCPos - direction;
if (Math.Abs(heightLayer[neighborCPos] - heightLayer[from]) > 1)
return PathCostForInvalidPath;
}
// Directional bonuses for smoother flow!
if (LaneBias != 0)
{