Use Tuple syntax

This commit is contained in:
teinarss
2020-08-02 13:41:03 +02:00
committed by Paul Chote
parent 8a74f6ea18
commit 19b02875c7
90 changed files with 738 additions and 826 deletions

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Pathfinder
/// <summary>
/// Stores the analyzed nodes by the expand function
/// </summary>
IEnumerable<Pair<CPos, int>> Considered { get; }
IEnumerable<(CPos Cell, int Cost)> Considered { get; }
Player Owner { get; }
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Pathfinder
protected IPriorityQueue<GraphConnection> OpenQueue { get; private set; }
public abstract IEnumerable<Pair<CPos, int>> Considered { get; }
public abstract IEnumerable<(CPos Cell, int Cost)> Considered { get; }
public Player Owner { get { return Graph.Actor.Owner; } }
public int MaxCost { get; protected set; }

View File

@@ -92,8 +92,8 @@ namespace OpenRA.Mods.Common.Pathfinder
readonly bool checkTerrainHeight;
CellLayer<CellInfo> groundInfo;
readonly Dictionary<byte, Pair<ICustomMovementLayer, CellLayer<CellInfo>>> customLayerInfo =
new Dictionary<byte, Pair<ICustomMovementLayer, CellLayer<CellInfo>>>();
readonly Dictionary<byte, (ICustomMovementLayer Layer, CellLayer<CellInfo> Info)> customLayerInfo =
new Dictionary<byte, (ICustomMovementLayer, CellLayer<CellInfo>)>();
public PathGraph(CellInfoLayerPool layerPool, Locomotor locomotor, Actor actor, World world, BlockedByActor check)
{
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Pathfinder
.Where(cml => cml.EnabledForActor(actor.Info, locomotorInfo));
foreach (var cml in layers)
customLayerInfo[cml.Index] = Pair.New(cml, pooledLayer.GetLayer());
customLayerInfo[cml.Index] = (cml, pooledLayer.GetLayer());
World = world;
worldMovementInfo = locomotorInfo.GetWorldMovementInfo(world);
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Pathfinder
public List<GraphConnection> GetConnections(CPos position)
{
var info = position.Layer == 0 ? groundInfo : customLayerInfo[position.Layer].Second;
var info = position.Layer == 0 ? groundInfo : customLayerInfo[position.Layer].Info;
var previousPos = info[position].PreviousPos;
var dx = position.X - previousPos.X;
@@ -156,8 +156,8 @@ namespace OpenRA.Mods.Common.Pathfinder
{
foreach (var cli in customLayerInfo.Values)
{
var layerPosition = new CPos(position.X, position.Y, cli.First.Index);
var entryCost = cli.First.EntryMovementCost(Actor.Info, locomotor.Info, layerPosition);
var layerPosition = new CPos(position.X, position.Y, cli.Layer.Index);
var entryCost = cli.Layer.EntryMovementCost(Actor.Info, locomotor.Info, layerPosition);
if (entryCost != CostForInvalidCell)
validNeighbors.Add(new GraphConnection(layerPosition, entryCost));
}
@@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.Pathfinder
else
{
var layerPosition = new CPos(position.X, position.Y, 0);
var exitCost = customLayerInfo[position.Layer].First.ExitMovementCost(Actor.Info, locomotor.Info, layerPosition);
var exitCost = customLayerInfo[position.Layer].Layer.ExitMovementCost(Actor.Info, locomotor.Info, layerPosition);
if (exitCost != CostForInvalidCell)
validNeighbors.Add(new GraphConnection(layerPosition, exitCost));
}
@@ -224,8 +224,8 @@ namespace OpenRA.Mods.Common.Pathfinder
public CellInfo this[CPos pos]
{
get { return (pos.Layer == 0 ? groundInfo : customLayerInfo[pos.Layer].Second)[pos]; }
set { (pos.Layer == 0 ? groundInfo : customLayerInfo[pos.Layer].Second)[pos] = value; }
get { return (pos.Layer == 0 ? groundInfo : customLayerInfo[pos.Layer].Info)[pos]; }
set { (pos.Layer == 0 ? groundInfo : customLayerInfo[pos.Layer].Info)[pos] = value; }
}
public void Dispose()

View File

@@ -30,19 +30,19 @@ namespace OpenRA.Mods.Common.Pathfinder
return LayerPoolTable.GetValue(world, CreateLayerPool);
}
public override IEnumerable<Pair<CPos, int>> Considered
public override IEnumerable<(CPos, int)> Considered
{
get { return considered; }
}
LinkedList<Pair<CPos, int>> considered;
LinkedList<(CPos, int)> considered;
#region Constructors
private PathSearch(IGraph<CellInfo> graph)
: base(graph)
{
considered = new LinkedList<Pair<CPos, int>>();
considered = new LinkedList<(CPos, int)>();
}
public static IPathSearch Search(World world, Locomotor locomotor, Actor self, BlockedByActor check, Func<CPos, bool> goalCondition)
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Pathfinder
var connection = new GraphConnection(location, cost);
OpenQueue.Add(connection);
StartPoints.Add(connection);
considered.AddLast(new Pair<CPos, int>(location, 0));
considered.AddLast((location, 0));
}
#endregion
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Pathfinder
if (gCost > MaxCost)
MaxCost = gCost;
considered.AddLast(new Pair<CPos, int>(neighborCPos, gCost));
considered.AddLast((neighborCPos, gCost));
}
}