Add range support to Fly.

This commit is contained in:
Paul Chote
2014-01-16 22:40:28 +13:00
parent 4eaaa052cc
commit db9ebd4a61
2 changed files with 21 additions and 5 deletions

View File

@@ -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<Plane>();
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<Target> GetTargets(Actor self)
{
yield return Target.FromPos(pos);
yield return target;
}
}
}

View File

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