diff --git a/OpenRA.Mods.RA/Armament.cs b/OpenRA.Mods.RA/Armament.cs index d01f9fa5fc..563802ced5 100755 --- a/OpenRA.Mods.RA/Armament.cs +++ b/OpenRA.Mods.RA/Armament.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA public readonly float LegacyRecoilRecovery = 0.2f; public readonly int[] LegacyLocalOffset = { }; - public readonly CoordinateModel OffsetModel = CoordinateModel.Legacy; + public CoordinateModel OffsetModel = CoordinateModel.Legacy; [Desc("Muzzle position relative to turret or body. (forward, right, up) triples")] public readonly WRange[] LocalOffset = {}; [Desc("Muzzle yaw relative to turret or body.")] @@ -57,7 +57,14 @@ namespace OpenRA.Mods.RA [Desc("Recoil recovery per-frame")] public readonly WRange RecoilRecovery = new WRange(9); - public object Create(ActorInitializer init) { return new Armament(init.self, this); } + public object Create(ActorInitializer init) + { + // Auto-detect coordinate type + if (LocalOffset.Length > 0 && OffsetModel == CoordinateModel.Legacy) + OffsetModel = CoordinateModel.World; + + return new Armament(init.self, this); + } } public class Armament : ITick diff --git a/OpenRA.Mods.RA/Turreted.cs b/OpenRA.Mods.RA/Turreted.cs index e2d1e7f6a1..fe466e46cd 100755 --- a/OpenRA.Mods.RA/Turreted.cs +++ b/OpenRA.Mods.RA/Turreted.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.Mods.RA.Render; using OpenRA.FileFormats; using OpenRA.Traits; @@ -25,11 +26,25 @@ namespace OpenRA.Mods.RA public readonly int[] LegacyOffset = {0,0}; public readonly bool AlignWhenIdle = false; - public readonly CoordinateModel OffsetModel = CoordinateModel.Legacy; + public CoordinateModel OffsetModel = CoordinateModel.Legacy; [Desc("Muzzle position relative to turret or body. (forward, right, up) triples")] public readonly WVec Offset = WVec.Zero; - public virtual object Create(ActorInitializer init) { return new Turreted(init, this); } + + bool HasWorldOffset(ArmamentInfo ai) + { + return ai.OffsetModel == CoordinateModel.World || ai.LocalOffset.Length > 0; + } + + public virtual object Create(ActorInitializer init) + { + // Auto-detect coordinate type + var arms = init.self.Info.Traits.WithInterface(); + if (Offset != WVec.Zero || arms.Any(ai => HasWorldOffset(ai))) + OffsetModel = CoordinateModel.World; + + return new Turreted(init, this); + } } public class Turreted : ITick, ISync, IResolveOrder