From 9cf916e8b6cf46cb89c42484526ffba9efc94cae Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 29 Sep 2016 21:26:07 +0200 Subject: [PATCH] Change Aircraft.IsMoving to only return true when moving horizontally Additionally added IsMovingVertically for potential edge cases where vertical movement needs to be considered. --- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index b245eddf41..090cb55601 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -115,11 +115,15 @@ namespace OpenRA.Mods.Common.Traits public int TurnSpeed { get { return Info.TurnSpeed; } } public Actor ReservedActor { get; private set; } public bool MayYieldReservation { get; private set; } + public bool IsMovingVertically { get; private set; } bool airborne; bool cruising; bool firstTick = true; + bool isMoving; + WPos cachedPosition; + public Aircraft(ActorInitializer init, AircraftInfo info) { Info = info; @@ -142,6 +146,7 @@ namespace OpenRA.Mods.Common.Traits { um = self.TraitOrDefault(); speedModifiers = self.TraitsImplementing().ToArray().Select(sm => sm.GetSpeedModifier()); + cachedPosition = self.CenterPosition; } public void AddedToWorld(Actor self) @@ -174,6 +179,11 @@ namespace OpenRA.Mods.Common.Traits self.QueueActivity(new TakeOff(self)); } + var oldCachedPosition = cachedPosition; + cachedPosition = self.CenterPosition; + isMoving = (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0; + IsMovingVertically = (oldCachedPosition - cachedPosition).VerticalLengthSquared != 0; + Repulse(); } @@ -483,7 +493,7 @@ namespace OpenRA.Mods.Common.Traits public CPos NearestMoveableCell(CPos cell) { return cell; } - public bool IsMoving { get { return self.World.Map.DistanceAboveTerrain(CenterPosition).Length > 0; } set { } } + public bool IsMoving { get { return isMoving; } set { } } public bool CanEnterTargetNow(Actor self, Target target) {