mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-02 12:24:15 +07:00
Fixed bugs with diplomatic victory (#5474)
This commit is contained in:
parent
56222a0ea7
commit
734fba8f30
@ -835,11 +835,10 @@ class CivilizationInfo {
|
||||
|
||||
private fun startTurnFlags() {
|
||||
for (flag in flagsCountdown.keys.toList()) {
|
||||
// There are cases where we remove flags while iterating, like ShowDiplomaticVotingResults
|
||||
// In case we remove flags while iterating
|
||||
if (!flagsCountdown.containsKey(flag)) continue
|
||||
|
||||
// the "ignoreCase = true" is to catch 'cityStateGreatPersonGift' instead of 'CityStateGreatPersonGift' being in old save files
|
||||
if (flag == CivFlags.CityStateGreatPersonGift.name || flag.equals(CivFlags.CityStateGreatPersonGift.name, ignoreCase = true)) {
|
||||
if (flag == CivFlags.CityStateGreatPersonGift.name) {
|
||||
val cityStateAllies = getKnownCivs().filter { it.isCityState() && it.getAllyCiv() == civName }
|
||||
|
||||
if (cityStateAllies.any()) flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
||||
@ -857,31 +856,35 @@ class CivilizationInfo {
|
||||
|
||||
if (flagsCountdown[flag]!! > 0)
|
||||
flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
||||
|
||||
if (flagsCountdown[flag]!! != 0) continue
|
||||
|
||||
when (flag) {
|
||||
CivFlags.TurnsTillNextDiplomaticVote.name -> addFlag(CivFlags.ShowDiplomaticVotingResults.name, 1)
|
||||
CivFlags.ShouldResetDiplomaticVotes.name -> {
|
||||
gameInfo.diplomaticVictoryVotesCast.clear()
|
||||
removeFlag(CivFlags.ShouldResetDiplomaticVotes.name)
|
||||
removeFlag(CivFlags.ShowDiplomaticVotingResults.name)
|
||||
}
|
||||
CivFlags.ShowDiplomaticVotingResults.name -> {
|
||||
|
||||
if (gameInfo.civilizations.any { it.victoryManager.hasWon() } )
|
||||
// We have either already done this calculation, or it doesn't matter anymore,
|
||||
// so don't waste resources doing it
|
||||
continue
|
||||
|
||||
addFlag(CivFlags.ShouldResetDiplomaticVotes.name, 1)
|
||||
}
|
||||
|
||||
}
|
||||
handleDiplomaticVictoryFlags()
|
||||
}
|
||||
|
||||
private fun handleDiplomaticVictoryFlags() {
|
||||
if (flagsCountdown[CivFlags.ShouldResetDiplomaticVotes.name] == 0) {
|
||||
gameInfo.diplomaticVictoryVotesCast.clear()
|
||||
removeFlag(CivFlags.ShouldResetDiplomaticVotes.name)
|
||||
removeFlag(CivFlags.ShowDiplomaticVotingResults.name)
|
||||
}
|
||||
|
||||
if (flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0) {
|
||||
if (gameInfo.civilizations.any { it.victoryManager.hasWon() } ) {
|
||||
removeFlag(CivFlags.TurnsTillNextDiplomaticVote.name)
|
||||
} else {
|
||||
addFlag(CivFlags.ShouldResetDiplomaticVotes.name, 1)
|
||||
addFlag(CivFlags.TurnsTillNextDiplomaticVote.name, getTurnsBetweenDiplomaticVotings())
|
||||
}
|
||||
}
|
||||
|
||||
if (flagsCountdown[CivFlags.TurnsTillNextDiplomaticVote.name] == 0) {
|
||||
addFlag(CivFlags.ShowDiplomaticVotingResults.name, 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun addFlag(flag: String, count: Int) { flagsCountdown[flag] = count }
|
||||
fun removeFlag(flag: String) { flagsCountdown.remove(flag) }
|
||||
fun addFlag(flag: String, count: Int) = flagsCountdown.set(flag, count)
|
||||
|
||||
fun removeFlag(flag: String) = flagsCountdown.remove(flag)
|
||||
|
||||
fun getTurnsBetweenDiplomaticVotings() = (15 * gameInfo.gameParameters.gameSpeed.modifier).toInt() // Dunno the exact calculation, hidden in Lua files
|
||||
|
||||
@ -895,7 +898,6 @@ class CivilizationInfo {
|
||||
|
||||
fun diplomaticVoteForCiv(chosenCivName: String?) {
|
||||
if (chosenCivName != null) gameInfo.diplomaticVictoryVotesCast[civName] = chosenCivName
|
||||
addFlag(CivFlags.TurnsTillNextDiplomaticVote.name, getTurnsBetweenDiplomaticVotings())
|
||||
}
|
||||
|
||||
fun shouldShowDiplomaticVotingResults() =
|
||||
|
@ -52,12 +52,13 @@ class VictoryManager {
|
||||
|
||||
fun hasEnoughVotesForDiplomaticVictory(): Boolean {
|
||||
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
||||
val bestCiv = results.maxByOrNull { it.value }
|
||||
if (bestCiv == null) return false
|
||||
val bestCiv = results.maxByOrNull { it.value } ?: return false
|
||||
|
||||
// If we don't have the highest score, we have not won anyway
|
||||
if (bestCiv.key != civInfo.civName) return false
|
||||
|
||||
if (bestCiv.value < votesNeededForDiplomaticVictory()) return false
|
||||
|
||||
// If there's a tie, we haven't won either
|
||||
return (results.none { it != bestCiv && it.value == bestCiv.value })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user