mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
Additional guard against no-barbarian games calling doRevoltSpawn (#6213)
This commit is contained in:
@ -30,6 +30,7 @@ import com.unciv.ui.utils.MayaCalendar
|
|||||||
import com.unciv.ui.utils.toPercent
|
import com.unciv.ui.utils.toPercent
|
||||||
import com.unciv.ui.victoryscreen.RankingType
|
import com.unciv.ui.victoryscreen.RankingType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.NoSuchElementException
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@ -960,7 +961,7 @@ class CivilizationInfo {
|
|||||||
shouldShowDiplomaticVotingResults()
|
shouldShowDiplomaticVotingResults()
|
||||||
|
|
||||||
private fun updateRevolts() {
|
private fun updateRevolts() {
|
||||||
if (gameInfo.civilizations.none { it.civName == Constants.barbarians }) {
|
if (gameInfo.civilizations.none { it.isBarbarian() }) {
|
||||||
// Can't spawn revolts without barbarians ¯\_(ツ)_/¯
|
// Can't spawn revolts without barbarians ¯\_(ツ)_/¯
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -977,6 +978,14 @@ class CivilizationInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun doRevoltSpawn() {
|
private fun doRevoltSpawn() {
|
||||||
|
val barbarians = try {
|
||||||
|
// The first test in `updateRevolts` should prevent getting here in a no-barbarians game, but it has been shown to still occur
|
||||||
|
gameInfo.getBarbarianCivilization()
|
||||||
|
} catch (ex: NoSuchElementException) {
|
||||||
|
removeFlag(CivFlags.RevoltSpawning.name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val random = Random()
|
val random = Random()
|
||||||
val rebelCount = 1 + random.nextInt(100 + 20 * (cities.size - 1)) / 100
|
val rebelCount = 1 + random.nextInt(100 + 20 * (cities.size - 1)) / 100
|
||||||
val spawnCity = cities.maxByOrNull { random.nextInt(it.population.population + 10) } ?: return
|
val spawnCity = cities.maxByOrNull { random.nextInt(it.population.population + 10) } ?: return
|
||||||
@ -992,7 +1001,7 @@ class CivilizationInfo {
|
|||||||
gameInfo.tileMap.placeUnitNearTile(
|
gameInfo.tileMap.placeUnitNearTile(
|
||||||
spawnTile.position,
|
spawnTile.position,
|
||||||
unitToSpawn.name,
|
unitToSpawn.name,
|
||||||
gameInfo.getBarbarianCivilization()
|
barbarians
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user