diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index 0bec480b1a..5fbc958a81 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -425,7 +425,11 @@ object SpecificUnitAutomation { //todo: maybe group by size and choose highest priority within the same size turns val closestCityThatCanAttackFrom = citiesThatCanAttackFrom.minByOrNull { pathsToCities[it]!!.size }!! val firstStepInPath = pathsToCities[closestCityThatCanAttackFrom]!!.first() - airUnit.movement.moveToTile(firstStepInPath) + try { + airUnit.movement.moveToTile(firstStepInPath) + }catch (ex:java.lang.Exception){ + println() + } } fun automateNukes(unit: MapUnit) { @@ -449,19 +453,20 @@ object SpecificUnitAutomation { private fun tryRelocateToNearbyAttackableCities(unit: MapUnit) { val tilesInRange = unit.currentTile.getTilesInDistance(unit.getRange()) val immediatelyReachableCities = tilesInRange - .filter { unit.movement.canMoveTo(it) } - - for (city in immediatelyReachableCities) { - if (city.getTilesInDistance(unit.getRange()) - .any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) }) { - unit.movement.moveToTile(city) - return - } - } + .filter { unit.movement.canMoveTo(it) } - val pathsToCities = unit.movement.getAerialPathsToCities() - if (pathsToCities.isEmpty()) return // can't actually move anywhere else - tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit) + for (city in immediatelyReachableCities) if (city.getTilesInDistance(unit.getRange()) + .any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) } + ) { + unit.movement.moveToTile(city) + return + } + + if (unit.baseUnit.isAirUnit()) { + val pathsToCities = unit.movement.getAerialPathsToCities() + if (pathsToCities.isEmpty()) return // can't actually move anywhere else + tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit) + } else UnitAutomation.tryHeadTowardsEnemyCity(unit) } private fun tryRelocateToCitiesWithEnemyNearBy(unit: MapUnit): Boolean { diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 02d7a35154..96760932ef 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -389,7 +389,7 @@ object UnitAutomation { return false } - private fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean { + fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean { if (unit.civInfo.cities.isEmpty()) return false // only focus on *attacking* 1 enemy at a time otherwise you'll lose on both fronts