From 34664e6071afb067718e4b60baa1ec0644fc400e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 20 Apr 2022 12:50:30 +0300 Subject: [PATCH] Fixed bug with aircraft rejection reasons --- .../automation/SpecificUnitAutomation.kt | 19 ++++++++----------- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 1 + 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index 5fbc958a81..a57ea9aa67 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -414,22 +414,19 @@ object SpecificUnitAutomation { private fun tryMoveToCitiesToAerialAttackFrom(pathsToCities: HashMap>, airUnit: MapUnit) { val citiesThatCanAttackFrom = pathsToCities.keys - .filter { - destinationCity -> destinationCity != airUnit.currentTile - && destinationCity.getTilesInDistance(airUnit.getRange()) - .any { BattleHelper.containsAttackableEnemy(it, MapUnitCombatant(airUnit)) } - } + .filter { destinationCity -> + destinationCity != airUnit.currentTile + && destinationCity.getTilesInDistance(airUnit.getRange()) + .any { BattleHelper.containsAttackableEnemy(it, MapUnitCombatant(airUnit)) } + } if (citiesThatCanAttackFrom.isEmpty()) return //todo: this logic looks similar to some parts of automateFighter, maybe pull out common code //todo: maybe group by size and choose highest priority within the same size turns - val closestCityThatCanAttackFrom = citiesThatCanAttackFrom.minByOrNull { pathsToCities[it]!!.size }!! + val closestCityThatCanAttackFrom = + citiesThatCanAttackFrom.minByOrNull { pathsToCities[it]!!.size }!! val firstStepInPath = pathsToCities[closestCityThatCanAttackFrom]!!.first() - try { - airUnit.movement.moveToTile(firstStepInPath) - }catch (ex:java.lang.Exception){ - println() - } + airUnit.movement.moveToTile(firstStepInPath) } fun automateNukes(unit: MapUnit) { diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index fa3fc6dbbf..65603888f0 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -229,6 +229,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction { val unit = MapUnit() unit.name = name unit.civInfo = civInfo + unit.owner = civInfo.civName // must be after setting name & civInfo because it sets the baseUnit according to the name // and the civInfo is required for using `hasUnique` when determining its movement options