Make AI difficulty changable (#11996)

* Added AIDifficultyLevel to the difficulty object

* Fixed difficulty levels not showing in the cyclopedia screen
This commit is contained in:
Oskar Niesen 2024-07-21 02:01:15 -05:00 committed by GitHub
parent 37b4bcbda8
commit 7d69945c57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 2 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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()

View File

@ -22,6 +22,7 @@ class Difficulty: INamed, ICivilopediaText {
var barbarianSpawnDelay: Int = 0
var playerBonusStartingUnits = ArrayList<String>()
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)

View File

@ -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