Add an `Undamaged' damagestate to simplify things related to healing.
This commit is contained in:
@@ -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
|
||||
{
|
||||
@@ -79,6 +79,9 @@ 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>();
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Traits
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new RepairIndicator(self)));
|
||||
self.InflictDamage(self, -hpToRepair, null);
|
||||
if (Health.HP == Health.MaxHP)
|
||||
if (Health.ExtendedDamageState == ExtendedDamageState.Undamaged)
|
||||
{
|
||||
isRepairing = false;
|
||||
return;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
}
|
||||
|
||||
self.InflictDamage(self, -hpToRepair, null);
|
||||
if (health.MaxHP == health.HP)
|
||||
if (health.ExtendedDamageState == ExtendedDamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
if (host != null)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
if (target == null || target.IsDead()) return NextActivity;
|
||||
var health = target.traits.Get<Health>();
|
||||
if (health.HP == health.MaxHP)
|
||||
if (health.ExtendedDamageState == ExtendedDamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
target.InflictDamage(self, -health.MaxHP, null);
|
||||
|
||||
@@ -222,12 +222,8 @@ namespace OpenRA.Mods.RA
|
||||
// unless forced, only heal allies.
|
||||
if (self.Owner.Stances[underCursor.Owner] != Stance.Ally && !forceFire) return null;
|
||||
|
||||
// we can only heal actors with health
|
||||
var health = underCursor.traits.GetOrDefault<Health>();
|
||||
if (health == null) return null;
|
||||
|
||||
// don't allow healing of fully-healed stuff!
|
||||
if (health.HP >= health.MaxHP) return null;
|
||||
if (underCursor.GetExtendedDamageState() == ExtendedDamageState.Undamaged) return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace OpenRA.Mods.RA
|
||||
if ((attack.target.CenterLocation - self.Location).LengthSquared > range * range + 2)
|
||||
return true; // wandered off faster than we could follow
|
||||
|
||||
var health = attack.target.Actor.traits.GetOrDefault<Health>();
|
||||
if (attack.target.IsActor && health.HP == health.MaxHP)
|
||||
if (attack.target.IsActor
|
||||
&& attack.target.Actor.GetExtendedDamageState() == ExtendedDamageState.Undamaged)
|
||||
return true; // fully healed
|
||||
|
||||
return false;
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
|
||||
return inRange
|
||||
.Where(a => a != self && self.Owner.Stances[ a.Owner ] == Stance.Ally)
|
||||
.Where(a => Combat.HasAnyValidWeapons(self, Target.FromActor(a)))
|
||||
.Where(a => a.traits.Contains<Health>() && a.traits.Get<Health>().HPFraction < 1f)
|
||||
.Where(a => a.traits.Contains<Health>() && a.GetExtendedDamageState() != ExtendedDamageState.Undamaged)
|
||||
.OrderBy(a => (a.Location - self.Location).LengthSquared)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -39,25 +39,19 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (order.OrderString != "EngineerRepair") return null;
|
||||
if (order.TargetActor == null) return null;
|
||||
var health = order.TargetActor.traits.GetOrDefault<Health>();
|
||||
if (health == null) return null;
|
||||
return (health.HP == health.MaxHP) ? "goldwrench-blocked" : "goldwrench";
|
||||
return (order.TargetActor.GetExtendedDamageState() == ExtendedDamageState.Undamaged) ? "goldwrench-blocked" : "goldwrench";
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
var health = order.TargetActor.traits.GetOrDefault<Health>();
|
||||
if (health == null) return null;
|
||||
return (order.OrderString == "EngineerRepair"
|
||||
&& health.HP < health.MaxHP) ? "Attack" : null;
|
||||
&& order.TargetActor.GetExtendedDamageState() != ExtendedDamageState.Undamaged) ? "Attack" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
var health = order.TargetActor.traits.GetOrDefault<Health>();
|
||||
if (health == null) return;
|
||||
|
||||
if (order.OrderString == "EngineerRepair" && health.HP < health.MaxHP)
|
||||
if (order.OrderString == "EngineerRepair"
|
||||
&& order.TargetActor.GetExtendedDamageState() != ExtendedDamageState.Undamaged)
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w =>
|
||||
|
||||
@@ -34,9 +34,8 @@ namespace OpenRA.Mods.RA.Orders
|
||||
if (underCursor == null)
|
||||
yield break;
|
||||
|
||||
var health = underCursor.traits.GetOrDefault<Health>();
|
||||
var repairable = health != null && underCursor.Info.Traits.Contains<RepairableBuildingInfo>();
|
||||
if (repairable && health.HPFraction < 1f)
|
||||
if (underCursor.Info.Traits.Contains<RepairableBuildingInfo>()
|
||||
&& underCursor.GetExtendedDamageState() != ExtendedDamageState.Undamaged)
|
||||
yield return new Order("Repair", underCursor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
|
||||
bool CanRepair(Actor self)
|
||||
{
|
||||
var li = self.traits.GetOrDefault<LimitedAmmo>();
|
||||
return (Health.HPFraction < 1f || (li != null && !li.FullAmmo()) );
|
||||
return (Health.ExtendedDamageState != ExtendedDamageState.Undamaged || (li != null && !li.FullAmmo()) );
|
||||
}
|
||||
|
||||
public string CursorForOrder(Actor self, Order order)
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
if (underCursor.Owner == self.Owner &&
|
||||
self.Info.Traits.Get<RepairableNearInfo>().Buildings.Contains( underCursor.Info.Name ) &&
|
||||
self.traits.Get<Health>().HPFraction < 1f)
|
||||
self.GetExtendedDamageState() != ExtendedDamageState.Undamaged)
|
||||
return new Order("Enter", self, underCursor);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user