diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 872f2a56de..db845b31c3 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -620,6 +620,13 @@ namespace OpenRA.Mods.Common.UtilityCommands if (depth == 1 && node.Key == "-IronCurtainable") node.Key = "-InvulnerabilityUpgrade@IRONCURTAIN"; + + // Replaced RemoveOnConditions with KillsSelf + if (depth == 1 && node.Key == "RemoveOnConditions") + { + node.Key = "KillsSelf"; + node.Value.Nodes.Add(new MiniYamlNode("RemoveInstead", new MiniYaml("true"))); + } } UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); diff --git a/OpenRA.Mods.RA/KillsSelf.cs b/OpenRA.Mods.RA/KillsSelf.cs new file mode 100644 index 0000000000..4c5916dae1 --- /dev/null +++ b/OpenRA.Mods.RA/KillsSelf.cs @@ -0,0 +1,71 @@ +#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 +{ + class KillsSelfInfo : ITraitInfo + { + [Desc("Enable only if this upgrade is enabled.")] + public readonly string RequiresUpgrade = null; + + [Desc("Remove the actor from the world (and destroy it) instead of killing it.")] + public readonly bool RemoveInstead = false; + + public object Create(ActorInitializer init) { return new KillsSelf(init.self, this); } + } + + class KillsSelf : INotifyAddedToWorld, IUpgradable + { + readonly KillsSelfInfo info; + readonly Actor self; + + public KillsSelf(Actor self, KillsSelfInfo info) + { + this.info = info; + this.self = self; + } + + public void AddedToWorld(Actor self) + { + if (info.RequiresUpgrade == null) + Kill(); + } + + public bool AcceptsUpgrade(string type) + { + return type == info.RequiresUpgrade; + } + + public void UpgradeAvailable(Actor self, string type, bool available) + { + if (type == info.RequiresUpgrade) + Kill(); + } + + void Kill() + { + if (self.IsDead()) + return; + + if (info.RemoveInstead || !self.HasTrait()) + self.Destroy(); + else + self.Kill(self); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 04654f5bdb..cf8c78884a 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -295,7 +295,6 @@ - diff --git a/OpenRA.Mods.RA/RemoveOnConditions.cs b/OpenRA.Mods.RA/RemoveOnConditions.cs deleted file mode 100644 index 5094f781f6..0000000000 --- a/OpenRA.Mods.RA/RemoveOnConditions.cs +++ /dev/null @@ -1,79 +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 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/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 5f8f688d2e..d11237ff82 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -11,7 +11,8 @@ Name: Concrete Description: Provides a strong foundation that prevents\ndamage from the terrain. RenderSprites: - RemoveOnConditions: + KillsSelf: + RemoveInstead: true CONCRETEA: Inherits: ^CONCRETE