diff --git a/OpenRA.Mods.Common/Traits/Pluggable.cs b/OpenRA.Mods.Common/Traits/Pluggable.cs index d91a850aaa..8aa5ee6074 100644 --- a/OpenRA.Mods.Common/Traits/Pluggable.cs +++ b/OpenRA.Mods.Common/Traits/Pluggable.cs @@ -9,40 +9,44 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class PluggableInfo : ITraitInfo, Requires + public class PluggableInfo : ITraitInfo, Requires, UsesInit { [Desc("Footprint cell offset where a plug can be placed.")] public readonly CVec Offset = CVec.Zero; - [FieldLoader.LoadUsing("LoadUpgrades", true)] - [Desc("Upgrades to grant for each accepted plug type.")] + [FieldLoader.Require, Desc("Upgrades to grant for each accepted plug type.")] public readonly Dictionary Upgrades = null; - static object LoadUpgrades(MiniYaml y) - { - return y.ToDictionary()["Upgrades"].Nodes.ToDictionary( - kv => kv.Key, - kv => FieldLoader.GetValue("(value)", kv.Value.Value)); - } - - public object Create(ActorInitializer init) { return new Pluggable(init.Self, this); } + public object Create(ActorInitializer init) { return new Pluggable(init, this); } } - public class Pluggable + public class Pluggable : INotifyCreated { public readonly PluggableInfo Info; + + readonly string initialPlug; readonly UpgradeManager upgradeManager; + string active; - public Pluggable(Actor self, PluggableInfo info) + public Pluggable(ActorInitializer init, PluggableInfo info) { Info = info; - upgradeManager = self.Trait(); + upgradeManager = init.Self.Trait(); + + var plugInit = init.Contains() ? init.Get>() : new Dictionary(); + if (plugInit.ContainsKey(Info.Offset)) + initialPlug = plugInit[Info.Offset]; + } + + public void Created(Actor self) + { + if (!string.IsNullOrEmpty(initialPlug)) + EnablePlug(self, initialPlug); } public bool AcceptsPlug(Actor self, string type) @@ -71,4 +75,13 @@ namespace OpenRA.Mods.Common.Traits upgradeManager.RevokeUpgrade(self, u, this); } } + + public class PlugsInit : IActorInit> + { + [DictionaryFromYamlKey] + readonly Dictionary value = new Dictionary(); + public PlugsInit() { } + public PlugsInit(Dictionary init) { value = init; } + public Dictionary Value(World world) { return value; } + } } diff --git a/mods/ts/maps/gdi4a/map.yaml b/mods/ts/maps/gdi4a/map.yaml index 6cae8144c8..38c2a84593 100644 --- a/mods/ts/maps/gdi4a/map.yaml +++ b/mods/ts/maps/gdi4a/map.yaml @@ -94,6 +94,8 @@ Actors: Owner: Neutral Health: 100 Facing: 37 + Plugs: + 0,0: tower.vulcan Actor12: gapile Location: 79,34 Owner: Neutral @@ -114,6 +116,8 @@ Actors: Owner: Neutral Health: 100 Facing: 179 + Plugs: + 0,0: tower.vulcan Actor16: garadr Location: 70,30 Owner: Neutral @@ -129,11 +133,15 @@ Actors: Owner: Neutral Health: 100 Facing: 24 + Plugs: + 0,0: tower.vulcan Actor19: gactwr Location: 98,54 Owner: Neutral Health: 100 Facing: 219 + Plugs: + 0,0: tower.vulcan Actor20: ammocrat Location: 69,34 Owner: Neutral