From c767ebe2bf9080ed349279b6b7ff9f8436bf181f Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 24 Feb 2022 16:29:09 +0200 Subject: [PATCH] More unique typing isn't this fun --- core/src/com/unciv/logic/city/CityConstructions.kt | 4 ++-- core/src/com/unciv/logic/city/CityInfo.kt | 2 +- core/src/com/unciv/logic/map/TileInfo.kt | 5 ++--- core/src/com/unciv/models/ruleset/tech/Technology.kt | 2 +- core/src/com/unciv/models/ruleset/unique/UniqueType.kt | 7 ++++++- core/src/com/unciv/models/ruleset/unit/Promotion.kt | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index b0777ff0d7..7f4043082c 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -391,7 +391,7 @@ class CityConstructions { private fun constructionBegun(construction: IConstruction) { if (construction !is Building) return - if (!construction.hasUnique("Triggers a global alert upon build start")) return + if (!construction.hasUnique(UniqueType.TriggersAlertOnStart)) return val buildingIcon = "BuildingIcons/${construction.name}" for (otherCiv in cityInfo.civInfo.gameInfo.civilizations) { if (otherCiv == cityInfo.civInfo) continue @@ -433,7 +433,7 @@ class CityConstructions { cityInfo.location, NotificationIcon.Construction, icon) } - if (construction is Building && construction.hasUnique("Triggers a global alert upon completion", + if (construction is Building && construction.hasUnique(UniqueType.TriggersAlertOnCompletion, StateForConditionals(cityInfo.civInfo, cityInfo) )) { for (otherCiv in cityInfo.civInfo.gameInfo.civilizations) { diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 2915124256..18cbad3fd2 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -610,7 +610,7 @@ class CityInfo { expansion.nextTurn(stats.culture) if (isBeingRazed) { val removedPopulation = - 1 + civInfo.getMatchingUniques("Cities are razed [] times as fast") + 1 + civInfo.getMatchingUniques(UniqueType.CitiesAreRazedXTimesFaster) .sumOf { it.params[0].toInt() - 1 } population.addPopulation(-1 * removedPopulation) if (population.population <= 0) { diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 2260e093be..96029d6d4c 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -249,7 +249,6 @@ open class TileInfo { fun isRoughTerrain() = getAllTerrains().any{ it.isRough() } - fun hasUnique(unique: String) = getAllTerrains().any { it.hasUnique(unique) } fun hasUnique(uniqueType: UniqueType) = getAllTerrains().any { it.hasUnique(uniqueType) } fun getWorkingCity(): CityInfo? { @@ -539,7 +538,7 @@ open class TileInfo { improvement.hasUnique(UniqueType.ImprovementBuildableByFreshWater) && isAdjacentToFreshwater -> true // If an unique of this type exists, we want all to match (e.g. Hill _and_ Forest would be meaningful). - improvement.getMatchingUniques("Can only be built on [] tiles").let { + improvement.getMatchingUniques(UniqueType.CanOnlyBeBuiltOnTile).let { it.any() && it.all { unique -> matchesTerrainFilter(unique.params[0]) } } -> true @@ -578,7 +577,7 @@ open class TileInfo { "Fresh Water" -> isAdjacentToFreshwater else -> { if (terrainFeatures.contains(filter)) return true - if (hasUnique(filter)) return true + if (getAllTerrains().any { it.hasUnique(filter) }) return true // Resource type check is last - cannot succeed if no resource here if (resource == null) return false // Checks 'luxury resource', 'strategic resource' and 'bonus resource' - only those that are visible of course diff --git a/core/src/com/unciv/models/ruleset/tech/Technology.kt b/core/src/com/unciv/models/ruleset/tech/Technology.kt index d8147905b5..cf73da781d 100644 --- a/core/src/com/unciv/models/ruleset/tech/Technology.kt +++ b/core/src/com/unciv/models/ruleset/tech/Technology.kt @@ -138,7 +138,7 @@ class Technology: RulesetObject() { .filter { it.requiredTech == name && (it.uniqueTo == civInfo.civName || it.uniqueTo==null && civInfo.getEquivalentUnit(it) == it) - && (nuclearWeaponsEnabled || !it.hasUnique("Nuclear weapon of Strength []")) + && (nuclearWeaponsEnabled || !it.isNuclearWeapon()) && (religionEnabled || !it.hasUnique(UniqueType.HiddenWithoutReligion)) && !it.hasUnique(UniqueType.HiddenFromCivilopedia) } diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 1e34c85e0c..fa21990f97 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -241,6 +241,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: ChanceToRecruitBarbarianFromEncampment("67% chance to earn 25 Gold and recruit a Barbarian unit from a conquered encampment", UniqueTarget.Global), ChanceToRecruitNavalBarbarian("50% chance of capturing defeated Barbarian naval units and earning 25 Gold", UniqueTarget.Global), TripleGoldFromEncampmentsAndCities("Receive triple Gold from Barbarian encampments and pillaging Cities", UniqueTarget.Global), + CitiesAreRazedXTimesFaster("Cities are razed [amount] times as fast", UniqueTarget.Global), EnablesOpenBorders("Enables Open Borders agreements", UniqueTarget.Global), // Should the 'R' in 'Research agreements' be capitalized? @@ -333,7 +334,9 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: ConvertFoodToProductionWhenConstructed("Excess Food converted to Production when under construction", UniqueTarget.Building, UniqueTarget.Unit), RequiresPopulation("Requires at least [amount] population", UniqueTarget.Building, UniqueTarget.Unit), - + + TriggersAlertOnStart("Triggers a global alert upon build start", UniqueTarget.Building, UniqueTarget.Unit), + TriggersAlertOnCompletion("Triggers a global alert upon completion", UniqueTarget.Building, UniqueTarget.Unit), //endregion @@ -366,6 +369,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: DestroyedWhenCityCaptured("Destroyed when the city is captured", UniqueTarget.Building), NotDestroyedWhenCityCaptured("Never destroyed when the city is captured", UniqueTarget.Building), DoublesGoldFromCapturingCity("Doubles Gold given to enemy if city is captured", UniqueTarget.Building), + RemoveAnnexUnhappiness("Remove extra unhappiness from annexed cities", UniqueTarget.Building), @@ -553,6 +557,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: CanBuildOutsideBorders("Can be built outside your borders", UniqueTarget.Improvement), CanBuildJustOutsideBorders("Can be built just outside your borders", UniqueTarget.Improvement), + CanOnlyBeBuiltOnTile("Can only be built on [tileFilter] tiles", UniqueTarget.Improvement), CannotBuildOnTile("Cannot be built on [tileFilter] tiles", UniqueTarget.Improvement), NoFeatureRemovalNeeded("Does not need removal of [tileFilter]", UniqueTarget.Improvement), diff --git a/core/src/com/unciv/models/ruleset/unit/Promotion.kt b/core/src/com/unciv/models/ruleset/unit/Promotion.kt index 1b5cc69073..5bb8b56347 100644 --- a/core/src/com/unciv/models/ruleset/unit/Promotion.kt +++ b/core/src/com/unciv/models/ruleset/unit/Promotion.kt @@ -101,7 +101,7 @@ class Promotion : RulesetObject() { } val grantors = ruleset.buildings.values.filter { - building -> building.getMatchingUniques("All newly-trained [] units [] receive the [] promotion") + building -> building.getMatchingUniques(UniqueType.UnitStartingPromotions) .any { it.params[2] == name } } + ruleset.terrains.values.filter { terrain -> terrain.getMatchingUniques(UniqueType.TerrainGrantsPromotion).any {