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.
This commit is contained in:
Paul Chote
2025-12-28 19:35:04 +00:00
committed by Gustas Kažukauskas
parent 0f22e3d4e4
commit eb09870a10
4 changed files with 8 additions and 16 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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<VariableObserver> GetVariableObservers()
{
foreach (var observer in base.GetVariableObservers())

View File

@@ -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<IOrderTargeter> IIssueOrder.Orders