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:
@@ -30,6 +30,11 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly struct CellInfo
|
public readonly struct CellInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The status of this node. Accessing other fields is only valid when the status is not <see cref="CellStatus.Unvisited"/>.
|
||||||
|
/// </summary>
|
||||||
|
public readonly CellStatus Status;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The cost to move from the start up to this node.
|
/// The cost to move from the start up to this node.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,19 +43,14 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The estimation of how far this node is from our target.
|
/// The estimation of how far this node is from our target.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly int EstimatedTotal;
|
public readonly int EstimatedTotalCost;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The previous node of this one that follows the shortest path.
|
/// The previous node of this one that follows the shortest path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly CPos PreviousPos;
|
public readonly CPos PreviousNode;
|
||||||
|
|
||||||
/// <summary>
|
public CellInfo(CellStatus status, int costSoFar, int estimatedTotalCost, CPos previousNode)
|
||||||
/// The status of this node. Accessing other fields is only valid when the status is not <see cref="CellStatus.Unvisited"/>.
|
|
||||||
/// </summary>
|
|
||||||
public readonly CellStatus Status;
|
|
||||||
|
|
||||||
public CellInfo(int costSoFar, int estimatedTotal, CPos previousPos, CellStatus status)
|
|
||||||
{
|
{
|
||||||
if (status == CellStatus.Unvisited)
|
if (status == CellStatus.Unvisited)
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
@@ -59,8 +59,8 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
|
|
||||||
Status = status;
|
Status = status;
|
||||||
CostSoFar = costSoFar;
|
CostSoFar = costSoFar;
|
||||||
EstimatedTotal = estimatedTotal;
|
EstimatedTotalCost = estimatedTotalCost;
|
||||||
PreviousPos = previousPos;
|
PreviousNode = previousNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
|
|
||||||
return
|
return
|
||||||
$"{Status} {nameof(CostSoFar)}={CostSoFar} " +
|
$"{Status} {nameof(CostSoFar)}={CostSoFar} " +
|
||||||
$"{nameof(EstimatedTotal)}={EstimatedTotal} {nameof(PreviousPos)}={PreviousPos}";
|
$"{nameof(EstimatedTotalCost)}={EstimatedTotalCost} {nameof(PreviousNode)}={PreviousNode}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,15 +157,15 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
{
|
{
|
||||||
var layer = position.Layer;
|
var layer = position.Layer;
|
||||||
var info = cellInfoForLayer[layer];
|
var info = cellInfoForLayer[layer];
|
||||||
var previousPos = info[position].PreviousPos;
|
var previousNode = info[position].PreviousNode;
|
||||||
|
|
||||||
var dx = position.X - previousPos.X;
|
var dx = position.X - previousNode.X;
|
||||||
var dy = position.Y - previousPos.Y;
|
var dy = position.Y - previousNode.Y;
|
||||||
var index = dy * 3 + dx + 4;
|
var index = dy * 3 + dx + 4;
|
||||||
|
|
||||||
var heightLayer = World.Map.Height;
|
var heightLayer = World.Map.Height;
|
||||||
var directions =
|
var directions =
|
||||||
(checkTerrainHeight && layer == 0 && previousPos.Layer == 0 && heightLayer[position] != heightLayer[previousPos]
|
(checkTerrainHeight && layer == 0 && previousNode.Layer == 0 && heightLayer[position] != heightLayer[previousNode]
|
||||||
? DirectedNeighborsConservative
|
? DirectedNeighborsConservative
|
||||||
: DirectedNeighbors)[index];
|
: DirectedNeighbors)[index];
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
search.isGoal = loc =>
|
search.isGoal = loc =>
|
||||||
{
|
{
|
||||||
var locInfo = search.Graph[loc];
|
var locInfo = search.Graph[loc];
|
||||||
return locInfo.EstimatedTotal - locInfo.CostSoFar == 0;
|
return locInfo.EstimatedTotalCost - locInfo.CostSoFar == 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var sl in froms)
|
foreach (var sl in froms)
|
||||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
protected override void AddInitialCell(CPos location)
|
protected override void AddInitialCell(CPos location)
|
||||||
{
|
{
|
||||||
var cost = heuristic(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);
|
var connection = new GraphConnection(location, cost);
|
||||||
OpenQueue.Add(connection);
|
OpenQueue.Add(connection);
|
||||||
StartPoints.Add(connection);
|
StartPoints.Add(connection);
|
||||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
var currentMinNode = OpenQueue.Pop().Destination;
|
var currentMinNode = OpenQueue.Pop().Destination;
|
||||||
|
|
||||||
var currentCell = Graph[currentMinNode];
|
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)
|
if (Graph.CustomCost != null && Graph.CustomCost(currentMinNode) == PathGraph.PathCostForInvalidPath)
|
||||||
return currentMinNode;
|
return currentMinNode;
|
||||||
@@ -128,12 +128,12 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
// estimated total and the cost so far
|
// estimated total and the cost so far
|
||||||
int hCost;
|
int hCost;
|
||||||
if (neighborCell.Status == CellStatus.Open)
|
if (neighborCell.Status == CellStatus.Open)
|
||||||
hCost = neighborCell.EstimatedTotal - neighborCell.CostSoFar;
|
hCost = neighborCell.EstimatedTotalCost - neighborCell.CostSoFar;
|
||||||
else
|
else
|
||||||
hCost = heuristic(neighborCPos);
|
hCost = heuristic(neighborCPos);
|
||||||
|
|
||||||
var estimatedCost = gCost + hCost;
|
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)
|
if (neighborCell.Status != CellStatus.Open)
|
||||||
OpenQueue.Add(new GraphConnection(neighborCPos, estimatedCost));
|
OpenQueue.Add(new GraphConnection(neighborCPos, estimatedCost));
|
||||||
|
|||||||
@@ -199,10 +199,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var ret = new List<CPos>();
|
var ret = new List<CPos>();
|
||||||
var currentNode = destination;
|
var currentNode = destination;
|
||||||
|
|
||||||
while (cellInfo[currentNode].PreviousPos != currentNode)
|
while (cellInfo[currentNode].PreviousNode != currentNode)
|
||||||
{
|
{
|
||||||
ret.Add(currentNode);
|
ret.Add(currentNode);
|
||||||
currentNode = cellInfo[currentNode].PreviousPos;
|
currentNode = cellInfo[currentNode].PreviousNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Add(currentNode);
|
ret.Add(currentNode);
|
||||||
@@ -217,10 +217,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var ret = new List<CPos>();
|
var ret = new List<CPos>();
|
||||||
|
|
||||||
var q = confluenceNode;
|
var q = confluenceNode;
|
||||||
while (ca[q].PreviousPos != q)
|
while (ca[q].PreviousNode != q)
|
||||||
{
|
{
|
||||||
ret.Add(q);
|
ret.Add(q);
|
||||||
q = ca[q].PreviousPos;
|
q = ca[q].PreviousNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Add(q);
|
ret.Add(q);
|
||||||
@@ -228,9 +228,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
ret.Reverse();
|
ret.Reverse();
|
||||||
|
|
||||||
q = confluenceNode;
|
q = confluenceNode;
|
||||||
while (cb[q].PreviousPos != q)
|
while (cb[q].PreviousNode != q)
|
||||||
{
|
{
|
||||||
q = cb[q].PreviousPos;
|
q = cb[q].PreviousNode;
|
||||||
ret.Add(q);
|
ret.Add(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user