Special construction set by the user (Gold, Science etc) are not auto-changed when a better alternative exists

This commit is contained in:
Yair Morgenstern
2019-06-13 16:58:56 +03:00
parent 5ddd4c7d7b
commit ab1a1be170
3 changed files with 16 additions and 12 deletions

View File

@ -360,7 +360,7 @@ class NextTurnAutomation{
for (i in 0..city.population.population) for (i in 0..city.population.population)
city.population.autoAssignPopulation() city.population.autoAssignPopulation()
Automation().chooseNextConstruction(city.cityConstructions) city.cityConstructions.chooseNextConstruction()
if (city.health < city.getMaxHealth()) if (city.health < city.getMaxHealth())
Automation().trainMilitaryUnit(city) // override previous decision if city is under attack Automation().trainMilitaryUnit(city) // override previous decision if city is under attack
} }

View File

@ -20,6 +20,7 @@ class CityConstructions {
var builtBuildings = ArrayList<String>() var builtBuildings = ArrayList<String>()
val inProgressConstructions = HashMap<String, Int>() val inProgressConstructions = HashMap<String, Int>()
var currentConstruction: String = "Monument" // default starting building! var currentConstruction: String = "Monument" // default starting building!
var currentConstructionIsUserSet = false
//region pure functions //region pure functions
fun clone(): CityConstructions { fun clone(): CityConstructions {
@ -172,7 +173,7 @@ class CityConstructions {
if (!construction.isBuildable(this)) { if (!construction.isBuildable(this)) {
// We can't build this building anymore! (Wonder has been built / resource is gone / etc.) // 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) cityInfo.civInfo.addNotification("[${cityInfo.name}] cannot continue work on [$saveCurrentConstruction]", cityInfo.location, Color.BROWN)
chooseNextConstruction() cancelCurrentConstruction()
} else } else
currentConstruction = saveCurrentConstruction currentConstruction = saveCurrentConstruction
} }
@ -192,8 +193,7 @@ class CityConstructions {
} else } else
cityInfo.civInfo.addNotification("[$currentConstruction] has been built in [" + cityInfo.name + "]", cityInfo.location, Color.BROWN) cityInfo.civInfo.addNotification("[$currentConstruction] has been built in [" + cityInfo.name + "]", cityInfo.location, Color.BROWN)
currentConstruction = "" cancelCurrentConstruction()
chooseNextConstruction()
} }
fun addBuilding(buildingName:String){ fun addBuilding(buildingName:String){
@ -211,10 +211,8 @@ class CityConstructions {
fun purchaseBuilding(buildingName: String) { fun purchaseBuilding(buildingName: String) {
cityInfo.civInfo.gold -= getConstruction(buildingName).getGoldCost(cityInfo.civInfo) cityInfo.civInfo.gold -= getConstruction(buildingName).getGoldCost(cityInfo.civInfo)
getConstruction(buildingName).postBuildEvent(this) getConstruction(buildingName).postBuildEvent(this)
if (currentConstruction == buildingName) { if (currentConstruction == buildingName)
currentConstruction = "" cancelCurrentConstruction()
chooseNextConstruction()
}
cityInfo.cityStats.update() cityInfo.cityStats.update()
} }
@ -228,13 +226,18 @@ class CityConstructions {
if (buildableCultureBuildings.isEmpty()) return if (buildableCultureBuildings.isEmpty()) return
val cultureBuildingToBuild = buildableCultureBuildings.minBy { it.cost }!!.name val cultureBuildingToBuild = buildableCultureBuildings.minBy { it.cost }!!.name
addBuilding(cultureBuildingToBuild) addBuilding(cultureBuildingToBuild)
if (currentConstruction == cultureBuildingToBuild) { if (currentConstruction == cultureBuildingToBuild)
currentConstruction="" cancelCurrentConstruction()
chooseNextConstruction() }
}
fun cancelCurrentConstruction(){
currentConstructionIsUserSet=false
currentConstruction=""
chooseNextConstruction()
} }
fun chooseNextConstruction() { fun chooseNextConstruction() {
if(currentConstructionIsUserSet) return
Automation().chooseNextConstruction(this) Automation().chooseNextConstruction(this)
} }
//endregion //endregion

View File

@ -38,6 +38,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
pickProductionButton.onClick { pickProductionButton.onClick {
lastConstruction = cityScreen.city.cityConstructions.currentConstruction lastConstruction = cityScreen.city.cityConstructions.currentConstruction
cityScreen.city.cityConstructions.currentConstruction = construction cityScreen.city.cityConstructions.currentConstruction = construction
cityScreen.city.cityConstructions.currentConstructionIsUserSet=true
cityScreen.city.cityStats.update() cityScreen.city.cityStats.update()
cityScreen.update() cityScreen.update()
} }