From ab1a1be1709644f28c981a7a1953fe0a58b80d89 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 13 Jun 2019 16:58:56 +0300 Subject: [PATCH] Special construction set by the user (Gold, Science etc) are not auto-changed when a better alternative exists --- .../logic/automation/NextTurnAutomation.kt | 2 +- .../com/unciv/logic/city/CityConstructions.kt | 25 +++++++++++-------- .../unciv/ui/cityscreen/ConstructionsTable.kt | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index c8935db31c..c914aee75f 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -360,7 +360,7 @@ class NextTurnAutomation{ for (i in 0..city.population.population) city.population.autoAssignPopulation() - Automation().chooseNextConstruction(city.cityConstructions) + city.cityConstructions.chooseNextConstruction() if (city.health < city.getMaxHealth()) Automation().trainMilitaryUnit(city) // override previous decision if city is under attack } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 434aec7780..bc82835a3b 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -20,6 +20,7 @@ class CityConstructions { var builtBuildings = ArrayList() val inProgressConstructions = HashMap() var currentConstruction: String = "Monument" // default starting building! + var currentConstructionIsUserSet = false //region pure functions fun clone(): CityConstructions { @@ -172,7 +173,7 @@ class CityConstructions { if (!construction.isBuildable(this)) { // We can't build this building anymore! (Wonder has been built / resource is gone / etc.) cityInfo.civInfo.addNotification("[${cityInfo.name}] cannot continue work on [$saveCurrentConstruction]", cityInfo.location, Color.BROWN) - chooseNextConstruction() + cancelCurrentConstruction() } else currentConstruction = saveCurrentConstruction } @@ -192,8 +193,7 @@ class CityConstructions { } else cityInfo.civInfo.addNotification("[$currentConstruction] has been built in [" + cityInfo.name + "]", cityInfo.location, Color.BROWN) - currentConstruction = "" - chooseNextConstruction() + cancelCurrentConstruction() } fun addBuilding(buildingName:String){ @@ -211,10 +211,8 @@ class CityConstructions { fun purchaseBuilding(buildingName: String) { cityInfo.civInfo.gold -= getConstruction(buildingName).getGoldCost(cityInfo.civInfo) getConstruction(buildingName).postBuildEvent(this) - if (currentConstruction == buildingName) { - currentConstruction = "" - chooseNextConstruction() - } + if (currentConstruction == buildingName) + cancelCurrentConstruction() cityInfo.cityStats.update() } @@ -228,13 +226,18 @@ class CityConstructions { if (buildableCultureBuildings.isEmpty()) return val cultureBuildingToBuild = buildableCultureBuildings.minBy { it.cost }!!.name addBuilding(cultureBuildingToBuild) - if (currentConstruction == cultureBuildingToBuild) { - currentConstruction="" - chooseNextConstruction() - } + if (currentConstruction == cultureBuildingToBuild) + cancelCurrentConstruction() + } + + fun cancelCurrentConstruction(){ + currentConstructionIsUserSet=false + currentConstruction="" + chooseNextConstruction() } fun chooseNextConstruction() { + if(currentConstructionIsUserSet) return Automation().chooseNextConstruction(this) } //endregion diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index 322c611d37..1075e7fabb 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -38,6 +38,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre pickProductionButton.onClick { lastConstruction = cityScreen.city.cityConstructions.currentConstruction cityScreen.city.cityConstructions.currentConstruction = construction + cityScreen.city.cityConstructions.currentConstructionIsUserSet=true cityScreen.city.cityStats.update() cityScreen.update() }