From 1a021a21fed35e0d9fd27a5fed27899ff5978c68 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 8 Aug 2020 21:56:51 +0300 Subject: [PATCH] AI no longer uses all its aluminum on units and leaves some for spaceship construction --- .../com/unciv/logic/automation/Automation.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index ef6202b4f6..f16c9193c2 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -63,22 +63,25 @@ object Automation { if (militaryUnits.map { it.name }.contains(city.cityConstructions.currentConstructionFromQueue)) return city.cityConstructions.currentConstructionFromQueue - val findWaterConnectedCitiesAndEnemies = BFS(city.getCenterTile()){it.isWater || it.isCityCenter()} + // This is so that the AI doesn't use all its aluminum on units and have none left for spaceship parts + if (city.civInfo.getCivResourcesByName()["Aluminum"]!! < 2) + militaryUnits.filter { it.requiredResource != "Aluminum" } + + val findWaterConnectedCitiesAndEnemies = BFS(city.getCenterTile()) { it.isWater || it.isCityCenter() } findWaterConnectedCitiesAndEnemies.stepToEnd() - if(findWaterConnectedCitiesAndEnemies.tilesReached.keys.none { + if (findWaterConnectedCitiesAndEnemies.tilesReached.keys.none { (it.isCityCenter() && it.getOwner() != city.civInfo) || (it.militaryUnit != null && it.militaryUnit!!.civInfo != city.civInfo) }) // there is absolutely no reason for you to make water units on this body of water. militaryUnits = militaryUnits.filter { it.unitType.isLandUnit() || it.unitType.isAirUnit() } val chosenUnit: BaseUnit - if(!city.civInfo.isAtWar() && city.civInfo.cities.any { it.getCenterTile().militaryUnit==null} - && militaryUnits.any { it.unitType== UnitType.Ranged }) // this is for city defence so get an archery unit if we can - chosenUnit = militaryUnits.filter { it.unitType== UnitType.Ranged }.maxBy { it.cost }!! - - else{ // randomize type of unit and take the most expensive of its kind - val chosenUnitType = militaryUnits.map { it.unitType }.distinct().filterNot{it==UnitType.Scout}.toList().random() - chosenUnit = militaryUnits.filter { it.unitType==chosenUnitType }.maxBy { it.cost }!! + if (!city.civInfo.isAtWar() && city.civInfo.cities.any { it.getCenterTile().militaryUnit == null } + && militaryUnits.any { it.unitType == UnitType.Ranged }) // this is for city defence so get an archery unit if we can + chosenUnit = militaryUnits.filter { it.unitType == UnitType.Ranged }.maxBy { it.cost }!! + else { // randomize type of unit and take the most expensive of its kind + val chosenUnitType = militaryUnits.map { it.unitType }.distinct().filterNot { it == UnitType.Scout }.toList().random() + chosenUnit = militaryUnits.filter { it.unitType == chosenUnitType }.maxBy { it.cost }!! } return chosenUnit.name }