From cba9995f99a8d55f6a99195e02f99f762178b295 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 27 Jun 2020 23:40:40 +0300 Subject: [PATCH] Fixed natural wonders not being considered 'impassible' for certain things (e.g. ancient ruins spawn) --- core/src/com/unciv/logic/GameInfo.kt | 5 ++--- core/src/com/unciv/logic/GameStarter.kt | 4 ++-- core/src/com/unciv/logic/automation/NextTurnAutomation.kt | 2 +- core/src/com/unciv/logic/automation/WorkerAutomation.kt | 2 +- core/src/com/unciv/logic/map/TileInfo.kt | 3 ++- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 2 +- core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt | 6 +++--- core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt | 6 +++--- core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 52fb0227c1..6f767f9819 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -183,9 +183,8 @@ class GameInfo { val tilesWithin3ofExistingEncampment = existingEncampments.asSequence() .flatMap { it.getTilesInDistance(3) }.toSet() val viableTiles = tileMap.values.filter { - !it.getBaseTerrain().impassable && it.isLand - && it.terrainFeature == null - && it.naturalWonder == null + it.isLand && it.terrainFeature == null + && !it.isImpassible() && it !in tilesWithin3ofExistingEncampment && it !in allViewableTiles } diff --git a/core/src/com/unciv/logic/GameStarter.kt b/core/src/com/unciv/logic/GameStarter.kt index e389d06020..7f4a9452fc 100644 --- a/core/src/com/unciv/logic/GameStarter.kt +++ b/core/src/com/unciv/logic/GameStarter.kt @@ -156,11 +156,11 @@ object GameStarter { private fun getStartingLocations(civs: List, tileMap: TileMap): HashMap { var landTiles = tileMap.values // Games starting on snow might as well start over... - .filter { it.isLand && !it.getBaseTerrain().impassable && it.baseTerrain!=Constants.snow } + .filter { it.isLand && !it.isImpassible() && it.baseTerrain!=Constants.snow } val landTilesInBigEnoughGroup = ArrayList() while (landTiles.any()) { - val bfs = BFS(landTiles.random()) { it.isLand && !it.getBaseTerrain().impassable } + val bfs = BFS(landTiles.random()) { it.isLand && !it.isImpassible() } bfs.stepToEnd() val tilesInGroup = bfs.tilesReached.keys landTiles = landTiles.filter { it !in tilesInGroup } diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index cea5c8f55a..b126ebcd56 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -429,7 +429,7 @@ object NextTurnAutomation{ val landPathBFS = BFS(ourCity.getCenterTile()) { val owner = it.getOwner(); - it.isLand && !it.getBaseTerrain().impassable + it.isLand && !it.isImpassible() && (owner == otherCiv || owner == null || civInfo.canEnterTiles(owner)) } diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index e21081d8d9..9fddc5fad8 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -139,7 +139,7 @@ class WorkerAutomation(val unit: MapUnit) { } private fun tileCanBeImproved(tile: TileInfo, civInfo: CivilizationInfo): Boolean { - if (!tile.isLand || tile.getBaseTerrain().impassable || tile.isCityCenter()) + if (!tile.isLand || tile.isImpassible() || tile.isCityCenter()) return false val city=tile.getCity() if (city == null || city.civInfo != civInfo) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 29fb7509f5..ab8ae31fbe 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -111,6 +111,7 @@ open class TileInfo { fun isCityCenter(): Boolean = getCity()?.location == position fun isNaturalWonder(): Boolean = naturalWonder != null + fun isImpassible() = getLastTerrain().impassable fun getTileImprovement(): TileImprovement? = if (improvement == null) null else ruleset.tileImprovements[improvement!!] @@ -400,7 +401,7 @@ open class TileInfo { if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString" lineList += "[$defencePercentString] to unit defence".tr() } - if (getBaseTerrain().impassable) lineList += Constants.impassable.tr() + if (isImpassible()) lineList += Constants.impassable.tr() return lineList.joinToString("\n") } diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 21267faa4f..bc718c0113 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -327,7 +327,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { // so multiple callees of this function have been optimized, // because optimization on this function results in massive benefits! fun canPassThrough(tile: TileInfo): Boolean { - if (tile.getBaseTerrain().impassable) return false + if (tile.isImpassible()) return false if (tile.isLand && unit.type.isWaterUnit() // Check that the tile is not a coastal city's center diff --git a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt index 0eb3ffa7ce..e9f04b6ea4 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt @@ -104,7 +104,7 @@ class MapGenerator(val ruleset: Ruleset) { private fun spreadAncientRuins(map: TileMap) { if(map.mapParameters.noRuins) return - val suitableTiles = map.values.filter { it.isLand && !it.getBaseTerrain().impassable } + val suitableTiles = map.values.filter { it.isLand && !it.isImpassible() } val locations = randomness.chooseSpreadOutLocations(suitableTiles.size/100, suitableTiles, 10) for(tile in locations) @@ -126,7 +126,7 @@ class MapGenerator(val ruleset: Ruleset) { private fun spreadStrategicResources(tileMap: TileMap, distance: Int) { val strategicResources = ruleset.tileResources.values.filter { it.resourceType == ResourceType.Strategic } // passable land tiles (no mountains, no wonders) without resources yet - val candidateTiles = tileMap.values.filter { it.resource == null && !it.getLastTerrain().impassable } + val candidateTiles = tileMap.values.filter { it.resource == null && !it.isImpassible() } val totalNumberOfResources = candidateTiles.size * tileMap.mapParameters.resourceRichness val resourcesPerType = (totalNumberOfResources/strategicResources.size).toInt() for (resource in strategicResources) { @@ -150,7 +150,7 @@ class MapGenerator(val ruleset: Ruleset) { val suitableTiles = tileMap.values .filter { it.resource == null && resourcesOfType.any { r -> r.terrainsCanBeFoundOn.contains(it.getLastTerrain().name) } } - val numberOfResources = tileMap.values.count { it.isLand && !it.getBaseTerrain().impassable } * + val numberOfResources = tileMap.values.count { it.isLand && !it.isImpassible() } * tileMap.mapParameters.resourceRichness val locations = randomness.chooseSpreadOutLocations(numberOfResources.toInt(), suitableTiles, distance) diff --git a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt index f37250b1e0..6af4b5f50c 100644 --- a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt @@ -503,18 +503,18 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera if (tileInfo.improvement!=null) { normalizeTileImprovement(tileInfo) } - if (tileInfo.getBaseTerrain().impassable || tileInfo.isWater) + if (tileInfo.isWater || tileInfo.isImpassible()) tileInfo.roadStatus= RoadStatus.None } private fun normalizeTileImprovement(tileInfo: TileInfo) { + val topTerrain = tileInfo.getLastTerrain() if (tileInfo.improvement!!.startsWith("StartingLocation")) { - if (!tileInfo.isLand || tileInfo.getBaseTerrain().impassable) + if (!tileInfo.isLand || topTerrain.impassable) tileInfo.improvement = null return } val improvement = tileInfo.getTileImprovement()!! - val topTerrain = tileInfo.getLastTerrain() val resource = if (tileInfo.resource!=null) tileInfo.getTileResource() else null when { // Precedence, simplified: terrainsCanBeBuiltOn, then improves-resource, then 'everywhere', default to false diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index a25c1ab04c..1879b6eece 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -376,7 +376,7 @@ object UnitActions { addGoldPerGreatPersonUsage(unit.civInfo) unit.destroy() }.takeIf { unit.currentMovement > 0f && !tile.isWater && - !tile.isCityCenter() && !tile.getLastTerrain().impassable && + !tile.isCityCenter() && !tile.isImpassible() && tile.improvement != improvementName && // citadel can be built only next to or within own borders (improvementName != Constants.citadel ||