From d9f0ca362f9f9424b667552a295720ef7eded589 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sat, 23 May 2015 19:34:24 +0200 Subject: [PATCH] Fix broken bridges being initialized with a non-zero HP value --- OpenRA.Game/Traits/Health.cs | 20 ++++++++++++++----- .../Traits/World/BridgeLayer.cs | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Traits/Health.cs b/OpenRA.Game/Traits/Health.cs index 208ac0a1db..e7f268bc84 100755 --- a/OpenRA.Game/Traits/Health.cs +++ b/OpenRA.Game/Traits/Health.cs @@ -41,11 +41,9 @@ namespace OpenRA.Traits public Health(ActorInitializer init, HealthInfo info) { Info = info; - MaxHP = info.HP; + MaxHP = info.HP > 0 ? info.HP : 1; hp = init.Contains() ? init.Get() * MaxHP / 100 : MaxHP; - if (hp <= 0) - hp = Math.Max(MaxHP / 100, 1); DisplayHp = hp; } @@ -176,9 +174,21 @@ namespace OpenRA.Traits public class HealthInit : IActorInit { [FieldFromYamlKey] readonly int value = 100; + readonly bool allowZero = false; public HealthInit() { } - public HealthInit(int init) { value = init; } - public int Value(World world) { return value; } + public HealthInit(int init, bool allowZero = false) + { + this.allowZero = allowZero; + value = init; + } + + public int Value(World world) + { + if (value < 0 || (value == 0 && !allowZero)) + return 1; + + return value; + } } public static class HealthExts diff --git a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs index 4603fe9e20..6f5fc6d4d2 100644 --- a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs @@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits { new LocationInit(new CPos(ni, nj)), new OwnerInit(w.WorldActor.Owner), - new HealthInit(bridgeTypes[tile].Second), + new HealthInit(bridgeTypes[tile].Second, true), }).Trait(); var subTiles = new Dictionary();