mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-24 13:41:08 +07:00
Resolved #11489 - better "escort settler" logic
This commit is contained in:
parent
235921e315
commit
741dc6379f
@ -209,6 +209,9 @@ object UnitAutomation {
|
|||||||
return AirUnitAutomation.automateBomber(unit)
|
return AirUnitAutomation.automateBomber(unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Accompany settlers
|
||||||
|
if (tryAccompanySettlerOrGreatPerson(unit)) return
|
||||||
|
|
||||||
if (tryGoToRuinAndEncampment(unit) && unit.currentMovement == 0f) return
|
if (tryGoToRuinAndEncampment(unit) && unit.currentMovement == 0f) return
|
||||||
|
|
||||||
if (tryUpgradeUnit(unit)) return
|
if (tryUpgradeUnit(unit)) return
|
||||||
@ -218,9 +221,6 @@ object UnitAutomation {
|
|||||||
// If there are no enemies nearby and we can heal here, wait until we are at full health
|
// If there are no enemies nearby and we can heal here, wait until we are at full health
|
||||||
if (unit.health < 100 && canUnitHealInTurnsOnCurrentTile(unit,2, 4)) return
|
if (unit.health < 100 && canUnitHealInTurnsOnCurrentTile(unit,2, 4)) return
|
||||||
|
|
||||||
// Accompany settlers
|
|
||||||
if (tryAccompanySettlerOrGreatPerson(unit)) return
|
|
||||||
|
|
||||||
if (tryHeadTowardsOurSiegedCity(unit)) return
|
if (tryHeadTowardsOurSiegedCity(unit)) return
|
||||||
|
|
||||||
// if a embarked melee unit can land and attack next turn, do not attack from water.
|
// if a embarked melee unit can land and attack next turn, do not attack from water.
|
||||||
@ -494,13 +494,14 @@ object UnitAutomation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun tryAccompanySettlerOrGreatPerson(unit: MapUnit): Boolean {
|
private fun tryAccompanySettlerOrGreatPerson(unit: MapUnit): Boolean {
|
||||||
|
val distanceToTiles = unit.movement.getDistanceToTiles()
|
||||||
val settlerOrGreatPersonToAccompany = unit.civ.units.getCivUnits()
|
val settlerOrGreatPersonToAccompany = unit.civ.units.getCivUnits()
|
||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
val tile = it.currentTile
|
val tile = it.currentTile
|
||||||
it.isCivilian() &&
|
it.isCivilian() &&
|
||||||
(it.hasUnique(UniqueType.FoundCity) || unit.isGreatPerson())
|
(it.hasUnique(UniqueType.FoundCity) || unit.isGreatPerson())
|
||||||
&& tile.militaryUnit == null && unit.movement.canMoveTo(tile)
|
&& (tile == unit.currentTile || tile.militaryUnit == null && unit.movement.canMoveTo(tile))
|
||||||
&& unit.movement.getDistanceToTiles().containsKey(tile)
|
&& distanceToTiles.containsKey(tile)
|
||||||
} ?: return false
|
} ?: return false
|
||||||
unit.movement.headTowards(settlerOrGreatPersonToAccompany.currentTile)
|
unit.movement.headTowards(settlerOrGreatPersonToAccompany.currentTile)
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user