diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs
index 8a8b6beae1..c513847fdd 100644
--- a/OpenRA.Game/Actor.cs
+++ b/OpenRA.Game/Actor.cs
@@ -560,8 +560,7 @@ namespace OpenRA
/// The invalid token ID.
public int RevokeCondition(int token)
{
- string condition;
- if (!conditionTokens.TryGetValue(token, out condition))
+ if (!conditionTokens.TryGetValue(token, out var condition))
throw new InvalidOperationException("Attempting to revoke condition with invalid token {0} for {1}.".F(token, this));
conditionTokens.Remove(token);
@@ -594,8 +593,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- Actor a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out Actor a) || !right.TryGetClrValue(out Actor b))
return false;
return a == b;
diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs
index 9e0cddfcf4..06a578d167 100644
--- a/OpenRA.Game/CPos.cs
+++ b/OpenRA.Game/CPos.cs
@@ -89,9 +89,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- CPos a;
- CVec b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out CPos a) || !right.TryGetClrValue(out CVec b))
throw new LuaException("Attempted to call CPos.Add(CPos, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -99,21 +97,18 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- CPos a;
var rightType = right.WrappedClrType();
- if (!left.TryGetClrValue(out a))
+ if (!left.TryGetClrValue(out CPos a))
throw new LuaException("Attempted to call CPos.Subtract(CPos, (CPos|CVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
if (rightType == typeof(CPos))
{
- CPos b;
- right.TryGetClrValue(out b);
+ right.TryGetClrValue(out CPos b);
return new LuaCustomClrObject(a - b);
}
else if (rightType == typeof(CVec))
{
- CVec b;
- right.TryGetClrValue(out b);
+ right.TryGetClrValue(out CVec b);
return new LuaCustomClrObject(a - b);
}
@@ -122,8 +117,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- CPos a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out CPos a) || !right.TryGetClrValue(out CPos b))
return false;
return a == b;
diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs
index 7099b7a094..2892537962 100644
--- a/OpenRA.Game/CVec.cs
+++ b/OpenRA.Game/CVec.cs
@@ -75,8 +75,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- CVec a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
throw new LuaException("Attempted to call CVec.Add(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -84,8 +83,7 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- CVec a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
throw new LuaException("Attempted to call CVec.Subtract(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a - b);
@@ -98,8 +96,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- CVec a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
return false;
return a == b;
diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs
index ebb67f281e..ebd347a10c 100644
--- a/OpenRA.Game/Exts.cs
+++ b/OpenRA.Game/Exts.cs
@@ -125,8 +125,7 @@ namespace OpenRA
public static V GetOrAdd(this Dictionary d, K k, Func createFn)
{
- V ret;
- if (!d.TryGetValue(k, out ret))
+ if (!d.TryGetValue(k, out var ret))
d.Add(k, ret = createFn(k));
return ret;
}
@@ -353,8 +352,7 @@ namespace OpenRA
public static int IntegerDivisionRoundingAwayFromZero(int dividend, int divisor)
{
- int remainder;
- var quotient = Math.DivRem(dividend, divisor, out remainder);
+ var quotient = Math.DivRem(dividend, divisor, out var remainder);
if (remainder == 0)
return quotient;
return quotient + (Math.Sign(dividend) == Math.Sign(divisor) ? 1 : -1);
@@ -405,8 +403,7 @@ namespace OpenRA
// Check for a key conflict:
if (d.ContainsKey(key))
{
- List dupKeyMessages;
- if (!dupKeys.TryGetValue(key, out dupKeyMessages))
+ if (!dupKeys.TryGetValue(key, out var dupKeyMessages))
{
// Log the initial conflicting value already inserted:
dupKeyMessages = new List();
diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs
index f8267e1074..9aa96f1ccd 100644
--- a/OpenRA.Game/FieldLoader.cs
+++ b/OpenRA.Game/FieldLoader.cs
@@ -121,8 +121,7 @@ namespace OpenRA
{
ret = null;
- MiniYaml yaml;
- if (!md.TryGetValue(yamlName, out yaml))
+ if (!md.TryGetValue(yamlName, out var yaml))
return false;
ret = GetValue(field.Name, field.FieldType, yaml, field);
@@ -185,37 +184,32 @@ namespace OpenRA
if (fieldType == typeof(int))
{
- int res;
- if (Exts.TryParseIntegerInvariant(value, out res))
+ if (Exts.TryParseIntegerInvariant(value, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(ushort))
{
- ushort res;
- if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
+ if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
if (fieldType == typeof(long))
{
- long res;
- if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
+ if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(float))
{
- float res;
- if (value != null && float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
+ if (value != null && float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
return res * (value.Contains('%') ? 0.01f : 1f);
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(decimal))
{
- decimal res;
- if (value != null && decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
+ if (value != null && decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
return res * (value.Contains('%') ? 0.01m : 1m);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -227,16 +221,14 @@ namespace OpenRA
}
else if (fieldType == typeof(Color))
{
- Color color;
- if (value != null && Color.TryParse(value, out color))
+ if (value != null && Color.TryParse(value, out var color))
return color;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(Hotkey))
{
- Hotkey res;
- if (Hotkey.TryParse(value, out res))
+ if (Hotkey.TryParse(value, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
@@ -247,8 +239,7 @@ namespace OpenRA
}
else if (fieldType == typeof(WDist))
{
- WDist res;
- if (WDist.TryParse(value, out res))
+ if (WDist.TryParse(value, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
@@ -260,8 +251,7 @@ namespace OpenRA
var parts = value.Split(',');
if (parts.Length == 3)
{
- WDist rx, ry, rz;
- if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
+ if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz))
return new WVec(rx, ry, rz);
}
}
@@ -281,8 +271,7 @@ namespace OpenRA
for (var i = 0; i < vecs.Length; ++i)
{
- WDist rx, ry, rz;
- if (WDist.TryParse(parts[3 * i], out rx) && WDist.TryParse(parts[3 * i + 1], out ry) && WDist.TryParse(parts[3 * i + 2], out rz))
+ if (WDist.TryParse(parts[3 * i], out var rx) && WDist.TryParse(parts[3 * i + 1], out var ry) && WDist.TryParse(parts[3 * i + 2], out var rz))
vecs[i] = new WVec(rx, ry, rz);
}
@@ -298,8 +287,7 @@ namespace OpenRA
var parts = value.Split(',');
if (parts.Length == 3)
{
- WDist rx, ry, rz;
- if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
+ if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz))
return new WPos(rx, ry, rz);
}
}
@@ -308,8 +296,7 @@ namespace OpenRA
}
else if (fieldType == typeof(WAngle))
{
- int res;
- if (Exts.TryParseIntegerInvariant(value, out res))
+ if (Exts.TryParseIntegerInvariant(value, out var res))
return new WAngle(res);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -320,8 +307,7 @@ namespace OpenRA
var parts = value.Split(',');
if (parts.Length == 3)
{
- int rr, rp, ry;
- if (Exts.TryParseIntegerInvariant(parts[0], out rr) && Exts.TryParseIntegerInvariant(parts[1], out rp) && Exts.TryParseIntegerInvariant(parts[2], out ry))
+ if (Exts.TryParseIntegerInvariant(parts[0], out var rr) && Exts.TryParseIntegerInvariant(parts[1], out var rp) && Exts.TryParseIntegerInvariant(parts[2], out var ry))
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
}
}
@@ -360,8 +346,7 @@ namespace OpenRA
var vecs = new CVec[parts.Length / 2];
for (var i = 0; i < vecs.Length; i++)
{
- int rx, ry;
- if (int.TryParse(parts[2 * i], out rx) && int.TryParse(parts[2 * i + 1], out ry))
+ if (int.TryParse(parts[2 * i], out var rx) && int.TryParse(parts[2 * i + 1], out var ry))
vecs[i] = new CVec(rx, ry);
}
@@ -415,8 +400,7 @@ namespace OpenRA
}
else if (fieldType == typeof(bool))
{
- bool result;
- if (bool.TryParse(value.ToLowerInvariant(), out result))
+ if (bool.TryParse(value.ToLowerInvariant(), out var result))
return result;
return InvalidValueAction(value, fieldType, fieldName);
@@ -509,8 +493,7 @@ namespace OpenRA
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
float xx = 0;
float yy = 0;
- float res;
- if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
+ if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
xx = res * (parts[0].Contains('%') ? 0.01f : 1f);
if (float.TryParse(parts[1].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
@@ -524,13 +507,11 @@ namespace OpenRA
if (value != null)
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- float x = 0;
- float y = 0;
- float z = 0;
- float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out x);
- float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out y);
+ float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var x);
+ float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var y);
// z component is optional for compatibility with older float2 definitions
+ float z = 0;
if (parts.Length > 2)
float.TryParse(parts[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out z);
@@ -575,8 +556,7 @@ namespace OpenRA
}
else if (fieldType == typeof(DateTime))
{
- DateTime dt;
- if (DateTime.TryParseExact(value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dt))
+ if (DateTime.TryParseExact(value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dt))
return dt;
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -726,8 +706,7 @@ namespace OpenRA
if (translations == null)
return key;
- string value;
- if (!translations.TryGetValue(key, out value))
+ if (!translations.TryGetValue(key, out var value))
return key;
return value;
diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs
index e7634f310c..fea594a6ef 100644
--- a/OpenRA.Game/FileSystem/FileSystem.cs
+++ b/OpenRA.Game/FileSystem/FileSystem.cs
@@ -67,15 +67,12 @@ namespace OpenRA.FileSystem
return new Folder(resolvedPath);
// Children of another package require special handling
- IReadOnlyPackage parent;
- string subPath = null;
- if (TryGetPackageContaining(filename, out parent, out subPath))
+ if (TryGetPackageContaining(filename, out var parent, out var subPath))
return parent.OpenPackage(subPath, this);
// Try and open it normally
- IReadOnlyPackage package;
var stream = Open(filename);
- if (TryParsePackage(stream, filename, out package))
+ if (TryParsePackage(stream, filename, out var package))
return package;
// No package loaders took ownership of the stream, so clean it up
@@ -97,8 +94,7 @@ namespace OpenRA.FileSystem
{
name = name.Substring(1);
- Manifest mod;
- if (!installedMods.TryGetValue(name, out mod))
+ if (!installedMods.TryGetValue(name, out var mod))
throw new InvalidOperationException("Could not load mod '{0}'. Available mods: {1}".F(name, installedMods.Keys.JoinWith(", ")));
package = mod.Package;
@@ -122,8 +118,7 @@ namespace OpenRA.FileSystem
public void Mount(IReadOnlyPackage package, string explicitName = null)
{
- var mountCount = 0;
- if (mountedPackages.TryGetValue(package, out mountCount))
+ if (mountedPackages.TryGetValue(package, out var mountCount))
{
// Package is already mounted
// Increment the mount count and bump up the file loading priority
@@ -149,8 +144,7 @@ namespace OpenRA.FileSystem
public bool Unmount(IReadOnlyPackage package)
{
- var mountCount = 0;
- if (!mountedPackages.TryGetValue(package, out mountCount))
+ if (!mountedPackages.TryGetValue(package, out var mountCount))
return false;
if (--mountCount <= 0)
@@ -211,8 +205,7 @@ namespace OpenRA.FileSystem
public Stream Open(string filename)
{
- Stream s;
- if (!TryOpen(filename, out s))
+ if (!TryOpen(filename, out var s))
throw new FileNotFoundException("File not found: {0}".F(filename), filename);
return s;
@@ -238,8 +231,7 @@ namespace OpenRA.FileSystem
var explicitSplit = filename.IndexOf('|');
if (explicitSplit > 0)
{
- IReadOnlyPackage explicitPackage;
- if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
+ if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
{
s = explicitPackage.GetStream(filename.Substring(explicitSplit + 1));
if (s != null)
@@ -274,12 +266,9 @@ namespace OpenRA.FileSystem
{
var explicitSplit = filename.IndexOf('|');
if (explicitSplit > 0)
- {
- IReadOnlyPackage explicitPackage;
- if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
+ if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
if (explicitPackage.Contains(filename.Substring(explicitSplit + 1)))
return true;
- }
return fileIndex.ContainsKey(filename);
}
@@ -293,8 +282,7 @@ namespace OpenRA.FileSystem
if (explicitSplit < 0)
return false;
- IReadOnlyPackage explicitPackage;
- if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
+ if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
return false;
if (installedMods[modID].Package == explicitPackage)
@@ -321,8 +309,7 @@ namespace OpenRA.FileSystem
if (parentPath.StartsWith("$", StringComparison.Ordinal))
{
- Manifest mod;
- if (!installedMods.TryGetValue(parentPath.Substring(1), out mod))
+ if (!installedMods.TryGetValue(parentPath.Substring(1), out var mod))
return null;
if (!(mod.Package is Folder))
diff --git a/OpenRA.Game/FileSystem/Folder.cs b/OpenRA.Game/FileSystem/Folder.cs
index ef05f80f3e..a258f88567 100644
--- a/OpenRA.Game/FileSystem/Folder.cs
+++ b/OpenRA.Game/FileSystem/Folder.cs
@@ -58,17 +58,15 @@ namespace OpenRA.FileSystem
return new Folder(resolvedPath);
// Zip files loaded from Folders (and *only* from Folders) can be read-write
- IReadWritePackage readWritePackage;
- if (ZipFileLoader.TryParseReadWritePackage(resolvedPath, out readWritePackage))
+ if (ZipFileLoader.TryParseReadWritePackage(resolvedPath, out var readWritePackage))
return readWritePackage;
// Other package types can be loaded normally
- IReadOnlyPackage package;
var s = GetStream(filename);
if (s == null)
return null;
- if (context.TryParsePackage(s, filename, out package))
+ if (context.TryParsePackage(s, filename, out var package))
return package;
s.Dispose();
diff --git a/OpenRA.Game/FileSystem/ZipFile.cs b/OpenRA.Game/FileSystem/ZipFile.cs
index 8baf451d00..63f7e365c6 100644
--- a/OpenRA.Game/FileSystem/ZipFile.cs
+++ b/OpenRA.Game/FileSystem/ZipFile.cs
@@ -81,12 +81,11 @@ namespace OpenRA.FileSystem
return new ZipFolder(this, filename);
// Other package types can be loaded normally
- IReadOnlyPackage package;
var s = GetStream(filename);
if (s == null)
return null;
- if (context.TryParsePackage(s, filename, out package))
+ if (context.TryParsePackage(s, filename, out var package))
return package;
s.Dispose();
diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs
index 0a1cdc7c26..e5a0e8c3fb 100644
--- a/OpenRA.Game/Game.cs
+++ b/OpenRA.Game/Game.cs
@@ -355,8 +355,7 @@ namespace OpenRA
ExternalMods = new ExternalMods();
- Manifest currentMod;
- if (modID != null && Mods.TryGetValue(modID, out currentMod))
+ if (modID != null && Mods.TryGetValue(modID, out var currentMod))
{
var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);
@@ -367,8 +366,7 @@ namespace OpenRA
ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);
- ExternalMod activeMod;
- if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out activeMod))
+ if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out var activeMod))
ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
}
diff --git a/OpenRA.Game/GameInformation.cs b/OpenRA.Game/GameInformation.cs
index 6291c65cd4..0ec409877d 100644
--- a/OpenRA.Game/GameInformation.cs
+++ b/OpenRA.Game/GameInformation.cs
@@ -133,9 +133,7 @@ namespace OpenRA
/// Gets the player information for the specified runtime player instance.
public Player GetPlayer(OpenRA.Player runtimePlayer)
{
- Player player;
-
- playersByRuntime.TryGetValue(runtimePlayer, out player);
+ playersByRuntime.TryGetValue(runtimePlayer, out var player);
return player;
}
diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs
index 726cd481f2..64714a6d69 100644
--- a/OpenRA.Game/GameRules/MusicInfo.cs
+++ b/OpenRA.Game/GameRules/MusicInfo.cs
@@ -41,8 +41,7 @@ namespace OpenRA.GameRules
public void Load(IReadOnlyFileSystem fileSystem)
{
- Stream stream;
- if (!fileSystem.TryOpen(Filename, out stream))
+ if (!fileSystem.TryOpen(Filename, out var stream))
return;
try
@@ -50,8 +49,7 @@ namespace OpenRA.GameRules
Exists = true;
foreach (var loader in Game.ModData.SoundLoaders)
{
- ISoundFormat soundFormat;
- if (loader.TryParseSound(stream, out soundFormat))
+ if (loader.TryParseSound(stream, out var soundFormat))
{
Length = (int)soundFormat.LengthInSeconds;
soundFormat.Dispose();
diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs
index f2f67e79cc..3193fc4c8e 100644
--- a/OpenRA.Game/GameRules/WeaponInfo.cs
+++ b/OpenRA.Game/GameRules/WeaponInfo.cs
@@ -137,8 +137,7 @@ namespace OpenRA.GameRules
static object LoadProjectile(MiniYaml yaml)
{
- MiniYaml proj;
- if (!yaml.ToDictionary().TryGetValue("Projectile", out proj))
+ if (!yaml.ToDictionary().TryGetValue("Projectile", out var proj))
return null;
var ret = Game.CreateObject(proj.Value + "Info");
FieldLoader.Load(ret, proj);
diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs
index aceb826bae..342ebbf8cc 100644
--- a/OpenRA.Game/Graphics/ChromeProvider.cs
+++ b/OpenRA.Game/Graphics/ChromeProvider.cs
@@ -160,8 +160,7 @@ namespace OpenRA.Graphics
return null;
}
- Rectangle mi;
- if (!collection.Regions.TryGetValue(imageName, out mi))
+ if (!collection.Regions.TryGetValue(imageName, out var mi))
return null;
// Cache the sprite
diff --git a/OpenRA.Game/Graphics/CursorSequence.cs b/OpenRA.Game/Graphics/CursorSequence.cs
index a6d105cb98..73b2ff3e52 100644
--- a/OpenRA.Game/Graphics/CursorSequence.cs
+++ b/OpenRA.Game/Graphics/CursorSequence.cs
@@ -47,15 +47,13 @@ namespace OpenRA.Graphics
if (d.ContainsKey("X"))
{
- int x;
- Exts.TryParseIntegerInvariant(d["X"].Value, out x);
+ Exts.TryParseIntegerInvariant(d["X"].Value, out var x);
Hotspot = Hotspot.WithX(x);
}
if (d.ContainsKey("Y"))
{
- int y;
- Exts.TryParseIntegerInvariant(d["Y"].Value, out y);
+ Exts.TryParseIntegerInvariant(d["Y"].Value, out var y);
Hotspot = Hotspot.WithY(y);
}
}
diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs
index c56f2ef958..60d050ea51 100644
--- a/OpenRA.Game/Graphics/HardwarePalette.cs
+++ b/OpenRA.Game/Graphics/HardwarePalette.cs
@@ -38,19 +38,16 @@ namespace OpenRA.Graphics
public IPalette GetPalette(string name)
{
- MutablePalette mutable;
- if (modifiablePalettes.TryGetValue(name, out mutable))
+ if (modifiablePalettes.TryGetValue(name, out var mutable))
return mutable.AsReadOnly();
- ImmutablePalette immutable;
- if (palettes.TryGetValue(name, out immutable))
+ if (palettes.TryGetValue(name, out var immutable))
return immutable;
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
}
public int GetPaletteIndex(string name)
{
- int ret;
- if (!indices.TryGetValue(name, out ret))
+ if (!indices.TryGetValue(name, out var ret))
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
return ret;
}
diff --git a/OpenRA.Game/Graphics/ModelRenderer.cs b/OpenRA.Game/Graphics/ModelRenderer.cs
index 5cb806e262..4d14775e1d 100644
--- a/OpenRA.Game/Graphics/ModelRenderer.cs
+++ b/OpenRA.Game/Graphics/ModelRenderer.cs
@@ -160,10 +160,8 @@ namespace OpenRA.Graphics
}
// Shadows are rendered at twice the resolution to reduce artifacts
- Size spriteSize, shadowSpriteSize;
- int2 spriteOffset, shadowSpriteOffset;
- CalculateSpriteGeometry(tl, br, 1, out spriteSize, out spriteOffset);
- CalculateSpriteGeometry(stl, sbr, 2, out shadowSpriteSize, out shadowSpriteOffset);
+ CalculateSpriteGeometry(tl, br, 1, out var spriteSize, out var spriteOffset);
+ CalculateSpriteGeometry(stl, sbr, 2, out var shadowSpriteSize, out var shadowSpriteOffset);
if (sheetBuilderForFrame == null)
sheetBuilderForFrame = new SheetBuilder(SheetType.BGRA, AllocateSheet);
diff --git a/OpenRA.Game/Graphics/PlayerColorRemap.cs b/OpenRA.Game/Graphics/PlayerColorRemap.cs
index 262ca8e7e4..714ff77314 100644
--- a/OpenRA.Game/Graphics/PlayerColorRemap.cs
+++ b/OpenRA.Game/Graphics/PlayerColorRemap.cs
@@ -53,8 +53,7 @@ namespace OpenRA.Graphics
public Color GetRemappedColor(Color original, int index)
{
- Color c;
- return remapColors.TryGetValue(index, out c)
+ return remapColors.TryGetValue(index, out var c)
? c : original;
}
}
diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs
index 0ee4698eac..2875c14f76 100644
--- a/OpenRA.Game/Graphics/SequenceProvider.cs
+++ b/OpenRA.Game/Graphics/SequenceProvider.cs
@@ -70,12 +70,10 @@ namespace OpenRA.Graphics
public ISpriteSequence GetSequence(string unitName, string sequenceName)
{
- UnitSequences unitSeq;
- if (!sequences.Value.TryGetValue(unitName, out unitSeq))
+ if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
- ISpriteSequence seq;
- if (!unitSeq.Value.TryGetValue(sequenceName, out seq))
+ if (!unitSeq.Value.TryGetValue(sequenceName, out var seq))
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
return seq;
@@ -88,8 +86,7 @@ namespace OpenRA.Graphics
public bool HasSequence(string unitName, string sequenceName)
{
- UnitSequences unitSeq;
- if (!sequences.Value.TryGetValue(unitName, out unitSeq))
+ if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
return unitSeq.Value.ContainsKey(sequenceName);
@@ -97,8 +94,7 @@ namespace OpenRA.Graphics
public IEnumerable Sequences(string unitName)
{
- UnitSequences unitSeq;
- if (!sequences.Value.TryGetValue(unitName, out unitSeq))
+ if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
return unitSeq.Value.Keys;
@@ -115,8 +111,7 @@ namespace OpenRA.Graphics
var key = node.Value.ToLines(node.Key).JoinWith("|");
- UnitSequences t;
- if (sequenceCache.TryGetValue(key, out t))
+ if (sequenceCache.TryGetValue(key, out var t))
items.Add(node.Key, t);
else
{
diff --git a/OpenRA.Game/Graphics/SpriteLoader.cs b/OpenRA.Game/Graphics/SpriteLoader.cs
index f8ac8d43da..db393b9d79 100644
--- a/OpenRA.Game/Graphics/SpriteLoader.cs
+++ b/OpenRA.Game/Graphics/SpriteLoader.cs
@@ -76,8 +76,7 @@ namespace OpenRA.Graphics
var allSprites = sprites.GetOrAdd(filename);
var sprite = allSprites.FirstOrDefault();
- ISpriteFrame[] unloaded;
- if (!unloadedFrames.TryGetValue(filename, out unloaded))
+ if (!unloadedFrames.TryGetValue(filename, out var unloaded))
unloaded = null;
// This is the first time that the file has been requested
@@ -85,8 +84,7 @@ namespace OpenRA.Graphics
// the loaded cache (initially empty)
if (sprite == null)
{
- TypeDictionary fileMetadata = null;
- unloaded = FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
+ unloaded = FrameLoader.GetFrames(fileSystem, filename, loaders, out var fileMetadata);
unloadedFrames[filename] = unloaded;
metadata[filename] = fileMetadata;
@@ -125,8 +123,7 @@ namespace OpenRA.Graphics
///
public TypeDictionary FrameMetadata(string filename)
{
- TypeDictionary fileMetadata;
- if (!metadata.TryGetValue(filename, out fileMetadata))
+ if (!metadata.TryGetValue(filename, out var fileMetadata))
{
FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
metadata[filename] = fileMetadata;
@@ -142,8 +139,7 @@ namespace OpenRA.Graphics
public FrameCache(IReadOnlyFileSystem fileSystem, ISpriteLoader[] loaders)
{
- TypeDictionary metadata;
- frames = new Cache(filename => FrameLoader.GetFrames(fileSystem, filename, loaders, out metadata));
+ frames = new Cache(filename => FrameLoader.GetFrames(fileSystem, filename, loaders, out var metadata));
}
public ISpriteFrame[] this[string filename] { get { return frames[filename]; } }
@@ -165,11 +161,10 @@ namespace OpenRA.Graphics
public static ISpriteFrame[] GetFrames(Stream stream, ISpriteLoader[] loaders, out TypeDictionary metadata)
{
- ISpriteFrame[] frames;
metadata = null;
foreach (var loader in loaders)
- if (loader.TryParseSprite(stream, out frames, out metadata))
+ if (loader.TryParseSprite(stream, out var frames, out metadata))
return frames;
return null;
diff --git a/OpenRA.Game/Graphics/Theater.cs b/OpenRA.Game/Graphics/Theater.cs
index af4a2ecc6a..e556466ab1 100644
--- a/OpenRA.Game/Graphics/Theater.cs
+++ b/OpenRA.Game/Graphics/Theater.cs
@@ -118,8 +118,7 @@ namespace OpenRA.Graphics
public Sprite TileSprite(TerrainTile r, int? variant = null)
{
- TheaterTemplate template;
- if (!templates.TryGetValue(r.Type, out template))
+ if (!templates.TryGetValue(r.Type, out var template))
return missingTile;
if (r.Index >= template.Stride)
diff --git a/OpenRA.Game/HotkeyManager.cs b/OpenRA.Game/HotkeyManager.cs
index 8d52221c41..392d16971f 100644
--- a/OpenRA.Game/HotkeyManager.cs
+++ b/OpenRA.Game/HotkeyManager.cs
@@ -50,8 +50,7 @@ namespace OpenRA
return () => keys[name];
// Try and parse as a hardcoded definition
- Hotkey key;
- if (!Hotkey.TryParse(name, out key))
+ if (!Hotkey.TryParse(name, out var key))
key = Hotkey.Invalid;
return () => key;
@@ -59,8 +58,7 @@ namespace OpenRA
public void Set(string name, Hotkey value)
{
- HotkeyDefinition definition;
- if (!definitions.TryGetValue(name, out definition))
+ if (!definitions.TryGetValue(name, out var definition))
return;
keys[name] = value;
diff --git a/OpenRA.Game/Input/Hotkey.cs b/OpenRA.Game/Input/Hotkey.cs
index 83fa9e1996..4264ae86be 100644
--- a/OpenRA.Game/Input/Hotkey.cs
+++ b/OpenRA.Game/Input/Hotkey.cs
@@ -32,11 +32,9 @@ namespace OpenRA
var parts = s.Split(' ');
- Keycode key;
- if (!Enum.TryParse(parts[0], true, out key))
+ if (!Enum.TryParse(parts[0], true, out var key))
{
- int c;
- if (!int.TryParse(parts[0], out c))
+ if (!int.TryParse(parts[0], out var c))
return false;
key = (Keycode)c;
}
diff --git a/OpenRA.Game/Input/Keycode.cs b/OpenRA.Game/Input/Keycode.cs
index 9e046efde4..77a7377726 100644
--- a/OpenRA.Game/Input/Keycode.cs
+++ b/OpenRA.Game/Input/Keycode.cs
@@ -498,8 +498,7 @@ namespace OpenRA
public static string DisplayString(Keycode k)
{
- string ret;
- if (!KeyNames.TryGetValue(k, out ret))
+ if (!KeyNames.TryGetValue(k, out var ret))
return k.ToString();
return ret;
diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs
index fc1ed2b4ca..67977d6a1e 100644
--- a/OpenRA.Game/Manifest.cs
+++ b/OpenRA.Game/Manifest.cs
@@ -96,8 +96,7 @@ namespace OpenRA
// TODO: Use fieldloader
MapFolders = YamlDictionary(yaml, "MapFolders");
- MiniYaml packages;
- if (yaml.TryGetValue("Packages", out packages))
+ if (yaml.TryGetValue("Packages", out var packages))
Packages = packages.ToDictionary(x => x.Value).AsReadOnly();
Rules = YamlList(yaml, "Rules");
@@ -217,9 +216,8 @@ namespace OpenRA
///
public T Get(ObjectCreator oc) where T : IGlobalModData
{
- MiniYaml data;
var t = typeof(T);
- if (!yaml.TryGetValue(t.Name, out data))
+ if (!yaml.TryGetValue(t.Name, out var data))
{
// Lazily create the default values if not explicitly defined.
return (T)oc.CreateBasic(t);
diff --git a/OpenRA.Game/Map/ActorInitializer.cs b/OpenRA.Game/Map/ActorInitializer.cs
index 1d4f22e3e4..20b3dadac6 100644
--- a/OpenRA.Game/Map/ActorInitializer.cs
+++ b/OpenRA.Game/Map/ActorInitializer.cs
@@ -185,14 +185,13 @@ namespace OpenRA
public virtual void Initialize(Dictionary values)
{
- object value;
foreach (var field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
var sa = field.GetCustomAttributes(false).DefaultIfEmpty(FieldLoader.SerializeAttribute.Default).First();
if (!sa.Serialize)
continue;
- if (values.TryGetValue(field.Name, out value))
+ if (values.TryGetValue(field.Name, out var value))
field.SetValue(this, value);
}
}
diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs
index 3a3d29cfef..aa5af91538 100644
--- a/OpenRA.Game/Map/MapCache.cs
+++ b/OpenRA.Game/Map/MapCache.cs
@@ -131,8 +131,7 @@ namespace OpenRA
// Enumerate map directories
foreach (var kv in modData.Manifest.MapFolders)
{
- MapClassification packageClassification;
- if (!Enum.TryParse(kv.Value, out packageClassification))
+ if (!Enum.TryParse(kv.Value, out MapClassification packageClassification))
continue;
if (!classification.HasFlag(packageClassification))
diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs
index 3320384eec..b56e42c152 100644
--- a/OpenRA.Game/Map/MapPreview.cs
+++ b/OpenRA.Game/Map/MapPreview.cs
@@ -233,8 +233,7 @@ namespace OpenRA
newData.GridType = gridType;
newData.Class = classification;
- MiniYaml temp;
- if (yaml.TryGetValue("MapFormat", out temp))
+ if (yaml.TryGetValue("MapFormat", out var temp))
{
var format = FieldLoader.GetValue("MapFormat", temp.Value);
if (format != Map.SupportedMapFormat)
@@ -269,8 +268,7 @@ namespace OpenRA
try
{
// Actor definitions may change if the map format changes
- MiniYaml actorDefinitions;
- if (yaml.TryGetValue("Actors", out actorDefinitions))
+ if (yaml.TryGetValue("Actors", out var actorDefinitions))
{
var spawns = new List();
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
@@ -293,8 +291,7 @@ namespace OpenRA
try
{
// Player definitions may change if the map format changes
- MiniYaml playerDefinitions;
- if (yaml.TryGetValue("Players", out playerDefinitions))
+ if (yaml.TryGetValue("Players", out var playerDefinitions))
{
newData.Players = new MapPlayers(playerDefinitions.Nodes);
newData.PlayerCount = newData.Players.Players.Count(x => x.Value.Playable);
@@ -331,8 +328,7 @@ namespace OpenRA
MiniYaml LoadRuleSection(Dictionary yaml, string section)
{
- MiniYaml node;
- if (!yaml.TryGetValue(section, out node))
+ if (!yaml.TryGetValue(section, out var node))
return null;
return node;
diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs
index fae2f938b1..72b0e55688 100644
--- a/OpenRA.Game/Map/TileSet.cs
+++ b/OpenRA.Game/Map/TileSet.cs
@@ -72,8 +72,7 @@ namespace OpenRA
tileInfo = new TerrainTileInfo[Size.X * Size.Y];
foreach (var node in nodes)
{
- int key;
- if (!int.TryParse(node.Key, out key) || key < 0 || key >= tileInfo.Length)
+ if (!int.TryParse(node.Key, out var key) || key < 0 || key >= tileInfo.Length)
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
@@ -86,8 +85,7 @@ namespace OpenRA
var i = 0;
foreach (var node in nodes)
{
- int key;
- if (!int.TryParse(node.Key, out key) || key != i++)
+ if (!int.TryParse(node.Key, out var key) || key != i++)
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
@@ -216,8 +214,7 @@ namespace OpenRA
public byte GetTerrainIndex(string type)
{
- byte index;
- if (terrainIndexByType.TryGetValue(type, out index))
+ if (terrainIndexByType.TryGetValue(type, out var index))
return index;
throw new InvalidDataException("Tileset '{0}' lacks terrain type '{1}'".F(Id, type));
@@ -225,8 +222,7 @@ namespace OpenRA
public byte GetTerrainIndex(TerrainTile r)
{
- TerrainTemplateInfo tpl;
- if (!Templates.TryGetValue(r.Type, out tpl))
+ if (!Templates.TryGetValue(r.Type, out var tpl))
return defaultWalkableTerrainIndex;
if (tpl.Contains(r.Index))
@@ -241,8 +237,7 @@ namespace OpenRA
public TerrainTileInfo GetTileInfo(TerrainTile r)
{
- TerrainTemplateInfo tpl;
- if (!Templates.TryGetValue(r.Type, out tpl))
+ if (!Templates.TryGetValue(r.Type, out var tpl))
return null;
return tpl.Contains(r.Index) ? tpl[r.Index] : null;
diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs
index 6419bf33db..f775de241d 100644
--- a/OpenRA.Game/MiniYaml.cs
+++ b/OpenRA.Game/MiniYaml.cs
@@ -339,8 +339,7 @@ namespace OpenRA
{
if (n.Key == "Inherits" || n.Key.StartsWith("Inherits@", StringComparison.Ordinal))
{
- MiniYaml parent;
- if (!tree.TryGetValue(n.Value.Value, out parent))
+ if (!tree.TryGetValue(n.Value.Value, out var parent))
throw new YamlException(
"{0}: Parent type `{1}` not found".F(n.Location, n.Value.Value));
@@ -428,9 +427,8 @@ namespace OpenRA
foreach (var key in allKeys)
{
- MiniYamlNode existingNode, overrideNode;
- existingDict.TryGetValue(key, out existingNode);
- overrideDict.TryGetValue(key, out overrideNode);
+ existingDict.TryGetValue(key, out var existingNode);
+ overrideDict.TryGetValue(key, out var overrideNode);
var loc = overrideNode == null ? default(MiniYamlNode.SourceLocation) : overrideNode.Location;
var comment = (overrideNode ?? existingNode).Comment;
diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs
index d810a76739..e442d1e60c 100644
--- a/OpenRA.Game/Network/GameServer.cs
+++ b/OpenRA.Game/Network/GameServer.cs
@@ -167,28 +167,22 @@ namespace OpenRA.Network
// Games advertised using the old API calculated the play time locally
if (State == 2 && PlayTime < 0)
- {
- DateTime startTime;
- if (DateTime.TryParse(Started, out startTime))
+ if (DateTime.TryParse(Started, out var startTime))
PlayTime = (int)(DateTime.UtcNow - startTime).TotalSeconds;
- }
- ExternalMod external;
var externalKey = ExternalMod.MakeKey(Mod, Version);
- if (Game.ExternalMods.TryGetValue(externalKey, out external) && external.Version == Version)
+ if (Game.ExternalMods.TryGetValue(externalKey, out var external) && external.Version == Version)
IsCompatible = true;
// Games advertised using the old API used local mod metadata
if (string.IsNullOrEmpty(ModTitle))
{
- Manifest mod;
-
if (external != null && external.Version == Version)
{
// Use external mod registration to populate the section header
ModTitle = external.Title;
}
- else if (Game.Mods.TryGetValue(Mod, out mod))
+ else if (Game.Mods.TryGetValue(Mod, out var mod))
{
// Use internal mod data to populate the section header, but
// on-connect switching must use the external mod plumbing.
diff --git a/OpenRA.Game/Network/Order.cs b/OpenRA.Game/Network/Order.cs
index 23222649c9..5b891f7759 100644
--- a/OpenRA.Game/Network/Order.cs
+++ b/OpenRA.Game/Network/Order.cs
@@ -107,8 +107,7 @@ namespace OpenRA
{
case TargetType.Actor:
{
- Actor targetActor;
- if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out targetActor))
+ if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out var targetActor))
target = Target.FromActor(targetActor);
break;
}
@@ -118,8 +117,7 @@ namespace OpenRA
var playerActorID = r.ReadUInt32();
var frozenActorID = r.ReadUInt32();
- Actor playerActor;
- if (world == null || !TryGetActorFromUInt(world, playerActorID, out playerActor))
+ if (world == null || !TryGetActorFromUInt(world, playerActorID, out var playerActor))
break;
if (playerActor.Owner.FrozenActorLayer == null)
diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs
index 82609f6b92..8c2aed63a7 100644
--- a/OpenRA.Game/Network/OrderManager.cs
+++ b/OpenRA.Game/Network/OrderManager.cs
@@ -149,8 +149,7 @@ namespace OpenRA.Network
void CheckSync(byte[] packet)
{
var frame = BitConverter.ToInt32(packet, 0);
- byte[] existingSync;
- if (syncForFrame.TryGetValue(frame, out existingSync))
+ if (syncForFrame.TryGetValue(frame, out var existingSync))
{
if (packet.Length != existingSync.Length)
OutOfSync(frame);
diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs
index 0c52d0d61b..0db45b31dc 100644
--- a/OpenRA.Game/Network/Session.cs
+++ b/OpenRA.Game/Network/Session.cs
@@ -250,8 +250,7 @@ namespace OpenRA.Network
public bool OptionOrDefault(string id, bool def)
{
- LobbyOptionState option;
- if (LobbyOptions.TryGetValue(id, out option))
+ if (LobbyOptions.TryGetValue(id, out var option))
return option.IsEnabled;
return def;
@@ -259,8 +258,7 @@ namespace OpenRA.Network
public string OptionOrDefault(string id, string def)
{
- LobbyOptionState option;
- if (LobbyOptions.TryGetValue(id, out option))
+ if (LobbyOptions.TryGetValue(id, out var option))
return option.Value;
return def;
diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs
index 716223fe62..cb80a3f0e8 100644
--- a/OpenRA.Game/Network/UnitOrders.cs
+++ b/OpenRA.Game/Network/UnitOrders.cs
@@ -190,9 +190,8 @@ namespace OpenRA.Network
var request = HandshakeRequest.Deserialize(order.TargetString);
var externalKey = ExternalMod.MakeKey(request.Mod, request.Version);
- ExternalMod external;
- if ((request.Mod != mod.Id || request.Version != mod.Metadata.Version)
- && Game.ExternalMods.TryGetValue(externalKey, out external))
+ if ((request.Mod != mod.Id || request.Version != mod.Metadata.Version) &&
+ Game.ExternalMods.TryGetValue(externalKey, out var external))
{
// The ConnectionFailedLogic will prompt the user to switch mods
orderManager.ServerExternalMod = external;
diff --git a/OpenRA.Game/ObjectCreator.cs b/OpenRA.Game/ObjectCreator.cs
index 8ffb0be529..4a8328667f 100644
--- a/OpenRA.Game/ObjectCreator.cs
+++ b/OpenRA.Game/ObjectCreator.cs
@@ -48,8 +48,7 @@ namespace OpenRA
// We can't check the internal name of the assembly, so we'll work off the data instead
var hash = CryptoUtil.SHA1Hash(File.ReadAllBytes(resolvedPath));
- Assembly assembly;
- if (!ResolvedAssemblies.TryGetValue(hash, out assembly))
+ if (!ResolvedAssemblies.TryGetValue(hash, out var assembly))
{
assembly = Assembly.LoadFile(resolvedPath);
ResolvedAssemblies.Add(hash, assembly);
diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs
index 165792c055..b5b6a22d65 100644
--- a/OpenRA.Game/Player.cs
+++ b/OpenRA.Game/Player.cs
@@ -253,8 +253,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- Player a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out Player a) || !right.TryGetClrValue(out Player b))
return false;
return a == b;
diff --git a/OpenRA.Game/Primitives/BitSet.cs b/OpenRA.Game/Primitives/BitSet.cs
index a10451ac3c..da34b5bf9b 100644
--- a/OpenRA.Game/Primitives/BitSet.cs
+++ b/OpenRA.Game/Primitives/BitSet.cs
@@ -47,14 +47,9 @@ namespace OpenRA.Primitives
BitSetIndex bits = 0;
lock (Bits)
- {
foreach (var value in values)
- {
- BitSetIndex valueBit;
- if (Bits.TryGetValue(value, out valueBit))
+ if (Bits.TryGetValue(value, out var valueBit))
bits |= valueBit;
- }
- }
return bits;
}
diff --git a/OpenRA.Game/Primitives/Color.cs b/OpenRA.Game/Primitives/Color.cs
index f01b75c0ea..def4ab341b 100644
--- a/OpenRA.Game/Primitives/Color.cs
+++ b/OpenRA.Game/Primitives/Color.cs
@@ -124,10 +124,10 @@ namespace OpenRA.Primitives
if (value.Length != 6 && value.Length != 8)
return false;
- byte red, green, blue, alpha = 255;
- if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out red)
- || !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out green)
- || !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out blue))
+ byte alpha = 255;
+ if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var red)
+ || !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var green)
+ || !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var blue))
return false;
if (value.Length == 8
diff --git a/OpenRA.Game/Primitives/LongBitSet.cs b/OpenRA.Game/Primitives/LongBitSet.cs
index 4ca81ada4c..74f48dd38a 100644
--- a/OpenRA.Game/Primitives/LongBitSet.cs
+++ b/OpenRA.Game/Primitives/LongBitSet.cs
@@ -50,14 +50,9 @@ namespace OpenRA.Primitives
long bits = 0;
lock (Bits)
- {
foreach (var value in values)
- {
- long valueBit;
- if (Bits.TryGetValue(value, out valueBit))
+ if (Bits.TryGetValue(value, out var valueBit))
bits |= valueBit;
- }
- }
return bits;
}
diff --git a/OpenRA.Game/Primitives/SegmentStream.cs b/OpenRA.Game/Primitives/SegmentStream.cs
index beef1ccc34..66080af01a 100644
--- a/OpenRA.Game/Primitives/SegmentStream.cs
+++ b/OpenRA.Game/Primitives/SegmentStream.cs
@@ -120,8 +120,7 @@ namespace OpenRA.Primitives
/// The length of the segment.
public static Stream CreateWithoutOwningStream(Stream stream, long offset, int count)
{
- Stream parentStream;
- var nestedOffset = offset + GetOverallNestedOffset(stream, out parentStream);
+ var nestedOffset = offset + GetOverallNestedOffset(stream, out var parentStream);
// Special case FileStream - instead of creating an in-memory copy,
// just reference the portion of the on-disk file that we need to save memory.
diff --git a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs
index af8d467066..9732da0eff 100644
--- a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs
+++ b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs
@@ -52,8 +52,7 @@ namespace OpenRA.Primitives
public bool Remove(T item)
{
- Rectangle bounds;
- if (!itemBounds.TryGetValue(item, out bounds))
+ if (!itemBounds.TryGetValue(item, out var bounds))
return false;
MutateBins(item, bounds, removeItem);
@@ -91,8 +90,7 @@ namespace OpenRA.Primitives
void MutateBins(T actor, Rectangle bounds, Action, T, Rectangle> action)
{
- int minRow, maxRow, minCol, maxCol;
- BoundsToBinRowsAndCols(bounds, out minRow, out maxRow, out minCol, out maxCol);
+ BoundsToBinRowsAndCols(bounds, out var minRow, out var maxRow, out var minCol, out var maxCol);
for (var row = minRow; row < maxRow; row++)
for (var col = minCol; col < maxCol; col++)
@@ -110,8 +108,7 @@ namespace OpenRA.Primitives
public IEnumerable InBox(Rectangle box)
{
- int minRow, maxRow, minCol, maxCol;
- BoundsToBinRowsAndCols(box, out minRow, out maxRow, out minCol, out maxCol);
+ BoundsToBinRowsAndCols(box, out var minRow, out var maxRow, out var minCol, out var maxCol);
// We want to return any items intersecting the box.
// If the box covers multiple bins, we must handle items that are contained in multiple bins and avoid
diff --git a/OpenRA.Game/Primitives/TypeDictionary.cs b/OpenRA.Game/Primitives/TypeDictionary.cs
index 04d7b5d7ed..f4e960224b 100644
--- a/OpenRA.Game/Primitives/TypeDictionary.cs
+++ b/OpenRA.Game/Primitives/TypeDictionary.cs
@@ -61,8 +61,7 @@ namespace OpenRA.Primitives
object Get(Type t, bool throwsIfMissing)
{
- List ret;
- if (!data.TryGetValue(t, out ret))
+ if (!data.TryGetValue(t, out var ret))
{
if (throwsIfMissing)
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(t));
@@ -76,8 +75,7 @@ namespace OpenRA.Primitives
public IEnumerable WithInterface()
{
- List objs;
- if (data.TryGetValue(typeof(T), out objs))
+ if (data.TryGetValue(typeof(T), out var objs))
return objs.Cast();
return new T[0];
}
@@ -94,8 +92,7 @@ namespace OpenRA.Primitives
void InnerRemove(Type t, object val)
{
- List objs;
- if (!data.TryGetValue(t, out objs))
+ if (!data.TryGetValue(t, out var objs))
return;
objs.Remove(val);
if (objs.Count == 0)
diff --git a/OpenRA.Game/Scripting/ScriptMemberExts.cs b/OpenRA.Game/Scripting/ScriptMemberExts.cs
index 7a9313a97e..8500a04206 100644
--- a/OpenRA.Game/Scripting/ScriptMemberExts.cs
+++ b/OpenRA.Game/Scripting/ScriptMemberExts.cs
@@ -28,8 +28,7 @@ namespace OpenRA.Scripting
public static string LuaDocString(this Type t)
{
- string ret;
- if (!LuaTypeNameReplacements.TryGetValue(t.Name, out ret))
+ if (!LuaTypeNameReplacements.TryGetValue(t.Name, out var ret))
ret = t.Name;
return ret;
}
diff --git a/OpenRA.Game/Scripting/ScriptMemberWrapper.cs b/OpenRA.Game/Scripting/ScriptMemberWrapper.cs
index bb61a5d4f1..5bc1d6aab2 100644
--- a/OpenRA.Game/Scripting/ScriptMemberWrapper.cs
+++ b/OpenRA.Game/Scripting/ScriptMemberWrapper.cs
@@ -111,8 +111,7 @@ namespace OpenRA.Scripting
if (IsSetProperty)
{
var pi = (PropertyInfo)Member;
- object clrValue;
- if (!value.TryGetClrValue(pi.PropertyType, out clrValue))
+ if (!value.TryGetClrValue(pi.PropertyType, out var clrValue))
throw new LuaException("Unable to convert '{0}' to Clr type '{1}'".F(value.WrappedClrType().Name, pi.PropertyType));
pi.SetValue(Target, clrValue, null);
diff --git a/OpenRA.Game/Scripting/ScriptObjectWrapper.cs b/OpenRA.Game/Scripting/ScriptObjectWrapper.cs
index f10c80f581..7a8b03dac2 100644
--- a/OpenRA.Game/Scripting/ScriptObjectWrapper.cs
+++ b/OpenRA.Game/Scripting/ScriptObjectWrapper.cs
@@ -51,8 +51,7 @@ namespace OpenRA.Scripting
get
{
var name = keyValue.ToString();
- ScriptMemberWrapper wrapper;
- if (!members.TryGetValue(name, out wrapper))
+ if (!members.TryGetValue(name, out var wrapper))
throw new LuaException(MemberNotFoundError(name));
return wrapper.Get(runtime);
@@ -61,8 +60,7 @@ namespace OpenRA.Scripting
set
{
var name = keyValue.ToString();
- ScriptMemberWrapper wrapper;
- if (!members.TryGetValue(name, out wrapper))
+ if (!members.TryGetValue(name, out var wrapper))
throw new LuaException(MemberNotFoundError(name));
wrapper.Set(runtime, value);
diff --git a/OpenRA.Game/Scripting/ScriptTypes.cs b/OpenRA.Game/Scripting/ScriptTypes.cs
index ebbabba9b2..e66cbbe088 100644
--- a/OpenRA.Game/Scripting/ScriptTypes.cs
+++ b/OpenRA.Game/Scripting/ScriptTypes.cs
@@ -18,8 +18,7 @@ namespace OpenRA.Scripting
{
public static Type WrappedClrType(this LuaValue value)
{
- object inner;
- if (value.TryGetClrObject(out inner))
+ if (value.TryGetClrObject(out var inner))
return inner.GetType();
return value.GetType();
@@ -27,16 +26,13 @@ namespace OpenRA.Scripting
public static bool TryGetClrValue(this LuaValue value, out T clrObject)
{
- object temp;
- var ret = value.TryGetClrValue(typeof(T), out temp);
+ var ret = value.TryGetClrValue(typeof(T), out object temp);
clrObject = ret ? (T)temp : default(T);
return ret;
}
public static bool TryGetClrValue(this LuaValue value, Type t, out object clrObject)
{
- object temp;
-
// Is t a nullable?
// If yes, get the underlying type
var nullable = Nullable.GetUnderlyingType(t);
@@ -44,7 +40,7 @@ namespace OpenRA.Scripting
t = nullable;
// Value wraps a CLR object
- if (value.TryGetClrObject(out temp))
+ if (value.TryGetClrObject(out var temp))
{
if (temp.GetType() == t)
{
diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs
index ccc5e801f8..5f3af39106 100644
--- a/OpenRA.Game/Server/Server.cs
+++ b/OpenRA.Game/Server/Server.cs
@@ -99,8 +99,7 @@ namespace OpenRA.Server
// Non-blocking sends are free to send only part of the data
while (start < length)
{
- SocketError error;
- var sent = s.Send(data, start, length - start, SocketFlags.None, out error);
+ var sent = s.Send(data, start, length - start, SocketFlags.None, out var error);
if (error == SocketError.WouldBlock)
{
Log.Write("server", "Non-blocking send of {0} bytes failed. Falling back to blocking send.", length - start);
@@ -716,8 +715,7 @@ namespace OpenRA.Server
break;
case "Pong":
{
- long pingSent;
- if (!OpenRA.Exts.TryParseInt64Invariant(o.TargetString, out pingSent))
+ if (!OpenRA.Exts.TryParseInt64Invariant(o.TargetString, out var pingSent))
{
Log.Write("server", "Invalid order pong payload: {0}", o.TargetString);
break;
diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs
index 4c36230770..ccbb3700d2 100644
--- a/OpenRA.Game/Settings.cs
+++ b/OpenRA.Game/Settings.cs
@@ -295,8 +295,7 @@ namespace OpenRA
yamlCache = MiniYaml.FromFile(settingsFile, false);
foreach (var yamlSection in yamlCache)
{
- object settingsSection;
- if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out settingsSection))
+ if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out var settingsSection))
LoadSectionYaml(yamlSection.Value, settingsSection);
}
diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs
index a05b481ea3..15d3fa67c1 100644
--- a/OpenRA.Game/Sound/Sound.cs
+++ b/OpenRA.Game/Sound/Sound.cs
@@ -66,11 +66,10 @@ namespace OpenRA
using (var stream = fileSystem.Open(filename))
{
- ISoundFormat soundFormat;
foreach (var loader in loaders)
{
stream.Position = 0;
- if (loader.TryParseSound(stream, out soundFormat))
+ if (loader.TryParseSound(stream, out var soundFormat))
{
var source = loadFormat(soundFormat);
soundFormat.Dispose();
diff --git a/OpenRA.Game/Support/VariableExpression.cs b/OpenRA.Game/Support/VariableExpression.cs
index 9d1e74d40a..9224a59213 100644
--- a/OpenRA.Game/Support/VariableExpression.cs
+++ b/OpenRA.Game/Support/VariableExpression.cs
@@ -668,8 +668,7 @@ namespace OpenRA.Support
static int ParseSymbol(string symbol, IReadOnlyDictionary symbols)
{
- int value;
- symbols.TryGetValue(symbol, out value);
+ symbols.TryGetValue(symbol, out var value);
return value;
}
diff --git a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs
index 135f3c2ea0..1ac00b385e 100644
--- a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs
+++ b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs
@@ -310,8 +310,7 @@ namespace OpenRA.Traits
public FrozenActor FromID(uint id)
{
- FrozenActor fa;
- if (!frozenActorsById.TryGetValue(id, out fa))
+ if (!frozenActorsById.TryGetValue(id, out var fa))
return null;
return fa;
diff --git a/OpenRA.Game/Traits/Player/Shroud.cs b/OpenRA.Game/Traits/Player/Shroud.cs
index a69ce2315b..731624062e 100644
--- a/OpenRA.Game/Traits/Player/Shroud.cs
+++ b/OpenRA.Game/Traits/Player/Shroud.cs
@@ -253,8 +253,7 @@ namespace OpenRA.Traits
public void RemoveSource(object key)
{
- ShroudSource state;
- if (!sources.TryGetValue(key, out state))
+ if (!sources.TryGetValue(key, out var state))
return;
foreach (var puv in state.ProjectedCells)
diff --git a/OpenRA.Game/WAngle.cs b/OpenRA.Game/WAngle.cs
index c092785299..d38e91d86c 100644
--- a/OpenRA.Game/WAngle.cs
+++ b/OpenRA.Game/WAngle.cs
@@ -221,19 +221,16 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WAngle a, b;
- int c;
-
- if (!left.TryGetClrValue(out a))
+ if (!left.TryGetClrValue(out WAngle a))
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
- if (right.TryGetClrValue(out c))
+ if (right.TryGetClrValue(out int c))
{
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
return new LuaCustomClrObject(a + FromFacing(c));
}
- if (right.TryGetClrValue(out b))
+ if (right.TryGetClrValue(out WAngle b))
return new LuaCustomClrObject(a + b);
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
@@ -241,19 +238,16 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WAngle a, b;
- int c;
-
- if (!left.TryGetClrValue(out a))
+ if (!left.TryGetClrValue(out WAngle a))
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
- if (right.TryGetClrValue(out c))
+ if (right.TryGetClrValue(out int c))
{
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
return new LuaCustomClrObject(a - FromFacing(c));
}
- if (right.TryGetClrValue(out b))
+ if (right.TryGetClrValue(out WAngle b))
return new LuaCustomClrObject(a - b);
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
@@ -261,8 +255,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WAngle a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WAngle a) || !right.TryGetClrValue(out WAngle b))
return false;
return a == b;
diff --git a/OpenRA.Game/WDist.cs b/OpenRA.Game/WDist.cs
index af90846353..d19218be05 100644
--- a/OpenRA.Game/WDist.cs
+++ b/OpenRA.Game/WDist.cs
@@ -114,9 +114,7 @@ namespace OpenRA
#region Scripting interface
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WDist a;
- WDist b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
throw new LuaException("Attempted to call WDist.Add(WDist, WDist) with invalid arguments.");
return new LuaCustomClrObject(a + b);
@@ -124,9 +122,7 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WDist a;
- WDist b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
throw new LuaException("Attempted to call WDist.Subtract(WDist, WDist) with invalid arguments.");
return new LuaCustomClrObject(a - b);
@@ -134,9 +130,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WDist a;
- WDist b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
throw new LuaException("Attempted to call WDist.Equals(WDist, WDist) with invalid arguments.");
return a == b;
diff --git a/OpenRA.Game/WPos.cs b/OpenRA.Game/WPos.cs
index a0571a8b61..d879a9d938 100644
--- a/OpenRA.Game/WPos.cs
+++ b/OpenRA.Game/WPos.cs
@@ -82,9 +82,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WPos a;
- WVec b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WPos a) || !right.TryGetClrValue(out WVec b))
throw new LuaException("Attempted to call WPos.Add(WPos, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -92,21 +90,18 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WPos a;
var rightType = right.WrappedClrType();
- if (!left.TryGetClrValue(out a))
+ if (!left.TryGetClrValue(out WPos a))
throw new LuaException("Attempted to call WPos.Subtract(WPos, (WPos|WVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
if (rightType == typeof(WPos))
{
- WPos b;
- right.TryGetClrValue(out b);
+ right.TryGetClrValue(out WPos b);
return new LuaCustomClrObject(a - b);
}
else if (rightType == typeof(WVec))
{
- WVec b;
- right.TryGetClrValue(out b);
+ right.TryGetClrValue(out WVec b);
return new LuaCustomClrObject(a - b);
}
@@ -115,8 +110,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WPos a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WPos a) || !right.TryGetClrValue(out WPos b))
return false;
return a == b;
diff --git a/OpenRA.Game/WRot.cs b/OpenRA.Game/WRot.cs
index fa7300d59a..cf79184638 100644
--- a/OpenRA.Game/WRot.cs
+++ b/OpenRA.Game/WRot.cs
@@ -158,8 +158,7 @@ namespace OpenRA
public Int32Matrix4x4 AsMatrix()
{
- Int32Matrix4x4 mtx;
- AsMatrix(out mtx);
+ AsMatrix(out var mtx);
return mtx;
}
diff --git a/OpenRA.Game/WVec.cs b/OpenRA.Game/WVec.cs
index cb4cbce63e..1a449d70a0 100644
--- a/OpenRA.Game/WVec.cs
+++ b/OpenRA.Game/WVec.cs
@@ -46,8 +46,7 @@ namespace OpenRA
public WVec Rotate(WRot rot)
{
- Int32Matrix4x4 mtx;
- rot.AsMatrix(out mtx);
+ rot.AsMatrix(out var mtx);
return Rotate(ref mtx);
}
@@ -111,8 +110,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WVec a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
throw new LuaException("Attempted to call WVec.Add(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -120,8 +118,7 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WVec a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
throw new LuaException("Attempted to call WVec.Subtract(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a - b);
@@ -134,8 +131,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
- WVec a, b;
- if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
+ if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
return false;
return a == b;
diff --git a/OpenRA.Game/Widgets/ChromeMetrics.cs b/OpenRA.Game/Widgets/ChromeMetrics.cs
index 7bcaf45e6d..553ff42bb0 100644
--- a/OpenRA.Game/Widgets/ChromeMetrics.cs
+++ b/OpenRA.Game/Widgets/ChromeMetrics.cs
@@ -35,8 +35,7 @@ namespace OpenRA.Widgets
public static bool TryGet(string key, out T result)
{
- string s;
- if (!data.TryGetValue(key, out s))
+ if (!data.TryGetValue(key, out var s))
{
result = default(T);
return false;
diff --git a/OpenRA.Game/Widgets/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs
index c0f3be368f..292ea3e5d1 100644
--- a/OpenRA.Game/Widgets/WidgetLoader.cs
+++ b/OpenRA.Game/Widgets/WidgetLoader.cs
@@ -37,8 +37,7 @@ namespace OpenRA
public Widget LoadWidget(WidgetArgs args, Widget parent, string w)
{
- MiniYamlNode ret;
- if (!widgets.TryGetValue(w, out ret))
+ if (!widgets.TryGetValue(w, out var ret))
throw new InvalidDataException("Cannot find widget with Id `{0}`".F(w));
return LoadWidget(args, parent, ret);
diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs
index 4c34c8d83e..c964317fea 100644
--- a/OpenRA.Game/World.cs
+++ b/OpenRA.Game/World.cs
@@ -486,8 +486,7 @@ namespace OpenRA
public Actor GetActorById(uint actorId)
{
- Actor a;
- if (actors.TryGetValue(actorId, out a))
+ if (actors.TryGetValue(actorId, out var a))
return a;
return null;
}
diff --git a/OpenRA.Mods.Cnc/Activities/LeapAttack.cs b/OpenRA.Mods.Cnc/Activities/LeapAttack.cs
index 15802d7a7d..dfeba82da7 100644
--- a/OpenRA.Mods.Cnc/Activities/LeapAttack.cs
+++ b/OpenRA.Mods.Cnc/Activities/LeapAttack.cs
@@ -80,8 +80,7 @@ namespace OpenRA.Mods.Cnc.Activities
if (IsCanceling)
return true;
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{
lastVisibleTarget = Target.FromTargetPositions(target);
diff --git a/OpenRA.Mods.Cnc/AudioLoaders/VocLoader.cs b/OpenRA.Mods.Cnc/AudioLoaders/VocLoader.cs
index ccb7f4135c..ba64eb9a9e 100644
--- a/OpenRA.Mods.Cnc/AudioLoaders/VocLoader.cs
+++ b/OpenRA.Mods.Cnc/AudioLoaders/VocLoader.cs
@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
this.stream = stream;
CheckVocHeader(stream);
- int sampleRate;
- Preload(stream, out blocks, out totalSamples, out sampleRate);
+ Preload(stream, out blocks, out totalSamples, out var sampleRate);
SampleRate = sampleRate;
Rewind();
}
diff --git a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs
index 0056b81c5c..a7954dd35f 100644
--- a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs
+++ b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs
@@ -48,10 +48,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
List entries;
if (isEncrypted)
- {
- long unused;
- entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused);
- }
+ entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out var unused);
else
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
@@ -93,9 +90,8 @@ namespace OpenRA.Mods.Cnc.FileSystem
{
var classicHash = PackageEntry.HashFilename(filename, PackageHashType.Classic);
var crcHash = PackageEntry.HashFilename(filename, PackageHashType.CRC32);
- PackageEntry e;
- if (entries.TryGetValue(classicHash, out e))
+ if (entries.TryGetValue(classicHash, out var e))
classicIndex.Add(filename, e);
if (entries.TryGetValue(crcHash, out e))
@@ -187,8 +183,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public Stream GetStream(string filename)
{
- PackageEntry e;
- if (!index.TryGetValue(filename, out e))
+ if (!index.TryGetValue(filename, out var e))
return null;
return GetContent(e);
@@ -210,12 +205,11 @@ namespace OpenRA.Mods.Cnc.FileSystem
public IReadOnlyPackage OpenPackage(string filename, FS context)
{
- IReadOnlyPackage package;
var childStream = GetStream(filename);
if (childStream == null)
return null;
- if (context.TryParsePackage(childStream, filename, out package))
+ if (context.TryParsePackage(childStream, filename, out var package))
return package;
childStream.Dispose();
@@ -237,9 +231,8 @@ namespace OpenRA.Mods.Cnc.FileSystem
}
// Load the global mix database
- Stream mixDatabase;
var allPossibleFilenames = new HashSet();
- if (context.TryOpen("global mix database.dat", out mixDatabase))
+ if (context.TryOpen("global mix database.dat", out var mixDatabase))
using (var db = new XccGlobalDatabase(mixDatabase))
foreach (var e in db.Entries)
allPossibleFilenames.Add(e);
diff --git a/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs b/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs
index a85e07a2eb..1c72214edc 100644
--- a/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs
+++ b/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs
@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public override string ToString()
{
- string filename;
- if (names.TryGetValue(Hash, out filename))
+ if (names.TryGetValue(Hash, out var filename))
return "{0} - offset 0x{1:x8} - length 0x{2:x8}".F(filename, Offset, Length);
else
return "0x{0:x8} - offset 0x{1:x8} - length 0x{2:x8}".F(Hash, Offset, Length);
diff --git a/OpenRA.Mods.Cnc/FileSystem/Pak.cs b/OpenRA.Mods.Cnc/FileSystem/Pak.cs
index 5811960df4..48ac89351c 100644
--- a/OpenRA.Mods.Cnc/FileSystem/Pak.cs
+++ b/OpenRA.Mods.Cnc/FileSystem/Pak.cs
@@ -66,8 +66,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public Stream GetStream(string filename)
{
- Entry entry;
- if (!index.TryGetValue(filename, out entry))
+ if (!index.TryGetValue(filename, out var entry))
return null;
return SegmentStream.CreateWithoutOwningStream(stream, entry.Offset, (int)entry.Length);
diff --git a/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs b/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs
index ae547975ab..7d46b16a6b 100644
--- a/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs
+++ b/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs
@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Cnc.Graphics
: base(modData)
{
var metadata = modData.Manifest.Get().Metadata;
- MiniYaml yaml;
- if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
+ if (metadata.TryGetValue("DefaultSpriteExtension", out var yaml))
DefaultSpriteExtension = yaml.Value;
if (metadata.TryGetValue("TilesetExtensions", out yaml))
@@ -51,8 +50,7 @@ namespace OpenRA.Mods.Cnc.Graphics
{
var tsId = tileSet.Id;
- MiniYaml yaml;
- if (d.TryGetValue("TilesetOverrides", out yaml))
+ if (d.TryGetValue("TilesetOverrides", out var yaml))
{
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
if (tsNode != null)
@@ -70,8 +68,7 @@ namespace OpenRA.Mods.Cnc.Graphics
if (LoadField(d, "UseTilesetCode", false))
{
- string code;
- if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
+ if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
}
@@ -79,8 +76,7 @@ namespace OpenRA.Mods.Cnc.Graphics
{
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
- string tilesetExtension;
- if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
+ if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
return spriteName + tilesetExtension;
return spriteName + loader.DefaultSpriteExtension;
diff --git a/OpenRA.Mods.Cnc/Traits/Disguise.cs b/OpenRA.Mods.Cnc/Traits/Disguise.cs
index 7a3d97660c..4f6ef469d4 100644
--- a/OpenRA.Mods.Cnc/Traits/Disguise.cs
+++ b/OpenRA.Mods.Cnc/Traits/Disguise.cs
@@ -235,8 +235,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (disguisedAsToken != Actor.InvalidConditionToken)
disguisedAsToken = self.RevokeCondition(disguisedAsToken);
- string disguisedAsCondition;
- if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out disguisedAsCondition))
+ if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out var disguisedAsCondition))
disguisedAsToken = self.GrantCondition(disguisedAsCondition);
}
}
diff --git a/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs b/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs
index 6f6c0fb45a..4d72163f18 100644
--- a/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs
+++ b/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs
@@ -53,8 +53,7 @@ namespace OpenRA.Mods.Cnc.Traits
{
var damageSubTicks = (int)(damage.Value * 100L * Info.DamageMultiplier / Info.DamageDivisor);
- SupportPowerInstance spi;
- if (spm.Powers.TryGetValue(Info.OrderName, out spi))
+ if (spm.Powers.TryGetValue(Info.OrderName, out var spi))
{
var dspi = spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance;
if (dspi != null)
diff --git a/OpenRA.Mods.Cnc/Traits/EnergyWall.cs b/OpenRA.Mods.Cnc/Traits/EnergyWall.cs
index 6713a837cc..ff27dca357 100644
--- a/OpenRA.Mods.Cnc/Traits/EnergyWall.cs
+++ b/OpenRA.Mods.Cnc/Traits/EnergyWall.cs
@@ -36,10 +36,8 @@ namespace OpenRA.Mods.Cnc.Traits
public 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;
diff --git a/OpenRA.Mods.Cnc/Traits/MadTank.cs b/OpenRA.Mods.Cnc/Traits/MadTank.cs
index 9648edd74c..28dee8c129 100644
--- a/OpenRA.Mods.Cnc/Traits/MadTank.cs
+++ b/OpenRA.Mods.Cnc/Traits/MadTank.cs
@@ -65,15 +65,13 @@ namespace OpenRA.Mods.Cnc.Traits
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
- WeaponInfo thumpDamageWeapon;
- WeaponInfo detonationWeapon;
var thumpDamageWeaponToLower = (ThumpDamageWeapon ?? string.Empty).ToLowerInvariant();
var detonationWeaponToLower = (DetonationWeapon ?? string.Empty).ToLowerInvariant();
- if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out thumpDamageWeapon))
+ if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out var thumpDamageWeapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(thumpDamageWeaponToLower));
- if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out detonationWeapon))
+ if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out var detonationWeapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(detonationWeaponToLower));
ThumpDamageWeaponInfo = thumpDamageWeapon;
diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs
index cd40b8e464..cd709e2b13 100644
--- a/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs
+++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs
@@ -66,9 +66,8 @@ namespace OpenRA.Mods.Cnc.Traits
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
- WeaponInfo weapon;
var weaponToLower = (Weapon ?? 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;
diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs
index 6fc6ef027d..58a0cd213c 100644
--- a/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs
+++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs
@@ -52,9 +52,8 @@ namespace OpenRA.Mods.Cnc.Traits
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
- WeaponInfo weapon;
var weaponToLower = (Weapon ?? 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;
diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs
index 4f5c2597b1..670db43657 100644
--- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs
+++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs
@@ -404,8 +404,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
if (overlayType == 0xFF)
continue;
- string actorType;
- if (OverlayToActor.TryGetValue(overlayType, out actorType))
+ if (OverlayToActor.TryGetValue(overlayType, out var actorType))
{
if (string.IsNullOrEmpty(actorType))
continue;
@@ -416,19 +415,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
// Only import the top-left cell of multi-celled overlays
var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
if (shape.Width > 1 && aboveType != 0xFF)
- {
- string a;
- if (OverlayToActor.TryGetValue(aboveType, out a) && a == actorType)
+ if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType)
continue;
- }
var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
if (shape.Height > 1 && leftType != 0xFF)
- {
- string a;
- if (OverlayToActor.TryGetValue(leftType, out a) && a == actorType)
+ if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType)
continue;
- }
}
var ar = new ActorReference(actorType)
@@ -437,8 +430,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
new OwnerInit("Neutral")
};
- DamageState damageState;
- if (OverlayToHealth.TryGetValue(overlayType, out damageState))
+ if (OverlayToHealth.TryGetValue(overlayType, out var damageState))
{
var health = 100;
if (damageState == DamageState.Critical)
@@ -484,8 +476,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var dy = rx + ry - fullSize.X - 1;
var cell = new MPos(dx / 2, dy).ToCPos(map);
- int wpindex;
- var ar = new ActorReference((!int.TryParse(kv.Key, out wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
+ var ar = new ActorReference((!int.TryParse(kv.Key, out var wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
ar.Add(new LocationInit(cell));
ar.Add(new OwnerInit("Neutral"));
@@ -598,8 +589,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
foreach (var node in lightingTypes)
{
- float val;
- if (node.Value != null && parsed.TryGetValue(node.Key, out val) && ((node.Key == "Level" && val != 0) || (node.Key != "Level" && val != 1.0f)))
+ if (node.Value != null && parsed.TryGetValue(node.Key, out var val) && ((node.Key == "Level" && val != 0) || (node.Key != "Level" && val != 1.0f)))
lightingNodes.Add(new MiniYamlNode(node.Value, FieldSaver.FormatValue(val)));
}
diff --git a/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs b/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs
index 32255bf734..f79298c736 100644
--- a/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs
+++ b/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs
@@ -265,9 +265,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
else
Console.WriteLine("\t\tFacings: 8");
- int length, stride;
- int.TryParse(splitting[2], out stride);
- int.TryParse(splitting[1], out length);
+ int.TryParse(splitting[2], out var stride);
+ int.TryParse(splitting[1], out var length);
if (stride != 0 && stride != length)
Console.WriteLine("\t\tStride: " + stride);
}
diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs
index 1c18e87761..81062991b0 100644
--- a/OpenRA.Mods.Common/Activities/Air/Fly.cs
+++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs
@@ -164,8 +164,7 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
diff --git a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs
index 7fc768867d..37152eaa9e 100644
--- a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs
+++ b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs
@@ -90,8 +90,7 @@ namespace OpenRA.Mods.Common.Activities
if (attackAircraft.IsTraitPaused)
return false;
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
attackAircraft.SetRequestedTarget(self, target, forceAttack);
hasTicked = true;
@@ -239,8 +238,7 @@ namespace OpenRA.Mods.Common.Activities
// Cancel the run if the target become invalid (e.g. killed) while visible
var targetWasVisibleActor = targetIsVisibleActor;
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
targetIsVisibleActor = target.Type == TargetType.Actor && !targetIsHiddenActor;
if (targetWasVisibleActor && !target.IsValidFor(self))
@@ -284,8 +282,7 @@ namespace OpenRA.Mods.Common.Activities
// Strafe attacks target the ground below the original target
// Update the position if we seen the target move; keep the previous one if it dies or disappears
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
attackAircraft.SetRequestedTarget(self, Target.FromTargetPositions(target), true);
diff --git a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs
index 2297de7a42..a06c3fefa3 100644
--- a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs
+++ b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs
@@ -55,8 +55,7 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceling)
return true;
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs
index afd7550d10..4855c3aa70 100644
--- a/OpenRA.Mods.Common/Activities/Attack.cs
+++ b/OpenRA.Mods.Common/Activities/Attack.cs
@@ -96,8 +96,7 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
- bool targetIsHiddenActor;
- target = RecalculateTarget(self, out targetIsHiddenActor);
+ target = RecalculateTarget(self, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{
diff --git a/OpenRA.Mods.Common/Activities/CaptureActor.cs b/OpenRA.Mods.Common/Activities/CaptureActor.cs
index 026960d131..817f505677 100644
--- a/OpenRA.Mods.Common/Activities/CaptureActor.cs
+++ b/OpenRA.Mods.Common/Activities/CaptureActor.cs
@@ -46,8 +46,7 @@ namespace OpenRA.Mods.Common.Activities
// StartCapture returns false when a capture delay is enabled
// We wait until it returns true before allowing entering the target
- Captures captures;
- if (!manager.StartCapture(self, enterActor, enterCaptureManager, out captures))
+ if (!manager.StartCapture(self, enterActor, enterCaptureManager, out var captures))
return false;
if (!captures.Info.ConsumedByCapture)
diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs
index d272632de6..91887588eb 100644
--- a/OpenRA.Mods.Common/Activities/Enter.cs
+++ b/OpenRA.Mods.Common/Activities/Enter.cs
@@ -62,8 +62,7 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self)
{
// Update our view of the target
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
diff --git a/OpenRA.Mods.Common/Activities/Move/Follow.cs b/OpenRA.Mods.Common/Activities/Move/Follow.cs
index cee54d77a2..8fb23f531a 100644
--- a/OpenRA.Mods.Common/Activities/Move/Follow.cs
+++ b/OpenRA.Mods.Common/Activities/Move/Follow.cs
@@ -51,8 +51,7 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceling)
return true;
- bool targetIsHiddenActor;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs
index 925e95add4..9c056ce8d3 100644
--- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs
+++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs
@@ -88,9 +88,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self)
{
- bool targetIsHiddenActor;
var oldTargetLocation = lastVisibleTargetLocation;
- target = target.Recalculate(self.Owner, out targetIsHiddenActor);
+ target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{
lastVisibleTarget = Target.FromTargetPositions(target);
diff --git a/OpenRA.Mods.Common/ColorValidator.cs b/OpenRA.Mods.Common/ColorValidator.cs
index 0251f20b27..407e2c794a 100644
--- a/OpenRA.Mods.Common/ColorValidator.cs
+++ b/OpenRA.Mods.Common/ColorValidator.cs
@@ -57,10 +57,7 @@ namespace OpenRA.Mods.Common
public bool IsValid(Color askedColor, out Color forbiddenColor, IEnumerable terrainColors, IEnumerable playerColors, HashSet errorMessages = null)
{
// Validate color against HSV
- float h, s, v;
- int a;
-
- askedColor.ToAhsv(out a, out h, out s, out v);
+ askedColor.ToAhsv(out var a, out var h, out var s, out var v);
if (s < HsvSaturationRange[0] || s > HsvSaturationRange[1] || v < HsvValueRange[0] || v > HsvValueRange[1])
{
if (errorMessages != null)
@@ -95,9 +92,8 @@ namespace OpenRA.Mods.Common
{
if (TeamColorPresets.Any())
{
- Color forbidden;
foreach (var c in TeamColorPresets.Shuffle(random))
- if (IsValid(c, out forbidden, terrainColors, playerColors))
+ if (IsValid(c, out var forbidden, terrainColors, playerColors))
return c;
}
@@ -107,7 +103,6 @@ namespace OpenRA.Mods.Common
public Color RandomValidColor(MersenneTwister random, IEnumerable terrainColors, IEnumerable playerColors)
{
Color color;
- Color forbidden;
do
{
var h = random.Next(255) / 255f;
@@ -115,7 +110,7 @@ namespace OpenRA.Mods.Common
var v = float2.Lerp(HsvValueRange[0], HsvValueRange[1], random.NextFloat());
color = Color.FromAhsv(h, s, v);
}
- while (!IsValid(color, out forbidden, terrainColors, playerColors));
+ while (!IsValid(color, out var forbidden, terrainColors, playerColors));
return color;
}
@@ -124,8 +119,7 @@ namespace OpenRA.Mods.Common
{
var errorMessages = new HashSet();
- Color forbiddenColor;
- if (IsValid(askedColor, out forbiddenColor, terrainColors, playerColors, errorMessages))
+ if (IsValid(askedColor, out var forbiddenColor, terrainColors, playerColors, errorMessages))
return askedColor;
// Vector between the 2 colors
diff --git a/OpenRA.Mods.Common/Commands/DevCommands.cs b/OpenRA.Mods.Common/Commands/DevCommands.cs
index 27eb1466ff..ae1a0df4ed 100644
--- a/OpenRA.Mods.Common/Commands/DevCommands.cs
+++ b/OpenRA.Mods.Common/Commands/DevCommands.cs
@@ -147,8 +147,7 @@ namespace OpenRA.Mods.Common.Commands
var orderString = toAll ? "DevGiveCashAll" : "DevGiveCash";
var giveCashOrder = new Order(orderString, world.LocalPlayer.PlayerActor, false);
- int cash;
- int.TryParse(arg, out cash);
+ int.TryParse(arg, out var cash);
giveCashOrder.ExtraData = (uint)cash;
world.IssueOrder(giveCashOrder);
diff --git a/OpenRA.Mods.Common/Commands/HelpCommand.cs b/OpenRA.Mods.Common/Commands/HelpCommand.cs
index 693a520918..a8470e8a6d 100644
--- a/OpenRA.Mods.Common/Commands/HelpCommand.cs
+++ b/OpenRA.Mods.Common/Commands/HelpCommand.cs
@@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Commands
foreach (var key in console.Commands.Keys)
{
- string description;
- if (!helpDescriptions.TryGetValue(key, out description))
+ if (!helpDescriptions.TryGetValue(key, out var description))
description = "no description available.";
Game.Debug("{0}: {1}", key, description);
diff --git a/OpenRA.Mods.Common/FileFormats/IniFile.cs b/OpenRA.Mods.Common/FileFormats/IniFile.cs
index 71c14c1612..063e92240b 100644
--- a/OpenRA.Mods.Common/FileFormats/IniFile.cs
+++ b/OpenRA.Mods.Common/FileFormats/IniFile.cs
@@ -62,8 +62,7 @@ namespace OpenRA.Mods.Common.FileFormats
return null;
var sectionName = m.Groups[1].Value.ToLowerInvariant();
- IniSection ret;
- if (!sections.TryGetValue(sectionName, out ret))
+ if (!sections.TryGetValue(sectionName, out var ret))
sections.Add(sectionName, ret = new IniSection(sectionName));
return ret;
}
@@ -102,8 +101,7 @@ namespace OpenRA.Mods.Common.FileFormats
public IniSection GetSection(string s, bool allowFail)
{
- IniSection section;
- if (sections.TryGetValue(s.ToLowerInvariant(), out section))
+ if (sections.TryGetValue(s.ToLowerInvariant(), out var section))
return section;
if (allowFail)
@@ -136,8 +134,7 @@ namespace OpenRA.Mods.Common.FileFormats
public string GetValue(string key, string defaultValue)
{
- string s;
- return values.TryGetValue(key, out s) ? s : defaultValue;
+ return values.TryGetValue(key, out var s) ? s : defaultValue;
}
public IEnumerator> GetEnumerator()
diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs
index 4d90eb223e..822bde423f 100644
--- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs
+++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs
@@ -394,8 +394,7 @@ namespace OpenRA.Mods.Common.FileFormats
public void ExtractFile(string filename, Stream output, Action onProgress = null)
{
- FileDescriptor file;
- if (!index.TryGetValue(filename, out file))
+ if (!index.TryGetValue(filename, out var file))
throw new FileNotFoundException(filename);
ExtractFile(file, output, onProgress);
diff --git a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs
index 636ad489aa..f679f9eb23 100644
--- a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs
+++ b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs
@@ -109,8 +109,7 @@ namespace OpenRA.Mods.Common.FileSystem
public Stream GetStream(string filename)
{
- Entry e;
- if (!index.TryGetValue(filename, out e))
+ if (!index.TryGetValue(filename, out var e))
return null;
s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs
index 988854c2bb..362bb0bb6e 100644
--- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs
+++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs
@@ -53,10 +53,9 @@ namespace OpenRA.Mods.Common.Graphics
var sequences = new Dictionary();
var nodes = node.Value.ToDictionary();
- MiniYaml defaults;
try
{
- if (nodes.TryGetValue("Defaults", out defaults))
+ if (nodes.TryGetValue("Defaults", out var defaults))
{
nodes.Remove("Defaults");
foreach (var n in nodes)
@@ -123,8 +122,7 @@ namespace OpenRA.Mods.Common.Graphics
protected static T LoadField(Dictionary d, string key, T fallback)
{
- MiniYaml value;
- if (d.TryGetValue(key, out value))
+ if (d.TryGetValue(key, out var value))
return FieldLoader.GetValue(key, value.Value);
return fallback;
@@ -174,8 +172,7 @@ namespace OpenRA.Mods.Common.Graphics
Func> getUsedFrames = frameCount =>
{
- MiniYaml length;
- if (d.TryGetValue("Length", out length) && length.Value == "*")
+ if (d.TryGetValue("Length", out var length) && length.Value == "*")
Length = Frames != null ? Frames.Length : frameCount - Start;
else
Length = LoadField(d, "Length", 1);
@@ -244,8 +241,7 @@ namespace OpenRA.Mods.Common.Graphics
return usedFrames;
};
- MiniYaml combine;
- if (d.TryGetValue("Combine", out combine))
+ if (d.TryGetValue("Combine", out var combine))
{
var combined = Enumerable.Empty();
foreach (var sub in combine.Nodes)
@@ -262,8 +258,7 @@ namespace OpenRA.Mods.Common.Graphics
Func> subGetUsedFrames = subFrameCount =>
{
- MiniYaml subLengthYaml;
- if (sd.TryGetValue("Length", out subLengthYaml) && subLengthYaml.Value == "*")
+ if (sd.TryGetValue("Length", out var subLengthYaml) && subLengthYaml.Value == "*")
subLength = subFrames != null ? subFrames.Length : subFrameCount - subStart;
else
subLength = LoadField(sd, "Length", 1);
diff --git a/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs
index 8da47d4fd7..7c74c7b85f 100644
--- a/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs
+++ b/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs
@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Common.Graphics
: base(modData)
{
var metadata = modData.Manifest.Get().Metadata;
- MiniYaml yaml;
- if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
+ if (metadata.TryGetValue("DefaultSpriteExtension", out var yaml))
DefaultSpriteExtension = yaml.Value;
if (metadata.TryGetValue("TilesetExtensions", out yaml))
@@ -51,8 +50,7 @@ namespace OpenRA.Mods.Common.Graphics
{
var tsId = tileSet.Id;
- MiniYaml yaml;
- if (d.TryGetValue("TilesetOverrides", out yaml))
+ if (d.TryGetValue("TilesetOverrides", out var yaml))
{
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
if (tsNode != null)
@@ -70,8 +68,7 @@ namespace OpenRA.Mods.Common.Graphics
if (LoadField(d, "UseTilesetCode", false))
{
- string code;
- if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
+ if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
}
@@ -79,8 +76,7 @@ namespace OpenRA.Mods.Common.Graphics
{
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
- string tilesetExtension;
- if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
+ if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
return spriteName + tilesetExtension;
return spriteName + loader.DefaultSpriteExtension;
diff --git a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs
index 4d9817cb86..e6d91197e1 100644
--- a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs
+++ b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs
@@ -89,9 +89,8 @@ namespace OpenRA.Mods.Common.Lint
var type = modData.ObjectCreator.FindType(widgetType + "Widget");
var keyNames = checkMethods.SelectMany(m => (IEnumerable)type.GetMethod(m).Invoke(null, new object[] { node, emitError, emitWarning }));
- Hotkey unused;
foreach (var name in keyNames)
- if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out unused))
+ if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out var unused))
emitError("{0} refers to a Key named `{1}` that does not exist".F(node.Location, name));
}
diff --git a/OpenRA.Mods.Common/Lint/CheckNotifications.cs b/OpenRA.Mods.Common/Lint/CheckNotifications.cs
index ddafcca946..1f0d0192e4 100644
--- a/OpenRA.Mods.Common/Lint/CheckNotifications.cs
+++ b/OpenRA.Mods.Common/Lint/CheckNotifications.cs
@@ -43,9 +43,8 @@ namespace OpenRA.Mods.Common.Lint
if (string.IsNullOrEmpty(notification))
continue;
- SoundInfo soundInfo;
- if (string.IsNullOrEmpty(type) || !rules.Notifications.TryGetValue(type.ToLowerInvariant(), out soundInfo) ||
- !soundInfo.Notifications.ContainsKey(notification))
+ if (string.IsNullOrEmpty(type) || !rules.Notifications.TryGetValue(type.ToLowerInvariant(), out var soundInfo) ||
+ !soundInfo.Notifications.ContainsKey(notification))
emitError("Undefined notification reference {0}.{1} detected at {2} for {3}".F(
type ?? "(null)", notification, traitInfo.GetType().Name, actorInfo.Key));
}
diff --git a/OpenRA.Mods.Common/Lint/CheckPlayers.cs b/OpenRA.Mods.Common/Lint/CheckPlayers.cs
index 5a7e9dc5aa..3975f65ec4 100644
--- a/OpenRA.Mods.Common/Lint/CheckPlayers.cs
+++ b/OpenRA.Mods.Common/Lint/CheckPlayers.cs
@@ -95,8 +95,7 @@ namespace OpenRA.Mods.Common.Lint
if (!playerNames.Contains(ownerName))
emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
- RequiresSpecificOwnersInfo info;
- if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out info))
+ if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info))
if (!info.ValidOwnerNames.Contains(ownerName))
emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", ")));
}
diff --git a/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs
index 8f2a607103..614ce6aa24 100644
--- a/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs
+++ b/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs
@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Common.LoadScreens
public override void StartGame(Arguments args)
{
var modId = args.GetValue("Content.Mod", null);
- Manifest selectedMod;
- if (modId == null || !Game.Mods.TryGetValue(modId, out selectedMod))
+ if (modId == null || !Game.Mods.TryGetValue(modId, out var selectedMod))
throw new InvalidOperationException("Invalid or missing Content.Mod argument.");
var content = selectedMod.Get(Game.ModData.ObjectCreator);
diff --git a/OpenRA.Mods.Common/Pathfinder/PathCacheStorage.cs b/OpenRA.Mods.Common/Pathfinder/PathCacheStorage.cs
index e96f33d19b..59d745aaf8 100644
--- a/OpenRA.Mods.Common/Pathfinder/PathCacheStorage.cs
+++ b/OpenRA.Mods.Common/Pathfinder/PathCacheStorage.cs
@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Pathfinder
public List Retrieve(string key)
{
- CachedPath cached;
- if (cachedPaths.TryGetValue(key, out cached))
+ if (cachedPaths.TryGetValue(key, out var cached))
{
if (IsExpired(cached))
{
diff --git a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs
index 728286ffc5..cc594caf74 100644
--- a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs
+++ b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs
@@ -218,9 +218,7 @@ namespace OpenRA.Mods.Common.Projectiles
}
// Check for blocking actors
- WPos blockedPos;
- if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos,
- info.Width, out blockedPos))
+ if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos, info.Width, out var blockedPos))
{
headPos = blockedPos;
target = headPos;
diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs
index 0662946d59..f685a70a2e 100644
--- a/OpenRA.Mods.Common/Projectiles/Bullet.cs
+++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs
@@ -205,9 +205,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Check for walls or other blocking obstacles
var shouldExplode = false;
- WPos blockedPos;
- if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
- out blockedPos))
+ if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos))
{
pos = blockedPos;
shouldExplode = true;
diff --git a/OpenRA.Mods.Common/Projectiles/InstantHit.cs b/OpenRA.Mods.Common/Projectiles/InstantHit.cs
index a9b9651c70..59ff825f4c 100644
--- a/OpenRA.Mods.Common/Projectiles/InstantHit.cs
+++ b/OpenRA.Mods.Common/Projectiles/InstantHit.cs
@@ -67,7 +67,6 @@ namespace OpenRA.Mods.Common.Projectiles
public void Tick(World world)
{
// Check for blocking actors
- WPos blockedPos;
if (info.Blockable)
{
// If GuidedTarget has become invalid due to getting killed the same tick,
@@ -77,7 +76,7 @@ namespace OpenRA.Mods.Common.Projectiles
target = Target.FromPos(args.PassiveTarget);
if (BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition,
- info.Width, out blockedPos))
+ info.Width, out var blockedPos))
target = Target.FromPos(blockedPos);
}
diff --git a/OpenRA.Mods.Common/Projectiles/LaserZap.cs b/OpenRA.Mods.Common/Projectiles/LaserZap.cs
index 6d67e41528..5ae71d2426 100644
--- a/OpenRA.Mods.Common/Projectiles/LaserZap.cs
+++ b/OpenRA.Mods.Common/Projectiles/LaserZap.cs
@@ -158,9 +158,7 @@ namespace OpenRA.Mods.Common.Projectiles
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
// Check for blocking actors
- WPos blockedPos;
- if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target,
- info.Width, out blockedPos))
+ if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target, info.Width, out var blockedPos))
{
target = blockedPos;
}
diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs
index 74ef4cd4a6..e73f58820b 100644
--- a/OpenRA.Mods.Common/Projectiles/Missile.cs
+++ b/OpenRA.Mods.Common/Projectiles/Missile.cs
@@ -849,9 +849,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Check for walls or other blocking obstacles
var shouldExplode = false;
- WPos blockedPos;
- if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
- out blockedPos))
+ if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos))
{
pos = blockedPos;
shouldExplode = true;
diff --git a/OpenRA.Mods.Common/Projectiles/Railgun.cs b/OpenRA.Mods.Common/Projectiles/Railgun.cs
index 1c95e3615f..f1fbe37217 100644
--- a/OpenRA.Mods.Common/Projectiles/Railgun.cs
+++ b/OpenRA.Mods.Common/Projectiles/Railgun.cs
@@ -148,9 +148,8 @@ namespace OpenRA.Mods.Common.Projectiles
void CalculateVectors()
{
// Check for blocking actors
- WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(args.SourceActor.World, target, args.Source,
- info.BeamWidth, out blockedPos))
+ info.BeamWidth, out var blockedPos))
target = blockedPos;
// Note: WAngle.Sin(x) = 1024 * Math.Sin(2pi/1024 * x)
diff --git a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs
index 924f5e0c34..3a808d8783 100644
--- a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs
+++ b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs
@@ -52,16 +52,14 @@ namespace OpenRA.Mods.Common.Scripting
using (kv.Value)
{
var key = kv.Key.ToString();
- Type type;
- if (!args.TryGetValue(key, out type))
+ if (!args.TryGetValue(key, out var type))
throw new LuaException("Unknown initializer type '{0}.{1}'".F(initInstance[0], key));
- object clrValue;
var isActorReference = type == typeof(ActorInitActorReference);
if (isActorReference)
type = kv.Value is LuaString ? typeof(string) : typeof(Actor);
- if (!kv.Value.TryGetClrValue(type, out clrValue))
+ if (!kv.Value.TryGetClrValue(type, out var clrValue))
throw new LuaException("Invalid data type for '{0}.{1}' (expected {2}, got {3})".F(initInstance[0], key, type.Name, kv.Value.WrappedClrType()));
if (isActorReference)
@@ -79,8 +77,7 @@ namespace OpenRA.Mods.Common.Scripting
var facingInit = init as FacingInit;
if (facingInit != null)
{
- int facing;
- if (value.TryGetClrValue(out facing))
+ if (value.TryGetClrValue(out int facing))
{
facingInit.Initialize(WAngle.FromFacing(facing));
Game.Debug("Initializing Facing with integers is deprecated. Use Angle instead.");
@@ -97,8 +94,7 @@ namespace OpenRA.Mods.Common.Scripting
var valueType = parameterType.IsEnum ? Enum.GetUnderlyingType(parameterType) : parameterType;
// Try and coerce the table value to the required type
- object clrValue;
- if (!value.TryGetClrValue(valueType, out clrValue))
+ if (!value.TryGetClrValue(valueType, out var clrValue))
continue;
initializer.Invoke(init, new[] { clrValue });
@@ -139,8 +135,7 @@ namespace OpenRA.Mods.Common.Scripting
"An optional second value can be used to exactly specify the producing queue type.")]
public int BuildTime(string type, string queue = null)
{
- ActorInfo ai;
- if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
+ if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
var bi = ai.TraitInfoOrDefault();
@@ -187,8 +182,7 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Returns the cruise altitude of the requested unit type (zero if it is ground-based).")]
public int CruiseAltitude(string type)
{
- ActorInfo ai;
- if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
+ if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
var pi = ai.TraitInfoOrDefault();
@@ -197,8 +191,7 @@ namespace OpenRA.Mods.Common.Scripting
public int Cost(string type)
{
- ActorInfo ai;
- if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
+ if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
var vi = ai.TraitInfoOrDefault();
diff --git a/OpenRA.Mods.Common/Scripting/Global/ColorGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ColorGlobal.cs
index 0b82e6bb43..e008b3ac82 100644
--- a/OpenRA.Mods.Common/Scripting/Global/ColorGlobal.cs
+++ b/OpenRA.Mods.Common/Scripting/Global/ColorGlobal.cs
@@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Scripting.Global
[Desc("Create a new color with the specified red/green/blue/[alpha] hex string (rrggbb[aa]).")]
public Color FromHex(string value)
{
- Color color;
- if (Color.TryParse(value, out color))
+ if (Color.TryParse(value, out var color))
return color;
throw new LuaException("Invalid rrggbb[aa] hex string.");
diff --git a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs
index 47b557418d..b3e0643a61 100644
--- a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs
+++ b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs
@@ -128,9 +128,7 @@ namespace OpenRA.Mods.Common.Scripting
"the map file (or nil, if the actor is dead or not found).")]
public Actor NamedActor(string actorName)
{
- Actor ret;
-
- if (!sma.Actors.TryGetValue(actorName, out ret))
+ if (!sma.Actors.TryGetValue(actorName, out var ret))
return null;
if (ret.Disposed)
diff --git a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs
index 30417fcd8f..8c85ab27ed 100644
--- a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs
+++ b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs
@@ -35,8 +35,7 @@ namespace OpenRA.Mods.Common.Scripting
Actor CreateActor(Player owner, string actorType, bool addToWorld, CPos? entryLocation = null, CPos? nextLocation = null)
{
- ActorInfo ai;
- if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out ai))
+ if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out var ai))
throw new LuaException("Unknown actor type '{0}'".F(actorType));
var initDict = new TypeDictionary();
diff --git a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs
index f53af83b5c..f479706368 100644
--- a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs
+++ b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs
@@ -183,8 +183,7 @@ namespace OpenRA.Mods.Common.Scripting
if (autotarget == null)
return;
- UnitStance stance;
- if (!Enum.TryParse(value, true, out stance))
+ if (!Enum.TryParse(value, true, out var stance))
throw new LuaException("Unknown stance type '{0}'".F(value));
autotarget.PredictedStance = stance;
diff --git a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs
index f6282b6024..6bbc9706d0 100644
--- a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs
+++ b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs
@@ -77,8 +77,7 @@ namespace OpenRA.Mods.Common.Scripting
{
var result = new List();
- ActorInfo ai;
- if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
+ if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
result.AddRange(Player.World.Actors
diff --git a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs
index f67e25ca3c..0577e731af 100644
--- a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs
+++ b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs
@@ -38,8 +38,7 @@ namespace OpenRA.Mods.Common.Scripting
"If 'Buildable.BuildAtProductionType' is not set either, a random exit will be selected.")]
public void Produce(string actorType, string factionVariant = null, string productionType = null)
{
- ActorInfo actorInfo;
- if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo))
+ if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out var actorInfo))
throw new LuaException("Unknown actor type '{0}'".F(actorType));
var bi = actorInfo.TraitInfo();
diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs
index 7d796fc59e..c26df4882b 100644
--- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs
+++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs
@@ -92,8 +92,7 @@ namespace OpenRA.Mods.Common.Server
var cmdName = cmd.Split(' ').First();
var cmdValue = cmd.Split(' ').Skip(1).JoinWith(" ");
- Func a;
- if (!commandHandlers.TryGetValue(cmdName, out a))
+ if (!commandHandlers.TryGetValue(cmdName, out var a))
return false;
return a(server, conn, client, cmdValue);
@@ -304,8 +303,7 @@ namespace OpenRA.Mods.Common.Server
var slot = server.LobbyInfo.Slots[parts[0]];
var bot = server.LobbyInfo.ClientInSlot(parts[0]);
- int controllerClientIndex;
- if (!Exts.TryParseIntegerInvariant(parts[1], out controllerClientIndex))
+ if (!Exts.TryParseIntegerInvariant(parts[1], out var controllerClientIndex))
{
Log.Write("server", "Invalid bot controller client index: {0}", parts[1]);
return false;
@@ -496,8 +494,7 @@ namespace OpenRA.Mods.Common.Server
options[o.Id] = o;
var split = s.Split(' ');
- LobbyOption option;
- if (split.Length < 2 || !options.TryGetValue(split[0], out option) ||
+ if (split.Length < 2 || !options.TryGetValue(split[0], out var option) ||
!option.Values.ContainsKey(split[1]))
{
server.SendOrderTo(conn, "Message", "Invalid configuration command.");
@@ -537,8 +534,7 @@ namespace OpenRA.Mods.Common.Server
return true;
}
- int teamCount;
- if (!Exts.TryParseIntegerInvariant(s, out teamCount))
+ if (!Exts.TryParseIntegerInvariant(s, out var teamCount))
{
server.SendOrderTo(conn, "Message", "Number of teams could not be parsed: {0}".F(s));
return true;
@@ -585,8 +581,7 @@ namespace OpenRA.Mods.Common.Server
return true;
}
- int kickClientID;
- Exts.TryParseIntegerInvariant(split[0], out kickClientID);
+ Exts.TryParseIntegerInvariant(split[0], out var kickClientID);
var kickConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
if (kickConn == null)
@@ -607,8 +602,7 @@ namespace OpenRA.Mods.Common.Server
server.SendOrderTo(kickConn, "ServerError", "You have been kicked from the server.");
server.DropClient(kickConn);
- bool tempBan;
- bool.TryParse(split[1], out tempBan);
+ bool.TryParse(split[1], out var tempBan);
if (tempBan)
{
@@ -631,8 +625,7 @@ namespace OpenRA.Mods.Common.Server
return true;
}
- int newAdminId;
- Exts.TryParseIntegerInvariant(s, out newAdminId);
+ Exts.TryParseIntegerInvariant(s, out var newAdminId);
var newAdminConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == newAdminId);
if (newAdminConn == null)
@@ -666,8 +659,7 @@ namespace OpenRA.Mods.Common.Server
return true;
}
- int targetId;
- Exts.TryParseIntegerInvariant(s, out targetId);
+ Exts.TryParseIntegerInvariant(s, out var targetId);
var targetConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == targetId);
if (targetConn == null)
@@ -746,8 +738,7 @@ namespace OpenRA.Mods.Common.Server
if (server.LobbyInfo.Slots[targetClient.Slot].LockTeam)
return true;
- int team;
- if (!Exts.TryParseIntegerInvariant(parts[1], out team))
+ if (!Exts.TryParseIntegerInvariant(parts[1], out var team))
{
Log.Write("server", "Invalid team: {0}", s);
return false;
@@ -776,9 +767,8 @@ namespace OpenRA.Mods.Common.Server
if (server.LobbyInfo.Slots[targetClient.Slot].LockSpawn)
return true;
- int spawnPoint;
- if (!Exts.TryParseIntegerInvariant(parts[1], out spawnPoint)
- || spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Length)
+ if (!Exts.TryParseIntegerInvariant(parts[1], out var spawnPoint)
+ || spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Length)
{
Log.Write("server", "Invalid spawn point: {0}", parts[1]);
return true;
@@ -901,8 +891,7 @@ namespace OpenRA.Mods.Common.Server
{
var value = o.DefaultValue;
var preferredValue = o.DefaultValue;
- Session.LobbyOptionState state;
- if (gs.LobbyOptions.TryGetValue(o.Id, out state))
+ if (gs.LobbyOptions.TryGetValue(o.Id, out var state))
{
// Propagate old state on map change
if (!o.IsLocked)
diff --git a/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs b/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs
index 28cbd20742..24503edc61 100644
--- a/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs
+++ b/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs
@@ -37,10 +37,8 @@ namespace OpenRA.Mods.Common.Server
foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions)
{
- Session.LobbyOptionState def;
- string optionName;
- if (!defaults.LobbyOptions.TryGetValue(kv.Key, out def) || kv.Value.Value != def.Value)
- if (optionNames.TryGetValue(kv.Key, out optionName))
+ if (!defaults.LobbyOptions.TryGetValue(kv.Key, out var def) || kv.Value.Value != def.Value)
+ if (optionNames.TryGetValue(kv.Key, out var optionName))
server.SendOrderTo(conn, "Message", optionName + ": " + kv.Value.Value);
}
}
diff --git a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs
index d92edeeb5d..4fdbb52c03 100644
--- a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs
+++ b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs
@@ -139,8 +139,7 @@ namespace OpenRA.Mods.Common.Server
if (errorCode != 0)
{
// Hardcoded error messages take precedence over the server-provided messages
- string message;
- if (!MasterServerErrors.TryGetValue(errorCode, out message))
+ if (!MasterServerErrors.TryGetValue(errorCode, out var message))
message = errorMessage;
masterServerMessages.Enqueue("Warning: " + message);
diff --git a/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs
index 409534c3bb..dc53804526 100644
--- a/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs
+++ b/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs
@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
offsets = new List();
var pngRectangle = new Rectangle(0, 0, png.Width, png.Height);
- string frame;
- for (var i = 0; png.EmbeddedData.TryGetValue("Frame[" + i + "]", out frame); i++)
+ for (var i = 0; png.EmbeddedData.TryGetValue("Frame[" + i + "]", out var frame); i++)
{
// Format: x,y,width,height;offsetX,offsetY
var coords = frame.Split(';');
diff --git a/OpenRA.Mods.Common/TargetExtensions.cs b/OpenRA.Mods.Common/TargetExtensions.cs
index 549dbb5cba..93c7f1ef6d 100644
--- a/OpenRA.Mods.Common/TargetExtensions.cs
+++ b/OpenRA.Mods.Common/TargetExtensions.cs
@@ -21,8 +21,7 @@ namespace OpenRA.Mods.Common
/// ///
public static Target RecalculateInvalidatingHiddenTargets(this Target t, Player viewer)
{
- bool targetIsHiddenActor;
- var updated = t.Recalculate(viewer, out targetIsHiddenActor);
+ var updated = t.Recalculate(viewer, out bool targetIsHiddenActor);
return targetIsHiddenActor ? Target.Invalid : updated;
}
diff --git a/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs b/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs
index 85664eaed9..d350f709d5 100644
--- a/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs
+++ b/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs
index 579008fc15..e7a76f6857 100644
--- a/OpenRA.Mods.Common/Traits/Armament.cs
+++ b/OpenRA.Mods.Common/Traits/Armament.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs
index 4a07dc010b..b760012e78 100644
--- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs
+++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs
index 81bfa0c070..ba30ef64c1 100644
--- a/OpenRA.Mods.Common/Traits/AutoTarget.cs
+++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs
@@ -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);
}
diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs
index 15f1532c9e..c7caf40d89 100644
--- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs
+++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs
@@ -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)
diff --git a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs
index c07e7fb804..92554d74c1 100644
--- a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs
+++ b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs
@@ -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("WaitingPowers", n.Value.Value);
}
}
diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs
index 782436148c..ae5deb6cf4 100644
--- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs
+++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs
index e86a4d698d..e4d7bed645 100644
--- a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs
+++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs
@@ -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.Reserve(cargo, carrier);
diff --git a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs
index 6145f5c43f..6ed8756e7e 100644
--- a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs
+++ b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs
index 8c2a94e20a..11c5869502 100644
--- a/OpenRA.Mods.Common/Traits/Cargo.cs
+++ b/OpenRA.Mods.Common/Traits/Cargo.cs
@@ -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();
p.Transport = null;
- Stack 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))
diff --git a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs
index a36d37d85e..9b4dc4ef4f 100644
--- a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs
+++ b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs
@@ -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 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 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 permanentTokensForSource;
- if (permanentTokens.TryGetValue(source, out permanentTokensForSource))
+ if (permanentTokens.TryGetValue(source, out var permanentTokensForSource))
{
if (!permanentTokensForSource.Remove(token))
return false;
diff --git a/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs
index db0133f8f5..11ef833721 100644
--- a/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs
+++ b/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs
@@ -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);
diff --git a/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs
index e02c739243..6bdb5391a1 100644
--- a/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs
+++ b/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs
@@ -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);
diff --git a/OpenRA.Mods.Common/Traits/Explodes.cs b/OpenRA.Mods.Common/Traits/Explodes.cs
index 5681327a2e..c5fffc0e9a 100644
--- a/OpenRA.Mods.Common/Traits/Explodes.cs
+++ b/OpenRA.Mods.Common/Traits/Explodes.cs
@@ -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;
}
diff --git a/OpenRA.Mods.Common/Traits/ExplosionOnDamageTransition.cs b/OpenRA.Mods.Common/Traits/ExplosionOnDamageTransition.cs
index 7bcffa28a8..3f7856c5e3 100644
--- a/OpenRA.Mods.Common/Traits/ExplosionOnDamageTransition.cs
+++ b/OpenRA.Mods.Common/Traits/ExplosionOnDamageTransition.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs
index 1fc451c28d..f6a40584ed 100644
--- a/OpenRA.Mods.Common/Traits/Mobile.cs
+++ b/OpenRA.Mods.Common/Traits/Mobile.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Passenger.cs b/OpenRA.Mods.Common/Traits/Passenger.cs
index c034808c91..316a2c6010 100644
--- a/OpenRA.Mods.Common/Traits/Passenger.cs
+++ b/OpenRA.Mods.Common/Traits/Passenger.cs
@@ -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
diff --git a/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs b/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs
index c3cfb1f83c..fdfcfe9a4e 100644
--- a/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs
+++ b/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs
@@ -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)
diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs
index 0c25914e15..7196627acd 100644
--- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs
+++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Pluggable.cs b/OpenRA.Mods.Common/Traits/Pluggable.cs
index 9673ef3622..80acd261d6 100644
--- a/OpenRA.Mods.Common/Traits/Pluggable.cs
+++ b/OpenRA.Mods.Common/Traits/Pluggable.cs
@@ -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)
diff --git a/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs b/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs
index 54058bcf1a..5b5b00e24c 100644
--- a/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs
+++ b/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs
@@ -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().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);
diff --git a/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs b/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs
index 38bfa9e5a6..1a833da2ef 100644
--- a/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs
+++ b/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Render/WithHarvesterPipsDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithHarvesterPipsDecoration.cs
index e1351ea111..488e8f0479 100644
--- a/OpenRA.Mods.Common/Traits/Render/WithHarvesterPipsDecoration.cs
+++ b/OpenRA.Mods.Common/Traits/Render/WithHarvesterPipsDecoration.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs
index 9af36c4bb9..72864a26e6 100644
--- a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs
+++ b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs
@@ -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)))
diff --git a/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs
index 677645ed9e..7d934d3856 100644
--- a/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs
+++ b/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs
@@ -122,9 +122,8 @@ namespace OpenRA.Mods.Common.Traits.Render
adjacent = 0;
foreach (var a in adjacentActors)
{
- CVec facing;
var wc = a.TraitsImplementing().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)
diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs
index 18f8ad2209..0c67fd5b28 100644
--- a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs
+++ b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs
@@ -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;
diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs
index 918e4e3d37..9b11b6c8c5 100644
--- a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs
+++ b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs
@@ -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().CruiseAltitude.Length;
diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs
index 217a32eca7..67fa0c9c59 100644
--- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs
+++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs
@@ -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);
diff --git a/OpenRA.Mods.Common/Traits/TerrainLighting.cs b/OpenRA.Mods.Common/Traits/TerrainLighting.cs
index 016f02e6c7..1d00ea6e2d 100644
--- a/OpenRA.Mods.Common/Traits/TerrainLighting.cs
+++ b/OpenRA.Mods.Common/Traits/TerrainLighting.cs
@@ -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);
diff --git a/OpenRA.Mods.Common/Traits/ThrowsShrapnel.cs b/OpenRA.Mods.Common/Traits/ThrowsShrapnel.cs
index 3020d01314..f576d8f40d 100644
--- a/OpenRA.Mods.Common/Traits/ThrowsShrapnel.cs
+++ b/OpenRA.Mods.Common/Traits/ThrowsShrapnel.cs
@@ -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();
diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs
index 73eea60cd7..f1704dd36a 100644
--- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs
+++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs
@@ -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 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 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))
diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs
index 0b98b80ef3..640f71936f 100644
--- a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs
+++ b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs
@@ -163,8 +163,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var cell in footprint)
{
- List 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 list;
- if (!cellMap.TryGetValue(location, out list))
+ if (!cellMap.TryGetValue(location, out var list))
{
list = new List();
cellMap.Add(location, list);
@@ -256,8 +254,7 @@ namespace OpenRA.Mods.Common.Traits
public IEnumerable PreviewsAt(CPos cell)
{
- List list;
- if (cellMap.TryGetValue(cell, out list))
+ if (cellMap.TryGetValue(cell, out var list))
return list;
return Enumerable.Empty();
@@ -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)
diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs
index b54a2c2b83..03dede4168 100644
--- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs
+++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs
@@ -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
{
diff --git a/OpenRA.Mods.Common/Traits/World/IndexedPalette.cs b/OpenRA.Mods.Common/Traits/World/IndexedPalette.cs
index ae689be5c2..29487c90d5 100644
--- a/OpenRA.Mods.Common/Traits/World/IndexedPalette.cs
+++ b/OpenRA.Mods.Common/Traits/World/IndexedPalette.cs
@@ -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;
}
}
diff --git a/OpenRA.Mods.Common/Traits/World/IndexedPlayerPalette.cs b/OpenRA.Mods.Common/Traits/World/IndexedPlayerPalette.cs
index 227bcdaf14..aa3781e61b 100644
--- a/OpenRA.Mods.Common/Traits/World/IndexedPlayerPalette.cs
+++ b/OpenRA.Mods.Common/Traits/World/IndexedPlayerPalette.cs
@@ -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);
diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs
index 23f38a970a..bfe2239a46 100644
--- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs
+++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs
@@ -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;
}
diff --git a/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs b/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs
index af4628ce06..2c39f98b60 100644
--- a/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs
+++ b/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs
@@ -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.
diff --git a/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs
index abda5928c8..cb1cd0387b 100644
--- a/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs
+++ b/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs
@@ -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
///
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);
diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs
index 14d3e1c663..55cab4b9fa 100644
--- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs
+++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs
@@ -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))
diff --git a/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs b/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs
index d1790955bc..a65a0f90b2 100644
--- a/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs
+++ b/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs
@@ -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();
- if (nd.TryGetValue("InitialSmudges", out smudgeYaml))
+ if (nd.TryGetValue("InitialSmudges", out var smudgeYaml))
{
foreach (var node in smudgeYaml.Nodes)
{
diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/AddPipDecorationTraits.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/AddPipDecorationTraits.cs
index abe2a5d98e..8775944664 100644
--- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/AddPipDecorationTraits.cs
+++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/AddPipDecorationTraits.cs
@@ -114,8 +114,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
{
ammoPool.RemoveNode(pipTypeNode);
- string sequence;
- if (PipReplacements.TryGetValue(pipTypeNode.Value.Value.ToLowerInvariant(), out sequence))
+ if (PipReplacements.TryGetValue(pipTypeNode.Value.Value.ToLowerInvariant(), out var sequence))
ammoPips.AddNode("FullSequence", sequence);
}
@@ -124,8 +123,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
{
ammoPool.RemoveNode(pipTypeEmptyNode);
- string sequence;
- if (PipReplacements.TryGetValue(pipTypeEmptyNode.Value.Value.ToLowerInvariant(), out sequence))
+ if (PipReplacements.TryGetValue(pipTypeEmptyNode.Value.Value.ToLowerInvariant(), out var sequence))
ammoPips.AddNode("EmptySequence", sequence);
}
@@ -252,9 +250,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
{
storesResources.RemoveNode(pipColorNode);
- string sequence;
var type = pipColorNode.Value.Value.ToLowerInvariant();
- if (type != "green" && PipReplacements.TryGetValue(type, out sequence))
+ if (type != "green" && PipReplacements.TryGetValue(type, out var sequence))
storagePips.AddNode("FullSequence", sequence);
}
else
diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ChangeTargetLineDelayToMilliseconds.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ChangeTargetLineDelayToMilliseconds.cs
index 957ff0a951..1ee410366d 100644
--- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ChangeTargetLineDelayToMilliseconds.cs
+++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ChangeTargetLineDelayToMilliseconds.cs
@@ -32,8 +32,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
var delayNode = dltt.LastChildMatching("Delay", false);
if (delayNode != null)
{
- int delay;
- if (Exts.TryParseIntegerInvariant(delayNode.Value.Value, out delay))
+ if (Exts.TryParseIntegerInvariant(delayNode.Value.Value, out var delay))
delayNode.ReplaceValue((delay * 1000 / 25).ToString());
}
}
diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ModernizeDecorationTraits.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ModernizeDecorationTraits.cs
index 16a577aef5..45f614e6cc 100644
--- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ModernizeDecorationTraits.cs
+++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ModernizeDecorationTraits.cs
@@ -82,8 +82,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
var positionNode = node.LastChildMatching("ReferencePoint");
if (positionNode != null)
{
- DecorationPosition value;
- if (!PositionMap.TryGetValue(positionNode.NodeValue(), out value))
+ if (!PositionMap.TryGetValue(positionNode.NodeValue(), out var value))
value = DecorationPosition.TopLeft;
if (value != DecorationPosition.TopLeft)
diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs
index cde295cc3e..21be789d91 100644
--- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs
+++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs
@@ -85,8 +85,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
if (projectileNode.Value.Value == null)
continue;
- string[] fieldNames;
- if (ProjectileFields.TryGetValue(projectileNode.Value.Value, out fieldNames))
+ if (ProjectileFields.TryGetValue(projectileNode.Value.Value, out var fieldNames))
{
foreach (var fieldName in fieldNames)
{
diff --git a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs
index e8f2424431..13cee511ea 100644
--- a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs
+++ b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs
@@ -29,9 +29,7 @@ namespace OpenRA.Mods.Common.UpdateRules
var yaml = new YamlFileSet();
foreach (var filename in files)
{
- string name;
- IReadOnlyPackage package;
- if (!modData.ModFiles.TryGetPackageContaining(filename, out package, out name) || !(package is IReadWritePackage))
+ if (!modData.ModFiles.TryGetPackageContaining(filename, out var package, out var name) || !(package is IReadWritePackage))
{
Console.WriteLine("Failed to load file `{0}` for writing. It will not be updated.", filename);
continue;
diff --git a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs
index 8a78e05203..51ce9afd08 100644
--- a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs
+++ b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs
@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
for (var i = 0; i < Palette.Size; i++)
palColors[i] = palette.GetColor(i);
- TypeDictionary metadata;
- var frames = FrameLoader.GetFrames(File.OpenRead(src), modData.SpriteLoaders, out metadata);
+ var frames = FrameLoader.GetFrames(File.OpenRead(src), modData.SpriteLoaders, out var metadata);
var usePadding = !args.Contains("--nopadding");
var count = 0;
diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractLanguageStringsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractLanguageStringsCommand.cs
index 17a817a7e3..56f1f79812 100644
--- a/OpenRA.Mods.Common/UtilityCommands/ExtractLanguageStringsCommand.cs
+++ b/OpenRA.Mods.Common/UtilityCommands/ExtractLanguageStringsCommand.cs
@@ -37,10 +37,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var filename in modData.Manifest.ChromeLayout)
{
- string name;
- OpenRA.FileSystem.IReadOnlyPackage package;
-
- modData.ModFiles.TryGetPackageContaining(filename, out package, out name);
+ modData.ModFiles.TryGetPackageContaining(filename, out var package, out var name);
name = package.Name + "/" + name;
Console.WriteLine("# {0}:", name);
diff --git a/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs b/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs
index 1f7da7b0fb..ef0de63987 100644
--- a/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs
+++ b/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs
@@ -25,7 +25,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
return PrintUsage();
var invalid = false;
- byte component;
for (int i = 1; i < args.Length; i++)
{
var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries);
@@ -38,7 +37,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
foreach (var part in parts)
{
- if (!byte.TryParse(part, out component))
+ if (!byte.TryParse(part, out var component))
{
invalid = true;
Console.WriteLine("Invalid component in color (argument " + i + "): [" + part + "]: " + args[i]);
@@ -114,7 +113,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
return PrintUsage();
var invalid = false;
- byte component;
for (int i = 1; i < args.Length; i++)
{
var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries);
@@ -127,7 +125,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
foreach (var part in parts)
{
- if (!byte.TryParse(part, out component))
+ if (!byte.TryParse(part, out var component))
{
invalid = true;
Console.WriteLine("Invalid component in color (argument " + i + "): [" + part + "]: " + args[i]);
diff --git a/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs
index 03e2bffb5d..dc051ccab7 100644
--- a/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs
+++ b/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs
@@ -202,8 +202,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
try
{
- YamlFileSet mapFiles;
- var mapSteps = UpdateUtils.UpdateMap(modData, package, rule, out mapFiles, mapExternalFilenames);
+ var mapSteps = UpdateUtils.UpdateMap(modData, package, rule, out var mapFiles, mapExternalFilenames);
allFiles.AddRange(mapFiles);
if (mapSteps.Any())
diff --git a/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs b/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs
index 7ce6dd65b5..a8ebe75d6e 100644
--- a/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs
+++ b/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs
@@ -63,8 +63,7 @@ namespace OpenRA.Mods.Common.Warheads
if (cellActors.Any(a => !IsValidAgainst(a, firedBy)))
continue;
- SmudgeLayer smudgeLayer;
- if (!smudgeLayers.TryGetValue(smudgeType, out smudgeLayer))
+ if (!smudgeLayers.TryGetValue(smudgeType, out var smudgeLayer))
throw new NotImplementedException("Unknown smudge type `{0}`".F(smudgeType));
smudgeLayer.AddSmudge(sc);
diff --git a/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs b/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs
index abf3565096..bcb609e66a 100644
--- a/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs
+++ b/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs
@@ -235,9 +235,7 @@ namespace OpenRA.Mods.Common.Widgets
public void Set(Color color)
{
- float h, s, v;
- int a;
- color.ToAhsv(out a, out h, out s, out v);
+ color.ToAhsv(out var a, out var h, out var s, out var v);
if (H != h || S != s || V != v)
{
diff --git a/OpenRA.Mods.Common/Widgets/LabelWidget.cs b/OpenRA.Mods.Common/Widgets/LabelWidget.cs
index 9baf17e6f6..a174abfd70 100644
--- a/OpenRA.Mods.Common/Widgets/LabelWidget.cs
+++ b/OpenRA.Mods.Common/Widgets/LabelWidget.cs
@@ -68,8 +68,7 @@ namespace OpenRA.Mods.Common.Widgets
public override void Draw()
{
- SpriteFont font;
- if (!Game.Renderer.Fonts.TryGetValue(Font, out font))
+ if (!Game.Renderer.Fonts.TryGetValue(Font, out var font))
throw new ArgumentException("Requested font '{0}' was not found.".F(Font));
var text = GetText();
diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs
index 18c8a2e3e8..d7095a914c 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs
@@ -272,10 +272,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Select the first visible
var firstVisible = assetVisByName.FirstOrDefault(kvp => kvp.Value);
- IReadOnlyPackage package;
- string filename;
- if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out package, out filename))
+ if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out var package, out var filename))
LoadAsset(package, filename);
}
@@ -290,8 +288,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
item.IsVisible = () =>
{
- bool visible;
- if (assetVisByName.TryGetValue(filepath, out visible))
+ if (assetVisByName.TryGetValue(filepath, out var visible))
return visible;
visible = FilterAsset(filepath);
diff --git a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs
index cc2b857c55..88aa6dc1d7 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs
@@ -27,8 +27,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action onChange,
Dictionary logicArgs)
{
- string actorType;
- if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out actorType))
+ if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out string actorType))
actorType = ChromeMetrics.Get("ColorPickerActorType");
var preview = widget.GetOrNull("PREVIEW");
@@ -103,8 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var palettePresetRows = 2;
var paletteCustomRows = 1;
- MiniYaml yaml;
- if (logicArgs.TryGetValue("PaletteColumns", out yaml))
+ if (logicArgs.TryGetValue("PaletteColumns", out var yaml))
if (!int.TryParse(yaml.Value, out paletteCols))
throw new YamlException("Invalid value for PaletteColumns: {0}".F(yaml.Value));
if (logicArgs.TryGetValue("PalettePresetRows", out yaml))
@@ -189,9 +187,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static float HueFromColor(Color c)
{
- float h, s, v;
- int a;
- c.ToAhsv(out a, out h, out s, out v);
+ c.ToAhsv(out var a, out var h, out var s, out var v);
return h;
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs
index 8568babda8..7cbe9016fa 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs
@@ -106,8 +106,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
actorIDErrorLabel.GetText = () => actorIDStatus == ActorIDStatus.Duplicate ?
"Duplicate Actor ID" : "Enter an Actor ID";
- MiniYaml yaml;
- if (logicArgs.TryGetValue("EditPanelPadding", out yaml))
+ if (logicArgs.TryGetValue("EditPanelPadding", out var yaml))
editPanelPadding = FieldLoader.GetValue("EditPanelPadding", yaml.Value);
okButton.IsDisabled = () => !IsValid() || !editActorPreview.IsDirty;
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs
index a9022ceee9..3d196df2a5 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs
@@ -45,9 +45,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
panel.Get("CREATE_BUTTON").OnClick = () =>
{
- int width, height;
- int.TryParse(widthTextField.Text, out width);
- int.TryParse(heightTextField.Text, out height);
+ int.TryParse(widthTextField.Text, out var width);
+ int.TryParse(heightTextField.Text, out var height);
// Require at least a 2x2 playable area so that the
// ground is visible through the edge shroud
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs
index 0c3d0636cd..d3340c723a 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs
@@ -19,8 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public AddFactionSuffixLogic(Widget widget, World world)
{
- string faction;
- if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out faction))
+ if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out string faction))
faction = world.LocalPlayer.Faction.InternalName;
var suffix = "-" + faction;
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs
index 82bb7fded7..b80f361401 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs
@@ -36,8 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
selection = world.Selection;
this.world = world;
- MiniYaml yaml;
- if (logicArgs.TryGetValue("ClickSound", out yaml))
+ if (logicArgs.TryGetValue("ClickSound", out var yaml))
clickSound = yaml.Value;
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
index 5c74590142..cb6b6801f2 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
@@ -209,8 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
- MiniYaml yaml;
- if (logicArgs.TryGetValue("ChatLineSound", out yaml))
+ if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
chatLineSound = yaml.Value;
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs
index e49719928a..dc732049db 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs
@@ -74,20 +74,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
buttonContainer.RemoveChild(buttonTemplate);
buttonContainer.IsVisible = () => !hideMenu;
- MiniYaml buttonStrideNode;
- if (logicArgs.TryGetValue("ButtonStride", out buttonStrideNode))
+ if (logicArgs.TryGetValue("ButtonStride", out var buttonStrideNode))
buttonStride = FieldLoader.GetValue("ButtonStride", buttonStrideNode.Value);
var scriptContext = world.WorldActor.TraitOrDefault();
hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
- MiniYaml buttonsNode;
- if (logicArgs.TryGetValue("Buttons", out buttonsNode))
+ if (logicArgs.TryGetValue("Buttons", out var buttonsNode))
{
- Action createHandler;
var buttonIds = FieldLoader.GetValue("Buttons", buttonsNode.Value);
foreach (var button in buttonIds)
- if (buttonHandlers.TryGetValue(button, out createHandler))
+ if (buttonHandlers.TryGetValue(button, out var createHandler))
createHandler();
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs
index 960f3f80d9..57ab772a0c 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs
@@ -35,8 +35,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
worldRoot = Ui.Root.Get("WORLD_ROOT");
menuRoot = Ui.Root.Get("MENU_ROOT");
- MiniYaml yaml;
-
// System buttons
var options = widget.GetOrNull("OPTIONS_BUTTON");
if (options != null)
@@ -85,7 +83,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
- if (logicArgs.TryGetValue("ClickSound", out yaml))
+ if (logicArgs.TryGetValue("ClickSound", out var yaml))
clickSound = yaml.Value;
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs
index 1963365b12..3d43851293 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs
@@ -76,8 +76,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
this.world = world;
- MiniYaml yaml;
- if (logicArgs.TryGetValue("CombinedViewKey", out yaml))
+ if (logicArgs.TryGetValue("CombinedViewKey", out var yaml))
combinedViewKey = modData.Hotkeys[yaml.Value];
if (logicArgs.TryGetValue("WorldViewKey", out yaml))
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs
index 23b8855dac..fb10ee7237 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs
@@ -165,8 +165,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static string ActorName(Ruleset rules, string a)
{
- ActorInfo ai;
- if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai))
+ if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out var ai))
{
var actorTooltip = ai.TraitInfos().FirstOrDefault(info => info.EnabledByDefault);
if (actorTooltip != null)
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
index 0896a4af7c..a6a362f030 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
@@ -450,8 +450,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (skirmishMode)
addBotOnMapLoad = true;
- MiniYaml yaml;
- if (logicArgs.TryGetValue("ChatLineSound", out yaml))
+ if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
chatLineSound = yaml.Value;
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs
index cc14c5b90b..cdd85b8556 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs
@@ -138,8 +138,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var getOptionLabel = new CachedTransform(id =>
{
- string value;
- if (id == null || !option.Values.TryGetValue(id, out value))
+ if (id == null || !option.Values.TryGetValue(id, out var value))
return "Not Available";
return value;
diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs
index ad10d21c39..a89a15aa84 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs
@@ -215,8 +215,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void EnumerateMaps(MapClassification tab, ScrollItemWidget template)
{
- int playerCountFilter;
- if (!int.TryParse(mapFilter, out playerCountFilter))
+ if (!int.TryParse(mapFilter, out var playerCountFilter))
playerCountFilter = -1;
var maps = tabMaps[tab]
diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs
index 396422ac1c..4885aaca2f 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs
@@ -26,9 +26,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
musicPlaylist = world.WorldActor.Trait();
- MiniYaml yaml;
var stopKey = new HotkeyReference();
- if (logicArgs.TryGetValue("StopMusicKey", out yaml))
+ if (logicArgs.TryGetValue("StopMusicKey", out var yaml))
stopKey = modData.Hotkeys[yaml.Value];
var pauseKey = new HotkeyReference();
diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs
index f4af9ded43..806ed8e111 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs
@@ -177,8 +177,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void CreateAndJoin()
{
var name = Settings.SanitizedServerName(panel.Get("SERVER_NAME").Text);
- int listenPort;
- if (!Exts.TryParseIntegerInvariant(panel.Get("LISTEN_PORT").Text, out listenPort))
+ if (!Exts.TryParseIntegerInvariant(panel.Get("LISTEN_PORT").Text, out var listenPort))
listenPort = 1234;
var passwordField = panel.GetOrNull("PASSWORD");
diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
index 01ef10bd20..f62ce85476 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
@@ -370,9 +370,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return () =>
{
- int x, y;
- Exts.TryParseIntegerInvariant(windowWidth.Text, out x);
- Exts.TryParseIntegerInvariant(windowHeight.Text, out y);
+ Exts.TryParseIntegerInvariant(windowWidth.Text, out var x);
+ Exts.TryParseIntegerInvariant(windowHeight.Text, out var y);
ds.WindowedSize = new int2(x, y);
nameTextfield.YieldKeyboardFocus();
};
@@ -590,8 +589,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Func returnTrue = () => true;
Action doNothing = () => { };
- MiniYaml hotkeyGroups;
- if (logicArgs.TryGetValue("HotkeyGroups", out hotkeyGroups))
+ if (logicArgs.TryGetValue("HotkeyGroups", out var hotkeyGroups))
{
InitHotkeyRemapDialog(panel);
diff --git a/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs
index 7919194ba8..5d8a079009 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs
@@ -18,10 +18,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
protected SingleHotkeyBaseLogic(Widget widget, ModData modData, string argName, string parentName, Dictionary logicArgs)
{
- MiniYaml yaml;
-
var namedKey = new HotkeyReference();
- if (logicArgs.TryGetValue(argName, out yaml))
+ if (logicArgs.TryGetValue(argName, out var yaml))
namedKey = modData.Hotkeys[yaml.Value];
var keyhandler = widget.Get(parentName);
diff --git a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs
index 6faf6fe56c..5c26f7d403 100644
--- a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs
+++ b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs
@@ -295,8 +295,7 @@ namespace OpenRA.Mods.Common.Widgets
{
// Queue a new item
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Sounds", ClickSound, null);
- string notification;
- var canQueue = CurrentQueue.CanQueue(buildable, out notification);
+ var canQueue = CurrentQueue.CanQueue(buildable, out var notification);
if (!CurrentQueue.AllQueued().Any())
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", notification, World.LocalPlayer.Faction.InternalName);
diff --git a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs
index 0a097c450c..51e733d482 100644
--- a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs
+++ b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs
@@ -64,8 +64,7 @@ namespace OpenRA.Mods.D2k.PackageLoaders
public Stream GetStream(string filename)
{
- Entry e;
- if (!index.TryGetValue(filename, out e))
+ if (!index.TryGetValue(filename, out var e))
return null;
return SegmentStream.CreateWithoutOwningStream(s, e.Offset, (int)e.Length);
diff --git a/OpenRA.Mods.D2k/Traits/World/D2kResourceRenderer.cs b/OpenRA.Mods.D2k/Traits/World/D2kResourceRenderer.cs
index 1aa9eeba43..e3cf3582ac 100644
--- a/OpenRA.Mods.D2k/Traits/World/D2kResourceRenderer.cs
+++ b/OpenRA.Mods.D2k/Traits/World/D2kResourceRenderer.cs
@@ -166,7 +166,6 @@ namespace OpenRA.Mods.D2k.Traits
return;
var clear = FindClearSides(renderType, cell);
- int index;
if (clear == ClearSides.None)
{
@@ -175,7 +174,7 @@ namespace OpenRA.Mods.D2k.Traits
UpdateSpriteLayers(cell, renderType.Variants.First().Value, sprites[frame], renderType.Palette);
}
- else if (SpriteMap.TryGetValue(clear, out index))
+ else if (SpriteMap.TryGetValue(clear, out var index))
{
UpdateSpriteLayers(cell, renderType.Variants.First().Value, index, renderType.Palette);
}
diff --git a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs
index 81c339a6e4..283d80df00 100644
--- a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs
+++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs
@@ -242,8 +242,7 @@ namespace OpenRA.Platforms.Default
atten = 0.66f * ((PoolSize - activeCount * 0.5f) / PoolSize);
}
- uint source;
- if (!TryGetSourceFromPool(out source))
+ if (!TryGetSourceFromPool(out var source))
return null;
var slot = sourcePool[source];
@@ -259,8 +258,7 @@ namespace OpenRA.Platforms.Default
{
var currFrame = Game.LocalTick;
- uint source;
- if (!TryGetSourceFromPool(out source))
+ if (!TryGetSourceFromPool(out var source))
return null;
var slot = sourcePool[source];
@@ -295,8 +293,7 @@ namespace OpenRA.Platforms.Default
void PauseSound(uint source, bool paused)
{
- int state;
- AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE, out state);
+ AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE, out var state);
if (paused)
{
if (state == AL10.AL_PLAYING)
@@ -317,8 +314,7 @@ namespace OpenRA.Platforms.Default
{
var sounds = sourcePool.Keys.Where(key =>
{
- int state;
- AL10.alGetSourcei(key, AL10.AL_SOURCE_STATE, out state);
+ AL10.alGetSourcei(key, AL10.AL_SOURCE_STATE, out var state);
return (state == AL10.AL_PLAYING || state == AL10.AL_PAUSED) &&
(music == null || key != ((OpenAlSound)music).Source) &&
(video == null || key != ((OpenAlSound)video).Source);
@@ -449,7 +445,7 @@ namespace OpenRA.Platforms.Default
public float Volume
{
- get { float volume; AL10.alGetSourcef(Source, AL10.AL_GAIN, out volume); return volume; }
+ get { AL10.alGetSourcef(Source, AL10.AL_GAIN, out var volume); return volume; }
set { AL10.alSourcef(Source, AL10.AL_GAIN, value); }
}
@@ -457,8 +453,7 @@ namespace OpenRA.Platforms.Default
{
get
{
- int sampleOffset;
- AL10.alGetSourcei(Source, AL11.AL_SAMPLE_OFFSET, out sampleOffset);
+ AL10.alGetSourcei(Source, AL11.AL_SAMPLE_OFFSET, out var sampleOffset);
return sampleOffset / SampleRate;
}
}
@@ -467,8 +462,7 @@ namespace OpenRA.Platforms.Default
{
get
{
- int state;
- AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
+ AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
return state == AL10.AL_STOPPED;
}
}
@@ -480,8 +474,7 @@ namespace OpenRA.Platforms.Default
protected void StopSource()
{
- int state;
- AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
+ AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
if (state == AL10.AL_PLAYING || state == AL10.AL_PAUSED)
AL10.alSourceStop(Source);
}
@@ -554,8 +547,7 @@ namespace OpenRA.Platforms.Default
// TODO: A race condition can happen between the state check and playing/rewinding if a
// user pauses/resumes at the right moment. The window of opportunity is small and the
// consequences are minor, so for now we'll ignore it.
- int state;
- AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
+ AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
if (state != AL10.AL_STOPPED)
AL10.alSourcePlay(source);
else
@@ -575,8 +567,7 @@ namespace OpenRA.Platforms.Default
// has stopped.
var currentSeek = SeekPosition;
- int state;
- AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out state);
+ AL10.alGetSourcei(Source, AL10.AL_SOURCE_STATE, out var state);
if (state == AL10.AL_STOPPED)
break;
diff --git a/OpenRA.Platforms.Default/OpenGL.cs b/OpenRA.Platforms.Default/OpenGL.cs
index f109698beb..7f49bb34ad 100644
--- a/OpenRA.Platforms.Default/OpenGL.cs
+++ b/OpenRA.Platforms.Default/OpenGL.cs
@@ -719,8 +719,7 @@ namespace OpenRA.Platforms.Default
if (Profile != GLProfile.Legacy)
{
- int extensionCount;
- glGetIntegerv(GL_NUM_EXTENSIONS, out extensionCount);
+ glGetIntegerv(GL_NUM_EXTENSIONS, out var extensionCount);
for (var i = 0; i < extensionCount; i++)
Log.Write("graphics", glGetStringi(GL_EXTENSIONS, (uint)i));
}
diff --git a/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs b/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs
index c855583d3d..80287f1dda 100644
--- a/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs
+++ b/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs
@@ -40,8 +40,7 @@ namespace OpenRA.Platforms.Default
if (OpenGL.Profile != GLProfile.Legacy)
{
- uint vao;
- OpenGL.glGenVertexArrays(1, out vao);
+ OpenGL.glGenVertexArrays(1, out var vao);
OpenGL.CheckGLError();
OpenGL.glBindVertexArray(vao);
OpenGL.CheckGLError();
diff --git a/OpenRA.Platforms.Default/Sdl2Input.cs b/OpenRA.Platforms.Default/Sdl2Input.cs
index 15b684f4ec..4e853369e0 100644
--- a/OpenRA.Platforms.Default/Sdl2Input.cs
+++ b/OpenRA.Platforms.Default/Sdl2Input.cs
@@ -67,8 +67,7 @@ namespace OpenRA.Platforms.Default
inputHandler.ModifierKeys(mods);
MouseInput? pendingMotion = null;
- SDL.SDL_Event e;
- while (SDL.SDL_PollEvent(out e) != 0)
+ while (SDL.SDL_PollEvent(out var e) != 0)
{
switch (e.type)
{
@@ -160,8 +159,7 @@ namespace OpenRA.Platforms.Default
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
{
- int x, y;
- SDL.SDL_GetMouseState(out x, out y);
+ SDL.SDL_GetMouseState(out var x, out var y);
var pos = EventPosition(device, x, y);
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, pos, new int2(0, e.wheel.y), mods, 0));
diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs
index e88f1d1c41..cc653d9674 100644
--- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs
+++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs
@@ -167,16 +167,14 @@ namespace OpenRA.Platforms.Default
if (videoDisplay < 0 || videoDisplay >= DisplayCount)
videoDisplay = 0;
- SDL.SDL_DisplayMode display;
- SDL.SDL_GetCurrentDisplayMode(videoDisplay, out display);
+ SDL.SDL_GetCurrentDisplayMode(videoDisplay, out var display);
// Windows and Linux define window sizes in native pixel units.
// Query the display/dpi scale so we can convert our requested effective size to pixels.
// This is not necessary on macOS, which defines window sizes in effective units ("points").
if (Platform.CurrentPlatform == PlatformType.Windows)
{
- float ddpi, hdpi, vdpi;
- if (SDL.SDL_GetDisplayDPI(videoDisplay, out ddpi, out hdpi, out vdpi) == 0)
+ if (SDL.SDL_GetDisplayDPI(videoDisplay, out var ddpi, out var hdpi, out var vdpi) == 0)
windowScale = ddpi / 96;
}
else if (Platform.CurrentPlatform != PlatformType.OSX)
@@ -195,9 +193,8 @@ namespace OpenRA.Platforms.Default
var p = Process.Start(psi);
var lines = p.StandardOutput.ReadToEnd().Split('\n');
- int dpi;
foreach (var line in lines)
- if (line.StartsWith("Xft.dpi") && int.TryParse(line.Substring(8), out dpi))
+ if (line.StartsWith("Xft.dpi") && int.TryParse(line.Substring(8), out var dpi))
windowScale = dpi / 96f;
}
catch { }
@@ -228,8 +225,7 @@ namespace OpenRA.Platforms.Default
// (if dark mode is enabled) unless we drain the event queue before initializing GL
if (Platform.CurrentPlatform == PlatformType.OSX)
{
- SDL.SDL_Event e;
- while (SDL.SDL_PollEvent(out e) != 0)
+ while (SDL.SDL_PollEvent(out var e) != 0)
{
// We can safely ignore all mouse/keyboard events and window size changes
// (these will be caught in the window setup below), but do need to process focus
@@ -254,9 +250,7 @@ namespace OpenRA.Platforms.Default
{
// OSX defines the window size in "points", with a device-dependent number of pixels per point.
// The window scale is simply the ratio of GL pixels / window points.
- int width, height;
-
- SDL.SDL_GL_GetDrawableSize(Window, out width, out height);
+ SDL.SDL_GL_GetDrawableSize(Window, out var width, out var height);
surfaceSize = new Size(width, height);
windowScale = width * 1f / windowSize.Width;
}
@@ -282,8 +276,7 @@ namespace OpenRA.Platforms.Default
// This is usually not what the player wants, but is the best we can consistently do.
if (Platform.CurrentPlatform == PlatformType.OSX)
{
- int width, height;
- SDL.SDL_GetWindowSize(Window, out width, out height);
+ SDL.SDL_GetWindowSize(Window, out var width, out var height);
windowSize = surfaceSize = new Size(width, height);
windowScale = 1;
}
@@ -380,8 +373,7 @@ namespace OpenRA.Platforms.Default
{
if (mode)
{
- int x, y;
- SDL.SDL_GetMouseState(out x, out y);
+ SDL.SDL_GetMouseState(out var x, out var y);
lockedMousePosition = new int2(x, y);
}
else
@@ -399,8 +391,7 @@ namespace OpenRA.Platforms.Default
// We need to recalculate our scale to account for the potential change in the actual rendered area
if (Platform.CurrentPlatform == PlatformType.OSX)
{
- int width, height;
- SDL.SDL_GL_GetDrawableSize(Window, out width, out height);
+ SDL.SDL_GL_GetDrawableSize(Window, out var width, out var height);
if (width != SurfaceSize.Width || height != SurfaceSize.Height)
{
diff --git a/OpenRA.Platforms.Default/Shader.cs b/OpenRA.Platforms.Default/Shader.cs
index 6cb1ea804c..55ec199fd8 100644
--- a/OpenRA.Platforms.Default/Shader.cs
+++ b/OpenRA.Platforms.Default/Shader.cs
@@ -51,16 +51,13 @@ namespace OpenRA.Platforms.Default
OpenGL.CheckGLError();
OpenGL.glCompileShader(shader);
OpenGL.CheckGLError();
- int success;
- OpenGL.glGetShaderiv(shader, OpenGL.GL_COMPILE_STATUS, out success);
+ OpenGL.glGetShaderiv(shader, OpenGL.GL_COMPILE_STATUS, out var success);
OpenGL.CheckGLError();
if (success == OpenGL.GL_FALSE)
{
- int len;
- OpenGL.glGetShaderiv(shader, OpenGL.GL_INFO_LOG_LENGTH, out len);
+ OpenGL.glGetShaderiv(shader, OpenGL.GL_INFO_LOG_LENGTH, out var len);
var log = new StringBuilder(len);
- int length;
- OpenGL.glGetShaderInfoLog(shader, len, out length, log);
+ OpenGL.glGetShaderInfoLog(shader, len, out var length, log);
Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
throw new InvalidProgramException("Compile error in shader object '{0}'".F(filename));
@@ -100,17 +97,14 @@ namespace OpenRA.Platforms.Default
OpenGL.glLinkProgram(program);
OpenGL.CheckGLError();
- int success;
- OpenGL.glGetProgramiv(program, OpenGL.GL_LINK_STATUS, out success);
+ OpenGL.glGetProgramiv(program, OpenGL.GL_LINK_STATUS, out var success);
OpenGL.CheckGLError();
if (success == OpenGL.GL_FALSE)
{
- int len;
- OpenGL.glGetProgramiv(program, OpenGL.GL_INFO_LOG_LENGTH, out len);
+ OpenGL.glGetProgramiv(program, OpenGL.GL_INFO_LOG_LENGTH, out var len);
var log = new StringBuilder(len);
- int length;
- OpenGL.glGetProgramInfoLog(program, len, out length, log);
+ OpenGL.glGetProgramInfoLog(program, len, out var length, log);
Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
throw new InvalidProgramException("Link error in shader program '{0}'".F(name));
}
@@ -118,18 +112,15 @@ namespace OpenRA.Platforms.Default
OpenGL.glUseProgram(program);
OpenGL.CheckGLError();
- int numUniforms;
- OpenGL.glGetProgramiv(program, OpenGL.GL_ACTIVE_UNIFORMS, out numUniforms);
+ OpenGL.glGetProgramiv(program, OpenGL.GL_ACTIVE_UNIFORMS, out var numUniforms);
OpenGL.CheckGLError();
var nextTexUnit = 0;
for (var i = 0; i < numUniforms; i++)
{
- int length, size;
- int type;
var sb = new StringBuilder(128);
- OpenGL.glGetActiveUniform(program, i, 128, out length, out size, out type, sb);
+ OpenGL.glGetActiveUniform(program, i, 128, out var length, out var size, out var type, sb);
var sampler = sb.ToString();
OpenGL.CheckGLError();
@@ -172,8 +163,7 @@ namespace OpenRA.Platforms.Default
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, texture.ID);
// Work around missing textureSize GLSL function by explicitly tracking sizes in a uniform
- int param;
- if (OpenGL.Profile == GLProfile.Legacy && legacySizeUniforms.TryGetValue(kv.Key, out param))
+ if (OpenGL.Profile == GLProfile.Legacy && legacySizeUniforms.TryGetValue(kv.Key, out var param))
{
OpenGL.glUniform2f(param, texture.Size.Width, texture.Size.Height);
OpenGL.CheckGLError();
@@ -195,8 +185,7 @@ namespace OpenRA.Platforms.Default
if (t == null)
return;
- int texUnit;
- if (samplers.TryGetValue(name, out texUnit))
+ if (samplers.TryGetValue(name, out var texUnit))
textures[texUnit] = t;
}
diff --git a/OpenRA.Platforms.Default/Texture.cs b/OpenRA.Platforms.Default/Texture.cs
index 88d8c32d7f..944a166e0c 100644
--- a/OpenRA.Platforms.Default/Texture.cs
+++ b/OpenRA.Platforms.Default/Texture.cs
@@ -122,11 +122,9 @@ namespace OpenRA.Platforms.Default
if (OpenGL.Profile == GLProfile.Embedded)
{
// Query the active framebuffer so we can restore it afterwards
- int lastFramebuffer;
- OpenGL.glGetIntegerv(OpenGL.GL_FRAMEBUFFER_BINDING, out lastFramebuffer);
+ OpenGL.glGetIntegerv(OpenGL.GL_FRAMEBUFFER_BINDING, out var lastFramebuffer);
- uint framebuffer;
- OpenGL.glGenFramebuffers(1, out framebuffer);
+ OpenGL.glGenFramebuffers(1, out var framebuffer);
OpenGL.glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, framebuffer);
OpenGL.CheckGLError();