From 0fe839add0b510a31c591250784e03d72349b452 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 1 Dec 2013 00:10:32 +1300 Subject: [PATCH] Move HealthExts.IsDead and Kill to Actor. --- OpenRA.Game/Actor.cs | 18 ++++++++++++++++++ OpenRA.Game/Traits/Health.cs | 16 ---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 39be1ac013..1067e1ad7a 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -28,6 +28,7 @@ namespace OpenRA Lazy occupySpace; Lazy facing; + Lazy health; public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } } @@ -72,6 +73,7 @@ namespace OpenRA } facing = Lazy.New(() => TraitOrDefault()); + health = Lazy.New(() => TraitOrDefault()); applyIRender = (x, wr) => x.Render(this, wr); applyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m); @@ -210,5 +212,21 @@ namespace OpenRA t.OnOwnerChanged(this, oldOwner, newOwner); }); } + + public bool IsDead() + { + if (Destroyed) + return true; + + return (health.Value == null) ? false : health.Value.IsDead; + } + + public void Kill(Actor attacker) + { + if (health.Value == null) + return; + + health.Value.InflictDamage(this, attacker, health.Value.MaxHP, null, true); + } } } diff --git a/OpenRA.Game/Traits/Health.cs b/OpenRA.Game/Traits/Health.cs index 06cd1c769b..e18596f0b2 100755 --- a/OpenRA.Game/Traits/Health.cs +++ b/OpenRA.Game/Traits/Health.cs @@ -168,15 +168,6 @@ namespace OpenRA.Traits public static class HealthExts { - public static bool IsDead(this Actor self) - { - if (self.Destroyed) - return true; - - var health = self.TraitOrDefault(); - return (health == null) ? false : health.IsDead; - } - public static DamageState GetDamageState(this Actor self) { if (self.Destroyed) @@ -193,12 +184,5 @@ namespace OpenRA.Traits if (health == null) return; health.InflictDamage(self, attacker, damage, warhead, false); } - - public static void Kill(this Actor self, Actor attacker) - { - var health = self.TraitOrDefault(); - if (health == null) return; - health.InflictDamage(self, attacker, health.MaxHP, null, true); - } } }