diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 36716979b1..770ade3d8a 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -55,7 +55,7 @@ namespace OpenRA.Traits .FirstOrDefault(); } - protected virtual string NormalizeSequence(Actor self, string baseSequence) + public virtual string NormalizeSequence(Actor self, string baseSequence) { string damageState = self.GetDamageState() >= DamageState.Heavy ? "damaged-" : ""; if (anim.HasSequence(damageState + baseSequence)) diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 4a6755178c..0713fd3395 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -85,7 +85,6 @@ - diff --git a/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs b/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs deleted file mode 100755 index 5402176fab..0000000000 --- a/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs +++ /dev/null @@ -1,65 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System.Collections.Generic; -using System.Linq; -using OpenRA.Graphics; -using OpenRA.Traits; -using OpenRA.Mods.RA.Render; - -namespace OpenRA.Mods.Cnc -{ - class RenderBuildingRefineryInfo : RenderBuildingInfo - { - public override object Create(ActorInitializer init) { return new RenderBuildingRefinery(init, this); } - } - - class RenderBuildingRefinery : RenderBuilding, INotifyBuildComplete, INotifySold, INotifyCapture - { - public Animation lights; - PlayerResources playerResources; - bool buildComplete; - - public RenderBuildingRefinery(ActorInitializer init, RenderBuildingRefineryInfo info) - : base(init, info) - { - playerResources = init.self.Owner.PlayerActor.Trait(); - - lights = new Animation(GetImage(init.self)); - lights.PlayFetchIndex("lights", - () => playerResources.OreCapacity != 0 - ? (59 * playerResources.Ore) / (10 * playerResources.OreCapacity) - : 0); - - anims.Add("lights", new AnimationWithOffset(lights, null, () => !buildComplete, 1024)); - } - - public void BuildingComplete( Actor self ) - { - buildComplete = true; - } - - public override void DamageStateChanged(Actor self, AttackInfo e) - { - if (lights.CurrentSequence != null) - lights.ReplaceAnim(NormalizeSequence(self, "lights")); - - base.DamageStateChanged(self, e); - } - - public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner) - { - playerResources = newOwner.PlayerActor.Trait(); - } - - public void Selling(Actor self) { anims.Remove("lights"); } - public void Sold(Actor self) { } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 67f14a46b7..515a2c40e6 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -453,6 +453,7 @@ + diff --git a/OpenRA.Mods.RA/Render/WithResources.cs b/OpenRA.Mods.RA/Render/WithResources.cs new file mode 100755 index 0000000000..611a5cc167 --- /dev/null +++ b/OpenRA.Mods.RA/Render/WithResources.cs @@ -0,0 +1,70 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Render +{ + class WithResourcesInfo : ITraitInfo, Requires + { + [Desc("Sequence name to use")] + public readonly string Sequence = "resources"; + + public object Create(ActorInitializer init) { return new WithResources(init.self, this); } + } + + class WithResources : INotifyBuildComplete, INotifySold, INotifyCapture, INotifyDamageStateChanged + { + WithResourcesInfo info; + Animation anim; + RenderSimple rs; + PlayerResources playerResources; + bool buildComplete; + + public WithResources(Actor self, WithResourcesInfo info) + { + this.info = info; + rs = self.Trait(); + playerResources = self.Owner.PlayerActor.Trait(); + + anim = new Animation(rs.GetImage(self)); + anim.PlayFetchIndex(info.Sequence, + () => playerResources.OreCapacity != 0 + ? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity) + : 0); + + rs.anims.Add("resources_{0}".F(info.Sequence), new AnimationWithOffset( + anim, null, () => !buildComplete, 1024)); + } + + public void BuildingComplete( Actor self ) + { + buildComplete = true; + } + + public void DamageStateChanged(Actor self, AttackInfo e) + { + if (anim.CurrentSequence != null) + anim.ReplaceAnim(rs.NormalizeSequence(self, info.Sequence)); + } + + public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner) + { + playerResources = newOwner.PlayerActor.Trait(); + } + + public void Selling(Actor self) { rs.anims.Remove("resources_{0}".F(info.Sequence)); } + public void Sold(Actor self) { } + } +} diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index f35a0da25f..591a948a56 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -134,8 +134,7 @@ PROC: InitialActivity: FindResources SpawnOffset: 1,2 Facing: 64 - -RenderBuilding: - RenderBuildingRefinery: + WithResources: SILO: Inherits: ^Building diff --git a/mods/cnc/sequences/structures.yaml b/mods/cnc/sequences/structures.yaml index 311b4e04f5..e1f52bbf02 100644 --- a/mods/cnc/sequences/structures.yaml +++ b/mods/cnc/sequences/structures.yaml @@ -54,11 +54,11 @@ proc: Start: 0 Length: * Tick: 80 - lights: proctwr + resources: proctwr Start: 0 Length: 6 Offset: -32,-21 - damaged-lights: proctwr + damaged-resources: proctwr Start: 6 Length: 6 Offset: -32,-21