mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 02:42:16 -04:00
Fix AI civilian unit not escaping enemy (#13637)
* Initial improvement of AI road planning * fix tile caching of road plans * fix worker not connecting city due to lower priority * remove unnecessary code * cleanup RoadBetweenCitiesAutomation.kt and enable harbor connection loging * fix invalid logic in road construction * apply reviewed changes * sort plan list by closer cities * apply reviewed changes and removed loging * Fix AI civilian unit not escaping enemy
This commit is contained in:
parent
f6b71fc0af
commit
6a652bbe9d
@ -210,10 +210,11 @@ object CivilianUnitAutomation {
|
||||
unit.movement.moveToTile(defensiveUnit)
|
||||
return
|
||||
}
|
||||
val distanceToClosestEnemyUnit = unit.civ.threatManager.getDistanceToClosestEnemyUnit(unit.getTile(), 4, false)
|
||||
val dangerousTiles = unit.civ.threatManager.getDangerousTiles(unit, distanceToClosestEnemyUnit)
|
||||
val tileFurthestFromEnemy = reachableTiles.keys
|
||||
.filter { unit.movement.canMoveTo(it) && unit.getDamageFromTerrain(it) < unit.health }
|
||||
.maxByOrNull { unit.civ.threatManager.getDistanceToClosestEnemyUnit(unit.getTile(), 4, false) }
|
||||
?: return // can't move anywhere!
|
||||
.maxByOrNull { if (it in dangerousTiles) 0 else distanceToClosestEnemyUnit } ?: return // can't move anywhere!
|
||||
unit.movement.moveToTile(tileFurthestFromEnemy)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user