mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-20 20:59:18 +07:00
Resolved #3382 - Added tryTakeBackCapturedCity by nob0dy73
This commit is contained in:
@ -135,6 +135,8 @@ object UnitAutomation {
|
|||||||
// if there is an attackable unit in the vicinity, attack!
|
// if there is an attackable unit in the vicinity, attack!
|
||||||
if (BattleHelper.tryAttackNearbyEnemy(unit)) return
|
if (BattleHelper.tryAttackNearbyEnemy(unit)) return
|
||||||
|
|
||||||
|
if(tryTakeBackCapturedCity(unit)) return
|
||||||
|
|
||||||
if (tryGarrisoningUnit(unit)) return
|
if (tryGarrisoningUnit(unit)) return
|
||||||
|
|
||||||
if (unit.health < 80 && tryHealUnit(unit)) return
|
if (unit.health < 80 && tryHealUnit(unit)) return
|
||||||
@ -384,6 +386,30 @@ object UnitAutomation {
|
|||||||
return targets.minBy { it.getHealth() }
|
return targets.minBy { it.getHealth() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun tryTakeBackCapturedCity(unit: MapUnit): Boolean {
|
||||||
|
var capturedCities = unit.civInfo.getKnownCivs().asSequence()
|
||||||
|
.flatMap { it.cities.asSequence() }
|
||||||
|
.filter { unit.civInfo.isAtWarWith(it.civInfo) &&
|
||||||
|
unit.civInfo.civName == it.foundingCiv &&
|
||||||
|
it.isInResistance() &&
|
||||||
|
it.health < it.getMaxHealth()} //Most likely just been captured
|
||||||
|
|
||||||
|
|
||||||
|
if (unit.type.isRanged()) // ranged units don't harm capturable cities, waste of a turn
|
||||||
|
capturedCities = capturedCities.filterNot { it.health == 1 }
|
||||||
|
|
||||||
|
val closestReachableCapturedCity = capturedCities
|
||||||
|
.map { it.getCenterTile() }
|
||||||
|
.sortedBy { it.aerialDistanceTo(unit.getTile()) }
|
||||||
|
.firstOrNull { unit.movement.canReach(it) }
|
||||||
|
|
||||||
|
if (closestReachableCapturedCity != null) {
|
||||||
|
return headTowardsEnemyCity(unit, closestReachableCapturedCity)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun tryGarrisoningUnit(unit: MapUnit): Boolean {
|
private fun tryGarrisoningUnit(unit: MapUnit): Boolean {
|
||||||
if (unit.type.isMelee() || unit.type.isWaterUnit()) return false // don't garrison melee units, they're not that good at it
|
if (unit.type.isMelee() || unit.type.isWaterUnit()) return false // don't garrison melee units, they're not that good at it
|
||||||
val citiesWithoutGarrison = unit.civInfo.cities.filter {
|
val citiesWithoutGarrison = unit.civInfo.cities.filter {
|
||||||
|
Reference in New Issue
Block a user