From 95e3713b69345bc7c5b5e2c3d250e988e78a61cf Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Thu, 30 Apr 2015 17:54:19 +0200 Subject: [PATCH] Add an upgrade rule --- OpenRA.Mods.Common/Activities/Transform.cs | 2 +- .../UtilityCommands/UpgradeRules.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Activities/Transform.cs b/OpenRA.Mods.Common/Activities/Transform.cs index fc5bb12623..c4cb2c8e34 100644 --- a/OpenRA.Mods.Common/Activities/Transform.cs +++ b/OpenRA.Mods.Common/Activities/Transform.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Activities var health = self.TraitOrDefault(); if (health != null) { - var newHP = (ForceHealthPercentage > 0) ? ForceHealthPercentage : (health.HP * 100) / health.MaxHP; + var newHP = ForceHealthPercentage > 0 ? ForceHealthPercentage : (health.HP * 100) / health.MaxHP; init.Add(new HealthInit(newHP)); } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index a2d6711479..a9b2689e2f 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; @@ -32,6 +33,18 @@ namespace OpenRA.Mods.Common.UtilityCommands .Select(s => ((int)Math.Round(FieldLoader.GetValue("(float value)", s) * 100)).ToString())); } + internal static void ConvertFloatToIntPercentage(ref string input) + { + var value = float.Parse(input, CultureInfo.InvariantCulture); + + if (value < 1) + value = (int)Math.Round(value * 100, 0); + else + value = (int)Math.Round(value, 0); + + input = value.ToString(); + } + internal static void ConvertPxToRange(ref string input) { ConvertPxToRange(ref input, 1, 1); @@ -1369,7 +1382,15 @@ namespace OpenRA.Mods.Common.UtilityCommands internal static void UpgradeActors(int engineVersion, ref List nodes, MiniYamlNode parent, int depth) { foreach (var node in nodes) + { + if (engineVersion < 20150430) + { + if (node.Key == "Health") + ConvertFloatToIntPercentage(ref node.Value.Value); + } + UpgradeActors(engineVersion, ref node.Value.Nodes, node, depth + 1); + } } } }