From 15a17335c14092d81ca047c7891e4d806d7e056c Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Sun, 31 Dec 2023 15:06:14 -0600 Subject: [PATCH] Worker remove feature far away from cities fix (#10847) * Worker AI doesn't remove forests and marshes away from their borders. * Reverted a previous change that slipped into this branch --- .../unciv/logic/automation/unit/WorkerAutomation.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt index e0568a1570..4f9f1ab215 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -25,6 +25,7 @@ import com.unciv.models.ruleset.tile.Terrain import com.unciv.models.ruleset.tile.TileImprovement import com.unciv.models.ruleset.unique.LocalUniqueCache import com.unciv.models.ruleset.unique.UniqueType +import com.unciv.models.stats.Stats import com.unciv.ui.screens.worldscreen.unit.actions.UnitActions import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsFromUniques import com.unciv.utils.Log @@ -644,7 +645,14 @@ class WorkerAutomation( private fun getImprovementRanking(tile: Tile, unit: MapUnit, improvementName: String, localUniqueCache: LocalUniqueCache): Float { val improvement = ruleSet.tileImprovements[improvementName]!! - val stats = tile.stats.getStatDiffForImprovement(improvement, civInfo, tile.getCity(), localUniqueCache) + var stats = Stats() + if (tile.getOwner() == unit.civ) + stats = tile.stats.getStatDiffForImprovement(improvement, civInfo, tile.getCity(), localUniqueCache) + // We could expand to this tile in the future + else if (ruleSet.tileImprovements[improvementName]!!.hasUnique(UniqueType.CanBuildOutsideBorders) && + tile.neighbors.any {it.getOwner() == unit.civ && it.owningCity != null && tile.aerialDistanceTo(it.owningCity!!.getCenterTile()) <= 3}) + stats = tile.stats.getStatDiffForImprovement(improvement, civInfo, tile.getCity(), localUniqueCache).div(3f) + var value = Automation.rankStatsValue(stats, unit.civ) // Calculate the bonus from gaining the resources, this isn't included in the stats above if (tile.resource != null && tile.tileResource.resourceType != ResourceType.Bonus) {