Add WVec.HorizontalLengthSquared to simplify range checks.
This commit is contained in:
@@ -38,6 +38,7 @@ namespace OpenRA
|
|||||||
public static int Dot(WVec a, WVec b) { return a.X * b.X + a.Y * b.Y + a.Z * b.Z; }
|
public static int Dot(WVec a, WVec b) { return a.X * b.X + a.Y * b.Y + a.Z * b.Z; }
|
||||||
public long LengthSquared { get { return (long)X * X + (long)Y * Y + (long)Z * Z; } }
|
public long LengthSquared { get { return (long)X * X + (long)Y * Y + (long)Z * Z; } }
|
||||||
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
|
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
|
||||||
|
public long HorizontalLengthSquared { get { return (long)X * X + (long)Y * Y; } }
|
||||||
|
|
||||||
public WVec Rotate(WRot rot)
|
public WVec Rotate(WRot rot)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,12 +91,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
// Target ranges are calculated in 2D, so ignore height differences
|
// Target ranges are calculated in 2D, so ignore height differences
|
||||||
var rangeSquared = range.Range*range.Range;
|
var rangeSquared = range.Range*range.Range;
|
||||||
return Positions.Any(t =>
|
return Positions.Any(t => (t - origin).HorizontalLengthSquared <= rangeSquared);
|
||||||
{
|
|
||||||
var dx = (long)(t.X - origin.X);
|
|
||||||
var dy = (long)(t.Y - origin.Y);
|
|
||||||
return dx*dx + dy*dy <= rangeSquared;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,19 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
if (!Target.IsValid)
|
if (!Target.IsValid)
|
||||||
Cancel(self);
|
Cancel(self);
|
||||||
|
|
||||||
if (IsCanceled) return NextActivity;
|
if (IsCanceled)
|
||||||
|
|
||||||
var d = Target.CenterPosition - self.CenterPosition;
|
|
||||||
if (d.LengthSquared < 256*256) // close enough (1/4 cell)
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var aircraft = self.Trait<Aircraft>();
|
var aircraft = self.Trait<Aircraft>();
|
||||||
|
var d = Target.CenterPosition - self.CenterPosition;
|
||||||
|
|
||||||
|
// close enough (1/16 cell)
|
||||||
|
// TODO: TickMove may overshoot if the aircraft speed is too high
|
||||||
|
if (d.HorizontalLengthSquared < 4096)
|
||||||
|
{
|
||||||
|
aircraft.SetPxPosition(self, PPos.FromWPos(Target.CenterPosition));
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (aircraft.Altitude > 0)
|
if (aircraft.Altitude > 0)
|
||||||
--aircraft.Altitude;
|
--aircraft.Altitude;
|
||||||
|
|||||||
Reference in New Issue
Block a user