diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index b1a1e2c3b0..6b8306c859 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -317,7 +317,7 @@ namespace OpenRA.Traits public interface IFacing { - int TurnSpeed { get; } + WAngle TurnSpeed { get; } WAngle Facing { get; set; } } diff --git a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs index efe944b56c..8d9b0c65ac 100644 --- a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs +++ b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs @@ -73,7 +73,7 @@ namespace OpenRA.Mods.Cnc.Traits public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } } // Isn't used anyway - public int TurnSpeed { get { return 255; } } + public WAngle TurnSpeed { get { return WAngle.Zero; } } CPos cachedLocation; diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index 5462deff99..a0432189c8 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -60,14 +60,14 @@ namespace OpenRA.Mods.Common.Activities 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 move = aircraft.Info.CanSlide ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing); if (moveOverride != WVec.Zero) move = moveOverride; - var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed; + var turnSpeed = turnSpeedOverride ?? aircraft.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. @@ -83,18 +83,18 @@ namespace OpenRA.Mods.Common.Activities 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); } // 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 move = WVec.Zero; - var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed; + var turnSpeed = turnSpeedOverride ?? aircraft.TurnSpeed; aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed); if (dat != desiredAltitude) @@ -261,12 +261,12 @@ namespace OpenRA.Mods.Common.Activities 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 // 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 - return turnSpeed > 0 ? 180 * speed / turnSpeed : 0; + return turnSpeed.Angle > 0 ? 180 * speed / turnSpeed.Angle : 0; } } } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs b/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs index f8341dc405..bf5a1e0caf 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs @@ -20,13 +20,13 @@ namespace OpenRA.Mods.Common.Activities { readonly Aircraft aircraft; readonly INotifyIdle[] tickIdles; - readonly int turnSpeed; + readonly WAngle turnSpeed; int remainingTicks; public FlyIdle(Actor self, int ticks = -1, bool tickIdle = true) { aircraft = self.Trait(); - turnSpeed = aircraft.IdleTurnSpeed > -1 ? aircraft.IdleTurnSpeed : aircraft.TurnSpeed; + turnSpeed = aircraft.IdleTurnSpeed ?? aircraft.TurnSpeed; remainingTicks = ticks; if (tickIdle) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 0413c07335..24bf8ee431 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -215,8 +215,8 @@ namespace OpenRA.Mods.Common.Traits public WPos CenterPosition { get; private set; } public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } } - public int TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? 4 * Info.TurnSpeed : 0; } } - public int IdleTurnSpeed { get { return Info.IdleTurnSpeed != -1 ? 4 * Info.IdleTurnSpeed : -1; } } + public WAngle TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? new WAngle(4 * Info.TurnSpeed) : WAngle.Zero; } } + public WAngle? IdleTurnSpeed { get { return Info.IdleTurnSpeed != -1 ? new WAngle(4 * Info.IdleTurnSpeed) : (WAngle?)null; } } public Actor ReservedActor { get; private set; } public bool MayYieldReservation { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index 9b534852d8..973d998d8a 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits [Sync] public WAngle Facing { get; set; } - public int TurnSpeed { get { return 0; } } + public WAngle TurnSpeed { get { return WAngle.Zero; } } public Husk(ActorInitializer init, HuskInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index f89fec1a1f..4eeb35b705 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Traits set { facing = value; } } - public int TurnSpeed { get { return 4 * Info.TurnSpeed; } } + public WAngle TurnSpeed { get { return new WAngle(4 * Info.TurnSpeed); } } #endregion [Sync] diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index 7f05f5f32b..95c6b471ec 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -40,14 +40,14 @@ namespace OpenRA.Mods.Common /// 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) /// - 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 rightTurn = (desiredFacing - facing).Angle; - if (leftTurn < step || rightTurn < step) + if (leftTurn < step.Angle || rightTurn < step.Angle) return desiredFacing; - return rightTurn < leftTurn ? new WAngle(facing.Angle + step) : new WAngle(facing.Angle - step); + return rightTurn < leftTurn ? facing + step : facing - step; } ///