mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 18:28:42 +07:00
Fixed bugs with diplomatic victory (#5474)
This commit is contained in:
@ -835,11 +835,10 @@ class CivilizationInfo {
|
|||||||
|
|
||||||
private fun startTurnFlags() {
|
private fun startTurnFlags() {
|
||||||
for (flag in flagsCountdown.keys.toList()) {
|
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
|
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) {
|
||||||
if (flag == CivFlags.CityStateGreatPersonGift.name || flag.equals(CivFlags.CityStateGreatPersonGift.name, ignoreCase = true)) {
|
|
||||||
val cityStateAllies = getKnownCivs().filter { it.isCityState() && it.getAllyCiv() == civName }
|
val cityStateAllies = getKnownCivs().filter { it.isCityState() && it.getAllyCiv() == civName }
|
||||||
|
|
||||||
if (cityStateAllies.any()) flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
if (cityStateAllies.any()) flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
||||||
@ -858,30 +857,34 @@ class CivilizationInfo {
|
|||||||
if (flagsCountdown[flag]!! > 0)
|
if (flagsCountdown[flag]!! > 0)
|
||||||
flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
flagsCountdown[flag] = flagsCountdown[flag]!! - 1
|
||||||
|
|
||||||
if (flagsCountdown[flag]!! != 0) continue
|
}
|
||||||
|
handleDiplomaticVictoryFlags()
|
||||||
|
}
|
||||||
|
|
||||||
when (flag) {
|
private fun handleDiplomaticVictoryFlags() {
|
||||||
CivFlags.TurnsTillNextDiplomaticVote.name -> addFlag(CivFlags.ShowDiplomaticVotingResults.name, 1)
|
if (flagsCountdown[CivFlags.ShouldResetDiplomaticVotes.name] == 0) {
|
||||||
CivFlags.ShouldResetDiplomaticVotes.name -> {
|
gameInfo.diplomaticVictoryVotesCast.clear()
|
||||||
gameInfo.diplomaticVictoryVotesCast.clear()
|
removeFlag(CivFlags.ShouldResetDiplomaticVotes.name)
|
||||||
removeFlag(CivFlags.ShouldResetDiplomaticVotes.name)
|
removeFlag(CivFlags.ShowDiplomaticVotingResults.name)
|
||||||
removeFlag(CivFlags.ShowDiplomaticVotingResults.name)
|
}
|
||||||
}
|
|
||||||
CivFlags.ShowDiplomaticVotingResults.name -> {
|
|
||||||
|
|
||||||
if (gameInfo.civilizations.any { it.victoryManager.hasWon() } )
|
if (flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0) {
|
||||||
// We have either already done this calculation, or it doesn't matter anymore,
|
if (gameInfo.civilizations.any { it.victoryManager.hasWon() } ) {
|
||||||
// so don't waste resources doing it
|
removeFlag(CivFlags.TurnsTillNextDiplomaticVote.name)
|
||||||
continue
|
} else {
|
||||||
|
addFlag(CivFlags.ShouldResetDiplomaticVotes.name, 1)
|
||||||
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 addFlag(flag: String, count: Int) = flagsCountdown.set(flag, count)
|
||||||
fun removeFlag(flag: String) { flagsCountdown.remove(flag) }
|
|
||||||
|
fun removeFlag(flag: String) = flagsCountdown.remove(flag)
|
||||||
|
|
||||||
fun getTurnsBetweenDiplomaticVotings() = (15 * gameInfo.gameParameters.gameSpeed.modifier).toInt() // Dunno the exact calculation, hidden in Lua files
|
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?) {
|
fun diplomaticVoteForCiv(chosenCivName: String?) {
|
||||||
if (chosenCivName != null) gameInfo.diplomaticVictoryVotesCast[civName] = chosenCivName
|
if (chosenCivName != null) gameInfo.diplomaticVictoryVotesCast[civName] = chosenCivName
|
||||||
addFlag(CivFlags.TurnsTillNextDiplomaticVote.name, getTurnsBetweenDiplomaticVotings())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldShowDiplomaticVotingResults() =
|
fun shouldShowDiplomaticVotingResults() =
|
||||||
|
@ -52,12 +52,13 @@ class VictoryManager {
|
|||||||
|
|
||||||
fun hasEnoughVotesForDiplomaticVictory(): Boolean {
|
fun hasEnoughVotesForDiplomaticVictory(): Boolean {
|
||||||
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
||||||
val bestCiv = results.maxByOrNull { it.value }
|
val bestCiv = results.maxByOrNull { it.value } ?: return false
|
||||||
if (bestCiv == null) return false
|
|
||||||
|
|
||||||
// If we don't have the highest score, we have not won anyway
|
// If we don't have the highest score, we have not won anyway
|
||||||
if (bestCiv.key != civInfo.civName) return false
|
if (bestCiv.key != civInfo.civName) return false
|
||||||
|
|
||||||
|
if (bestCiv.value < votesNeededForDiplomaticVictory()) return false
|
||||||
|
|
||||||
// If there's a tie, we haven't won either
|
// If there's a tie, we haven't won either
|
||||||
return (results.none { it != bestCiv && it.value == bestCiv.value })
|
return (results.none { it != bestCiv && it.value == bestCiv.value })
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user