From 86b0ee8c9776d9cc37c1375b0945302bf9ecf51c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 9 Jan 2010 00:21:39 +1300 Subject: [PATCH] Iron curtain power implementation; Remove AutoActivate attribute to be part of the GPS implementation --- OpenRa.Game/Chrome.cs | 38 ---------------- OpenRa.Game/GameRules/SupportPowerInfo.cs | 1 - OpenRa.Game/OpenRa.Game.csproj | 1 + .../Orders/IronCurtainOrderGenerator.cs | 11 ++++- OpenRa.Game/Orders/Order.cs | 14 ++++++ OpenRa.Game/SupportPower.cs | 20 +++++++-- OpenRa.Game/SupportPowers/GpsSatellite.cs | 10 ++++- .../SupportPowers/ISupportPowerImpl.cs | 3 ++ OpenRa.Game/SupportPowers/IronCurtainPower.cs | 43 +++++++++++++++++++ OpenRa.Game/SupportPowers/NullPower.cs | 3 ++ OpenRa.Game/Traits/IronCurtainable.cs | 9 +--- units.ini | 3 +- 12 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 OpenRa.Game/SupportPowers/IronCurtainPower.cs diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 2966536c79..006e3a9b0d 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -320,32 +320,6 @@ namespace OpenRa.Game void DrawButtons() { - // Chronoshift - Rectangle chronoshiftRect = new Rectangle(6, 14, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height); - var chronoshiftDrawPos = Game.viewport.Location + new float2(chronoshiftRect.Location); - - var hasChronosphere = Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains()); - - if (!hasChronosphere) - repairButton.ReplaceAnim("disabled"); - else - AddButton(chronoshiftRect, isLmb => HandleChronosphereButton()); - - buildPaletteRenderer.DrawSprite(repairButton.Image, chronoshiftDrawPos, PaletteType.Chrome); - - // Iron Curtain - Rectangle curtainRect = new Rectangle(6, 14+50, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height); - var curtainDrawPos = Game.viewport.Location + new float2(curtainRect.Location); - - var hasCurtain = Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains()); - - if (!hasCurtain) - repairButton.ReplaceAnim("disabled"); - else - AddButton(curtainRect, isLmb => HandleIronCurtainButton()); - - buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome); - // Repair Rectangle repairRect = new Rectangle(Game.viewport.Width - 120, 5, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height); var repairDrawPos = Game.viewport.Location + new float2(repairRect.Location); @@ -435,18 +409,6 @@ namespace OpenRa.Game } } - void HandleChronosphereButton() - { - if (Game.controller.ToggleInputMode()) - Sound.Play("slcttgt1.aud"); - } - - void HandleIronCurtainButton() - { - if (Game.controller.ToggleInputMode()) - Sound.Play("slcttgt1.aud"); - } - void DrawChat() { var chatpos = new int2(400, Game.viewport.Height - 20); diff --git a/OpenRa.Game/GameRules/SupportPowerInfo.cs b/OpenRa.Game/GameRules/SupportPowerInfo.cs index 0f6192c8cd..2a84d600ba 100644 --- a/OpenRa.Game/GameRules/SupportPowerInfo.cs +++ b/OpenRa.Game/GameRules/SupportPowerInfo.cs @@ -17,6 +17,5 @@ namespace OpenRa.Game.GameRules public readonly int TechLevel = -1; public readonly bool GivenAuto = true; public readonly string Impl = null; - public readonly bool AutoActivate = false; } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 15182d690a..876f551722 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -123,6 +123,7 @@ + diff --git a/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs b/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs index d73c787f19..286fef488b 100644 --- a/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs +++ b/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs @@ -4,11 +4,17 @@ using System.Linq; using System.Text; using OpenRa.Game.GameRules; using OpenRa.Game.Traits; - +using OpenRa.Game.SupportPowers; namespace OpenRa.Game.Orders { class IronCurtainOrderGenerator : IOrderGenerator { + ISupportPowerImpl power; + public IronCurtainOrderGenerator(ISupportPowerImpl power) + { + this.power = power; + } + public IEnumerable Order(int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) @@ -31,7 +37,8 @@ namespace OpenRa.Game.Orders if (unit != null) { - yield return new Order("IronCurtain", underCursor, null, int2.Zero, null); + yield return new Order("IronCurtain", underCursor, this.power); + //yield return new Order("IronCurtain", underCursor, null, int2.Zero, null); } } } diff --git a/OpenRa.Game/Orders/Order.cs b/OpenRa.Game/Orders/Order.cs index c2d25713bc..6caa67148d 100644 --- a/OpenRa.Game/Orders/Order.cs +++ b/OpenRa.Game/Orders/Order.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using OpenRa.Game.SupportPowers; namespace OpenRa.Game { @@ -31,6 +32,19 @@ namespace OpenRa.Game this.TargetLocation = targetLocation; this.TargetString = targetString; } + // This is a hack - fix me + public readonly ISupportPowerImpl Power; + public Order(string orderString, Actor subject, ISupportPowerImpl power) + { + this.OrderString = orderString; + this.SubjectId = UIntFromActor( subject ); + + this.Power = power; + + this.TargetActorId = UIntFromActor(null); + this.TargetLocation = int2.Zero; + this.TargetString = null; + } public bool Validate() { diff --git a/OpenRa.Game/SupportPower.cs b/OpenRa.Game/SupportPower.cs index 3f8bab86a6..9ae79fecbf 100644 --- a/OpenRa.Game/SupportPower.cs +++ b/OpenRa.Game/SupportPower.cs @@ -37,7 +37,9 @@ namespace OpenRa.Game public bool IsDone { get { return RemainingTime == 0; } } public int RemainingTime { get; private set; } public int TotalTime { get; private set; } - + bool notifiedReady = false; + bool notifiedCharging = false; + public void Tick() { if (Info.OneShot && IsUsed) @@ -59,10 +61,20 @@ namespace OpenRa.Game if (IsAvailable && (!Info.Powered || Owner.GetPowerState() == PowerState.Normal)) { if (RemainingTime > 0) --RemainingTime; + if (!notifiedCharging) + { + Impl.IsChargingNotification(this); + notifiedCharging = true; + } } - if (RemainingTime == 0 && Info.AutoActivate) - Activate(); + if (RemainingTime == 0 + && Impl != null + && !notifiedReady) + { + Impl.IsReadyNotification(this); + notifiedReady = true; + } } public void Activate() @@ -79,6 +91,8 @@ namespace OpenRa.Game IsAvailable = false; } RemainingTime = TotalTime; + notifiedReady = false; + notifiedCharging = false; } public void Give(bool requireCharge) // called by crate/spy/etc code diff --git a/OpenRa.Game/SupportPowers/GpsSatellite.cs b/OpenRa.Game/SupportPowers/GpsSatellite.cs index a40f959de1..6e072ac2c0 100644 --- a/OpenRa.Game/SupportPowers/GpsSatellite.cs +++ b/OpenRa.Game/SupportPowers/GpsSatellite.cs @@ -8,8 +8,16 @@ namespace OpenRa.Game.SupportPowers { class GpsSatellite : ISupportPowerImpl { - const int revealDelay = 30 * 25; + const int revealDelay = 15 * 25; + public void OnFireNotification(Actor a, int2 xy) { } + public void IsChargingNotification(SupportPower p) { } + public void IsReadyNotification(SupportPower p) + { + // Power is auto-activated + Activate(p); + } + public void Activate(SupportPower p) { var launchSite = Game.world.Actors diff --git a/OpenRa.Game/SupportPowers/ISupportPowerImpl.cs b/OpenRa.Game/SupportPowers/ISupportPowerImpl.cs index b8831e63c2..b1ef896690 100644 --- a/OpenRa.Game/SupportPowers/ISupportPowerImpl.cs +++ b/OpenRa.Game/SupportPowers/ISupportPowerImpl.cs @@ -8,5 +8,8 @@ namespace OpenRa.Game.SupportPowers interface ISupportPowerImpl { void Activate(SupportPower p); + void OnFireNotification(Actor target, int2 xy); + void IsChargingNotification(SupportPower p); + void IsReadyNotification(SupportPower p); } } diff --git a/OpenRa.Game/SupportPowers/IronCurtainPower.cs b/OpenRa.Game/SupportPowers/IronCurtainPower.cs new file mode 100644 index 0000000000..67bb0b5c6d --- /dev/null +++ b/OpenRa.Game/SupportPowers/IronCurtainPower.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using OpenRa.Game.Orders; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.SupportPowers +{ + class IronCurtainPower : ISupportPowerImpl + { + public void IsReadyNotification(SupportPower p) + { + Sound.Play("ironrdy1.aud"); + } + + public void IsChargingNotification(SupportPower p) + { + Sound.Play("ironchg1.aud"); + } + + public void OnFireNotification(Actor target, int2 xy) + { + p.FinishActivate(); + Game.controller.CancelInputMode(); + Sound.Play("ironcur9.aud"); + + // Play active anim + var ironCurtain = Game.world.Actors + .Where(a => a.Owner == p.Owner && a.traits.Contains()) + .FirstOrDefault(); + if (ironCurtain != null) + ironCurtain.traits.Get().PlayCustomAnim(ironCurtain, "active"); + } + SupportPower p; + public void Activate(SupportPower p) + { + this.p = p; + // Pick a building to use + Game.controller.orderGenerator = new IronCurtainOrderGenerator(this); + Sound.Play("slcttgt1.aud"); + } + } +} diff --git a/OpenRa.Game/SupportPowers/NullPower.cs b/OpenRa.Game/SupportPowers/NullPower.cs index dadb23b5bd..57f76dc60d 100644 --- a/OpenRa.Game/SupportPowers/NullPower.cs +++ b/OpenRa.Game/SupportPowers/NullPower.cs @@ -7,6 +7,9 @@ namespace OpenRa.Game.SupportPowers { class NullPower : ISupportPowerImpl { + public void OnFireNotification(Actor a, int2 xy) { } + public void IsReadyNotification(SupportPower p) { } + public void IsChargingNotification(SupportPower p) { } public void Activate(SupportPower p) { // if this was a real power, i'd do something here! diff --git a/OpenRa.Game/Traits/IronCurtainable.cs b/OpenRa.Game/Traits/IronCurtainable.cs index 84374c0a57..e49ace50a3 100644 --- a/OpenRa.Game/Traits/IronCurtainable.cs +++ b/OpenRa.Game/Traits/IronCurtainable.cs @@ -28,16 +28,9 @@ namespace OpenRa.Game.Traits { if (order.OrderString == "IronCurtain") { - Game.controller.CancelInputMode(); + order.Power.OnFireNotification(self, self.Location); Game.world.AddFrameEndTask(w => w.Add(new InvulnEffect(self))); RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25); - Sound.Play("ironcur9.aud"); - // Play active anim - var ironCurtain = Game.world.Actors - .Where(a => a.Owner == order.Subject.Owner && a.traits.Contains()) - .FirstOrDefault(); - if (ironCurtain != null) - ironCurtain.traits.Get().PlayCustomAnim(ironCurtain, "active"); } } } diff --git a/units.ini b/units.ini index abbdf16043..43af439a17 100644 --- a/units.ini +++ b/units.ini @@ -890,7 +890,6 @@ Prerequisite=ATEK Image=gpssicon TechLevel=12 Impl=GpsSatellite -AutoActivate=yes [InvulnerabilityPower] ; the point of IRON ChargeTime=11 @@ -899,4 +898,4 @@ LongDesc=Makes a single unit invulnerable for a \nshort time. Image=infxicon Prerequisite=IRON TechLevel=12 -Impl=NullPower \ No newline at end of file +Impl=IronCurtainPower \ No newline at end of file