Shift Actor.Health onto a trait.

Known regressions:
 - cnc only
 - health bar colors
 - can't repair buildings
This commit is contained in:
Paul Chote
2010-07-30 00:01:59 +12:00
parent 1e08dc6301
commit 6fba888d45
56 changed files with 530 additions and 303 deletions

View File

@@ -47,8 +47,12 @@ namespace OpenRA.Mods.RA.Activities
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
var a = w.CreateActor(actor, self.Location + offset, self.Owner);
a.Health = GetHealthToTransfer(self, a, transferPercentage);
var health = a.traits.GetOrDefault<Health>();
if (health != null)
{
health.TransferHPFromActor(a, self, transferPercentage);
}
if (selected)
w.Selection.Add(w, a);
});
@@ -56,14 +60,5 @@ namespace OpenRA.Mods.RA.Activities
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
public static int GetHealthToTransfer(Actor from, Actor to, bool transferPercentage)
{
var oldHP = from.GetMaxHP();
var newHP = to.GetMaxHP();
return (transferPercentage)
? (int)((float)from.Health / oldHP * newHP)
: Math.Min(from.Health, newHP);
}
}
}