TargetLine for Rally Points

Also enabled allied players to see waypoints.
This commit is contained in:
Huw Pascoe
2015-11-14 22:05:22 +00:00
parent bacac082cc
commit e92ccdf808
2 changed files with 49 additions and 8 deletions

View File

@@ -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<IRenderable> 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<IRenderable> 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;
}
}
}