From 3ece9ede4213ece5fd10c4993c19d6562c5cff47 Mon Sep 17 00:00:00 2001 From: huwpascoe Date: Fri, 19 Sep 2014 02:48:11 +0100 Subject: [PATCH] Turrets now realign when not attacking. --- .../UtilityCommands/UpgradeRules.cs | 9 +++++++ OpenRA.Mods.RA/Turreted.cs | 26 +++++++++++++------ mods/cnc/rules/vehicles.yaml | 2 +- mods/d2k/rules/vehicles.yaml | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 69a6b4cc3f..e485b3f50e 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -645,6 +645,15 @@ namespace OpenRA.Mods.Common.UtilityCommands } } + if (engineVersion < 20141002) + { + if (node.Key == "AlignWhenIdle" && parentKey == "Turreted") + { + node.Key = "RealignDelay"; + node.Value.Value = "0"; + } + } + UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); } } diff --git a/OpenRA.Mods.RA/Turreted.cs b/OpenRA.Mods.RA/Turreted.cs index b181f69c0c..8e46f0b6fc 100755 --- a/OpenRA.Mods.RA/Turreted.cs +++ b/OpenRA.Mods.RA/Turreted.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -18,7 +19,9 @@ namespace OpenRA.Mods.RA [Desc("Rate of Turning")] public readonly int ROT = 255; public readonly int InitialFacing = 128; - public readonly bool AlignWhenIdle = false; + + [Desc("Number of ticks before turret is realigned. (-1 turns off realignment)")] + public readonly int RealignDelay = 40; [Desc("Muzzle position relative to turret or body. (forward, right, up) triples")] public readonly WVec Offset = WVec.Zero; @@ -26,13 +29,15 @@ namespace OpenRA.Mods.RA public virtual object Create(ActorInitializer init) { return new Turreted(init, this); } } - public class Turreted : ITick, ISync, IResolveOrder + public class Turreted : ITick, ISync { [Sync] public int QuantizedFacings = 0; [Sync] public int turretFacing = 0; public int? desiredFacing; TurretedInfo info; IFacing facing; + Lazy attack; + int realignTick = 0; // For subclasses that want to move the turret relative to the body protected WVec LocalOffset = WVec.Zero; @@ -56,10 +61,21 @@ namespace OpenRA.Mods.RA this.info = info; turretFacing = GetInitialTurretFacing(init, info.InitialFacing); facing = init.self.TraitOrDefault(); + attack = Exts.Lazy(() => init.self.TraitOrDefault()); } public virtual void Tick(Actor self) { + if (attack.Value != null && !attack.Value.IsAttacking) + { + if (realignTick < info.RealignDelay) + realignTick++; + else if (info.RealignDelay > -1) + desiredFacing = null; + } + else + realignTick = 0; + var df = desiredFacing ?? ( facing != null ? facing.Facing : turretFacing ); turretFacing = Util.TickFacing(turretFacing, df, info.ROT); } @@ -70,12 +86,6 @@ namespace OpenRA.Mods.RA return turretFacing == desiredFacing; } - public virtual void ResolveOrder(Actor self, Order order) - { - if (info.AlignWhenIdle && order.OrderString != "Attack") - desiredFacing = null; - } - // Turret offset in world-space public WVec Position(Actor self) { diff --git a/mods/cnc/rules/vehicles.yaml b/mods/cnc/rules/vehicles.yaml index 0df1495b2f..465a8aa291 100644 --- a/mods/cnc/rules/vehicles.yaml +++ b/mods/cnc/rules/vehicles.yaml @@ -493,7 +493,7 @@ MLRS: Turreted: ROT: 8 Offset: -128,0,128 - AlignWhenIdle: true + RealignDelay: 0 Armament: Weapon: Patriot LocalOffset: 0,-171,0, 0,171,0 diff --git a/mods/d2k/rules/vehicles.yaml b/mods/d2k/rules/vehicles.yaml index d6a9565895..7ad8af58a5 100644 --- a/mods/d2k/rules/vehicles.yaml +++ b/mods/d2k/rules/vehicles.yaml @@ -207,7 +207,7 @@ QUAD.starport: Range: 7c0 Turreted: ROT: 6 - AlignWhenIdle: true + RealignDelay: 0 Armament: Weapon: 90mm Recoil: 128