From 888d7c638fa546a6ea1bf09d0d2ec282e7d7f5d3 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 29 Sep 2016 21:16:30 +0200 Subject: [PATCH 1/5] Move Aircraft.firstTick above constructor --- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index b3097617b4..9fc472ea1e 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -118,6 +118,7 @@ namespace OpenRA.Mods.Common.Traits bool airborne; bool cruising; + bool firstTick = true; public Aircraft(ActorInitializer init, AircraftInfo info) { @@ -154,7 +155,6 @@ namespace OpenRA.Mods.Common.Traits OnCruisingAltitudeReached(); } - bool firstTick = true; public virtual void Tick(Actor self) { if (firstTick) From 6571f926fbb39d3a48f40d661172aa767fee2061 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 29 Sep 2016 21:21:34 +0200 Subject: [PATCH 2/5] Aircraft.ReserveSpawnBuilding style fixes --- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 9fc472ea1e..b245eddf41 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -266,12 +266,12 @@ namespace OpenRA.Mods.Common.Traits protected void ReserveSpawnBuilding() { - /* HACK: not spawning in the air, so try to assoc. with our afld. */ - var afld = GetActorBelow(); - if (afld == null) + // HACK: Not spawning in the air, so try to associate with our spawner. + var spawner = GetActorBelow(); + if (spawner == null) return; - MakeReservation(afld); + MakeReservation(spawner); } public void MakeReservation(Actor target) From 9cf916e8b6cf46cb89c42484526ffba9efc94cae Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 29 Sep 2016 21:26:07 +0200 Subject: [PATCH 3/5] 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) { From 4b8700bb97299031b911c168b56e3abced5b4b5d Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 29 Sep 2016 22:35:01 +0200 Subject: [PATCH 4/5] Remove work-around for aircraft from WithMoveAnimation --- OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs index aab405043f..ffcb69b146 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs @@ -27,24 +27,16 @@ namespace OpenRA.Mods.Common.Traits.Render readonly IMove movement; readonly WithSpriteBody wsb; - WPos cachedPosition; - public WithMoveAnimation(ActorInitializer init, WithMoveAnimationInfo info) { this.info = info; movement = init.Self.Trait(); wsb = init.Self.Trait(); - - cachedPosition = init.Self.CenterPosition; } public void Tick(Actor self) { - var oldCachedPosition = cachedPosition; - cachedPosition = self.CenterPosition; - - // Flying units set IsMoving whenever they are airborne, which isn't enough for our purposes - var isMoving = movement.IsMoving && !self.IsDead && (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0; + var isMoving = movement.IsMoving && !self.IsDead; if (isMoving ^ (wsb.DefaultAnimation.CurrentSequence.Name != info.MoveSequence)) return; From 16d4ee003429d30d0857e3d3f816c525dd1740d3 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 2 Oct 2016 20:27:03 +0200 Subject: [PATCH 5/5] Move `IsMovingVertically` to IMove - avoids an Aircraft trait look-up in #11886 - potentially useful for future additional locomotors (jumpjet), custom locomotors in external mods, possibly future updates to default ground locomotor (Mobile) with regard to behavior on slopes --- OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 6 ++++-- OpenRA.Mods.Common/Traits/Mobile.cs | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 112a570207..6e580d5234 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -308,6 +308,7 @@ namespace OpenRA.Traits Activity VisualMove(Actor self, WPos fromPos, WPos toPos); CPos NearestMoveableCell(CPos target); bool IsMoving { get; set; } + bool IsMovingVertically { get; set; } bool CanEnterTargetNow(Actor self, Target target); } diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 090cb55601..9913652d8f 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -115,13 +115,13 @@ 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; + bool isMovingVertically; WPos cachedPosition; public Aircraft(ActorInitializer init, AircraftInfo info) @@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Traits var oldCachedPosition = cachedPosition; cachedPosition = self.CenterPosition; isMoving = (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0; - IsMovingVertically = (oldCachedPosition - cachedPosition).VerticalLengthSquared != 0; + isMovingVertically = (oldCachedPosition - cachedPosition).VerticalLengthSquared != 0; Repulse(); } @@ -495,6 +495,8 @@ namespace OpenRA.Mods.Common.Traits public bool IsMoving { get { return isMoving; } set { } } + public bool IsMovingVertically { get { return isMovingVertically; } set { } } + public bool CanEnterTargetNow(Actor self, Target target) { if (target.Positions.Any(p => self.World.ActorMap.GetActorsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != target.Actor))) diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 1398767c77..cdd07f2a70 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -327,6 +327,7 @@ namespace OpenRA.Mods.Common.Traits readonly Actor self; readonly Lazy> speedModifiers; public bool IsMoving { get; set; } + public bool IsMovingVertically { get { return false; } set { } } int facing; CPos fromCell, toCell;