mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
AI knows not to try and heal units which would heal anyway
This commit is contained in:
parent
fad967b31a
commit
24b46e8c2c
@ -171,9 +171,14 @@ object UnitAutomation {
|
||||
}
|
||||
|
||||
fun tryHealUnit(unit: MapUnit): Boolean {
|
||||
if (unit.type.isRanged() && unit.hasUnique("Unit will heal every turn, even if it performs an action"))
|
||||
return false // will heal anyway, and attacks don't hurt
|
||||
|
||||
val unitDistanceToTiles = unit.movement.getDistanceToTiles()
|
||||
val tilesInDistance = unitDistanceToTiles.keys.filter { unit.movement.canMoveTo(it) }
|
||||
if (unitDistanceToTiles.isEmpty()) return true // can't move, so...
|
||||
|
||||
|
||||
val currentUnitTile = unit.getTile()
|
||||
|
||||
if (tryPillageImprovement(unit)) return true
|
||||
@ -191,8 +196,10 @@ object UnitAutomation {
|
||||
|
||||
var bestTilesForHealing = tilesByHealingRate.maxBy { it.key }!!.value
|
||||
// within the tiles with best healing rate (say 15), we'll prefer one which has the highest defensive bonuses
|
||||
val bestTilesWithoutBombardableTiles = bestTilesForHealing.filterNot { it.getTilesInDistance(2)
|
||||
.any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) } }
|
||||
val bestTilesWithoutBombardableTiles = bestTilesForHealing.filterNot {
|
||||
it.getTilesInDistance(2)
|
||||
.any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) }
|
||||
}
|
||||
if (bestTilesWithoutBombardableTiles.any()) bestTilesForHealing = bestTilesWithoutBombardableTiles
|
||||
val bestTileForHealing = bestTilesForHealing.maxBy { it.getDefensiveBonus() }!!
|
||||
val bestTileForHealingRank = unit.rankTileForHealing(bestTileForHealing)
|
||||
@ -274,8 +281,10 @@ object UnitAutomation {
|
||||
private fun tryHeadTowardsSiegedCity(unit: MapUnit): Boolean {
|
||||
val siegedCities = unit.civInfo.cities
|
||||
.asSequence()
|
||||
.filter { unit.civInfo == it.civInfo &&
|
||||
it.health < it.getMaxHealth() * 0.75 } //Weird health issues and making sure that not all forces move to good defenses
|
||||
.filter {
|
||||
unit.civInfo == it.civInfo &&
|
||||
it.health < it.getMaxHealth() * 0.75
|
||||
} //Weird health issues and making sure that not all forces move to good defenses
|
||||
|
||||
val reachableTileNearSiegedCity = siegedCities
|
||||
.flatMap { it.getCenterTile().getTilesAtDistance(2) }
|
||||
@ -389,10 +398,12 @@ object UnitAutomation {
|
||||
private fun tryTakeBackCapturedCity(unit: MapUnit): Boolean {
|
||||
var capturedCities = unit.civInfo.getKnownCivs().asSequence()
|
||||
.flatMap { it.cities.asSequence() }
|
||||
.filter { unit.civInfo.isAtWarWith(it.civInfo) &&
|
||||
.filter {
|
||||
unit.civInfo.isAtWarWith(it.civInfo) &&
|
||||
unit.civInfo.civName == it.foundingCiv &&
|
||||
it.isInResistance() &&
|
||||
it.health < it.getMaxHealth()} //Most likely just been captured
|
||||
it.health < it.getMaxHealth()
|
||||
} //Most likely just been captured
|
||||
|
||||
|
||||
if (unit.type.isRanged()) // ranged units don't harm capturable cities, waste of a turn
|
||||
|
Loading…
x
Reference in New Issue
Block a user