From e92ccdf8086d2d5389aafe857d7da83275993255 Mon Sep 17 00:00:00 2001 From: Huw Pascoe Date: Sat, 14 Nov 2015 22:05:22 +0000 Subject: [PATCH] TargetLine for Rally Points Also enabled allied players to see waypoints. --- .../Effects/RallyPointIndicator.cs | 48 ++++++++++++++++--- .../Traits/Buildings/RallyPoint.cs | 9 +++- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs index 0c3ac93922..940685bcc9 100644 --- a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs +++ b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs @@ -22,11 +22,16 @@ namespace OpenRA.Mods.Common.Effects readonly RallyPoint rp; readonly Animation flag; readonly Animation circles; + readonly ExitInfo[] exits; - public RallyPointIndicator(Actor building, RallyPoint rp) + readonly WPos[] targetLine = new WPos[2]; + CPos cachedLocation; + + public RallyPointIndicator(Actor building, RallyPoint rp, ExitInfo[] exits) { this.building = building; this.rp = rp; + this.exits = exits; flag = new Animation(building.World, rp.Info.Image); flag.PlayRepeating(rp.Info.FlagSequence); @@ -35,7 +40,6 @@ namespace OpenRA.Mods.Common.Effects circles.Play(rp.Info.CirclesSequence); } - CPos cachedLocation; public void Tick(World world) { flag.Tick(); @@ -44,6 +48,26 @@ namespace OpenRA.Mods.Common.Effects if (cachedLocation != rp.Location) { cachedLocation = rp.Location; + + var rallyPos = world.Map.CenterOfCell(cachedLocation); + var exitPos = building.CenterPosition; + + // Find closest exit + var dist = int.MaxValue; + foreach (var exit in exits) + { + var ep = building.CenterPosition + exit.SpawnOffset; + var len = (rallyPos - ep).Length; + if (len < dist) + { + dist = len; + exitPos = ep; + } + } + + targetLine[0] = exitPos; + targetLine[1] = rallyPos; + circles.Play(rp.Info.CirclesSequence); } @@ -53,15 +77,27 @@ namespace OpenRA.Mods.Common.Effects public IEnumerable Render(WorldRenderer wr) { - if (building.Owner != building.World.LocalPlayer) + if (!building.IsInWorld || !building.Owner.IsAlliedWith(building.World.LocalPlayer)) return SpriteRenderable.None; - if (!building.IsInWorld || !building.World.Selection.Actors.Contains(building)) + if (!building.World.Selection.Actors.Contains(building)) return SpriteRenderable.None; - var pos = wr.World.Map.CenterOfCell(cachedLocation); + return RenderInner(wr); + } + + IEnumerable RenderInner(WorldRenderer wr) + { var palette = wr.Palette(rp.PaletteName); - return circles.Render(pos, palette).Concat(flag.Render(pos, palette)); + + if (Game.Settings.Game.DrawTargetLine) + yield return new TargetLineRenderable(targetLine, building.Owner.Color.RGB); + + foreach (var r in circles.Render(targetLine[1], palette)) + yield return r; + + foreach (var r in flag.Render(targetLine[1], palette)) + yield return r; } } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs index 9cd6e19aba..45e907578f 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Mods.Common.Effects; using OpenRA.Traits; @@ -32,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new RallyPoint(init.Self, this); } } - public class RallyPoint : IIssueOrder, IResolveOrder, ISync, INotifyOwnerChanged + public class RallyPoint : IIssueOrder, IResolveOrder, ISync, INotifyOwnerChanged, INotifyCreated { [Sync] public CPos Location; public RallyPointInfo Info; @@ -48,7 +49,11 @@ namespace OpenRA.Mods.Common.Traits Info = info; ResetLocation(self); PaletteName = info.IsPlayerPalette ? info.Palette + self.Owner.InternalName : info.Palette; - self.World.Add(new RallyPointIndicator(self, this)); + } + + public void Created(Actor self) + { + self.World.Add(new RallyPointIndicator(self, this, self.Info.TraitInfos().ToArray())); } public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)