Account for damage state in ActorPreviews.

This commit is contained in:
Paul Chote
2015-04-03 20:50:47 +01:00
parent ef55cb6528
commit 09bad3f0ef
11 changed files with 39 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Graphics
{
@@ -41,5 +42,32 @@ namespace OpenRA.Mods.Common.Graphics
public T Get<T>() where T : IActorInit { return dict.Get<T>(); }
public U Get<T, U>() where T : IActorInit<U> { return dict.Get<T>().Value(World); }
public bool Contains<T>() where T : IActorInit { return dict.Contains<T>(); }
public DamageState GetDamageState()
{
var health = dict.GetOrDefault<HealthInit>();
if (health == null)
return DamageState.Undamaged;
var hf = health.Value(null);
if (hf <= 0)
return DamageState.Dead;
if (hf < 0.25f)
return DamageState.Critical;
if (hf < 0.5f)
return DamageState.Heavy;
if (hf < 0.75f)
return DamageState.Medium;
if (hf < 1.0f)
return DamageState.Light;
return DamageState.Undamaged;
}
}
}