Close immediate win loophole (playing alone) (#9176)

This commit is contained in:
SomeTroglodyte 2023-04-13 10:52:16 +02:00 committed by GitHub
parent 19b243abfe
commit 2e61023248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View File

@ -221,17 +221,14 @@ class GameOptionsTable(
private fun Table.addRandomPlayersCheckbox() =
addCheckbox("Random number of Civilizations", gameParameters.randomNumberOfPlayers)
{newRandomNumberOfPlayers ->
{ newRandomNumberOfPlayers ->
gameParameters.randomNumberOfPlayers = newRandomNumberOfPlayers
if (newRandomNumberOfPlayers) {
// remove all random AI from player picker
val newPlayers = gameParameters.players.asSequence()
gameParameters.players = gameParameters.players.asSequence()
.filterNot { it.playerType == PlayerType.AI && it.chosenCiv == Constants.random }
.toCollection(ArrayList(gameParameters.players.size))
if (newPlayers.size != gameParameters.players.size) {
gameParameters.players = newPlayers
updatePlayerPickerTable("")
}
updatePlayerPickerTable("")
} else {
// Fill up player picker with random AI until previously active min reached
val additionalRandom = gameParameters.minNumberOfPlayers - gameParameters.players.size

View File

@ -65,6 +65,7 @@ class NewGameScreen(
if (gameSetupInfo.gameParameters.victoryTypes.isEmpty())
gameSetupInfo.gameParameters.victoryTypes.addAll(ruleset.victories.keys)
rightSideButton.enable() // now because PlayerPickerTable init might disable it again
playerPickerTable = PlayerPickerTable(
this, gameSetupInfo.gameParameters,
if (isPortrait) stage.width - 20f else 0f
@ -98,7 +99,6 @@ class NewGameScreen(
}
}
rightSideButton.enable()
rightSideButton.setText("Start game!".tr())
rightSideButton.onClick(this::onStartGameClicked)
}

View File

@ -124,7 +124,7 @@ class PlayerPickerTable(
// enable start game when at least one human player and they're not alone
val humanPlayerCount = gameParameters.players.count { it.playerType == PlayerType.Human }
val isValid = humanPlayerCount >= 1
val isValid = humanPlayerCount >= 1 && (isRandomNumberOfPlayers || gameParameters.players.size >= 2)
(previousScreen as? PickerScreen)?.setRightSideButtonEnabled(isValid)
}