mirror of
https://github.com/yairm210/Unciv.git
synced 2024-12-22 17:24:24 +07:00
Prevent incorrect settler retreat (#12652)
* Update CivilianUnitAutomation.kt * Update SpecificUnitAutomation.kt * Update SpecificUnitAutomation.kt
This commit is contained in:
parent
b55e02fd4d
commit
203222af7d
@ -18,6 +18,9 @@ object CivilianUnitAutomation {
|
||||
&& unit.civ.units.getCivUnits().any { unit.hasUnique(UniqueType.AddInCapital) }
|
||||
|
||||
fun automateCivilianUnit(unit: MapUnit, dangerousTiles: HashSet<Tile>) {
|
||||
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
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user