From 68ee549edb0b53d2a8bacf371233e9fcb4b12d8f Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 29 Nov 2019 12:01:32 +0200 Subject: [PATCH] Map editor normalizes tiles, so you can't add improvements of features where they shouldn't belong Placing a civ starting location removes older starting locations --- .../ui/mapeditor/TileEditorOptionsTable.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt index 3196ab7fb3..ffb078c28b 100644 --- a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt @@ -307,11 +307,48 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera if (improvement.name == "Road") tileInfo.roadStatus = RoadStatus.Road else if (improvement.name == "Railroad") tileInfo.roadStatus = RoadStatus.Railroad else tileInfo.improvement = improvement.name + + if(improvement.name.startsWith("StartingLocation")) + for(tileGroup in mapEditorScreen.mapHolder.tileGroups){ + val tile = tileGroup.tileInfo + if(tile.improvement==improvement.name && tile!=tileInfo) + tile.improvement=null + tile.setTransients() + tileGroup.update() + } } toggleBottomLeftRiver -> tileInfo.hasBottomLeftRiver = !tileInfo.hasBottomLeftRiver toggleBottomRiver -> tileInfo.hasBottomRiver = !tileInfo.hasBottomRiver toggleBottomRightRiver -> tileInfo.hasBottomRightRiver = !tileInfo.hasBottomRightRiver } + + normalizeTile(tileInfo) + tileInfo.setTransients() + } + + fun normalizeTile(tileInfo: TileInfo){ + if(tileInfo.terrainFeature!=null){ + val terrainFeature = tileInfo.getTerrainFeature()!! + if(terrainFeature.occursOn!=null && !terrainFeature.occursOn.contains(tileInfo.baseTerrain)) + tileInfo.terrainFeature=null + } + if(tileInfo.resource!=null){ + val resource = tileInfo.getTileResource() + if(resource.terrainsCanBeFoundOn.none { it==tileInfo.baseTerrain || it==tileInfo.terrainFeature }) + tileInfo.resource=null + } + if(tileInfo.improvement!=null){ + if(tileInfo.improvement!!.startsWith("StartingLocation")){ + if(tileInfo.isWater || tileInfo.getBaseTerrain().impassable) + tileInfo.improvement=null + } + else { + val improvement = tileInfo.getTileImprovement()!! + if (improvement.terrainsCanBeBuiltOn.isNotEmpty() // for "everywhere" improvements like city ruins, encampments, ancient ruins + && improvement.terrainsCanBeBuiltOn.none { it == tileInfo.baseTerrain || it == tileInfo.terrainFeature }) + tileInfo.improvement = null + } + } }