diff --git a/OpenRA.Game/Activities/Activity.cs b/OpenRA.Game/Activities/Activity.cs index 452267bd65..45187373a8 100644 --- a/OpenRA.Game/Activities/Activity.cs +++ b/OpenRA.Game/Activities/Activity.cs @@ -185,8 +185,7 @@ namespace OpenRA.Activities /// internal void OnActorDisposeOuter(Actor self) { - if (ChildActivity != null) - ChildActivity.OnActorDisposeOuter(self); + ChildActivity?.OnActorDisposeOuter(self); OnActorDispose(self); } @@ -199,8 +198,7 @@ namespace OpenRA.Activities if (!IsInterruptible) return; - if (ChildActivity != null) - ChildActivity.Cancel(self); + ChildActivity?.Cancel(self); // Directly mark activities that are queued and therefore didn't run yet as done State = State == ActivityState.Queued ? ActivityState.Done : ActivityState.Canceling; @@ -243,11 +241,9 @@ namespace OpenRA.Activities Console.WriteLine(GetType().ToString().Split('.').Last()); - if (ChildActivity != null) - ChildActivity.PrintActivityTree(self, origin, level + 1); + ChildActivity?.PrintActivityTree(self, origin, level + 1); - if (NextActivity != null) - NextActivity.PrintActivityTree(self, origin, level); + NextActivity?.PrintActivityTree(self, origin, level); } } diff --git a/OpenRA.Game/Activities/CallFunc.cs b/OpenRA.Game/Activities/CallFunc.cs index 2705369243..21ffe40dac 100644 --- a/OpenRA.Game/Activities/CallFunc.cs +++ b/OpenRA.Game/Activities/CallFunc.cs @@ -26,7 +26,7 @@ namespace OpenRA.Activities public override bool Tick(Actor self) { - if (a != null) a(); + a?.Invoke(); return true; } } diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index c513847fdd..c53b7a2d66 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -329,8 +329,7 @@ namespace OpenRA public void CancelActivity() { - if (CurrentActivity != null) - CurrentActivity.Cancel(this); + CurrentActivity?.Cancel(this); } public override int GetHashCode() @@ -382,8 +381,7 @@ namespace OpenRA { // If CurrentActivity isn't null, run OnActorDisposeOuter in case some cleanups are needed. // This should be done before the FrameEndTask to avoid dependency issues. - if (CurrentActivity != null) - CurrentActivity.OnActorDisposeOuter(this); + CurrentActivity?.OnActorDisposeOuter(this); // Allow traits/activities to prevent a race condition when they depend on disposing the actor (e.g. Transforms) WillDispose = true; @@ -402,8 +400,7 @@ namespace OpenRA World.TraitDict.RemoveActor(this); Disposed = true; - if (luaInterface != null) - luaInterface.Value.OnActorDestroyed(); + luaInterface?.Value.OnActorDestroyed(); }); } diff --git a/OpenRA.Game/Download.cs b/OpenRA.Game/Download.cs index b06acb5750..8a9d7415fd 100644 --- a/OpenRA.Game/Download.cs +++ b/OpenRA.Game/Download.cs @@ -90,8 +90,7 @@ namespace OpenRA public void CancelAsync() { lock (syncObject) - if (wc != null) - wc.CancelAsync(); + wc?.CancelAsync(); } } } diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index 9aa96f1ccd..f30c228250 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -179,8 +179,7 @@ namespace OpenRA public static object GetValue(string fieldName, Type fieldType, MiniYaml yaml, MemberInfo field) { - var value = yaml.Value; - if (value != null) value = value.Trim(); + var value = yaml.Value?.Trim(); if (fieldType == typeof(int)) { diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index fea594a6ef..c7c14bad9f 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -197,10 +197,7 @@ namespace OpenRA.FileSystem var package = fileIndex[filename] .LastOrDefault(x => x.Contains(filename)); - if (package != null) - return package.GetStream(filename); - - return null; + return package?.GetStream(filename); } public Stream Open(string filename) diff --git a/OpenRA.Game/FileSystem/ZipFile.cs b/OpenRA.Game/FileSystem/ZipFile.cs index 63f7e365c6..5fc0a16afa 100644 --- a/OpenRA.Game/FileSystem/ZipFile.cs +++ b/OpenRA.Game/FileSystem/ZipFile.cs @@ -66,8 +66,7 @@ namespace OpenRA.FileSystem public void Dispose() { - if (pkg != null) - pkg.Close(); + pkg?.Close(); } public IReadOnlyPackage OpenPackage(string filename, FileSystem context) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 5a0c05ab05..520455b944 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -80,7 +80,7 @@ namespace OpenRA static void JoinInner(OrderManager om) { - if (OrderManager != null) OrderManager.Dispose(); + OrderManager?.Dispose(); OrderManager = om; lastConnectionState = ConnectionState.PreConnecting; ConnectionStateChanged(OrderManager); @@ -154,8 +154,7 @@ namespace OpenRA internal static void StartGame(string mapUID, WorldType type) { // Dispose of the old world before creating a new one. - if (worldRenderer != null) - worldRenderer.Dispose(); + worldRenderer?.Dispose(); Cursor.SetCursor(null); BeforeGameStart(); @@ -330,11 +329,9 @@ namespace OpenRA Log.Write("graphics", "{0}", e); Console.WriteLine("Renderer initialization failed. Check graphics.log for details."); - if (Renderer != null) - Renderer.Dispose(); + Renderer?.Dispose(); - if (Sound != null) - Sound.Dispose(); + Sound?.Dispose(); } } @@ -388,13 +385,10 @@ namespace OpenRA Ui.ResetAll(); - if (worldRenderer != null) - worldRenderer.Dispose(); + worldRenderer?.Dispose(); worldRenderer = null; - if (server != null) - server.Shutdown(); - if (OrderManager != null) - OrderManager.Dispose(); + server?.Shutdown(); + OrderManager?.Dispose(); if (ModData != null) { @@ -430,8 +424,7 @@ namespace OpenRA var grid = ModData.Manifest.Contains() ? ModData.Manifest.Get() : null; Renderer.InitializeDepthBuffer(grid); - if (Cursor != null) - Cursor.Dispose(); + Cursor?.Dispose(); Cursor = new CursorManager(ModData.CursorProvider); @@ -446,8 +439,7 @@ namespace OpenRA try { - if (discoverNat != null) - discoverNat.Wait(); + discoverNat?.Wait(); } catch (Exception e) { @@ -610,8 +602,7 @@ namespace OpenRA Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer)); } - if (benchmark != null) - benchmark.Tick(LocalTick); + benchmark?.Tick(LocalTick); } } @@ -836,12 +827,10 @@ namespace OpenRA finally { // Ensure that the active replay is properly saved - if (OrderManager != null) - OrderManager.Dispose(); + OrderManager?.Dispose(); } - if (worldRenderer != null) - worldRenderer.Dispose(); + worldRenderer?.Dispose(); ModData.Dispose(); ChromeProvider.Deinitialize(); @@ -880,8 +869,7 @@ namespace OpenRA public static void Disconnect() { - if (OrderManager.World != null) - OrderManager.World.TraitDict.PrintReport(); + OrderManager.World?.TraitDict.PrintReport(); OrderManager.Dispose(); CloseServer(); @@ -890,8 +878,7 @@ namespace OpenRA public static void CloseServer() { - if (server != null) - server.Shutdown(); + server?.Shutdown(); } public static T CreateObject(string name) diff --git a/OpenRA.Game/Graphics/Animation.cs b/OpenRA.Game/Graphics/Animation.cs index b029903369..fd9587568b 100644 --- a/OpenRA.Game/Graphics/Animation.cs +++ b/OpenRA.Game/Graphics/Animation.cs @@ -156,7 +156,7 @@ namespace OpenRA.Graphics { frame = CurrentSequence.Length - 1; tickFunc = () => { }; - if (after != null) after(); + after?.Invoke(); } }; } diff --git a/OpenRA.Game/Graphics/Sheet.cs b/OpenRA.Game/Graphics/Sheet.cs index 51da5762f5..706b6236da 100644 --- a/OpenRA.Game/Graphics/Sheet.cs +++ b/OpenRA.Game/Graphics/Sheet.cs @@ -146,8 +146,7 @@ namespace OpenRA.Graphics public void Dispose() { - if (texture != null) - texture.Dispose(); + texture?.Dispose(); } } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index ab2a56dd53..d70abc81e4 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -97,8 +97,8 @@ namespace OpenRA.Graphics var oldHeight = palette.Height; palette.AddPalette(name, pal, allowModifiers); - if (oldHeight != palette.Height && PaletteInvalidated != null) - PaletteInvalidated(); + if (oldHeight != palette.Height) + PaletteInvalidated?.Invoke(); } } @@ -258,8 +258,7 @@ namespace OpenRA.Graphics if (enableDepthBuffer) Game.Renderer.Context.EnableDepthBuffer(); - if (terrainRenderer != null) - terrainRenderer.RenderTerrain(this, Viewport); + terrainRenderer?.RenderTerrain(this, Viewport); Game.Renderer.Flush(); diff --git a/OpenRA.Game/InstalledMods.cs b/OpenRA.Game/InstalledMods.cs index 5afc90e5d0..27c8728826 100644 --- a/OpenRA.Game/InstalledMods.cs +++ b/OpenRA.Game/InstalledMods.cs @@ -78,8 +78,7 @@ namespace OpenRA Log.Write("debug", "Load mod '{0}': {1}".F(path, e)); } - if (package != null) - package.Dispose(); + package?.Dispose(); return null; } diff --git a/OpenRA.Game/LocalPlayerProfile.cs b/OpenRA.Game/LocalPlayerProfile.cs index 068c565ae9..9da2b880e3 100644 --- a/OpenRA.Game/LocalPlayerProfile.cs +++ b/OpenRA.Game/LocalPlayerProfile.cs @@ -108,8 +108,7 @@ namespace OpenRA } finally { - if (onComplete != null) - onComplete(); + onComplete?.Invoke(); } }; diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 67977d6a1e..f4318c416e 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -245,8 +245,7 @@ namespace OpenRA foreach (var module in modules) { var disposableModule = module as IDisposable; - if (disposableModule != null) - disposableModule.Dispose(); + disposableModule?.Dispose(); } } } diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index d46d84c10b..3a291ec45c 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -73,8 +73,7 @@ namespace OpenRA { entries[Index(cell)] = value; - if (CellEntryChanged != null) - CellEntryChanged(cell); + CellEntryChanged?.Invoke(cell); } } @@ -90,8 +89,7 @@ namespace OpenRA { entries[Index(uv)] = value; - if (CellEntryChanged != null) - CellEntryChanged(uv.ToCPos(GridType)); + CellEntryChanged?.Invoke(uv.ToCPos(GridType)); } } diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index aa5af91538..60ef036644 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -111,8 +111,7 @@ namespace OpenRA } catch (Exception e) { - if (mapPackage != null) - mapPackage.Dispose(); + mapPackage?.Dispose(); Console.WriteLine("Failed to load map: {0}", map); Console.WriteLine("Details: {0}", e); Log.Write("debug", "Failed to load map: {0}", map); @@ -192,8 +191,7 @@ namespace OpenRA foreach (var p in maps.Values) p.UpdateRemoteSearch(MapStatus.Unavailable, null); - if (queryFailed != null) - queryFailed(); + queryFailed?.Invoke(); return; } @@ -213,8 +211,7 @@ namespace OpenRA { Log.Write("debug", "Can't parse remote map search data:\n{0}", data); Log.Write("debug", "Exception: {0}", e); - if (queryFailed != null) - queryFailed(); + queryFailed?.Invoke(); } }; @@ -298,8 +295,7 @@ namespace OpenRA Game.RunAfterTick(() => { // Wait for any existing thread to exit before starting a new one. - if (previewLoaderThread != null) - previewLoaderThread.Join(); + previewLoaderThread?.Join(); previewLoaderThread = new Thread(LoadAsyncInternal) { diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index b56e42c152..ca6d66f416 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -412,8 +412,7 @@ namespace OpenRA if (innerData.Preview != null) cache.CacheMinimap(this); - if (parseMetadata != null) - parseMetadata(this); + parseMetadata?.Invoke(this); } // Update the status and class unconditionally @@ -522,9 +521,7 @@ namespace OpenRA public void Delete() { Invalidate(); - var deleteFromPackage = parentPackage as IReadWritePackage; - if (deleteFromPackage != null) - deleteFromPackage.Delete(Package.Name); + (parentPackage as IReadWritePackage)?.Delete(Package.Name); } Stream IReadOnlyFileSystem.Open(string filename) diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 35090ebbd4..d777d2a362 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -177,8 +177,7 @@ namespace OpenRA public Map PrepareMap(string uid) { - if (LoadScreen != null) - LoadScreen.Display(); + LoadScreen?.Display(); if (MapCache[uid].Status != MapStatus.Available) throw new InvalidDataException("Invalid map uid: {0}".F(uid)); @@ -202,12 +201,10 @@ namespace OpenRA public void Dispose() { - if (LoadScreen != null) - LoadScreen.Dispose(); + LoadScreen?.Dispose(); MapCache.Dispose(); - if (ObjectCreator != null) - ObjectCreator.Dispose(); + ObjectCreator?.Dispose(); Manifest.Dispose(); } diff --git a/OpenRA.Game/Network/Connection.cs b/OpenRA.Game/Network/Connection.cs index a098ebef8e..df20adcde8 100644 --- a/OpenRA.Game/Network/Connection.cs +++ b/OpenRA.Game/Network/Connection.cs @@ -174,23 +174,21 @@ namespace OpenRA.Network foreach (var p in packets) { packetFn(p.FromClient, p.Data); - if (Recorder != null) - Recorder.Receive(p.FromClient, p.Data); + Recorder?.Receive(p.FromClient, p.Data); } } public void StartRecording(Func chooseFilename) { // If we have a previous recording then save/dispose it and start a new one. - if (Recorder != null) - Recorder.Dispose(); + Recorder?.Dispose(); Recorder = new ReplayRecorder(chooseFilename); } protected virtual void Dispose(bool disposing) { - if (disposing && Recorder != null) - Recorder.Dispose(); + if (disposing) + Recorder?.Dispose(); } public void Dispose() @@ -372,8 +370,7 @@ namespace OpenRA.Network // Closing the stream will cause any reads on the receiving thread to throw. // This will mark the connection as no longer connected and the thread will terminate cleanly. - if (tcp != null) - tcp.Close(); + tcp?.Close(); base.Dispose(disposing); } diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index 8c2aed63a7..1abfff9938 100644 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -206,8 +206,7 @@ namespace OpenRA.Network public void Dispose() { disposed = true; - if (Connection != null) - Connection.Dispose(); + Connection?.Dispose(); } } diff --git a/OpenRA.Game/Network/ReplayRecorder.cs b/OpenRA.Game/Network/ReplayRecorder.cs index f1cd6d1fb1..37261b72bb 100644 --- a/OpenRA.Game/Network/ReplayRecorder.cs +++ b/OpenRA.Game/Network/ReplayRecorder.cs @@ -100,8 +100,7 @@ namespace OpenRA.Network Metadata.Write(writer); } - if (preStartBuffer != null) - preStartBuffer.Dispose(); + preStartBuffer?.Dispose(); writer.Close(); } } diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index cb80a3f0e8..349ff3ef6e 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -145,8 +145,7 @@ namespace OpenRA.Network var data = MiniYaml.FromString(order.TargetString)[0]; var traitIndex = int.Parse(data.Key); - if (world != null) - world.AddGameSaveTraitData(traitIndex, data.Value); + world?.AddGameSaveTraitData(traitIndex, data.Value); break; } diff --git a/OpenRA.Game/ObjectCreator.cs b/OpenRA.Game/ObjectCreator.cs index 4a8328667f..78c2c3ee09 100644 --- a/OpenRA.Game/ObjectCreator.cs +++ b/OpenRA.Game/ObjectCreator.cs @@ -67,10 +67,7 @@ namespace OpenRA if (a.FullName == e.Name) return a; - if (assemblies == null) - return null; - - return assemblies.Select(a => a.Assembly).FirstOrDefault(a => a.FullName == e.Name); + return assemblies?.Select(a => a.Assembly).FirstOrDefault(a => a.FullName == e.Name); } // Only used by the linter to prevent exceptions from being thrown during a lint run diff --git a/OpenRA.Game/Renderer.cs b/OpenRA.Game/Renderer.cs index 9fec7df685..a5b820ac08 100644 --- a/OpenRA.Game/Renderer.cs +++ b/OpenRA.Game/Renderer.cs @@ -115,8 +115,7 @@ namespace OpenRA font.Dispose(); using (new PerfTimer("SpriteFonts")) { - if (fontSheetBuilder != null) - fontSheetBuilder.Dispose(); + fontSheetBuilder?.Dispose(); fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512); Fonts = modData.Manifest.Get().FontList.ToDictionary(x => x.Key, x => new SpriteFont(x.Value.Font, modData.DefaultFileSystem.Open(x.Value.Font).ReadAllBytes(), @@ -156,8 +155,7 @@ namespace OpenRA if (screenSprite == null || screenSprite.Sheet.Size != surfaceBufferSize) { - if (screenBuffer != null) - screenBuffer.Dispose(); + screenBuffer?.Dispose(); // Render the screen into a frame buffer to simplify reading back screenshots screenBuffer = Context.CreateFrameBuffer(surfaceBufferSize, Color.FromArgb(0xFF, 0, 0, 0)); @@ -195,8 +193,7 @@ namespace OpenRA var worldBufferSize = worldViewport.Size.NextPowerOf2(); if (worldSprite == null || worldSprite.Sheet.Size != worldBufferSize) { - if (worldBuffer != null) - worldBuffer.Dispose(); + worldBuffer?.Dispose(); // Render the world into a framebuffer at 1:1 scaling to allow the depth buffer to match the artwork at all zoom levels worldBuffer = Context.CreateFrameBuffer(worldBufferSize); @@ -329,8 +326,7 @@ namespace OpenRA { if (currentBatchRenderer == value) return; - if (currentBatchRenderer != null) - currentBatchRenderer.Flush(); + currentBatchRenderer?.Flush(); currentBatchRenderer = value; } } @@ -460,8 +456,7 @@ namespace OpenRA { WorldModelRenderer.Dispose(); tempBuffer.Dispose(); - if (fontSheetBuilder != null) - fontSheetBuilder.Dispose(); + fontSheetBuilder?.Dispose(); if (Fonts != null) foreach (var font in Fonts.Values) font.Dispose(); diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 5d29d9751e..2461cd0793 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -267,8 +267,7 @@ namespace OpenRA.Scripting return; disposed = true; - if (runtime != null) - runtime.Dispose(); + runtime?.Dispose(); } static IEnumerable ExtractRequiredTypes(Type t) diff --git a/OpenRA.Game/Scripting/ScriptTypes.cs b/OpenRA.Game/Scripting/ScriptTypes.cs index e66cbbe088..b11b6aca1c 100644 --- a/OpenRA.Game/Scripting/ScriptTypes.cs +++ b/OpenRA.Game/Scripting/ScriptTypes.cs @@ -168,8 +168,7 @@ namespace OpenRA.Scripting { // Object needs additional notification / context var notify = obj as IScriptNotifyBind; - if (notify != null) - notify.OnScriptBind(context); + notify?.OnScriptBind(context); return new LuaCustomClrObject(obj); } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 5f3af39106..26f8166490 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -244,8 +244,7 @@ namespace OpenRA.Server } var conn = Conns.SingleOrDefault(c => c.Socket == s); - if (conn != null) - conn.ReadData(this); + conn?.ReadData(this); } delayedActions.PerformActions(0); diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 15d3fa67c1..5a0e48a097 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -88,8 +88,7 @@ namespace OpenRA if (sounds != null) foreach (var soundSource in sounds.Values) - if (soundSource != null) - soundSource.Dispose(); + soundSource?.Dispose(); this.loaders = loaders; this.fileSystem = fileSystem; @@ -430,8 +429,8 @@ namespace OpenRA StopAudio(); if (sounds != null) foreach (var soundSource in sounds.Values) - if (soundSource != null) - soundSource.Dispose(); + soundSource?.Dispose(); + soundEngine.Dispose(); } } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 66401b17e5..3f4b7368db 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -113,11 +113,9 @@ namespace OpenRA.Widgets if (wasMouseOver != MouseOverWidget) { - if (wasMouseOver != null) - wasMouseOver.MouseExited(); + wasMouseOver?.MouseExited(); - if (MouseOverWidget != null) - MouseOverWidget.MouseEntered(); + MouseOverWidget?.MouseEntered(); } return handled; diff --git a/OpenRA.Game/Widgets/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs index 292ea3e5d1..3a60fc660a 100644 --- a/OpenRA.Game/Widgets/WidgetLoader.cs +++ b/OpenRA.Game/Widgets/WidgetLoader.cs @@ -50,8 +50,7 @@ namespace OpenRA var widget = NewWidget(node.Key, args); - if (parent != null) - parent.AddChild(widget); + parent?.AddChild(widget); if (node.Key.Contains("@")) FieldLoader.LoadField(widget, "Id", node.Key.Split('@')[1]); diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index c964317fea..3a26388609 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -89,8 +89,7 @@ namespace OpenRA { renderPlayer = value; - if (RenderPlayerChanged != null) - RenderPlayerChanged(value); + RenderPlayerChanged?.Invoke(value); } } } @@ -159,8 +158,7 @@ namespace OpenRA set { Sync.AssertUnsynced("The current order generator may not be changed from synced code"); - if (orderGenerator != null) - orderGenerator.Deactivate(); + orderGenerator?.Deactivate(); orderGenerator = value; } @@ -581,8 +579,7 @@ namespace OpenRA { Disposing = true; - if (OrderGenerator != null) - OrderGenerator.Deactivate(); + OrderGenerator?.Deactivate(); frameEndActions.Clear(); diff --git a/OpenRA.Mods.Cnc/Activities/Infiltrate.cs b/OpenRA.Mods.Cnc/Activities/Infiltrate.cs index be1b9a13df..257635cb2d 100644 --- a/OpenRA.Mods.Cnc/Activities/Infiltrate.cs +++ b/OpenRA.Mods.Cnc/Activities/Infiltrate.cs @@ -65,8 +65,7 @@ namespace OpenRA.Mods.Cnc.Activities t.Infiltrated(targetActor, self, infiltrates.Info.Types); var exp = self.Owner.PlayerActor.TraitOrDefault(); - if (exp != null) - exp.GiveExperience(infiltrates.Info.PlayerExperience); + exp?.GiveExperience(infiltrates.Info.PlayerExperience); if (!string.IsNullOrEmpty(infiltrates.Info.Notification)) Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", diff --git a/OpenRA.Mods.Cnc/Activities/Teleport.cs b/OpenRA.Mods.Cnc/Activities/Teleport.cs index 616ec72211..57d873aac6 100644 --- a/OpenRA.Mods.Cnc/Activities/Teleport.cs +++ b/OpenRA.Mods.Cnc/Activities/Teleport.cs @@ -97,8 +97,8 @@ namespace OpenRA.Mods.Cnc.Activities } // Consume teleport charges if this wasn't triggered via chronosphere - if (teleporter == self && pc != null) - pc.ResetChargeTime(); + if (teleporter == self) + pc?.ResetChargeTime(); // Trigger screen desaturate effect if (screenFlash) diff --git a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs index 47c63f37a6..a04f5ee0e0 100644 --- a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs +++ b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs @@ -194,8 +194,7 @@ namespace OpenRA.Mods.Cnc.Graphics public void RefreshBuffer() { - if (vertexBuffer != null) - vertexBuffer.Dispose(); + vertexBuffer?.Dispose(); vertexBuffer = Game.Renderer.CreateVertexBuffer(totalVertexCount); vertexBuffer.SetData(vertices.SelectMany(v => v).ToArray(), totalVertexCount); cachedVertexCount = totalVertexCount; @@ -234,8 +233,7 @@ namespace OpenRA.Mods.Cnc.Graphics public void Dispose() { - if (vertexBuffer != null) - vertexBuffer.Dispose(); + vertexBuffer?.Dispose(); sheetBuilder.Dispose(); } } diff --git a/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs b/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs index 4d72163f18..5f21f1d64a 100644 --- a/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs +++ b/OpenRA.Mods.Cnc/Traits/DrainPrerequisitePowerOnDamage.cs @@ -52,13 +52,8 @@ namespace OpenRA.Mods.Cnc.Traits if (!IsTraitDisabled && damage != null) { var damageSubTicks = (int)(damage.Value * 100L * Info.DamageMultiplier / Info.DamageDivisor); - if (spm.Powers.TryGetValue(Info.OrderName, out var spi)) - { - var dspi = spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance; - if (dspi != null) - dspi.Discharge(damageSubTicks); - } + (spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance)?.Discharge(damageSubTicks); } return 100; diff --git a/OpenRA.Mods.Cnc/Traits/MadTank.cs b/OpenRA.Mods.Cnc/Traits/MadTank.cs index 28dee8c129..fada306fcb 100644 --- a/OpenRA.Mods.Cnc/Traits/MadTank.cs +++ b/OpenRA.Mods.Cnc/Traits/MadTank.cs @@ -240,9 +240,7 @@ namespace OpenRA.Mods.Cnc.Traits new LocationInit(self.Location), new OwnerInit(self.Owner) }); - var driverMobile = driver.TraitOrDefault(); - if (driverMobile != null) - driverMobile.Nudge(driver); + driver.TraitOrDefault()?.Nudge(driver); } } } diff --git a/OpenRA.Mods.Cnc/Traits/TransferTimedExternalConditionOnTransform.cs b/OpenRA.Mods.Cnc/Traits/TransferTimedExternalConditionOnTransform.cs index 2eea764877..4aaed5c566 100644 --- a/OpenRA.Mods.Cnc/Traits/TransferTimedExternalConditionOnTransform.cs +++ b/OpenRA.Mods.Cnc/Traits/TransferTimedExternalConditionOnTransform.cs @@ -49,8 +49,7 @@ namespace OpenRA.Mods.Cnc.Traits var external = toActor.TraitsImplementing() .FirstOrDefault(t => t.Info.Condition == info.Condition && t.CanGrantCondition(toActor, this)); - if (external != null) - external.GrantCondition(toActor, this, duration, remaining); + external?.GrantCondition(toActor, this, duration, remaining); } void IConditionTimerWatcher.Update(int duration, int remaining) diff --git a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs index 37152eaa9e..4a3ebe124d 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs @@ -128,8 +128,8 @@ namespace OpenRA.Mods.Common.Activities return true; // AbortOnResupply cancels the current activity (after resupplying) plus any queued activities - if (attackAircraft.Info.AbortOnResupply && NextActivity != null) - NextActivity.Cancel(self); + if (attackAircraft.Info.AbortOnResupply) + NextActivity?.Cancel(self); QueueChild(new ReturnToBase(self)); returnToBase = true; diff --git a/OpenRA.Mods.Common/Activities/CaptureActor.cs b/OpenRA.Mods.Common/Activities/CaptureActor.cs index 817f505677..c0826a358f 100644 --- a/OpenRA.Mods.Common/Activities/CaptureActor.cs +++ b/OpenRA.Mods.Common/Activities/CaptureActor.cs @@ -112,11 +112,7 @@ namespace OpenRA.Mods.Common.Activities t.OnCapture(enterActor, self, oldOwner, self.Owner, captures.Info.CaptureTypes); if (self.Owner.Stances[oldOwner].HasStance(captures.Info.PlayerExperienceStances)) - { - var exp = self.Owner.PlayerActor.TraitOrDefault(); - if (exp != null) - exp.GiveExperience(captures.Info.PlayerExperience); - } + self.Owner.PlayerActor.TraitOrDefault()?.GiveExperience(captures.Info.PlayerExperience); if (captures.Info.ConsumedByCapture) self.Dispose(); diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 86893e9194..56ad2d55b4 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -177,8 +177,7 @@ namespace OpenRA.Mods.Common.Activities if (IsCanceling && mobile.CanStayInCell(mobile.ToCell)) { - if (path != null) - path.Clear(); + path?.Clear(); return true; } diff --git a/OpenRA.Mods.Common/Activities/Resupply.cs b/OpenRA.Mods.Common/Activities/Resupply.cs index b01a5f4780..3ca128062b 100644 --- a/OpenRA.Mods.Common/Activities/Resupply.cs +++ b/OpenRA.Mods.Common/Activities/Resupply.cs @@ -138,9 +138,7 @@ namespace OpenRA.Mods.Common.Activities QueueChild(move.MoveTo(targetCell, targetLineColor: Color.Green)); var delta = (self.CenterPosition - host.CenterPosition).LengthSquared; - var transport = transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta); - if (transport != null) - transport.RequestTransport(self, targetCell); + transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell); return false; } @@ -261,11 +259,7 @@ namespace OpenRA.Mods.Common.Activities if (health.DamageState == DamageState.Undamaged) { if (host.Actor.Owner != self.Owner) - { - var exp = host.Actor.Owner.PlayerActor.TraitOrDefault(); - if (exp != null) - exp.GiveExperience(repairsUnits.Info.PlayerExperience); - } + host.Actor.Owner.PlayerActor.TraitOrDefault()?.GiveExperience(repairsUnits.Info.PlayerExperience); Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", repairsUnits.Info.FinishRepairingNotification, self.Owner.Faction.InternalName); diff --git a/OpenRA.Mods.Common/ColorValidator.cs b/OpenRA.Mods.Common/ColorValidator.cs index 3dd2cd3a09..4716803089 100644 --- a/OpenRA.Mods.Common/ColorValidator.cs +++ b/OpenRA.Mods.Common/ColorValidator.cs @@ -60,8 +60,7 @@ namespace OpenRA.Mods.Common askedColor.ToAhsv(out _, out _, out var s, out var v); if (s < HsvSaturationRange[0] || s > HsvSaturationRange[1] || v < HsvValueRange[0] || v > HsvValueRange[1]) { - if (errorMessages != null) - errorMessages.Add("Color was adjusted to be inside the allowed range."); + errorMessages?.Add("Color was adjusted to be inside the allowed range."); forbiddenColor = askedColor; return false; } @@ -69,16 +68,14 @@ namespace OpenRA.Mods.Common // Validate color against the current map tileset if (!IsValid(askedColor, terrainColors, out forbiddenColor)) { - if (errorMessages != null) - errorMessages.Add("Color was adjusted to be less similar to the terrain."); + errorMessages?.Add("Color was adjusted to be less similar to the terrain."); return false; } // Validate color against other clients if (!IsValid(askedColor, playerColors, out forbiddenColor)) { - if (errorMessages != null) - errorMessages.Add("Color was adjusted to be less similar to another player."); + errorMessages?.Add("Color was adjusted to be less similar to another player."); return false; } diff --git a/OpenRA.Mods.Common/DiscordService.cs b/OpenRA.Mods.Common/DiscordService.cs index d6c88c68cf..20789b0b9a 100644 --- a/OpenRA.Mods.Common/DiscordService.cs +++ b/OpenRA.Mods.Common/DiscordService.cs @@ -178,37 +178,27 @@ namespace OpenRA.Mods.Common public static void UpdateStatus(DiscordState state, string details = null, string secret = null, int? players = null, int? slots = null) { - var service = GetService(); - if (service != null) - service.SetStatus(state, details, secret, players, slots); + GetService()?.SetStatus(state, details, secret, players, slots); } public static void SetPlayers(int players, int slots) { - var service = GetService(); - if (service != null) + GetService()?.client.UpdateParty(new Party { - service.client.UpdateParty(new Party - { - ID = Secrets.CreateFriendlySecret(new Random()), - Size = players, - Max = slots - }); - } + ID = Secrets.CreateFriendlySecret(new Random()), + Size = players, + Max = slots + }); } public static void UpdatePlayers(int players, int slots) { - var service = GetService(); - if (service != null) - service.client.UpdatePartySize(players, slots); + GetService()?.client.UpdatePartySize(players, slots); } public static void UpdateDetails(string details) { - var service = GetService(); - if (service != null) - service.client.UpdateDetails(details); + GetService()?.client.UpdateDetails(details); } } } diff --git a/OpenRA.Mods.Common/Effects/Beacon.cs b/OpenRA.Mods.Common/Effects/Beacon.cs index 7bda4fe1ef..f6a0f92b89 100644 --- a/OpenRA.Mods.Common/Effects/Beacon.cs +++ b/OpenRA.Mods.Common/Effects/Beacon.cs @@ -96,17 +96,10 @@ namespace OpenRA.Mods.Common.Effects arrowSpeed *= -1; } - if (arrow != null) - arrow.Tick(); - - if (beacon != null) - beacon.Tick(); - - if (circles != null) - circles.Tick(); - - if (clock != null) - clock.Tick(); + arrow?.Tick(); + beacon?.Tick(); + circles?.Tick(); + clock?.Tick(); if (duration > 0 && duration <= tick++) owner.World.AddFrameEndTask(w => w.Remove(this)); diff --git a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs index 56d950004a..692952006a 100644 --- a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs +++ b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs @@ -48,18 +48,15 @@ namespace OpenRA.Mods.Common.Effects void IEffect.Tick(World world) { - if (flag != null) - flag.Tick(); + flag?.Tick(); - if (circles != null) - circles.Tick(); + circles?.Tick(); if (cachedLocations == null || !cachedLocations.SequenceEqual(rp.Path)) { UpdateTargetLineNodes(world); - if (circles != null) - circles.Play(rp.Info.CirclesSequence); + circles?.Play(rp.Info.CirclesSequence); } if (!building.IsInWorld || building.IsDead) diff --git a/OpenRA.Mods.Common/FileFormats/Blast.cs b/OpenRA.Mods.Common/FileFormats/Blast.cs index af610f9c52..0acdb8edb8 100644 --- a/OpenRA.Mods.Common/FileFormats/Blast.cs +++ b/OpenRA.Mods.Common/FileFormats/Blast.cs @@ -107,8 +107,7 @@ namespace OpenRA.Mods.Common.FileFormats for (var i = 0; i < next; i++) output.WriteByte(outBuffer[i]); - if (onProgress != null) - onProgress(input.Position - inputStart, output.Position - outputStart); + onProgress?.Invoke(input.Position - inputStart, output.Position - outputStart); break; } @@ -155,8 +154,7 @@ namespace OpenRA.Mods.Common.FileFormats next = 0; first = false; - if (onProgress != null) - onProgress(input.Position - inputStart, output.Position - outputStart); + onProgress?.Invoke(input.Position - inputStart, output.Position - outputStart); } } while (len != 0); @@ -173,8 +171,7 @@ namespace OpenRA.Mods.Common.FileFormats next = 0; first = false; - if (onProgress != null) - onProgress(input.Position - inputStart, output.Position - outputStart); + onProgress?.Invoke(input.Position - inputStart, output.Position - outputStart); } } } diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs index 822bde423f..ff326cf82e 100644 --- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs @@ -243,8 +243,7 @@ namespace OpenRA.Mods.Common.FileFormats toExtract -= bytesToExtract; while (!inf.IsNeedingInput) { - if (onProgress != null) - onProgress((int)(100 * output.Position / file.ExpandedSize)); + onProgress?.Invoke((int)(100 * output.Position / file.ExpandedSize)); var inflated = inf.Inflate(buffer); output.Write(buffer, 0, inflated); @@ -258,8 +257,7 @@ namespace OpenRA.Mods.Common.FileFormats { do { - if (onProgress != null) - onProgress((int)(100 * output.Position / file.ExpandedSize)); + onProgress?.Invoke((int)(100 * output.Position / file.ExpandedSize)); toExtract -= remainingInArchive; output.Write(GetBytes(remainingInArchive), 0, (int)remainingInArchive); diff --git a/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs b/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs index f772d8b15f..250f6c7803 100644 --- a/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs @@ -101,8 +101,7 @@ namespace OpenRA.Mods.Common.FileFormats var decompressedBytes = 0; for (var i = 0; i < folder.BlockCount; i++) { - if (onProgress != null) - onProgress((int)(100 * output.Position / file.DecompressedLength)); + onProgress?.Invoke((int)(100 * output.Position / file.DecompressedLength)); // Ignore checksums stream.Position += 4; diff --git a/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs index 2c86c4cfec..915b3b20eb 100644 --- a/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs @@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.LoadScreens dpiScale = scale; // Force images to be reloaded on the next display - if (sheet != null) - sheet.Dispose(); + sheet?.Dispose(); sheet = null; } @@ -94,8 +93,8 @@ namespace OpenRA.Mods.Common.LoadScreens protected override void Dispose(bool disposing) { - if (disposing && sheet != null) - sheet.Dispose(); + if (disposing) + sheet?.Dispose(); base.Dispose(disposing); } diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 72b71993f8..4c05099301 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -218,8 +218,7 @@ namespace OpenRA.Mods.Common.Orders world.CancelInputMode(); foreach (var v in variants) - if (v.Preview != null) - v.Preview.Tick(); + v.Preview?.Tick(); } void IOrderGenerator.SelectionChanged(World world, IEnumerable selected) { } diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index f685a70a2e..5a98843375 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -197,8 +197,7 @@ namespace OpenRA.Mods.Common.Projectiles public void Tick(World world) { - if (anim != null) - anim.Tick(); + anim?.Tick(); lastPos = pos; pos = WPos.LerpQuadratic(source, target, angle, ticks, length); diff --git a/OpenRA.Mods.Common/Projectiles/GravityBomb.cs b/OpenRA.Mods.Common/Projectiles/GravityBomb.cs index a328a6b7c7..aec40d23ee 100644 --- a/OpenRA.Mods.Common/Projectiles/GravityBomb.cs +++ b/OpenRA.Mods.Common/Projectiles/GravityBomb.cs @@ -100,8 +100,7 @@ namespace OpenRA.Mods.Common.Projectiles args.Weapon.Impact(Target.FromPos(pos), warheadArgs); } - if (anim != null) - anim.Tick(); + anim?.Tick(); } public IEnumerable Render(WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index e73f58820b..d9f1274cc5 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -792,8 +792,7 @@ namespace OpenRA.Mods.Common.Projectiles public void Tick(World world) { ticks++; - if (anim != null) - anim.Tick(); + anim?.Tick(); // Switch from freefall mode to homing mode if (ticks == info.HomingActivationDelay + 1) diff --git a/OpenRA.Mods.Common/Projectiles/Railgun.cs b/OpenRA.Mods.Common/Projectiles/Railgun.cs index f1fbe37217..27a3c69d06 100644 --- a/OpenRA.Mods.Common/Projectiles/Railgun.cs +++ b/OpenRA.Mods.Common/Projectiles/Railgun.cs @@ -227,8 +227,7 @@ namespace OpenRA.Mods.Common.Projectiles } } - if (hitanim != null) - hitanim.Tick(); + hitanim?.Tick(); if (ticks++ > info.Duration && animationComplete) world.AddFrameEndTask(w => w.Remove(this)); diff --git a/OpenRA.Mods.Common/Scripting/CallLuaFunc.cs b/OpenRA.Mods.Common/Scripting/CallLuaFunc.cs index 2be7fb89a2..237b18f3d8 100644 --- a/OpenRA.Mods.Common/Scripting/CallLuaFunc.cs +++ b/OpenRA.Mods.Common/Scripting/CallLuaFunc.cs @@ -31,8 +31,7 @@ namespace OpenRA.Mods.Common.Activities { try { - if (function != null) - function.Call().Dispose(); + function?.Call().Dispose(); } catch (Exception ex) { diff --git a/OpenRA.Mods.Common/Scripting/Global/RadarGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/RadarGlobal.cs index bb71878687..f50d90c1bc 100644 --- a/OpenRA.Mods.Common/Scripting/Global/RadarGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/RadarGlobal.cs @@ -29,14 +29,7 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Creates a new radar ping that stays for the specified time at the specified WPos.")] public void Ping(Player player, WPos position, Color color, int duration = 30 * 25) { - if (radarPings != null) - { - radarPings.Add( - () => player.World.RenderPlayer == player, - position, - color, - duration); - } + radarPings?.Add(() => player.World.RenderPlayer == player, position, color, duration); } } } diff --git a/OpenRA.Mods.Common/Scripting/LuaScript.cs b/OpenRA.Mods.Common/Scripting/LuaScript.cs index 67613df245..3259448d73 100644 --- a/OpenRA.Mods.Common/Scripting/LuaScript.cs +++ b/OpenRA.Mods.Common/Scripting/LuaScript.cs @@ -54,8 +54,7 @@ namespace OpenRA.Mods.Common.Scripting if (disposed) return; - if (context != null) - context.Dispose(); + context?.Dispose(); disposed = true; } diff --git a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs index f479706368..a641b59c81 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs @@ -172,10 +172,7 @@ namespace OpenRA.Mods.Common.Scripting { get { - if (autotarget == null) - return null; - - return autotarget.Stance.ToString(); + return autotarget?.Stance.ToString(); } set @@ -197,10 +194,8 @@ namespace OpenRA.Mods.Common.Scripting get { var tooltip = tooltips.FirstEnabledTraitOrDefault(); - if (tooltip == null) - return null; - return tooltip.Info.Name; + return tooltip?.Info.Name; } } diff --git a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs index 4fdbb52c03..5910665b9a 100644 --- a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs @@ -98,8 +98,7 @@ namespace OpenRA.Mods.Common.Server public void GameEnded(S server) { - if (LanGameBeacon != null) - LanGameBeacon.Stop(); + LanGameBeacon?.Stop(); lastChanged = Game.RunTime; } diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/StateMachine.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/StateMachine.cs index 2eafad5b63..da298c0de8 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/StateMachine.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/StateMachine.cs @@ -18,8 +18,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads public void Update(Squad squad) { - if (currentState != null) - currentState.Tick(squad); + currentState?.Tick(squad); } public void ChangeState(Squad squad, IState newState, bool rememberPrevious) @@ -27,14 +26,12 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads if (rememberPrevious) previousState = currentState; - if (currentState != null) - currentState.Deactivate(squad); + currentState?.Deactivate(squad); if (newState != null) currentState = newState; - if (currentState != null) - currentState.Activate(squad); + currentState?.Activate(squad); } public void RevertToPreviousState(Squad squad, bool saveCurrentState) diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs index ae5deb6cf4..a59a8f78aa 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs @@ -302,8 +302,7 @@ namespace OpenRA.Mods.Common.Traits // If this bridge repair operation connects two pathfinding domains, // update the domain index. var domainIndex = self.World.WorldActor.TraitOrDefault(); - if (domainIndex != null) - domainIndex.UpdateCells(self.World, footprint.Keys); + domainIndex?.UpdateCells(self.World, footprint.Keys); if (LongBridgeSegmentIsDead() && !killedUnits) { diff --git a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs index 6ed8756e7e..cf751b2302 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs @@ -70,9 +70,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var cell in cells) self.World.Map.CustomTerrain[cell] = terrainIndex; - var domainIndex = self.World.WorldActor.TraitOrDefault(); - if (domainIndex != null) - domainIndex.UpdateCells(self.World, cells); + self.World.WorldActor.TraitOrDefault()?.UpdateCells(self.World, cells); } void INotifyAddedToWorld.AddedToWorld(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs index 3aa4ba7f7e..6839080080 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs @@ -91,10 +91,7 @@ namespace OpenRA.Mods.Common.Traits void INotifyLineBuildSegmentsChanged.SegmentRemoved(Actor self, Actor segment) { - if (segments == null) - return; - - segments.Remove(segment); + segments?.Remove(segment); } void INotifyAddedToWorld.AddedToWorld(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index 047eb9165b..4a979c10a7 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -172,9 +172,7 @@ namespace OpenRA.Mods.Common.Traits if (r == self.Owner) return; - var exp = r.PlayerActor.TraitOrDefault(); - if (exp != null) - exp.GiveExperience(Info.PlayerExperience); + r.PlayerActor.TraitOrDefault()?.GiveExperience(Info.PlayerExperience); }); Repairers.Clear(); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs index f61c36d8f9..5d83c0229e 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs @@ -131,8 +131,8 @@ namespace OpenRA.Mods.Common.Traits // Manually manage the inner activity queue var activity = currentTransform ?? transform.GetTransformActivity(self); - if (!order.Queued && activity.NextActivity != null) - activity.NextActivity.Cancel(self); + if (!order.Queued) + activity.NextActivity?.Cancel(self); activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs index ac03452c9a..d691dce88d 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs @@ -95,8 +95,8 @@ namespace OpenRA.Mods.Common.Traits // Manually manage the inner activity queue var activity = currentTransform ?? transform.GetTransformActivity(self); - if (!order.Queued && activity.NextActivity != null) - activity.NextActivity.Cancel(self); + if (!order.Queued) + activity.NextActivity?.Cancel(self); activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs index 4b6b43eae4..9373be162d 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs @@ -110,8 +110,8 @@ namespace OpenRA.Mods.Common.Traits // Manually manage the inner activity queue var activity = currentTransform ?? transform.GetTransformActivity(self); - if (!order.Queued && activity.NextActivity != null) - activity.NextActivity.Cancel(self); + if (!order.Queued) + activity.NextActivity?.Cancel(self); activity.Queue(new IssueOrderAfterTransform("Move", order.Target, Color.Green)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs index b8f24b649b..a657ab0c46 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs @@ -129,8 +129,8 @@ namespace OpenRA.Mods.Common.Traits // Manually manage the inner activity queue var activity = currentTransform ?? transform.GetTransformActivity(self); - if (!order.Queued && activity.NextActivity != null) - activity.NextActivity.Cancel(self); + if (!order.Queued) + activity.NextActivity?.Cancel(self); activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs index e7b37b05dd..3762faaea9 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs @@ -123,8 +123,8 @@ namespace OpenRA.Mods.Common.Traits // Manually manage the inner activity queue var activity = currentTransform ?? transform.GetTransformActivity(self); - if (!order.Queued && activity.NextActivity != null) - activity.NextActivity.Cancel(self); + if (!order.Queued) + activity.NextActivity?.Cancel(self); activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs index 17b8c12196..1103c5078b 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoTransforms.cs @@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued || currentTransform == null) return; - if (!order.Queued && currentTransform.NextActivity != null) - currentTransform.NextActivity.Cancel(self); + if (!order.Queued) + currentTransform.NextActivity?.Cancel(self); currentTransform.Queue(new IssueOrderAfterTransform("DeployTransform", order.Target, Color.Green)); diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToCrusher.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToCrusher.cs index 5faf30b706..e2cb7304ae 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToCrusher.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToCrusher.cs @@ -44,20 +44,16 @@ namespace OpenRA.Mods.Common.Traits void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet crushClasses) { - var external = crusher.TraitsImplementing() - .FirstOrDefault(t => t.Info.Condition == Info.OnCrushCondition && t.CanGrantCondition(crusher, self)); - - if (external != null) - external.GrantCondition(crusher, self, Info.OnCrushDuration); + crusher.TraitsImplementing() + .FirstOrDefault(t => t.Info.Condition == Info.OnCrushCondition && t.CanGrantCondition(crusher, self)) + ?.GrantCondition(crusher, self, Info.OnCrushDuration); } void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet crushClasses) { - var external = crusher.TraitsImplementing() - .FirstOrDefault(t => t.Info.Condition == Info.WarnCrushCondition && t.CanGrantCondition(crusher, self)); - - if (external != null) - external.GrantCondition(crusher, self, Info.WarnCrushDuration); + crusher.TraitsImplementing() + .FirstOrDefault(t => t.Info.Condition == Info.WarnCrushCondition && t.CanGrantCondition(crusher, self)) + ?.GrantCondition(crusher, self, Info.WarnCrushDuration); } } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToProduced.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToProduced.cs index 0f8f0dd02e..665723b399 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToProduced.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantExternalConditionToProduced.cs @@ -36,11 +36,9 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled || other.IsDead) return; - var external = other.TraitsImplementing() - .FirstOrDefault(t => t.Info.Condition == Info.Condition && t.CanGrantCondition(other, self)); - - if (external != null) - external.GrantCondition(other, self, Info.Duration); + other.TraitsImplementing() + .FirstOrDefault(t => t.Info.Condition == Info.Condition && t.CanGrantCondition(other, self)) + ?.GrantCondition(other, self, Info.Duration); } } } diff --git a/OpenRA.Mods.Common/Traits/Crates/Crate.cs b/OpenRA.Mods.Common/Traits/Crates/Crate.cs index d299a5c38f..244a71dee1 100644 --- a/OpenRA.Mods.Common/Traits/Crates/Crate.cs +++ b/OpenRA.Mods.Common/Traits/Crates/Crate.cs @@ -248,9 +248,7 @@ namespace OpenRA.Mods.Common.Traits { self.World.AddToMaps(self, this); - var cs = self.World.WorldActor.TraitOrDefault(); - if (cs != null) - cs.IncrementCrates(); + self.World.WorldActor.TraitOrDefault()?.IncrementCrates(); if (self.World.Map.DistanceAboveTerrain(CenterPosition) > WDist.Zero && self.TraitOrDefault() != null) self.QueueActivity(new Parachute(self)); @@ -260,9 +258,7 @@ namespace OpenRA.Mods.Common.Traits { self.World.RemoveFromMaps(self, this); - var cs = self.World.WorldActor.TraitOrDefault(); - if (cs != null) - cs.DecrementCrates(); + self.World.WorldActor.TraitOrDefault()?.DecrementCrates(); } } } diff --git a/OpenRA.Mods.Common/Traits/Crates/LevelUpCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/LevelUpCrateAction.cs index 94017f9f82..b3648d8c4d 100644 --- a/OpenRA.Mods.Common/Traits/Crates/LevelUpCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/LevelUpCrateAction.cs @@ -72,9 +72,7 @@ namespace OpenRA.Mods.Common.Traits var recipient = actor; // loop variable in closure hazard recipient.World.AddFrameEndTask(w => { - var gainsExperience = recipient.TraitOrDefault(); - if (gainsExperience != null) - gainsExperience.GiveLevels(info.Levels); + recipient.TraitOrDefault()?.GiveLevels(info.Levels); }); } diff --git a/OpenRA.Mods.Common/Traits/EjectOnDeath.cs b/OpenRA.Mods.Common/Traits/EjectOnDeath.cs index c15a8cd478..b8587d77ff 100644 --- a/OpenRA.Mods.Common/Traits/EjectOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/EjectOnDeath.cs @@ -90,11 +90,7 @@ namespace OpenRA.Mods.Common.Traits var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td); if (!inAir) - { - var pilotMobile = pilot.TraitOrDefault(); - if (pilotMobile != null) - pilotMobile.Nudge(pilot); - } + pilot.TraitOrDefault()?.Nudge(pilot); else Game.Sound.Play(SoundType.World, Info.ChuteSound, cp); }); diff --git a/OpenRA.Mods.Common/Traits/GivesExperience.cs b/OpenRA.Mods.Common/Traits/GivesExperience.cs index 80947f3bec..fe79c7d61a 100644 --- a/OpenRA.Mods.Common/Traits/GivesExperience.cs +++ b/OpenRA.Mods.Common/Traits/GivesExperience.cs @@ -66,9 +66,8 @@ namespace OpenRA.Mods.Common.Traits killer.GiveExperience(Util.ApplyPercentageModifiers(exp, killerExperienceModifier)); } - var attackerExp = e.Attacker.Owner.PlayerActor.TraitOrDefault(); - if (attackerExp != null) - attackerExp.GiveExperience(Util.ApplyPercentageModifiers(exp, new[] { info.PlayerExperienceModifier })); + e.Attacker.Owner.PlayerActor.TraitOrDefault() + ?.GiveExperience(Util.ApplyPercentageModifiers(exp, new[] { info.PlayerExperienceModifier })); } } } diff --git a/OpenRA.Mods.Common/Traits/Player/AllyRepair.cs b/OpenRA.Mods.Common/Traits/Player/AllyRepair.cs index ba78fc2781..094f69a482 100644 --- a/OpenRA.Mods.Common/Traits/Player/AllyRepair.cs +++ b/OpenRA.Mods.Common/Traits/Player/AllyRepair.cs @@ -26,9 +26,7 @@ namespace OpenRA.Mods.Common.Traits if (!building.AppearsFriendlyTo(self)) return; - var rb = building.TraitOrDefault(); - if (rb != null) - rb.RepairBuilding(building, self.Owner); + building.TraitOrDefault()?.RepairBuilding(building, self.Owner); } } } diff --git a/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs b/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs index b4a182cb46..efd64debe5 100644 --- a/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs @@ -80,8 +80,7 @@ namespace OpenRA.Mods.Common.Traits if (p != self.Owner && p.IsAlliedWith(self.Owner) && p != e.Attacker.Owner) Game.Sound.PlayNotification(rules, p, "Speech", info.AllyNotification, p.Faction.InternalName); - if (radarPings != null) - radarPings.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration); + radarPings?.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration); } lastAttackTime = self.World.WorldTick; diff --git a/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs b/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs index 0fe0136a94..7e6653b71c 100644 --- a/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs @@ -244,10 +244,7 @@ namespace OpenRA.Mods.Common.Traits case "DevPlayerExperience": { - var playerExperience = self.Owner.PlayerActor.TraitOrDefault(); - if (playerExperience != null) - playerExperience.GiveExperience((int)order.ExtraData); - + self.Owner.PlayerActor.TraitOrDefault()?.GiveExperience((int)order.ExtraData); break; } diff --git a/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs b/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs index 21b8e8ec35..40d9ce6b9b 100644 --- a/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs +++ b/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs @@ -61,8 +61,7 @@ namespace OpenRA.Mods.Common.Traits { Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName); - if (radarPings != null) - radarPings.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration); + radarPings?.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration); } lastAttackTime = self.World.WorldTick; diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index 9dfd31ee76..6ebb986aec 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -170,8 +170,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var t in buildingInfo.Tiles(targetLocation)) { var host = buildingInfluence.GetBuildingAt(t); - if (host != null) - host.World.Remove(host); + host?.World.Remove(host); } } @@ -193,14 +192,10 @@ namespace OpenRA.Mods.Common.Traits queue.EndProduction(item); + // FindBaseProvider may return null if the build anywhere cheat is active + // BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location if (buildingInfo.RequiresBaseProvider) - { - // May be null if the build anywhere cheat is active - // BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location - var provider = buildingInfo.FindBaseProvider(w, self.Owner, targetLocation); - if (provider != null) - provider.BeginCooldown(); - } + buildingInfo.FindBaseProvider(w, self.Owner, targetLocation)?.BeginCooldown(); if (GetNumBuildables(self.Owner) > prevItems) triggerNotification = true; diff --git a/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs b/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs index de374dff5d..9fdb107c1c 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs @@ -61,8 +61,7 @@ namespace OpenRA.Mods.Common.Traits { terrainColor[uv] = GetColor(world.Map, uv); - if (CellTerrainColorChanged != null) - CellTerrainColorChanged(uv); + CellTerrainColorChanged?.Invoke(uv); } public void WorldLoaded(World w, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs index 7196627acd..ea9b19a7b3 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs @@ -465,9 +465,7 @@ namespace OpenRA.Mods.Common.Traits protected void PauseProduction(string itemName, bool paused) { - var item = Queue.FirstOrDefault(a => a.Item == itemName); - if (item != null) - item.Pause(paused); + Queue.FirstOrDefault(a => a.Item == itemName)?.Pause(paused); } protected void CancelProduction(string itemName, uint numberToCancel) @@ -646,8 +644,7 @@ namespace OpenRA.Mods.Common.Traits if (Done) { - if (OnComplete != null) - OnComplete(); + OnComplete?.Invoke(); return; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs index 59be5403a5..7dfba69dba 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs @@ -105,14 +105,11 @@ namespace OpenRA.Mods.Common.Traits.Render { Reverse(self, () => { - var wsb = wsbs.FirstEnabledTraitOrDefault(); - // HACK: The actor remains alive and active for one tick before the followup activity // (sell/transform/etc) runs. This causes visual glitches that we attempt to minimize // by forcing the animation to frame 0 and regranting the make condition. // These workarounds will break the actor if the followup activity doesn't dispose it! - if (wsb != null) - wsb.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0); + wsbs.FirstEnabledTraitOrDefault()?.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0); token = self.GrantCondition(info.Condition); diff --git a/OpenRA.Mods.Common/Traits/Render/WithParachute.cs b/OpenRA.Mods.Common/Traits/Render/WithParachute.cs index 0a3dc360c0..fc64dbaa3c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithParachute.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithParachute.cs @@ -159,8 +159,7 @@ namespace OpenRA.Mods.Common.Traits.Render void ITick.Tick(Actor self) { - if (shadow != null) - shadow.Tick(); + shadow?.Tick(); } IEnumerable IRender.Render(Actor self, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs index b73b8c2974..56d1777bb7 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs @@ -97,8 +97,7 @@ namespace OpenRA.Mods.Common.Traits.Render DefaultAnimation.PlayThen(NormalizeSequence(self, name), () => { CancelCustomAnimation(self); - if (after != null) - after(); + after?.Invoke(); }); } @@ -112,8 +111,7 @@ namespace OpenRA.Mods.Common.Traits.Render DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name), () => { CancelCustomAnimation(self); - if (after != null) - after(); + after?.Invoke(); }); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs index c53f959ccb..e391a116ea 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs @@ -132,8 +132,7 @@ namespace OpenRA.Mods.Common.Traits.Render DefaultAnimation.PlayThen(NormalizeSequence(self, name), () => { CancelCustomAnimation(self); - if (after != null) - after(); + after?.Invoke(); }); } diff --git a/OpenRA.Mods.Common/Traits/Sound/AnnounceOnSeen.cs b/OpenRA.Mods.Common/Traits/Sound/AnnounceOnSeen.cs index 9a571ffb95..d3874b9024 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AnnounceOnSeen.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AnnounceOnSeen.cs @@ -57,8 +57,8 @@ namespace OpenRA.Mods.Common.Traits.Sound Game.Sound.PlayNotification(self.World.Map.Rules, discoverer, "Speech", Info.Notification, discoverer.Faction.InternalName); // Radar notification - if (Info.PingRadar && radarPings.Value != null) - radarPings.Value.Add(() => true, self.CenterPosition, Color.Red, 50); + if (Info.PingRadar) + radarPings.Value?.Add(() => true, self.CenterPosition, Color.Red, 50); } } } diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs index 79ff198fe4..85e4539318 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs @@ -83,13 +83,9 @@ namespace OpenRA.Mods.Common.Traits Game.Sound.Play(SoundType.World, info.OnFireSound, order.Target.CenterPosition); foreach (var a in UnitsInRange(self.World.Map.CellContaining(order.Target.CenterPosition))) - { - var external = a.TraitsImplementing() - .FirstOrDefault(t => t.Info.Condition == info.Condition && t.CanGrantCondition(a, self)); - - if (external != null) - external.GrantCondition(a, self, info.Duration); - } + a.TraitsImplementing() + .FirstOrDefault(t => t.Info.Condition == info.Condition && t.CanGrantCondition(a, self)) + ?.GrantCondition(a, self, info.Duration); } public IEnumerable UnitsInRange(CPos xy) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index 67fa0c9c59..fa3b98b8d4 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -227,10 +227,8 @@ namespace OpenRA.Mods.Common.Traits return; var power = Instances.FirstOrDefault(i => !i.IsTraitPaused); - if (power == null) - return; - power.SelectTarget(power.Self, Key, Manager); + power?.SelectTarget(power.Self, Key, Manager); } public virtual void Activate(Order order) diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index f1704dd36a..a81882026c 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -381,8 +381,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var t in triggers) t.Dirty = true; - if (CellUpdated != null) - CellUpdated(c.Cell); + CellUpdated?.Invoke(c.Cell); } } @@ -403,8 +402,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var t in triggers) t.Dirty = true; - if (CellUpdated != null) - CellUpdated(c.Cell); + CellUpdated?.Invoke(c.Cell); } } diff --git a/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs b/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs index a4fced5a45..4bebd35f75 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs @@ -49,8 +49,7 @@ namespace OpenRA.Mods.Common.Traits ClearRedo(); undoStack.Push(actionContainer); - if (ItemAdded != null) - ItemAdded(actionContainer); + ItemAdded?.Invoke(actionContainer); } public void Undo() @@ -66,8 +65,7 @@ namespace OpenRA.Mods.Common.Traits editorAction.Status = EditorActionStatus.Future; redoStack.Push(editorAction); - if (OnChange != null) - OnChange(); + OnChange?.Invoke(); } void ClearRedo() @@ -76,8 +74,7 @@ namespace OpenRA.Mods.Common.Traits { var item = redoStack.Pop(); - if (ItemRemoved != null) - ItemRemoved(item); + ItemRemoved?.Invoke(item); } } @@ -95,8 +92,7 @@ namespace OpenRA.Mods.Common.Traits undoStack.Peek().Status = EditorActionStatus.History; undoStack.Push(editorAction); - if (OnChange != null) - OnChange(); + OnChange?.Invoke(); } public bool HasUndos() diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index 03dede4168..65a3b3ce4f 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -92,8 +92,7 @@ namespace OpenRA.Mods.Common.Traits UpdateNetWorth(t.Type, t.Density, newTile.Type, newTile.Density); Tiles[uv] = newTile; Map.CustomTerrain[uv] = newTerrain; - if (CellChanged != null) - CellChanged(cell, type); + CellChanged?.Invoke(cell, type); // Neighbouring cell density depends on this cell foreach (var d in CVec.Directions) @@ -111,8 +110,7 @@ namespace OpenRA.Mods.Common.Traits neighbouringTile.Density = density; Tiles[neighbouringCell] = neighbouringTile; - if (CellChanged != null) - CellChanged(neighbouringCell, type); + CellChanged?.Invoke(neighbouringCell, type); } } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index 55cab4b9fa..f80f31b75b 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -158,8 +158,7 @@ namespace OpenRA.Mods.Common.Traits cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n); Content[p] = cell; - if (CellChanged != null) - CellChanged(p, cell.Type); + CellChanged?.Invoke(p, cell.Type); } public bool IsFull(CPos cell) @@ -183,8 +182,7 @@ namespace OpenRA.Mods.Common.Traits else Content[cell] = c; - if (CellChanged != null) - CellChanged(cell, c.Type); + CellChanged?.Invoke(cell, c.Type); return c.Type; } @@ -202,8 +200,7 @@ namespace OpenRA.Mods.Common.Traits Content[cell] = ResourceLayerContents.Empty; world.Map.CustomTerrain[cell] = byte.MaxValue; - if (CellChanged != null) - CellChanged(cell, c.Type); + CellChanged?.Invoke(cell, c.Type); } public ResourceType GetResourceType(CPos cell) { return Content[cell].Type; } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs index 21ae9bf040..26925826e3 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/MoveClassicFacingFudge.cs @@ -70,8 +70,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules foreach (var sequence in sequenceNode.Value.Nodes) { var facingFudgeNode = sequence.LastChildMatching("UseClassicFacingFudge"); - if (facingFudgeNode != null) - facingFudgeNode.RenameKey("UseClassicFacings"); + facingFudgeNode?.RenameKey("UseClassicFacings"); } yield break; diff --git a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs index 13cee511ea..45d93ec225 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs @@ -263,8 +263,7 @@ namespace OpenRA.Mods.Common.UpdateRules public static void Save(this YamlFileSet files) { foreach (var file in files) - if (file.Item1 != null) - file.Item1.Update(file.Item2, Encoding.UTF8.GetBytes(file.Item3.WriteToString())); + file.Item1?.Update(file.Item2, Encoding.UTF8.GetBytes(file.Item3.WriteToString())); } /// Checks if node is a removal (has '-' prefix) diff --git a/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs b/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs index 381f80cdda..9255ad59e3 100644 --- a/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs @@ -38,11 +38,9 @@ namespace OpenRA.Mods.Common.Warheads if (!IsValidAgainst(a, firedBy)) continue; - var external = a.TraitsImplementing() - .FirstOrDefault(t => t.Info.Condition == Condition && t.CanGrantCondition(a, firedBy)); - - if (external != null) - external.GrantCondition(a, firedBy, Duration); + a.TraitsImplementing() + .FirstOrDefault(t => t.Info.Condition == Condition && t.CanGrantCondition(a, firedBy)) + ?.GrantCondition(a, firedBy, Duration); } } } diff --git a/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs b/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs index 944649ea43..23b8a0b8ec 100644 --- a/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs +++ b/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs @@ -71,8 +71,7 @@ namespace OpenRA.Mods.Common.Widgets cancelButton.OnClick = () => { Ui.CloseWindow(); - if (onCancel != null) - onCancel(); + onCancel?.Invoke(); }; if (!string.IsNullOrEmpty(cancelText) && cancelButton != null) @@ -85,8 +84,7 @@ namespace OpenRA.Mods.Common.Widgets otherButton.Bounds.Y += headerHeight; otherButton.OnClick = () => { - if (onOther != null) - onOther(); + onOther?.Invoke(); }; if (!string.IsNullOrEmpty(otherText) && otherButton != null) @@ -156,8 +154,7 @@ namespace OpenRA.Mods.Common.Widgets cancelButton.OnClick = () => { Ui.CloseWindow(); - if (onCancel != null) - onCancel(); + onCancel?.Invoke(); }; // Validation diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs index 00dc7cc790..8c104e2fab 100644 --- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs @@ -129,9 +129,7 @@ namespace OpenRA.Mods.Common.Widgets oldBounds.Height); panelRoot.AddChild(panel); - var scrollPanel = panel as ScrollPanelWidget; - if (scrollPanel != null) - scrollPanel.ScrollToSelectedItem(); + (panel as ScrollPanelWidget)?.ScrollToSelectedItem(); } public void ShowDropDown(string panelTemplate, int maxHeight, IEnumerable options, Func setupItem) diff --git a/OpenRA.Mods.Common/Widgets/EditorViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/EditorViewportControllerWidget.cs index 7fe2cd10e4..a4d4d8c6e7 100644 --- a/OpenRA.Mods.Common/Widgets/EditorViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/EditorViewportControllerWidget.cs @@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Widgets public void ClearBrush() { SetBrush(null); } public void SetBrush(IEditorBrush brush) { - if (CurrentBrush != null) - CurrentBrush.Dispose(); + CurrentBrush?.Dispose(); CurrentBrush = brush ?? DefaultBrush; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs index a8792e669b..a267616424 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs @@ -40,8 +40,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.ColorPicker)) td.Add(o); - if (preview != null) - preview.SetPreview(actor, td); + preview?.SetPreview(actor, td); var hueSlider = widget.Get("HUE"); var mixer = widget.Get("MIXER"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index 7cbe9016fa..8b7f853796 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -375,8 +375,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void Reset() { - if (editActorPreview != null) - editActorPreview.Reset(); + editActorPreview?.Reset(); } void Close() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs index 6acf0599c6..f5bf636951 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs @@ -71,8 +71,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic categorySelector.OnMouseDown = _ => { - if (SearchTextField != null) - SearchTextField.YieldKeyboardFocus(); + SearchTextField?.YieldKeyboardFocus(); categorySelector.RemovePanel(); categorySelector.AttachPanel(CreateCategoriesPanel(Panel)); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index cb6b6801f2..5896ebb879 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -233,8 +233,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public void AddChatLineWrapper(string name, Color nameColor, string text, Color textColor) { - if (chatOverlayDisplay != null) - chatOverlayDisplay.AddLine(name, nameColor, text, textColor); + chatOverlayDisplay?.AddLine(name, nameColor, text, textColor); // HACK: Force disable the chat notification sound for the in-menu chat dialog // This works around our inability to disable the sounds for the in-game dialog when it is hidden diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index dc732049db..d62d1bca07 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -64,8 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic menu = widget.Get("INGAME_MENU"); mpe = world.WorldActor.TraitOrDefault(); - if (mpe != null) - mpe.Fade(mpe.Info.MenuEffect); + mpe?.Fade(mpe.Info.MenuEffect); menu.Get("VERSION_LABEL").Text = modData.Manifest.Metadata.Version; @@ -158,8 +157,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void CloseMenu() { Ui.CloseWindow(); - if (mpe != null) - mpe.Fade(MenuPaletteEffect.EffectType.None); + mpe?.Fade(MenuPaletteEffect.EffectType.None); onExit(); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs index 7f31d160a0..c8c6e2b829 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs @@ -317,8 +317,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic output.Write(buffer, 0, write); copied += write; - if (onProgress != null) - onProgress(copied); + onProgress?.Invoke(copied); } } @@ -375,15 +374,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { Log.Write("install", "Extracting {0} -> {1}".F(sourcePath, targetPath)); if (type == ExtractionType.Blast) - { - Action onBlastProgress = (read, _) => - { - if (onProgress != null) - onProgress(read); - }; - - Blast.Decompress(source, target, onBlastProgress); - } + Blast.Decompress(source, target, (read, _) => onProgress?.Invoke(read)); else CopyStream(source, target, length, onProgress); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index a89a15aa84..231b09219d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -330,8 +330,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic onConfirm: () => { var newUid = DeleteMap(map); - if (after != null) - after(newUid); + after?.Invoke(newUid); }, confirmText: "Delete", onCancel: () => { }); @@ -345,8 +344,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic onConfirm: () => { maps.Do(m => DeleteMap(m)); - if (after != null) - after(Game.ModData.MapCache.ChooseInitialMap(null, Game.CosmeticRandom)); + after?.Invoke(Game.ModData.MapCache.ChooseInitialMap(null, Game.CosmeticRandom)); }, confirmText: "Delete", onCancel: () => { }); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index a7140fa95b..c88e50d5f6 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -350,8 +350,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic player.PlayThen(() => { StopVideo(player); - if (onComplete != null) - onComplete(); + onComplete?.Invoke(); }); // Mute other distracting sounds diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 7e1a96ca3b..9ac0df263e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -415,8 +415,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic onConfirm: () => { DeleteReplay(r); - if (after != null) - after.Invoke(); + after?.Invoke(); }, confirmText: "Delete", onCancel: () => { }); diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs index 16b678dafd..2ff583be37 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs @@ -541,8 +541,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreach (var row in rows) serverList.AddChild(row); - if (nextServerRow != null) - nextServerRow.OnClick(); + nextServerRow?.OnClick(); playerCount = games.Sum(g => g.Players); }); @@ -744,8 +743,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (disposing && !disposed) { disposed = true; - if (lanGameProbe != null) - lanGameProbe.Dispose(); + lanGameProbe?.Dispose(); } base.Dispose(disposing); diff --git a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs index 283d80df00..673347e479 100644 --- a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs +++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs @@ -326,17 +326,13 @@ namespace OpenRA.Platforms.Default public void StopSound(ISound sound) { - if (sound == null) - return; - - ((OpenAlSound)sound).Stop(); + ((OpenAlSound)sound)?.Stop(); } public void StopAllSounds() { foreach (var slot in sourcePool.Values) - if (slot.Sound != null) - slot.Sound.Stop(); + slot.Sound?.Stop(); } public void SetListenerPosition(WPos position) diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs index 46e8db6121..ff93732563 100644 --- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs +++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs @@ -415,8 +415,7 @@ namespace OpenRA.Platforms.Default disposed = true; - if (context != null) - context.Dispose(); + context?.Dispose(); if (Window != IntPtr.Zero) SDL.SDL_DestroyWindow(Window); diff --git a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs index fc04bb63da..c55e2d9c8f 100644 --- a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs +++ b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs @@ -260,8 +260,7 @@ namespace OpenRA.Platforms.Default var localResult = result; result = null; - if (localEdi != null) - localEdi.Throw(); + localEdi?.Throw(); return localResult; } } @@ -278,8 +277,7 @@ namespace OpenRA.Platforms.Default void QueueMessage(Message message) { var exception = messageException; - if (exception != null) - exception.Throw(); + exception?.Throw(); lock (messages) {