From af49e8297ffdf3d9ab1f6e32a2778cf88218fb5d Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 4 Aug 2023 09:29:34 +0300 Subject: [PATCH] #9876 fix - Lock known city states before gaining influence to avoid altering the sequence we're iterating on --- .../unciv/logic/automation/civilization/NextTurnAutomation.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt index 3a155dab85..da2da49cab 100644 --- a/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt @@ -293,7 +293,9 @@ object NextTurnAutomation { } private fun useGoldForCityStates(civ: Civilization) { - val knownCityStates = civ.getKnownCivs().filter { it.isCityState() } + // RARE EDGE CASE: If you ally with a city-state, you may reveal more map that includes ANOTHER civ! + // So if we don't lock this list, we may later discover that there are more known civs, concurrent modification exception! + val knownCityStates = civ.getKnownCivs().filter { it.isCityState() }.toList() // canBeMarriedBy checks actual cost, but it can't be below 500*speedmodifier, and the later check is expensive if (civ.gold >= 330 && civ.getHappiness() > 0 && civ.hasUnique(UniqueType.CityStateCanBeBoughtForGold)) {