mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 09:18:43 +07:00
Improved UnitAutomation tryPrepare() cityToDefend evaluation (#11879)
This commit is contained in:
@ -512,12 +512,17 @@ object UnitAutomation {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val hostileCivs = civInfo.getKnownCivs().filter { it.isAtWarWith(civInfo) || hasPreparationFlag(it) }
|
val hostileCivs = civInfo.getKnownCivs().filter { it.isAtWarWith(civInfo) || hasPreparationFlag(it) }.toSet()
|
||||||
val citiesToDefend = hostileCivs.mapNotNull { NextTurnAutomation.getClosestCities(civInfo, it) }
|
val closeCities = civInfo.threatManager.getNeighboringCitiesOfOtherCivs().filter { it.second.civ in hostileCivs }
|
||||||
.sortedBy { unit.getTile().aerialDistanceTo(it.city1.getCenterTile()) }
|
val closestDistance = closeCities.minOfOrNull { it.first.getCenterTile().aerialDistanceTo(it.second.getCenterTile()) }
|
||||||
|
?: return false
|
||||||
|
val citiesToDefend = closeCities.filter { it.first.getCenterTile().aerialDistanceTo(it.second.getCenterTile()) <= closestDistance + 2 }
|
||||||
|
.map { it.first }
|
||||||
|
.distinct() // Remove duplicate cities
|
||||||
|
.sortedBy { unit.getTile().aerialDistanceTo(it.getCenterTile()) }
|
||||||
|
|
||||||
// Move to the closest city with a tile we can enter nearby
|
// Move to the closest city with a tile we can enter nearby
|
||||||
for ((city, _) in citiesToDefend) {
|
for (city in citiesToDefend) {
|
||||||
if (unit.getTile().aerialDistanceTo(city.getCenterTile()) <= 2) return true
|
if (unit.getTile().aerialDistanceTo(city.getCenterTile()) <= 2) return true
|
||||||
val tileToMoveTo = city.getCenterTile().getTilesInDistance(2).firstOrNull { unit.movement.canMoveTo(it) && unit.movement.canReach(it) } ?: continue
|
val tileToMoveTo = city.getCenterTile().getTilesInDistance(2).firstOrNull { unit.movement.canMoveTo(it) && unit.movement.canReach(it) } ?: continue
|
||||||
unit.movement.headTowards(tileToMoveTo)
|
unit.movement.headTowards(tileToMoveTo)
|
||||||
|
Reference in New Issue
Block a user