Kill HPFraction

This commit is contained in:
Paul Chote
2011-04-11 10:47:55 +12:00
parent cd64d62b7e
commit 61db3b3965
5 changed files with 19 additions and 15 deletions

View File

@@ -43,10 +43,6 @@ namespace OpenRA.Traits
public int HP { get { return hp; } }
public readonly int MaxHP;
public float HPFraction
{
get { return hp * 1f / MaxHP; }
}
public bool IsDead { get { return hp <= 0; } }
public bool RemoveOnDeath = true;

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Traits
healthColor.G / 2,
healthColor.B / 2);
var z = float2.Lerp(xy, Xy, health.HPFraction);
var z = float2.Lerp(xy, Xy, (float)health.HP / health.MaxHP);
Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -4), Xy + new float2(0, -4), c, c);

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Activities
if (ForceHealthPercentage > 0)
init.Add( new HealthInit( ForceHealthPercentage * 1f / 100 ));
else
init.Add( new HealthInit( health.HPFraction ));
init.Add( new HealthInit( (float)health.HP / health.MaxHP ));
}
var a = w.CreateActor( ToActor, init );

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA
{
class EmitInfantryOnSellInfo : TraitInfo<EmitInfantryOnSell>
{
public readonly float ValueFraction = .4f;
public readonly float MinHpFraction = .3f;
public readonly float ValuePercent = 40;
public readonly float MinHpPercent = 30;
[ActorReference]
public readonly string[] ActorTypes = { "e1" };
@@ -36,8 +36,11 @@ namespace OpenRA.Mods.RA
var cost = csv != null ? csv.Value : (valued != null ? valued.Cost : 0);
var health = self.TraitOrDefault<Health>();
var hpFraction = (health == null) ? 1f : health.HPFraction;
var dudesValue = (int)(hpFraction * info.ValueFraction * cost);
var dudesValue = info.ValuePercent * cost;
if (health != null)
dudesValue = dudesValue*health.HP / health.MaxHP;
dudesValue /= 100;
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = Rules.Info[a].Traits.Get<ValuedInfo>().Cost }).ToArray();

View File

@@ -12,31 +12,36 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class SelfHealingInfo : TraitInfo<SelfHealing>, ITraitPrerequisite<HealthInfo>
class SelfHealingInfo : ITraitInfo, ITraitPrerequisite<HealthInfo>
{
public readonly int Step = 5;
public readonly int Ticks = 5;
public readonly float HealIfBelow = .5f;
public virtual object Create(ActorInitializer init) { return new SelfHealing(this); }
}
class SelfHealing : ITick, ISync
{
[Sync]
int ticks;
SelfHealingInfo Info;
public SelfHealing(SelfHealingInfo info) { Info = info; }
public void Tick(Actor self)
{
if (self.IsDead())
return;
var info = self.Info.Traits.Get<SelfHealingInfo>();
if (self.Trait<Health>().HPFraction >= info.HealIfBelow)
var health = self.Trait<Health>();
if (health.HP >= Info.HealIfBelow*health.MaxHP)
return;
if (--ticks <= 0)
{
ticks = info.Ticks;
self.InflictDamage(self, -info.Step, null);
ticks = Info.Ticks;
self.InflictDamage(self, -Info.Step, null);
}
}
}