diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index f90d0b3465..c795758372 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -359,8 +359,7 @@ namespace OpenRA public override bool Equals(object obj) { - var o = obj as Actor; - return o != null && Equals(o); + return obj is Actor o && Equals(o); } public bool Equals(Actor other) diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 9b41efe7b8..8fe5fa5f1a 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -511,8 +511,7 @@ namespace OpenRA public static bool IsTraitEnabled(this T trait) { - var disabledTrait = trait as IDisabledTrait; - return disabledTrait == null || !disabledTrait.IsTraitDisabled; + return !(trait is IDisabledTrait disabledTrait) || !disabledTrait.IsTraitDisabled; } public static T FirstEnabledTraitOrDefault(this IEnumerable ts) diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index 97d4ab5fa9..0035496c71 100644 --- a/OpenRA.Game/GameRules/Ruleset.cs +++ b/OpenRA.Game/GameRules/Ruleset.cs @@ -67,8 +67,7 @@ namespace OpenRA foreach (var weapon in Weapons) { - var projectileLoaded = weapon.Value.Projectile as IRulesetLoaded; - if (projectileLoaded != null) + if (weapon.Value.Projectile is IRulesetLoaded projectileLoaded) { try { @@ -82,8 +81,7 @@ namespace OpenRA foreach (var warhead in weapon.Value.Warheads) { - var cacher = warhead as IRulesetLoaded; - if (cacher != null) + if (warhead is IRulesetLoaded cacher) { try { diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 74a626818f..29239854ec 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -41,8 +41,7 @@ namespace OpenRA.Graphics // See combined.vert for documentation on the channel attribute format var attribC = r.Channel == TextureChannel.RGBA ? 0x02 : ((byte)r.Channel) << 1 | 0x01; attribC |= samplers.X << 6; - var ss = r as SpriteWithSecondaryData; - if (ss != null) + if (r is SpriteWithSecondaryData ss) { sl = ss.SecondaryLeft; st = ss.SecondaryTop; diff --git a/OpenRA.Game/Input/Hotkey.cs b/OpenRA.Game/Input/Hotkey.cs index b510cebaca..106a8883d6 100644 --- a/OpenRA.Game/Input/Hotkey.cs +++ b/OpenRA.Game/Input/Hotkey.cs @@ -81,8 +81,7 @@ namespace OpenRA public override bool Equals(object obj) { - var o = obj as Hotkey?; - return o != null && o == this; + return obj is Hotkey o && (Hotkey?)o == this; } public override string ToString() { return "{0} {1}".F(Key, Modifiers.ToString("F")); } diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 7ea2a59280..1cf099d506 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -148,8 +148,7 @@ namespace OpenRA { foreach (var map in package.Contents) { - var mapPackage = package.OpenPackage(map, modData.ModFiles) as IReadWritePackage; - if (mapPackage != null) + if (package.OpenPackage(map, modData.ModFiles) is IReadWritePackage mapPackage) yield return mapPackage; } } diff --git a/OpenRA.Game/Primitives/SegmentStream.cs b/OpenRA.Game/Primitives/SegmentStream.cs index f1bdce4f30..8b1a1c1c46 100644 --- a/OpenRA.Game/Primitives/SegmentStream.cs +++ b/OpenRA.Game/Primitives/SegmentStream.cs @@ -131,8 +131,7 @@ namespace OpenRA.Primitives { var offset = 0L; overallBaseStream = stream; - var segmentStream = stream as SegmentStream; - if (segmentStream != null) + if (stream is SegmentStream segmentStream) offset += segmentStream.BaseOffset + GetOverallNestedOffset(segmentStream.BaseStream, out overallBaseStream); return offset; } diff --git a/OpenRA.Game/Primitives/float3.cs b/OpenRA.Game/Primitives/float3.cs index 45de826ff5..94253dc8f2 100644 --- a/OpenRA.Game/Primitives/float3.cs +++ b/OpenRA.Game/Primitives/float3.cs @@ -55,8 +55,7 @@ namespace OpenRA public override bool Equals(object obj) { - var o = obj as float3?; - return o != null && o == this; + return obj is float3 o && (float3?)o == this; } public override string ToString() { return "{0},{1},{2}".F(X, Y, Z); } diff --git a/OpenRA.Game/Support/ExceptionHandler.cs b/OpenRA.Game/Support/ExceptionHandler.cs index bed6f3dee4..7db23ec89f 100644 --- a/OpenRA.Game/Support/ExceptionHandler.cs +++ b/OpenRA.Game/Support/ExceptionHandler.cs @@ -63,13 +63,11 @@ namespace OpenRA sb.AppendIndentedFormatLine(indent, "Exception of type `{0}`: {1}", ex.GetType().FullName, ex.Message); - var tle = ex as TypeLoadException; - var oom = ex as OutOfMemoryException; - if (tle != null) + if (ex is TypeLoadException tle) { sb.AppendIndentedFormatLine(indent, "TypeName=`{0}`", tle.TypeName); } - else if (oom != null) + else if (ex is OutOfMemoryException) { var gcMemoryBeforeCollect = GC.GetTotalMemory(false); GC.Collect(); diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index e32c114a9a..737d69cf33 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -73,11 +73,10 @@ namespace OpenRA.Widgets public static T LoadWidget(string id, Widget parent, WidgetArgs args) where T : Widget { - var widget = LoadWidget(id, parent, args) as T; - if (widget == null) - throw new InvalidOperationException( - "Widget {0} is not of type {1}".F(id, typeof(T).Name)); - return widget; + if (LoadWidget(id, parent, args) is T widget) + return widget; + + throw new InvalidOperationException("Widget {0} is not of type {1}".F(id, typeof(T).Name)); } public static Widget LoadWidget(string id, Widget parent, WidgetArgs args) diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 718ba0c274..3afaa404e7 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -273,8 +273,7 @@ namespace OpenRA gameInfo.DisabledSpawnPoints = OrderManager.LobbyInfo.DisabledSpawnPoints; - var echo = OrderManager.Connection as EchoConnection; - var rc = echo != null ? echo.Recorder : null; + var rc = (OrderManager.Connection as EchoConnection)?.Recorder; if (rc != null) rc.Metadata = new ReplayMetadata(gameInfo); @@ -326,12 +325,10 @@ namespace OpenRA { effects.Add(e); - var sp = e as ISpatiallyPartitionable; - if (sp == null) + if (!(e is ISpatiallyPartitionable)) unpartitionedEffects.Add(e); - var se = e as ISync; - if (se != null) + if (e is ISync se) syncedEffects.Add(se); } @@ -339,12 +336,10 @@ namespace OpenRA { effects.Remove(e); - var sp = e as ISpatiallyPartitionable; - if (sp == null) + if (!(e is ISpatiallyPartitionable)) unpartitionedEffects.Remove(e); - var se = e as ISync; - if (se != null) + if (e is ISync se) syncedEffects.Remove(se); } diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs index beea440fce..798938622d 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs @@ -183,19 +183,19 @@ namespace OpenRA.Mods.Cnc.Traits public override string IconOverlayTextOverride() { - var info = Info as GrantPrerequisiteChargeDrainPowerInfo; - if (info == null || !Active) + if (!Active) return null; + var info = (GrantPrerequisiteChargeDrainPowerInfo)Info; return active ? info.ActiveText : available ? info.AvailableText : null; } public override string TooltipTimeTextOverride() { - var info = Info as GrantPrerequisiteChargeDrainPowerInfo; - if (info == null || !Active) + if (!Active) return null; + var info = (GrantPrerequisiteChargeDrainPowerInfo)Info; return active ? info.ActiveText : available ? info.AvailableText : null; } } diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index 15dbfa1295..db96a02b25 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -197,10 +197,9 @@ namespace OpenRA.Mods.Common.Activities maxRange = armaments.Min(a => a.MaxRange()); var pos = self.CenterPosition; - var mobile = move as Mobile; if (!target.IsInRange(pos, maxRange) || (minRange.Length != 0 && target.IsInRange(pos, minRange)) - || (mobile != null && !mobile.CanInteractWithGroundLayer(self))) + || (move is Mobile mobile && !mobile.CanInteractWithGroundLayer(self))) { // Try to move within range, drop the target otherwise if (move == null) diff --git a/OpenRA.Mods.Common/ActorInitializer.cs b/OpenRA.Mods.Common/ActorInitializer.cs index 06ffbfc345..90fa82b052 100644 --- a/OpenRA.Mods.Common/ActorInitializer.cs +++ b/OpenRA.Mods.Common/ActorInitializer.cs @@ -102,12 +102,8 @@ namespace OpenRA.Mods.Common public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { - if (destinationType == typeof(string)) - { - var reference = value as ActorInitActorReference; - if (reference != null) - return reference.InternalName; - } + if (destinationType == typeof(string) && value is ActorInitActorReference reference) + return reference.InternalName; return base.ConvertTo(context, culture, value, destinationType); } diff --git a/OpenRA.Mods.Common/Effects/FlashTarget.cs b/OpenRA.Mods.Common/Effects/FlashTarget.cs index 95431eb8a1..3daf44501e 100644 --- a/OpenRA.Mods.Common/Effects/FlashTarget.cs +++ b/OpenRA.Mods.Common/Effects/FlashTarget.cs @@ -34,8 +34,7 @@ namespace OpenRA.Mods.Common.Effects target.World.RemoveAll(effect => { - var flashTarget = effect as FlashTarget; - return flashTarget != null && flashTarget.target == target; + return effect is FlashTarget flashTarget && flashTarget.target == target; }); } diff --git a/OpenRA.Mods.Common/Lint/CheckAngle.cs b/OpenRA.Mods.Common/Lint/CheckAngle.cs index 6737d33445..3dfa4f9441 100644 --- a/OpenRA.Mods.Common/Lint/CheckAngle.cs +++ b/OpenRA.Mods.Common/Lint/CheckAngle.cs @@ -20,8 +20,7 @@ namespace OpenRA.Mods.Common.Lint { foreach (var weaponInfo in rules.Weapons) { - var missile = weaponInfo.Value.Projectile as MissileInfo; - if (missile != null) + if (weaponInfo.Value.Projectile is MissileInfo missile) { var minAngle = missile.MinimumLaunchAngle.Angle; var maxAngle = missile.MaximumLaunchAngle.Angle; @@ -31,8 +30,7 @@ namespace OpenRA.Mods.Common.Lint CheckLaunchAngles(weaponInfo.Key, minAngle, testMaxAngle, maxAngle, emitError); } - var bullet = weaponInfo.Value.Projectile as BulletInfo; - if (bullet != null) + if (weaponInfo.Value.Projectile is BulletInfo bullet) { var minAngle = bullet.LaunchAngle[0].Angle; var maxAngle = bullet.LaunchAngle.Length > 1 ? bullet.LaunchAngle[1].Angle : minAngle; diff --git a/OpenRA.Mods.Common/Lint/CheckRangeLimit.cs b/OpenRA.Mods.Common/Lint/CheckRangeLimit.cs index 132cf25f3b..9cc4539725 100644 --- a/OpenRA.Mods.Common/Lint/CheckRangeLimit.cs +++ b/OpenRA.Mods.Common/Lint/CheckRangeLimit.cs @@ -21,9 +21,8 @@ namespace OpenRA.Mods.Common.Lint foreach (var weaponInfo in rules.Weapons) { var range = weaponInfo.Value.Range; - var missile = weaponInfo.Value.Projectile as MissileInfo; - if (missile != null && missile.RangeLimit > WDist.Zero && missile.RangeLimit < range) + if (weaponInfo.Value.Projectile is MissileInfo missile && missile.RangeLimit > WDist.Zero && missile.RangeLimit < range) emitError("Weapon `{0}`: projectile RangeLimit lower than weapon range!" .F(weaponInfo.Key)); } diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index a55b7a3d6c..581a4237e3 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -325,8 +325,7 @@ namespace OpenRA.Mods.Common.Orders foreach (var blocker in blockers) { CPos moveCell; - var mobile = blocker.Trait as Mobile; - if (mobile != null) + if (blocker.Trait is Mobile mobile) { var availableCells = adjacentTiles.Where(t => mobile.CanEnterCell(t)).ToList(); if (availableCells.Count == 0) diff --git a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs index 3a808d8783..6d20230d44 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs @@ -40,9 +40,7 @@ namespace OpenRA.Mods.Common.Scripting if (initInstance.Length > 1) initType.GetField("InstanceName").SetValue(init, initInstance[1]); - var compositeInit = init as CompositeActorInit; - var tableValue = value as LuaTable; - if (tableValue != null && compositeInit != null) + if (value is LuaTable tableValue && init is CompositeActorInit compositeInit) { var args = compositeInit.InitializeArgs(); var initValues = new Dictionary(); @@ -74,8 +72,7 @@ namespace OpenRA.Mods.Common.Scripting } // HACK: Backward compatibility for legacy int facings - var facingInit = init as FacingInit; - if (facingInit != null) + if (init is FacingInit facingInit) { if (value.TryGetClrValue(out int facing)) { diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index a37ddd921a..7f2ef22312 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -117,10 +117,8 @@ namespace OpenRA.Mods.Common.Traits { if (!h.Key.IsIdle) { - var act = h.Key.CurrentActivity as FindAndDeliverResources; - // Ignore this actor if FindAndDeliverResources is working fine or it is performing a different activity - if (act == null || !act.LastSearchFailed) + if (!(h.Key.CurrentActivity is FindAndDeliverResources act) || !act.LastSearchFailed) continue; } diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs index b672cb40d5..f0216fb430 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs @@ -36,8 +36,7 @@ namespace OpenRA.Mods.Common.Traits // The DeployTransform order does not have a position associated with it, // so we can only queue a new transformation if something else has // already triggered the undeploy. - var currentTransform = self.CurrentActivity as Transform; - if (!order.Queued || currentTransform == null) + if (!order.Queued || !(self.CurrentActivity is Transform currentTransform)) return; if (!order.Queued) diff --git a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs index 94b2197e42..7185aba9fb 100644 --- a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs +++ b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs @@ -91,8 +91,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable RenderArmaments(Actor self, AttackBase attack) { // Fire ports on garrisonable structures - var garrison = attack as AttackGarrisoned; - if (garrison != null) + if (attack is AttackGarrisoned garrison) { var bodyOrientation = coords.Value.QuantizeOrientation(self, self.Orientation); foreach (var p in garrison.Info.Ports) diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index 6db86f7b4c..ba844cd03e 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -209,12 +209,10 @@ namespace OpenRA.Mods.Common.Traits { Func saveInit = init => { - var factionInit = init as FactionInit; - if (factionInit != null && factionInit.Value == Owner.Faction) + if (init is FactionInit factionInit && factionInit.Value == Owner.Faction) return false; - var healthInit = init as HealthInit; - if (healthInit != null && healthInit.Value == 100) + if (init is HealthInit healthInit && healthInit.Value == 100) return false; // TODO: Other default values will need to be filtered diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index 1a6bfd8264..db36c49a99 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -303,8 +303,7 @@ namespace OpenRA.Mods.Common.Traits if (check <= BlockedByActor.Immovable && cellFlag.HasCellFlag(CellFlag.HasMovableActor) && actor.Owner.RelationshipWith(otherActor.Owner) == PlayerRelationship.Ally) { - var mobile = otherActor.OccupiesSpace as Mobile; - if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable) + if (otherActor.OccupiesSpace is Mobile mobile && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable) return false; } @@ -324,8 +323,7 @@ namespace OpenRA.Mods.Common.Traits if (cellFlag.HasCellFlag(CellFlag.HasTransitOnlyActor)) { // Transit only tiles should not block movement - var building = otherActor.OccupiesSpace as Building; - if (building != null && building.TransitOnlyCells().Contains(cell)) + if (otherActor.OccupiesSpace is Building building && building.TransitOnlyCells().Contains(cell)) return false; } @@ -346,16 +344,11 @@ namespace OpenRA.Mods.Common.Traits static bool IsMoving(Actor self, Actor other) { // PERF: Because we can be sure that OccupiesSpace is Mobile here we can save some performance by avoiding querying for the trait. - var otherMobile = other.OccupiesSpace as Mobile; - if (otherMobile == null || !otherMobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal)) + if (!(other.OccupiesSpace is Mobile otherMobile) || !otherMobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal)) return false; // PERF: Same here. - var selfMobile = self.OccupiesSpace as Mobile; - if (selfMobile == null) - return false; - - return true; + return self.OccupiesSpace is Mobile; } public void WorldLoaded(World w, WorldRenderer wr) @@ -466,8 +459,7 @@ namespace OpenRA.Mods.Common.Traits var isMovable = mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable; var isMoving = isMovable && mobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal); - var building = actor.OccupiesSpace as Building; - var isTransitOnly = building != null && building.TransitOnlyCells().Contains(cell); + var isTransitOnly = actor.OccupiesSpace is Building building && building.TransitOnlyCells().Contains(cell); if (isTransitOnly) { diff --git a/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs b/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs index b60d0179a5..b4b655fda6 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs @@ -158,8 +158,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr, TerrainTemplateInfo t, int2 origin, float scale) { - var template = t as DefaultTerrainTemplateInfo; - if (template == null) + if (!(t is DefaultTerrainTemplateInfo template)) yield break; var ts = map.Grid.TileSize; diff --git a/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs index 744b320129..92eb777d66 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs @@ -36,8 +36,8 @@ namespace OpenRA.Mods.Common.UtilityCommands var modData = Game.ModData = utility.ModData; // HACK: We know that maps can only be oramap or folders, which are ReadWrite - var package = new Folder(Platform.EngineDir).OpenPackage(args[1], modData.ModFiles) as IReadWritePackage; - if (package == null) + var folder = new Folder(Platform.EngineDir); + if (!(folder.OpenPackage(args[1], modData.ModFiles) is IReadWritePackage package)) throw new FileNotFoundException(args[1]); IEnumerable rules = null; diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 1c6cbce502..ef83c18ba2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -371,9 +371,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic currentPackage = package; currentFilename = filename; var prefix = ""; - var fs = modData.DefaultFileSystem as OpenRA.FileSystem.FileSystem; - if (fs != null) + if (modData.DefaultFileSystem is OpenRA.FileSystem.FileSystem fs) { prefix = fs.GetPrefix(package); if (prefix != null) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 0fdd42b775..cbf5ba190c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -180,8 +180,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic try { - var package = map.Package as IReadWritePackage; - if (package == null || package.Name != combinedPath) + if (!(map.Package is IReadWritePackage package) || package.Name != combinedPath) { selectedDirectory.Folder.Delete(combinedPath); if (fileType == MapFileType.OraMap) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs index 9096042f86..6b286c9337 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs @@ -273,12 +273,10 @@ namespace OpenRA.Mods.Common.Widgets bool IsForceModifiersActive(Modifiers modifiers) { - var fmog = world.OrderGenerator as ForceModifiersOrderGenerator; - if (fmog != null && fmog.Modifiers.HasFlag(modifiers)) + if (world.OrderGenerator is ForceModifiersOrderGenerator fmog && fmog.Modifiers.HasFlag(modifiers)) return true; - var uog = world.OrderGenerator as UnitOrderGenerator; - if (uog != null && Game.GetModifierKeys().HasFlag(modifiers)) + if (world.OrderGenerator is UnitOrderGenerator uog && Game.GetModifierKeys().HasFlag(modifiers)) return true; return false; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs index 57a48b1c74..ad83c2b72a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs @@ -65,8 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic status.GetText = statusText; } - var timerTooltip = timer as LabelWithTooltipWidget; - if (timerTooltip != null) + if (timer is LabelWithTooltipWidget timerTooltip) { var connection = orderManager.Connection as ReplayConnection; if (connection != null && connection.FinalGameTick != 0) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/OrderButtonsChromeLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/OrderButtonsChromeLogic.cs index 2817f2b1f0..3d031702a3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/OrderButtonsChromeLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/OrderButtonsChromeLogic.cs @@ -19,8 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public SellOrderButtonLogic(Widget widget, World world) { - var sell = widget as ButtonWidget; - if (sell != null) + if (widget is ButtonWidget sell) OrderButtonsChromeUtils.BindOrderButton(world, sell, "sell"); } } @@ -30,8 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public RepairOrderButtonLogic(Widget widget, World world) { - var repair = widget as ButtonWidget; - if (repair != null) + if (widget is ButtonWidget repair) OrderButtonsChromeUtils.BindOrderButton(world, repair, "repair"); } } @@ -41,8 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public PowerdownOrderButtonLogic(Widget widget, World world) { - var power = widget as ButtonWidget; - if (power != null) + if (widget is ButtonWidget power) OrderButtonsChromeUtils.BindOrderButton(world, power, "power"); } } @@ -52,8 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public BeaconOrderButtonLogic(Widget widget, World world) { - var beacon = widget as ButtonWidget; - if (beacon != null) + if (widget is ButtonWidget beacon) OrderButtonsChromeUtils.BindOrderButton(world, beacon, "beacon"); } } diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index 76b4f7d432..5263c8a3cf 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -282,8 +282,7 @@ namespace OpenRA.Mods.Common.Widgets { var item = Children.FirstOrDefault(c => { - var si = c as ScrollItemWidget; - return si != null && si.ItemKey == itemKey; + return c is ScrollItemWidget si && si.ItemKey == itemKey; }); if (item != null) @@ -294,8 +293,7 @@ namespace OpenRA.Mods.Common.Widgets { var item = Children.FirstOrDefault(c => { - var si = c as ScrollItemWidget; - return si != null && si.IsSelected(); + return c is ScrollItemWidget si && si.IsSelected(); }); if (item != null) diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index d8995e269d..3c7a92c8d5 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -88,9 +88,8 @@ namespace OpenRA.Mods.Common.Widgets var useClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle; var multiClick = mi.MultiTapCount >= 2; - var uog = World.OrderGenerator as UnitOrderGenerator; - if (uog == null) + if (!(World.OrderGenerator is UnitOrderGenerator uog)) { ApplyOrders(World, mi); isDragging = false; diff --git a/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs b/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs index 5ac636d1ce..0dc9b6acb5 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs @@ -83,8 +83,7 @@ namespace OpenRA.Mods.D2k.Traits.Buildings { var map = self.World.Map; - var terrainInfo = self.World.Map.Rules.TerrainInfo as ITemplatedTerrainInfo; - if (terrainInfo == null) + if (!(self.World.Map.Rules.TerrainInfo is ITemplatedTerrainInfo terrainInfo)) throw new InvalidDataException("D2kBuilding requires a template-based tileset."); var template = terrainInfo.Templates[info.ConcreteTemplate]; diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs index b856773f35..345b228e8c 100644 --- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs +++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs @@ -354,14 +354,13 @@ namespace OpenRA.Platforms.Default public void SetHardwareCursor(IHardwareCursor cursor) { VerifyThreadAffinity(); - var c = cursor as Sdl2HardwareCursor; - if (c == null) - SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_FALSE); - else + if (cursor is Sdl2HardwareCursor c) { SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_TRUE); SDL.SDL_SetCursor(c.Cursor); } + else + SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_FALSE); } public void SetRelativeMouseMode(bool mode)