diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index 46fb2eb5d4..8a095f96ee 100644 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -166,7 +166,7 @@ namespace OpenRA.Mods.RA Produceable[self.World.Map.Rules.Actors[key]].Visible = false; } - public void PrerequisitesItemVisable(string key) + public void PrerequisitesItemVisible(string key) { Produceable[self.World.Map.Rules.Actors[key]].Visible = true; } diff --git a/OpenRA.Mods.RA/Player/TechTree.cs b/OpenRA.Mods.RA/Player/TechTree.cs index 131818239f..24e76c2a7a 100755 --- a/OpenRA.Mods.RA/Player/TechTree.cs +++ b/OpenRA.Mods.RA/Player/TechTree.cs @@ -142,7 +142,7 @@ namespace OpenRA.Mods.RA watcher.PrerequisitesItemHidden(Key); if (!nowHidden && hidden) - watcher.PrerequisitesItemVisable(Key); + watcher.PrerequisitesItemVisible(Key); if (nowHasPrerequisites && !hasPrerequisites) watcher.PrerequisitesAvailable(Key); diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPower.cs b/OpenRA.Mods.RA/SupportPowers/SupportPower.cs index 86231f77c4..506ad62584 100755 --- a/OpenRA.Mods.RA/SupportPowers/SupportPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPower.cs @@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA public readonly string LongDesc = ""; public readonly bool AllowMultiple = false; public readonly bool OneShot = false; + public readonly string[] Prerequisites = {}; public readonly string BeginChargeSound = null; public readonly string EndChargeSound = null; diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs index 7d35647115..5bceff7b41 100644 --- a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs @@ -16,23 +16,25 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - public class SupportPowerManagerInfo : ITraitInfo, Requires + public class SupportPowerManagerInfo : ITraitInfo, Requires, Requires { public object Create(ActorInitializer init) { return new SupportPowerManager(init); } } - public class SupportPowerManager : ITick, IResolveOrder + public class SupportPowerManager : ITick, IResolveOrder, ITechTreeElement { public readonly Actor self; public readonly Dictionary Powers = new Dictionary(); public readonly DeveloperMode DevMode; + public readonly TechTree TechTree; public readonly Lazy RadarPings; public SupportPowerManager(ActorInitializer init) { self = init.self; - DevMode = init.self.Trait(); + DevMode = self.Trait(); + TechTree = self.Trait(); RadarPings = Exts.Lazy(() => init.world.WorldActor.TraitOrDefault()); init.world.ActorAdded += ActorAdded; @@ -46,28 +48,30 @@ namespace OpenRA.Mods.RA void ActorAdded(Actor a) { - if (a.Owner != self.Owner || !a.HasTrait()) + if (a.Owner != self.Owner) return; foreach (var t in a.TraitsImplementing()) { var key = MakeKey(t); - if (Powers.ContainsKey(key)) + if (!Powers.ContainsKey(key)) { - Powers[key].Instances.Add(t); - } - else - { - var si = new SupportPowerInstance(key, this) + Powers.Add(key, new SupportPowerInstance(key, this) { - Instances = new List() { t }, + Instances = new List(), RemainingTime = t.Info.ChargeTime * 25, TotalTime = t.Info.ChargeTime * 25, - }; + }); - Powers.Add(key, si); + if (t.Info.Prerequisites.Any()) + { + TechTree.Add(key, t.Info.Prerequisites, 0, this); + TechTree.Update(); + } } + + Powers[key].Instances.Add(t); } } @@ -80,8 +84,13 @@ namespace OpenRA.Mods.RA { var key = MakeKey(t); Powers[key].Instances.Remove(t); + if (Powers[key].Instances.Count == 0 && !Powers[key].Disabled) + { Powers.Remove(key); + TechTree.Remove(key); + TechTree.Update(); + } } } @@ -114,6 +123,28 @@ namespace OpenRA.Mods.RA return a.TraitsImplementing() .Select(t => Powers[MakeKey(t)]); } + + public void PrerequisitesAvailable(string key) + { + SupportPowerInstance sp; + if (!Powers.TryGetValue(key, out sp)) + return; + + sp.Disabled = false; + } + + public void PrerequisitesUnavailable(string key) + { + SupportPowerInstance sp; + if (!Powers.TryGetValue(key, out sp)) + return; + + sp.Disabled = true; + sp.RemainingTime = sp.TotalTime; + } + + public void PrerequisitesItemHidden(string key) { } + public void PrerequisitesItemVisible(string key) { } } public class SupportPowerInstance @@ -125,7 +156,7 @@ namespace OpenRA.Mods.RA public int RemainingTime; public int TotalTime; public bool Active { get; private set; } - public bool Disabled { get; private set; } + public bool Disabled { get; set; } public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } } public bool Ready { get { return Active && RemainingTime == 0; } } diff --git a/OpenRA.Mods.RA/TraitsInterfaces.cs b/OpenRA.Mods.RA/TraitsInterfaces.cs index 63c088db17..0e166c14ff 100755 --- a/OpenRA.Mods.RA/TraitsInterfaces.cs +++ b/OpenRA.Mods.RA/TraitsInterfaces.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA void PrerequisitesAvailable(string key); void PrerequisitesUnavailable(string key); void PrerequisitesItemHidden(string key); - void PrerequisitesItemVisable(string key); + void PrerequisitesItemVisible(string key); } public interface ITechTreePrerequisite diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index f1d7b2fe18..db6f99be28 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -985,7 +985,6 @@ AFLD: ChargeTime: 360 Description: Paratroopers LongDesc: A Badger drops a squad of infantry\nanywhere on the map. - Prerequisites: AFLD DropItems: E1,E1,E1,E3,E3 SelectTargetSound: slcttgt1.aud ProductionBar: