Use named pathfinding constants.
- Rename CostForInvalidCell to PathCostForInvalidPath - Add MovementCostForUnreachableCell - Update usages of int.MaxValue and short.Maxvalue to use named constants where relevant. - Update costs on ICustomMovementLayer to return short, for consistency with costs from Locomotor. - Rename some methods to distinguish between path/movement cost.
This commit is contained in:
@@ -80,14 +80,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return cellCenters[cell];
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
return ends.Contains(cell) ? 0 : PathGraph.CostForInvalidCell;
|
||||
return ends.Contains(cell) ? (short)0 : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
return ends.Contains(cell) ? 0 : PathGraph.CostForInvalidCell;
|
||||
return ends.Contains(cell) ? (short)0 : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
byte ICustomMovementLayer.GetTerrainIndex(CPos cell)
|
||||
|
||||
@@ -87,16 +87,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return map.Ramp[cell] == 0;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
var jli = (JumpjetLocomotorInfo)li;
|
||||
return ValidTransitionCell(cell, jli) ? jli.JumpjetTransitionCost : PathGraph.CostForInvalidCell;
|
||||
return ValidTransitionCell(cell, jli) ? jli.JumpjetTransitionCost : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
var jli = (JumpjetLocomotorInfo)li;
|
||||
return ValidTransitionCell(cell, jli) ? jli.JumpjetTransitionCost : PathGraph.CostForInvalidCell;
|
||||
return ValidTransitionCell(cell, jli) ? jli.JumpjetTransitionCost : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
byte ICustomMovementLayer.GetTerrainIndex(CPos cell)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class JumpjetLocomotorInfo : LocomotorInfo
|
||||
{
|
||||
[Desc("Pathfinding cost for taking off or landing.")]
|
||||
public readonly int JumpjetTransitionCost = 0;
|
||||
public readonly short JumpjetTransitionCost = 0;
|
||||
|
||||
[Desc("The terrain types that this actor can transition on. Leave empty to allow any.")]
|
||||
public readonly HashSet<string> JumpjetTransitionTerrainTypes = new HashSet<string>();
|
||||
|
||||
@@ -13,6 +13,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Pathfinder;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
@@ -109,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public TerrainInfo()
|
||||
{
|
||||
Cost = short.MaxValue;
|
||||
Cost = PathGraph.MovementCostForUnreachableCell;
|
||||
Speed = 0;
|
||||
}
|
||||
|
||||
@@ -168,13 +169,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!info.TerrainSpeeds.TryGetValue(terrainInfo.TerrainTypes[i].Type, out terrainInfos[i]))
|
||||
terrainInfos[i] = LocomotorInfo.TerrainInfo.Impassable;
|
||||
|
||||
MovementClass = (uint)terrainInfos.Select(ti => ti.Cost < short.MaxValue).ToBits();
|
||||
MovementClass = (uint)terrainInfos.Select(ti => ti.Cost != PathGraph.MovementCostForUnreachableCell).ToBits();
|
||||
}
|
||||
|
||||
public short MovementCostForCell(CPos cell)
|
||||
{
|
||||
if (!world.Map.Contains(cell))
|
||||
return short.MaxValue;
|
||||
return PathGraph.MovementCostForUnreachableCell;
|
||||
|
||||
return cell.Layer == 0 ? cellsCost[cell] : customLayerCellsCost[cell.Layer][cell];
|
||||
}
|
||||
@@ -190,13 +191,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public short MovementCostToEnterCell(Actor actor, CPos destNode, BlockedByActor check, Actor ignoreActor)
|
||||
{
|
||||
if (!world.Map.Contains(destNode))
|
||||
return short.MaxValue;
|
||||
return PathGraph.MovementCostForUnreachableCell;
|
||||
|
||||
var cellCost = destNode.Layer == 0 ? cellsCost[destNode] : customLayerCellsCost[destNode.Layer][destNode];
|
||||
|
||||
if (cellCost == short.MaxValue ||
|
||||
if (cellCost == PathGraph.MovementCostForUnreachableCell ||
|
||||
!CanMoveFreelyInto(actor, destNode, check, ignoreActor))
|
||||
return short.MaxValue;
|
||||
return PathGraph.MovementCostForUnreachableCell;
|
||||
|
||||
return cellCost;
|
||||
}
|
||||
@@ -276,7 +277,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public SubCell GetAvailableSubCell(Actor self, CPos cell, BlockedByActor check, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null)
|
||||
{
|
||||
if (MovementCostForCell(cell) == short.MaxValue)
|
||||
if (MovementCostForCell(cell) == PathGraph.MovementCostForUnreachableCell)
|
||||
return SubCell.Invalid;
|
||||
|
||||
if (check > BlockedByActor.None)
|
||||
@@ -381,7 +382,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var index = cml.GetTerrainIndex(cell);
|
||||
|
||||
var cost = short.MaxValue;
|
||||
var cost = PathGraph.MovementCostForUnreachableCell;
|
||||
|
||||
if (index != byte.MaxValue)
|
||||
cost = terrainInfos[index].Cost;
|
||||
@@ -416,7 +417,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
? world.Map.GetTerrainIndex(cell)
|
||||
: world.GetCustomMovementLayers()[cell.Layer].GetTerrainIndex(cell);
|
||||
|
||||
var cost = short.MaxValue;
|
||||
var cost = PathGraph.MovementCostForUnreachableCell;
|
||||
|
||||
if (index != byte.MaxValue)
|
||||
cost = terrainInfos[index].Cost;
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// make some progress on the first search
|
||||
var p = fromSrc.Expand();
|
||||
if (fromDest.Graph[p].Status == CellStatus.Closed &&
|
||||
fromDest.Graph[p].CostSoFar < int.MaxValue)
|
||||
fromDest.Graph[p].CostSoFar != PathGraph.PathCostForInvalidPath)
|
||||
{
|
||||
path = MakeBidiPath(fromSrc, fromDest, p);
|
||||
break;
|
||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// make some progress on the second search
|
||||
var q = fromDest.Expand();
|
||||
if (fromSrc.Graph[q].Status == CellStatus.Closed &&
|
||||
fromSrc.Graph[q].CostSoFar < int.MaxValue)
|
||||
fromSrc.Graph[q].CostSoFar != PathGraph.PathCostForInvalidPath)
|
||||
{
|
||||
path = MakeBidiPath(fromSrc, fromDest, q);
|
||||
break;
|
||||
|
||||
@@ -85,16 +85,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return map.Ramp[cell] == 0;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
var sli = (SubterraneanLocomotorInfo)li;
|
||||
return ValidTransitionCell(cell, sli) ? sli.SubterraneanTransitionCost : PathGraph.CostForInvalidCell;
|
||||
return ValidTransitionCell(cell, sli) ? sli.SubterraneanTransitionCost : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
var sli = (SubterraneanLocomotorInfo)li;
|
||||
return ValidTransitionCell(cell, sli) ? sli.SubterraneanTransitionCost : PathGraph.CostForInvalidCell;
|
||||
return ValidTransitionCell(cell, sli) ? sli.SubterraneanTransitionCost : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
byte ICustomMovementLayer.GetTerrainIndex(CPos cell)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class SubterraneanLocomotorInfo : LocomotorInfo
|
||||
{
|
||||
[Desc("Pathfinding cost for submerging or reemerging.")]
|
||||
public readonly int SubterraneanTransitionCost = 0;
|
||||
public readonly short SubterraneanTransitionCost = 0;
|
||||
|
||||
[Desc("The terrain types that this actor can transition on. Leave empty to allow any.")]
|
||||
public readonly HashSet<string> SubterraneanTransitionTerrainTypes = new HashSet<string>();
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Can this actor transition on slopes?")]
|
||||
public readonly bool SubterraneanTransitionOnRamps = false;
|
||||
|
||||
[Desc("Depth at which the subterranian condition is applied.")]
|
||||
[Desc("Depth at which the subterranean condition is applied.")]
|
||||
public readonly WDist SubterraneanTransitionDepth = new WDist(-1024);
|
||||
|
||||
public override bool DisableDomainPassabilityCheck => true;
|
||||
|
||||
@@ -79,14 +79,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return cellCenters[cell];
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.EntryMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
return portals.Contains(cell) ? 0 : PathGraph.CostForInvalidCell;
|
||||
return portals.Contains(cell) ? (short)0 : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
int ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
short ICustomMovementLayer.ExitMovementCost(LocomotorInfo li, CPos cell)
|
||||
{
|
||||
return portals.Contains(cell) ? 0 : PathGraph.CostForInvalidCell;
|
||||
return portals.Contains(cell) ? (short)0 : PathGraph.MovementCostForUnreachableCell;
|
||||
}
|
||||
|
||||
byte ICustomMovementLayer.GetTerrainIndex(CPos cell)
|
||||
|
||||
Reference in New Issue
Block a user