Convert the float health percentage to an int one
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
@@ -42,7 +43,10 @@ namespace OpenRA.Traits
|
|||||||
Info = info;
|
Info = info;
|
||||||
MaxHP = info.HP;
|
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;
|
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() { }
|
||||||
public HealthInit(float init) { value = init; }
|
public HealthInit(int init) { value = init; }
|
||||||
public float Value(World world) { return value; }
|
public int Value(World world) { return value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HealthExts
|
public static class HealthExts
|
||||||
|
|||||||
@@ -70,10 +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)
|
var newHP = (ForceHealthPercentage > 0) ? ForceHealthPercentage : (health.HP * 100) / health.MaxHP;
|
||||||
? ForceHealthPercentage / 100f
|
|
||||||
: (float)health.HP / health.MaxHP;
|
|
||||||
|
|
||||||
init.Add(new HealthInit(newHP));
|
init.Add(new HealthInit(newHP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,27 +43,27 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Bridge(init.Self, this); }
|
public object Create(ActorInitializer init) { return new Bridge(init.Self, this); }
|
||||||
|
|
||||||
public IEnumerable<Pair<ushort, float>> Templates
|
public IEnumerable<Pair<ushort, int>> Templates
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Template != 0)
|
if (Template != 0)
|
||||||
yield return Pair.New(Template, 1f);
|
yield return Pair.New(Template, 100);
|
||||||
|
|
||||||
if (DamagedTemplate != 0)
|
if (DamagedTemplate != 0)
|
||||||
yield return Pair.New(DamagedTemplate, .5f);
|
yield return Pair.New(DamagedTemplate, 50);
|
||||||
|
|
||||||
if (DestroyedTemplate != 0)
|
if (DestroyedTemplate != 0)
|
||||||
yield return Pair.New(DestroyedTemplate, 0f);
|
yield return Pair.New(DestroyedTemplate, 0);
|
||||||
|
|
||||||
if (DestroyedPlusNorthTemplate != 0)
|
if (DestroyedPlusNorthTemplate != 0)
|
||||||
yield return Pair.New(DestroyedPlusNorthTemplate, 0f);
|
yield return Pair.New(DestroyedPlusNorthTemplate, 0);
|
||||||
|
|
||||||
if (DestroyedPlusSouthTemplate != 0)
|
if (DestroyedPlusSouthTemplate != 0)
|
||||||
yield return Pair.New(DestroyedPlusSouthTemplate, 0f);
|
yield return Pair.New(DestroyedPlusSouthTemplate, 0);
|
||||||
|
|
||||||
if (DestroyedPlusBothTemplate != 0)
|
if (DestroyedPlusBothTemplate != 0)
|
||||||
yield return Pair.New(DestroyedPlusBothTemplate, 0f);
|
yield return Pair.New(DestroyedPlusBothTemplate, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly BridgeLayerInfo info;
|
readonly BridgeLayerInfo info;
|
||||||
readonly World world;
|
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;
|
CellLayer<Bridge> bridges;
|
||||||
|
|
||||||
public BridgeLayer(Actor self, BridgeLayerInfo info)
|
public BridgeLayer(Actor self, BridgeLayerInfo info)
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
players.Add(parts[0]);
|
players.Add(parts[0]);
|
||||||
|
|
||||||
var loc = Exts.ParseIntegerInvariant(parts[3]);
|
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 facing = (section == "INFANTRY") ? Exts.ParseIntegerInvariant(parts[6]) : Exts.ParseIntegerInvariant(parts[4]);
|
||||||
|
|
||||||
var actor = new ActorReference(parts[1].ToLowerInvariant())
|
var actor = new ActorReference(parts[1].ToLowerInvariant())
|
||||||
@@ -415,7 +415,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
};
|
};
|
||||||
|
|
||||||
var initDict = actor.InitDict;
|
var initDict = actor.InitDict;
|
||||||
if (health != 1)
|
if (health != 100)
|
||||||
initDict.Add(new HealthInit(health));
|
initDict.Add(new HealthInit(health));
|
||||||
if (facing != 0)
|
if (facing != 0)
|
||||||
initDict.Add(new FacingInit(facing));
|
initDict.Add(new FacingInit(facing));
|
||||||
|
|||||||
Reference in New Issue
Block a user