Skip to content

Commit e03c2f7

Browse files
committed
Fix depth of large terrain objects with impassable cells
1 parent 9faf37c commit e03c2f7

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/TSMapEditor/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace TSMapEditor
55
{
66
public static class Constants
77
{
8-
public const string ReleaseVersion = "1.3.4";
8+
public const string ReleaseVersion = "1.3.5";
99

1010
public static int CellSizeX = 48;
1111
public static int CellSizeY = 24;

src/TSMapEditor/Rendering/ObjectRenderers/ObjectRenderer.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private float GetDepthFromPosition(T gameObject)
299299

300300
private MapTile GetSouthernmostCell(T gameObject)
301301
{
302-
MapTile tile;
302+
MapTile tile = null;
303303

304304
if (gameObject.WhatAmI() == RTTIType.Building)
305305
{
@@ -309,6 +309,33 @@ private MapTile GetSouthernmostCell(T gameObject)
309309
if (tile == null)
310310
tile = Map.GetTile(structure.Position);
311311
}
312+
else if (gameObject.WhatAmI() == RTTIType.Terrain)
313+
{
314+
var terrainObject = gameObject as TerrainObject;
315+
316+
// If the terrain object is larger than 1x1, we might need to handle it more like structures.
317+
// We can do this by looking at its impassable cell configuration.
318+
if (terrainObject.TerrainType.ImpassableCells != null)
319+
{
320+
int maxX = 0;
321+
int maxY = 0;
322+
for (int i = 0; i < terrainObject.TerrainType.ImpassableCells.Count; i++)
323+
{
324+
var impassableCellOffset = terrainObject.TerrainType.ImpassableCells[i];
325+
if (impassableCellOffset.X > maxX)
326+
maxX = impassableCellOffset.X;
327+
328+
if (impassableCellOffset.Y > maxY)
329+
maxY = impassableCellOffset.Y;
330+
}
331+
332+
Point2D southernmostCellCoords = terrainObject.Position + new Point2D(maxX, maxY);
333+
tile = Map.GetTile(southernmostCellCoords);
334+
}
335+
336+
if (tile == null)
337+
tile = Map.GetTile(terrainObject.Position);
338+
}
312339
else
313340
{
314341
tile = Map.GetTile(gameObject.Position);

0 commit comments

Comments
 (0)