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)
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
}

View File

@ -20,6 +20,7 @@ class CityConstructions {
var builtBuildings = ArrayList<String>()
val inProgressConstructions = HashMap<String, Int>()
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

View File

@ -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()
}