Use out var syntax
This commit is contained in:
@@ -40,9 +40,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(Explosion))
|
||||
return;
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = Explosion.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
ExplosionWeapon = weapon;
|
||||
|
||||
@@ -87,10 +87,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
WeaponInfo weaponInfo;
|
||||
|
||||
var weaponToLower = Weapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weaponInfo))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weaponInfo))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
WeaponInfo = weaponInfo;
|
||||
|
||||
@@ -108,8 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// requestedTargetPresetForActivity will be cleared once the activity starts running and calls UpdateRequestedTarget
|
||||
if (self.CurrentActivity != null && self.CurrentActivity.NextActivity == requestedTargetPresetForActivity)
|
||||
{
|
||||
bool targetIsHiddenActor;
|
||||
RequestedTarget = RequestedTarget.Recalculate(self.Owner, out targetIsHiddenActor);
|
||||
RequestedTarget = RequestedTarget.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||
}
|
||||
|
||||
// Requested activity has been canceled
|
||||
@@ -271,8 +270,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (attack.IsTraitPaused)
|
||||
return false;
|
||||
|
||||
bool targetIsHiddenActor;
|
||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
||||
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||
attack.SetRequestedTarget(self, target, forceAttack);
|
||||
hasTicked = true;
|
||||
|
||||
|
||||
@@ -171,8 +171,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (conditionToken != Actor.InvalidConditionToken)
|
||||
conditionToken = self.RevokeCondition(conditionToken);
|
||||
|
||||
string condition;
|
||||
if (Info.ConditionByStance.TryGetValue(stance, out condition))
|
||||
if (Info.ConditionByStance.TryGetValue(stance, out var condition))
|
||||
conditionToken = self.GrantCondition(condition);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
|
||||
protected static bool NearToPosSafely(Squad owner, WPos loc)
|
||||
{
|
||||
Actor a;
|
||||
return NearToPosSafely(owner, loc, out a);
|
||||
return NearToPosSafely(owner, loc, out var a);
|
||||
}
|
||||
|
||||
protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget)
|
||||
|
||||
@@ -223,8 +223,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var n in waitingPowersNode.Value.Nodes)
|
||||
{
|
||||
SupportPowerInstance instance;
|
||||
if (supportPowerManager.Powers.TryGetValue(n.Key, out instance))
|
||||
if (supportPowerManager.Powers.TryGetValue(n.Key, out var instance))
|
||||
waitingPowers[instance] = FieldLoader.GetValue<int>("WaitingPowers", n.Value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(DemolishWeapon))
|
||||
throw new YamlException("A value for DemolishWeapon of a Bridge trait is missing.");
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = DemolishWeapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
DemolishWeaponInfo = weapon;
|
||||
|
||||
@@ -60,10 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void DoDelivery(CPos location, string actorName, string carrierActorName)
|
||||
{
|
||||
Actor cargo;
|
||||
Actor carrier;
|
||||
|
||||
CreateActors(actorName, carrierActorName, out cargo, out carrier);
|
||||
CreateActors(actorName, carrierActorName, out var cargo, out var carrier);
|
||||
|
||||
var carryable = cargo.Trait<Carryable>();
|
||||
carryable.Reserve(cargo, carrier);
|
||||
|
||||
@@ -36,9 +36,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = (DemolishWeapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
DemolishWeaponInfo = weapon;
|
||||
|
||||
@@ -171,11 +171,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (cargo.Any())
|
||||
{
|
||||
foreach (var c in cargo)
|
||||
{
|
||||
string passengerCondition;
|
||||
if (Info.PassengerConditions.TryGetValue(c.Info.Name, out passengerCondition))
|
||||
if (Info.PassengerConditions.TryGetValue(c.Info.Name, out var passengerCondition))
|
||||
passengerTokens.GetOrAdd(c.Info.Name).Push(self.GrantCondition(passengerCondition));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Info.LoadedCondition))
|
||||
loadedTokens.Push(self.GrantCondition(Info.LoadedCondition));
|
||||
@@ -353,8 +350,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var p = passenger.Trait<Passenger>();
|
||||
p.Transport = null;
|
||||
|
||||
Stack<int> passengerToken;
|
||||
if (passengerTokens.TryGetValue(passenger.Info.Name, out passengerToken) && passengerToken.Any())
|
||||
if (passengerTokens.TryGetValue(passenger.Info.Name, out var passengerToken) && passengerToken.Any())
|
||||
self.RevokeCondition(passengerToken.Pop());
|
||||
|
||||
if (loadedTokens.Any())
|
||||
@@ -400,8 +396,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
npe.OnPassengerEntered(self, a);
|
||||
}
|
||||
|
||||
string passengerCondition;
|
||||
if (Info.PassengerConditions.TryGetValue(a.Info.Name, out passengerCondition))
|
||||
if (Info.PassengerConditions.TryGetValue(a.Info.Name, out var passengerCondition))
|
||||
passengerTokens.GetOrAdd(a.Info.Name).Push(self.GrantCondition(passengerCondition));
|
||||
|
||||
if (!string.IsNullOrEmpty(Info.LoadedCondition))
|
||||
|
||||
@@ -76,11 +76,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Timed tokens do not count towards the source cap: the condition with the shortest
|
||||
// remaining duration can always be revoked to make room.
|
||||
if (Info.SourceCap > 0)
|
||||
{
|
||||
HashSet<int> permanentTokensForSource;
|
||||
if (permanentTokens.TryGetValue(source, out permanentTokensForSource) && permanentTokensForSource.Count >= Info.SourceCap)
|
||||
if (permanentTokens.TryGetValue(source, out var permanentTokensForSource) && permanentTokensForSource.Count >= Info.SourceCap)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Info.TotalCap > 0 && permanentTokens.Values.Sum(t => t.Count) >= Info.TotalCap)
|
||||
return false;
|
||||
@@ -94,8 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return Actor.InvalidConditionToken;
|
||||
|
||||
var token = self.GrantCondition(Info.Condition);
|
||||
HashSet<int> permanent;
|
||||
permanentTokens.TryGetValue(source, out permanent);
|
||||
permanentTokens.TryGetValue(source, out var permanent);
|
||||
|
||||
// Callers can override the amount of time remaining by passing a value
|
||||
// between 1 and the duration
|
||||
@@ -167,8 +163,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
HashSet<int> permanentTokensForSource;
|
||||
if (permanentTokens.TryGetValue(source, out permanentTokensForSource))
|
||||
if (permanentTokens.TryGetValue(source, out var permanentTokensForSource))
|
||||
{
|
||||
if (!permanentTokensForSource.Remove(token))
|
||||
return false;
|
||||
|
||||
@@ -47,8 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void RevokeCondition(Actor self, Actor segment)
|
||||
{
|
||||
int token;
|
||||
if (!tokens.TryGetValue(segment, out token))
|
||||
if (!tokens.TryGetValue(segment, out var token))
|
||||
return;
|
||||
|
||||
tokens.Remove(segment);
|
||||
|
||||
@@ -151,8 +151,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (a.Disposed)
|
||||
return;
|
||||
|
||||
int token;
|
||||
if (!tokens.TryGetValue(a, out token))
|
||||
if (!tokens.TryGetValue(a, out var token))
|
||||
return;
|
||||
|
||||
tokens.Remove(a);
|
||||
|
||||
@@ -60,18 +60,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Weapon))
|
||||
{
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = Weapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
WeaponInfo = weapon;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(EmptyWeapon))
|
||||
{
|
||||
WeaponInfo emptyWeapon;
|
||||
var emptyWeaponToLower = EmptyWeapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(emptyWeaponToLower, out emptyWeapon))
|
||||
if (!rules.Weapons.TryGetValue(emptyWeaponToLower, out var emptyWeapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(emptyWeaponToLower));
|
||||
EmptyWeaponInfo = emptyWeapon;
|
||||
}
|
||||
|
||||
@@ -37,9 +37,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(Weapon))
|
||||
return;
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = Weapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
@@ -419,8 +419,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (ToCell.Layer == 0)
|
||||
return true;
|
||||
|
||||
ICustomMovementLayer layer;
|
||||
if (self.World.GetCustomMovementLayers().TryGetValue(ToCell.Layer, out layer))
|
||||
if (self.World.GetCustomMovementLayers().TryGetValue(ToCell.Layer, out var layer))
|
||||
return layer.InteractsWithDefaultLayer;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -129,12 +129,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyEnteredCargo.OnEnteredCargo(Actor self, Actor cargo)
|
||||
{
|
||||
string specificCargoCondition;
|
||||
|
||||
if (anyCargoToken == Actor.InvalidConditionToken)
|
||||
anyCargoToken = self.GrantCondition(Info.CargoCondition);
|
||||
|
||||
if (specificCargoToken == Actor.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out specificCargoCondition))
|
||||
if (specificCargoToken == Actor.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out var specificCargoCondition))
|
||||
specificCargoToken = self.GrantCondition(specificCargoCondition);
|
||||
|
||||
// Allow scripted / initial actors to move from the unload point back into the cell grid on unload
|
||||
|
||||
@@ -69,8 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
{
|
||||
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
|
||||
if (!upgradables.TryGetValue(key, out list))
|
||||
if (!upgradables.TryGetValue(key, out var list))
|
||||
return;
|
||||
|
||||
foreach (var u in list)
|
||||
@@ -79,8 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesUnavailable(string key)
|
||||
{
|
||||
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
|
||||
if (!upgradables.TryGetValue(key, out list))
|
||||
if (!upgradables.TryGetValue(key, out var list))
|
||||
return;
|
||||
|
||||
foreach (var u in list)
|
||||
|
||||
@@ -270,8 +270,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanBuild(ActorInfo actor)
|
||||
{
|
||||
ProductionState ps;
|
||||
if (!Producible.TryGetValue(actor, out ps))
|
||||
if (!Producible.TryGetValue(actor, out var ps))
|
||||
return false;
|
||||
|
||||
return ps.Buildable || developerMode.AllTech;
|
||||
|
||||
@@ -120,8 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void EnablePlug(Actor self, string type)
|
||||
{
|
||||
string condition;
|
||||
if (!Info.Conditions.TryGetValue(type, out condition))
|
||||
if (!Info.Conditions.TryGetValue(type, out var condition))
|
||||
return;
|
||||
|
||||
if (conditionToken != Actor.InvalidConditionToken)
|
||||
|
||||
@@ -78,8 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
// Old is 0 if a is not in powerDrain
|
||||
int old;
|
||||
powerDrain.TryGetValue(a, out old);
|
||||
powerDrain.TryGetValue(a, out var old);
|
||||
|
||||
var amount = a.TraitsImplementing<Power>().Where(t => !t.IsTraitDisabled).Sum(p => p.GetEnabledPower());
|
||||
powerDrain[a] = amount;
|
||||
@@ -106,8 +105,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (a.IsInWorld)
|
||||
return;
|
||||
|
||||
int amount;
|
||||
if (!powerDrain.TryGetValue(a, out amount))
|
||||
if (!powerDrain.TryGetValue(a, out var amount))
|
||||
return;
|
||||
powerDrain.Remove(a);
|
||||
|
||||
|
||||
@@ -80,8 +80,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
bool IProductionIconOverlay.IsOverlayActive(ActorInfo ai)
|
||||
{
|
||||
bool isActive;
|
||||
if (!overlayActive.TryGetValue(ai, out isActive))
|
||||
if (!overlayActive.TryGetValue(ai, out var isActive))
|
||||
return false;
|
||||
|
||||
return isActive;
|
||||
|
||||
@@ -61,12 +61,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
var n = i * harvester.Info.Capacity / Info.PipCount;
|
||||
|
||||
string sequence;
|
||||
foreach (var rt in harvester.Contents)
|
||||
{
|
||||
if (n < rt.Value)
|
||||
{
|
||||
if (!Info.ResourceSequences.TryGetValue(rt.Key.Type, out sequence))
|
||||
if (!Info.ResourceSequences.TryGetValue(rt.Key.Type, out var sequence))
|
||||
sequence = Info.FullSequence;
|
||||
|
||||
return sequence;
|
||||
|
||||
@@ -135,9 +135,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
public void Attacking(Actor self, Target target, Armament a)
|
||||
{
|
||||
string sequence;
|
||||
var info = GetDisplayInfo();
|
||||
if (!info.AttackSequences.TryGetValue(a.Info.Name, out sequence))
|
||||
if (!info.AttackSequences.TryGetValue(a.Info.Name, out var sequence))
|
||||
sequence = info.DefaultAttackSequence;
|
||||
|
||||
if (!string.IsNullOrEmpty(sequence) && DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, sequence)))
|
||||
|
||||
@@ -122,9 +122,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
adjacent = 0;
|
||||
foreach (var a in adjacentActors)
|
||||
{
|
||||
CVec facing;
|
||||
var wc = a.TraitsImplementing<IWallConnector>().FirstEnabledTraitOrDefault();
|
||||
if (wc == null || !wc.AdjacentWallCanConnect(a, self.Location, wallInfo.Type, out facing))
|
||||
if (wc == null || !wc.AdjacentWallCanConnect(a, self.Location, wallInfo.Type, out var facing))
|
||||
continue;
|
||||
|
||||
if (facing.Y > 0)
|
||||
|
||||
@@ -107,9 +107,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!string.IsNullOrEmpty(TrailImage) && !TrailSequences.Any())
|
||||
throw new YamlException("At least one entry in TrailSequences must be defined when TrailImage is defined.");
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = (MissileWeapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
@@ -108,8 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
facing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
|
||||
|
||||
var utLower = info.UnitType.ToLowerInvariant();
|
||||
ActorInfo unitType;
|
||||
if (!self.World.Map.Rules.Actors.TryGetValue(utLower, out unitType))
|
||||
if (!self.World.Map.Rules.Actors.TryGetValue(utLower, out var unitType))
|
||||
throw new YamlException("Actors ruleset does not include the entry '{0}'".F(utLower));
|
||||
|
||||
var altitude = unitType.TraitInfo<AircraftInfo>().CruiseAltitude.Length;
|
||||
|
||||
@@ -119,8 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
{
|
||||
SupportPowerInstance sp;
|
||||
if (!Powers.TryGetValue(key, out sp))
|
||||
if (!Powers.TryGetValue(key, out var sp))
|
||||
return;
|
||||
|
||||
sp.PrerequisitesAvailable(true);
|
||||
@@ -128,8 +127,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesUnavailable(string key)
|
||||
{
|
||||
SupportPowerInstance sp;
|
||||
if (!Powers.TryGetValue(key, out sp))
|
||||
if (!Powers.TryGetValue(key, out var sp))
|
||||
return;
|
||||
|
||||
sp.PrerequisitesAvailable(false);
|
||||
|
||||
@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RemoveLightSource(int token)
|
||||
{
|
||||
LightSource source;
|
||||
if (!lightSources.TryGetValue(token, out source))
|
||||
if (!lightSources.TryGetValue(token, out var source))
|
||||
return;
|
||||
|
||||
lightSources.Remove(token);
|
||||
|
||||
@@ -38,9 +38,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
WeaponInfos = Weapons.Select(w =>
|
||||
{
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = w.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
return weapon;
|
||||
}).ToArray();
|
||||
|
||||
@@ -377,8 +377,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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.Cell, out triggers))
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out var triggers))
|
||||
foreach (var t in triggers)
|
||||
t.Dirty = true;
|
||||
|
||||
@@ -400,8 +399,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
RemoveInfluenceInner(ref temp, self);
|
||||
layer[uv] = temp;
|
||||
|
||||
List<CellTrigger> triggers;
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out triggers))
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out var triggers))
|
||||
foreach (var t in triggers)
|
||||
t.Dirty = true;
|
||||
|
||||
@@ -487,8 +485,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RemoveCellTrigger(int id)
|
||||
{
|
||||
CellTrigger trigger;
|
||||
if (!cellTriggers.TryGetValue(id, out trigger))
|
||||
if (!cellTriggers.TryGetValue(id, out var trigger))
|
||||
return;
|
||||
|
||||
foreach (var c in trigger.Footprint)
|
||||
@@ -514,8 +511,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RemoveProximityTrigger(int id)
|
||||
{
|
||||
ProximityTrigger t;
|
||||
if (!proximityTriggers.TryGetValue(id, out t))
|
||||
if (!proximityTriggers.TryGetValue(id, out var t))
|
||||
return;
|
||||
|
||||
foreach (var bin in BinsInBox(t.TopLeft, t.BottomRight))
|
||||
@@ -526,8 +522,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void UpdateProximityTrigger(int id, WPos newPos, WDist newRange, WDist newVRange)
|
||||
{
|
||||
ProximityTrigger t;
|
||||
if (!proximityTriggers.TryGetValue(id, out t))
|
||||
if (!proximityTriggers.TryGetValue(id, out var t))
|
||||
return;
|
||||
|
||||
foreach (var bin in BinsInBox(t.TopLeft, t.BottomRight))
|
||||
|
||||
@@ -163,8 +163,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var cell in footprint)
|
||||
{
|
||||
List<EditorActorPreview> list;
|
||||
if (!cellMap.TryGetValue(cell, out list))
|
||||
if (!cellMap.TryGetValue(cell, out var list))
|
||||
continue;
|
||||
|
||||
list.Remove(preview);
|
||||
@@ -228,8 +227,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void AddPreviewLocation(EditorActorPreview preview, CPos location)
|
||||
{
|
||||
List<EditorActorPreview> list;
|
||||
if (!cellMap.TryGetValue(location, out list))
|
||||
if (!cellMap.TryGetValue(location, out var list))
|
||||
{
|
||||
list = new List<EditorActorPreview>();
|
||||
cellMap.Add(location, list);
|
||||
@@ -256,8 +254,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<EditorActorPreview> PreviewsAt(CPos cell)
|
||||
{
|
||||
List<EditorActorPreview> list;
|
||||
if (cellMap.TryGetValue(cell, out list))
|
||||
if (cellMap.TryGetValue(cell, out var list))
|
||||
return list;
|
||||
|
||||
return Enumerable.Empty<EditorActorPreview>();
|
||||
@@ -274,8 +271,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var blocked = previews.Any(p =>
|
||||
{
|
||||
SubCell s;
|
||||
return p.Footprint.TryGetValue(cell, out s) && s == (SubCell)i;
|
||||
return p.Footprint.TryGetValue(cell, out var s) && s == (SubCell)i;
|
||||
});
|
||||
|
||||
if (!blocked)
|
||||
|
||||
@@ -71,11 +71,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var tile = Map.Resources[uv];
|
||||
var t = Tiles[uv];
|
||||
ResourceType type;
|
||||
|
||||
var newTile = ResourceLayerContents.Empty;
|
||||
var newTerrain = byte.MaxValue;
|
||||
if (Resources.TryGetValue(tile.Type, out type))
|
||||
if (Resources.TryGetValue(tile.Type, out var type))
|
||||
{
|
||||
newTile = new ResourceLayerContents
|
||||
{
|
||||
|
||||
@@ -83,8 +83,7 @@ namespace OpenRA.Mods.Common
|
||||
|
||||
public Color GetRemappedColor(Color original, int index)
|
||||
{
|
||||
int c;
|
||||
return replacements.TryGetValue(index, out c)
|
||||
return replacements.TryGetValue(index, out var c)
|
||||
? basePalette.GetColor(c) : original;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ namespace OpenRA.Mods.Common
|
||||
{
|
||||
var basePalette = wr.Palette(info.BasePalette).Palette;
|
||||
ImmutablePalette pal;
|
||||
int[] remap;
|
||||
|
||||
if (info.PlayerIndex.TryGetValue(playerName, out remap))
|
||||
if (info.PlayerIndex.TryGetValue(playerName, out var remap))
|
||||
pal = new ImmutablePalette(basePalette, new IndexedColorRemap(basePalette, info.RemapIndex, remap));
|
||||
else
|
||||
pal = new ImmutablePalette(basePalette);
|
||||
|
||||
@@ -107,8 +107,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var kvp in TerrainSpeeds)
|
||||
{
|
||||
byte index;
|
||||
if (tileSet.TryGetTerrainIndex(kvp.Key, out index))
|
||||
if (tileSet.TryGetTerrainIndex(kvp.Key, out var index))
|
||||
info[index] = kvp.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!lines.MoveNext() || (lines.Current != "GIMP Palette" && lines.Current != "JASC-PAL"))
|
||||
throw new InvalidDataException("File `{0}` is not a valid GIMP or JASC palette.".F(Filename));
|
||||
|
||||
byte r, g, b, a;
|
||||
byte a;
|
||||
a = 255;
|
||||
var i = 0;
|
||||
|
||||
@@ -77,13 +77,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (rgba.Length < 3)
|
||||
throw new InvalidDataException("Invalid RGB(A) triplet/quartet: ({0})".F(string.Join(" ", rgba)));
|
||||
|
||||
if (!byte.TryParse(rgba[0], out r))
|
||||
if (!byte.TryParse(rgba[0], out var r))
|
||||
throw new InvalidDataException("Invalid R value: {0}".F(rgba[0]));
|
||||
|
||||
if (!byte.TryParse(rgba[1], out g))
|
||||
if (!byte.TryParse(rgba[1], out var g))
|
||||
throw new InvalidDataException("Invalid G value: {0}".F(rgba[1]));
|
||||
|
||||
if (!byte.TryParse(rgba[2], out b))
|
||||
if (!byte.TryParse(rgba[2], out var b))
|
||||
throw new InvalidDataException("Invalid B value: {0}".F(rgba[2]));
|
||||
|
||||
// Check if color has a (valid) alpha value.
|
||||
|
||||
@@ -38,8 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
// Remove the actor's last claim, if it has one
|
||||
CPos lastClaim;
|
||||
if (claimByActor.TryGetValue(claimer, out lastClaim))
|
||||
if (claimByActor.TryGetValue(claimer, out var lastClaim))
|
||||
claimByCell.GetOrAdd(lastClaim).Remove(claimer);
|
||||
|
||||
claimers.Add(claimer);
|
||||
@@ -61,8 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
/// </summary>
|
||||
public void RemoveClaim(Actor claimer)
|
||||
{
|
||||
CPos lastClaim;
|
||||
if (claimByActor.TryGetValue(claimer, out lastClaim))
|
||||
if (claimByActor.TryGetValue(claimer, out var lastClaim))
|
||||
claimByCell.GetOrAdd(lastClaim).Remove(claimer);
|
||||
|
||||
claimByActor.Remove(claimer);
|
||||
|
||||
@@ -82,8 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var cell in w.Map.AllCells)
|
||||
{
|
||||
ResourceType t;
|
||||
if (!resources.TryGetValue(w.Map.Resources[cell].Type, out t))
|
||||
if (!resources.TryGetValue(w.Map.Resources[cell].Type, out var t))
|
||||
continue;
|
||||
|
||||
if (!AllowResourceAt(t, cell))
|
||||
|
||||
@@ -51,10 +51,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static object LoadInitialSmudges(MiniYaml yaml)
|
||||
{
|
||||
MiniYaml smudgeYaml;
|
||||
var nd = yaml.ToDictionary();
|
||||
var smudges = new Dictionary<CPos, MapSmudge>();
|
||||
if (nd.TryGetValue("InitialSmudges", out smudgeYaml))
|
||||
if (nd.TryGetValue("InitialSmudges", out var smudgeYaml))
|
||||
{
|
||||
foreach (var node in smudgeYaml.Nodes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user