From aa3be63492ca1e5d2a5ec4e4375a64bae8831793 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sat, 24 Jul 2021 20:45:51 +0200 Subject: [PATCH] Fix canImprovementBeBuiltHere regression (#4623) --- core/src/com/unciv/logic/map/TileInfo.kt | 7 ++-- .../map/TileImprovementConstructionTests.kt | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 2174f07431..3179427e61 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -430,9 +430,12 @@ open class TileInfo { // deprecated as of 3.15.15 "Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile() -> true // - improvement.uniqueObjects.filter { it.placeholderText == "Can only be built on [] tiles" }.all { - unique -> matchesTerrainFilter(unique.params[0]) + + // If an unique of this type exists, we want all to match (e.g. Hill _and_ Forest would be meaningful). + improvement.uniqueObjects.filter { it.placeholderText == "Can only be built on [] tiles" }.let { + it.any() && it.all { unique -> matchesTerrainFilter(unique.params[0]) } } -> true + else -> resourceIsVisible && getTileResource().improvement == improvement.name } } diff --git a/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt b/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt index 751ed1bcf1..a341745744 100644 --- a/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt +++ b/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt @@ -89,6 +89,19 @@ class TileImprovementConstructionTests { } } + @Test + fun coastalImprovementsCanNOTBeBuiltInland() { + tile.baseTerrain = "Plains" + tile.setTransients() + + for (improvement in ruleSet.tileImprovements.values) { + if (!improvement.uniques.contains("Can only be built on [Coastal] tiles")) continue + civInfo.civName = improvement.uniqueTo ?: "OtherCiv" + val canBeBuilt = tile.canBuildImprovement(improvement, civInfo) + Assert.assertFalse(improvement.name, canBeBuilt) + } + } + @Test fun uniqueToOtherImprovementsCanNOTBeBuilt() { for (improvement in ruleSet.tileImprovements.values) { @@ -101,6 +114,25 @@ class TileImprovementConstructionTests { } } + @Test + fun improvementsCanNOTBeBuiltOnWrongResource() { + tile.baseTerrain = "Plains" + civInfo.civName = "OtherCiv" + + for (resource in ruleSet.tileResources.values) { + if (resource.improvement == null) continue + val improvement = ruleSet.tileImprovements[resource.improvement]!! + if (improvement.terrainsCanBeBuiltOn.isNotEmpty()) continue + val wrongResource = ruleSet.tileResources.values.firstOrNull { + it != resource && it.improvement != improvement.name + } ?: continue + tile.resource = wrongResource.name + tile.setTransients() + val canBeBuilt = tile.canBuildImprovement(improvement, civInfo) + Assert.assertFalse(improvement.name, canBeBuilt) + } + } + @Test fun terraceFarmCanNOTBeBuiltOnBonus() { tile.baseTerrain = "Plains"