From bfa9c657000126595c32b3803219a0d679a8fcef Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 30 Sep 2020 23:17:09 +0300 Subject: [PATCH] Modding - Buildings can be rendered obsolete (unbuildable) by techs --- .../jsons/translations/template.properties | 23 +------------- core/src/com/unciv/logic/map/TileInfo.kt | 5 ++-- core/src/com/unciv/models/ruleset/Building.kt | 1 + .../unciv/models/ruleset/tech/Technology.kt | 11 ++++++- .../com/unciv/ui/pickerscreens/TechButton.kt | 30 +++++++++++-------- 5 files changed, 33 insertions(+), 37 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index a3f6ad302d..18ae9e8b72 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -26,6 +26,7 @@ Get [unitName] = Hydro Plant = +1 population in each city = +[buildingName] obsoleted = # Diplomacy,Trade,Nations @@ -919,25 +920,3 @@ Must be on [terrain] = in this city = in every city = in capital = - -# Quests -Route = -Build a road to connect your capital to our city. = -Kill Camp = -We feel threatened by a Barbarian Camp near our city. Please take care of it. = -Connect Resource = -In order to make our civilizations stronger, connect [Resource] to your trade network. = -Construct Wonder = -We recommend you to start building [Wonder] to show the whole world your civilization strength. = -Great Person = -Great People can change the course of a Civilization! You will be rewarded for acquiring a new [Great Person]. = -Kill City State = -You will be rewarded for destroying the city state of [Target]! = -Find Player = -You have yet to discover where [Civilization] set up their cities. You will be rewarded for finding their territories. = -Find Natural Wonder = -Send your best explorers on a quest to discover Natural Wonders. Nobody knows the location of [Natural Wonder] yet. = -Contest Culture = -The civilization with the largest Culture growth will gain a reward. = -Contest Techs = -The civilization with the largest number of new Technologies researched will gain a reward. = diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index b289ea5076..5b82498834 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -245,8 +245,9 @@ open class TileInfo { if (improvement.improvingTech != null && observingCiv.tech.isResearched(improvement.improvingTech!!)) stats.add(improvement.improvingTechStats!!) // eg Chemistry for mines - for (unique in improvement.uniqueObjects) if (unique.placeholderText == "[] once [] is discovered" - && observingCiv.tech.isResearched(unique.params[1])) stats.add(Stats.parse(unique.params[0])) + for (unique in improvement.uniqueObjects) + if (unique.placeholderText == "[] once [] is discovered" && observingCiv.tech.isResearched(unique.params[1])) + stats.add(Stats.parse(unique.params[0])) if (city != null) { val cityWideUniques = city.cityConstructions.builtBuildingUniqueMap.getUniques("[] from [] tiles in this city") diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index ae64416871..5c9b58a8d4 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -249,6 +249,7 @@ class Building : NamedStats(), IConstruction { if (civInfo.cities.none { it.cityConstructions.containsBuildingOrEquivalent(filter) }) return unique.text // Wonder is not built } else if (!civInfo.policies.adoptedPolicies.contains(filter)) return "Policy is not adopted" // this reason should not be displayed } + "Obsolete with []" -> if (civInfo.tech.isResearched(unique.params[0])) return unique.text "Must have an owned mountain within 2 tiles" -> // Deprecated as of 3.10.8 . Use "Must have an owned [Mountain] within [2] tiles" instead if (cityCenter.getTilesInDistance(2) diff --git a/core/src/com/unciv/models/ruleset/tech/Technology.kt b/core/src/com/unciv/models/ruleset/tech/Technology.kt index 036f7e558d..dc842e4a54 100644 --- a/core/src/com/unciv/models/ruleset/tech/Technology.kt +++ b/core/src/com/unciv/models/ruleset/tech/Technology.kt @@ -32,7 +32,7 @@ class Technology { if (!mapOfImprovedImprovements.containsKey(key)) mapOfImprovedImprovements[key] = ArrayList() mapOfImprovedImprovements[key]!!.add(improvement.name) } - for ( improvements in mapOfImprovedImprovements) { + for (improvements in mapOfImprovedImprovements) { val impimpString = improvements.key.tr() + improvements.value.joinToString(", "," ") { it.tr() } lineList += impimpString } @@ -69,6 +69,9 @@ class Technology { lineList += " * " + wonder.name.tr() + " (" + wonder.getShortDescription(ruleset) + ")" } + for(building in getObsoletedBuildings(viewingCiv)) + lineList += "[${building.name}] obsoleted" + val revealedResource = ruleset.tileResources.values.filter { it.revealedBy == name } .map { it.name }.firstOrNull() // can only be one if (revealedResource != null) lineList += "Reveals [$revealedResource] on the map".tr() @@ -94,6 +97,12 @@ class Technology { return enabledBuildings } + fun getObsoletedBuildings(civInfo: CivilizationInfo): Sequence { + val obsoletedBuildings = civInfo.gameInfo.ruleSet.buildings.values.asSequence() + .filter { it.uniqueObjects.any { it.placeholderText=="Obsolete with []" && it.params[0]==name } } + return obsoletedBuildings.filter { civInfo.getEquivalentBuilding(it.name)==it } + } + fun getEnabledUnits(civInfo: CivilizationInfo): List { var enabledUnits = civInfo.gameInfo.ruleSet.units.values.filter { it.requiredTech == name && diff --git a/core/src/com/unciv/ui/pickerscreens/TechButton.kt b/core/src/com/unciv/ui/pickerscreens/TechButton.kt index bf7595c0e9..151abed4f0 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechButton.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechButton.kt @@ -5,10 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align import com.unciv.logic.civilization.TechManager -import com.unciv.ui.utils.CameraStageBaseScreen -import com.unciv.ui.utils.ImageGetter -import com.unciv.ui.utils.surroundWithCircle -import com.unciv.ui.utils.toLabel +import com.unciv.ui.utils.* class TechButton(techName:String, private val techManager: TechManager, isWorldScreen: Boolean = true) : Table(CameraStageBaseScreen.skin) { val text= "".toLabel().apply { setAlignment(Align.center) } @@ -44,9 +41,9 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS val techIconSize = 30f val civName = techManager.civInfo.civName - val gameBasics = techManager.civInfo.gameInfo.ruleSet + val ruleset = techManager.civInfo.gameInfo.ruleSet - val tech = gameBasics.technologies[techName]!! + val tech = ruleset.technologies[techName]!! for (unit in tech.getEnabledUnits(techManager.civInfo)) techEnabledIcons.add(ImageGetter.getConstructionImage(unit.name).surroundWithCircle(techIconSize)) @@ -54,16 +51,26 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS for (building in tech.getEnabledBuildings(techManager.civInfo)) techEnabledIcons.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(techIconSize)) - for (improvement in gameBasics.tileImprovements.values + for(building in tech.getObsoletedBuildings(techManager.civInfo) ) + techEnabledIcons.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(techIconSize).apply { + val closeImage = ImageGetter.getImage("OtherIcons/Close") + closeImage.setSize(techIconSize/2,techIconSize/2) + closeImage.color = Color.RED + closeImage.center(this) + addActor(closeImage) + }) + + for (improvement in ruleset.tileImprovements.values .filter { it.techRequired == techName || it.uniqueObjects.any { u -> u.params.contains(techName) } - || it.improvingTech == techName } - .filter { it.uniqueTo==null || it.uniqueTo==civName }) { + || it.improvingTech == techName + || it.uniqueObjects.any { it.placeholderText=="[] once [] is discovered" && it.params[1]==techName } } + .filter { it.uniqueTo==null || it.uniqueTo==civName }) if (improvement.name.startsWith("Remove")) techEnabledIcons.add(ImageGetter.getImage("OtherIcons/Stop")).size(techIconSize) else techEnabledIcons.add(ImageGetter.getImprovementIcon(improvement.name, techIconSize)) - } - for (resource in gameBasics.tileResources.values.filter { it.revealedBy == techName }) + + for (resource in ruleset.tileResources.values.filter { it.revealedBy == techName }) techEnabledIcons.add(ImageGetter.getResourceImage(resource.name, techIconSize)) for (unique in tech.uniques) @@ -72,7 +79,6 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS if (isWorldScreen) rightSide.add(techEnabledIcons) else rightSide.add(techEnabledIcons) -// .width(techEnabledIcons.children.size * (techIconSize+6f)) .minWidth(225f) } } \ No newline at end of file