Console command to change difficulty (#12039)

This commit is contained in:
SomeTroglodyte
2024-08-03 22:18:23 +02:00
committed by GitHub
parent 6bafab3c71
commit d0e6dfcdfa
4 changed files with 17 additions and 2 deletions

View File

@ -149,7 +149,7 @@ class DiplomacyFunctions(val civInfo: Civilization) {
fun canPassThroughTiles(otherCiv: Civilization): Boolean {
if (otherCiv == civInfo) return true
if (otherCiv.isBarbarian) return true
if (civInfo.isBarbarian && civInfo.gameInfo.turns >= civInfo.gameInfo.difficultyObject.turnBarbariansCanEnterPlayerTiles)
if (civInfo.isBarbarian && civInfo.gameInfo.turns >= civInfo.gameInfo.getDifficulty().turnBarbariansCanEnterPlayerTiles)
return true
val diplomacyManager = civInfo.diplomacy[otherCiv.civName]
if (diplomacyManager != null && (diplomacyManager.hasOpenBorders || diplomacyManager.diplomaticStatus == DiplomaticStatus.War))

View File

@ -0,0 +1,13 @@
package com.unciv.ui.screens.devconsole
internal class ConsoleGameCommands : ConsoleCommandNode {
override val subcommands = hashMapOf<String, ConsoleCommand>(
"setdifficulty" to ConsoleAction("game setdifficulty <difficulty>") { console, params ->
val difficulty = params[0].findOrNull(console.gameInfo.ruleset.difficulties.values)
?: throw ConsoleErrorException("Unrecognized difficulty")
console.gameInfo.difficulty = difficulty.name
console.gameInfo.setTransients()
DevConsoleResponse.OK
},
)
}

View File

@ -35,6 +35,7 @@ internal enum class ConsoleParameterType(
techName( { ruleset.technologies.keys } ),
cityName( { civilizations.flatMap { civ -> civ.cities.map { it.name } } } ),
triggeredUniqueTemplate( { UniqueType.values().filter { it.canAcceptUniqueTarget(UniqueTarget.Triggerable) }.map { it.text } }, preferquoted = true ),
difficulty( { ruleset.difficulties.keys } )
;
private fun getOptions(console: DevConsolePopup) = console.gameInfo.getOptions()

View File

@ -91,6 +91,7 @@ internal class ConsoleCommandRoot : ConsoleCommandNode {
"history" to ConsoleAction("history") { console, _ ->
console.showHistory()
DevConsoleResponse.hint("") // Trick console into staying open
}
},
"game" to ConsoleGameCommands()
)
}