From d298f85099539f4012e953e33ed56bae81b8bcb2 Mon Sep 17 00:00:00 2001 From: random271 <50424145+random271@users.noreply.github.com> Date: Wed, 28 Jun 2023 09:48:44 +0200 Subject: [PATCH] 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 --- .../src/com/unciv/logic/automation/unit/WorkerAutomation.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt index 8f8e99c997..732f7b13ea 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -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