mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Resolved #4202 - AI cities now build workboats for use in other cities
Solves the 'landlocked but with water improvement' deadlock
This commit is contained in:
parent
93268f53ee
commit
4c41536ed8
@ -138,26 +138,28 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
|
|||||||
|
|
||||||
private fun addWorkBoatChoice() {
|
private fun addWorkBoatChoice() {
|
||||||
val buildableWorkboatUnits = cityInfo.cityConstructions.getConstructableUnits()
|
val buildableWorkboatUnits = cityInfo.cityConstructions.getConstructableUnits()
|
||||||
.filter { it.hasUnique(UniqueType.CreateWaterImprovements)
|
.filter {
|
||||||
&& Automation.allowSpendingResource(civInfo, it) }
|
it.hasUnique(UniqueType.CreateWaterImprovements)
|
||||||
|
&& Automation.allowSpendingResource(civInfo, it)
|
||||||
|
}
|
||||||
val canBuildWorkboat = buildableWorkboatUnits.any()
|
val canBuildWorkboat = buildableWorkboatUnits.any()
|
||||||
&& !cityInfo.getTiles().any { it.civilianUnit?.hasUnique(UniqueType.CreateWaterImprovements) == true }
|
&& !cityInfo.getTiles()
|
||||||
|
.any { it.civilianUnit?.hasUnique(UniqueType.CreateWaterImprovements) == true }
|
||||||
if (!canBuildWorkboat) return
|
if (!canBuildWorkboat) return
|
||||||
val tilesThatNeedWorkboat = cityInfo.getTiles()
|
|
||||||
.filter { it.isWater && it.hasViewableResource(civInfo) && it.improvement == null }.toList()
|
|
||||||
if (tilesThatNeedWorkboat.isEmpty()) return
|
|
||||||
|
|
||||||
// If we can't reach the tile we need to improve within 15 tiles, it's probably unreachable.
|
|
||||||
val bfs = BFS(cityInfo.getCenterTile()) { (it.isWater || it.isCityCenter()) && it.isFriendlyTerritory(civInfo) }
|
val bfs = BFS(cityInfo.getCenterTile()) {
|
||||||
for (i in 1..15) {
|
(it.isWater || it.isCityCenter()) && it.isFriendlyTerritory(civInfo)
|
||||||
bfs.nextStep()
|
|
||||||
if (tilesThatNeedWorkboat.any { bfs.hasReachedTile(it) })
|
|
||||||
break
|
|
||||||
if (bfs.hasEnded()) break
|
|
||||||
}
|
}
|
||||||
if (tilesThatNeedWorkboat.none { bfs.hasReachedTile(it) }) return
|
for (i in 1..10) bfs.nextStep()
|
||||||
|
if (!bfs.getReachedTiles()
|
||||||
|
.any { it.hasViewableResource(civInfo) && it.improvement == null && it.getOwner() == civInfo }
|
||||||
|
) return
|
||||||
|
|
||||||
addChoice(relativeCostEffectiveness, buildableWorkboatUnits.minByOrNull { it.cost }!!.name, 0.6f)
|
addChoice(
|
||||||
|
relativeCostEffectiveness, buildableWorkboatUnits.minByOrNull { it.cost }!!.name,
|
||||||
|
0.6f
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addWorkerChoice() {
|
private fun addWorkerChoice() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user