mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Revert "Workers try to build roads utilizing existing roads, and railroads overriding existing roads"
This reverts commit e558ebcc59
.
This commit is contained in:
@ -221,15 +221,13 @@ class WorkerAutomation(
|
||||
if (candidateCities.none()) return false // do nothing.
|
||||
|
||||
val isCandidateTilePredicate: (Tile) -> Boolean = { it.isLand && unit.movement.canPassThrough(it) }
|
||||
val getTilePriority: (Tile) -> Int = { it.roadStatus.ordinal }
|
||||
val currentTile = unit.getTile()
|
||||
val cityTilesToSeek = ArrayList(tilesOfConnectedCities.sortedBy { it.aerialDistanceTo(currentTile) })
|
||||
|
||||
for (toConnectCity in candidateCities) {
|
||||
val toConnectTile = toConnectCity.getCenterTile()
|
||||
|
||||
val bfs: BFS = bfsCache[toConnectTile.position] ?:
|
||||
BFS(toConnectTile, getTilePriority, isCandidateTilePredicate).apply {
|
||||
BFS(toConnectTile, isCandidateTilePredicate).apply {
|
||||
maxSize = HexMath.getNumberOfTilesInHexagon(
|
||||
WorkerAutomationConst.maxBfsReachPadding +
|
||||
tilesOfConnectedCities.minOf { it.aerialDistanceTo(toConnectTile) }
|
||||
@ -240,7 +238,6 @@ class WorkerAutomation(
|
||||
while (true) {
|
||||
for (cityTile in cityTilesToSeek.toList()) { // copy since we change while running
|
||||
if (!bfs.hasReachedTile(cityTile)) continue
|
||||
|
||||
// we have a winner!
|
||||
val pathToCity = bfs.getPathTo(cityTile)
|
||||
val roadableTiles = pathToCity.filter { it.getUnpillagedRoad() < bestRoadAvailable }
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.unciv.logic.map
|
||||
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import kotlin.collections.ArrayDeque
|
||||
|
||||
/**
|
||||
* Defines intermediate steps of a breadth-first search, for use in either get shortest path or get connected tiles.
|
||||
*/
|
||||
class BFS(
|
||||
val startingPoint: Tile,
|
||||
/** The *higher* the number, the *greater* the priority */
|
||||
private val priorityFunction: ((Tile) -> Int)? = null,
|
||||
private val predicate : (Tile) -> Boolean,
|
||||
private val predicate : (Tile) -> Boolean
|
||||
) {
|
||||
/** Maximum number of tiles to search */
|
||||
var maxSize = Int.MAX_VALUE
|
||||
@ -51,11 +50,7 @@ class BFS(
|
||||
fun nextStep() {
|
||||
if (tilesReached.size >= maxSize) { tilesToCheck.clear(); return }
|
||||
val current = tilesToCheck.removeFirstOrNull() ?: return
|
||||
|
||||
val sortedNeighbors = if (priorityFunction==null) current.neighbors
|
||||
else current.neighbors.sortedByDescending(priorityFunction)
|
||||
|
||||
for (neighbor in sortedNeighbors) {
|
||||
for (neighbor in current.neighbors) {
|
||||
if (neighbor !in tilesReached && predicate(neighbor)) {
|
||||
tilesReached[neighbor] = current
|
||||
tilesToCheck.add(neighbor)
|
||||
|
Reference in New Issue
Block a user