Move Power out of Building and into its own trait

Conflicts:
	mods/ts/rules/structures.yaml
This commit is contained in:
ScottNZ
2014-08-02 01:38:14 +12:00
parent 9527d7c2f4
commit 692e3a9c88
23 changed files with 383 additions and 211 deletions

View File

@@ -23,8 +23,6 @@ namespace OpenRA.Mods.RA.Buildings
public class BuildingInfo : ITraitInfo, IOccupySpaceInfo, UsesInit<LocationInit>
{
[Desc("If negative, it will drain power, if positive, it will provide power.")]
public readonly int Power = 0;
[Desc("Where you are allowed to place the building (Water, Clear, ...)")]
public readonly string[] TerrainTypes = {};
[Desc("The range to the next building it can be constructed. Set it higher for walls.")]
@@ -101,7 +99,7 @@ namespace OpenRA.Mods.RA.Buildings
}
}
public class Building : INotifyDamage, IOccupySpace, INotifyCapture, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld
public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld
{
public readonly BuildingInfo Info;
public bool BuildComplete { get; private set; }
@@ -109,8 +107,6 @@ namespace OpenRA.Mods.RA.Buildings
readonly Actor self;
public readonly bool SkipMakeAnimation;
PowerManager PlayerPower;
/* shared activity lock: undeploy, sell, capture, etc */
[Sync] public bool Locked = true;
@@ -135,7 +131,6 @@ namespace OpenRA.Mods.RA.Buildings
this.self = init.self;
this.topLeft = init.Get<LocationInit, CPos>();
this.Info = info;
this.PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
@@ -144,30 +139,9 @@ namespace OpenRA.Mods.RA.Buildings
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
}
public int GetPowerUsage()
{
if (Info.Power <= 0)
return Info.Power;
var health = self.TraitOrDefault<Health>();
return health != null ? (Info.Power * health.HP / health.MaxHP) : Info.Power;
}
public void Damaged(Actor self, AttackInfo e)
{
// Power plants lose power with damage
if (Info.Power > 0)
PlayerPower.UpdateActor(self, GetPowerUsage());
}
Pair<CPos, SubCell>[] occupiedCells;
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
}
public void Created(Actor self)
{
if (SkipMakeAnimation || !self.HasTrait<WithMakeAnimation>())