diff --git a/OpenRA.Game/Graphics/Animation.cs b/OpenRA.Game/Graphics/Animation.cs index 2b85cb28b4..a39a1564e8 100644 --- a/OpenRA.Game/Graphics/Animation.cs +++ b/OpenRA.Game/Graphics/Animation.cs @@ -15,14 +15,16 @@ namespace OpenRA.Graphics { public class Animation { - string name; public Sequence CurrentSequence { get; private set; } public bool IsDecoration = false; + public Func Paused; + + Func facingFunc; + int frame = 0; bool backwards = false; bool tickAlways; - - Func facingFunc; + string name; public string Name { get { return name; } } @@ -122,7 +124,8 @@ namespace OpenRA.Graphics public void Tick() { - Tick(40); // tick one frame + if (Paused == null || !Paused()) + Tick(40); // tick one frame } public bool HasSequence(string seq) { return SequenceProvider.HasSequence(name, seq); } diff --git a/OpenRA.Game/Graphics/AnimationWithOffset.cs b/OpenRA.Game/Graphics/AnimationWithOffset.cs index dd3075c5b3..60dfb8d5db 100644 --- a/OpenRA.Game/Graphics/AnimationWithOffset.cs +++ b/OpenRA.Game/Graphics/AnimationWithOffset.cs @@ -18,17 +18,19 @@ namespace OpenRA.Graphics public readonly Animation Animation; public readonly Func OffsetFunc; public readonly Func DisableFunc; + public readonly Func Paused; public readonly Func ZOffset; public AnimationWithOffset(Animation a, Func offset, Func disable) - : this(a, offset, disable, null) { } + : this(a, offset, disable, () => false, null) { } public AnimationWithOffset(Animation a, Func offset, Func disable, int zOffset) - : this(a, offset, disable, _ => zOffset) { } + : this(a, offset, disable, () => false, _ => zOffset) { } - public AnimationWithOffset(Animation a, Func offset, Func disable, Func zOffset) + public AnimationWithOffset(Animation a, Func offset, Func disable, Func pause, Func zOffset) { this.Animation = a; + this.Animation.Paused = pause; this.OffsetFunc = offset; this.DisableFunc = disable; this.ZOffset = zOffset; @@ -45,7 +47,7 @@ namespace OpenRA.Graphics public static implicit operator AnimationWithOffset(Animation a) { - return new AnimationWithOffset(a, null, null, null); + return new AnimationWithOffset(a, null, null, null, null); } } } diff --git a/OpenRA.Game/Traits/Render/RenderSprites.cs b/OpenRA.Game/Traits/Render/RenderSprites.cs index cb0f86c5d7..ff5a2fa182 100755 --- a/OpenRA.Game/Traits/Render/RenderSprites.cs +++ b/OpenRA.Game/Traits/Render/RenderSprites.cs @@ -46,7 +46,7 @@ namespace OpenRA.Traits { get { return anims[""].Animation; } protected set { anims[""] = new AnimationWithOffset(value, - anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].ZOffset); } + anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].Paused, anims[""].ZOffset); } } RenderSpritesInfo Info; diff --git a/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs b/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs index 2976fd4426..36f984435b 100644 --- a/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs +++ b/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 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, @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Render var overlay = new Animation(rs.GetImage(init.self)); overlay.PlayThen(info.Sequence, () => buildComplete = false); rs.anims.Add("make_overlay_{0}".F(info.Sequence), - new AnimationWithOffset(overlay, null, () => !buildComplete, null)); + new AnimationWithOffset(overlay, null, () => !buildComplete)); } } diff --git a/OpenRA.Mods.RA/Attack/AttackGarrisoned.cs b/OpenRA.Mods.RA/Attack/AttackGarrisoned.cs index 66fab04cb1..8d6933f5e2 100644 --- a/OpenRA.Mods.RA/Attack/AttackGarrisoned.cs +++ b/OpenRA.Mods.RA/Attack/AttackGarrisoned.cs @@ -164,6 +164,7 @@ namespace OpenRA.Mods.RA var muzzleFlash = new AnimationWithOffset(muzzleAnim, () => PortOffset(self, port), () => false, + () => false, p => WithTurret.ZOffsetFromCenter(self, p, 1024)); muzzles.Add(muzzleFlash); diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 505b7e288d..c7a8e4728e 100755 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA.Buildings { for (var x = scanStart.X; x < scanEnd.X; x++) { - var pos = new CPos(x, y); + var pos = new CPos(x, y); var at = bi.GetBuildingAt(pos); if (at == null || !at.IsInWorld || !at.HasTrait()) continue; diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index 8a2f476737..eb57e2d5ee 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 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, @@ -9,6 +9,7 @@ #endregion using System; +using System.Linq; using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Mods.RA.Buildings; @@ -20,6 +21,7 @@ namespace OpenRA.Mods.RA.Render public class RenderBuildingInfo : RenderSimpleInfo, Requires, IPlaceBuildingDecoration { public readonly bool HasMakeAnimation = true; + public readonly bool PauseOnLowPower = false; public override object Create(ActorInitializer init) { return new RenderBuilding(init, this);} @@ -35,6 +37,8 @@ namespace OpenRA.Mods.RA.Render public class RenderBuilding : RenderSimple, INotifyDamageStateChanged { + RenderBuildingInfo info; + public RenderBuilding(ActorInitializer init, RenderBuildingInfo info) : this(init, info, () => 0) { } @@ -42,6 +46,7 @@ namespace OpenRA.Mods.RA.Render : base(init.self, baseFacing) { var self = init.self; + this.info = info; // Work around a bogus crash anim.PlayRepeating(NormalizeSequence(self, "idle")); @@ -59,6 +64,13 @@ namespace OpenRA.Mods.RA.Render anim.PlayRepeating(NormalizeSequence(self, "idle")); foreach (var x in self.TraitsImplementing()) x.BuildingComplete(self); + + if (info.PauseOnLowPower) + { + var disabled = self.TraitsImplementing(); + anim.Paused = () => disabled.Any(d => d.Disabled) + && anim.CurrentSequence.Name == NormalizeSequence(self, "idle"); + } } public void PlayCustomAnimThen(Actor self, string name, Action a) diff --git a/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs b/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs index 8ccc4df5ae..1d23b82789 100644 --- a/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs +++ b/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs @@ -42,7 +42,8 @@ namespace OpenRA.Mods.RA.Render rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !visible, - p => WithTurret.ZOffsetFromCenter(self, p, 0))); + () => false, + p => WithTurret.ZOffsetFromCenter(self, p, 0))); } public void Harvested(Actor self, ResourceType resource) diff --git a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs index c1911ad2be..a37c091ad3 100644 --- a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs +++ b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Render [Desc("Position relative to body")] public readonly WVec Offset = WVec.Zero; - public readonly bool HideOnLowPower = false; + public readonly bool PauseOnLowPower = false; public object Create(ActorInitializer init) { return new WithIdleOverlay(init.self, this); } } @@ -46,7 +46,8 @@ namespace OpenRA.Mods.RA.Render rs.anims.Add("idle_overlay_{0}".F(info.Sequence), new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), - () => !buildComplete || (info.HideOnLowPower && disabled.Any(d => d.Disabled)), + () => !buildComplete, + () => info.PauseOnLowPower && disabled.Any(d => d.Disabled), p => WithTurret.ZOffsetFromCenter(self, p, 1))); } diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index c35c3c68c2..448d060e42 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -54,9 +54,10 @@ namespace OpenRA.Mods.RA.Render var muzzleFlash = new Animation(render.GetImage(self), getFacing); visible.Add(barrel, false); anims.Add(barrel, - new AnimationWithOffset(muzzleFlash, + new AnimationWithOffset(muzzleFlash, () => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel), () => !visible[barrel], + () => false, p => WithTurret.ZOffsetFromCenter(self, p, 2))); } } diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index ad37e57b15..bc24df4adf 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Render rotorAnim.PlayRepeating(info.Sequence); rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), - null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); + null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 1))); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/WithTurret.cs b/OpenRA.Mods.RA/Render/WithTurret.cs index 88e647d621..5e2283a611 100755 --- a/OpenRA.Mods.RA/Render/WithTurret.cs +++ b/OpenRA.Mods.RA/Render/WithTurret.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA.Render anim = new Animation(rs.GetImage(self), () => t.turretFacing); anim.Play(info.Sequence); rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( - anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1))); + anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1))); // Restrict turret facings to match the sprite t.QuantizedFacings = anim.CurrentSequence.Facings; diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index ffb638bfa1..93ddf63d2b 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -367,6 +367,8 @@ HQ: RequiresPower: CanPowerDown: DisabledOverlay: + RenderBuilding: + PauseOnLowPower: yes Health: HP: 750 RevealsShroud: @@ -440,6 +442,8 @@ EYE: RequiresPower: CanPowerDown: DisabledOverlay: + RenderBuilding: + PauseOnLowPower: yes Health: HP: 1200 RevealsShroud: diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index da05abe490..f03ec22c87 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -338,7 +338,7 @@ CONCRETEB: Prerequisite: Outpost WithIdleOverlay@DISH: Sequence: idle-dish - HideOnLowPower: yes + PauseOnLowPower: yes ^STARPORT: Inherits: ^Building diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index d31607dcfc..6d398d9ab9 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -67,6 +67,8 @@ GAP: RequiresPower: CanPowerDown: DisabledOverlay: + RenderBuilding: + PauseOnLowPower: yes Health: HP: 1000 Armor: