From e33c783fc1fa8f31f04b1226b14d601e649adb51 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:48:16 +1300 Subject: [PATCH] Ditto for GpsDot. --- OpenRA.Mods.RA/Effects/GpsDot.cs | 69 ++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs index 5517341fd4..7b63f440dc 100644 --- a/OpenRA.Mods.RA/Effects/GpsDot.cs +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -15,65 +15,76 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Effects { - class GpsDotInfo : ITraitInfo, Requires + class GpsDotInfo : ITraitInfo { public readonly string String = "Infantry"; + public readonly string IndicatorPalettePrefix = "player"; + public object Create(ActorInitializer init) { - return new GpsDot(init, String); + return new GpsDot(init.self, this); } } class GpsDot : IEffect { Actor self; - GpsWatcher watcher; - RenderSimple rs; - bool show = false; + GpsDotInfo info; Animation anim; - public GpsDot(ActorInitializer init, string s) - { - anim = new Animation("gpsdot"); - anim.PlayRepeating(s); + GpsWatcher watcher; + HiddenUnderFog huf; + Spy spy; + bool show = false; + + public GpsDot(Actor self, GpsDotInfo info) + { + this.self = self; + this.info = info; + anim = new Animation("gpsdot"); + anim.PlayRepeating(info.String); - self = init.self; - rs = self.Trait(); self.World.AddFrameEndTask(w => w.Add(this)); - if(self.World.LocalPlayer != null) + if (self.World.LocalPlayer != null) watcher = self.World.LocalPlayer.PlayerActor.Trait(); } + bool firstTick = true; public void Tick(World world) { - show = false; - if (self.Destroyed) world.AddFrameEndTask(w => w.Remove(this)); - if (world.LocalPlayer == null) + if (world.LocalPlayer == null || !self.IsInWorld || self.Destroyed) return; - if ( - self.IsInWorld - && (watcher.Granted || watcher.GrantedAllies) - && !self.Trait().IsVisible(self.World.RenderedShroud, self) // WRONG - && (!self.HasTrait() || !self.Trait().Cloaked) - && (!self.HasTrait() || !self.Trait().Disguised) - ) + // Can be granted at runtime via a crate, so can't cache + var cloak = self.TraitOrDefault(); + + if (firstTick) { - show = true; + huf = self.TraitOrDefault(); + spy = self.TraitOrDefault(); + firstTick = false; } + + var hasGps = (watcher != null && (watcher.Granted || watcher.GrantedAllies)); + var hasDot = (huf != null && !huf.IsVisible(self.World.RenderedShroud, self)); // WRONG (why?) + var dotHidden = (cloak != null && cloak.Cloaked) || (spy != null && spy.Disguised); + + show = hasGps && hasDot && !dotHidden; } public IEnumerable Render(WorldRenderer wr) { - if (show && !self.Destroyed) - { - var p = self.CenterLocation; - yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner, wr), p.Y) - .WithScale(1.5f); - } + if (!show || self.Destroyed) + yield break; + + var p = self.CenterLocation; + var palette = wr.Palette(info.IndicatorPalettePrefix+self.Owner.InternalName); + yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, palette, p.Y) + .WithScale(1.5f); + } } }