From e111bba509511092df28488362aa1f8053db6ddd Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 31 Aug 2020 22:39:03 +0300 Subject: [PATCH] #3050 - Added "automated workers don't replace improvements" setting --- .../jsons/translations/template.properties | 1 + .../logic/automation/WorkerAutomation.kt | 24 +++++++++---------- .../com/unciv/models/metadata/GameSettings.kt | 2 ++ .../mainmenu/WorldScreenOptionsPopup.kt | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 75230ab2..9507c6e0 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -342,6 +342,7 @@ Move units with a single tap = Show tutorials = Auto-assign city production = Auto-build roads = +Automated workers replace improvements = Show minimap = Show pixel units = Show pixel improvements = diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index c42bf81c..707036a1 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -144,16 +144,17 @@ class WorkerAutomation(val unit: MapUnit) { private fun tileCanBeImproved(tile: TileInfo, civInfo: CivilizationInfo): Boolean { if (!tile.isLand || tile.isImpassible() || tile.isCityCenter()) return false - val city=tile.getCity() + val city = tile.getCity() if (city == null || city.civInfo != civInfo) return false + if (tile.improvement != null && !UncivGame.Current.settings.automatedWorkersReplaceImprovements) + return false - if(tile.improvement==null){ - if(tile.improvementInProgress!=null) return true + if (tile.improvement == null) { + if (tile.improvementInProgress != null) return true val chosenImprovement = chooseImprovement(tile, civInfo) - if(chosenImprovement!=null && tile.canBuildImprovement(chosenImprovement, civInfo)) return true - } - else if(!tile.containsGreatImprovement() && tile.hasViewableResource(civInfo) + if (chosenImprovement != null && tile.canBuildImprovement(chosenImprovement, civInfo)) return true + } else if (!tile.containsGreatImprovement() && tile.hasViewableResource(civInfo) && tile.getTileResource().improvement != tile.improvement && tile.canBuildImprovement(chooseImprovement(tile, civInfo)!!, civInfo)) return true @@ -178,10 +179,10 @@ class WorkerAutomation(val unit: MapUnit) { private fun chooseImprovement(tile: TileInfo, civInfo: CivilizationInfo): TileImprovement? { val improvementStringForResource : String ?= when { tile.resource == null || !tile.hasViewableResource(civInfo) -> null - tile.terrainFeature == Constants.marsh && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Marsh" - tile.terrainFeature == "Fallout" && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Fallout" // for really mad modders - tile.terrainFeature == Constants.jungle && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Jungle" - tile.terrainFeature == Constants.forest && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Forest" + tile.terrainFeature == Constants.marsh && !isImprovementOnFeatureAllowed(tile, civInfo) -> "Remove Marsh" + tile.terrainFeature == "Fallout" && !isImprovementOnFeatureAllowed(tile, civInfo) -> "Remove Fallout" // for really mad modders + tile.terrainFeature == Constants.jungle && !isImprovementOnFeatureAllowed(tile, civInfo) -> "Remove Jungle" + tile.terrainFeature == Constants.forest && !isImprovementOnFeatureAllowed(tile, civInfo) -> "Remove Forest" else -> tile.getTileResource().improvement } @@ -214,9 +215,6 @@ class WorkerAutomation(val unit: MapUnit) { return unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementString] // For mods, the tile improvement may not exist, so don't assume. } private fun isImprovementOnFeatureAllowed(tile: TileInfo, civInfo: CivilizationInfo): Boolean { - // Old hardcoded logic amounts to: - //return tile.terrainFeature == Constants.forest && tile.getTileResource().improvement == "Camp" - // routine assumes the caller ensured that terrainFeature and resource are both present val resourceImprovementName = tile.getTileResource().improvement ?: return false diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 0b247639..18c84ea2 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -23,6 +23,8 @@ class GameSettings { var showTutorials: Boolean = true var autoAssignCityProduction: Boolean = true var autoBuildingRoads: Boolean = true + var automatedWorkersReplaceImprovements = true + var showMinimap: Boolean = true var showPixelUnits: Boolean = false var showPixelImprovements: Boolean = true diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt index 7a906c23..63015ae5 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt @@ -109,6 +109,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen) } } addYesNoRow ("Auto-build roads", settings.autoBuildingRoads) { settings.autoBuildingRoads = it } + addYesNoRow ("Automated workers replace improvements", settings.automatedWorkersReplaceImprovements) { settings.automatedWorkersReplaceImprovements = it } addYesNoRow ("Order trade offers by amount", settings.orderTradeOffersByAmount) { settings.orderTradeOffersByAmount = it } addAutosaveTurnsSelectBox()