diff --git a/OpenRA.Game/WPos.cs b/OpenRA.Game/WPos.cs index 0966d6c849..6ea08e0b78 100644 --- a/OpenRA.Game/WPos.cs +++ b/OpenRA.Game/WPos.cs @@ -65,8 +65,10 @@ namespace OpenRA // Add an additional quadratic variation to height // Uses decimal to avoid integer overflow - var offset = (int)((decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div)); - return new WPos(ret.X, ret.Y, ret.Z + offset); + var offset = (decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div); + var clampedOffset = (int)(offset + (decimal)ret.Z).Clamp((decimal)int.MinValue, (decimal)int.MaxValue); + + return new WPos(ret.X, ret.Y, clampedOffset); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }