mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 05:14:32 -04:00
Do not trigger the Time Victory if it is not enabled (#7197)
* Whitespaces * Use the proper list of victory types * Clean up if the victory type was removed
This commit is contained in:
parent
1facd97782
commit
35a4f079b1
@ -28,7 +28,7 @@ class VictoryManager {
|
|||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun votesNeededForDiplomaticVictory(): Int {
|
private fun votesNeededForDiplomaticVictory(): Int {
|
||||||
val civCount = civInfo.gameInfo.civilizations.count { !it.isDefeated() }
|
val civCount = civInfo.gameInfo.civilizations.count { !it.isDefeated() }
|
||||||
|
|
||||||
@ -38,24 +38,24 @@ class VictoryManager {
|
|||||||
else (67 - 1.1 * civCount) / 100 * civCount
|
else (67 - 1.1 * civCount) / 100 * civCount
|
||||||
).toInt()
|
).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasEnoughVotesForDiplomaticVictory(): Boolean {
|
fun hasEnoughVotesForDiplomaticVictory(): Boolean {
|
||||||
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
||||||
val bestCiv = results.maxByOrNull { it.value } ?: return false
|
val bestCiv = results.maxByOrNull { it.value } ?: 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 we don't have enough votes, we haven't won
|
// If we don't have enough votes, we haven't won
|
||||||
if (bestCiv.value < votesNeededForDiplomaticVictory()) 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 })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVictoryTypeAchieved(): String? {
|
fun getVictoryTypeAchieved(): String? {
|
||||||
if (!civInfo.isMajorCiv()) return null
|
if (!civInfo.isMajorCiv()) return null
|
||||||
for (victoryName in civInfo.gameInfo.ruleSet.victories.keys.filter { it != Constants.neutralVictoryType}) {
|
for (victoryName in civInfo.gameInfo.gameParameters.victoryTypes.filter { it != Constants.neutralVictoryType}) {
|
||||||
if (getNextMilestone(victoryName) == null)
|
if (getNextMilestone(victoryName) == null)
|
||||||
return victoryName
|
return victoryName
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ class VictoryManager {
|
|||||||
return Constants.neutralVictoryType
|
return Constants.neutralVictoryType
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getNextMilestone(victory: String): Milestone? {
|
fun getNextMilestone(victory: String): Milestone? {
|
||||||
for (milestone in civInfo.gameInfo.ruleSet.victories[victory]!!.milestoneObjects) {
|
for (milestone in civInfo.gameInfo.ruleSet.victories[victory]!!.milestoneObjects) {
|
||||||
if (!milestone.hasBeenCompletedBy(civInfo))
|
if (!milestone.hasBeenCompletedBy(civInfo))
|
||||||
@ -71,7 +71,7 @@ class VictoryManager {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun amountMilestonesCompleted(victory: String): Int {
|
fun amountMilestonesCompleted(victory: String): Int {
|
||||||
var completed = 0
|
var completed = 0
|
||||||
for (milestone in civInfo.gameInfo.ruleSet.victories[victory]!!.milestoneObjects) {
|
for (milestone in civInfo.gameInfo.ruleSet.victories[victory]!!.milestoneObjects) {
|
||||||
@ -84,4 +84,4 @@ class VictoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun hasWon() = getVictoryTypeAchieved() != null
|
fun hasWon() = getVictoryTypeAchieved() != null
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,9 @@ class NewGameScreen(
|
|||||||
updateRuleset() // must come before playerPickerTable so mod nations from fromSettings
|
updateRuleset() // must come before playerPickerTable so mod nations from fromSettings
|
||||||
// Has to be initialized before the mapOptionsTable, since the mapOptionsTable refers to it on init
|
// Has to be initialized before the mapOptionsTable, since the mapOptionsTable refers to it on init
|
||||||
|
|
||||||
|
// remove the victory types which are not in the rule set (e.g. were in the recently disabled mod)
|
||||||
|
gameSetupInfo.gameParameters.victoryTypes.removeAll { it !in ruleset.victories.keys }
|
||||||
|
|
||||||
if (gameSetupInfo.gameParameters.victoryTypes.isEmpty())
|
if (gameSetupInfo.gameParameters.victoryTypes.isEmpty())
|
||||||
gameSetupInfo.gameParameters.victoryTypes.addAll(ruleset.victories.keys)
|
gameSetupInfo.gameParameters.victoryTypes.addAll(ruleset.victories.keys)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user