Account for damage state in ActorPreviews.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user