From db9ebd4a617186a6f3177894c77e3d684185d302 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 16 Jan 2014 22:40:28 +1300 Subject: [PATCH] Add range support to Fly. --- OpenRA.Mods.RA/Air/Fly.cs | 23 +++++++++++++++++++---- OpenRA.Mods.RA/Air/Plane.cs | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.RA/Air/Fly.cs b/OpenRA.Mods.RA/Air/Fly.cs index 3dc05ccf67..00932de85d 100755 --- a/OpenRA.Mods.RA/Air/Fly.cs +++ b/OpenRA.Mods.RA/Air/Fly.cs @@ -15,13 +15,22 @@ namespace OpenRA.Mods.RA.Air { public class Fly : Activity { - readonly WPos pos; readonly Plane plane; + readonly Target target; + readonly WRange maxRange; + readonly WRange minRange; public Fly(Actor self, Target t) { plane = self.Trait(); - pos = t.CenterPosition; + target = t; + } + + public Fly(Actor self, Target t, WRange minRange, WRange maxRange) + : this(self, t) + { + this.maxRange = maxRange; + this.minRange = minRange; } public static void FlyToward(Actor self, Plane plane, int desiredFacing, WRange desiredAltitude) @@ -46,8 +55,14 @@ namespace OpenRA.Mods.RA.Air if (IsCanceled) return NextActivity; + // Inside the target annulus, so we're done + var insideMaxRange = maxRange.Range > 0 && target.IsInRange(plane.CenterPosition, maxRange); + var insideMinRange = minRange.Range > 0 && target.IsInRange(plane.CenterPosition, minRange); + if (insideMaxRange && !insideMinRange) + return NextActivity; + // Close enough (ported from old code which checked length against sqrt(50) px) - var d = pos - self.CenterPosition; + var d = target.CenterPosition - self.CenterPosition; if (d.HorizontalLengthSquared < 91022) return NextActivity; @@ -64,7 +79,7 @@ namespace OpenRA.Mods.RA.Air public override IEnumerable GetTargets(Actor self) { - yield return Target.FromPos(pos); + yield return target; } } } diff --git a/OpenRA.Mods.RA/Air/Plane.cs b/OpenRA.Mods.RA/Air/Plane.cs index d74032880b..5a2ed916b0 100755 --- a/OpenRA.Mods.RA/Air/Plane.cs +++ b/OpenRA.Mods.RA/Air/Plane.cs @@ -94,7 +94,8 @@ namespace OpenRA.Mods.RA.Air public Activity MoveTo(CPos cell, int nearEnough) { return new Fly(self, Target.FromCell(cell)); } public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Fly(self, Target.FromCell(cell)); } - public Activity MoveWithinRange(Target target, WRange range) { return new Fly(self, target); } + public Activity MoveWithinRange(Target target, WRange range) { return new Fly(self, target, WRange.Zero, range); } + public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new Fly(self, target, minRange, maxRange); } public CPos NearestMoveableCell(CPos cell) { return cell; } } }