From cfd12fb4b8c3195059d023d84a776efc9c994b66 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sat, 21 Sep 2024 22:40:07 +0300 Subject: [PATCH] Resolved #12177 - Getting all resources does not eliminate WLTK day --- .../unciv/logic/city/managers/CityTurnManager.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/logic/city/managers/CityTurnManager.kt b/core/src/com/unciv/logic/city/managers/CityTurnManager.kt index a2b9f27399..afb269be7b 100644 --- a/core/src/com/unciv/logic/city/managers/CityTurnManager.kt +++ b/core/src/com/unciv/logic/city/managers/CityTurnManager.kt @@ -93,17 +93,19 @@ class CityTurnManager(val city: City) { it.resourceType == ResourceType.Luxury && // Must be luxury !it.hasUnique(UniqueType.CityStateOnlyResource) && // Not a city-state only resource eg jewelry it.name != city.demandedResource && // Not same as last time - !city.civ.hasResource(it.name) && // Not one we already have it.name in city.tileMap.resources && // Must exist somewhere on the map city.getCenterTile().getTilesInDistance(city.getWorkRange()).none { nearTile -> nearTile.resource == it.name } // Not in this city's radius } + val missingResources = candidates.filter { !city.civ.hasResource(it.name) } + + if (missingResources.isEmpty()) { // hooray happpy day forever! + city.demandedResource = candidates.randomOrNull()?.name ?: "" + return // actually triggering "wtlk" is done in tryWeLoveTheKing(), *next turn* + } - val chosenResource = candidates.randomOrNull() - /* What if we had a WLTKD before but now the player has every resource in the game? We can't - pick a new resource, so the resource will stay stay the same and the city will demand it - again even if the player still has it. But we shouldn't punish success. */ - if (chosenResource != null) - city.demandedResource = chosenResource.name + val chosenResource = missingResources.randomOrNull() + + city.demandedResource = chosenResource?.name ?: "" // mods may have no resources as candidates even if (city.demandedResource == "") // Failed to get a valid resource, try again some time later city.setFlag(CityFlags.ResourceDemand, 15 + Random.Default.nextInt(10)) else