From 344c96319b27c7a69a71cb538e86ee58f59dc6be Mon Sep 17 00:00:00 2001 From: SimonCeder <63475501+SimonCeder@users.noreply.github.com> Date: Fri, 1 Oct 2021 14:51:30 +0200 Subject: [PATCH] Fix Fountain of Youth (#5355) * fix fountain of youth * fix test fail * reviews * reviews --- .../jsons/Civ V - Vanilla/Terrains.json | 6 +++- core/src/com/unciv/logic/city/CityStats.kt | 4 ++- core/src/com/unciv/logic/map/MapUnit.kt | 8 +++-- core/src/com/unciv/logic/map/TileInfo.kt | 29 ++++++++++++------- .../unciv/models/ruleset/unique/UniqueType.kt | 2 +- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Terrains.json b/android/assets/jsons/Civ V - Vanilla/Terrains.json index 5315da0509..c21a2059c7 100644 --- a/android/assets/jsons/Civ V - Vanilla/Terrains.json +++ b/android/assets/jsons/Civ V - Vanilla/Terrains.json @@ -233,6 +233,7 @@ "name": "El Dorado", "type": "NaturalWonder", "culture": 5, + "overrideStats": true, "occursOn": ["Plains"], "turnsInto": "Plains", "impassable": true, @@ -246,12 +247,14 @@ "name": "Fountain of Youth", "type": "NaturalWonder", "happiness": 10, + "overrideStats": true, "occursOn": ["Plains"], "turnsInto": "Plains", "impassable": true, "unbuildable": true, "uniques": ["Must be adjacent to [0] [Coast] tiles", - "Grants [Rejuvenation] ([all healing effects doubled]) to adjacent [{Military} {Land}] units for the rest of the game"], + "Grants [Rejuvenation] ([all healing effects doubled]) to adjacent [{Military} {Land}] units for the rest of the game", + "Tile provides yield without assigned population"], "weight": 1 }, { @@ -411,6 +414,7 @@ "name": "King Solomon's Mines", "type": "NaturalWonder", "production": 6, + "overrideStats": true, "occursOn": ["Plains","Desert"], "uniques": ["Must be adjacent to [0] [Coast] tiles", "Must be adjacent to [0] to [2] [Mountain] tiles"], diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index 359b1d4b07..735e2aa497 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -45,7 +45,9 @@ class CityStats(val cityInfo: CityInfo) { val stats = Stats() for (cell in cityInfo.tilesInRange .filter { cityInfo.location == it.position || cityInfo.isWorked(it) || - it.getTileImprovement()?.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation)==true && it.owningCity == cityInfo }) + it.owningCity == cityInfo && (it.getTileImprovement()?.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation) == true || + it.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation)) + }) stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo)) return stats } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index a4c2aecd0b..b7eecd0a46 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -648,13 +648,15 @@ class MapUnit { .flatMap { it.getUnits().asSequence() }.map { it.adjacentHealingBonus() }.maxOrNull() if (maxAdjacentHealingBonus != null) amountToHealBy += maxAdjacentHealingBonus - if (hasUnique("All healing effects doubled")) - amountToHealBy *= 2 + healBy(amountToHealBy) } fun healBy(amount: Int) { - health += amount + health += if (hasUnique("All healing effects doubled")) + amount * 2 + else + amount if (health > 100) health = 100 } diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index dc3b84d836..f38d18f0f7 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -194,7 +194,8 @@ open class TileInfo { fun isRoughTerrain() = getAllTerrains().any{ it.isRough() } - fun hasUnique(unique: String) = getAllTerrains().any { it.uniques.contains(unique) } + fun hasUnique(unique: String) = getAllTerrains().any { it.hasUnique(unique) } + fun hasUnique(uniqueType: UniqueType) = getAllTerrains().any { it.hasUnique(uniqueType) } fun getWorkingCity(): CityInfo? { val civInfo = getOwner() ?: return null @@ -203,7 +204,8 @@ open class TileInfo { fun isWorked(): Boolean = getWorkingCity() != null fun providesYield() = getCity() != null && (isCityCenter() || isWorked() - || getTileImprovement()?.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation) == true) + || getTileImprovement()?.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation) == true + || hasUnique(UniqueType.TileProvidesYieldWithoutPopulation)) fun isLocked(): Boolean { val workingCity = getWorkingCity() @@ -222,6 +224,20 @@ open class TileInfo { stats.add(terrainFeatureBase) } + if (naturalWonder != null) { + val wonder = getNaturalWonder().clone() + + // Spain doubles tile yield + if (city != null && city.civInfo.hasUnique("Tile yields from Natural Wonders doubled")) { + wonder.timesInPlace(2f) + } + + if (getNaturalWonder().overrideStats) + stats = wonder + else + stats.add(wonder) + } + if (city != null) { var tileUniques = city.getMatchingUniques("[] from [] tiles []") .filter { city.matchesFilter(it.params[2]) } @@ -245,15 +261,6 @@ open class TileInfo { stats.add(unique.stats) } - if (naturalWonder != null) { - val wonder = getNaturalWonder() - stats.add(wonder) - - // Spain doubles tile yield - if (city != null && city.civInfo.hasUnique("Tile yields from Natural Wonders doubled")) { - stats.add(wonder) - } - } // resource base if (hasViewableResource(observingCiv)) stats.add(getTileResource()) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index cc054dc25b..b67be96486 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -78,7 +78,7 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) { @Deprecated("As of 3.16.14", ReplaceWith("[amount]% growth [cityFilter] "), DeprecationLevel.WARNING) GrowthPercentBonusWhenNotAtWar("+[amount]% growth [cityFilter] when not at war", UniqueTarget.Global), - TileProvidesYieldWithoutPopulation("Tile provides yield without assigned population", UniqueTarget.Improvement), + TileProvidesYieldWithoutPopulation("Tile provides yield without assigned population", UniqueTarget.Terrain, UniqueTarget.Improvement), @Deprecated("As of 3.16.16", ReplaceWith("[amount]% maintenance costs for [mapUnitFilter] units"), DeprecationLevel.WARNING) DecreasedUnitMaintenanceCostsByFilter("-[amount]% [mapUnitFilter] unit maintenance costs"), // No conditional support