diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index bd95a395..1dd74fe3 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -43,19 +43,24 @@ class WorkerAutomation(val unit: MapUnit) { fun tryConnectingCities():Boolean{ // returns whether we actually did anything + val techEnablingRailroad = GameBasics.TileImprovements["Railroad"]!!.techRequired!! + val canBuildRailroad = unit.civInfo.tech.isResearched(techEnablingRailroad) + + val targetRoadName = if (canBuildRailroad) "Railroad" else "Road" + val targetStatus = if (canBuildRailroad) RoadStatus.Railroad else RoadStatus.Road + val citiesThatNeedConnecting = unit.civInfo.cities .filter { it.population.population>3 && !it.isCapital() - && !it.cityStats.isConnectedToCapital(RoadStatus.Road) } + && !it.cityStats.isConnectedToCapital(targetStatus) } if(citiesThatNeedConnecting.isEmpty()) return false // do nothing. val citiesThatNeedConnectingBfs = citiesThatNeedConnecting .map { city -> BFS(city.getCenterTile()){it.isLand() && unit.canPassThrough(it)} } .toMutableList() - val connectedCities = unit.civInfo.cities.filter { it.isCapital() || it.cityStats.isConnectedToCapital(RoadStatus.Road) } + val connectedCities = unit.civInfo.cities.filter { it.isCapital() || it.cityStats.isConnectedToCapital(targetStatus) } .map { it.getCenterTile() } - while(citiesThatNeedConnectingBfs.any()){ for(bfs in citiesThatNeedConnectingBfs.toList()){ bfs.nextStep() @@ -66,7 +71,7 @@ class WorkerAutomation(val unit: MapUnit) { for(city in connectedCities) if(bfs.tilesToCheck.contains(city)) { // we have a winner! val pathToCity = bfs.getPathTo(city) - val roadableTiles = pathToCity.filter { it.roadStatus==RoadStatus.None } + val roadableTiles = pathToCity.filter { it.roadStatus < targetStatus } val tileToConstructRoadOn :TileInfo if(unit.currentTile in roadableTiles) tileToConstructRoadOn = unit.currentTile else{ @@ -76,8 +81,8 @@ class WorkerAutomation(val unit: MapUnit) { unit.movementAlgs().headTowards(tileToConstructRoadOn) } if(unit.currentMovement>0 && unit.currentTile==tileToConstructRoadOn - && unit.currentTile.improvementInProgress!="Road") - tileToConstructRoadOn.startWorkingOnImprovement(GameBasics.TileImprovements["Road"]!!,unit.civInfo) + && unit.currentTile.improvementInProgress!=targetRoadName) + tileToConstructRoadOn.startWorkingOnImprovement(GameBasics.TileImprovements[targetRoadName]!!,unit.civInfo) return true } }