From 43717a89b55c374276c0caf0b91f79f05f398527 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 5 Jun 2020 20:17:32 +0100 Subject: [PATCH] Add Orientation getter to IFacing. --- OpenRA.Game/Actor.cs | 4 +--- OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + OpenRA.Mods.Cnc/Traits/TDGunboat.cs | 10 +++++++++- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 10 +++++++++- OpenRA.Mods.Common/Traits/Husk.cs | 10 +++++++++- OpenRA.Mods.Common/Traits/Mobile.cs | 15 ++++++++++----- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index c9b24a61c6..663a76b7a2 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -69,9 +69,7 @@ namespace OpenRA { get { - // TODO: Support non-zero pitch/roll in IFacing (IOrientation?) - var facingValue = facing != null ? facing.Facing : WAngle.Zero; - return new WRot(WAngle.Zero, WAngle.Zero, facingValue); + return facing != null ? facing.Orientation : WRot.Zero; } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 6b8306c859..175f864dd0 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -319,6 +319,7 @@ namespace OpenRA.Traits { WAngle TurnSpeed { get; } WAngle Facing { get; set; } + WRot Orientation { get; } } public interface IFacingInfo : ITraitInfoInterface { int GetInitialFacing(); } diff --git a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs index cad845c3f3..2186967fd2 100644 --- a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs +++ b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs @@ -64,8 +64,16 @@ namespace OpenRA.Mods.Cnc.Traits IEnumerable speedModifiers; INotifyVisualPositionChanged[] notifyVisualPositionChanged; + WRot orientation; + [Sync] - public WAngle Facing { get; set; } + public WAngle Facing + { + get { return orientation.Yaw; } + set { orientation = orientation.WithYaw(value); } + } + + public WRot Orientation { get { return orientation; } } [Sync] public WPos CenterPosition { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index da98bfca2f..1924dbfee7 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -208,8 +208,16 @@ namespace OpenRA.Mods.Common.Traits INotifyVisualPositionChanged[] notifyVisualPositionChanged; IOverrideAircraftLanding overrideAircraftLanding; + WRot orientation; + [Sync] - public WAngle Facing { get; set; } + public WAngle Facing + { + get { return orientation.Yaw; } + set { orientation = orientation.WithYaw(value); } + } + + public WRot Orientation { get { return orientation; } } [Sync] public WPos CenterPosition { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index c907fe6d42..ef4d2f5987 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -68,8 +68,16 @@ namespace OpenRA.Mods.Common.Traits [Sync] public WPos CenterPosition { get; private set; } + WRot orientation; + [Sync] - public WAngle Facing { get; set; } + public WAngle Facing + { + get { return orientation.Yaw; } + set { orientation = orientation.WithYaw(value); } + } + + public WRot Orientation { get { return orientation; } } public WAngle TurnSpeed { get { return WAngle.Zero; } } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 6485128990..7dd4f44a62 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -195,10 +195,12 @@ namespace OpenRA.Mods.Common.Traits } #endregion - WAngle oldFacing, facing; + WAngle oldFacing; + WRot orientation; WPos oldPos; CPos fromCell, toCell; public SubCell FromSubCell, ToSubCell; + INotifyCustomLayerChanged[] notifyCustomLayerChanged; INotifyVisualPositionChanged[] notifyVisualPositionChanged; INotifyMoving[] notifyMoving; @@ -216,13 +218,16 @@ namespace OpenRA.Mods.Common.Traits } #region IFacing + [Sync] public WAngle Facing { - get { return facing; } - set { facing = value; } + get { return orientation.Yaw; } + set { orientation = orientation.WithYaw(value); } } + public WRot Orientation { get { return orientation; } } + public WAngle TurnSpeed { get { return new WAngle(4 * Info.TurnSpeed); } } #endregion @@ -858,12 +863,12 @@ namespace OpenRA.Mods.Common.Traits void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits) { if (!inits.Contains() && !inits.Contains()) - inits.Add(new DynamicFacingInit(() => facing.Facing)); + inits.Add(new DynamicFacingInit(() => Facing.Facing)); } void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init) { - init.Add(new FacingInit(facing.Facing)); + init.Add(new FacingInit(Facing.Facing)); // Allows the husk to drag to its final position if (CanEnterCell(self.Location, self, BlockedByActor.Stationary))