diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj
index 0f4e25dde5..185d03cc18 100644
--- a/OpenRa.Game/OpenRa.Game.csproj
+++ b/OpenRa.Game/OpenRa.Game.csproj
@@ -146,6 +146,7 @@
+
diff --git a/OpenRa.Game/Traits/Activities/Sell.cs b/OpenRa.Game/Traits/Activities/Sell.cs
new file mode 100644
index 0000000000..d0dac1d145
--- /dev/null
+++ b/OpenRa.Game/Traits/Activities/Sell.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenRa.Game.Traits.Activities
+{
+ class Sell : IActivity
+ {
+ public IActivity NextActivity { get; set; }
+
+ bool started;
+
+ void DoSell(Actor self)
+ {
+ var refund = Rules.General.RefundPercent
+ * self.Health * self.Info.Cost / self.Info.Strength;
+
+ self.Owner.GiveCash((int)refund);
+ self.Health = 0;
+ Game.world.Remove(self);
+ }
+
+ public IActivity Tick(Actor self)
+ {
+ if (!started)
+ {
+ var rb = self.traits.Get();
+ rb.PlayCustomAnimBackwards(self, "make",
+ () => Game.world.AddFrameEndTask(w => DoSell(self)));
+
+ Sound.Play("cashturn.aud");
+ started = true;
+ }
+
+ return this;
+ }
+
+ public void Cancel(Actor self) { /* never gonna give you up.. */ }
+ }
+}
diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs
index 2dd81f7266..24830e0a67 100644
--- a/OpenRa.Game/Traits/RenderBuilding.cs
+++ b/OpenRa.Game/Traits/RenderBuilding.cs
@@ -62,6 +62,12 @@ namespace OpenRa.Game.Traits
() => anim.PlayRepeating(GetPrefix(self) + "idle"));
}
+ public void PlayCustomAnimBackwards(Actor self, string name, Action a)
+ {
+ anim.PlayBackwardsThen(GetPrefix(self) + name,
+ () => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });
+ }
+
public virtual void Damaged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged)