Add range support to Fly.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user