From b5d198adcdd52fb8d9fbfabc5fc275bd544e7684 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 17 Jul 2018 23:05:55 +0300 Subject: [PATCH] AI examines city construction each turn, in case there's something better to build --- .../com/unciv/logic/automation/Automation.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index 9ae2e3aaf9..0f0fd5d193 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -18,7 +18,7 @@ class Automation { val stats = tile.getTileStats(null, civInfo) var rank = 0.0f if (stats.food <= 2) rank += stats.food - else rank += (2 + (stats.food - 2) / 2f) // 1 point for each food up to 2, from there on half a point + else rank += (2 + (stats.food - 2) / 2) // 1 point for each food up to 2, from there on half a point if(civInfo.gold>0 && civInfo.getStatsForNextTurn().gold>0) rank += stats.gold / 2 else rank += stats.gold rank += stats.production @@ -73,6 +73,17 @@ class Automation { for (unit in rangedUnits) UnitAutomation().automateUnitMoves(unit) for (unit in meleeUnits) UnitAutomation().automateUnitMoves(unit) + + for (city in civInfo.cities) { + // reassign everyone from scratch + city.workedTiles.clear() + (0..city.population.population).forEach { city.population.autoAssignPopulation()} + chooseNextConstruction(city.cityConstructions) + if (city.health < city.getMaxHealth()) + trainCombatUnit(city) // override previous decision if city is under attack + } + + // train settler? if (civInfo.cities.any() && civInfo.happiness > civInfo.cities.size +5 @@ -84,13 +95,6 @@ class Automation { bestCity.cityConstructions.currentConstruction = "Settler" } - for (city in civInfo.cities) { - if (city.health < city.getMaxHealth()) trainCombatUnit(city) - // reassign everyone from scratch - city.workedTiles.clear() - (0..city.population.population).forEach { city.population.autoAssignPopulation()} - } - } private fun trainCombatUnit(city: CityInfo) { @@ -111,6 +115,9 @@ class Automation { fun chooseNextConstruction(cityConstructions: CityConstructions) { cityConstructions.run { + currentConstruction="" // This is so that if we're currently in the middle of building a wonder, + // buildableWonders will still contain it + val buildableNotWonders = getBuildableBuildings().filterNot { it.isWonder } val buildableWonders = getBuildableBuildings().filter { it.isWonder }