Add an `Undamaged' damagestate to simplify things related to healing.

This commit is contained in:
Paul Chote
2010-07-30 01:22:41 +12:00
parent 87d2071007
commit 98ac5a036f
10 changed files with 27 additions and 29 deletions

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Traits
public virtual object Create(ActorInitializer init) { return new Health(init, this); }
}
public enum ExtendedDamageState { Normal, ThreeQuarter, Half, Quarter, Dead };
public enum ExtendedDamageState { Undamaged, Normal, ThreeQuarter, Half, Quarter, Dead };
public class Health
{
@@ -78,7 +78,10 @@ namespace OpenRA.Traits
if (hp < MaxHP * 0.75f)
return ExtendedDamageState.ThreeQuarter;
if (hp == MaxHP)
return ExtendedDamageState.Undamaged;
return ExtendedDamageState.Normal;
}
}
@@ -155,6 +158,12 @@ namespace OpenRA.Traits
return (health == null) ? DamageState.Normal : health.DamageState;
}
public static ExtendedDamageState GetExtendedDamageState(this Actor self)
{
var health = self.traits.GetOrDefault<Health>();
return (health == null) ? ExtendedDamageState.Undamaged : health.ExtendedDamageState;
}
public static void InflictDamage(this Actor self, Actor attacker, int damage, WarheadInfo warhead)
{
var health = self.traits.GetOrDefault<Health>();