diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
index 3cd96f7a4a..72c741aea3 100644
--- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
+++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
@@ -520,6 +520,7 @@
+
diff --git a/OpenRA.Mods.RA/Render/WithActiveAnimation.cs b/OpenRA.Mods.RA/Render/WithActiveAnimation.cs
new file mode 100644
index 0000000000..cd8dbe29f8
--- /dev/null
+++ b/OpenRA.Mods.RA/Render/WithActiveAnimation.cs
@@ -0,0 +1,65 @@
+#region Copyright & License Information
+/*
+ * 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,
+ * see COPYING.
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using OpenRA.Graphics;
+using OpenRA.Traits;
+
+namespace OpenRA.Mods.RA.Render
+{
+ [Desc("Replaces the idle animation of a building.")]
+ public class WithActiveAnimationInfo : ITraitInfo, Requires
+ {
+ [Desc("Sequence name to use")]
+ public readonly string Sequence = "active";
+
+ public readonly int Interval = 750;
+
+ public readonly bool PauseOnLowPower = false;
+
+ public object Create(ActorInitializer init) { return new WithActiveAnimation(init.self, this); }
+ }
+
+ public class WithActiveAnimation : ITickRender, INotifyBuildComplete
+ {
+ readonly IEnumerable disabled;
+ readonly WithActiveAnimationInfo info;
+ readonly RenderBuilding renderBuilding;
+
+ public WithActiveAnimation(Actor self, WithActiveAnimationInfo info)
+ {
+ disabled = self.TraitsImplementing();
+ renderBuilding = self.Trait();
+ this.info = info;
+ }
+
+ int ticks;
+ public void TickRender(WorldRenderer wr, Actor self)
+ {
+ if (!buildComplete)
+ return;
+
+ if (--ticks <= 0)
+ {
+ if (!(info.PauseOnLowPower && disabled.Any(d => d.Disabled)))
+ renderBuilding.PlayCustomAnim(self, info.Sequence);
+ ticks = info.Interval;
+ }
+ }
+
+ bool buildComplete = false;
+
+ public void BuildingComplete(Actor self)
+ {
+ buildComplete = true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenRA.Mods.RA/SeedsResource.cs b/OpenRA.Mods.RA/SeedsResource.cs
index 73bc803c2c..6528127dca 100644
--- a/OpenRA.Mods.RA/SeedsResource.cs
+++ b/OpenRA.Mods.RA/SeedsResource.cs
@@ -17,47 +17,49 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
- class SeedsResourceInfo : TraitInfo
+ [Desc("Lets the actor spread resources around it in a circle.")]
+ class SeedsResourceInfo : ITraitInfo
{
public readonly int Interval = 75;
public readonly string ResourceType = "Ore";
public readonly int MaxRange = 100;
- public readonly int AnimationInterval = 750;
+
+ public object Create(ActorInitializer init) { return new SeedsResource(init.self, this); }
}
class SeedsResource : ITick, ISeedableResource
{
+ readonly SeedsResourceInfo info;
+
+ readonly ResourceType resourceType;
+ readonly ResourceLayer resLayer;
+
+ public SeedsResource(Actor self, SeedsResourceInfo info)
+ {
+ this.info = info;
+
+ resourceType = self.World.WorldActor.TraitsImplementing()
+ .FirstOrDefault(t => t.Info.Name == info.ResourceType);
+
+ if (resourceType == null)
+ throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType));
+
+ resLayer = self.World.WorldActor.Trait();
+ }
+
int ticks;
- int animationTicks;
public void Tick(Actor self)
{
if (--ticks <= 0)
{
Seed(self);
- ticks = self.Info.Traits.Get().Interval;
- }
-
- if (--animationTicks <= 0)
- {
- var info = self.Info.Traits.Get();
- self.Trait().PlayCustomAnim(self, "active");
- animationTicks = info.AnimationInterval;
+ ticks = info.Interval;
}
}
public void Seed(Actor self)
{
- var info = self.Info.Traits.Get();
- var resourceType = self.World.WorldActor
- .TraitsImplementing()
- .FirstOrDefault(t => t.Info.Name == info.ResourceType);
-
- if (resourceType == null)
- throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType));
-
- var resLayer = self.World.WorldActor.Trait();
-
var cell = RandomWalk(self.Location, self.World.SharedRandom)
.Take(info.MaxRange)
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p))
diff --git a/mods/cnc/rules/trees.yaml b/mods/cnc/rules/trees.yaml
index ce52e9aecc..e68f027384 100644
--- a/mods/cnc/rules/trees.yaml
+++ b/mods/cnc/rules/trees.yaml
@@ -3,6 +3,7 @@ SPLIT2:
SeedsResource:
ResourceType: Tiberium
Interval: 55
+ WithActiveAnimation:
SPLIT3:
Inherits: ^TibTree
@@ -11,6 +12,7 @@ SPLIT3:
SeedsResource:
ResourceType: Tiberium
Interval: 55
+ WithActiveAnimation:
SPLITBLUE:
Inherits: ^TibTree
@@ -19,6 +21,7 @@ SPLITBLUE:
SeedsResource:
ResourceType: BlueTiberium
Interval: 110
+ WithActiveAnimation:
Tooltip:
Name: Blossom Tree (blue)
RadarColorFromTerrain:
diff --git a/mods/d2k/rules/misc.yaml b/mods/d2k/rules/misc.yaml
index bef6076078..13e6e8a445 100644
--- a/mods/d2k/rules/misc.yaml
+++ b/mods/d2k/rules/misc.yaml
@@ -113,6 +113,7 @@ SPICEBLOOM:
SeedsResource:
ResourceType: Spice
Interval: 75
+ WithActiveAnimation:
RadarColorFromTerrain:
Terrain: Spice
BodyOrientation:
diff --git a/mods/ra/sequences/decorations.yaml b/mods/ra/sequences/decorations.yaml
index db881ad307..a447ba86bd 100644
--- a/mods/ra/sequences/decorations.yaml
+++ b/mods/ra/sequences/decorations.yaml
@@ -223,18 +223,6 @@ t01:
Length: 8
Tick: 80
-mine:
- idle:
- Start: 0
- active:
- Start: 0
-
-railmine:
- idle:
- Start: 0
- active:
- Start: 0
-
v01:
idle:
Start: 0
diff --git a/mods/ra/sequences/misc.yaml b/mods/ra/sequences/misc.yaml
index 1092fbf7ae..b0408434aa 100644
--- a/mods/ra/sequences/misc.yaml
+++ b/mods/ra/sequences/misc.yaml
@@ -608,3 +608,11 @@ craters:
Length: *
cr6: cr6
Length: *
+
+mine:
+ idle:
+ Start: 0
+
+railmine:
+ idle:
+ Start: 0