From d8fd48b4ceac3d7f5919f0731c2e542eb6270c81 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 4 May 2019 21:55:31 +0300 Subject: [PATCH] Workers can now remove Roads and Railroads --- android/assets/jsons/TileImprovements.json | 10 +++++++ core/src/com/unciv/logic/GameInfo.kt | 29 +++++++++++-------- core/src/com/unciv/logic/map/MapUnit.kt | 5 ++-- core/src/com/unciv/logic/map/TileInfo.kt | 2 ++ .../pickerscreens/ImprovementPickerScreen.kt | 1 + 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/android/assets/jsons/TileImprovements.json b/android/assets/jsons/TileImprovements.json index ad630c6ba0..69b5201e02 100644 --- a/android/assets/jsons/TileImprovements.json +++ b/android/assets/jsons/TileImprovements.json @@ -111,6 +111,16 @@ techRequired:"Bronze Working" }, + // These are unique and have unique in-game checks related to them + { + name:"Remove Road", + turnsToBuild:2 + }, + { + name:"Remove Railroad", + turnsToBuild:2 + }, + // Great Person improvements { name:"Academy", diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 91d93c5c55..d7f4728b04 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -3,6 +3,7 @@ package com.unciv.logic import com.badlogic.gdx.graphics.Color import com.unciv.GameParameters import com.unciv.logic.automation.NextTurnAutomation +import com.unciv.logic.city.CityConstructions import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.PlayerType import com.unciv.logic.map.TileInfo @@ -142,18 +143,9 @@ class GameInfo { } // As of 2.14.1, changed Machu Pichu to Machu Picchu - val oldMachuName = "Machu Pichu" - val newMachuName = "Machu Picchu" - if(cityConstructions.builtBuildings.contains(oldMachuName)){ - cityConstructions.builtBuildings.remove(oldMachuName) - cityConstructions.builtBuildings.add(newMachuName) - } - if (cityConstructions.currentConstruction == oldMachuName) - cityConstructions.currentConstruction = newMachuName - if (cityConstructions.inProgressConstructions.containsKey(oldMachuName)) { - cityConstructions.inProgressConstructions[newMachuName] = cityConstructions.inProgressConstructions[oldMachuName]!! - cityConstructions.inProgressConstructions.remove(oldMachuName) - } + changeBuildingName(cityConstructions, "Machu Pichu", "Machu Picchu") + // As of 2.16.1, changed Colloseum to Colosseum + changeBuildingName(cityConstructions, "Colloseum", "Colosseum") } } @@ -163,4 +155,17 @@ class GameInfo { } } + private fun changeBuildingName(cityConstructions: CityConstructions, oldBuildingName: String, newBuildingName: String) { + if (cityConstructions.builtBuildings.contains(oldBuildingName)) { + cityConstructions.builtBuildings.remove(oldBuildingName) + cityConstructions.builtBuildings.add(newBuildingName) + } + if (cityConstructions.currentConstruction == oldBuildingName) + cityConstructions.currentConstruction = newBuildingName + if (cityConstructions.inProgressConstructions.containsKey(oldBuildingName)) { + cityConstructions.inProgressConstructions[newBuildingName] = cityConstructions.inProgressConstructions[oldBuildingName]!! + cityConstructions.inProgressConstructions.remove(oldBuildingName) + } + } + } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 922adfb61e..936f6ed01a 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -322,8 +322,9 @@ class MapUnit { && !tileImprovement.terrainsCanBeBuiltOn.contains(tile.baseTerrain)) { tile.improvement = null // We removed a terrain (e.g. Forest) and the improvement (e.g. Lumber mill) requires it! } - - tile.terrainFeature = null + if(tile.improvementInProgress=="Remove Road" || tile.improvementInProgress=="Remove Railroad") + tile.roadStatus = RoadStatus.None + else tile.terrainFeature = null } tile.improvementInProgress == "Road" -> tile.roadStatus = RoadStatus.Road tile.improvementInProgress == "Railroad" -> tile.roadStatus = RoadStatus.Railroad diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index d3c9320e97..5eee458cb2 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -202,6 +202,8 @@ open class TileInfo { if (improvement.terrainsCanBeBuiltOn.contains(topTerrain!!.name)) return true if (improvement.name == "Road" && this.roadStatus === RoadStatus.None) return true if (improvement.name == "Railroad" && this.roadStatus !== RoadStatus.Railroad) return true + if(improvement.name == "Remove Road" && this.roadStatus===RoadStatus.Road) return true + if(improvement.name == "Remove Railroad" && this.roadStatus===RoadStatus.Railroad) return true if (topTerrain.unbuildable && !(topTerrain.name=="Forest" && improvement.name=="Camp")) return false return hasViewableResource(civInfo) && getTileResource().improvement == improvement.name diff --git a/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt index 347b1df9dc..9e5420f4ef 100644 --- a/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt @@ -29,6 +29,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() { val regularImprovements = VerticalGroup() regularImprovements.space(10f) + for (improvement in GameBasics.TileImprovements.values) { if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue if(improvement.name == tileInfo.improvement) continue