diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index 63dc0d1b28..cfb1cea319 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -37,14 +37,15 @@ namespace OpenRA.Mods.Common.Activities this.minRange = minRange; } - public static void FlyToward(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude) + public static void FlyToward(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude, int turnSpeedOverride = -1) { desiredAltitude = new WDist(aircraft.CenterPosition.Z) + desiredAltitude - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); var move = aircraft.FlyStep(aircraft.Facing); var altitude = aircraft.CenterPosition.Z; - aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); + var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed; + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed); if (altitude != desiredAltitude.Length) { diff --git a/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs b/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs index 775d0dd91d..61feac3859 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs @@ -17,14 +17,14 @@ namespace OpenRA.Mods.Common.Activities public class FlyCircle : Activity { readonly Aircraft aircraft; - readonly WDist cruiseAltitude; + readonly int turnSpeedOverride; int remainingTicks; - public FlyCircle(Actor self, int ticks = -1) + public FlyCircle(Actor self, int ticks = -1, int turnSpeedOverride = -1) { aircraft = self.Trait(); - cruiseAltitude = aircraft.Info.CruiseAltitude; remainingTicks = ticks; + this.turnSpeedOverride = turnSpeedOverride; } public override Activity Tick(Actor self) @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities // We can't possibly turn this fast var desiredFacing = aircraft.Facing + 64; - Fly.FlyToward(self, aircraft, desiredFacing, cruiseAltitude); + Fly.FlyToward(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, turnSpeedOverride); return this; } diff --git a/OpenRA.Mods.Common/Activities/Air/HeliFlyCircle.cs b/OpenRA.Mods.Common/Activities/Air/HeliFlyCircle.cs index a104da4d5d..3209602a27 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliFlyCircle.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliFlyCircle.cs @@ -17,10 +17,12 @@ namespace OpenRA.Mods.Common.Activities public class HeliFlyCircle : Activity { readonly Aircraft aircraft; + readonly int turnSpeedOverride; - public HeliFlyCircle(Actor self) + public HeliFlyCircle(Actor self, int turnSpeedOverride = -1) { aircraft = self.Trait(); + this.turnSpeedOverride = turnSpeedOverride; } public override Activity Tick(Actor self) @@ -42,7 +44,8 @@ namespace OpenRA.Mods.Common.Activities aircraft.SetPosition(self, aircraft.CenterPosition + move); var desiredFacing = aircraft.Facing + 64; - aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed / 3); + var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed; + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed); return this; } diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 2de00b2bd7..24d17a8fe8 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -942,6 +942,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index a2524a5884..06e1dd7d64 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -40,6 +40,9 @@ namespace OpenRA.Mods.Common.Traits public readonly int TurnSpeed = 255; + [Desc("Turn speed to apply when aircraft flies in circles while idle. Defaults to TurnSpeed if negative.")] + public readonly int IdleTurnSpeed = -1; + public readonly int Speed = 1; [Desc("Minimum altitude where this aircraft is considered airborne.")] diff --git a/OpenRA.Mods.Common/Traits/AutoCarryall.cs b/OpenRA.Mods.Common/Traits/AutoCarryall.cs index 972a13bada..ca562f185d 100644 --- a/OpenRA.Mods.Common/Traits/AutoCarryall.cs +++ b/OpenRA.Mods.Common/Traits/AutoCarryall.cs @@ -33,9 +33,13 @@ namespace OpenRA.Mods.Common.Traits busy = false; FindCarryableForTransport(self); - // TODO: This should be handled by the aircraft trait + // TODO: This should be handled by the Aircraft trait if (!busy) - self.QueueActivity(new HeliFlyCircle(self)); + { + var aircraft = self.Trait(); + var turnSpeedOverride = aircraft.Info.IdleTurnSpeed > -1 ? aircraft.Info.IdleTurnSpeed : aircraft.TurnSpeed; + self.QueueActivity(new HeliFlyCircle(self, turnSpeedOverride)); + } } // A carryable notifying us that he'd like to be carried diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemovedAutoCarryallCircleTurnSpeed.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemovedAutoCarryallCircleTurnSpeed.cs new file mode 100644 index 0000000000..55f4bf0b5d --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemovedAutoCarryallCircleTurnSpeed.cs @@ -0,0 +1,55 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class RemovedAutoCarryallCircleTurnSpeed : UpdateRule + { + public override string Name { get { return "Removed AutoCarryall idle circling turnspeed hardcoding"; } } + public override string Description + { + get + { + return "Aircraft that circle while idle despite having CanHover (AutoCarryall) have their\n" + + "turn speed during idle circling no longer hardcoded to 1/3 of regular TurnSpeed." + + "Note that the new IdleTurnSpeed override works on all aircraft that circle when idle."; + } + } + + bool showMessage; + bool messageShown; + + public override IEnumerable AfterUpdate(ModData modData) + { + var message = "While circling idle, your AutoCarryall(s) will now turn at full TurnSpeed,\n" + + "unless you manually define a custom IdleTurnSpeed."; + + if (showMessage && !messageShown) + yield return message; + + showMessage = false; + messageShown = true; + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + var autoCarryall = actorNode.LastChildMatching("AutoCarryall"); + if (autoCarryall == null) + yield break; + + showMessage = true; + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index a297ae9fff..347559cc41 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -109,6 +109,7 @@ namespace OpenRA.Mods.Common.UpdateRules new RemoveNegativeDamageFullHealthCheck(), new RemoveResourceExplodeModifier(), new DefineLevelUpImageDefault(), + new RemovedAutoCarryallCircleTurnSpeed(), }) }; diff --git a/mods/d2k/rules/aircraft.yaml b/mods/d2k/rules/aircraft.yaml index 1c70d0cf56..21eed96499 100644 --- a/mods/d2k/rules/aircraft.yaml +++ b/mods/d2k/rules/aircraft.yaml @@ -20,6 +20,7 @@ carryall.reinforce: AirborneCondition: airborne CanHover: True VTOL: true + IdleTurnSpeed: 1 Targetable@GROUND: TargetTypes: Ground, Vehicle RequiresCondition: !airborne