Add option to Enable/Disable unit upgrades for automated units (#9941)

* Add option to enable/disable unit upgrades for automated units

* Add automated unit upgrade String to template.properties

* Change check for isPlayer to isHuman when performing upgrades for automated units
This commit is contained in:
John McDonnell 2023-08-21 18:16:59 +03:00 committed by GitHub
parent f7415bf0a9
commit 56a3f298ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

View File

@ -767,6 +767,7 @@ Auto-assign city production =
Auto-build roads =
Automated workers replace improvements =
Automated units move on turn start =
Automated units can upgrade =
Order trade offers by amount =
Ask for confirmation when pressing next turn =
Notifications log max turns =

View File

@ -1,6 +1,7 @@
package com.unciv.logic.automation.unit
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.automation.Automation
import com.unciv.logic.automation.civilization.NextTurnAutomation
import com.unciv.logic.battle.Battle
@ -17,6 +18,7 @@ import com.unciv.logic.civilization.managers.ReligionState
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.Tile
import com.unciv.models.UnitActionType
import com.unciv.models.metadata.GameSettings
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActions
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsPillage
@ -128,6 +130,8 @@ object UnitAutomation {
}
internal fun tryUpgradeUnit(unit: MapUnit): Boolean {
val isHuman = unit.civ.isHuman()
if (!UncivGame.Current.settings.automatedUnitsCanUpgrade && isHuman) return false
if (unit.baseUnit.upgradesTo == null) return false
val upgradedUnit = unit.upgrade.getUnitToUpgradeTo()
if (!upgradedUnit.isBuildable(unit.civ)) return false // for resource reasons, usually

View File

@ -71,6 +71,7 @@ class GameSettings {
var autoBuildingRoads: Boolean = true
var automatedWorkersReplaceImprovements = true
var automatedUnitsMoveOnTurnStart: Boolean = false
var automatedUnitsCanUpgrade: Boolean = true
var showMinimap: Boolean = true
var minimapSize: Int = 6 // default corresponds to 15% screen space

View File

@ -42,6 +42,11 @@ fun gameplayTab(
"Automated units move on turn start",
settings.automatedUnitsMoveOnTurnStart, true
) { settings.automatedUnitsMoveOnTurnStart = it }
optionsPopup.addCheckbox(
this,
"Automated units can upgrade",
settings.automatedUnitsCanUpgrade, true
) { settings.automatedUnitsCanUpgrade = it }
optionsPopup.addCheckbox(this, "Order trade offers by amount", settings.orderTradeOffersByAmount) { settings.orderTradeOffersByAmount = it }
optionsPopup.addCheckbox(this, "Ask for confirmation when pressing next turn", settings.confirmNextTurn) { settings.confirmNextTurn = it }