From 7d69945c57f8e52f12be95f65a5c7a87b8c3b026 Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Sun, 21 Jul 2024 02:01:15 -0500 Subject: [PATCH] Make AI difficulty changable (#11996) * Added AIDifficultyLevel to the difficulty object * Fixed difficulty levels not showing in the cyclopedia screen --- .../assets/jsons/Civ V - Gods & Kings/Difficulties.json | 8 ++++++++ android/assets/jsons/Civ V - Vanilla/Difficulties.json | 8 ++++++++ core/src/com/unciv/logic/civilization/Civilization.kt | 4 +++- core/src/com/unciv/models/ruleset/nation/Difficulty.kt | 2 ++ .../ui/screens/civilopediascreen/CivilopediaScreen.kt | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Difficulties.json b/android/assets/jsons/Civ V - Gods & Kings/Difficulties.json index f629cd13cf..52203ec2bf 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Difficulties.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Difficulties.json @@ -13,6 +13,7 @@ "barbarianBonus": 0.75, "barbarianSpawnDelay": 8, "playerBonusStartingUnits": [], // Note that the units from Eras.json are added to this pool. This should only contain bonus starting units. + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1.6, // that is to say it'll take them 1.6 times as long to grow the city "aiUnitCostModifier": 1.75, "aiBuildingCostModifier": 1.6, @@ -42,6 +43,7 @@ "barbarianBonus": 0.5, "barbarianSpawnDelay": 5, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1.3, "aiUnitCostModifier": 1.3, "aiBuildingCostModifier": 1.3, @@ -71,6 +73,7 @@ "barbarianBonus": 0.4, "barbarianSpawnDelay": 3, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1.1, "aiUnitCostModifier": 1.1, "aiBuildingCostModifier": 1.1, @@ -100,6 +103,7 @@ "barbarianBonus": 0.33, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1, "aiUnitCostModifier": 1, "aiBuildingCostModifier": 1, @@ -129,6 +133,7 @@ "barbarianBonus": 0.25, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.9, "aiUnitCostModifier": 0.85, "aiBuildingCostModifier": 0.85, @@ -158,6 +163,7 @@ "barbarianBonus": 0.2, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.85, "aiUnitCostModifier": 0.8, "aiBuildingCostModifier": 0.8, @@ -187,6 +193,7 @@ "barbarianBonus": 0.1, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.75, "aiUnitCostModifier": 0.65, "aiBuildingCostModifier": 0.65, @@ -216,6 +223,7 @@ "barbarianBonus": 0, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.6, "aiUnitCostModifier": 0.5, "aiBuildingCostModifier": 0.5, diff --git a/android/assets/jsons/Civ V - Vanilla/Difficulties.json b/android/assets/jsons/Civ V - Vanilla/Difficulties.json index f629cd13cf..52203ec2bf 100644 --- a/android/assets/jsons/Civ V - Vanilla/Difficulties.json +++ b/android/assets/jsons/Civ V - Vanilla/Difficulties.json @@ -13,6 +13,7 @@ "barbarianBonus": 0.75, "barbarianSpawnDelay": 8, "playerBonusStartingUnits": [], // Note that the units from Eras.json are added to this pool. This should only contain bonus starting units. + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1.6, // that is to say it'll take them 1.6 times as long to grow the city "aiUnitCostModifier": 1.75, "aiBuildingCostModifier": 1.6, @@ -42,6 +43,7 @@ "barbarianBonus": 0.5, "barbarianSpawnDelay": 5, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1.3, "aiUnitCostModifier": 1.3, "aiBuildingCostModifier": 1.3, @@ -71,6 +73,7 @@ "barbarianBonus": 0.4, "barbarianSpawnDelay": 3, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1.1, "aiUnitCostModifier": 1.1, "aiBuildingCostModifier": 1.1, @@ -100,6 +103,7 @@ "barbarianBonus": 0.33, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 1, "aiUnitCostModifier": 1, "aiBuildingCostModifier": 1, @@ -129,6 +133,7 @@ "barbarianBonus": 0.25, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.9, "aiUnitCostModifier": 0.85, "aiBuildingCostModifier": 0.85, @@ -158,6 +163,7 @@ "barbarianBonus": 0.2, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.85, "aiUnitCostModifier": 0.8, "aiBuildingCostModifier": 0.8, @@ -187,6 +193,7 @@ "barbarianBonus": 0.1, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.75, "aiUnitCostModifier": 0.65, "aiBuildingCostModifier": 0.65, @@ -216,6 +223,7 @@ "barbarianBonus": 0, "barbarianSpawnDelay": 0, "playerBonusStartingUnits": [], + "aiDifficultyLevel": "Chieftain", "aiCityGrowthModifier": 0.6, "aiUnitCostModifier": 0.5, "aiBuildingCostModifier": 0.5, diff --git a/core/src/com/unciv/logic/civilization/Civilization.kt b/core/src/com/unciv/logic/civilization/Civilization.kt index cf580c22fe..9d7f66add0 100644 --- a/core/src/com/unciv/logic/civilization/Civilization.kt +++ b/core/src/com/unciv/logic/civilization/Civilization.kt @@ -314,7 +314,9 @@ class Civilization : IsPartOfGameInfoSerialization { //region pure functions fun getDifficulty(): Difficulty { if (isHuman()) return gameInfo.getDifficulty() - // TODO We should be able to mark a difficulty as 'default AI difficulty' somehow + if (gameInfo.ruleset.difficulties.containsKey(gameInfo.getDifficulty().aiDifficultyLevel)) { + return gameInfo.ruleset.difficulties[gameInfo.getDifficulty().aiDifficultyLevel]!! + } val chieftainDifficulty = gameInfo.ruleset.difficulties["Chieftain"] if (chieftainDifficulty != null) return chieftainDifficulty return gameInfo.ruleset.difficulties.values.first() diff --git a/core/src/com/unciv/models/ruleset/nation/Difficulty.kt b/core/src/com/unciv/models/ruleset/nation/Difficulty.kt index 725bac28b2..b53efe6de7 100644 --- a/core/src/com/unciv/models/ruleset/nation/Difficulty.kt +++ b/core/src/com/unciv/models/ruleset/nation/Difficulty.kt @@ -22,6 +22,7 @@ class Difficulty: INamed, ICivilopediaText { var barbarianSpawnDelay: Int = 0 var playerBonusStartingUnits = ArrayList() + var aiDifficultyLevel: String? = null var aiCityGrowthModifier: Float = 1f var aiUnitCostModifier: Float = 1f var aiBuildingCostModifier: Float = 1f @@ -71,6 +72,7 @@ class Difficulty: INamed, ICivilopediaText { lines += FormattedLine() lines += FormattedLine("AI settings", header = 3) + lines += FormattedLine("{AI difficulty level}: $aiDifficultyLevel", indent = 1) lines += FormattedLine("{AI city growth modifier}: ${aiCityGrowthModifier.toPercent()}% ${Fonts.food}", indent = 1) lines += FormattedLine("{AI unit cost modifier}: ${aiUnitCostModifier.toPercent()}% ${Fonts.production}", indent = 1) lines += FormattedLine("{AI building cost modifier}: ${aiBuildingCostModifier.toPercent()}% ${Fonts.production}", indent = 1) diff --git a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt index 685ed011e9..b364624f12 100644 --- a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt @@ -202,7 +202,7 @@ class CivilopediaScreen( // do not confuse with IConstruction.shouldBeDisplayed - that one tests all prerequisites for building fun shouldBeDisplayed(obj: ICivilopediaText) = - obj is IHasUniques && !obj.isHiddenFromCivilopedia(game.gameInfo, ruleset) + obj !is IHasUniques || !obj.isHiddenFromCivilopedia(game.gameInfo, ruleset) for (loopCategory in CivilopediaCategories.entries) { if (!religionEnabled && loopCategory == CivilopediaCategories.Belief) continue