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

View File

@@ -51,5 +51,13 @@ namespace OpenRa.Game
return Rules.WeaponInfo[weapon]; 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;
}
} }
} }