mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 17:59:11 +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.victoryscreen.RankingType
|
||||
import java.util.*
|
||||
import kotlin.NoSuchElementException
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.math.max
|
||||
@ -960,7 +961,7 @@ class CivilizationInfo {
|
||||
shouldShowDiplomaticVotingResults()
|
||||
|
||||
private fun updateRevolts() {
|
||||
if (gameInfo.civilizations.none { it.civName == Constants.barbarians }) {
|
||||
if (gameInfo.civilizations.none { it.isBarbarian() }) {
|
||||
// Can't spawn revolts without barbarians ¯\_(ツ)_/¯
|
||||
return
|
||||
}
|
||||
@ -977,6 +978,14 @@ class CivilizationInfo {
|
||||
}
|
||||
|
||||
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 rebelCount = 1 + random.nextInt(100 + 20 * (cities.size - 1)) / 100
|
||||
val spawnCity = cities.maxByOrNull { random.nextInt(it.population.population + 10) } ?: return
|
||||
@ -992,7 +1001,7 @@ class CivilizationInfo {
|
||||
gameInfo.tileMap.placeUnitNearTile(
|
||||
spawnTile.position,
|
||||
unitToSpawn.name,
|
||||
gameInfo.getBarbarianCivilization()
|
||||
barbarians
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user