diff --git a/android/assets/jsons/Civ V - Vanilla/TileImprovements.json b/android/assets/jsons/Civ V - Vanilla/TileImprovements.json index aad3f03325..74ef97ee31 100644 --- a/android/assets/jsons/Civ V - Vanilla/TileImprovements.json +++ b/android/assets/jsons/Civ V - Vanilla/TileImprovements.json @@ -206,7 +206,7 @@ "uniqueTo": "Polynesia", "culture": 1, "turnsToBuild": 4, - "uniques": ["[+1 Culture] for each adjacent [Moai]", "Can only be built on Coastal tiles", "[+1 Gold] once [Flight] is discovered"], + "uniques": ["[+1 Culture] for each adjacent [Moai]", "Can only be built on [Coastal] tiles", "[+1 Gold] once [Flight] is discovered"], "techRequired": "Construction", "shortcutKey": "M" }, @@ -216,7 +216,7 @@ "terrainsCanBeBuiltOn": ["Hill"], "food": 1, "turnsToBuild": 7, - "uniques": ["[+1 Food] for each adjacent [Mountain]", "Cannot be built on bonus resource", + "uniques": ["[+1 Food] for each adjacent [Mountain]", "Cannot be built on [Bonus resource] tiles", "[+1 Food] on [Fresh water] tiles once [Civil Service] is discovered", "[+1 Food] on [non-fresh water] tiles once [Fertilizer] is discovered"], "techRequired": "Construction", diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index a6c537e431..2174f07431 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -397,8 +397,10 @@ open class TileInfo { return when { improvement.name == this.improvement -> false isCityCenter() -> false - "Cannot be built on bonus resource" in improvement.uniques && resource != null + // deprecated as of 3.15.15 + "Cannot be built on bonus resource" in improvement.uniques && resource != null && getTileResource().resourceType == ResourceType.Bonus -> false + // improvement.uniqueObjects.filter { it.placeholderText == "Cannot be built on [] tiles" }.any { unique -> matchesTerrainFilter(unique.params[0]) } -> false @@ -425,10 +427,12 @@ open class TileInfo { topTerrain.unbuildable && !improvement.isAllowedOnFeature(topTerrain.name) -> false // DO NOT reverse this &&. isAdjacentToFreshwater() is a lazy which calls a function, and reversing it breaks the tests. improvement.hasUnique("Can also be built on tiles adjacent to fresh water") && isAdjacentToFreshwater -> true - "Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile() -> true - improvement.uniqueObjects.filter { it.placeholderText == "Can only be built on [] tiles" }.any { - unique -> !matchesTerrainFilter(unique.params[0]) - } -> false + // 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]) + } -> true else -> resourceIsVisible && getTileResource().improvement == improvement.name } } @@ -462,11 +466,16 @@ open class TileInfo { else -> { if (terrainFeatures.contains(filter)) return true if (hasUnique(filter)) return true + // Resource type check is last - cannot succeed if no resource here + if (resource == null) return false // Checks 'luxury resource', 'strategic resource' and 'bonus resource' - only those that are visible of course - if (observingCiv != null && hasViewableResource(observingCiv) - && getTileResource().resourceType.name + " resource" == filter) - return true - return false + // not using hasViewableResource as observingCiv is often not passed in, + // and we want to be able to at least test for non-strategic in that case. + val resourceObject = getTileResource() + if (resourceObject.resourceType.name + " resource" != filter) return false // filter match + if (resourceObject.revealedBy == null) return true // no need for tech + if (observingCiv == null) return false // can't check tech + return observingCiv.tech.isResearched(resourceObject.revealedBy!!) } } } diff --git a/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt b/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt index 70e9ebcc18..751ed1bcf1 100644 --- a/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt +++ b/tests/src/com/unciv/logic/map/TileImprovementConstructionTests.kt @@ -82,7 +82,7 @@ class TileImprovementConstructionTests { map.tileMatrix.add(arrayListOf(tile, otherTile)) for (improvement in ruleSet.tileImprovements.values) { - if (!improvement.uniques.contains("Can only be built on Coastal tiles")) continue + if (!improvement.uniques.contains("Can only be built on [Coastal] tiles")) continue civInfo.civName = improvement.uniqueTo ?: "OtherCiv" val canBeBuilt = tile.canBuildImprovement(improvement, civInfo) Assert.assertTrue(improvement.name, canBeBuilt) @@ -100,4 +100,19 @@ class TileImprovementConstructionTests { Assert.assertFalse(improvement.name, canBeBuilt) } } + + @Test + fun terraceFarmCanNOTBeBuiltOnBonus() { + tile.baseTerrain = "Plains" + tile.terrainFeatures.add("Hill") + tile.resource = "Sheep" + tile.setTransients() + civInfo.civName = "Inca" + + for (improvement in ruleSet.tileImprovements.values) { + if (!improvement.uniques.contains("Cannot be built on [Bonus resource] tiles")) continue + val canBeBuilt = tile.canBuildImprovement(improvement, civInfo) + Assert.assertFalse(improvement.name, canBeBuilt) + } + } } \ No newline at end of file