From dd39ab5b12f632b57822a9ad45813e9c9ec9397c Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Tue, 9 Oct 2018 21:13:53 +0300 Subject: [PATCH] Add Update Rule to change Cloak>RequiresCondition to PauseOnCondition --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../20180923/CloakRequiresConditionToPause.cs | 55 +++++++++++++++++++ OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 1 + 3 files changed, 57 insertions(+) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/20180923/CloakRequiresConditionToPause.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index bdf595ff57..5dbbfa4cfb 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -591,6 +591,7 @@ + diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20180923/CloakRequiresConditionToPause.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/CloakRequiresConditionToPause.cs new file mode 100644 index 0000000000..a6d516c722 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/CloakRequiresConditionToPause.cs @@ -0,0 +1,55 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class CloakRequiresConditionToPause : UpdateRule + { + public override string Name { get { return "Change Cloak>RequiresCondition to PauseOnCondition"; } } + public override string Description + { + get + { + return "Disabling cloak trait now resets the delay to recloak to InitialCloakDelay.\n" + + "To keep the old behaviour, you should pause the trait instead."; + } + } + + bool displayedMessage; + public override IEnumerable AfterUpdate(ModData modData) + { + var message = "You may want to update the result of PauseOnCondition, as this update\n" + + "just adds ! prefix to RequiresCondition's value to reverse it."; + + if (!displayedMessage) + yield return message; + + displayedMessage = true; + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + foreach (var node in actorNode.ChildrenMatching("Cloak").Where(t => t.ChildrenMatching("RequiresCondition").Any())) + { + var rc = node.LastChildMatching("RequiresCondition"); + + rc.ReplaceValue("!(" + rc.Value.Value + ")"); + rc.RenameKey("PauseOnCondition"); + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 787e3dad49..e7ddc05131 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -104,6 +104,7 @@ namespace OpenRA.Mods.Common.UpdateRules new MergeAttackPlaneAndHeli(), new RemovedDemolishLocking(), new RequireProductionType(), + new CloakRequiresConditionToPause(), }) };