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

@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
{
// PERF: Reuse collection to avoid allocations.
footprint.UnionWith(self.OccupiesSpace.OccupiedCells()
.SelectMany(kv => Shroud.ProjectedCellsInRange(map, map.CenterOfCell(kv.First), minRange, maxRange, Info.MaxHeightDelta)));
.SelectMany(kv => Shroud.ProjectedCellsInRange(map, map.CenterOfCell(kv.Cell), minRange, maxRange, Info.MaxHeightDelta)));
var cells = footprint.ToArray();
footprint.Clear();
return cells;

View File

@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Traits
INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, INotifyBecomingIdle, ICreationActivity,
IActorPreviewInitModifier, IDeathActorInitModifier, IIssueDeployOrder, IIssueOrder, IResolveOrder, IOrderVoice
{
static readonly Pair<CPos, SubCell>[] NoCells = { };
static readonly (CPos, SubCell)[] NoCells = { };
readonly Actor self;
@@ -597,12 +597,12 @@ namespace OpenRA.Mods.Common.Traits
get { return !IsTraitDisabled && !IsTraitPaused ? Util.ApplyPercentageModifiers(Info.Speed, speedModifiers) : 0; }
}
public Pair<CPos, SubCell>[] OccupiedCells()
public (CPos Cell, SubCell SubCell)[] OccupiedCells()
{
if (!self.IsAtGroundLevel())
return landingCells.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
return landingCells.Select(c => (c, SubCell.FullCell)).ToArray();
return new[] { Pair.New(TopLeft, SubCell.FullCell) };
return new[] { (TopLeft, SubCell.FullCell) };
}
public WVec FlyStep(WAngle facing)

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
"Overrides `Color` if both set.")]
public readonly string Terrain = null;
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<Pair<MPos, Color>> destinationBuffer)
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer)
{
var tileSet = map.Rules.TileSet;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
var ios = ai.TraitInfo<IOccupySpaceInfo>();
var cells = ios.OccupiedCells(ai, s.Get<LocationInit>().Value);
foreach (var cell in cells)
destinationBuffer.Add(new Pair<MPos, Color>(cell.Key.ToMPos(map), color));
destinationBuffer.Add((cell.Key.ToMPos(map), color));
}
}

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
int currentBarrel;
int barrelCount;
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
List<(int Ticks, Action Func)> delayedActions = new List<(int, Action)>();
public WDist Recoil;
public int FireDelay { get; protected set; }
@@ -211,12 +211,12 @@ namespace OpenRA.Mods.Common.Traits
for (var i = 0; i < delayedActions.Count; i++)
{
var x = delayedActions[i];
if (--x.First <= 0)
x.Second();
if (--x.Ticks <= 0)
x.Func();
delayedActions[i] = x;
}
delayedActions.RemoveAll(a => a.First <= 0);
delayedActions.RemoveAll(a => a.Ticks <= 0);
}
void ITick.Tick(Actor self)
@@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Traits
protected void ScheduleDelayedAction(int t, Action a)
{
if (t > 0)
delayedActions.Add(Pair.New(t, a));
delayedActions.Add((t, a));
else
a();
}

View File

@@ -64,27 +64,27 @@ namespace OpenRA.Mods.Common.Traits
DemolishWeaponInfo = weapon;
}
public IEnumerable<Pair<ushort, int>> Templates
public IEnumerable<(ushort Template, int Health)> Templates
{
get
{
if (Template != 0)
yield return Pair.New(Template, 100);
yield return (Template, 100);
if (DamagedTemplate != 0)
yield return Pair.New(DamagedTemplate, 49);
yield return (DamagedTemplate, 49);
if (DestroyedTemplate != 0)
yield return Pair.New(DestroyedTemplate, 0);
yield return (DestroyedTemplate, 0);
if (DestroyedPlusNorthTemplate != 0)
yield return Pair.New(DestroyedPlusNorthTemplate, 0);
yield return (DestroyedPlusNorthTemplate, 0);
if (DestroyedPlusSouthTemplate != 0)
yield return Pair.New(DestroyedPlusSouthTemplate, 0);
yield return (DestroyedPlusSouthTemplate, 0);
if (DestroyedPlusBothTemplate != 0)
yield return Pair.New(DestroyedPlusBothTemplate, 0);
yield return (DestroyedPlusBothTemplate, 0);
}
}
}
@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits
var palette = wr.Palette(TileSet.TerrainPaletteInternalName);
renderables = new Dictionary<ushort, IRenderable[]>();
foreach (var t in info.Templates)
renderables.Add(t.First, TemplateRenderables(wr, palette, t.First));
renderables.Add(t.Template, TemplateRenderables(wr, palette, t.Template));
initialized = true;
}

View File

@@ -13,7 +13,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -268,8 +267,8 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self;
readonly BuildingInfluence influence;
Pair<CPos, SubCell>[] occupiedCells;
Pair<CPos, SubCell>[] targetableCells;
(CPos, SubCell)[] occupiedCells;
(CPos, SubCell)[] targetableCells;
CPos[] transitOnlyCells;
public CPos TopLeft { get { return topLeft; } }
@@ -283,21 +282,21 @@ namespace OpenRA.Mods.Common.Traits
influence = self.World.WorldActor.Trait<BuildingInfluence>();
occupiedCells = Info.OccupiedTiles(TopLeft)
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
.Select(c => (c, SubCell.FullCell)).ToArray();
targetableCells = Info.FootprintTiles(TopLeft, FootprintCellType.Occupied)
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
.Select(c => (c, SubCell.FullCell)).ToArray();
transitOnlyCells = Info.TransitOnlyTiles(TopLeft).ToArray();
CenterPosition = init.World.Map.CenterOfCell(topLeft) + Info.CenterOffset(init.World);
}
public Pair<CPos, SubCell>[] OccupiedCells() { return occupiedCells; }
public (CPos, SubCell)[] OccupiedCells() { return occupiedCells; }
public CPos[] TransitOnlyCells() { return transitOnlyCells; }
Pair<CPos, SubCell>[] ITargetableCells.TargetableCells() { return targetableCells; }
(CPos, SubCell)[] ITargetableCells.TargetableCells() { return targetableCells; }
void INotifyAddedToWorld.AddedToWorld(Actor self)
{

View File

@@ -54,13 +54,13 @@ namespace OpenRA.Mods.Common.Traits
world.IsCellBuildable(t, ai, bi, toIgnore));
}
public static IEnumerable<Pair<CPos, Actor>> GetLineBuildCells(World world, CPos cell, ActorInfo ai, BuildingInfo bi, Player owner)
public static IEnumerable<(CPos Cell, Actor Actor)> GetLineBuildCells(World world, CPos cell, ActorInfo ai, BuildingInfo bi, Player owner)
{
var lbi = ai.TraitInfo<LineBuildInfo>();
var topLeft = cell; // 1x1 assumption!
if (world.IsCellBuildable(topLeft, ai, bi))
yield return Pair.New<CPos, Actor>(topLeft, null);
yield return (topLeft, null);
// Start at place location, search outwards
// TODO: First make it work, then make it nice
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
// Place intermediate-line sections
if (dirs[d] > 0)
for (var i = 1; i < dirs[d]; i++)
yield return Pair.New(topLeft + i * vecs[d], connectors[d]);
yield return (topLeft + i * vecs[d], connectors[d]);
}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
class CapturableProgressBar : ConditionalTrait<CapturableProgressBarInfo>, ISelectionBar, ICaptureProgressWatcher
{
Dictionary<Actor, Pair<int, int>> progress = new Dictionary<Actor, Pair<int, int>>();
Dictionary<Actor, (int Current, int Total)> progress = new Dictionary<Actor, (int, int)>();
public CapturableProgressBar(Actor self, CapturableProgressBarInfo info)
: base(info) { }
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
if (total == 0)
progress.Remove(captor);
else
progress[captor] = Pair.New(current, total);
progress[captor] = (current, total);
}
float ISelectionBar.GetValue()
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsTraitDisabled || !progress.Any())
return 0f;
return progress.Values.Max(p => (float)p.First / p.Second);
return progress.Values.Max(p => (float)p.Current / p.Total);
}
Color ISelectionBar.GetColor() { return Info.Color; }

View File

@@ -155,20 +155,20 @@ namespace OpenRA.Mods.Common.Traits
if (crateActions.Any())
{
var shares = crateActions.Select(a => Pair.New(a, a.GetSelectionSharesOuter(crusher)));
var shares = crateActions.Select(a => (Action: a, Shares: a.GetSelectionSharesOuter(crusher)));
var totalShares = shares.Sum(a => a.Second);
var totalShares = shares.Sum(a => a.Shares);
var n = self.World.SharedRandom.Next(totalShares);
foreach (var s in shares)
{
if (n < s.Second)
if (n < s.Shares)
{
s.First.Activate(crusher);
s.Action.Activate(crusher);
return;
}
n -= s.Second;
n -= s.Shares;
}
}
}
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.Common.Traits
}
public CPos TopLeft { get { return Location; } }
public Pair<CPos, SubCell>[] OccupiedCells() { return new[] { Pair.New(Location, SubCell.FullCell) }; }
public (CPos, SubCell)[] OccupiedCells() { return new[] { (Location, SubCell.FullCell) }; }
public WPos CenterPosition { get; private set; }

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var kv in self.OccupiesSpace.OccupiedCells())
{
totalTiles++;
if (!Info.Terrain.Contains(self.World.Map.GetTerrainInfo(kv.First).Type))
if (!Info.Terrain.Contains(self.World.Map.GetTerrainInfo(kv.Cell).Type))
safeTiles++;
}

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
if (info.DrawPerimiterCellVectors)
{
var occupiedCells = self.OccupiesSpace.OccupiedCells().Select(p => p.First).ToArray();
var occupiedCells = self.OccupiesSpace.OccupiedCells().Select(p => p.Cell).ToArray();
perimeterCells = Util.ExpandFootprint(occupiedCells, true).Except(occupiedCells).ToArray();
foreach (var perimCell in perimeterCells)

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
readonly GainsExperienceInfo info;
readonly int initialExperience;
readonly List<Pair<int, string>> nextLevel = new List<Pair<int, string>>();
readonly List<(int RequiredExperience, string Condition)> nextLevel = new List<(int, string)>();
// Stored as a percentage of our value
[Sync]
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
var requiredExperience = info.ExperienceModifier < 0 ? (valued != null ? valued.Cost : 1) : info.ExperienceModifier;
foreach (var kv in info.Conditions)
nextLevel.Add(Pair.New(kv.Key * requiredExperience, kv.Value));
nextLevel.Add((kv.Key * requiredExperience, kv.Value));
if (initialExperience > 0)
GiveExperience(initialExperience, info.SuppressLevelupAnimation);
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var newLevel = Math.Min(Level + numLevels, MaxLevel);
GiveExperience(nextLevel[newLevel - 1].First - Experience, silent);
GiveExperience(nextLevel[newLevel - 1].RequiredExperience - Experience, silent);
}
public void GiveExperience(int amount, bool silent = false)
@@ -108,11 +108,11 @@ namespace OpenRA.Mods.Common.Traits
if (MaxLevel == 0)
return;
Experience = (Experience + amount).Clamp(0, nextLevel[MaxLevel - 1].First);
Experience = (Experience + amount).Clamp(0, nextLevel[MaxLevel - 1].RequiredExperience);
while (Level < MaxLevel && Experience >= nextLevel[Level].First)
while (Level < MaxLevel && Experience >= nextLevel[Level].RequiredExperience)
{
self.GrantCondition(nextLevel[Level].Second);
self.GrantCondition(nextLevel[Level].Condition);
Level++;

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
if (Info.UseTargetableCellsOffsets && targetableCells != null)
foreach (var c in targetableCells.TargetableCells())
yield return self.World.Map.CenterOfCell(c.First);
yield return self.World.Map.CenterOfCell(c.Cell);
foreach (var o in Info.TargetableOffsets)
{

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Traits
return true;
}
public Pair<CPos, SubCell>[] OccupiedCells() { return new[] { Pair.New(TopLeft, SubCell.FullCell) }; }
public (CPos, SubCell)[] OccupiedCells() { return new[] { (TopLeft, SubCell.FullCell) }; }
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; }
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; }
public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
[Sync]
readonly WPos position;
readonly Pair<CPos, SubCell>[] occupied;
readonly (CPos, SubCell)[] occupied;
public Immobile(ActorInitializer init, ImmobileInfo info)
{
@@ -47,14 +47,14 @@ namespace OpenRA.Mods.Common.Traits
position = init.World.Map.CenterOfCell(location);
if (info.OccupiesSpace)
occupied = new[] { Pair.New(TopLeft, SubCell.FullCell) };
occupied = new[] { (TopLeft, SubCell.FullCell) };
else
occupied = new Pair<CPos, SubCell>[0];
occupied = new (CPos, SubCell)[0];
}
public CPos TopLeft { get { return location; } }
public WPos CenterPosition { get { return position; } }
public Pair<CPos, SubCell>[] OccupiedCells() { return occupied; }
public (CPos, SubCell)[] OccupiedCells() { return occupied; }
void INotifyAddedToWorld.AddedToWorld(Actor self)
{

View File

@@ -229,16 +229,16 @@ namespace OpenRA.Mods.Common.Traits
public CPos TopLeft { get { return ToCell; } }
public Pair<CPos, SubCell>[] OccupiedCells()
public (CPos, SubCell)[] OccupiedCells()
{
if (FromCell == ToCell)
return new[] { Pair.New(FromCell, FromSubCell) };
return new[] { (FromCell, FromSubCell) };
// HACK: Should be fixed properly, see https://github.com/OpenRA/OpenRA/pull/17292 for an explanation
if (Info.LocomotorInfo.SharesCell)
return new[] { Pair.New(ToCell, ToSubCell) };
return new[] { (ToCell, ToSubCell) };
return new[] { Pair.New(FromCell, FromSubCell), Pair.New(ToCell, ToSubCell) };
return new[] { (FromCell, FromSubCell), (ToCell, ToSubCell) };
}
#endregion

View File

@@ -78,12 +78,12 @@ namespace OpenRA.Mods.Common.Traits
var myTeam = self.World.LobbyInfo.ClientWithIndex(self.Owner.ClientIndex).Team;
var teams = self.World.Players.Where(p => !p.NonCombatant && p.Playable)
.Select(p => new Pair<Player, PlayerStatistics>(p, p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.Second != null ? p.Second.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.First.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.Second != null ? gg.Second.Experience : 0));
.Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics != null ? gg.PlayerStatistics.Experience : 0));
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().First == self.Owner))
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().Player == self.Owner))
{
mo.MarkCompleted(self.Owner, objectiveID);
return;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
public class GrantConditionOnPrerequisiteManager : ITechTreeElement
{
readonly Actor self;
readonly Dictionary<string, List<Pair<Actor, GrantConditionOnPrerequisite>>> upgradables = new Dictionary<string, List<Pair<Actor, GrantConditionOnPrerequisite>>>();
readonly Dictionary<string, List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)>> upgradables = new Dictionary<string, List<(Actor, GrantConditionOnPrerequisite)>>();
readonly TechTree techTree;
public GrantConditionOnPrerequisiteManager(ActorInitializer init)
@@ -44,11 +44,11 @@ namespace OpenRA.Mods.Common.Traits
var key = MakeKey(prerequisites);
if (!upgradables.ContainsKey(key))
{
upgradables.Add(key, new List<Pair<Actor, GrantConditionOnPrerequisite>>());
upgradables.Add(key, new List<(Actor, GrantConditionOnPrerequisite)>());
techTree.Add(key, prerequisites, 0, this);
}
upgradables[key].Add(Pair.New(actor, u));
upgradables[key].Add((actor, u));
// Notify the current state
u.PrerequisitesUpdated(actor, techTree.HasPrerequisites(prerequisites));
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
var key = MakeKey(prerequisites);
var list = upgradables[key];
list.RemoveAll(x => x.First == actor && x.Second == u);
list.RemoveAll(x => x.Actor == actor && x.GrantConditionOnPrerequisite == u);
if (!list.Any())
{
upgradables.Remove(key);
@@ -69,22 +69,22 @@ namespace OpenRA.Mods.Common.Traits
public void PrerequisitesAvailable(string key)
{
List<Pair<Actor, GrantConditionOnPrerequisite>> list;
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
if (!upgradables.TryGetValue(key, out list))
return;
foreach (var u in list)
u.Second.PrerequisitesUpdated(u.First, true);
u.GrantConditionOnPrerequisite.PrerequisitesUpdated(u.Actor, true);
}
public void PrerequisitesUnavailable(string key)
{
List<Pair<Actor, GrantConditionOnPrerequisite>> list;
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
if (!upgradables.TryGetValue(key, out list))
return;
foreach (var u in list)
u.Second.PrerequisitesUpdated(u.First, false);
u.GrantConditionOnPrerequisite.PrerequisitesUpdated(u.Actor, false);
}
public void PrerequisitesItemHidden(string key) { }

View File

@@ -119,16 +119,16 @@ namespace OpenRA.Mods.Common.Traits
foreach (var t in BuildingUtils.GetLineBuildCells(w, targetLocation, actorInfo, buildingInfo, order.Player))
{
if (t.First == targetLocation)
if (t.Cell == targetLocation)
continue;
w.CreateActor(t.First == targetLocation ? actorInfo.Name : segmentType, new TypeDictionary
w.CreateActor(t.Cell == targetLocation ? actorInfo.Name : segmentType, new TypeDictionary
{
new LocationInit(t.First),
new LocationInit(t.Cell),
new OwnerInit(order.Player),
new FactionInit(faction),
new LineBuildDirectionInit(t.First.X == targetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X),
new LineBuildParentInit(new[] { t.Second, placed }),
new LineBuildDirectionInit(t.Cell.X == targetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X),
new LineBuildParentInit(new[] { t.Actor, placed }),
new PlaceBuildingInit()
});
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public bool IsInitialized { get; private set; }
readonly World world;
CellLayer<Pair<int, int>> terrainColor;
CellLayer<(int, int)> terrainColor;
readonly Shroud shroud;
public event Action<MPos> CellTerrainColorChanged = null;
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World w, WorldRenderer wr)
{
terrainColor = new CellLayer<Pair<int, int>>(w.Map);
terrainColor = new CellLayer<(int, int)>(w.Map);
w.AddFrameEndTask(_ =>
{
@@ -82,22 +82,22 @@ namespace OpenRA.Mods.Common.Traits
});
}
public Pair<int, int> this[MPos uv]
public (int Left, int Right) this[MPos uv]
{
get { return terrainColor[uv]; }
}
public static Pair<int, int> GetColor(Map map, MPos uv)
public static (int Left, int Right) GetColor(Map map, MPos uv)
{
var custom = map.CustomTerrain[uv];
if (custom != byte.MaxValue)
{
var c = map.Rules.TileSet[custom].Color.ToArgb();
return Pair.New(c, c);
return (c, c);
}
var tc = map.GetTerrainColorPair(uv);
return Pair.New(tc.First.ToArgb(), tc.Second.ToArgb());
return (tc.Left.ToArgb(), tc.Right.ToArgb());
}
}
}

View File

@@ -119,12 +119,12 @@ namespace OpenRA.Mods.Common.Traits
var myTeam = self.World.LobbyInfo.ClientWithIndex(self.Owner.ClientIndex).Team;
var teams = self.World.Players.Where(p => !p.NonCombatant && p.Playable)
.Select(p => new Pair<Player, PlayerStatistics>(p, p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.Second != null ? p.Second.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.First.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.Second != null ? gg.Second.Experience : 0));
.Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics != null ? gg.PlayerStatistics.Experience : 0));
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().First == self.Owner))
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().Player == self.Owner))
{
mo.MarkCompleted(self.Owner, objectiveID);
return;

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits.Radar
modifier = self.TraitsImplementing<IRadarColorModifier>().FirstOrDefault();
}
public void PopulateRadarSignatureCells(Actor self, List<Pair<CPos, Color>> destinationBuffer)
public void PopulateRadarSignatureCells(Actor self, List<(CPos Cell, Color Color)> destinationBuffer)
{
var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer;
if (IsTraitDisabled || (viewer != null && !Info.ValidStances.HasStance(self.Owner.Stances[viewer])))
@@ -51,12 +51,12 @@ namespace OpenRA.Mods.Common.Traits.Radar
if (Info.UseLocation)
{
destinationBuffer.Add(Pair.New(self.Location, color));
destinationBuffer.Add((self.Location, color));
return;
}
foreach (var cell in self.OccupiesSpace.OccupiedCells())
destinationBuffer.Add(Pair.New(cell.First, color));
destinationBuffer.Add((cell.Cell, color));
}
}
}

View File

@@ -87,12 +87,12 @@ namespace OpenRA.Mods.Common.Traits.Render
public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged, IActorPreviewInitModifier
{
static readonly Pair<DamageState, string>[] DamagePrefixes =
static readonly (DamageState DamageState, string Prefix)[] DamagePrefixes =
{
Pair.New(DamageState.Critical, "critical-"),
Pair.New(DamageState.Heavy, "damaged-"),
Pair.New(DamageState.Medium, "scratched-"),
Pair.New(DamageState.Light, "scuffed-")
(DamageState.Critical, "critical-"),
(DamageState.Heavy, "damaged-"),
(DamageState.Medium, "scratched-"),
(DamageState.Light, "scuffed-")
};
class AnimationWrapper
@@ -251,9 +251,9 @@ namespace OpenRA.Mods.Common.Traits.Render
// Remove existing damage prefix
foreach (var s in DamagePrefixes)
{
if (sequence.StartsWith(s.Second, StringComparison.Ordinal))
if (sequence.StartsWith(s.Prefix, StringComparison.Ordinal))
{
sequence = sequence.Substring(s.Second.Length);
sequence = sequence.Substring(s.Prefix.Length);
break;
}
}
@@ -267,8 +267,8 @@ namespace OpenRA.Mods.Common.Traits.Render
sequence = UnnormalizeSequence(sequence);
foreach (var s in DamagePrefixes)
if (state >= s.First && anim.HasSequence(s.Second + sequence))
return s.Second + sequence;
if (state >= s.DamageState && anim.HasSequence(s.Prefix + sequence))
return s.Prefix + sequence;
return sequence;
}

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
SendParatroopers(self, order.Target.CenterPosition, facing);
}
public Pair<Actor[], Actor[]> SendParatroopers(Actor self, WPos target, WAngle? facing = null)
public (Actor[] Aircraft, Actor[] Units) SendParatroopers(Actor self, WPos target, WAngle? facing = null)
{
var aircraft = new List<Actor>();
var units = new List<Actor>();
@@ -266,7 +266,7 @@ namespace OpenRA.Mods.Common.Traits
}
});
return Pair.New(aircraft.ToArray(), units.ToArray());
return (aircraft.ToArray(), units.ToArray());
}
void RemoveCamera(Actor camera)

View File

@@ -359,20 +359,20 @@ namespace OpenRA.Mods.Common.Traits
{
foreach (var c in ios.OccupiedCells())
{
var uv = c.First.ToMPos(map);
var uv = c.Cell.ToMPos(map);
if (!influence.Contains(uv))
continue;
var layer = c.First.Layer == 0 ? influence : customInfluence[c.First.Layer];
layer[uv] = new InfluenceNode { Next = layer[uv], SubCell = c.Second, Actor = self };
var layer = c.Cell.Layer == 0 ? influence : customInfluence[c.Cell.Layer];
layer[uv] = new InfluenceNode { Next = layer[uv], SubCell = c.SubCell, Actor = self };
List<CellTrigger> triggers;
if (cellTriggerInfluence.TryGetValue(c.First, out triggers))
if (cellTriggerInfluence.TryGetValue(c.Cell, out triggers))
foreach (var t in triggers)
t.Dirty = true;
if (CellUpdated != null)
CellUpdated(c.First);
CellUpdated(c.Cell);
}
}
@@ -380,22 +380,22 @@ namespace OpenRA.Mods.Common.Traits
{
foreach (var c in ios.OccupiedCells())
{
var uv = c.First.ToMPos(map);
var uv = c.Cell.ToMPos(map);
if (!influence.Contains(uv))
continue;
var layer = c.First.Layer == 0 ? influence : customInfluence[c.First.Layer];
var layer = c.Cell.Layer == 0 ? influence : customInfluence[c.Cell.Layer];
var temp = layer[uv];
RemoveInfluenceInner(ref temp, self);
layer[uv] = temp;
List<CellTrigger> triggers;
if (cellTriggerInfluence.TryGetValue(c.First, out triggers))
if (cellTriggerInfluence.TryGetValue(c.Cell, out triggers))
foreach (var t in triggers)
t.Dirty = true;
if (CellUpdated != null)
CellUpdated(c.First);
CellUpdated(c.Cell);
}
}
@@ -416,7 +416,7 @@ namespace OpenRA.Mods.Common.Traits
return;
foreach (var c in ios.OccupiedCells())
CellUpdated(c.First);
CellUpdated(c.Cell);
}
void ITick.Tick(Actor self)

View File

@@ -315,11 +315,11 @@ namespace OpenRA.Mods.Common.Traits
return nodes;
}
public void PopulateRadarSignatureCells(Actor self, List<Pair<CPos, Color>> destinationBuffer)
public void PopulateRadarSignatureCells(Actor self, List<(CPos Cell, Color Color)> destinationBuffer)
{
foreach (var previewsForCell in cellMap)
foreach (var preview in previewsForCell.Value)
destinationBuffer.Add(Pair.New(previewsForCell.Key, preview.RadarColor));
destinationBuffer.Add((previewsForCell.Key, preview.RadarColor));
}
public EditorActorPreview this[string id]

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
class LegacyBridgeLayer : IWorldLoaded
{
readonly LegacyBridgeLayerInfo info;
readonly Dictionary<ushort, Pair<string, int>> bridgeTypes = new Dictionary<ushort, Pair<string, int>>();
readonly Dictionary<ushort, (string Template, int Health)> bridgeTypes = new Dictionary<ushort, (string, int)>();
CellLayer<Bridge> bridges;
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
{
var bi = w.Map.Rules.Actors[bridge].TraitInfo<BridgeInfo>();
foreach (var template in bi.Templates)
bridgeTypes.Add(template.First, Pair.New(bridge, template.Second));
bridgeTypes.Add(template.Template, (bridge, template.Health));
}
// Take all templates to overlay from the map
@@ -73,11 +73,11 @@ namespace OpenRA.Mods.Common.Traits
var nj = cell.Y - index / template.Size.X;
// Create a new actor for this bridge and keep track of which subtiles this bridge includes
var bridge = w.CreateActor(bridgeTypes[tile].First, new TypeDictionary
var bridge = w.CreateActor(bridgeTypes[tile].Template, new TypeDictionary
{
new LocationInit(new CPos(ni, nj)),
new OwnerInit(w.WorldActor.Owner),
new HealthInit(bridgeTypes[tile].Second, true),
new HealthInit(bridgeTypes[tile].Health, true),
}).Trait<Bridge>();
var subTiles = new Dictionary<CPos, byte>();

View File

@@ -133,8 +133,8 @@ namespace OpenRA.Mods.Common.Traits
var n = taken.Count == 0 || !separateTeamSpawns
? world.SharedRandom.Next(available.Count)
: available // pick the most distant spawnpoint from everyone else
.Select((k, i) => Pair.New(k, i))
.MaxBy(a => taken.Sum(t => (t - a.First).LengthSquared)).Second;
.Select((k, i) => (Cell: k, Index: i))
.MaxBy(a => taken.Sum(t => (t - a.Cell).LengthSquared)).Index;
var sp = available[n];
available.RemoveAt(n);

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Allow resource to spawn on ramp tiles.")]
public readonly bool AllowOnRamps = false;
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<Pair<MPos, Color>> destinationBuffer)
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer)
{
var tileSet = map.Rules.TileSet;
var color = tileSet[tileSet.GetTerrainIndex(TerrainType)].Color;
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
{
var cell = new MPos(i, j);
if (map.Resources[cell].Type == ResourceType)
destinationBuffer.Add(new Pair<MPos, Color>(cell, color));
destinationBuffer.Add((cell, color));
}
}
}