diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index f97bde2277..bd690e7c51 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -713,11 +713,34 @@ namespace OpenRA var isRectangularIsometric = Grid.Type == MapGridType.RectangularIsometric; - // Fudge the heightmap offset by adding as much extra as we need / can. - // This tries to correct for our incorrect assumption that MPos == PPos - var heightOffset = Math.Min(Grid.MaximumTerrainHeight, MapSize.Y - Bounds.Bottom); + var top = int.MaxValue; + var bottom = int.MinValue; + + if (Grid.MaximumTerrainHeight > 0) + { + // The minimap is drawn in cell space, so we need to + // unproject the PPos bounds to find the MPos boundaries. + // This matches the calculation in RadarWidget that is used ingame + for (var x = Bounds.Left; x < Bounds.Right; x++) + { + var allTop = Unproject(new PPos(x, Bounds.Top)); + var allBottom = Unproject(new PPos(x, Bounds.Bottom)); + if (allTop.Any()) + top = Math.Min(top, allTop.MinBy(uv => uv.V).V); + + if (allBottom.Any()) + bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V); + } + } + else + { + // If the mod uses flat maps, MPos == PPos and we can take the bounds rect directly + top = Bounds.Top; + bottom = Bounds.Bottom; + } + var width = Bounds.Width; - var height = Bounds.Height + heightOffset; + var height = bottom - top; var bitmapWidth = width; if (isRectangularIsometric) @@ -726,13 +749,13 @@ namespace OpenRA var stride = bitmapWidth * 4; var pxStride = 4; var minimapData = new byte[stride * height]; - (Color Left, Color Right) terrainColor = default((Color, Color)); + (Color Left, Color Right) terrainColor = default; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { - var uv = new MPos(x + Bounds.Left, y + Bounds.Top); + var uv = new MPos(x + Bounds.Left, y + top); // FirstOrDefault will return a (MPos.Zero, Color.Transparent) if positions is empty var actorColor = positions.FirstOrDefault(ap => ap.Position == uv).Color; diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index b9a263870c..2875cdbc85 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -193,7 +193,7 @@ namespace OpenRA.Mods.Common.Widgets top = Math.Min(top, allTop.MinBy(uv => uv.V).V); if (allBottom.Any()) - bottom = Math.Max(bottom, allBottom.MinBy(uv => uv.V).V); + bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V); } var b = Rectangle.FromLTRB(left, top, right, bottom);