From 298771a72b03022c23f77eb0c6fe02c1ec6f182b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 18 Jun 2023 01:01:12 +0300 Subject: [PATCH] Revert "Workers try to build roads utilizing existing roads, and railroads overriding existing roads" This reverts commit e558ebcc594ff300149e470ed7734c33f6af50c8. --- .../unciv/logic/automation/unit/WorkerAutomation.kt | 5 +---- core/src/com/unciv/logic/map/BFS.kt | 11 +++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt index 0d5e085981..078c0305f0 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -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 } diff --git a/core/src/com/unciv/logic/map/BFS.kt b/core/src/com/unciv/logic/map/BFS.kt index 8e7f6c1f41..debcb63b66 100644 --- a/core/src/com/unciv/logic/map/BFS.kt +++ b/core/src/com/unciv/logic/map/BFS.kt @@ -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)