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:
metablaster 2025-07-18 11:26:06 +02:00 committed by GitHub
parent f6b71fc0af
commit 6a652bbe9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
}