From 8de47b4a627262bf7c7af22ec6b5eb8f23b8c6b0 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 2 Aug 2023 11:46:26 +0300 Subject: [PATCH] Resolved #9871 Workers now remove fallout and similar stat-hindering terrains --- .../com/unciv/logic/automation/unit/WorkerAutomation.kt | 4 ++-- core/src/com/unciv/logic/map/tile/TileStatFunctions.kt | 8 ++++++++ core/src/com/unciv/models/stats/Stats.kt | 1 + 3 files changed, 11 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 1c0511674d..b3d3a5c5db 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -342,12 +342,12 @@ class WorkerAutomation( val junkImprovement = tile.getTileImprovement()?.hasUnique(UniqueType.AutomatedWorkersWillReplace) == true || (tile.improvement == Constants.fort && !evaluateFortSuroundings(tile, false) && !civInfo.isHuman()) - if (tile.improvement != null && junkImprovement == false + if (tile.improvement != null && !junkImprovement && !UncivGame.Current.settings.automatedWorkersReplaceImprovements && unit.civ.isHuman()) return false - if (tile.improvement == null || junkImprovement == true) { + if (tile.improvement == null || junkImprovement) { if (tile.improvementInProgress != null && unit.canBuildImprovement(tile.getTileImprovementInProgress()!!, tile)) return true val chosenImprovement = chooseImprovement(unit, tile) if (chosenImprovement != null && tile.improvementFunctions.canBuildImprovement(chosenImprovement, civInfo) && unit.canBuildImprovement(chosenImprovement, tile)) return true diff --git a/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt b/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt index 5dfb799ecd..1de681845d 100644 --- a/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt +++ b/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt @@ -201,6 +201,14 @@ class TileStatFunctions(val tile: Tile) { city: City?, cityUniqueCache: LocalUniqueCache = LocalUniqueCache(false) ): Stats { + if (improvement.name.startsWith(Constants.remove)){ + val currentTileStats = getTileStats(city, observingCiv, cityUniqueCache) + val tileClone = tile.clone() + tileClone.removeTerrainFeature(improvement.name.removePrefix(Constants.remove)) + val tileStatsAfterRemoval = tileClone.stats.getTileStats(city, observingCiv, cityUniqueCache) + return tileStatsAfterRemoval.minus(currentTileStats) + } + val stats = improvement.cloneStats() if (tile.hasViewableResource(observingCiv) && tile.tileResource.isImprovedBy(improvement.name) && tile.tileResource.improvementStats != null diff --git a/core/src/com/unciv/models/stats/Stats.kt b/core/src/com/unciv/models/stats/Stats.kt index 78d3fb21e4..16bcf64d69 100644 --- a/core/src/com/unciv/models/stats/Stats.kt +++ b/core/src/com/unciv/models/stats/Stats.kt @@ -94,6 +94,7 @@ open class Stats( /** @return a new [Stats] instance containing the sum of its operands value by value */ operator fun plus(stats: Stats) = clone().apply { add(stats) } + operator fun minus(stats: Stats) = clone().apply { add(stats.times(-1)) } /** Adds the [value] parameter to the instance value specified by [stat] in place * @return `this` to allow chaining */