Merge pull request #9994 from huwpascoe/rally
TargetLine for Rally Points
This commit is contained in:
@@ -22,11 +22,16 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
readonly RallyPoint rp;
|
readonly RallyPoint rp;
|
||||||
readonly Animation flag;
|
readonly Animation flag;
|
||||||
readonly Animation circles;
|
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.building = building;
|
||||||
this.rp = rp;
|
this.rp = rp;
|
||||||
|
this.exits = exits;
|
||||||
|
|
||||||
flag = new Animation(building.World, rp.Info.Image);
|
flag = new Animation(building.World, rp.Info.Image);
|
||||||
flag.PlayRepeating(rp.Info.FlagSequence);
|
flag.PlayRepeating(rp.Info.FlagSequence);
|
||||||
@@ -35,7 +40,6 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
circles.Play(rp.Info.CirclesSequence);
|
circles.Play(rp.Info.CirclesSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos cachedLocation;
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
flag.Tick();
|
flag.Tick();
|
||||||
@@ -44,6 +48,26 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
if (cachedLocation != rp.Location)
|
if (cachedLocation != rp.Location)
|
||||||
{
|
{
|
||||||
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);
|
circles.Play(rp.Info.CirclesSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,15 +77,27 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (building.Owner != building.World.LocalPlayer)
|
if (!building.IsInWorld || !building.Owner.IsAlliedWith(building.World.LocalPlayer))
|
||||||
return SpriteRenderable.None;
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
if (!building.IsInWorld || !building.World.Selection.Actors.Contains(building))
|
if (!building.World.Selection.Actors.Contains(building))
|
||||||
return SpriteRenderable.None;
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
var pos = wr.World.Map.CenterOfCell(cachedLocation);
|
return RenderInner(wr);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<IRenderable> RenderInner(WorldRenderer wr)
|
||||||
|
{
|
||||||
var palette = wr.Palette(rp.PaletteName);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new RallyPoint(init.Self, this); }
|
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;
|
[Sync] public CPos Location;
|
||||||
public RallyPointInfo Info;
|
public RallyPointInfo Info;
|
||||||
@@ -48,7 +49,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Info = info;
|
Info = info;
|
||||||
ResetLocation(self);
|
ResetLocation(self);
|
||||||
PaletteName = info.IsPlayerPalette ? info.Palette + self.Owner.InternalName : info.Palette;
|
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<ExitInfo>().ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
|||||||
Reference in New Issue
Block a user