Add an upgrade rule
This commit is contained in:
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var health = self.TraitOrDefault<Health>();
|
var health = self.TraitOrDefault<Health>();
|
||||||
if (health != null)
|
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));
|
init.Add(new HealthInit(newHP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -32,6 +33,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
.Select(s => ((int)Math.Round(FieldLoader.GetValue<float>("(float value)", s) * 100)).ToString()));
|
.Select(s => ((int)Math.Round(FieldLoader.GetValue<float>("(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)
|
internal static void ConvertPxToRange(ref string input)
|
||||||
{
|
{
|
||||||
ConvertPxToRange(ref input, 1, 1);
|
ConvertPxToRange(ref input, 1, 1);
|
||||||
@@ -1369,7 +1382,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
internal static void UpgradeActors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
internal static void UpgradeActors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
||||||
{
|
{
|
||||||
foreach (var node in nodes)
|
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);
|
UpgradeActors(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user