From eb09870a103d8f8a2f6fe07aa30085888e93b269 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 28 Dec 2025 19:35:04 +0000 Subject: [PATCH] Fix landing altitude checks. Both GetPosition and LandPosition were trying to solve the problem of dynamic altitude offsets for carryalls with different-sized cargo. However, because they both apply the offsets, when the two are used together the two sets of offsets cancel to 0, producing incorrect behaviour. GetPosition is removed in favor of using CenterPosition with the dynamic LandAltitude. Fly.Tick and Carryall ignore the z coordinate so their behaviour is unchanged. Land and Aircraft.AtLandAltitude now return the correct result. --- OpenRA.Mods.Common/Activities/Air/Fly.cs | 2 +- OpenRA.Mods.Common/Activities/Air/Land.cs | 8 +++++--- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 11 +---------- OpenRA.Mods.Common/Traits/Carryall.cs | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index acdbb9a33d..3f752626d2 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -166,7 +166,7 @@ namespace OpenRA.Mods.Common.Activities return true; var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; - var pos = aircraft.GetPosition(); + var pos = self.CenterPosition; var delta = checkTarget.CenterPosition - pos; // Inside the target annulus, so we're done diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index ece6ed3fc8..6376396cb3 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -104,14 +104,15 @@ namespace OpenRA.Mods.Common.Activities return true; } - var pos = aircraft.GetPosition(); + var pos = self.CenterPosition; // Reevaluate target position in case the target has moved. targetPosition = target.CenterPosition + offset; landingCell = self.World.Map.CellContaining(targetPosition); // We are already at the landing location. - if ((targetPosition - pos).LengthSquared == 0) + var delta = pos - targetPosition; + if (delta.HorizontalLengthSquared == 0 && delta.Z == aircraft.LandAltitude.Length) return true; // Look for free landing cell @@ -132,7 +133,8 @@ namespace OpenRA.Mods.Common.Activities targetPosition = target.CenterPosition + offset; landingCell = self.World.Map.CellContaining(targetPosition); - if ((targetPosition - pos).LengthSquared == 0) + delta = pos - targetPosition; + if (delta.HorizontalLengthSquared == 0 && delta.Z == aircraft.LandAltitude.Length) return true; } } diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 104b8c15b0..978fc02fd7 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -300,7 +300,7 @@ namespace OpenRA.Mods.Common.Traits return self.CenterPosition - new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(self.CenterPosition)); } - public bool AtLandAltitude => self.World.Map.DistanceAboveTerrain(GetPosition()) == LandAltitude; + public bool AtLandAltitude => self.World.Map.DistanceAboveTerrain(self.CenterPosition) == LandAltitude; bool airborne; bool cruising; @@ -342,15 +342,6 @@ namespace OpenRA.Mods.Common.Traits } } - public WPos GetPosition() - { - var pos = self.CenterPosition; - foreach (var offset in positionOffsets) - pos += offset.PositionOffset; - - return pos; - } - public override IEnumerable GetVariableObservers() { foreach (var observer in base.GetVariableObservers()) diff --git a/OpenRA.Mods.Common/Traits/Carryall.cs b/OpenRA.Mods.Common/Traits/Carryall.cs index edbc7fc124..0694a7102a 100644 --- a/OpenRA.Mods.Common/Traits/Carryall.cs +++ b/OpenRA.Mods.Common/Traits/Carryall.cs @@ -309,8 +309,7 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) return false; - var targetCell = self.World.Map.CellContaining(aircraft.GetPosition()); - return Carryable != null && aircraft.CanLand(targetCell, blockedByMobile: false); + return Carryable != null && aircraft.CanLand(self.Location, blockedByMobile: false); } IEnumerable IIssueOrder.Orders