diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 55ae30fc65..ecef9032e1 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -880,6 +880,7 @@ + diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/ScaleSupportPowerSecondsToTicks.cs b/OpenRA.Mods.Common/UpdateRules/Rules/ScaleSupportPowerSecondsToTicks.cs new file mode 100644 index 0000000000..2cf9e10ad6 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/ScaleSupportPowerSecondsToTicks.cs @@ -0,0 +1,78 @@ +#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.Collections.Generic; +using OpenRA.Primitives; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class ScaleSupportPowerSecondsToTicks : UpdateRule + { + public override string Name { get { return "Scale support power time fields from seconds to ticks."; } } + public override string Description + { + get + { + return "Scales ChargeTime, GpsPower.RevealDelay, and ChronoshiftPower.Duration\n" + + "from seconds to ticks (in other words, by a factor of 25).\n" + + "Additionally, renames 'ChargeTime' to 'ChargeInterval'."; + } + } + + static readonly Dictionary ChargeTimeMapping = new Dictionary() + { + { "AirstrikePower", "ChargeTime" }, + { "GrantExternalConditionPower", "ChargeTime" }, + { "NukePower", "ChargeTime" }, + { "ParatroopersPower", "ChargeTime" }, + { "ProduceActorPower", "ChargeTime" }, + { "SpawnActorPower", "ChargeTime" }, + { "AttackOrderPower", "ChargeTime" }, + { "GpsPower", "ChargeTime" }, + { "ChronoshiftPower", "ChargeTime" }, + { "IonCannonPower", "ChargeTime" }, + }; + + static readonly Dictionary SingularCases = new Dictionary() + { + { "GpsPower", "RevealDelay" }, + { "ChronoshiftPower", "Duration" }, + }; + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + foreach (var kv in ChargeTimeMapping) + { + foreach (var trait in actorNode.ChildrenMatching(kv.Key)) + { + var node = trait.LastChildMatching(kv.Value); + if (node != null) + { + node.ReplaceValue((25 * node.NodeValue()).ToString()); + node.RenameKey("ChargeInterval"); + } + } + } + + foreach (var kv in SingularCases) + { + foreach (var trait in actorNode.ChildrenMatching(kv.Key)) + { + var node = trait.LastChildMatching(kv.Value); + if (node != null) + node.ReplaceValue((25 * node.NodeValue()).ToString()); + } + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 789c2f1f47..5c38530f1a 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -43,7 +43,8 @@ namespace OpenRA.Mods.Common.UpdateRules new DecoupleSelfReloading(), new RemovePlayerPaletteTileset(), new RenameWithTurreted(), - new ScaleDefaultModHealth() + new ScaleDefaultModHealth(), + new ScaleSupportPowerSecondsToTicks() }), new UpdatePath("release-20180218", "release-20180307", new UpdateRule[0]),