Convert the float health percentage to an int one

This commit is contained in:
abcdefg30
2015-02-14 22:19:17 +01:00
parent 732001f3f3
commit 8d2307db83
5 changed files with 20 additions and 19 deletions

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.GameRules;
@@ -42,7 +43,10 @@ namespace OpenRA.Traits
Info = info;
MaxHP = info.HP;
hp = init.Contains<HealthInit>() ? (int)(init.Get<HealthInit, float>() * MaxHP) : MaxHP;
hp = init.Contains<HealthInit>() ? init.Get<HealthInit, int>() * MaxHP / 100 : MaxHP;
if (hp <= 0)
hp = Math.Max(MaxHP / 100, 1);
DisplayHp = hp;
}
@@ -169,12 +173,12 @@ namespace OpenRA.Traits
}
}
public class HealthInit : IActorInit<float>
public class HealthInit : IActorInit<int>
{
[FieldFromYamlKey] readonly float value = 1f;
[FieldFromYamlKey] readonly int value = 100;
public HealthInit() { }
public HealthInit(float init) { value = init; }
public float Value(World world) { return value; }
public HealthInit(int init) { value = init; }
public int Value(World world) { return value; }
}
public static class HealthExts

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));