From 14f89b6799237c0d75d3a2a34f591636d605b2e6 Mon Sep 17 00:00:00 2001 From: lyrjie Date: Mon, 10 Feb 2020 12:32:59 +0300 Subject: [PATCH] Fix: Moai being buildable on forests, etc. (#1896) * Moved terrain.unbuildable check above moai coastal tile check * Refactor --- core/src/com/unciv/logic/map/TileInfo.kt | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index aed50c5876..fed5324893 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -235,23 +235,23 @@ open class TileInfo { return stats } + /** Returns true if the [improvement] can be built on this [TileInfo] */ fun canBuildImprovement(improvement: TileImprovement, civInfo: CivilizationInfo): Boolean { - if (isCityCenter() || improvement.name == this.improvement) return false - if(improvement.uniqueTo!=null && improvement.uniqueTo!=civInfo.civName) return false - if (improvement.techRequired != null && !civInfo.tech.isResearched(improvement.techRequired!!)) return false - val topTerrain = getLastTerrain() - if (improvement.terrainsCanBeBuiltOn.contains(topTerrain.name)) return true - - if (improvement.name == "Road" && this.roadStatus === RoadStatus.None) return true - if (improvement.name == "Railroad" && this.roadStatus !== RoadStatus.Railroad) return true - if(improvement.name == "Remove Road" && this.roadStatus===RoadStatus.Road) return true - if(improvement.name == "Remove Railroad" && this.roadStatus===RoadStatus.Railroad) return true - - if("Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile()) return true - if (topTerrain.unbuildable && !(topTerrain.name==Constants.forest && improvement.name=="Camp")) return false - return hasViewableResource(civInfo) && getTileResource().improvement == improvement.name - + return when { + isCityCenter() -> false + improvement.name == this.improvement -> false + improvement.uniqueTo?.equals(civInfo) == false -> false + improvement.techRequired?.let { civInfo.tech.isResearched(it) } == false -> false + improvement.terrainsCanBeBuiltOn.contains(topTerrain.name) -> true + improvement.name == "Road" && roadStatus == RoadStatus.None -> true + improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true + improvement.name == "Remove Road" && this.roadStatus == RoadStatus.Road -> true + improvement.name == "Remove Railroad" && this.roadStatus == RoadStatus.Railroad -> true + topTerrain.unbuildable && !(topTerrain.name == Constants.forest && improvement.name == "Camp") -> false + "Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile() -> true + else -> hasViewableResource(civInfo) && getTileResource().improvement == improvement.name + } } fun hasImprovementInProgress() = improvementInProgress!=null