diff --git a/OpenRA.Mods.Common/Traits/Pluggable.cs b/OpenRA.Mods.Common/Traits/Pluggable.cs index e27ec24929..d1214be5b6 100644 --- a/OpenRA.Mods.Common/Traits/Pluggable.cs +++ b/OpenRA.Mods.Common/Traits/Pluggable.cs @@ -14,13 +14,15 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class PluggableInfo : ITraitInfo, Requires, UsesInit + public class PluggableInfo : ITraitInfo, UsesInit { [Desc("Footprint cell offset where a plug can be placed.")] public readonly CVec Offset = CVec.Zero; - [FieldLoader.Require, Desc("Upgrades to grant for each accepted plug type.")] - public readonly Dictionary Upgrades = null; + [FieldLoader.Require] + [UpgradeGrantedReference] + [Desc("Conditions to grant for each accepted plug type.")] + public readonly Dictionary Conditions = null; public object Create(ActorInitializer init) { return new Pluggable(init, this); } } @@ -30,14 +32,14 @@ namespace OpenRA.Mods.Common.Traits public readonly PluggableInfo Info; readonly string initialPlug; - readonly UpgradeManager upgradeManager; + UpgradeManager upgradeManager; + int conditionToken = UpgradeManager.InvalidConditionToken; string active; public Pluggable(ActorInitializer init, PluggableInfo info) { Info = info; - upgradeManager = init.Self.Trait(); var plugInit = init.Contains() ? init.Get>() : new Dictionary(); if (plugInit.ContainsKey(Info.Offset)) @@ -46,24 +48,24 @@ namespace OpenRA.Mods.Common.Traits public void Created(Actor self) { + upgradeManager = self.TraitOrDefault(); + if (!string.IsNullOrEmpty(initialPlug)) EnablePlug(self, initialPlug); } public bool AcceptsPlug(Actor self, string type) { - return active == null && Info.Upgrades.ContainsKey(type); + return active == null && Info.Conditions.ContainsKey(type); } public void EnablePlug(Actor self, string type) { - string[] upgrades; - if (!Info.Upgrades.TryGetValue(type, out upgrades)) + string condition; + if (!Info.Conditions.TryGetValue(type, out condition)) return; - foreach (var u in upgrades) - upgradeManager.GrantUpgrade(self, u, this); - + conditionToken = upgradeManager.GrantCondition(self, condition); active = type; } @@ -72,8 +74,10 @@ namespace OpenRA.Mods.Common.Traits if (type != active) return; - foreach (var u in Info.Upgrades[type]) - upgradeManager.RevokeUpgrade(self, u, this); + if (conditionToken != UpgradeManager.InvalidConditionToken) + conditionToken = upgradeManager.RevokeCondition(self, conditionToken); + + active = null; } } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index b40f38561e..96dc5e1ad7 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -644,6 +644,21 @@ namespace OpenRA.Mods.Common.UtilityCommands if (!node.Value.Nodes.Any(n => n.Key == "AttackingCondition")) node.Value.Nodes.Add(new MiniYamlNode("AttackingCondition", "attacking")); } + + if (node.Key.StartsWith("Pluggable", StringComparison.Ordinal)) + { + var upgrades = node.Value.Nodes.FirstOrDefault(n => n.Key == "Upgrades"); + if (upgrades != null) + { + upgrades.Key = "Conditions"; + foreach (var n in upgrades.Value.Nodes) + { + var conditions = FieldLoader.GetValue("", n.Value.Value); + if (conditions.Length > 1) + Console.WriteLine("Unable to automatically migrate multiple Pluggable upgrades to a condition. This must be corrected manually"); + } + } + } } UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); diff --git a/mods/ts/rules/gdi-structures.yaml b/mods/ts/rules/gdi-structures.yaml index ec6fd95cc4..19f495c6f4 100644 --- a/mods/ts/rules/gdi-structures.yaml +++ b/mods/ts/rules/gdi-structures.yaml @@ -38,7 +38,7 @@ GAPOWR: DisabledOverlay: Pluggable@pluga: Offset: 0,1 - Upgrades: + Conditions: powrup: powrup.a Power@pluga: RequiresCondition: powrup.a @@ -48,7 +48,7 @@ GAPOWR: Sequence: idle-powrupa Pluggable@plugb: Offset: 1,1 - Upgrades: + Conditions: powrup: powrup.b WithIdleOverlay@plugb: RequiresCondition: powrup.b @@ -438,7 +438,7 @@ GAPLUG: Amount: -50 Pluggable@pluga: Offset: 0,2 - Upgrades: + Conditions: plug.ioncannon: plug.ioncannona plug.hunterseeker: plug.hunterseekera WithIdleOverlay@ioncannona: @@ -449,7 +449,7 @@ GAPLUG: Sequence: idle-hunterseekera Pluggable@plugb: Offset: 1,2 - Upgrades: + Conditions: plug.ioncannon: plug.ioncannonb plug.hunterseeker: plug.hunterseekerb WithIdleOverlay@ioncannonb: diff --git a/mods/ts/rules/gdi-support.yaml b/mods/ts/rules/gdi-support.yaml index c4469e53b8..31f5c8723e 100644 --- a/mods/ts/rules/gdi-support.yaml +++ b/mods/ts/rules/gdi-support.yaml @@ -126,7 +126,7 @@ GACTWR: RequiresCondition: tower.sam Amount: -10 Pluggable: - Upgrades: + Conditions: tower.vulcan: tower.vulcan tower.rocket: tower.rocket tower.sam: tower.sam