diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
index 691417e495..6935478767 100644
--- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
+++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
@@ -292,6 +292,7 @@
+
@@ -473,7 +474,6 @@
-
diff --git a/OpenRA.Mods.RA/RemoveImmediately.cs b/OpenRA.Mods.RA/RemoveImmediately.cs
deleted file mode 100644
index 35675d252d..0000000000
--- a/OpenRA.Mods.RA/RemoveImmediately.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-#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 OpenRA.Traits;
-
-namespace OpenRA.Mods.RA
-{
- [Desc("Destroy the actor right after being added to the game world.")]
- public class RemoveImmediatelyInfo : TraitInfo {}
-
- public class RemoveImmediately : INotifyAddedToWorld
- {
- public void AddedToWorld(Actor self) { self.Destroy(); }
- }
-}
diff --git a/OpenRA.Mods.RA/RemoveOnConditions.cs b/OpenRA.Mods.RA/RemoveOnConditions.cs
new file mode 100644
index 0000000000..5094f781f6
--- /dev/null
+++ b/OpenRA.Mods.RA/RemoveOnConditions.cs
@@ -0,0 +1,79 @@
+#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;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using OpenRA.Primitives;
+using OpenRA.Traits;
+using OpenRA.Effects;
+
+namespace OpenRA.Mods.RA
+{
+ [Desc("Destroys the actor after a specified number of ticks if all conditions are met.")]
+ class RemoveOnConditionsInfo : ITraitInfo
+ {
+ [Desc("Prerequisites required before removal")]
+ public readonly string[] Prerequisites = {};
+
+ [Desc("Delay until it starts checking if you have the prerequisites", "0 = Removal attempted on AddedToWorld")]
+ public readonly int Delay = 0;
+
+ [Desc("Should the trait kill instead of destroy?")]
+ public readonly bool KillInstead = false;
+
+ public object Create(ActorInitializer init) { return new RemoveOnConditions(init.self, this); }
+ }
+
+ class RemoveOnConditions : INotifyAddedToWorld, ITechTreeElement
+ {
+ readonly RemoveOnConditionsInfo info;
+ readonly Actor self;
+
+ public RemoveOnConditions(Actor self, RemoveOnConditionsInfo info)
+ {
+ this.info = info;
+ this.self = self;
+ }
+
+ public void AddedToWorld(Actor self)
+ {
+ Action act = () =>
+ {
+ if (!info.Prerequisites.Any() || self.Owner.PlayerActor.Trait().HasPrerequisites(info.Prerequisites))
+ Remove();
+ else
+ self.Owner.PlayerActor.Trait().Add("remove_" + string.Join("_", info.Prerequisites.OrderBy(a => a)), info.Prerequisites, 0, this);
+ };
+
+ if (info.Delay <= 0 && (!info.Prerequisites.Any() || self.Owner.PlayerActor.Trait().HasPrerequisites(info.Prerequisites)))
+ Remove();
+ else
+ self.World.AddFrameEndTask(w => w.Add(new DelayedAction(info.Delay, act)));
+ }
+
+ void Remove()
+ {
+ if (!self.IsDead())
+ {
+ if (info.KillInstead && self.HasTrait())
+ self.Kill(self);
+ else
+ self.Destroy();
+ }
+ }
+
+ public void PrerequisitesAvailable(string key) { Remove(); }
+ public void PrerequisitesUnavailable(string key) { }
+ public void PrerequisitesItemHidden(string key) { }
+ public void PrerequisitesItemVisible(string key) { }
+ }
+}
diff --git a/OpenRA.Utility/UpgradeRules.cs b/OpenRA.Utility/UpgradeRules.cs
index e4631d0436..c1e348eda7 100644
--- a/OpenRA.Utility/UpgradeRules.cs
+++ b/OpenRA.Utility/UpgradeRules.cs
@@ -437,6 +437,20 @@ namespace OpenRA.Utility
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
+
+ // RemoveImmediately was replaced with RemoveOnConditions
+ if (engineVersion < 20140821)
+ {
+ if (depth == 1)
+ {
+ if (node.Key == "RemoveImmediately")
+ node.Key = "RemoveOnConditions";
+
+ if (node.Key == "-RemoveImmediately")
+ node.Key = "-RemoveOnConditions";
+ }
+ }
+
}
}
diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml
index ce4fa51046..f63d93b622 100644
--- a/mods/d2k/rules/structures.yaml
+++ b/mods/d2k/rules/structures.yaml
@@ -12,7 +12,7 @@
Name: Concrete
Description: Provides a strong foundation that prevents\ndamage from the terrain.
RenderSprites:
- RemoveImmediately:
+ RemoveOnConditions:
CONCRETEA:
Inherits: ^CONCRETE