From 71ce515d6d9fec53c5dc71040cf58d600b353957 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 19 Feb 2023 09:55:33 +0000 Subject: [PATCH] Fix IDE0004 --- .editorconfig | 3 +++ OpenRA.Game/WAngle.cs | 2 +- OpenRA.Game/WPos.cs | 2 +- OpenRA.Game/World.cs | 2 +- OpenRA.Mods.Common/Activities/Sell.cs | 4 ++-- .../Traits/BotModules/Squads/AttackOrFleeFuzzy.cs | 2 +- OpenRA.Mods.Common/Traits/Sellable.cs | 4 ++-- OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsUtils.cs | 2 +- OpenRA.Platforms.Default/Texture.cs | 2 +- 12 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.editorconfig b/.editorconfig index a1cbc249d0..edb4d5c30e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -135,6 +135,9 @@ dotnet_diagnostic.IDE0001.severity = warning # Simplify member access. dotnet_diagnostic.IDE0002.severity = warning +# Remove unnecessary cast. +dotnet_diagnostic.IDE0004.severity = warning + # Use 'var' instead of explicit type. dotnet_diagnostic.IDE0007.severity = warning diff --git a/OpenRA.Game/WAngle.cs b/OpenRA.Game/WAngle.cs index b6dab003c2..d8ced13279 100644 --- a/OpenRA.Game/WAngle.cs +++ b/OpenRA.Game/WAngle.cs @@ -22,7 +22,7 @@ namespace OpenRA public readonly struct WAngle : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, IEquatable { public readonly int Angle; - public int AngleSquared => (int)Angle * Angle; + public int AngleSquared => Angle * Angle; public WAngle(int a) { diff --git a/OpenRA.Game/WPos.cs b/OpenRA.Game/WPos.cs index 9acd2decc6..7ad7774555 100644 --- a/OpenRA.Game/WPos.cs +++ b/OpenRA.Game/WPos.cs @@ -66,7 +66,7 @@ namespace OpenRA // Add an additional quadratic variation to height // Uses decimal to avoid integer overflow var offset = (decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div); - var clampedOffset = (int)(offset + (decimal)ret.Z).Clamp((decimal)int.MinValue, (decimal)int.MaxValue); + var clampedOffset = (int)(offset + ret.Z).Clamp(int.MinValue, int.MaxValue); return new WPos(ret.X, ret.Y, clampedOffset); } diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index a80110b65f..b1a6187e39 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -374,7 +374,7 @@ namespace OpenRA public void RemoveAll(Predicate predicate) { effects.RemoveAll(predicate); - unpartitionedEffects.RemoveAll(e => predicate((IEffect)e)); + unpartitionedEffects.RemoveAll(e => predicate(e)); syncedEffects.RemoveAll(e => predicate((IEffect)e)); } diff --git a/OpenRA.Mods.Common/Activities/Sell.cs b/OpenRA.Mods.Common/Activities/Sell.cs index 9fc46a8391..2476d331c0 100644 --- a/OpenRA.Mods.Common/Activities/Sell.cs +++ b/OpenRA.Mods.Common/Activities/Sell.cs @@ -37,8 +37,8 @@ namespace OpenRA.Mods.Common.Activities var sellValue = self.GetSellValue(); // Cast to long to avoid overflow when multiplying by the health - var hp = health != null ? (long)health.HP : 1L; - var maxHP = health != null ? (long)health.MaxHP : 1L; + var hp = health != null ? health.HP : 1L; + var maxHP = health != null ? health.MaxHP : 1L; var refund = (int)(sellValue * sellableInfo.RefundPercent * hp / (100 * maxHP)); refund = playerResources.ChangeCash(refund); diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs index 5ad364bfc4..d57b81c618 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs @@ -181,7 +181,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads return !double.IsNaN(attackChance) && attackChance < 30.0; } - static float NormalizedHealth(IEnumerable actors, float normalizeByValue) + static float NormalizedHealth(IEnumerable actors, int normalizeByValue) { var sumOfMaxHp = 0; var sumOfHp = 0; diff --git a/OpenRA.Mods.Common/Traits/Sellable.cs b/OpenRA.Mods.Common/Traits/Sellable.cs index 82beca31fa..12158fa9fd 100644 --- a/OpenRA.Mods.Common/Traits/Sellable.cs +++ b/OpenRA.Mods.Common/Traits/Sellable.cs @@ -109,8 +109,8 @@ namespace OpenRA.Mods.Common.Traits var sellValue = self.GetSellValue(); // Cast to long to avoid overflow when multiplying by the health - var hp = health != null ? (long)health.Value.HP : 1L; - var maxHP = health != null ? (long)health.Value.MaxHP : 1L; + var hp = health != null ? health.Value.HP : 1L; + var maxHP = health != null ? health.Value.MaxHP : 1L; var refund = (int)(sellValue * info.RefundPercent * hp / (100 * maxHP)); return "Refund: $" + refund; diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index 3b9a3aa385..d9f16b6ac0 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -253,7 +253,7 @@ namespace OpenRA.Mods.Common.Traits var content = resources[cell]; var oldDensity = content.Type == resourceInfo.ResourceIndex ? content.Index : 0; var density = (byte)Math.Min(resourceInfo.MaxDensity, oldDensity + amount); - Map.Resources[cell] = new ResourceTile((byte)resourceInfo.ResourceIndex, density); + Map.Resources[cell] = new ResourceTile(resourceInfo.ResourceIndex, density); return density - oldDensity; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs index 0af34efdbd..ea5a459d78 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (dropdownColumns.Count == 0) { - row = dropdownRowTemplate.Clone() as Widget; + row = dropdownRowTemplate.Clone(); row.Bounds.Y = optionsContainer.Bounds.Height; optionsContainer.Bounds.Height += row.Bounds.Height; foreach (var child in row.Children) diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index 14a1173943..62e511090a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -253,7 +253,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic .ToList(); // 'all game types' extra item - categories.Insert(0, (null as string, tabMaps[tab].Length)); + categories.Insert(0, (null, tabMaps[tab].Length)); string ShowItem((string Category, int Count) x) => (x.Category ?? allMaps) + $" ({x.Count})"; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsUtils.cs index 104270eac1..0c72fa4b4f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsUtils.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic throw new InvalidOperationException($"{group.GetType().Name} does not contain a preference type {pref}"); var ss = parent.Get(id); - ss.Value = (float)(int)field.GetValue(group); + ss.Value = (int)field.GetValue(group); ss.OnChange += x => field.SetValue(group, (int)x); } diff --git a/OpenRA.Platforms.Default/Texture.cs b/OpenRA.Platforms.Default/Texture.cs index 2f4950f99c..c6ae9adf67 100644 --- a/OpenRA.Platforms.Default/Texture.cs +++ b/OpenRA.Platforms.Default/Texture.cs @@ -163,7 +163,7 @@ namespace OpenRA.Platforms.Default { fixed (byte* ptr = &data[0]) { - var intPtr = new IntPtr((void*)ptr); + var intPtr = new IntPtr(ptr); OpenGL.glGetTexImage(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, intPtr); }