Fixed a rare diplomacy voting bug in one-more-turn mode (#5845)

* Fixed a rare bug where in one-more-turn mode after conquering all other civs, players could be asked to vote, despite having no one to vote for

* Removed code duplication
This commit is contained in:
Xander Lenstra 2021-12-27 08:01:04 +01:00 committed by GitHub
parent f03918f610
commit f14ec29468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -930,6 +930,8 @@ class CivilizationInfo {
fun mayVoteForDiplomaticVictory() =
getTurnsTillNextDiplomaticVote() == 0
&& civName !in gameInfo.diplomaticVictoryVotesCast.keys
// Only vote if there is someone to vote for, may happen in one-more-turn mode
&& gameInfo.civilizations.any { it.isMajorCiv() && !it.isDefeated() && it != this }
fun diplomaticVoteForCiv(chosenCivName: String?) {
if (chosenCivName != null) gameInfo.diplomaticVictoryVotesCast[civName] = chosenCivName
@ -937,10 +939,11 @@ class CivilizationInfo {
fun shouldShowDiplomaticVotingResults() =
flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0
&& gameInfo.civilizations.any { it.isMajorCiv() && !it.isDefeated() && it != this }
// Yes, this is the same function as above, but with a different use case so it has a different name.
fun shouldCheckForDiplomaticVictory() =
flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0
shouldShowDiplomaticVotingResults()
/** Modify gold by a given amount making sure it does neither overflow nor underflow.
* @param delta the amount to add (can be negative)