diff --git a/.editorconfig b/.editorconfig index ae322722d9..b50db22e9b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -147,6 +147,9 @@ dotnet_diagnostic.IDE0044.severity = warning # Unused private member. dotnet_diagnostic.IDE0052.severity = warning +# Unnecessary value assignment. +dotnet_diagnostic.IDE0059.severity = warning + # Unused parameter. dotnet_diagnostic.IDE0060.severity = warning diff --git a/OpenRA.Game/WDist.cs b/OpenRA.Game/WDist.cs index 7388f1dd34..a46940e2b0 100644 --- a/OpenRA.Game/WDist.cs +++ b/OpenRA.Game/WDist.cs @@ -66,7 +66,7 @@ namespace OpenRA s = s.ToLowerInvariant(); var components = s.Split('c'); var cell = 0; - var subcell = 0; + int subcell; switch (components.Length) { diff --git a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs index ff43999991..75eaa2952c 100644 --- a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs +++ b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs @@ -224,13 +224,11 @@ namespace OpenRA.Mods.Cnc.FileFormats uint nTwoByteLen, bit; int nTwoBitLen; - var j = 0; - InitBigNum(nTmp, 0, len); InitBigNum(n1, 0, len); nTwoBitLen = (int)BitLenBigNum(n2, len); bit = 1U << (nTwoBitLen % 32); - j = ((nTwoBitLen + 32) / 32) - 1; + var j = ((nTwoBitLen + 32) / 32) - 1; nTwoByteLen = (uint)((nTwoBitLen - 1) / 32) * 4; nTmp[nTwoByteLen / 4] |= 1U << ((nTwoBitLen - 1) & 0x1f); diff --git a/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs b/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs index 678eca8752..fc1b17f4eb 100644 --- a/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs +++ b/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc.FileFormats Width = stream.ReadUInt16(); Height = stream.ReadUInt16(); - var delta = stream.ReadUInt16() + 37; + /*var delta = */stream.ReadUInt16(); /* + 37*/ var flags = stream.ReadUInt16(); frameOffsets = new uint[FrameCount + 2]; diff --git a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs index d670794705..20cf122541 100644 --- a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs @@ -109,7 +109,6 @@ namespace OpenRA.Mods.Cnc.Graphics static IEnumerable DrawZapWandering(WorldRenderer wr, float2 from, float2 to, ISpriteSequence s, string pal) { - var z = float2.Zero; /* hack */ var dist = to - from; var norm = (1f / dist.Length) * new float2(-dist.Y, dist.X); @@ -121,14 +120,14 @@ namespace OpenRA.Mods.Cnc.Graphics renderables.AddRange(DrawZap(wr, from, p1, s, out p1, pal)); renderables.AddRange(DrawZap(wr, p1, p2, s, out p2, pal)); - renderables.AddRange(DrawZap(wr, p2, to, s, out z, pal)); + renderables.AddRange(DrawZap(wr, p2, to, s, out _, pal)); } else { var p1 = from + (1 / 2f) * dist + WDist.FromPDF(Game.CosmeticRandom, 2).Length * dist.Length / 4096 * norm; renderables.AddRange(DrawZap(wr, from, p1, s, out p1, pal)); - renderables.AddRange(DrawZap(wr, p1, to, s, out z, pal)); + renderables.AddRange(DrawZap(wr, p1, to, s, out _, pal)); } return renderables; diff --git a/OpenRA.Mods.Cnc/Traits/Disguise.cs b/OpenRA.Mods.Cnc/Traits/Disguise.cs index 77f0f30f6f..336944f055 100644 --- a/OpenRA.Mods.Cnc/Traits/Disguise.cs +++ b/OpenRA.Mods.Cnc/Traits/Disguise.cs @@ -162,7 +162,7 @@ namespace OpenRA.Mods.Cnc.Traits if (!Disguised || self.Owner.IsAlliedWith(self.World.RenderPlayer)) return color; - return color = Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerRelationshipColor(self) : AsPlayer.Color; + return Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerRelationshipColor(self) : AsPlayer.Color; } public void DisguiseAs(Actor target) diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs index 70ffb4cc0b..c037feb83f 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs @@ -621,8 +621,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands } // Merge Ground into Ambient - float ground = 0; - if (parsed.TryGetValue("Ground", out ground)) + if (parsed.TryGetValue("Ground", out var ground)) { if (!parsed.ContainsKey("Ambient")) parsed["Ambient"] = 1f; diff --git a/OpenRA.Mods.Cnc/VideoLoaders/WsaLoader.cs b/OpenRA.Mods.Cnc/VideoLoaders/WsaLoader.cs index 646933ecf8..333126d0b6 100644 --- a/OpenRA.Mods.Cnc/VideoLoaders/WsaLoader.cs +++ b/OpenRA.Mods.Cnc/VideoLoaders/WsaLoader.cs @@ -40,15 +40,15 @@ namespace OpenRA.Mods.Cnc.VideoLoaders if (frames <= 1) // TODO: find a better way to differentiate .shp icons return false; - var x = s.ReadUInt16(); - var y = s.ReadUInt16(); + /* var x = */ s.ReadUInt16(); + /* var y = */ s.ReadUInt16(); var width = s.ReadUInt16(); var height = s.ReadUInt16(); if (width <= 0 || height <= 0) return false; - var delta = s.ReadUInt16() + 37; + /*var delta = */ s.ReadUInt16(); /* + 37;*/ var flags = s.ReadUInt16(); @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Cnc.VideoLoaders if (flags == 1) { - var palette = s.ReadBytes(768); + /* var palette = */ s.ReadBytes(768); for (var i = 0; i < offsets.Length; i++) offsets[i] += 768; } diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs index 43e610ac53..e1b1415140 100644 --- a/OpenRA.Mods.Common/Activities/Enter.cs +++ b/OpenRA.Mods.Common/Activities/Enter.cs @@ -66,7 +66,6 @@ namespace OpenRA.Mods.Common.Activities if (!targetIsHiddenActor && target.Type == TargetType.Actor) lastVisibleTarget = Target.FromTargetPositions(target); - var oldUseLastVisibleTarget = useLastVisibleTarget; useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self); // Cancel immediately if the target died while we were entering it diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 82ccb74d66..9c54deede7 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -355,13 +355,12 @@ namespace OpenRA.Mods.Common.Projectiles var tarDistVec = targetPosition + offset - pos; var relTarHorDist = tarDistVec.HorizontalLength; - int predClfHgt = 0; - int predClfDist = 0; - int lastHtChg = 0; - int lastHt = 0; + var predClfHgt = 0; + var predClfDist = 0; + var lastHt = 0; if (info.TerrainHeightAware) - InclineLookahead(world, relTarHorDist, out predClfHgt, out predClfDist, out lastHtChg, out lastHt); + InclineLookahead(world, relTarHorDist, out predClfHgt, out predClfDist, out _, out lastHt); // Height difference between the incline height and missile height var diffClfMslHgt = predClfHgt - pos.Z; @@ -590,7 +589,7 @@ namespace OpenRA.Mods.Common.Projectiles int HomingInnerTick(int predClfDist, int diffClfMslHgt, int relTarHorDist, int lastHtChg, int lastHt, int relTarHgt, int vFacing, bool targetPassedBy) { - int desiredVFacing = vFacing; + int desiredVFacing; // Incline coming up -> attempt to reach the incline so that after predClfDist // the height above the terrain is positive but as close to 0 as possible diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs index b5381d1cd4..2640a8160a 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs @@ -54,8 +54,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads protected static Actor FindDefenselessTarget(Squad owner) { - Actor target = null; - FindSafePlace(owner, out target, true); + FindSafePlace(owner, out var target, true); return target; } diff --git a/OpenRA.Mods.Common/Traits/Carryall.cs b/OpenRA.Mods.Common/Traits/Carryall.cs index 398a76fc3c..1d038fb3e1 100644 --- a/OpenRA.Mods.Common/Traits/Carryall.cs +++ b/OpenRA.Mods.Common/Traits/Carryall.cs @@ -97,7 +97,6 @@ namespace OpenRA.Mods.Common.Traits readonly AircraftInfo aircraftInfo; readonly Aircraft aircraft; readonly BodyOrientation body; - readonly IMove move; readonly IFacing facing; readonly Actor self; @@ -125,7 +124,6 @@ namespace OpenRA.Mods.Common.Traits aircraftInfo = self.Info.TraitInfoOrDefault(); aircraft = self.Trait(); body = self.Trait(); - move = self.Trait(); facing = self.Trait(); this.self = self; @@ -347,7 +345,6 @@ namespace OpenRA.Mods.Common.Traits if (!aircraftInfo.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell)) return; - var targetLocation = move.NearestMoveableCell(cell); self.QueueActivity(order.Queued, new DeliverUnit(self, order.Target, Info.DropRange, Info.TargetLineColor)); self.ShowTargetLines(); } @@ -435,9 +432,7 @@ namespace OpenRA.Mods.Common.Traits if (!info.AllowDropOff || !modifiers.HasModifier(TargetModifiers.ForceMove)) return false; - cursor = info.DropOffCursor; var type = target.Type; - if ((type == TargetType.Actor && target.Actor.Info.HasTraitInfo()) || (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.HasTraitInfo())) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs index d46f65d494..3d35b9b264 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs @@ -38,8 +38,6 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) { - var modId = modData.Manifest.Id; - foreach (var bo in actorNode.ChildrenMatching("BodyOrientation")) { var usesClassicFacings = false; diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RenameSelfHealing.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RenameSelfHealing.cs index 24903302bc..648f8630dc 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RenameSelfHealing.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RenameSelfHealing.cs @@ -23,8 +23,6 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) { - var modId = modData.Manifest.Id; - foreach (var sh in actorNode.ChildrenMatching("SelfHealing")) { sh.RenameChildrenMatching("HealIfBelow", "StartIfBelow"); diff --git a/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs index e1304a99f5..006e9df687 100644 --- a/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var palette = new ImmutablePalette(args[1], new[] { 0 }, Array.Empty()); - SequenceProvider sequences = null; + SequenceProvider sequences; var mapPackage = new Folder(Platform.EngineDir).OpenPackage(args[2], modData.ModFiles); if (mapPackage != null) sequences = new Map(modData, mapPackage).Rules.Sequences; diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index ced97796b5..82d7fd0c72 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -118,8 +118,7 @@ namespace OpenRA.Mods.Common.UtilityCommands { var iniFormat = basicSection.GetValue("NewINIFormat", "0"); - var iniFormatVersion = 0; - Exts.TryParseIntegerInvariant(iniFormat, out iniFormatVersion); + Exts.TryParseIntegerInvariant(iniFormat, out var iniFormatVersion); return iniFormatVersion; } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs index d9557c022b..eb025a49ce 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs @@ -18,8 +18,6 @@ using OpenRA.Mods.Common.UpdateRules; namespace OpenRA.Mods.Common.UtilityCommands { - using YamlFileSet = List<(IReadWritePackage, string, List)>; - class UpdateMapCommand : IUtilityCommand { string IUtilityCommand.Name => "--update-map"; @@ -102,15 +100,23 @@ namespace OpenRA.Mods.Common.UtilityCommands var externalFilenames = new HashSet(); foreach (var rule in rules) { - Console.WriteLine("{0}: {1}", rule.GetType().Name, rule.Name); - var mapFiles = new YamlFileSet(); - var manualSteps = new List(); - + Console.WriteLine($"{rule.GetType().Name}: {rule.Name}"); Console.Write(" Updating map... "); try { - manualSteps = UpdateUtils.UpdateMap(modData, mapPackage, rule, out mapFiles, externalFilenames); + var manualSteps = UpdateUtils.UpdateMap(modData, mapPackage, rule, out var mapFiles, externalFilenames); + + // Files are saved after each successful automated rule update + mapFiles.Save(); + Console.WriteLine("COMPLETE"); + + if (manualSteps.Count > 0) + { + Console.WriteLine(" Manual changes are required to complete this update:"); + foreach (var manualStep in manualSteps) + Console.WriteLine(" * " + manualStep.Replace("\n", "\n ")); + } } catch (Exception ex) { @@ -119,24 +125,13 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine(); Console.WriteLine(" The automated changes for this rule were not applied because of an error."); Console.WriteLine(" After the issue reported below is resolved you should run the updater"); - Console.WriteLine(" with SOURCE set to {0} to retry these changes", rule.GetType().Name); + Console.WriteLine($" with SOURCE set to {rule.GetType().Name} to retry these changes"); Console.WriteLine(); Console.WriteLine(" The exception reported was:"); Console.WriteLine(" " + ex.ToString().Replace("\n", "\n ")); continue; } - // Files are saved after each successful automated rule update - mapFiles.Save(); - Console.WriteLine("COMPLETE"); - - if (manualSteps.Count > 0) - { - Console.WriteLine(" Manual changes are required to complete this update:"); - foreach (var manualStep in manualSteps) - Console.WriteLine(" * " + manualStep.Replace("\n", "\n ")); - } - Console.WriteLine(); } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs index a22c8b7767..d6979474c6 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs @@ -167,9 +167,9 @@ namespace OpenRA.Mods.Common.UtilityCommands foreach (var rule in rules) { var manualSteps = new List(); - var allFiles = new YamlFileSet(); + YamlFileSet allFiles; - LogLine(logWriter, "{0}: {1}", rule.GetType().Name, rule.Name); + LogLine(logWriter, $"{rule.GetType().Name}: {rule.Name}"); try { diff --git a/OpenRA.Platforms.Default/Sdl2Input.cs b/OpenRA.Platforms.Default/Sdl2Input.cs index 7f8ba1ec29..d2d77e06e8 100644 --- a/OpenRA.Platforms.Default/Sdl2Input.cs +++ b/OpenRA.Platforms.Default/Sdl2Input.cs @@ -221,10 +221,7 @@ namespace OpenRA.Platforms.Default } if (pendingMotion != null) - { inputHandler.OnMouseInput(pendingMotion.Value); - pendingMotion = null; - } } } }