Merge pull request #7475 from abcdefg30/perhealth

Convert the float health percentage to an int percentage
This commit is contained in:
Paul Chote
2015-05-03 08:35:58 +12:00
21 changed files with 138 additions and 116 deletions

View File

@@ -70,10 +70,7 @@ namespace OpenRA.Mods.Common.Activities
var health = self.TraitOrDefault<Health>();
if (health != null)
{
var newHP = (ForceHealthPercentage > 0)
? ForceHealthPercentage / 100f
: (float)health.HP / health.MaxHP;
var newHP = ForceHealthPercentage > 0 ? ForceHealthPercentage : (health.HP * 100) / health.MaxHP;
init.Add(new HealthInit(newHP));
}

View File

@@ -43,27 +43,27 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new Bridge(init.Self, this); }
public IEnumerable<Pair<ushort, float>> Templates
public IEnumerable<Pair<ushort, int>> Templates
{
get
{
if (Template != 0)
yield return Pair.New(Template, 1f);
yield return Pair.New(Template, 100);
if (DamagedTemplate != 0)
yield return Pair.New(DamagedTemplate, .5f);
yield return Pair.New(DamagedTemplate, 50);
if (DestroyedTemplate != 0)
yield return Pair.New(DestroyedTemplate, 0f);
yield return Pair.New(DestroyedTemplate, 0);
if (DestroyedPlusNorthTemplate != 0)
yield return Pair.New(DestroyedPlusNorthTemplate, 0f);
yield return Pair.New(DestroyedPlusNorthTemplate, 0);
if (DestroyedPlusSouthTemplate != 0)
yield return Pair.New(DestroyedPlusSouthTemplate, 0f);
yield return Pair.New(DestroyedPlusSouthTemplate, 0);
if (DestroyedPlusBothTemplate != 0)
yield return Pair.New(DestroyedPlusBothTemplate, 0f);
yield return Pair.New(DestroyedPlusBothTemplate, 0);
}
}
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly BridgeLayerInfo info;
readonly World world;
Dictionary<ushort, Pair<string, float>> bridgeTypes = new Dictionary<ushort, Pair<string, float>>();
Dictionary<ushort, Pair<string, int>> bridgeTypes = new Dictionary<ushort, Pair<string, int>>();
CellLayer<Bridge> bridges;
public BridgeLayer(Actor self, BridgeLayerInfo info)

View File

@@ -405,7 +405,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
players.Add(parts[0]);
var loc = Exts.ParseIntegerInvariant(parts[3]);
var health = float.Parse(parts[2], NumberFormatInfo.InvariantInfo) / 256;
var health = Exts.ParseIntegerInvariant(parts[2]) * 100 / 256;
var facing = (section == "INFANTRY") ? Exts.ParseIntegerInvariant(parts[6]) : Exts.ParseIntegerInvariant(parts[4]);
var actor = new ActorReference(parts[1].ToLowerInvariant())
@@ -415,7 +415,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
};
var initDict = actor.InitDict;
if (health != 1)
if (health != 100)
initDict.Add(new HealthInit(health));
if (facing != 0)
initDict.Add(new FacingInit(facing));

View File

@@ -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>("(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<MiniYamlNode> 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);
}
}
}
}