AI: update CreatesOneImprovement handling (#13497)

* Update

* Update Automation.kt

* Update Automation.kt

* Update Automation.kt

* Update Automation.kt
This commit is contained in:
EmperorPinguin 2025-06-26 22:45:06 +02:00 committed by GitHub
parent fce04aaddd
commit 86d7324298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 7 deletions

View File

@ -428,15 +428,24 @@ object Automation {
}
}
private fun improvementIsRemovable(city: City, tile: Tile): Boolean {
val stateForConditionals = StateForConditionals(city.civ, city, tile = tile)
return (tile.getTileImprovement()?.hasUnique(UniqueType.AutomatedUnitsWillNotReplace, stateForConditionals) == false && tile.getTileImprovement()?.hasUnique(UniqueType.Irremovable, stateForConditionals) == false)
}
/** Support [UniqueType.CreatesOneImprovement] unique - find best tile for placement automation */
fun getTileForConstructionImprovement(city: City, improvement: TileImprovement): Tile? {
val localUniqueCache = LocalUniqueCache()
val civ = city.civ
return city.getTiles().filter {
it.getTileImprovement()?.hasUnique(UniqueType.AutomatedUnitsWillNotReplace,
StateForConditionals(city.civ, city, tile = it)) == false
&& it.improvementFunctions.canBuildImprovement(improvement, city.civ)
(it.getTileImprovement() == null || improvementIsRemovable(city, it))
&& it.improvementFunctions.canBuildImprovement(improvement, civ)
}.maxByOrNull {
rankTileForCityWork(it, city, localUniqueCache)
// Needs to take into account future improvement layouts, and better placement of citadel-like improvements
rankStatsValue(it.stats.getStatDiffForImprovement(improvement, civ, city, localUniqueCache, it.stats.getTileStats(city, civ, localUniqueCache)), civ) + (
if (improvement.hasUnique(UniqueType.DefensiveBonus)) {
it.aerialDistanceTo(city.getCenterTile()) + it.getDefensiveBonus(false) }
else 0).toFloat()
}
}

View File

@ -164,8 +164,11 @@ class TileImprovementFunctions(val tile: Tile) {
tile.improvementIsPillaged = false
tile.improvement = improvementName
improvementFieldHasChanged = true
removeCreatesOneImprovementMarker()
if (improvementName != null && (improvementObject!!.hasUnique(UniqueType.Irremovable) || tile.isMarkedForCreatesOneImprovement(improvementName))) {
// I'm not sure what would happen if we try to replace an irremovable improvement
// Let's not cancel our "Districts" in progress unless when finishing it (don't mess it up with accidental worker movements etc.)
removeCreatesOneImprovementMarker()
}
}
}