diff --git a/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt index d653188319..b718c5d698 100644 --- a/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt @@ -18,6 +18,9 @@ object CivilianUnitAutomation { && unit.civ.units.getCivUnits().any { unit.hasUnique(UniqueType.AddInCapital) } fun automateCivilianUnit(unit: MapUnit, dangerousTiles: HashSet) { + if (unit.hasUnique(UniqueType.FoundCity)) + return SpecificUnitAutomation.automateSettlerActions(unit, dangerousTiles) + if (tryRunAwayIfNeccessary(unit)) return if (shouldClearTileForAddInCapitalUnits(unit, unit.currentTile)) { @@ -28,9 +31,6 @@ object CivilianUnitAutomation { unit.movement.moveToTile(tilesCanMoveTo.minByOrNull { it.value.totalDistance }!!.key) } - if (unit.hasUnique(UniqueType.FoundCity)) - return SpecificUnitAutomation.automateSettlerActions(unit, dangerousTiles) - if (unit.isAutomatingRoadConnection()) return unit.civ.getWorkerAutomation().roadToAutomation.automateConnectRoad(unit, dangerousTiles) @@ -158,7 +158,7 @@ object CivilianUnitAutomation { } /** Returns whether the civilian spends its turn hiding and not moving */ - private fun tryRunAwayIfNeccessary(unit: MapUnit): Boolean { + fun tryRunAwayIfNeccessary(unit: MapUnit): Boolean { // This is a little 'Bugblatter Beast of Traal': Run if we can attack an enemy // Cheaper than determining which enemies could attack us next turn val enemyUnitsInWalkingDistance = unit.movement.getDistanceToTiles().keys diff --git a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt index 9104fe1be8..e6b87212a8 100644 --- a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt @@ -1,6 +1,7 @@ package com.unciv.logic.automation.unit import com.unciv.logic.automation.Automation +import com.unciv.logic.automation.unit.CivilianUnitAutomation.tryRunAwayIfNeccessary import com.unciv.logic.battle.GreatGeneralImplementation import com.unciv.logic.city.City import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers @@ -190,9 +191,14 @@ object SpecificUnitAutomation { throw Exception("City within distance") return } + + val shouldSettle = (unit.getTile() == bestCityLocation && unit.hasMovement()) + if (shouldSettle) return foundCityAction.action.invoke() + //Settle if we're already on the best tile, before looking if we should retreat from barbarians + if (tryRunAwayIfNeccessary(unit)) return unit.movement.headTowards(bestCityLocation) - if (unit.getTile() == bestCityLocation && unit.hasMovement()) - foundCityAction.action.invoke() + if (shouldSettle) foundCityAction.action.invoke() + //TODO: evaluate 1-tile move with settle on same turn as "safe" } /** @return whether there was any progress in placing the improvement. A return value of `false`