diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 5e591a39f3..8fdbd6bb77 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -102,6 +102,7 @@ + diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPowerChargeBar.cs b/OpenRA.Mods.RA/SupportPowers/SupportPowerChargeBar.cs new file mode 100644 index 0000000000..073c0e11e6 --- /dev/null +++ b/OpenRA.Mods.RA/SupportPowers/SupportPowerChargeBar.cs @@ -0,0 +1,43 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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.Drawing; +using System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + class SupportPowerChargeBarInfo : ITraitInfo + { + public object Create(ActorInitializer init) { return new SupportPowerChargeBar(init.self); } + } + + class SupportPowerChargeBar : ISelectionBar + { + Actor self; + public SupportPowerChargeBar(Actor self) { this.self = self; } + + public float GetValue() + { + // only people we like should see our charge status. + if (self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] != Stance.Ally) + return 0; + + var spm = self.Owner.PlayerActor.Trait(); + var power = spm.GetPowersForActor(self).FirstOrDefault(sp => !sp.Disabled); + + if (power == null) return 0; + + return 1 - (float)power.RemainingTime / power.TotalTime; + } + + public Color GetColor() { return Color.Magenta; } + } +} diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs index 21a912215d..f85949f1da 100755 --- a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs @@ -34,6 +34,11 @@ namespace OpenRA.Mods.RA init.world.ActorAdded += ActorAdded; init.world.ActorRemoved += ActorRemoved; + } + + static string MakeKey(SupportPower sp) + { + return sp.Info.AllowMultiple ? sp.Info.OrderName + "_" + sp.self.ActorID : sp.Info.OrderName; } void ActorAdded(Actor a) @@ -42,8 +47,8 @@ namespace OpenRA.Mods.RA return; foreach (var t in a.TraitsImplementing()) - { - var key = (t.Info.AllowMultiple) ? t.Info.OrderName+"_"+a.ActorID : t.Info.OrderName; + { + var key = MakeKey(t); if (Powers.ContainsKey(key)) { @@ -69,8 +74,8 @@ namespace OpenRA.Mods.RA return; foreach (var t in a.TraitsImplementing()) - { - var key = (t.Info.AllowMultiple) ? t.Info.OrderName+"_"+a.ActorID : t.Info.OrderName; + { + var key = MakeKey(t); Powers[key].Instances.Remove(t); if (Powers[key].Instances.Count == 0 && !Powers[key].Disabled) Powers.Remove(key); @@ -94,6 +99,17 @@ namespace OpenRA.Mods.RA { if (Powers.ContainsKey(key)) Powers[key].Target(); + } + + static readonly SupportPowerInstance[] NoInstances; + + public IEnumerable GetPowersForActor(Actor a) + { + if (a.Owner != self.Owner || !a.HasTrait()) + return NoInstances; + + return a.TraitsImplementing() + .Select(t => Powers[MakeKey(t)]); } public class SupportPowerInstance diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 0afd5de438..c50ad2c105 100755 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -35,6 +35,8 @@ MSLO: SpawnOffset: 10,0 CanPowerDown: RequiresPower: + SupportPowerChargeBar: + GAP: RequiresPower: CanPowerDown: @@ -211,6 +213,7 @@ IRON: SelectTargetSound: slcttgt1.aud BeginChargeSound: ironchg1.aud EndChargeSound: ironrdy1.aud + SupportPowerChargeBar: PDOX: RequiresPower: @@ -250,6 +253,7 @@ PDOX: EndChargeSound: chrordy1.aud Duration: 30 KillCargo: yes + SupportPowerChargeBar: TSLA: RequiresPower: @@ -546,6 +550,7 @@ ATEK: LongDesc: Reveals the entire map RevealDelay: 15 LaunchSound: satlnch1.aud + SupportPowerChargeBar: WEAP: Inherits: ^Building @@ -770,6 +775,7 @@ AFLD: DropItems: E1,E1,E1,E3,E3 SelectTargetSound: slcttgt1.aud ProductionBar: + SupportPowerChargeBar: POWR: Inherits: ^Building