From 03e09e25bb57a0c85f0614d8ac20c03e531d8f8b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 3 Aug 2013 11:47:25 +1200 Subject: [PATCH] Fix turret facings for GTWR etc. Fixes #3610. --- OpenRA.Game/Traits/BodyOrientation.cs | 21 ++++++++++++++++----- OpenRA.Game/Traits/Render/RenderSimple.cs | 2 +- OpenRA.Game/Traits/TraitsInterfaces.cs | 3 ++- OpenRA.Mods.Cnc/RenderGunboat.cs | 2 +- OpenRA.Mods.RA/Render/RenderBuilding.cs | 2 +- OpenRA.Mods.RA/Render/RenderInfantry.cs | 2 +- mods/cnc/rules/structures.yaml | 6 ++---- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/OpenRA.Game/Traits/BodyOrientation.cs b/OpenRA.Game/Traits/BodyOrientation.cs index 653030a6da..c2fa3cfb98 100755 --- a/OpenRA.Game/Traits/BodyOrientation.cs +++ b/OpenRA.Game/Traits/BodyOrientation.cs @@ -18,6 +18,9 @@ namespace OpenRA.Traits { public class BodyOrientationInfo : ITraitInfo, IBodyOrientationInfo { + [Desc("Number of facings for gameplay calculations. -1 indiciates auto-detection from sequence")] + public readonly int QuantizedFacings = -1; + [Desc("Camera pitch for rotation calculations")] public readonly WAngle CameraPitch = WAngle.FromDegrees(40); public object Create(ActorInitializer init) { return new BodyOrientation(init.self, this); } @@ -25,21 +28,23 @@ namespace OpenRA.Traits public class BodyOrientation : IBodyOrientation { - [Sync] public int QuantizedFacings { get; set; } - BodyOrientationInfo Info; + [Sync] public int QuantizedFacings { get; private set; } + BodyOrientationInfo info; public BodyOrientation(Actor self, BodyOrientationInfo info) { - Info = info; + this.info = info; + if (info.QuantizedFacings > 0) + QuantizedFacings = info.QuantizedFacings; } - public WAngle CameraPitch { get { return Info.CameraPitch; } } + public WAngle CameraPitch { get { return info.CameraPitch; } } public WVec LocalToWorld(WVec vec) { // RA's 2d perspective doesn't correspond to an orthonormal 3D // coordinate system, so fudge the y axis to make things look good - return new WVec(vec.Y, -Info.CameraPitch.Sin()*vec.X/1024, vec.Z); + return new WVec(vec.Y, -info.CameraPitch.Sin()*vec.X/1024, vec.Z); } public WRot QuantizeOrientation(Actor self, WRot orientation) @@ -54,5 +59,11 @@ namespace OpenRA.Traits // Roll and pitch are always zero if yaw is quantized return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); } + + public void SetAutodetectedFacings(int facings) + { + if (info.QuantizedFacings < 0) + QuantizedFacings = facings; + } } } diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 42e3eae6c3..09c0aaa8bc 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -44,7 +44,7 @@ namespace OpenRA.Traits : this(self, MakeFacingFunc(self)) { anim.PlayRepeating("idle"); - self.Trait().QuantizedFacings = anim.CurrentSequence.Facings; + self.Trait().SetAutodetectedFacings(anim.CurrentSequence.Facings); } public int2 SelectionSize(Actor self) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index e979a7ce14..faf8a1449f 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -191,9 +191,10 @@ namespace OpenRA.Traits public interface IBodyOrientation { WAngle CameraPitch { get; } - int QuantizedFacings { get; set; } + int QuantizedFacings { get; } WVec LocalToWorld(WVec vec); WRot QuantizeOrientation(Actor self, WRot orientation); + void SetAutodetectedFacings(int facings); } public interface IBodyOrientationInfo {} diff --git a/OpenRA.Mods.Cnc/RenderGunboat.cs b/OpenRA.Mods.Cnc/RenderGunboat.cs index 5f48da7d60..21f6f26dba 100644 --- a/OpenRA.Mods.Cnc/RenderGunboat.cs +++ b/OpenRA.Mods.Cnc/RenderGunboat.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Render rightWake.Play("wake-right"); anims.Add("wake-right", new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87)); - self.Trait().QuantizedFacings = 2; + self.Trait().SetAutodetectedFacings(2); } public void DamageStateChanged(Actor self, AttackInfo e) diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index c7bc5e4708..b3e70badc8 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Render // Work around a bogus crash anim.PlayRepeating( NormalizeSequence(self, "idle") ); - self.Trait().QuantizedFacings = anim.CurrentSequence.Facings; + self.Trait().SetAutodetectedFacings(anim.CurrentSequence.Facings); // Can't call Complete() directly from ctor because other traits haven't been inited yet if (self.Info.Traits.Get().HasMakeAnimation && !init.Contains()) diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index c23055f3a6..542811b779 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Render State = AnimationState.Waiting; mobile = self.Trait(); - self.Trait().QuantizedFacings = anim.CurrentSequence.Facings; + self.Trait().SetAutodetectedFacings(anim.CurrentSequence.Facings); } public void Attacking(Actor self, Target target) diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index b92329c046..178bf52614 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -605,8 +605,6 @@ OBLI: Turreted: ROT:255 AutoTarget: - RenderBuilding: - QuantizedFacings: 8 -RenderBuilding: RenderRangeCircle: -EmitInfantryOnSell: @@ -638,7 +636,7 @@ GTWR: Weapon: HighV LocalOffset: 256,0,256 AttackTurreted: - RenderBuilding: + BodyOrientation: QuantizedFacings: 8 AutoTarget: DetectCloaked: @@ -682,7 +680,7 @@ ATWR: LocalYaw: -100,100 AttackTurreted: AutoTarget: - RenderBuilding: + BodyOrientation: QuantizedFacings: 8 RenderDetectionCircle: DetectCloaked: