Merge pull request #406 from ninjatao/fix_automate

chooseImprovement returns null when there is already better improvement.
This commit is contained in:
Yair Morgenstern 2019-01-07 08:12:50 +02:00 committed by GitHub
commit 911bd6fc67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -31,7 +31,7 @@ class WorkerAutomation(val unit: MapUnit) {
}
if (tile.improvementInProgress == null && tile.isLand()) {
val improvement = chooseImprovement(tile, unit.civInfo)
if (tile.canBuildImprovement(improvement, unit.civInfo)) {
if (improvement != null && tile.canBuildImprovement(improvement, unit.civInfo)) {
// What if we're stuck on this tile but can't build there?
tile.startWorkingOnImprovement(improvement, unit.civInfo)
return
@ -132,7 +132,7 @@ class WorkerAutomation(val unit: MapUnit) {
return priority
}
private fun chooseImprovement(tile: TileInfo, civInfo: CivilizationInfo): TileImprovement {
private fun chooseImprovement(tile: TileInfo, civInfo: CivilizationInfo): TileImprovement? {
val improvementStringForResource : String ?= when {
tile.resource == null || !tile.hasViewableResource(civInfo) -> null
tile.terrainFeature == "Marsh" -> "Remove Marsh"
@ -144,6 +144,7 @@ class WorkerAutomation(val unit: MapUnit) {
val improvementString = when {
tile.improvementInProgress != null -> tile.improvementInProgress
improvementStringForResource != null -> improvementStringForResource
tile.containsGreatImprovement() -> null
tile.terrainFeature == "Jungle" -> "Trading post"
tile.terrainFeature == "Marsh" -> "Remove Marsh"
tile.terrainFeature == "Forest" -> "Lumber mill"
@ -152,6 +153,7 @@ class WorkerAutomation(val unit: MapUnit) {
tile.baseTerrain == "Tundra" -> "Trading post"
else -> throw Exception("No improvement found for "+tile.baseTerrain)
}
if (improvementString == null) return null
return GameBasics.TileImprovements[improvementString]!!
}

View File

@ -184,7 +184,8 @@ open class TileInfo {
return stats
}
fun canBuildImprovement(improvement: TileImprovement, civInfo: CivilizationInfo): Boolean {
fun canBuildImprovement(improvement: TileImprovement?, civInfo: CivilizationInfo): Boolean {
if (improvement == null) return false
if (isCityCenter() || improvement.name == this.improvement) return false
val topTerrain = if (terrainFeature == null) getBaseTerrain() else getTerrainFeature()
if (improvement.techRequired != null && !civInfo.tech.isResearched(improvement.techRequired!!)) return false