Minor pathfinder changes
This commit is contained in:
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
if (string.IsNullOrEmpty(id))
|
if (string.IsNullOrEmpty(id))
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
builder.Append(this.Graph.Actor.ActorID);
|
builder.Append(Graph.Actor.ActorID);
|
||||||
while (!startPoints.Empty)
|
while (!startPoints.Empty)
|
||||||
{
|
{
|
||||||
var startpoint = startPoints.Pop();
|
var startpoint = startPoints.Pop();
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
{
|
{
|
||||||
defaultCellInfoLayer =
|
defaultCellInfoLayer =
|
||||||
CellLayer<CellInfo>.CreateInstance(
|
CellLayer<CellInfo>.CreateInstance(
|
||||||
mpos => new CellInfo(int.MaxValue, int.MaxValue, mpos.ToCPos(map as Map), CellStatus.Unvisited),
|
mpos => new CellInfo(int.MaxValue, int.MaxValue, mpos.ToCPos(map), CellStatus.Unvisited),
|
||||||
new Size(map.MapSize.X, map.MapSize.Y),
|
new Size(map.MapSize.X, map.MapSize.Y),
|
||||||
map.TileShape);
|
map.TileShape);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,5 +25,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
/// a unit took to move one cell diagonally)
|
/// a unit took to move one cell diagonally)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const int DiagonalCellCost = 177;
|
public const int DiagonalCellCost = 177;
|
||||||
|
|
||||||
|
public const int InvalidNode = int.MaxValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all the Connections for a given node in the graph
|
/// Gets all the Connections for a given node in the graph
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ICollection<GraphConnection> GetConnections(CPos position);
|
IEnumerable<GraphConnection> GetConnections(CPos position);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves an object given a node in the graph
|
/// Retrieves an object given a node in the graph
|
||||||
@@ -73,8 +73,6 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
readonly MobileInfo mobileInfo;
|
readonly MobileInfo mobileInfo;
|
||||||
CellLayer<CellInfo> cellInfo;
|
CellLayer<CellInfo> cellInfo;
|
||||||
|
|
||||||
public const int InvalidNode = int.MaxValue;
|
|
||||||
|
|
||||||
public PathGraph(CellLayer<CellInfo> cellInfo, MobileInfo mobileInfo, Actor actor, World world, bool checkForBlocked)
|
public PathGraph(CellLayer<CellInfo> cellInfo, MobileInfo mobileInfo, Actor actor, World world, bool checkForBlocked)
|
||||||
{
|
{
|
||||||
this.cellInfo = cellInfo;
|
this.cellInfo = cellInfo;
|
||||||
@@ -102,7 +100,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
new[] { new CVec(1, -1), new CVec(1, 0), new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1) },
|
new[] { new CVec(1, -1), new CVec(1, 0), new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1) },
|
||||||
};
|
};
|
||||||
|
|
||||||
public ICollection<GraphConnection> GetConnections(CPos position)
|
public IEnumerable<GraphConnection> GetConnections(CPos position)
|
||||||
{
|
{
|
||||||
var previousPos = cellInfo[position].PreviousPos;
|
var previousPos = cellInfo[position].PreviousPos;
|
||||||
|
|
||||||
@@ -116,7 +114,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
{
|
{
|
||||||
var neighbor = position + directions[i];
|
var neighbor = position + directions[i];
|
||||||
var movementCost = GetCostToNode(neighbor, directions[i]);
|
var movementCost = GetCostToNode(neighbor, directions[i]);
|
||||||
if (movementCost != InvalidNode)
|
if (movementCost != Constants.InvalidNode)
|
||||||
validNeighbors.AddLast(new GraphConnection(position, neighbor, movementCost));
|
validNeighbors.AddLast(new GraphConnection(position, neighbor, movementCost));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,17 +125,17 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
{
|
{
|
||||||
int movementCost;
|
int movementCost;
|
||||||
if (mobileInfo.CanEnterCell(
|
if (mobileInfo.CanEnterCell(
|
||||||
World as World,
|
World,
|
||||||
Actor as Actor,
|
Actor,
|
||||||
destNode,
|
destNode,
|
||||||
out movementCost,
|
out movementCost,
|
||||||
IgnoredActor as Actor,
|
IgnoredActor,
|
||||||
checkConditions) && !(CustomBlock != null && CustomBlock(destNode)))
|
checkConditions) && !(CustomBlock != null && CustomBlock(destNode)))
|
||||||
{
|
{
|
||||||
return CalculateCellCost(destNode, direction, movementCost);
|
return CalculateCellCost(destNode, direction, movementCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
return InvalidNode;
|
return Constants.InvalidNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CalculateCellCost(CPos neighborCPos, CVec direction, int movementCost)
|
int CalculateCellCost(CPos neighborCPos, CVec direction, int movementCost)
|
||||||
@@ -148,7 +146,13 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
cellCost = (cellCost * 34) / 24;
|
cellCost = (cellCost * 34) / 24;
|
||||||
|
|
||||||
if (CustomCost != null)
|
if (CustomCost != null)
|
||||||
cellCost += CustomCost(neighborCPos);
|
{
|
||||||
|
var customCost = CustomCost(neighborCPos);
|
||||||
|
if (customCost == Constants.InvalidNode)
|
||||||
|
return Constants.InvalidNode;
|
||||||
|
|
||||||
|
cellCost += customCost;
|
||||||
|
}
|
||||||
|
|
||||||
// directional bonuses for smoother flow!
|
// directional bonuses for smoother flow!
|
||||||
if (LaneBias != 0)
|
if (LaneBias != 0)
|
||||||
@@ -184,15 +188,8 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
|
|
||||||
public CellInfo this[CPos pos]
|
public CellInfo this[CPos pos]
|
||||||
{
|
{
|
||||||
get
|
get { return cellInfo[pos]; }
|
||||||
{
|
set { cellInfo[pos] = value; }
|
||||||
return cellInfo[pos];
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
cellInfo[pos] = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// This assumes that the SubCell does not change during the path traversal
|
// This assumes that the SubCell does not change during the path traversal
|
||||||
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Length / 1024 + 1)
|
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Length / 1024 + 1)
|
||||||
.Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= range.LengthSquared
|
.Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= range.LengthSquared
|
||||||
&& mi.CanEnterCell(self.World as World, self as Actor, t));
|
&& mi.CanEnterCell(self.World, self, t));
|
||||||
|
|
||||||
// See if there is any cell within range that does not involve a cross-domain request
|
// See if there is any cell within range that does not involve a cross-domain request
|
||||||
// Really, we only need to check the circle perimeter, but it's not clear that would be a performance win
|
// Really, we only need to check the circle perimeter, but it's not clear that would be a performance win
|
||||||
|
|||||||
Reference in New Issue
Block a user