Automated workers no longer stay on unimprovable tile if another tile is improvable

This commit is contained in:
Yair Morgenstern 2023-05-08 18:29:34 +03:00
parent e0505d1eb7
commit f8b4b202e7

View File

@ -86,7 +86,7 @@ class WorkerAutomation(
if (result.isEmpty()) if (result.isEmpty())
debug("\tempty") debug("\tempty")
else result.forEach { else result.forEach {
debug("\t$it") // ${it.getCity()?.name} included in Tile toString() debug("\t$it")
} }
} }
result result
@ -297,8 +297,9 @@ class WorkerAutomation(
val selectedTile = workableTiles.firstOrNull { unit.movement.canReach(it) && (tileCanBeImproved(unit, it) || it.isPillaged()) } val selectedTile = workableTiles.firstOrNull { unit.movement.canReach(it) && (tileCanBeImproved(unit, it) || it.isPillaged()) }
return if (selectedTile != null return if (selectedTile != null
&& (!workableTiles.contains(currentTile) && ((!tileCanBeImproved(unit, currentTile) && !currentTile.isPillaged()) // current tile is unimprovable
|| getPriority(selectedTile) > getPriority(currentTile))) || !workableTiles.contains(currentTile) // current tile is unworkable by city
|| getPriority(selectedTile) > getPriority(currentTile))) // current tile is less important
selectedTile selectedTile
else currentTile else currentTile
} }