From f80710ac7a40a1a9a08bbabefaff4aa34355ddf9 Mon Sep 17 00:00:00 2001 From: ScottNZ Date: Mon, 10 Mar 2014 20:54:22 +1300 Subject: [PATCH] Let cloaked units optionally uncloak when unloading --- OpenRA.Mods.RA/Activities/UnloadCargo.cs | 5 +++++ OpenRA.Mods.RA/Cloak.cs | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/UnloadCargo.cs b/OpenRA.Mods.RA/Activities/UnloadCargo.cs index 40ca5f011c..81a5be6796 100644 --- a/OpenRA.Mods.RA/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.RA/Activities/UnloadCargo.cs @@ -20,12 +20,14 @@ namespace OpenRA.Mods.RA.Activities { readonly Actor self; readonly Cargo cargo; + readonly Cloak cloak; readonly bool unloadAll; public UnloadCargo(Actor self, bool unloadAll) { this.self = self; cargo = self.Trait(); + cloak = self.TraitOrDefault(); this.unloadAll = unloadAll; } @@ -52,6 +54,9 @@ namespace OpenRA.Mods.RA.Activities if (IsCanceled || cargo.IsEmpty(self)) return NextActivity; + if (cloak != null && cloak.Info.UncloakOnUnload) + cloak.Uncloak(); + var actor = cargo.Peek(self); var exitCell = ChooseExitCell(actor); diff --git a/OpenRA.Mods.RA/Cloak.cs b/OpenRA.Mods.RA/Cloak.cs index c1dd4b1449..59ed7ec97d 100644 --- a/OpenRA.Mods.RA/Cloak.cs +++ b/OpenRA.Mods.RA/Cloak.cs @@ -22,6 +22,7 @@ namespace OpenRA.Mods.RA public readonly int InitialDelay = 10; // Ticks public readonly int CloakDelay = 30; // Ticks public readonly bool UncloakOnMove = false; + public readonly bool UncloakOnUnload = false; public readonly bool RequiresCrate = false; public readonly string CloakSound = null; @@ -38,24 +39,24 @@ namespace OpenRA.Mods.RA [Sync] bool crateDisabled; Actor self; - CloakInfo info; + public readonly CloakInfo Info; CPos? lastPos; public Cloak(Actor self, CloakInfo info) { - this.info = info; this.self = self; + Info = info; remainingTime = info.InitialDelay; crateDisabled = info.RequiresCrate; } - public void Uncloak() { Uncloak(info.CloakDelay); } + public void Uncloak() { Uncloak(Info.CloakDelay); } public void Uncloak(int time) { if (Cloaked) - Sound.Play(info.UncloakSound, self.CenterPosition); + Sound.Play(Info.UncloakSound, self.CenterPosition); remainingTime = Math.Max(remainingTime, time); } @@ -77,10 +78,10 @@ namespace OpenRA.Mods.RA return r; if (Cloaked && IsVisible(self, self.World.RenderPlayer)) - if (string.IsNullOrEmpty(info.Palette)) + if (string.IsNullOrEmpty(Info.Palette)) return r; else - return r.Select(a => a.WithPalette(wr.Palette(info.Palette))); + return r.Select(a => a.WithPalette(wr.Palette(Info.Palette))); else return SpriteRenderable.None; } @@ -90,13 +91,13 @@ namespace OpenRA.Mods.RA if (remainingTime > 0 && !crateDisabled && !damageDisabled && --remainingTime <= 0) { self.Generation++; - Sound.Play(info.CloakSound, self.CenterPosition); + Sound.Play(Info.CloakSound, self.CenterPosition); } if (self.IsDisabled()) Uncloak(); - if (info.UncloakOnMove && (lastPos == null || lastPos.Value != self.Location)) + if (Info.UncloakOnMove && (lastPos == null || lastPos.Value != self.Location)) { Uncloak(); lastPos = self.Location; @@ -121,7 +122,7 @@ namespace OpenRA.Mods.RA return c; } - public bool AcceptsCloakCrate { get { return info.RequiresCrate && crateDisabled; } } + public bool AcceptsCloakCrate { get { return Info.RequiresCrate && crateDisabled; } } public void ReceivedCloakCrate(Actor self) {