Fixing workers dying in mountains bug for Carthage (#9665)

* Fixed workers dying in mountain tiles issue for Carthage

* Accounts for all damage dealing tiles

* Update WorkerAutomation.kt

* Update Tile.kt

* Update WorkerAutomation.kt

* Update WorkerAutomation.kt
This commit is contained in:
random271 2023-06-28 09:48:44 +02:00 committed by GitHub
parent 73fa87e6b4
commit d298f85099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -270,7 +270,7 @@ class WorkerAutomation(
.filter {
it !in tilesToAvoid
&& (it.civilianUnit == null || it == currentTile)
&& (it.owningCity == null || it.getOwner()==civInfo)
&& (it.owningCity == null || it.getOwner() == civInfo)
&& getPriority(it) > 1
&& it.getTilesInDistance(2) // don't work in range of enemy cities
.none { tile -> tile.isCityCenter() && tile.getCity()!!.civ.isAtWarWith(civInfo) }
@ -279,9 +279,11 @@ class WorkerAutomation(
}
.sortedByDescending { getPriority(it) }
// Carthage can move through mountains, special case
// If there is a non-damage dealing tile available, move to that tile, otherwise move to the damage dealing tile
// These are the expensive calculations (tileCanBeImproved, canReach), so we only apply these filters after everything else it done.
val selectedTile =
workableTiles.firstOrNull { unit.movement.canReach(it) && (tileCanBeImproved(unit, it) || it.isPillaged()) }
workableTiles.sortedByDescending { tile -> unit.getDamageFromTerrain(tile) <= 0 }.firstOrNull { unit.movement.canReach(it) && (tileCanBeImproved(unit, it) || it.isPillaged()) }
?: return currentTile
return if ((!tileCanBeImproved(unit, currentTile) && !currentTile.isPillaged()) // current tile is unimprovable