Skip to content

Commit e495209

Browse files
committed
Fix bug where building was not added to map if it had been placed only partially outside of the map (the placement tools allow it)
1 parent 21c7608 commit e495209

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/TSMapEditor/Initialization/MapLoader.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -396,40 +396,32 @@ public static void ReadBuildings(IMap map, IniFile mapIni)
396396

397397
FindAttachedTag(map, building, attachedTag);
398398

399-
bool isClear = true;
399+
bool isClear = false;
400400

401401
void CheckFoundationCell(Point2D cellCoords)
402402
{
403-
if (!isClear)
404-
return;
405-
406403
var tile = map.GetTile(cellCoords);
407-
if (tile == null)
408-
{
409-
isClear = false;
410-
AddMapLoadError(string.Format(Translate("MapLoader.CheckFoundationCell.TileOutOfBounds",
411-
"Building {0} has been placed outside of the map at {1}. Skipping adding it to map."),
412-
buildingType.ININame, cellCoords));
413-
return;
414-
}
415-
416-
if (tile.Structures.Count > 0)
404+
if (tile != null)
417405
{
418-
Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell at {cellCoords} that already contains other buildings: {string.Join(", ", tile.Structures.Select(s => s.ObjectType.ININame))}");
406+
isClear = true;
407+
tile.Structures.Add(building);
419408
}
420409
}
421410

411+
// Go through foundation cells and register the building to all tiles that are valid on its foundation.
412+
// If the building was added to no cells (all cells on its foundation were nonexistent),
413+
// then the building is outside of the map and we should not consider it as belonging to the map.
422414
buildingType.ArtConfig.DoForFoundationCoordsOrOrigin(offset => CheckFoundationCell(building.Position + offset));
423415

424416
if (!isClear)
417+
{
418+
AddMapLoadError(string.Format(Translate("MapLoader.CheckFoundationCell.TileOutOfBounds",
419+
"Building {0} has been placed outside of the map at {1}. Skipping adding it to map."),
420+
buildingType.ININame, building.Position));
425421
continue;
422+
}
426423

427424
map.Structures.Add(building);
428-
buildingType.ArtConfig.DoForFoundationCoordsOrOrigin(offset =>
429-
{
430-
var tile = map.GetTile(building.Position + offset);
431-
tile.Structures.Add(building);
432-
});
433425

434426
building.LightTiles(map.Tiles);
435427
}

0 commit comments

Comments
 (0)