Change IFacing.TurnSpeed to WAngle.
This commit is contained in:
@@ -317,7 +317,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public interface IFacing
|
public interface IFacing
|
||||||
{
|
{
|
||||||
int TurnSpeed { get; }
|
WAngle TurnSpeed { get; }
|
||||||
WAngle Facing { get; set; }
|
WAngle Facing { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
|
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
|
||||||
|
|
||||||
// Isn't used anyway
|
// Isn't used anyway
|
||||||
public int TurnSpeed { get { return 255; } }
|
public WAngle TurnSpeed { get { return WAngle.Zero; } }
|
||||||
|
|
||||||
CPos cachedLocation;
|
CPos cachedLocation;
|
||||||
|
|
||||||
|
|||||||
@@ -60,14 +60,14 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
this.minRange = minRange;
|
this.minRange = minRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FlyTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, WVec moveOverride, int turnSpeedOverride = -1)
|
public static void FlyTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, WVec moveOverride, WAngle? turnSpeedOverride = null)
|
||||||
{
|
{
|
||||||
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
|
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
|
||||||
var move = aircraft.Info.CanSlide ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
|
var move = aircraft.Info.CanSlide ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
|
||||||
if (moveOverride != WVec.Zero)
|
if (moveOverride != WVec.Zero)
|
||||||
move = moveOverride;
|
move = moveOverride;
|
||||||
|
|
||||||
var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed;
|
var turnSpeed = turnSpeedOverride ?? aircraft.TurnSpeed;
|
||||||
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed);
|
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed);
|
||||||
|
|
||||||
// Note: we assume that if move.Z is not zero, it's intentional and we want to move in that vertical direction instead of towards desiredAltitude.
|
// Note: we assume that if move.Z is not zero, it's intentional and we want to move in that vertical direction instead of towards desiredAltitude.
|
||||||
@@ -83,18 +83,18 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
aircraft.SetPosition(self, aircraft.CenterPosition + move);
|
aircraft.SetPosition(self, aircraft.CenterPosition + move);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FlyTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, int turnSpeedOverride = -1)
|
public static void FlyTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, WAngle? turnSpeedOverride = null)
|
||||||
{
|
{
|
||||||
FlyTick(self, aircraft, desiredFacing, desiredAltitude, WVec.Zero, turnSpeedOverride);
|
FlyTick(self, aircraft, desiredFacing, desiredAltitude, WVec.Zero, turnSpeedOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should only be used for vertical-only movement, usually VTOL take-off or land. Terrain-induced altitude changes should always be handled by FlyTick.
|
// Should only be used for vertical-only movement, usually VTOL take-off or land. Terrain-induced altitude changes should always be handled by FlyTick.
|
||||||
public static bool VerticalTakeOffOrLandTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, int turnSpeedOverride = -1)
|
public static bool VerticalTakeOffOrLandTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, WAngle? turnSpeedOverride = null)
|
||||||
{
|
{
|
||||||
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
|
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
|
||||||
var move = WVec.Zero;
|
var move = WVec.Zero;
|
||||||
|
|
||||||
var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed;
|
var turnSpeed = turnSpeedOverride ?? aircraft.TurnSpeed;
|
||||||
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed);
|
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed);
|
||||||
|
|
||||||
if (dat != desiredAltitude)
|
if (dat != desiredAltitude)
|
||||||
@@ -261,12 +261,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
|
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int CalculateTurnRadius(int speed, int turnSpeed)
|
public static int CalculateTurnRadius(int speed, WAngle turnSpeed)
|
||||||
{
|
{
|
||||||
// turnSpeed -> divide into 256 to get the number of ticks per complete rotation
|
// turnSpeed -> divide into 256 to get the number of ticks per complete rotation
|
||||||
// speed -> multiply to get distance travelled per rotation (circumference)
|
// speed -> multiply to get distance travelled per rotation (circumference)
|
||||||
// 180 -> divide by 2*pi to get the turn radius: 180==1024/(2*pi), with some extra leeway
|
// 180 -> divide by 2*pi to get the turn radius: 180==1024/(2*pi), with some extra leeway
|
||||||
return turnSpeed > 0 ? 180 * speed / turnSpeed : 0;
|
return turnSpeed.Angle > 0 ? 180 * speed / turnSpeed.Angle : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
readonly Aircraft aircraft;
|
readonly Aircraft aircraft;
|
||||||
readonly INotifyIdle[] tickIdles;
|
readonly INotifyIdle[] tickIdles;
|
||||||
readonly int turnSpeed;
|
readonly WAngle turnSpeed;
|
||||||
int remainingTicks;
|
int remainingTicks;
|
||||||
|
|
||||||
public FlyIdle(Actor self, int ticks = -1, bool tickIdle = true)
|
public FlyIdle(Actor self, int ticks = -1, bool tickIdle = true)
|
||||||
{
|
{
|
||||||
aircraft = self.Trait<Aircraft>();
|
aircraft = self.Trait<Aircraft>();
|
||||||
turnSpeed = aircraft.IdleTurnSpeed > -1 ? aircraft.IdleTurnSpeed : aircraft.TurnSpeed;
|
turnSpeed = aircraft.IdleTurnSpeed ?? aircraft.TurnSpeed;
|
||||||
remainingTicks = ticks;
|
remainingTicks = ticks;
|
||||||
|
|
||||||
if (tickIdle)
|
if (tickIdle)
|
||||||
|
|||||||
@@ -215,8 +215,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public WPos CenterPosition { get; private set; }
|
public WPos CenterPosition { get; private set; }
|
||||||
|
|
||||||
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
|
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
|
||||||
public int TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? 4 * Info.TurnSpeed : 0; } }
|
public WAngle TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? new WAngle(4 * Info.TurnSpeed) : WAngle.Zero; } }
|
||||||
public int IdleTurnSpeed { get { return Info.IdleTurnSpeed != -1 ? 4 * Info.IdleTurnSpeed : -1; } }
|
public WAngle? IdleTurnSpeed { get { return Info.IdleTurnSpeed != -1 ? new WAngle(4 * Info.IdleTurnSpeed) : (WAngle?)null; } }
|
||||||
|
|
||||||
public Actor ReservedActor { get; private set; }
|
public Actor ReservedActor { get; private set; }
|
||||||
public bool MayYieldReservation { get; private set; }
|
public bool MayYieldReservation { get; private set; }
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Sync]
|
[Sync]
|
||||||
public WAngle Facing { get; set; }
|
public WAngle Facing { get; set; }
|
||||||
|
|
||||||
public int TurnSpeed { get { return 0; } }
|
public WAngle TurnSpeed { get { return WAngle.Zero; } }
|
||||||
|
|
||||||
public Husk(ActorInitializer init, HuskInfo info)
|
public Husk(ActorInitializer init, HuskInfo info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
set { facing = value; }
|
set { facing = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int TurnSpeed { get { return 4 * Info.TurnSpeed; } }
|
public WAngle TurnSpeed { get { return new WAngle(4 * Info.TurnSpeed); } }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ namespace OpenRA.Mods.Common
|
|||||||
/// If facing is already within step of desiredFacing then desiredFacing is returned.
|
/// If facing is already within step of desiredFacing then desiredFacing is returned.
|
||||||
/// Step is given as an integer to allow negative values (step away from the desired facing)
|
/// Step is given as an integer to allow negative values (step away from the desired facing)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static WAngle TickFacing(WAngle facing, WAngle desiredFacing, int step)
|
public static WAngle TickFacing(WAngle facing, WAngle desiredFacing, WAngle step)
|
||||||
{
|
{
|
||||||
var leftTurn = (facing - desiredFacing).Angle;
|
var leftTurn = (facing - desiredFacing).Angle;
|
||||||
var rightTurn = (desiredFacing - facing).Angle;
|
var rightTurn = (desiredFacing - facing).Angle;
|
||||||
if (leftTurn < step || rightTurn < step)
|
if (leftTurn < step.Angle || rightTurn < step.Angle)
|
||||||
return desiredFacing;
|
return desiredFacing;
|
||||||
|
|
||||||
return rightTurn < leftTurn ? new WAngle(facing.Angle + step) : new WAngle(facing.Angle - step);
|
return rightTurn < leftTurn ? facing + step : facing - step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user