Auto build railroad.
This commit is contained in:
parent
2923dc80c9
commit
f717645019
1 changed files with 11 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue