removed LegacyInfo from Actor

This commit is contained in:
Chris Forbes
2010-01-12 22:07:42 +13:00
parent ee14b0a670
commit 0cb5eca673
2 changed files with 20 additions and 15 deletions

View File

@@ -12,11 +12,7 @@ namespace OpenRa.Game
{
[Sync]
public readonly TypeDictionary traits = new TypeDictionary();
[Obsolete]
public readonly LegacyUnitInfo LegacyInfo;
public readonly NewUnitInfo Info;
public readonly uint ActorID;
[Sync]
public int2 Location;
@@ -29,20 +25,19 @@ namespace OpenRa.Game
public Actor( string name, int2 location, Player owner )
{
ActorID = Game.world.NextAID();
LegacyInfo = name != null ? Rules.UnitInfo[name.ToLowerInvariant()] : null; // temporary
Location = location;
CenterLocation = Traits.Util.CenterOfCell(Location);
Owner = owner;
if (LegacyInfo == null) return;
Health = LegacyInfo.Strength; /* todo: fix walls, etc so this is always true! */
if (name != null)
{
Info = Rules.NewUnitInfo[name.ToLowerInvariant()];
Health = this.GetMaxHP();
foreach (var trait in Info.Traits.WithInterface<ITraitInfo>())
traits.Add(trait.Create(this));
}
}
public void Tick()
{
@@ -128,7 +123,7 @@ namespace OpenRa.Game
public DamageState GetDamageState()
{
if (Health <= 0) return DamageState.Dead;
var halfStrength = LegacyInfo.Strength * Rules.General.ConditionYellow;
var halfStrength = this.GetMaxHP() * Rules.General.ConditionYellow;
return Health < halfStrength ? DamageState.Half : DamageState.Normal;
}
@@ -151,8 +146,10 @@ namespace OpenRa.Game
Game.world.AddFrameEndTask(w => w.Remove(this));
}
if (Health > LegacyInfo.Strength)
Health = LegacyInfo.Strength;
var maxHP = this.GetMaxHP();
if (Health > maxHP) Health = maxHP;
var newState = GetDamageState();

View File

@@ -51,5 +51,13 @@ namespace OpenRa.Game
return Rules.WeaponInfo[weapon];
}
public static int GetMaxHP(this Actor self)
{
if (self.Info == null) return 0;
var oai = self.Info.Traits.GetOrDefault<OwnedActorInfo>();
if (oai == null) return 0;
return oai.HP;
}
}
}