Add 'on [difficulty] or higher' conditional (#13700)

This commit is contained in:
Rob Loach 2025-07-25 06:06:11 -04:00 committed by GitHub
parent 602cd985db
commit 9002464c15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 0 deletions

View File

@ -142,6 +142,13 @@ object Conditionals {
UniqueType.ConditionalIfStartingInEra -> checkOnGameInfo { gameParameters.startingEra == conditional.params[0] }
UniqueType.ConditionalSpeed -> checkOnGameInfo { gameParameters.speed == conditional.params[0] }
UniqueType.ConditionalDifficulty -> checkOnGameInfo { gameParameters.difficulty == conditional.params[0] }
UniqueType.ConditionalDifficultyOrHigher -> checkOnGameInfo {
val difficulty = conditional.params[0]
if (difficulty in ruleset.difficulties) {
val difficulties = ruleset.difficulties.keys.toList()
difficulties.indexOf(difficulty) >= difficulties.indexOf(getDifficulty().name)
} else false
}
UniqueType.ConditionalVictoryEnabled -> checkOnGameInfo { gameParameters.victoryTypes.contains(conditional.params[0]) }
UniqueType.ConditionalVictoryDisabled -> checkOnGameInfo { !gameParameters.victoryTypes.contains(conditional.params[0]) }
UniqueType.ConditionalReligionEnabled -> checkOnGameInfo { isReligionEnabled() }

View File

@ -124,6 +124,7 @@ interface IHasUniques : INamed {
UniqueType.ConditionalVictoryEnabled,
UniqueType.ConditionalSpeed,
UniqueType.ConditionalDifficulty,
UniqueType.ConditionalDifficultyOrHigher,
UniqueType.ConditionalReligionEnabled,
UniqueType.ConditionalReligionDisabled,
UniqueType.ConditionalEspionageEnabled,

View File

@ -690,6 +690,7 @@ enum class UniqueType(
ConditionalAfterTurns("after turn number [nonNegativeAmount]", UniqueTarget.Conditional),
ConditionalSpeed("on [speed] game speed", UniqueTarget.Conditional),
ConditionalDifficulty("on [difficulty] difficulty", UniqueTarget.Conditional),
ConditionalDifficultyOrHigher("on [difficulty] difficulty or higher", UniqueTarget.Conditional),
ConditionalVictoryEnabled("when [victoryType] Victory is enabled", UniqueTarget.Conditional),
ConditionalVictoryDisabled("when [victoryType] Victory is disabled", UniqueTarget.Conditional),
ConditionalReligionEnabled("when religion is enabled", UniqueTarget.Conditional),

View File

@ -3176,6 +3176,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Conditional
??? example "<on [difficulty] difficulty or higher>"
Example: "<on [Prince] difficulty or higher>"
Applicable to: Conditional
??? example "<when [victoryType] Victory is enabled>"
Example: "<when [Domination] Victory is enabled>"

View File

@ -608,6 +608,39 @@ class GlobalUniquesTests {
// endregion happiness
// region Conditionals
@Test
fun conditionalDifficulty() {
val civInfo = game.addCiv()
val tile = game.getTile(Vector2.Zero)
val city = game.addCity(civInfo, tile, true)
val tests = listOf(
"<on [Settler] difficulty>" to 0,
"<on [Chieftain] difficulty>" to 0,
"<on [Prince] difficulty>" to 1, // TestGame is Prince
"<on [King] difficulty>" to 0,
"<on [Emperor] difficulty>" to 0,
"<on [Settler] difficulty or higher>" to 0,
"<on [Chieftain] difficulty or higher>" to 0,
"<on [Prince] difficulty or higher>" to 1,
"<on [King] difficulty or higher>" to 1,
"<on [Emperor] difficulty or higher>" to 1,
"<on [Not Found] difficulty>" to 0,
"<on [Not Found] difficulty or higher>" to 0,
)
Assert.assertEquals(civInfo.gold, 0)
for ((test, expected) in tests) {
val building = game.createBuilding("Gain [1] [Gold] $test")
city.cityConstructions.addBuilding(building)
Assert.assertEquals("Conditional `$test` should be: $expected", civInfo.gold, expected)
civInfo.addGold(-civInfo.gold) // Reset the gold
}
}
// endregion
// region Great Persons
@Test