Fix: Moai being buildable on forests, etc. (#1896)

* Moved terrain.unbuildable check above moai coastal tile check

* Refactor
This commit is contained in:
lyrjie 2020-02-10 12:32:59 +03:00 committed by GitHub
parent 6d2cf860a7
commit 14f89b6799

View File

@ -235,23 +235,23 @@ open class TileInfo {
return stats return stats
} }
/** Returns true if the [improvement] can be built on this [TileInfo] */
fun canBuildImprovement(improvement: TileImprovement, civInfo: CivilizationInfo): Boolean { 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() val topTerrain = getLastTerrain()
if (improvement.terrainsCanBeBuiltOn.contains(topTerrain.name)) return true return when {
isCityCenter() -> false
if (improvement.name == "Road" && this.roadStatus === RoadStatus.None) return true improvement.name == this.improvement -> false
if (improvement.name == "Railroad" && this.roadStatus !== RoadStatus.Railroad) return true improvement.uniqueTo?.equals(civInfo) == false -> false
if(improvement.name == "Remove Road" && this.roadStatus===RoadStatus.Road) return true improvement.techRequired?.let { civInfo.tech.isResearched(it) } == false -> false
if(improvement.name == "Remove Railroad" && this.roadStatus===RoadStatus.Railroad) return true improvement.terrainsCanBeBuiltOn.contains(topTerrain.name) -> true
improvement.name == "Road" && roadStatus == RoadStatus.None -> true
if("Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile()) return true improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true
if (topTerrain.unbuildable && !(topTerrain.name==Constants.forest && improvement.name=="Camp")) return false improvement.name == "Remove Road" && this.roadStatus == RoadStatus.Road -> true
return hasViewableResource(civInfo) && getTileResource().improvement == improvement.name 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 fun hasImprovementInProgress() = improvementInProgress!=null