Use out var syntax
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -57,10 +57,7 @@ namespace OpenRA.Mods.Common
|
||||
public bool IsValid(Color askedColor, out Color forbiddenColor, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, HashSet<string> 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<Color> terrainColors, IEnumerable<Color> 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<string>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<KeyValuePair<string, string>> GetEnumerator()
|
||||
|
||||
@@ -394,8 +394,7 @@ namespace OpenRA.Mods.Common.FileFormats
|
||||
|
||||
public void ExtractFile(string filename, Stream output, Action<int> 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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -53,10 +53,9 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
var sequences = new Dictionary<string, ISpriteSequence>();
|
||||
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<T>(Dictionary<string, MiniYaml> d, string key, T fallback)
|
||||
{
|
||||
MiniYaml value;
|
||||
if (d.TryGetValue(key, out value))
|
||||
if (d.TryGetValue(key, out var value))
|
||||
return FieldLoader.GetValue<T>(key, value.Value);
|
||||
|
||||
return fallback;
|
||||
@@ -174,8 +172,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
Func<int, IEnumerable<int>> 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<Sprite>();
|
||||
foreach (var sub in combine.Nodes)
|
||||
@@ -262,8 +258,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
Func<int, IEnumerable<int>> 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);
|
||||
|
||||
@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
: base(modData)
|
||||
{
|
||||
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().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;
|
||||
|
||||
@@ -89,9 +89,8 @@ namespace OpenRA.Mods.Common.Lint
|
||||
var type = modData.ObjectCreator.FindType(widgetType + "Widget");
|
||||
var keyNames = checkMethods.SelectMany(m => (IEnumerable<string>)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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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(", ")));
|
||||
}
|
||||
|
||||
@@ -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<ModContent>(Game.ModData.ObjectCreator);
|
||||
|
||||
@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
||||
|
||||
public List<CPos> Retrieve(string key)
|
||||
{
|
||||
CachedPath cached;
|
||||
if (cachedPaths.TryGetValue(key, out cached))
|
||||
if (cachedPaths.TryGetValue(key, out var cached))
|
||||
{
|
||||
if (IsExpired(cached))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<BuildableInfo>();
|
||||
@@ -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<ICruiseAltitudeInfo>();
|
||||
@@ -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<ValuedInfo>();
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -183,8 +183,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (autotarget == null)
|
||||
return;
|
||||
|
||||
UnitStance stance;
|
||||
if (!Enum<UnitStance>.TryParse(value, true, out stance))
|
||||
if (!Enum<UnitStance>.TryParse(value, true, out var stance))
|
||||
throw new LuaException("Unknown stance type '{0}'".F(value));
|
||||
|
||||
autotarget.PredictedStance = stance;
|
||||
|
||||
@@ -77,8 +77,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var result = new List<Actor>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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<BuildableInfo>();
|
||||
|
||||
@@ -92,8 +92,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
var cmdName = cmd.Split(' ').First();
|
||||
var cmdValue = cmd.Split(' ').Skip(1).JoinWith(" ");
|
||||
|
||||
Func<S, Connection, Session.Client, string, bool> 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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
|
||||
offsets = new List<float2>();
|
||||
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(';');
|
||||
|
||||
@@ -21,8 +21,7 @@ namespace OpenRA.Mods.Common
|
||||
/// /// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(Explosion))
|
||||
return;
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = Explosion.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
ExplosionWeapon = weapon;
|
||||
|
||||
@@ -87,10 +87,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
WeaponInfo weaponInfo;
|
||||
|
||||
var weaponToLower = Weapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weaponInfo))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weaponInfo))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
WeaponInfo = weaponInfo;
|
||||
|
||||
@@ -108,8 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// requestedTargetPresetForActivity will be cleared once the activity starts running and calls UpdateRequestedTarget
|
||||
if (self.CurrentActivity != null && self.CurrentActivity.NextActivity == requestedTargetPresetForActivity)
|
||||
{
|
||||
bool targetIsHiddenActor;
|
||||
RequestedTarget = RequestedTarget.Recalculate(self.Owner, out targetIsHiddenActor);
|
||||
RequestedTarget = RequestedTarget.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||
}
|
||||
|
||||
// Requested activity has been canceled
|
||||
@@ -271,8 +270,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (attack.IsTraitPaused)
|
||||
return false;
|
||||
|
||||
bool targetIsHiddenActor;
|
||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
||||
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||
attack.SetRequestedTarget(self, target, forceAttack);
|
||||
hasTicked = true;
|
||||
|
||||
|
||||
@@ -171,8 +171,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (conditionToken != Actor.InvalidConditionToken)
|
||||
conditionToken = self.RevokeCondition(conditionToken);
|
||||
|
||||
string condition;
|
||||
if (Info.ConditionByStance.TryGetValue(stance, out condition))
|
||||
if (Info.ConditionByStance.TryGetValue(stance, out var condition))
|
||||
conditionToken = self.GrantCondition(condition);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
|
||||
protected static bool NearToPosSafely(Squad owner, WPos loc)
|
||||
{
|
||||
Actor a;
|
||||
return NearToPosSafely(owner, loc, out a);
|
||||
return NearToPosSafely(owner, loc, out var a);
|
||||
}
|
||||
|
||||
protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget)
|
||||
|
||||
@@ -223,8 +223,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var n in waitingPowersNode.Value.Nodes)
|
||||
{
|
||||
SupportPowerInstance instance;
|
||||
if (supportPowerManager.Powers.TryGetValue(n.Key, out instance))
|
||||
if (supportPowerManager.Powers.TryGetValue(n.Key, out var instance))
|
||||
waitingPowers[instance] = FieldLoader.GetValue<int>("WaitingPowers", n.Value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(DemolishWeapon))
|
||||
throw new YamlException("A value for DemolishWeapon of a Bridge trait is missing.");
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = DemolishWeapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
DemolishWeaponInfo = weapon;
|
||||
|
||||
@@ -60,10 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void DoDelivery(CPos location, string actorName, string carrierActorName)
|
||||
{
|
||||
Actor cargo;
|
||||
Actor carrier;
|
||||
|
||||
CreateActors(actorName, carrierActorName, out cargo, out carrier);
|
||||
CreateActors(actorName, carrierActorName, out var cargo, out var carrier);
|
||||
|
||||
var carryable = cargo.Trait<Carryable>();
|
||||
carryable.Reserve(cargo, carrier);
|
||||
|
||||
@@ -36,9 +36,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = (DemolishWeapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
DemolishWeaponInfo = weapon;
|
||||
|
||||
@@ -171,11 +171,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (cargo.Any())
|
||||
{
|
||||
foreach (var c in cargo)
|
||||
{
|
||||
string passengerCondition;
|
||||
if (Info.PassengerConditions.TryGetValue(c.Info.Name, out passengerCondition))
|
||||
if (Info.PassengerConditions.TryGetValue(c.Info.Name, out var passengerCondition))
|
||||
passengerTokens.GetOrAdd(c.Info.Name).Push(self.GrantCondition(passengerCondition));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Info.LoadedCondition))
|
||||
loadedTokens.Push(self.GrantCondition(Info.LoadedCondition));
|
||||
@@ -353,8 +350,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var p = passenger.Trait<Passenger>();
|
||||
p.Transport = null;
|
||||
|
||||
Stack<int> passengerToken;
|
||||
if (passengerTokens.TryGetValue(passenger.Info.Name, out passengerToken) && passengerToken.Any())
|
||||
if (passengerTokens.TryGetValue(passenger.Info.Name, out var passengerToken) && passengerToken.Any())
|
||||
self.RevokeCondition(passengerToken.Pop());
|
||||
|
||||
if (loadedTokens.Any())
|
||||
@@ -400,8 +396,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
npe.OnPassengerEntered(self, a);
|
||||
}
|
||||
|
||||
string passengerCondition;
|
||||
if (Info.PassengerConditions.TryGetValue(a.Info.Name, out passengerCondition))
|
||||
if (Info.PassengerConditions.TryGetValue(a.Info.Name, out var passengerCondition))
|
||||
passengerTokens.GetOrAdd(a.Info.Name).Push(self.GrantCondition(passengerCondition));
|
||||
|
||||
if (!string.IsNullOrEmpty(Info.LoadedCondition))
|
||||
|
||||
@@ -76,11 +76,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Timed tokens do not count towards the source cap: the condition with the shortest
|
||||
// remaining duration can always be revoked to make room.
|
||||
if (Info.SourceCap > 0)
|
||||
{
|
||||
HashSet<int> permanentTokensForSource;
|
||||
if (permanentTokens.TryGetValue(source, out permanentTokensForSource) && permanentTokensForSource.Count >= Info.SourceCap)
|
||||
if (permanentTokens.TryGetValue(source, out var permanentTokensForSource) && permanentTokensForSource.Count >= Info.SourceCap)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Info.TotalCap > 0 && permanentTokens.Values.Sum(t => t.Count) >= Info.TotalCap)
|
||||
return false;
|
||||
@@ -94,8 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return Actor.InvalidConditionToken;
|
||||
|
||||
var token = self.GrantCondition(Info.Condition);
|
||||
HashSet<int> permanent;
|
||||
permanentTokens.TryGetValue(source, out permanent);
|
||||
permanentTokens.TryGetValue(source, out var permanent);
|
||||
|
||||
// Callers can override the amount of time remaining by passing a value
|
||||
// between 1 and the duration
|
||||
@@ -167,8 +163,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
HashSet<int> permanentTokensForSource;
|
||||
if (permanentTokens.TryGetValue(source, out permanentTokensForSource))
|
||||
if (permanentTokens.TryGetValue(source, out var permanentTokensForSource))
|
||||
{
|
||||
if (!permanentTokensForSource.Remove(token))
|
||||
return false;
|
||||
|
||||
@@ -47,8 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void RevokeCondition(Actor self, Actor segment)
|
||||
{
|
||||
int token;
|
||||
if (!tokens.TryGetValue(segment, out token))
|
||||
if (!tokens.TryGetValue(segment, out var token))
|
||||
return;
|
||||
|
||||
tokens.Remove(segment);
|
||||
|
||||
@@ -151,8 +151,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (a.Disposed)
|
||||
return;
|
||||
|
||||
int token;
|
||||
if (!tokens.TryGetValue(a, out token))
|
||||
if (!tokens.TryGetValue(a, out var token))
|
||||
return;
|
||||
|
||||
tokens.Remove(a);
|
||||
|
||||
@@ -60,18 +60,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Weapon))
|
||||
{
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = Weapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
WeaponInfo = weapon;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(EmptyWeapon))
|
||||
{
|
||||
WeaponInfo emptyWeapon;
|
||||
var emptyWeaponToLower = EmptyWeapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(emptyWeaponToLower, out emptyWeapon))
|
||||
if (!rules.Weapons.TryGetValue(emptyWeaponToLower, out var emptyWeapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(emptyWeaponToLower));
|
||||
EmptyWeaponInfo = emptyWeapon;
|
||||
}
|
||||
|
||||
@@ -37,9 +37,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(Weapon))
|
||||
return;
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = Weapon.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
@@ -419,8 +419,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (ToCell.Layer == 0)
|
||||
return true;
|
||||
|
||||
ICustomMovementLayer layer;
|
||||
if (self.World.GetCustomMovementLayers().TryGetValue(ToCell.Layer, out layer))
|
||||
if (self.World.GetCustomMovementLayers().TryGetValue(ToCell.Layer, out var layer))
|
||||
return layer.InteractsWithDefaultLayer;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -129,12 +129,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyEnteredCargo.OnEnteredCargo(Actor self, Actor cargo)
|
||||
{
|
||||
string specificCargoCondition;
|
||||
|
||||
if (anyCargoToken == Actor.InvalidConditionToken)
|
||||
anyCargoToken = self.GrantCondition(Info.CargoCondition);
|
||||
|
||||
if (specificCargoToken == Actor.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out specificCargoCondition))
|
||||
if (specificCargoToken == Actor.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out var specificCargoCondition))
|
||||
specificCargoToken = self.GrantCondition(specificCargoCondition);
|
||||
|
||||
// Allow scripted / initial actors to move from the unload point back into the cell grid on unload
|
||||
|
||||
@@ -69,8 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
{
|
||||
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
|
||||
if (!upgradables.TryGetValue(key, out list))
|
||||
if (!upgradables.TryGetValue(key, out var list))
|
||||
return;
|
||||
|
||||
foreach (var u in list)
|
||||
@@ -79,8 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesUnavailable(string key)
|
||||
{
|
||||
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
|
||||
if (!upgradables.TryGetValue(key, out list))
|
||||
if (!upgradables.TryGetValue(key, out var list))
|
||||
return;
|
||||
|
||||
foreach (var u in list)
|
||||
|
||||
@@ -270,8 +270,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanBuild(ActorInfo actor)
|
||||
{
|
||||
ProductionState ps;
|
||||
if (!Producible.TryGetValue(actor, out ps))
|
||||
if (!Producible.TryGetValue(actor, out var ps))
|
||||
return false;
|
||||
|
||||
return ps.Buildable || developerMode.AllTech;
|
||||
|
||||
@@ -120,8 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void EnablePlug(Actor self, string type)
|
||||
{
|
||||
string condition;
|
||||
if (!Info.Conditions.TryGetValue(type, out condition))
|
||||
if (!Info.Conditions.TryGetValue(type, out var condition))
|
||||
return;
|
||||
|
||||
if (conditionToken != Actor.InvalidConditionToken)
|
||||
|
||||
@@ -78,8 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
// Old is 0 if a is not in powerDrain
|
||||
int old;
|
||||
powerDrain.TryGetValue(a, out old);
|
||||
powerDrain.TryGetValue(a, out var old);
|
||||
|
||||
var amount = a.TraitsImplementing<Power>().Where(t => !t.IsTraitDisabled).Sum(p => p.GetEnabledPower());
|
||||
powerDrain[a] = amount;
|
||||
@@ -106,8 +105,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (a.IsInWorld)
|
||||
return;
|
||||
|
||||
int amount;
|
||||
if (!powerDrain.TryGetValue(a, out amount))
|
||||
if (!powerDrain.TryGetValue(a, out var amount))
|
||||
return;
|
||||
powerDrain.Remove(a);
|
||||
|
||||
|
||||
@@ -80,8 +80,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
bool IProductionIconOverlay.IsOverlayActive(ActorInfo ai)
|
||||
{
|
||||
bool isActive;
|
||||
if (!overlayActive.TryGetValue(ai, out isActive))
|
||||
if (!overlayActive.TryGetValue(ai, out var isActive))
|
||||
return false;
|
||||
|
||||
return isActive;
|
||||
|
||||
@@ -61,12 +61,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
var n = i * harvester.Info.Capacity / Info.PipCount;
|
||||
|
||||
string sequence;
|
||||
foreach (var rt in harvester.Contents)
|
||||
{
|
||||
if (n < rt.Value)
|
||||
{
|
||||
if (!Info.ResourceSequences.TryGetValue(rt.Key.Type, out sequence))
|
||||
if (!Info.ResourceSequences.TryGetValue(rt.Key.Type, out var sequence))
|
||||
sequence = Info.FullSequence;
|
||||
|
||||
return sequence;
|
||||
|
||||
@@ -135,9 +135,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
public void Attacking(Actor self, Target target, Armament a)
|
||||
{
|
||||
string sequence;
|
||||
var info = GetDisplayInfo();
|
||||
if (!info.AttackSequences.TryGetValue(a.Info.Name, out sequence))
|
||||
if (!info.AttackSequences.TryGetValue(a.Info.Name, out var sequence))
|
||||
sequence = info.DefaultAttackSequence;
|
||||
|
||||
if (!string.IsNullOrEmpty(sequence) && DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, sequence)))
|
||||
|
||||
@@ -122,9 +122,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
adjacent = 0;
|
||||
foreach (var a in adjacentActors)
|
||||
{
|
||||
CVec facing;
|
||||
var wc = a.TraitsImplementing<IWallConnector>().FirstEnabledTraitOrDefault();
|
||||
if (wc == null || !wc.AdjacentWallCanConnect(a, self.Location, wallInfo.Type, out facing))
|
||||
if (wc == null || !wc.AdjacentWallCanConnect(a, self.Location, wallInfo.Type, out var facing))
|
||||
continue;
|
||||
|
||||
if (facing.Y > 0)
|
||||
|
||||
@@ -107,9 +107,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!string.IsNullOrEmpty(TrailImage) && !TrailSequences.Any())
|
||||
throw new YamlException("At least one entry in TrailSequences must be defined when TrailImage is defined.");
|
||||
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = (MissileWeapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
@@ -108,8 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
facing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
|
||||
|
||||
var utLower = info.UnitType.ToLowerInvariant();
|
||||
ActorInfo unitType;
|
||||
if (!self.World.Map.Rules.Actors.TryGetValue(utLower, out unitType))
|
||||
if (!self.World.Map.Rules.Actors.TryGetValue(utLower, out var unitType))
|
||||
throw new YamlException("Actors ruleset does not include the entry '{0}'".F(utLower));
|
||||
|
||||
var altitude = unitType.TraitInfo<AircraftInfo>().CruiseAltitude.Length;
|
||||
|
||||
@@ -119,8 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
{
|
||||
SupportPowerInstance sp;
|
||||
if (!Powers.TryGetValue(key, out sp))
|
||||
if (!Powers.TryGetValue(key, out var sp))
|
||||
return;
|
||||
|
||||
sp.PrerequisitesAvailable(true);
|
||||
@@ -128,8 +127,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesUnavailable(string key)
|
||||
{
|
||||
SupportPowerInstance sp;
|
||||
if (!Powers.TryGetValue(key, out sp))
|
||||
if (!Powers.TryGetValue(key, out var sp))
|
||||
return;
|
||||
|
||||
sp.PrerequisitesAvailable(false);
|
||||
|
||||
@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RemoveLightSource(int token)
|
||||
{
|
||||
LightSource source;
|
||||
if (!lightSources.TryGetValue(token, out source))
|
||||
if (!lightSources.TryGetValue(token, out var source))
|
||||
return;
|
||||
|
||||
lightSources.Remove(token);
|
||||
|
||||
@@ -38,9 +38,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
WeaponInfos = Weapons.Select(w =>
|
||||
{
|
||||
WeaponInfo weapon;
|
||||
var weaponToLower = w.ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||
return weapon;
|
||||
}).ToArray();
|
||||
|
||||
@@ -377,8 +377,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var layer = c.Cell.Layer == 0 ? influence : customInfluence[c.Cell.Layer];
|
||||
layer[uv] = new InfluenceNode { Next = layer[uv], SubCell = c.SubCell, Actor = self };
|
||||
|
||||
List<CellTrigger> triggers;
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out triggers))
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out var triggers))
|
||||
foreach (var t in triggers)
|
||||
t.Dirty = true;
|
||||
|
||||
@@ -400,8 +399,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
RemoveInfluenceInner(ref temp, self);
|
||||
layer[uv] = temp;
|
||||
|
||||
List<CellTrigger> triggers;
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out triggers))
|
||||
if (cellTriggerInfluence.TryGetValue(c.Cell, out var triggers))
|
||||
foreach (var t in triggers)
|
||||
t.Dirty = true;
|
||||
|
||||
@@ -487,8 +485,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RemoveCellTrigger(int id)
|
||||
{
|
||||
CellTrigger trigger;
|
||||
if (!cellTriggers.TryGetValue(id, out trigger))
|
||||
if (!cellTriggers.TryGetValue(id, out var trigger))
|
||||
return;
|
||||
|
||||
foreach (var c in trigger.Footprint)
|
||||
@@ -514,8 +511,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void RemoveProximityTrigger(int id)
|
||||
{
|
||||
ProximityTrigger t;
|
||||
if (!proximityTriggers.TryGetValue(id, out t))
|
||||
if (!proximityTriggers.TryGetValue(id, out var t))
|
||||
return;
|
||||
|
||||
foreach (var bin in BinsInBox(t.TopLeft, t.BottomRight))
|
||||
@@ -526,8 +522,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void UpdateProximityTrigger(int id, WPos newPos, WDist newRange, WDist newVRange)
|
||||
{
|
||||
ProximityTrigger t;
|
||||
if (!proximityTriggers.TryGetValue(id, out t))
|
||||
if (!proximityTriggers.TryGetValue(id, out var t))
|
||||
return;
|
||||
|
||||
foreach (var bin in BinsInBox(t.TopLeft, t.BottomRight))
|
||||
|
||||
@@ -163,8 +163,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var cell in footprint)
|
||||
{
|
||||
List<EditorActorPreview> list;
|
||||
if (!cellMap.TryGetValue(cell, out list))
|
||||
if (!cellMap.TryGetValue(cell, out var list))
|
||||
continue;
|
||||
|
||||
list.Remove(preview);
|
||||
@@ -228,8 +227,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void AddPreviewLocation(EditorActorPreview preview, CPos location)
|
||||
{
|
||||
List<EditorActorPreview> list;
|
||||
if (!cellMap.TryGetValue(location, out list))
|
||||
if (!cellMap.TryGetValue(location, out var list))
|
||||
{
|
||||
list = new List<EditorActorPreview>();
|
||||
cellMap.Add(location, list);
|
||||
@@ -256,8 +254,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<EditorActorPreview> PreviewsAt(CPos cell)
|
||||
{
|
||||
List<EditorActorPreview> list;
|
||||
if (cellMap.TryGetValue(cell, out list))
|
||||
if (cellMap.TryGetValue(cell, out var list))
|
||||
return list;
|
||||
|
||||
return Enumerable.Empty<EditorActorPreview>();
|
||||
@@ -274,8 +271,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var blocked = previews.Any(p =>
|
||||
{
|
||||
SubCell s;
|
||||
return p.Footprint.TryGetValue(cell, out s) && s == (SubCell)i;
|
||||
return p.Footprint.TryGetValue(cell, out var s) && s == (SubCell)i;
|
||||
});
|
||||
|
||||
if (!blocked)
|
||||
|
||||
@@ -71,11 +71,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var tile = Map.Resources[uv];
|
||||
var t = Tiles[uv];
|
||||
ResourceType type;
|
||||
|
||||
var newTile = ResourceLayerContents.Empty;
|
||||
var newTerrain = byte.MaxValue;
|
||||
if (Resources.TryGetValue(tile.Type, out type))
|
||||
if (Resources.TryGetValue(tile.Type, out var type))
|
||||
{
|
||||
newTile = new ResourceLayerContents
|
||||
{
|
||||
|
||||
@@ -83,8 +83,7 @@ namespace OpenRA.Mods.Common
|
||||
|
||||
public Color GetRemappedColor(Color original, int index)
|
||||
{
|
||||
int c;
|
||||
return replacements.TryGetValue(index, out c)
|
||||
return replacements.TryGetValue(index, out var c)
|
||||
? basePalette.GetColor(c) : original;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ namespace OpenRA.Mods.Common
|
||||
{
|
||||
var basePalette = wr.Palette(info.BasePalette).Palette;
|
||||
ImmutablePalette pal;
|
||||
int[] remap;
|
||||
|
||||
if (info.PlayerIndex.TryGetValue(playerName, out remap))
|
||||
if (info.PlayerIndex.TryGetValue(playerName, out var remap))
|
||||
pal = new ImmutablePalette(basePalette, new IndexedColorRemap(basePalette, info.RemapIndex, remap));
|
||||
else
|
||||
pal = new ImmutablePalette(basePalette);
|
||||
|
||||
@@ -107,8 +107,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var kvp in TerrainSpeeds)
|
||||
{
|
||||
byte index;
|
||||
if (tileSet.TryGetTerrainIndex(kvp.Key, out index))
|
||||
if (tileSet.TryGetTerrainIndex(kvp.Key, out var index))
|
||||
info[index] = kvp.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!lines.MoveNext() || (lines.Current != "GIMP Palette" && lines.Current != "JASC-PAL"))
|
||||
throw new InvalidDataException("File `{0}` is not a valid GIMP or JASC palette.".F(Filename));
|
||||
|
||||
byte r, g, b, a;
|
||||
byte a;
|
||||
a = 255;
|
||||
var i = 0;
|
||||
|
||||
@@ -77,13 +77,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (rgba.Length < 3)
|
||||
throw new InvalidDataException("Invalid RGB(A) triplet/quartet: ({0})".F(string.Join(" ", rgba)));
|
||||
|
||||
if (!byte.TryParse(rgba[0], out r))
|
||||
if (!byte.TryParse(rgba[0], out var r))
|
||||
throw new InvalidDataException("Invalid R value: {0}".F(rgba[0]));
|
||||
|
||||
if (!byte.TryParse(rgba[1], out g))
|
||||
if (!byte.TryParse(rgba[1], out var g))
|
||||
throw new InvalidDataException("Invalid G value: {0}".F(rgba[1]));
|
||||
|
||||
if (!byte.TryParse(rgba[2], out b))
|
||||
if (!byte.TryParse(rgba[2], out var b))
|
||||
throw new InvalidDataException("Invalid B value: {0}".F(rgba[2]));
|
||||
|
||||
// Check if color has a (valid) alpha value.
|
||||
|
||||
@@ -38,8 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
// Remove the actor's last claim, if it has one
|
||||
CPos lastClaim;
|
||||
if (claimByActor.TryGetValue(claimer, out lastClaim))
|
||||
if (claimByActor.TryGetValue(claimer, out var lastClaim))
|
||||
claimByCell.GetOrAdd(lastClaim).Remove(claimer);
|
||||
|
||||
claimers.Add(claimer);
|
||||
@@ -61,8 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
/// </summary>
|
||||
public void RemoveClaim(Actor claimer)
|
||||
{
|
||||
CPos lastClaim;
|
||||
if (claimByActor.TryGetValue(claimer, out lastClaim))
|
||||
if (claimByActor.TryGetValue(claimer, out var lastClaim))
|
||||
claimByCell.GetOrAdd(lastClaim).Remove(claimer);
|
||||
|
||||
claimByActor.Remove(claimer);
|
||||
|
||||
@@ -82,8 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var cell in w.Map.AllCells)
|
||||
{
|
||||
ResourceType t;
|
||||
if (!resources.TryGetValue(w.Map.Resources[cell].Type, out t))
|
||||
if (!resources.TryGetValue(w.Map.Resources[cell].Type, out var t))
|
||||
continue;
|
||||
|
||||
if (!AllowResourceAt(t, cell))
|
||||
|
||||
@@ -51,10 +51,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static object LoadInitialSmudges(MiniYaml yaml)
|
||||
{
|
||||
MiniYaml smudgeYaml;
|
||||
var nd = yaml.ToDictionary();
|
||||
var smudges = new Dictionary<CPos, MapSmudge>();
|
||||
if (nd.TryGetValue("InitialSmudges", out smudgeYaml))
|
||||
if (nd.TryGetValue("InitialSmudges", out var smudgeYaml))
|
||||
{
|
||||
foreach (var node in smudgeYaml.Nodes)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LegacyReferencePoints>(), out value))
|
||||
if (!PositionMap.TryGetValue(positionNode.NodeValue<LegacyReferencePoints>(), out var value))
|
||||
value = DecorationPosition.TopLeft;
|
||||
|
||||
if (value != DecorationPosition.TopLeft)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -27,8 +27,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action<Color> onChange,
|
||||
Dictionary<string, MiniYaml> 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<string>("ColorPickerActorType");
|
||||
|
||||
var preview = widget.GetOrNull<ActorPreviewWidget>("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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int>("EditPanelPadding", yaml.Value);
|
||||
|
||||
okButton.IsDisabled = () => !IsValid() || !editActorPreview.IsDirty;
|
||||
|
||||
@@ -45,9 +45,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
panel.Get<ButtonWidget>("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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int2>("ButtonStride", buttonStrideNode.Value);
|
||||
|
||||
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
||||
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<string[]>("Buttons", buttonsNode.Value);
|
||||
foreach (var button in buttonIds)
|
||||
if (buttonHandlers.TryGetValue(button, out createHandler))
|
||||
if (buttonHandlers.TryGetValue(button, out var createHandler))
|
||||
createHandler();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<MenuButtonWidget>("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;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user