From 69ce160ff924333a912016b53978e4d1bb7fabe2 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 10 Dec 2023 22:59:45 +0200 Subject: [PATCH] Added 'relevant city' to conditionals, taking the city from the relevant tile where no city provided directly (#10684) --- core/src/com/unciv/models/ruleset/unique/Unique.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/Unique.kt b/core/src/com/unciv/models/ruleset/unique/Unique.kt index 25429f9841..bd7e8d14c7 100644 --- a/core/src/com/unciv/models/ruleset/unique/Unique.kt +++ b/core/src/com/unciv/models/ruleset/unique/Unique.kt @@ -155,10 +155,15 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s ?: state.city?.getCenterTile() } + val relevantCity by lazy { + state.city + ?: relevantTile?.getCity() + } + val stateBasedRandom by lazy { Random(state.hashCode()) } fun getResourceAmount(resourceName: String): Int { - if (state.city != null) return state.city.getResourceAmount(resourceName) + if (relevantCity != null) return relevantCity!!.getResourceAmount(resourceName) if (state.civInfo != null) return state.civInfo.getResourceAmount(resourceName) return 0 } @@ -171,8 +176,8 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s /** Helper to simplify conditional tests requiring a City */ fun checkOnCity(predicate: (City.() -> Boolean)): Boolean { - if (state.city == null) return false - return state.city.predicate() + if (relevantCity == null) return false + return relevantCity!!.predicate() } /** Helper to simplify the "compare civ's current era with named era" conditions */