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

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

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

View File

@@ -320,17 +320,17 @@ Actors:
Actor83: gun
Location: 46,55
Owner: Nod
Health: 0.5
Health: 50
Facing: 160
Actor84: gun
Location: 41,55
Owner: Nod
Health: 0.5
Health: 50
Facing: 160
Actor85: gun
Location: 49,55
Owner: Nod
Health: 0.1875
Health: 19
Facing: 160
Actor92: e1
Location: 57,45

View File

@@ -303,7 +303,7 @@ Actors:
Actor78: pyle
Location: 55,51
Owner: GDI
Health: 0.34375
Health: 34
Actor81: nuke
Location: 55,32
Owner: Nod
@@ -313,16 +313,16 @@ Actors:
Actor83: nuke
Location: 53,52
Owner: GDI
Health: 0.025
Health: 2
Actor85: bggy
Location: 52,39
Owner: Nod
Health: 0.5195313
Health: 52
Facing: 96
Actor87: jeep
Location: 54,49
Owner: GDI
Health: 0.3320313
Health: 33
Facing: 96
Actor88: jeep
Location: 57,49
@@ -331,12 +331,12 @@ Actors:
Actor89: bggy
Location: 33,37
Owner: Nod
Health: 0.578125
Health: 58
Facing: 96
Actor91: bggy
Location: 59,39
Owner: Nod
Health: 0.5
Health: 50
Facing: 160
Actor92: jeep
Location: 56,54
@@ -535,7 +535,7 @@ Actors:
Actor133: e1
Location: 51,49
Owner: GDI
Health: 0.9765625
Health: 98
Facing: 128
SubCell: 4
Actor134: e1
@@ -546,7 +546,7 @@ Actors:
Actor135: e1
Location: 52,50
Owner: GDI
Health: 0.5195313
Health: 52
Facing: 224
SubCell: 4
Actor136: e1
@@ -615,18 +615,18 @@ Actors:
RushBuggy: bggy
Location: 51,50
Owner: Nod
Health: 0.1835938
Health: 18
Facing: 96
RushRifle1: e1
Location: 54,48
Owner: Nod
Health: 0.4765625
Health: 48
Facing: 128
SubCell: 3
RushRifle2: e1
Location: 52,52
Owner: Nod
Health: 0.3164063
Health: 32
Facing: 96
SubCell: 0
RushRifle3: e1

View File

@@ -690,7 +690,7 @@ Actors:
GdiProc: proc
Location: 50,51
Owner: AbandonedBase
Health: 0.3085938
Health: 31
FreeActor: False
GdiHarv: harv
Location: 48,53
@@ -699,27 +699,27 @@ Actors:
GdiWeap: weap
Location: 50,54
Owner: AbandonedBase
Health: 0.2695313
Health: 27
GdiNuke1: nuke
Location: 53,55
Owner: AbandonedBase
Health: 0.2890625
Health: 29
GdiPyle: pyle
Location: 46,55
Owner: AbandonedBase
Health: 0.25
Health: 25
GdiSilo1: silo
Location: 53,51
Owner: AbandonedBase
Health: 0.3320313
Health: 33
GdiSilo2: silo
Location: 53,53
Owner: AbandonedBase
Health: 0.25
Health: 25
GdiNuke2: nuke
Location: 48,56
Owner: AbandonedBase
Health: 0.2070313
Health: 21
NodConYard: fact
Location: 9,29
Owner: Nod

View File

@@ -585,11 +585,11 @@ Actors:
GdiNuke1: nuke
Location: 33,51
Owner: AbandonedBase
Health: 0.4570313
Health: 46
GdiProc1: proc
Location: 27,52
Owner: AbandonedBase
Health: 0.4765625
Health: 48
FreeActor: False
GdiHarv: harv
Location: 27,55
@@ -598,19 +598,19 @@ Actors:
GdiWeap1: weap
Location: 35,51
Owner: AbandonedBase
Health: 0.4140625
Health: 41
GdiNuke2: nuke
Location: 31,51
Owner: AbandonedBase
Health: 0.3945313
Health: 39
GdiPyle1: pyle
Location: 31,54
Owner: AbandonedBase
Health: 0.4570313
Health: 46
GdiSilo1: silo
Location: 26,51
Owner: AbandonedBase
Health: 0.40625
Health: 41
GdiSilo2: silo
Location: 29,51
Owner: AbandonedBase

View File

@@ -238,7 +238,7 @@ Actors:
Harvester: harv
Location: 5,29
Owner: GDI
Health: 0.3945313
Health: 39
Facing: 224
McvEntry: waypoint
Location: 33,48

View File

@@ -364,7 +364,7 @@ Actors:
Actor105: c6
Location: 14,37
Owner: Neutral
Health: 0.5976563
Health: 60
Facing: 96
SubCell: 1
Actor106: c7

View File

@@ -433,7 +433,7 @@ Actors:
Actor104: c6
Location: 14,36
Owner: Neutral
Health: 0.5976563
Health: 60
SubCell: 4
Actor105: c7
Location: 18,38

View File

@@ -179,7 +179,7 @@ Actors:
Actor39: v32
Location: 46,37
Owner: NodSupporter
Health: 0.7265625
Health: 73
Actor41: v34
Location: 49,38
Owner: NodSupporter
@@ -264,7 +264,7 @@ Actors:
Actor86: e1
Location: 43,15
Owner: GDI
Health: 0.8789063
Health: 88
Facing: 32
SubCell: 3
Actor99: e1
@@ -274,7 +274,7 @@ Actors:
Actor100: e1
Location: 43,15
Owner: GDI
Health: 0.9375
Health: 94
Facing: 32
SubCell: 4
Actor105: e1
@@ -346,7 +346,7 @@ Actors:
Actor129: e2
Location: 36,10
Owner: GDI
Health: 0.3789063
Health: 38
Facing: 64
SubCell: 0
Actor131: e1
@@ -401,7 +401,7 @@ Actors:
Civilian1: v33
Location: 48,34
Owner: Neutral
Health: 0.625
Health: 62
Civilian2: v33
Location: 54,37
Owner: Neutral

View File

@@ -170,7 +170,7 @@ Actors:
Actor34: kenn
Location: 64,65
Owner: USSR
Health: 0.9921875
Health: 99
Actor35: powr
Location: 65,57
Owner: USSR

View File

@@ -264,7 +264,7 @@ Actors:
Actor63: kenn
Location: 58,68
Owner: USSR
Health: 0.9921875
Health: 99
Actor64: brl3
Location: 65,59
Owner: USSR
@@ -337,7 +337,7 @@ Actors:
Actor87: v19
Location: 75,48
Owner: USSR
Health: 0.5195313
Health: 52
Actor88: v19
Location: 62,57
Owner: USSR
@@ -564,7 +564,7 @@ Actors:
Actor137: e2
Location: 73,51
Owner: USSR
Health: 0.5585938
Health: 56
Facing: 224
SubCell: 4
Actor138: medi
@@ -674,7 +674,7 @@ Actors:
Harvester: harv
Location: 55,65
Owner: USSR
Health: 0.5
Health: 50
Facing: 160
TruckEntryPoint: waypoint
Location: 49,44

View File

@@ -773,7 +773,7 @@ Actors:
Actor249: v2rl
Location: 76,66
Owner: USSR
Health: 0.5195313
Health: 52
Facing: 224
Actor250: e1.autotarget
Location: 42,56

View File

@@ -1010,7 +1010,7 @@ Actors:
USSRSubPen: spen
Location: 109,53
Owner: USSR
Health: 0.5195313
Health: 52
USSRFlameTower1: ftur
Location: 82,82
Owner: USSR
@@ -1032,11 +1032,11 @@ Actors:
USSRRadarDome: dome
Location: 105,56
Owner: USSR
Health: 0.5625
Health: 56
USSRPowerPlant: powr
Location: 103,55
Owner: USSR
Health: 0.5195313
Health: 52
USSRBarracks1: barr
Location: 84,81
Owner: USSR
@@ -1053,17 +1053,17 @@ Actors:
Heavy1: 3tnk
Location: 96,66
Owner: USSR
Health: 0.125
Health: 13
Facing: 128
Heavy2: 3tnk
Location: 97,65
Owner: USSR
Health: 0.125
Health: 13
Facing: 128
Heavy3: 3tnk
Location: 98,66
Owner: USSR
Health: 0.0625
Health: 6
Facing: 128
USSRTruk: truk
Location: 56,93
@@ -1133,7 +1133,7 @@ Actors:
PrisonedMedi: medi
Location: 104,47
Owner: Greece
Health: 0.1484375
Health: 15
Facing: 192
SubCell: 0
PrisonedEngi1: hacke6

View File

@@ -1354,46 +1354,46 @@ Actors:
Actor424: weap
Location: 38,19
Owner: Outpost
Health: 0.375
Health: 37
Actor425: pbox
Location: 22,27
Owner: Outpost
Health: 0.28125
Health: 28
Actor426: pbox
Location: 44,27
Owner: Outpost
Health: 0.3515625
Health: 35
Actor427: pbox
Location: 40,29
Owner: Outpost
Health: 0.375
Health: 37
Actor428: dome
Location: 35,19
Owner: Outpost
Health: 0.3515625
Health: 35
Actor429: gun
Location: 45,25
Owner: Outpost
Health: 0.3125
Health: 31
Facing: 96
Actor430: gun
Location: 29,30
Owner: Outpost
Health: 0.1875
Health: 19
Facing: 32
Actor431: gun
Location: 38,29
Owner: Outpost
Health: 0.3945313
Health: 39
Facing: 96
Actor432: tent
Location: 33,22
Owner: Outpost
Health: 0.5
Health: 50
Actor433: fix
Location: 32,28
Owner: Outpost
Health: 0.3125
Health: 31
Actor434: ftur
Location: 78,34
Owner: BadGuy
@@ -1442,7 +1442,7 @@ Actors:
Actor450: spen
Location: 102,47
Owner: BadGuy
Health: 0.875
Health: 88
Actor451: fact
Location: 88,87
Owner: USSR
@@ -1596,23 +1596,23 @@ Actors:
Actor508: silo
Location: 36,18
Owner: Outpost
Health: 0.5898438
Health: 59
Actor509: silo
Location: 37,18
Owner: Outpost
Health: 0.08203125
Health: 8
Actor510: silo
Location: 37,19
Owner: Outpost
Health: 0.3320313
Health: 33
Actor511: apwr
Location: 26,20
Owner: Outpost
Health: 0.25
Health: 25
Actor512: apwr
Location: 23,23
Owner: Outpost
Health: 0.1367188
Health: 14
Actor515: v02
Location: 23,99
Owner: Neutral
@@ -1997,7 +1997,7 @@ Actors:
USSRSpen: spen
Location: 32,56
Owner: BadGuy
Health: 0.6875
Health: 69
USSROutpostSilo: silo
Location: 37,61
Owner: BadGuy
@@ -2016,7 +2016,7 @@ Actors:
AlliedBaseProc: proc
Location: 27,25
Owner: Outpost
Health: 0.3476563
Health: 35
FreeActor: False
AlliedBaseHarv: harv
Location: 30,26

View File

@@ -230,31 +230,31 @@ Actors:
Actor53: v08
Location: 41,54
Owner: France
Health: 0.5195313
Health: 52
Actor54: v07
Location: 54,65
Owner: France
Health: 0.4375
Health: 44
Actor55: v07
Location: 38,52
Owner: France
Health: 0.4375
Health: 44
Actor56: v06
Location: 46,51
Owner: France
Health: 0.9921875
Health: 99
Actor57: v05
Location: 36,55
Owner: France
Health: 0.5
Health: 50
Actor58: v04
Location: 35,51
Owner: France
Health: 0.3515625
Health: 35
Actor59: v02
Location: 36,57
Owner: France
Health: 0.5625
Health: 56
Actor60: brl3
Location: 34,52
Owner: Germany
@@ -360,11 +360,11 @@ Actors:
Actor99: v04
Location: 58,54
Owner: France
Health: 0.4140625
Health: 41
Actor100: v02
Location: 56,54
Owner: France
Health: 0.7070313
Health: 71
Actor101: dome
Location: 45,79
Owner: USSR
@@ -428,11 +428,11 @@ Actors:
Actor121: v05
Location: 48,62
Owner: France
Health: 0.4140625
Health: 41
Actor123: jeep
Location: 46,52
Owner: France
Health: 0.6640625
Health: 66
Facing: 96
Actor125: jeep
Location: 55,57
@@ -441,7 +441,7 @@ Actors:
Actor126: jeep
Location: 39,65
Owner: France
Health: 0.625
Health: 63
Facing: 64
Actor127: c9
Location: 50,64
@@ -557,16 +557,16 @@ Actors:
Church: v01
Location: 40,63
Owner: France
Health: 0.5390625
Health: 54
StartJeep: jeep
Location: 44,76
Owner: France
Health: 0.5195313
Health: 52
Facing: 32
LonelyGuard: e1
Location: 42,81
Owner: USSR
Health: 0.1367188
Health: 14
SubCell: 2
Airfield1: afld
Location: 39,77

View File

@@ -394,27 +394,27 @@ Actors:
Actor97: powr
Location: 32,43
Owner: Allies
Health: 0.2
Health: 20
Actor72: dome
Location: 44,44
Owner: Allies
Health: 0.3
Health: 30
Actor127: fact
Location: 38,38
Owner: Allies
Health: 0.4
Health: 40
Actor128: powr
Location: 35,45
Owner: Allies
Health: 0.4
Health: 40
Actor129: powr
Location: 30,34
Owner: Allies
Health: 0.3
Health: 30
Actor130: weap
Location: 33,35
Owner: Allies
Health: 0.3
Health: 30
Actor131: tc01
Location: 30,45
Owner: Neutral
@@ -427,11 +427,11 @@ Actors:
Actor134: agun
Location: 35,42
Owner: Allies
Health: 0.4
Health: 40
Actor135: gun
Location: 27,35
Owner: Allies
Health: 0.4
Health: 40
Actor136: gun
Location: 28,41
Owner: Allies
@@ -447,11 +447,11 @@ Actors:
Actor140: pbox
Location: 28,38
Owner: Allies
Health: 0.5
Health: 50
Actor141: agun
Location: 32,31
Owner: Allies
Health: 0.4
Health: 40
Actor143: fenc
Location: 31,30
Owner: Allies
@@ -470,11 +470,11 @@ Actors:
Actor147: tent
Location: 43,34
Owner: Allies
Health: 0.3
Health: 30
Actor148: fix
Location: 44,39
Owner: Allies
Health: 0.2
Health: 20
Actor137: cycl
Location: 29,39
Owner: Allies
@@ -487,7 +487,7 @@ Actors:
Actor152: gun
Location: 49,38
Owner: Allies
Health: 0.3
Health: 30
Actor157: fenc
Location: 46,32
Owner: Allies
@@ -506,11 +506,11 @@ Actors:
Actor158: gun
Location: 39,32
Owner: Allies
Health: 0.3
Health: 30
Actor159: powr
Location: 46,33
Owner: Allies
Health: 0.3
Health: 30
Actor145: fenc
Location: 40,32
Owner: Allies
@@ -532,7 +532,7 @@ Actors:
Actor166: agun
Location: 46,37
Owner: Allies
Health: 0.5
Health: 50
Actor167: e1
Location: 35,33
Owner: Allies