diff --git a/.editorconfig b/.editorconfig index f6f3e2f00e..28a46eb589 100644 --- a/.editorconfig +++ b/.editorconfig @@ -980,6 +980,9 @@ dotnet_diagnostic.RCS1058.severity = warning # Avoid locking on publicly accessible instance. dotnet_diagnostic.RCS1059.severity = warning +# Merge 'if' with nested 'if'. +dotnet_diagnostic.RCS1061.severity = warning + # Remove empty 'finally' clause. dotnet_diagnostic.RCS1066.severity = warning diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index c8f8602027..ad7904edc4 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -195,11 +195,11 @@ namespace OpenRA if (value != null) { var parts = value.Split(SplitComma); - if (parts.Length == 3) - { - if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz)) - return new WVec(rx, ry, rz); - } + if (parts.Length == 3 + && WDist.TryParse(parts[0], out var rx) + && WDist.TryParse(parts[1], out var ry) + && WDist.TryParse(parts[2], out var rz)) + return new WVec(rx, ry, rz); } return InvalidValueAction(value, fieldType, fieldName); @@ -219,8 +219,8 @@ namespace OpenRA for (var i = 0; i < vecs.Length; ++i) { if (WDist.TryParse(parts[3 * i], out var rx) - && WDist.TryParse(parts[3 * i + 1], out var ry) - && WDist.TryParse(parts[3 * i + 2], out var rz)) + && WDist.TryParse(parts[3 * i + 1], out var ry) + && WDist.TryParse(parts[3 * i + 2], out var rz)) vecs[i] = new WVec(rx, ry, rz); } @@ -235,13 +235,11 @@ namespace OpenRA if (value != null) { var parts = value.Split(SplitComma); - if (parts.Length == 3) - { - if (WDist.TryParse(parts[0], out var rx) - && WDist.TryParse(parts[1], out var ry) - && WDist.TryParse(parts[2], out var rz)) - return new WPos(rx, ry, rz); - } + if (parts.Length == 3 + && WDist.TryParse(parts[0], out var rx) + && WDist.TryParse(parts[1], out var ry) + && WDist.TryParse(parts[2], out var rz)) + return new WPos(rx, ry, rz); } return InvalidValueAction(value, fieldType, fieldName); @@ -259,13 +257,11 @@ namespace OpenRA if (value != null) { var parts = value.Split(SplitComma); - if (parts.Length == 3) - { - if (Exts.TryParseInt32Invariant(parts[0], out var rr) - && Exts.TryParseInt32Invariant(parts[1], out var rp) - && Exts.TryParseInt32Invariant(parts[2], out var ry)) - return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry)); - } + if (parts.Length == 3 + && Exts.TryParseInt32Invariant(parts[0], out var rr) + && Exts.TryParseInt32Invariant(parts[1], out var rp) + && Exts.TryParseInt32Invariant(parts[2], out var ry)) + return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry)); } return InvalidValueAction(value, fieldType, fieldName); diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index ed6072c8a4..c21bbb2170 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -226,14 +226,11 @@ namespace OpenRA.FileSystem public bool TryOpen(string filename, out Stream s) { var explicitSplit = filename.IndexOf('|'); - if (explicitSplit > 0) + if (explicitSplit > 0 && explicitMounts.TryGetValue(filename[..explicitSplit], out var explicitPackage)) { - if (explicitMounts.TryGetValue(filename[..explicitSplit], out var explicitPackage)) - { - s = explicitPackage.GetStream(filename[(explicitSplit + 1)..]); - if (s != null) - return true; - } + s = explicitPackage.GetStream(filename[(explicitSplit + 1)..]); + if (s != null) + return true; } s = GetFromCache(filename); @@ -262,10 +259,10 @@ namespace OpenRA.FileSystem public bool Exists(string filename) { var explicitSplit = filename.IndexOf('|'); - if (explicitSplit > 0) - if (explicitMounts.TryGetValue(filename[..explicitSplit], out var explicitPackage)) - if (explicitPackage.Contains(filename[(explicitSplit + 1)..])) - return true; + if (explicitSplit > 0 && + explicitMounts.TryGetValue(filename[..explicitSplit], out var explicitPackage) && + explicitPackage.Contains(filename[(explicitSplit + 1)..])) + return true; return fileIndex.ContainsKey(filename); } diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs index 7a7b766b18..7e17cfb68a 100644 --- a/OpenRA.Game/Network/GameServer.cs +++ b/OpenRA.Game/Network/GameServer.cs @@ -169,9 +169,8 @@ namespace OpenRA.Network } // Games advertised using the old API calculated the play time locally - if (State == 2 && PlayTime < 0) - if (DateTime.TryParse(Started, out var startTime)) - PlayTime = (int)(DateTime.UtcNow - startTime).TotalSeconds; + if (State == 2 && PlayTime < 0 && DateTime.TryParse(Started, out var startTime)) + PlayTime = (int)(DateTime.UtcNow - startTime).TotalSeconds; var externalKey = ExternalMod.MakeKey(Mod, Version); if (Game.ExternalMods.TryGetValue(externalKey, out var external) && external.Version == Version) diff --git a/OpenRA.Game/Scripting/ScriptTypes.cs b/OpenRA.Game/Scripting/ScriptTypes.cs index edfd8ff943..e86e4c17d2 100644 --- a/OpenRA.Game/Scripting/ScriptTypes.cs +++ b/OpenRA.Game/Scripting/ScriptTypes.cs @@ -40,13 +40,10 @@ namespace OpenRA.Scripting t = nullable; // Value wraps a CLR object - if (value.TryGetClrObject(out var temp)) + if (value.TryGetClrObject(out var temp) && temp.GetType() == t) { - if (temp.GetType() == t) - { - clrObject = temp; - return true; - } + clrObject = temp; + return true; } if (value is LuaNil && !t.IsValueType) diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index e4a1b7d7d3..3483b3b5b3 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -153,9 +153,8 @@ namespace OpenRA.Server return; // Regularly check player ping - if (lastPingSent.ElapsedMilliseconds > 1000) - if (TrySendData(CreatePingFrame())) - lastPingSent.Restart(); + if (lastPingSent.ElapsedMilliseconds > 1000 && TrySendData(CreatePingFrame())) + lastPingSent.Restart(); // Send all data immediately, we will block again on read while (sendQueue.TryTake(out var data, 0)) diff --git a/OpenRA.Game/Support/VariableExpression.cs b/OpenRA.Game/Support/VariableExpression.cs index 08fed5dc98..1cd2d0013f 100644 --- a/OpenRA.Game/Support/VariableExpression.cs +++ b/OpenRA.Game/Support/VariableExpression.cs @@ -750,13 +750,11 @@ namespace OpenRA.Support public void Push(Expression expression, ExpressionType type) { expressions.Add(expression); - if (type == ExpressionType.Int) - if (expression.Type != typeof(int)) - throw new InvalidOperationException($"Expected System.Int type instead of {expression.Type} for {expression}"); + if (type == ExpressionType.Int && expression.Type != typeof(int)) + throw new InvalidOperationException($"Expected System.Int type instead of {expression.Type} for {expression}"); - if (type == ExpressionType.Bool) - if (expression.Type != typeof(bool)) - throw new InvalidOperationException($"Expected System.Boolean type instead of {expression.Type} for {expression}"); + if (type == ExpressionType.Bool && expression.Type != typeof(bool)) + throw new InvalidOperationException($"Expected System.Boolean type instead of {expression.Type} for {expression}"); types.Add(type); } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 3ab1975e8a..7aeac493f9 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -312,9 +312,8 @@ namespace OpenRA.Widgets return true; foreach (var child in Children) - if (child.IsVisible()) - if (child.EventBoundsContains(location)) - return true; + if (child.IsVisible() && child.EventBoundsContains(location)) + return true; return false; } diff --git a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs index a683e189ed..d4ef9f3116 100644 --- a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs +++ b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs @@ -378,11 +378,8 @@ namespace OpenRA.Mods.Cnc.FileFormats if (tmp > 0) { MulBignumWord(esi, globOne, tmp, 2 * len); - if ((*edi & 0x8000) == 0) - { - if (SubBigNum((uint*)esi, (uint*)esi, g1, 0, (int)len) != 0) - (*edi)--; - } + if ((*edi & 0x8000) == 0 && SubBigNum((uint*)esi, (uint*)esi, g1, 0, (int)len) != 0) + (*edi)--; } } diff --git a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs index 54dcb15015..41bacf8bec 100644 --- a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs +++ b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs @@ -235,10 +235,9 @@ namespace OpenRA.Mods.Cnc.FileSystem } // Load the global mix database - if (globalFilenames == null) - if (context.TryOpen("global mix database.dat", out var mixDatabase)) - using (var db = new XccGlobalDatabase(mixDatabase)) - globalFilenames = db.Entries.ToHashSet().ToArray(); + if (globalFilenames == null && context.TryOpen("global mix database.dat", out var mixDatabase)) + using (var db = new XccGlobalDatabase(mixDatabase)) + globalFilenames = db.Entries.ToHashSet().ToArray(); package = new MixFile(s, filename, globalFilenames ?? Array.Empty()); return true; diff --git a/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs b/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs index 783290cfe1..736a23eb69 100644 --- a/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs +++ b/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs @@ -60,14 +60,11 @@ namespace OpenRA.Mods.Cnc.Graphics var tilesetNode = node.Value.NodeWithKeyOrDefault(tileset); if (tilesetNode != null) { - if (frames == null) + if (frames == null && LoadField("Length", null, data) != "*") { - if (LoadField("Length", null, data) != "*") - { - var subStart = LoadField("Start", 0, data); - var subLength = LoadField("Length", 1, data); - frames = Exts.MakeArray(subLength, i => subStart + i); - } + var subStart = LoadField("Start", 0, data); + var subLength = LoadField("Length", 1, data); + frames = Exts.MakeArray(subLength, i => subStart + i); } return new[] { new ReservationInfo(tilesetNode.Value.Value, frames, frames, tilesetNode.Location) }; diff --git a/OpenRA.Mods.Cnc/Traits/MadTank.cs b/OpenRA.Mods.Cnc/Traits/MadTank.cs index 66847f5734..ea65f6c43c 100644 --- a/OpenRA.Mods.Cnc/Traits/MadTank.cs +++ b/OpenRA.Mods.Cnc/Traits/MadTank.cs @@ -203,13 +203,10 @@ namespace OpenRA.Mods.Cnc.Traits mad.initiated = true; } - if (++ticks % mad.info.ThumpInterval == 0) + if (++ticks % mad.info.ThumpInterval == 0 && mad.info.ThumpDamageWeapon != null) { - if (mad.info.ThumpDamageWeapon != null) - { - // Use .FromPos since this weapon needs to affect more than just the MadTank actor - mad.info.ThumpDamageWeaponInfo.Impact(Target.FromPos(self.CenterPosition), self); - } + // Use .FromPos since this weapon needs to affect more than just the MadTank actor + mad.info.ThumpDamageWeaponInfo.Impact(Target.FromPos(self.CenterPosition), self); } if (ticks == mad.info.ChargeDelay) diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs index 921b756dff..2d99002d61 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs @@ -441,14 +441,12 @@ namespace OpenRA.Mods.Cnc.UtilityCommands // Only import the top-left cell of multi-celled overlays // Returning true here means this is a part of a bigger overlay that has already been handled. var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]]; - if (shape.Width > 1 && aboveType != 0xFF) - if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType) - return true; + if (shape.Width > 1 && aboveType != 0xFF && OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType) + return true; var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]]; - if (shape.Height > 1 && leftType != 0xFF) - if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType) - return true; + if (shape.Height > 1 && leftType != 0xFF && OverlayToActor.TryGetValue(leftType, out var l) && l == actorType) + return true; } actorReference = new ActorReference(actorType) diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs index b04cd6bb3a..5ad615dd4e 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs @@ -282,14 +282,12 @@ namespace OpenRA.Mods.Cnc.UtilityCommands // Only import the top-left cell of multi-celled overlays // Returning true here means this is a part of a bigger overlay that has already been handled. var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]]; - if (shape.Width > 1 && aboveType != 0xFF) - if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType) - return true; + if (shape.Width > 1 && aboveType != 0xFF && OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType) + return true; var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]]; - if (shape.Height > 1 && leftType != 0xFF) - if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType) - return true; + if (shape.Height > 1 && leftType != 0xFF && OverlayToActor.TryGetValue(leftType, out var l) && l == actorType) + return true; } // Fix position of vein hole actors. diff --git a/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs index 40046118d6..bbc2c3d4ad 100644 --- a/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs @@ -58,14 +58,11 @@ namespace OpenRA.Mods.Common.Graphics var tilesetNode = node.Value.NodeWithKeyOrDefault(tileset); if (tilesetNode != null) { - if (frames == null) + if (frames == null && LoadField("Length", null, data) != "*") { - if (LoadField("Length", null, data) != "*") - { - var subStart = LoadField("Start", 0, data); - var subLength = LoadField("Length", 1, data); - frames = Exts.MakeArray(subLength, i => subStart + i); - } + var subStart = LoadField("Start", 0, data); + var subLength = LoadField("Length", 1, data); + frames = Exts.MakeArray(subLength, i => subStart + i); } return new[] { new ReservationInfo(tilesetNode.Value.Value, frames, frames, tilesetNode.Location) }; diff --git a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs index 863475c2e1..0f2ae827b7 100644 --- a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs +++ b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs @@ -109,9 +109,10 @@ namespace OpenRA.Mods.Common.Lint } foreach (var n in node.Value.Nodes) - if (checkArgKeys.Contains(n.Key)) - if (!namedKeys.Contains(n.Value.Value) && !Hotkey.TryParse(n.Value.Value, out var unused)) - emitError($"{filename} {node.Value.Value}:{n.Key} refers to a Key named `{n.Value.Value}` that does not exist."); + if (checkArgKeys.Contains(n.Key) && + !namedKeys.Contains(n.Value.Value) && + !Hotkey.TryParse(n.Value.Value, out var unused)) + emitError($"{filename} {node.Value.Value}:{n.Key} refers to a Key named `{n.Value.Value}` that does not exist."); } if (node.Value.Nodes != null) diff --git a/OpenRA.Mods.Common/Lint/CheckOwners.cs b/OpenRA.Mods.Common/Lint/CheckOwners.cs index 2c0c2e23f6..c5ccc50ce2 100644 --- a/OpenRA.Mods.Common/Lint/CheckOwners.cs +++ b/OpenRA.Mods.Common/Lint/CheckOwners.cs @@ -40,9 +40,8 @@ namespace OpenRA.Mods.Common.Lint if (!playerNames.Contains(ownerName)) emitError($"Actor `{kv.Key}` is owned by unknown player `{ownerName}`."); - if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info)) - if (!info.ValidOwnerNames.Contains(ownerName)) - emitError($"Actor `{kv.Key}` owner `{ownerName}` is not one of ValidOwnerNames: {info.ValidOwnerNames.JoinWith(", ")}"); + if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info) && !info.ValidOwnerNames.Contains(ownerName)) + emitError($"Actor `{kv.Key}` owner `{ownerName}` is not one of ValidOwnerNames: {info.ValidOwnerNames.JoinWith(", ")}"); } } } diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs index ed252e878b..8d398d144c 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs @@ -256,9 +256,9 @@ namespace OpenRA.Mods.Common.Lint if (element is Placeable placeable) { var expression = placeable.Expression; - if (expression is IInlineExpression inlineExpression) - if (inlineExpression is VariableReference variableReference) - CheckVariableReference(variableReference.Id.Name.ToString(), key, attribute, emitWarning, file); + if (expression is IInlineExpression inlineExpression && + inlineExpression is VariableReference variableReference) + CheckVariableReference(variableReference.Id.Name.ToString(), key, attribute, emitWarning, file); if (expression is SelectExpression selectExpression) { @@ -269,9 +269,9 @@ namespace OpenRA.Mods.Common.Lint if (variantElement is Placeable variantPlaceable) { var variantExpression = variantPlaceable.Expression; - if (variantExpression is IInlineExpression variantInlineExpression) - if (variantInlineExpression is VariableReference variantVariableReference) - CheckVariableReference(variantVariableReference.Id.Name.ToString(), key, attribute, emitWarning, file); + if (variantExpression is IInlineExpression variantInlineExpression && + variantInlineExpression is VariableReference variantVariableReference) + CheckVariableReference(variantVariableReference.Id.Name.ToString(), key, attribute, emitWarning, file); } } } diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index d5ef5d4c51..c517ba5f59 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -377,9 +377,8 @@ namespace OpenRA.Mods.Common.Projectiles // If the impact position is within any actor's HitShape, we have a direct hit // PERF: Avoid using TraitsImplementing that needs to find the actor in the trait dictionary. foreach (var targetPos in victim.EnabledTargetablePositions) - if (targetPos is HitShape h) - if (h.DistanceFromEdge(victim, pos).Length <= 0) - return true; + if (targetPos is HitShape h && h.DistanceFromEdge(victim, pos).Length <= 0) + return true; } return false; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs index 1d2030c8c5..938ca4eada 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs @@ -94,9 +94,10 @@ namespace OpenRA.Mods.Common.Traits var pos = self.CenterPosition; var armaments = ChooseArmamentsForTarget(target, forceAttack); foreach (var a in armaments) - if (target.IsInRange(pos, a.MaxRange()) && (a.Weapon.MinRange == WDist.Zero || !target.IsInRange(pos, a.Weapon.MinRange))) - if (TargetInFiringArc(self, target, Info.FacingTolerance)) - return true; + if (target.IsInRange(pos, a.MaxRange()) && + (a.Weapon.MinRange == WDist.Zero || !target.IsInRange(pos, a.Weapon.MinRange)) && + TargetInFiringArc(self, target, Info.FacingTolerance)) + return true; return false; } diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index f91f20c44a..956693d5c0 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -247,13 +247,11 @@ namespace OpenRA.Mods.Common.Traits a => a.TraitInfos().Where(i => i.EnabledByDefault).Sum(p => p.Amount)); // First priority is to get out of a low power situation - if (playerPower != null && playerPower.ExcessPower < minimumExcessPower) + if (playerPower != null && playerPower.ExcessPower < minimumExcessPower && + power != null && power.TraitInfos().Where(i => i.EnabledByDefault).Sum(p => p.Amount) > 0) { - if (power != null && power.TraitInfos().Where(i => i.EnabledByDefault).Sum(p => p.Amount) > 0) - { - AIUtils.BotDebug("{0} decided to build {1}: Priority override (low power)", queue.Actor.Owner, power.Name); - return power; - } + AIUtils.BotDebug("{0} decided to build {1}: Priority override (low power)", queue.Actor.Owner, power.Name); + return power; } // Next is to build up a strong economy diff --git a/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs index 0072609f10..6b3750d085 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs @@ -34,14 +34,11 @@ namespace OpenRA.Mods.Common.Traits return; var rb = self.TraitOrDefault(); - if (rb != null) + if (rb != null && e.DamageState > DamageState.Light && e.PreviousDamageState <= DamageState.Light && !rb.RepairActive) { - if (e.DamageState > DamageState.Light && e.PreviousDamageState <= DamageState.Light && !rb.RepairActive) - { - AIUtils.BotDebug("{0} noticed damage {1} {2}->{3}, repairing.", - self.Owner, self, e.PreviousDamageState, e.DamageState); - bot.QueueOrder(new Order("RepairBuilding", self.Owner.PlayerActor, Target.FromActor(self), false)); - } + AIUtils.BotDebug("{0} noticed damage {1} {2}->{3}, repairing.", + self.Owner, self, e.PreviousDamageState, e.DamageState); + bot.QueueOrder(new Order("RepairBuilding", self.Owner.PlayerActor, Target.FromActor(self), false)); } } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs index 1306228f75..522770b1bd 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs @@ -75,11 +75,13 @@ namespace OpenRA.Mods.Common.Traits // Timed tokens do not count towards the source cap: the condition with the shortest // remaining duration can always be revoked to make room. - if (Info.SourceCap > 0) - if (permanentTokens.TryGetValue(source, out var permanentTokensForSource) && permanentTokensForSource.Count >= Info.SourceCap) - return false; + if (Info.SourceCap > 0 && + permanentTokens.TryGetValue(source, out var permanentTokensForSource) && + permanentTokensForSource.Count >= Info.SourceCap) + return false; - if (Info.TotalCap > 0 && permanentTokens.Values.Sum(t => t.Count) >= Info.TotalCap) + if (Info.TotalCap > 0 && + permanentTokens.Values.Sum(t => t.Count) >= Info.TotalCap) return false; return true; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs index 490bdaaa24..8909d0a068 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs @@ -93,29 +93,34 @@ namespace OpenRA.Mods.Common.Traits static bool TargetChanged(in Target lastTarget, in Target target) { // Invalidate reveal changing the target. - if (lastTarget.Type == TargetType.FrozenActor && target.Type == TargetType.Actor) - if (lastTarget.FrozenActor.Actor == target.Actor) - return false; + if (lastTarget.Type == TargetType.FrozenActor && + target.Type == TargetType.Actor && + lastTarget.FrozenActor.Actor == target.Actor) + return false; - if (lastTarget.Type == TargetType.Actor && target.Type == TargetType.FrozenActor) - if (target.FrozenActor.Actor == lastTarget.Actor) - return false; + if (lastTarget.Type == TargetType.Actor && + target.Type == TargetType.FrozenActor && + target.FrozenActor.Actor == lastTarget.Actor) + return false; if (lastTarget.Type != target.Type) return true; // Invalidate attacking different targets with shared target types. - if (lastTarget.Type == TargetType.Actor && target.Type == TargetType.Actor) - if (lastTarget.Actor != target.Actor) - return true; + if (lastTarget.Type == TargetType.Actor && + target.Type == TargetType.Actor && + lastTarget.Actor != target.Actor) + return true; - if (lastTarget.Type == TargetType.FrozenActor && target.Type == TargetType.FrozenActor) - if (lastTarget.FrozenActor != target.FrozenActor) - return true; + if (lastTarget.Type == TargetType.FrozenActor && + target.Type == TargetType.FrozenActor && + lastTarget.FrozenActor != target.FrozenActor) + return true; - if (lastTarget.Type == TargetType.Terrain && target.Type == TargetType.Terrain) - if (lastTarget.CenterPosition != target.CenterPosition) - return true; + if (lastTarget.Type == TargetType.Terrain && + target.Type == TargetType.Terrain && + lastTarget.CenterPosition != target.CenterPosition) + return true; return false; } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnClientDock.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnClientDock.cs index 08e2442130..faad3d20b3 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnClientDock.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnClientDock.cs @@ -48,17 +48,16 @@ namespace OpenRA.Mods.Common.Traits void INotifyDockClient.Docked(Actor self, Actor host) { - if (info.Condition != null && (info.DockHostNames == null || info.DockHostNames.Contains(host.Info.Name))) + if (info.Condition != null && + (info.DockHostNames == null || info.DockHostNames.Contains(host.Info.Name)) && + token == Actor.InvalidConditionToken) { - if (token == Actor.InvalidConditionToken) + if (delayedtoken == Actor.InvalidConditionToken) + token = self.GrantCondition(info.Condition); + else { - if (delayedtoken == Actor.InvalidConditionToken) - token = self.GrantCondition(info.Condition); - else - { - token = delayedtoken; - delayedtoken = Actor.InvalidConditionToken; - } + token = delayedtoken; + delayedtoken = Actor.InvalidConditionToken; } } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHostDock.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHostDock.cs index cb4c9f6275..4adcdbaf95 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHostDock.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHostDock.cs @@ -48,17 +48,16 @@ namespace OpenRA.Mods.Common.Traits void INotifyDockHost.Docked(Actor self, Actor client) { - if (info.Condition != null && (info.DockClientNames == null || info.DockClientNames.Contains(client.Info.Name))) + if (info.Condition != null && + (info.DockClientNames == null || info.DockClientNames.Contains(client.Info.Name)) && + token == Actor.InvalidConditionToken) { - if (token == Actor.InvalidConditionToken) + if (delayedtoken == Actor.InvalidConditionToken) + token = self.GrantCondition(info.Condition); + else { - if (delayedtoken == Actor.InvalidConditionToken) - token = self.GrantCondition(info.Condition); - else - { - token = delayedtoken; - delayedtoken = Actor.InvalidConditionToken; - } + token = delayedtoken; + delayedtoken = Actor.InvalidConditionToken; } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs index 396ac8e6f3..94da84729d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs @@ -97,15 +97,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic var palettePresetRows = 2; var paletteCustomRows = 1; - if (logicArgs.TryGetValue("PaletteColumns", out var yaml)) - if (!int.TryParse(yaml.Value, out paletteCols)) - throw new YamlException($"Invalid value for PaletteColumns: {yaml.Value}"); - if (logicArgs.TryGetValue("PalettePresetRows", out yaml)) - if (!int.TryParse(yaml.Value, out palettePresetRows)) - throw new YamlException($"Invalid value for PalettePresetRows: {yaml.Value}"); - if (logicArgs.TryGetValue("PaletteCustomRows", out yaml)) - if (!int.TryParse(yaml.Value, out paletteCustomRows)) - throw new YamlException($"Invalid value for PaletteCustomRows: {yaml.Value}"); + if (logicArgs.TryGetValue("PaletteColumns", out var yaml) && !int.TryParse(yaml.Value, out paletteCols)) + throw new YamlException($"Invalid value for PaletteColumns: {yaml.Value}"); + if (logicArgs.TryGetValue("PalettePresetRows", out yaml) && !int.TryParse(yaml.Value, out palettePresetRows)) + throw new YamlException($"Invalid value for PalettePresetRows: {yaml.Value}"); + if (logicArgs.TryGetValue("PaletteCustomRows", out yaml) && !int.TryParse(yaml.Value, out paletteCustomRows)) + throw new YamlException($"Invalid value for PaletteCustomRows: {yaml.Value}"); var presetColors = colorManager.PresetColors; for (var j = 0; j < palettePresetRows; j++) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index c22bc2c9e2..de4893ea00 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -140,15 +140,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic } // Check for duplicate actor ID - if (!CurrentActor.ID.Equals(actorId, StringComparison.OrdinalIgnoreCase)) + if (!CurrentActor.ID.Equals(actorId, StringComparison.OrdinalIgnoreCase) && editorActorLayer[actorId] != null) { - if (editorActorLayer[actorId] != null) - { - nextActorIDStatus = ActorIDStatus.Duplicate; - actorIDErrorLabel.Text = TranslationProvider.GetString(DuplicateActorId); - actorIDErrorLabel.Visible = true; - return; - } + nextActorIDStatus = ActorIDStatus.Duplicate; + actorIDErrorLabel.Text = TranslationProvider.GetString(DuplicateActorId); + actorIDErrorLabel.Visible = true; + return; } SetActorID(actorId); diff --git a/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs index 2e92f4e230..5f940a788b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs @@ -100,27 +100,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic { badgesVisible = false; - if (localProfile.State == LocalPlayerProfile.LinkState.Linked) + if (localProfile.State == LocalPlayerProfile.LinkState.Linked && localProfile.ProfileData.Badges.Count > 0) { - if (localProfile.ProfileData.Badges.Count > 0) - { - Func negotiateWidth = _ => widget.Get("PROFILE_HEADER").Bounds.Width; + Func negotiateWidth = _ => widget.Get("PROFILE_HEADER").Bounds.Width; - // Remove any stale badges that may be left over from a previous session - badgeContainer.RemoveChildren(); + // Remove any stale badges that may be left over from a previous session + badgeContainer.RemoveChildren(); - var badges = Ui.LoadWidget("PLAYER_PROFILE_BADGES_INSERT", badgeContainer, new WidgetArgs() + var badges = Ui.LoadWidget("PLAYER_PROFILE_BADGES_INSERT", badgeContainer, new WidgetArgs() { { "worldRenderer", worldRenderer }, { "profile", localProfile.ProfileData }, { "negotiateWidth", negotiateWidth } }); - if (badges.Bounds.Height > 0) - { - badgeContainer.Bounds.Height = badges.Bounds.Height; - badgesVisible = true; - } + if (badges.Bounds.Height > 0) + { + badgeContainer.Bounds.Height = badges.Bounds.Height; + badgesVisible = true; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs index 6c80d145cd..a492024166 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs @@ -25,9 +25,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic var keyhandler = widget.Get(parentName); keyhandler.AddHandler(e => { - if (e.Event == KeyInputEvent.Down) - if (namedKey.IsActivatedBy(e)) - return OnHotkeyActivated(e); + if (e.Event == KeyInputEvent.Down && namedKey.IsActivatedBy(e)) + return OnHotkeyActivated(e); return false; }); diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index b1fb3ca1c8..617cd65eaa 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -107,16 +107,15 @@ namespace OpenRA.Mods.Common.Widgets if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up) { - if (useClassicMouseStyle && HasMouseFocus) + if (useClassicMouseStyle && HasMouseFocus && + !IsValidDragbox && World.Selection.Actors.Count != 0 && + !multiClick && uog.InputOverridesSelection(World, mousePos, mi)) { - if (!IsValidDragbox && World.Selection.Actors.Count != 0 && !multiClick && uog.InputOverridesSelection(World, mousePos, mi)) - { - // Order units instead of selecting - ApplyOrders(World, mi); - isDragging = false; - YieldMouseFocus(mi); - return true; - } + // Order units instead of selecting + ApplyOrders(World, mi); + isDragging = false; + YieldMouseFocus(mi); + return true; } if (multiClick) diff --git a/OpenRA.Platforms.Default/FreeTypeFont.cs b/OpenRA.Platforms.Default/FreeTypeFont.cs index 72b218d3e7..c17ab83a95 100644 --- a/OpenRA.Platforms.Default/FreeTypeFont.cs +++ b/OpenRA.Platforms.Default/FreeTypeFont.cs @@ -131,15 +131,12 @@ namespace OpenRA.Platforms.Default public void Dispose() { - if (!disposed) + if (!disposed && faceHandle.IsAllocated) { - if (faceHandle.IsAllocated) - { - FreeType.FT_Done_Face(face); + FreeType.FT_Done_Face(face); - faceHandle.Free(); - disposed = true; - } + faceHandle.Free(); + disposed = true; } } }