Softcode Fountain of Youth (#5308)

* Softcode Rejuvenation

* Softcode Rejuvenation - comments
This commit is contained in:
SomeTroglodyte
2021-09-25 21:15:03 +02:00
committed by GitHub
parent a4c38174b6
commit 8d33dacc3c
6 changed files with 36 additions and 37 deletions

View File

@ -251,7 +251,7 @@
"impassable": true, "impassable": true,
"unbuildable": true, "unbuildable": true,
"uniques": ["Must be adjacent to [0] [Coast] tiles", "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"],
"weight": 1 "weight": 1
}, },
{ {
@ -404,7 +404,7 @@
"impassable": true, "impassable": true,
"unbuildable": true, "unbuildable": true,
"weight": 10 "weight": 10
} },
/* /*
// BNW wonders // BNW wonders
{ {
@ -424,11 +424,10 @@
"type": "NaturalWonder", "type": "NaturalWonder",
"food": 6, "food": 6,
"occursOn": ["Plains"], "occursOn": ["Plains"],
"uniques": ["Must be adjacent to [0] [Coast] tiles"],
"turnsInto": "Mountain", "turnsInto": "Mountain",
"impassable": true, "impassable": true,
"unbuildable": true, "unbuildable": true,
"uniques": ["Fresh water"], "uniques": ["Fresh water","Must be adjacent to [0] [Coast] tiles"],
"weight": 10 "weight": 10
}, },
{ {
@ -443,7 +442,7 @@
"uniques": ["Must be adjacent to [0] [Coast] tiles", "uniques": ["Must be adjacent to [0] [Coast] tiles",
"Must be adjacent to [2] to [6] [Hill] tiles", "Must be adjacent to [2] to [6] [Hill] tiles",
"Must be adjacent to [0] to [2] [Mountain] tiles", "Must be adjacent to [0] to [2] [Mountain] tiles",
"Grants Altitude Training (double movement and +10% Strength in hills) to adjacent land units for the rest of the game"], //ToDo "Grants [Altitude Training] ([double movement and +10% Strength in hills]) to adjacent [Land] units for the rest of the game"],
"weight": 10 "weight": 10
} }
*/ */

View File

@ -35,26 +35,6 @@ object Constants {
val vegetation = arrayOf(forest, jungle) val vegetation = arrayOf(forest, jungle)
val sea = arrayOf(ocean, coast) val sea = arrayOf(ocean, coast)
const val barringerCrater = "Barringer Crater"
const val grandMesa = "Grand Mesa"
const val greatBarrierReef = "Great Barrier Reef"
const val krakatoa = "Krakatoa"
const val mountFuji = "Mount Fuji"
const val oldFaithful = "Old Faithful"
const val rockOfGibraltar = "Rock of Gibraltar"
const val cerroDePotosi = "Cerro de Potosi"
const val elDorado = "El Dorado"
const val fountainOfYouth = "Fountain of Youth"
const val mountKailash = "Mount Kailash"
const val mountSinai = "Mount Sinai"
const val sriPada = "Sri Pada"
const val uluru = "Uluru"
/*
const val kingSolomonsMines = "King Solomon's Mines" //BNW
const val lakeVictoria = "Lake Victoria" //BNW
const val mountKilimanjaro = "Mount Kilimanjaro" //BNW
*/
const val barbarianEncampment = "Barbarian encampment" const val barbarianEncampment = "Barbarian encampment"
const val peaceTreaty = "Peace Treaty" const val peaceTreaty = "Peace Treaty"

View File

@ -13,6 +13,7 @@ import com.unciv.models.UnitActionType
import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.unique.Unique import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.tile.TileImprovement import com.unciv.models.ruleset.tile.TileImprovement
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.ruleset.unit.UnitType
import com.unciv.ui.utils.toPercent import com.unciv.ui.utils.toPercent
@ -746,12 +747,14 @@ class MapUnit {
if (tile.improvement == Constants.barbarianEncampment && !civInfo.isBarbarian()) if (tile.improvement == Constants.barbarianEncampment && !civInfo.isBarbarian())
clearEncampment(tile) clearEncampment(tile)
if (!hasUnique("All healing effects doubled") && baseUnit.isLandUnit() && baseUnit.isMilitary()) { val promotionUniques = tile.neighbors
//todo: Grants [promotion] to adjacent [unitFilter] units for the rest of the game .flatMap { it.getAllTerrains() }
val gainDoubleHealPromotion = tile.neighbors .flatMap { it.getMatchingUniques(UniqueType.TerrainGrantsPromotion) }
.any { it.hasUnique("Grants Rejuvenation (all healing effects doubled) to adjacent military land units for the rest of the game") } for (unique in promotionUniques) {
if (gainDoubleHealPromotion && civInfo.gameInfo.ruleSet.unitPromotions.containsKey("Rejuvenation")) if (!this.matchesFilter(unique.params[2])) continue
promotions.addPromotion("Rejuvenation", true) val promotion = unique.params[0]
if (promotion in promotions.promotions) continue
promotions.addPromotion(promotion, true)
} }
updateVisibleTiles() updateVisibleTiles()

View File

@ -18,6 +18,10 @@ enum class UniqueParameterType(val parameterName:String) {
private val knownValues = setOf("Wounded", "Barbarians", "City-State", "Embarked", "Non-City") private val knownValues = setOf("Wounded", "Barbarians", "City-State", "Embarked", "Non-City")
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueComplianceErrorSeverity? { UniqueType.UniqueComplianceErrorSeverity? {
if ('{' in parameterText) // "{filter} {filter}" for and logic
return parameterText.removePrefix("{").removeSuffix("}").split("} {")
.mapNotNull { getErrorSeverity(it, ruleset) }
.maxByOrNull { it.ordinal }
if (parameterText in knownValues) return null if (parameterText in knownValues) return null
return BaseUnitFilter.getErrorSeverity(parameterText, ruleset) return BaseUnitFilter.getErrorSeverity(parameterText, ruleset)
} }
@ -91,6 +95,18 @@ enum class UniqueParameterType(val parameterName:String) {
return UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific return UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific
} }
}, },
Promotion("promotion") {
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueComplianceErrorSeverity? = when (parameterText) {
in ruleset.unitPromotions -> null
else -> UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific
}
},
/** Behaves like [Unknown], but states explicitly the parameter is OK and its contents are ignored */
Comment("comment") {
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueComplianceErrorSeverity? = null
},
Unknown("param") { Unknown("param") {
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueComplianceErrorSeverity? { UniqueType.UniqueComplianceErrorSeverity? {

View File

@ -97,6 +97,8 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) {
NaturalWonderConvertNeighbors("Neighboring tiles will convert to [baseTerrain]", UniqueTarget.Terrain), NaturalWonderConvertNeighbors("Neighboring tiles will convert to [baseTerrain]", UniqueTarget.Terrain),
NaturalWonderConvertNeighborsExcept("Neighboring tiles except [terrainFilter] will convert to [baseTerrain]", UniqueTarget.Terrain), NaturalWonderConvertNeighborsExcept("Neighboring tiles except [terrainFilter] will convert to [baseTerrain]", UniqueTarget.Terrain),
TerrainGrantsPromotion("Grants [promotion] ([comment]) to adjacent [mapUnitFilter] units for the rest of the game", UniqueTarget.Terrain),
///// CONDITIONALS ///// CONDITIONALS

View File

@ -3,6 +3,7 @@ package com.unciv.models.ruleset.unit
import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetObject import com.unciv.models.ruleset.RulesetObject
import com.unciv.models.ruleset.unique.UniqueTarget import com.unciv.models.ruleset.unique.UniqueTarget
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.civilopedia.FormattedLine import com.unciv.ui.civilopedia.FormattedLine
@ -111,10 +112,8 @@ class Promotion : RulesetObject() {
&& it.params[2] == name && it.params[2] == name
} }
} + ruleset.terrains.values.filter { } + ruleset.terrains.values.filter {
// once that unique is parameterized, this will be the efficient order of checks terrain -> terrain.uniqueObjects.any {
terrain -> terrain.uniques.any { it.isOfType(UniqueType.TerrainGrantsPromotion) && name == it.params[0]
it == "Grants Rejuvenation (all healing effects doubled) to adjacent military land units for the rest of the game"
&& name == "Rejuvenation"
} }
} }
if (grantors.isNotEmpty()) { if (grantors.isNotEmpty()) {