diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index 0a8a292b64..0f82aa7c56 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -44,6 +44,8 @@ namespace OpenRA.Traits public readonly BuildingInfo Info; [Sync] readonly int2 topLeft; + + readonly PowerManager PlayerPower; public bool Disabled { @@ -57,6 +59,8 @@ namespace OpenRA.Traits Info = self.Info.Traits.Get(); self.CenterLocation = Game.CellSize * ((float2)topLeft + .5f * (float2)Info.Dimensions); + + PlayerPower = init.self.Owner.PlayerActor.Trait(); } public int GetPowerUsage() @@ -78,6 +82,19 @@ namespace OpenRA.Traits public void Damaged(Actor self, AttackInfo e) { + // Power plants lose power with damage + if (Info.Power > 0) + { + var modifier = self + .TraitsImplementing() + .Select(t => t.GetPowerModifier()) + .Product(); + + var health = self.TraitOrDefault(); + var healthFraction = (health == null) ? 1f : health.HPFraction; + PlayerPower.UpdateActor(self, (int)(modifier * healthFraction * Info.Power)); + } + if (e.DamageState == DamageState.Dead) { self.World.WorldActor.Trait().AddEffect(10, self.CenterLocation, 1);