Let cloaked units optionally uncloak when unloading

This commit is contained in:
ScottNZ
2014-03-10 20:54:22 +13:00
parent 9f69d13336
commit f80710ac7a
2 changed files with 15 additions and 9 deletions

View File

@@ -20,12 +20,14 @@ namespace OpenRA.Mods.RA.Activities
{ {
readonly Actor self; readonly Actor self;
readonly Cargo cargo; readonly Cargo cargo;
readonly Cloak cloak;
readonly bool unloadAll; readonly bool unloadAll;
public UnloadCargo(Actor self, bool unloadAll) public UnloadCargo(Actor self, bool unloadAll)
{ {
this.self = self; this.self = self;
cargo = self.Trait<Cargo>(); cargo = self.Trait<Cargo>();
cloak = self.TraitOrDefault<Cloak>();
this.unloadAll = unloadAll; this.unloadAll = unloadAll;
} }
@@ -52,6 +54,9 @@ namespace OpenRA.Mods.RA.Activities
if (IsCanceled || cargo.IsEmpty(self)) if (IsCanceled || cargo.IsEmpty(self))
return NextActivity; return NextActivity;
if (cloak != null && cloak.Info.UncloakOnUnload)
cloak.Uncloak();
var actor = cargo.Peek(self); var actor = cargo.Peek(self);
var exitCell = ChooseExitCell(actor); var exitCell = ChooseExitCell(actor);

View File

@@ -22,6 +22,7 @@ namespace OpenRA.Mods.RA
public readonly int InitialDelay = 10; // Ticks public readonly int InitialDelay = 10; // Ticks
public readonly int CloakDelay = 30; // Ticks public readonly int CloakDelay = 30; // Ticks
public readonly bool UncloakOnMove = false; public readonly bool UncloakOnMove = false;
public readonly bool UncloakOnUnload = false;
public readonly bool RequiresCrate = false; public readonly bool RequiresCrate = false;
public readonly string CloakSound = null; public readonly string CloakSound = null;
@@ -38,24 +39,24 @@ namespace OpenRA.Mods.RA
[Sync] bool crateDisabled; [Sync] bool crateDisabled;
Actor self; Actor self;
CloakInfo info; public readonly CloakInfo Info;
CPos? lastPos; CPos? lastPos;
public Cloak(Actor self, CloakInfo info) public Cloak(Actor self, CloakInfo info)
{ {
this.info = info;
this.self = self; this.self = self;
Info = info;
remainingTime = info.InitialDelay; remainingTime = info.InitialDelay;
crateDisabled = info.RequiresCrate; crateDisabled = info.RequiresCrate;
} }
public void Uncloak() { Uncloak(info.CloakDelay); } public void Uncloak() { Uncloak(Info.CloakDelay); }
public void Uncloak(int time) public void Uncloak(int time)
{ {
if (Cloaked) if (Cloaked)
Sound.Play(info.UncloakSound, self.CenterPosition); Sound.Play(Info.UncloakSound, self.CenterPosition);
remainingTime = Math.Max(remainingTime, time); remainingTime = Math.Max(remainingTime, time);
} }
@@ -77,10 +78,10 @@ namespace OpenRA.Mods.RA
return r; return r;
if (Cloaked && IsVisible(self, self.World.RenderPlayer)) if (Cloaked && IsVisible(self, self.World.RenderPlayer))
if (string.IsNullOrEmpty(info.Palette)) if (string.IsNullOrEmpty(Info.Palette))
return r; return r;
else else
return r.Select(a => a.WithPalette(wr.Palette(info.Palette))); return r.Select(a => a.WithPalette(wr.Palette(Info.Palette)));
else else
return SpriteRenderable.None; return SpriteRenderable.None;
} }
@@ -90,13 +91,13 @@ namespace OpenRA.Mods.RA
if (remainingTime > 0 && !crateDisabled && !damageDisabled && --remainingTime <= 0) if (remainingTime > 0 && !crateDisabled && !damageDisabled && --remainingTime <= 0)
{ {
self.Generation++; self.Generation++;
Sound.Play(info.CloakSound, self.CenterPosition); Sound.Play(Info.CloakSound, self.CenterPosition);
} }
if (self.IsDisabled()) if (self.IsDisabled())
Uncloak(); Uncloak();
if (info.UncloakOnMove && (lastPos == null || lastPos.Value != self.Location)) if (Info.UncloakOnMove && (lastPos == null || lastPos.Value != self.Location))
{ {
Uncloak(); Uncloak();
lastPos = self.Location; lastPos = self.Location;
@@ -121,7 +122,7 @@ namespace OpenRA.Mods.RA
return c; return c;
} }
public bool AcceptsCloakCrate { get { return info.RequiresCrate && crateDisabled; } } public bool AcceptsCloakCrate { get { return Info.RequiresCrate && crateDisabled; } }
public void ReceivedCloakCrate(Actor self) public void ReceivedCloakCrate(Actor self)
{ {