Adjust some naming and order of parameters in CellInfo

- Make Status the first field.
- Rename EstimatedTotal to EstimatedTotalCost to make it clearer it has the same unit as the CostSoFar field.
- Rename PreviousPos to PreviousNode as node terminology is a better match for usage.
This commit is contained in:
RoosterDragon
2021-11-18 15:30:26 +00:00
committed by abcdefg30
parent 98b25ddd5e
commit 290ed17c9d
4 changed files with 26 additions and 26 deletions

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Pathfinder
search.isGoal = loc =>
{
var locInfo = search.Graph[loc];
return locInfo.EstimatedTotal - locInfo.CostSoFar == 0;
return locInfo.EstimatedTotalCost - locInfo.CostSoFar == 0;
};
foreach (var sl in froms)
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Pathfinder
protected override void AddInitialCell(CPos location)
{
var cost = heuristic(location);
Graph[location] = new CellInfo(0, cost, location, CellStatus.Open);
Graph[location] = new CellInfo(CellStatus.Open, 0, cost, location);
var connection = new GraphConnection(location, cost);
OpenQueue.Add(connection);
StartPoints.Add(connection);
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Pathfinder
var currentMinNode = OpenQueue.Pop().Destination;
var currentCell = Graph[currentMinNode];
Graph[currentMinNode] = new CellInfo(currentCell.CostSoFar, currentCell.EstimatedTotal, currentCell.PreviousPos, CellStatus.Closed);
Graph[currentMinNode] = new CellInfo(CellStatus.Closed, currentCell.CostSoFar, currentCell.EstimatedTotalCost, currentCell.PreviousNode);
if (Graph.CustomCost != null && Graph.CustomCost(currentMinNode) == PathGraph.PathCostForInvalidPath)
return currentMinNode;
@@ -128,12 +128,12 @@ namespace OpenRA.Mods.Common.Pathfinder
// estimated total and the cost so far
int hCost;
if (neighborCell.Status == CellStatus.Open)
hCost = neighborCell.EstimatedTotal - neighborCell.CostSoFar;
hCost = neighborCell.EstimatedTotalCost - neighborCell.CostSoFar;
else
hCost = heuristic(neighborCPos);
var estimatedCost = gCost + hCost;
Graph[neighborCPos] = new CellInfo(gCost, estimatedCost, currentMinNode, CellStatus.Open);
Graph[neighborCPos] = new CellInfo(CellStatus.Open, gCost, estimatedCost, currentMinNode);
if (neighborCell.Status != CellStatus.Open)
OpenQueue.Add(new GraphConnection(neighborCPos, estimatedCost));