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