mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-24 18:06:04 +07:00
Fix loop when AI is trying to remove an improvement with the same name as a terrain feature (#11352)
* Fix loop when AI is trying to remove an improvement with the same name as a terrain feature * whoops
This commit is contained in:
parent
c5611e9588
commit
e17229779a
@ -394,15 +394,22 @@ class WorkerAutomation(
|
||||
|
||||
val stats = tile.stats.getStatDiffForImprovement(improvement, civInfo, tile.getCity(), localUniqueCache)
|
||||
|
||||
if (improvementName.startsWith("Remove ")) {
|
||||
if (improvementName.startsWith(Constants.remove)) {
|
||||
// We need to look beyond what we are doing right now and at the final improvement that will be on this tile
|
||||
val terrainName = improvementName.replace("Remove ", "")
|
||||
if (ruleSet.terrains.containsKey(terrainName)) { // Otherwise we get an infinite loop with remove roads
|
||||
tile.removeTerrainFeature(terrainName)
|
||||
val wantedFinalImprovement = chooseImprovement(unit, tile)
|
||||
val removedObject = improvementName.replace(Constants.remove, "")
|
||||
val removedFeature = tile.terrainFeatures.firstOrNull { it == removedObject }
|
||||
val removedImprovement = if (removedObject == tile.improvement) removedObject else null
|
||||
|
||||
if (removedFeature != null || removedImprovement != null) {
|
||||
val newTile = tile.clone()
|
||||
newTile.setTerrainTransients()
|
||||
if (removedFeature != null)
|
||||
newTile.removeTerrainFeature(removedFeature)
|
||||
if (removedImprovement != null)
|
||||
newTile.removeImprovement()
|
||||
val wantedFinalImprovement = chooseImprovement(unit, newTile)
|
||||
if (wantedFinalImprovement != null)
|
||||
stats.add(tile.stats.getStatDiffForImprovement(wantedFinalImprovement, civInfo, tile.getCity(), localUniqueCache))
|
||||
tile.addTerrainFeature(terrainName)
|
||||
stats.add(newTile.stats.getStatDiffForImprovement(wantedFinalImprovement, civInfo, newTile.getCity(), localUniqueCache))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user