From a6f8f578609e558a846debd07c5c4c700c937532 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 24 Apr 2023 13:56:10 +0200 Subject: [PATCH] Avoid first contact alerts for dead City-States (#9269) * Avoid first contact alerts for dead City-States * Clearer simpler (hopefully) updateOurTiles --- .../transients/CivInfoTransientCache.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt b/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt index fc5ce73f36..657c839b4e 100644 --- a/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt +++ b/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt @@ -143,19 +143,26 @@ class CivInfoTransientCache(val civInfo: Civilization) { /** Our tiles update pretty infrequently - most 'viewable tile' changes are due to unit movements, * which means we can store this separately and use it 'as is' so we don't need to find the neighboring tiles every time * a unit moves */ - fun updateOurTiles(){ - val newOurTilesAndNeighboring = HashSet() - val ownedTiles = civInfo.cities.asSequence().flatMap { it.getTiles() } - newOurTilesAndNeighboring.addAll(ownedTiles) - val neighboringUnownedTiles = ownedTiles.flatMap { tile -> tile.neighbors.filter { it.getOwner() != civInfo } } - newOurTilesAndNeighboring.addAll(neighboringUnownedTiles) - ourTilesAndNeighboringTiles = newOurTilesAndNeighboring + fun updateOurTiles() { + ourTilesAndNeighboringTiles = civInfo.cities.asSequence() + .flatMap { it.getTiles() } // our owned tiles, still distinct + .flatMap { sequenceOf(it) + it.neighbors } + // now we got a mix of owned, unowned and competitor-owned tiles, and **duplicates** + // but Sequence.toSet is just as good at making them distinct as any other operation + .toSet() updateViewableTiles() updateCivResources() } private fun setNewViewableTiles() { + if (civInfo.isDefeated()) { + // Avoid meeting dead city states when entering a tile owned by their former ally (#9245) + // In that case ourTilesAndNeighboringTiles and getCivUnits will be empty, but the for + // loop getKnownCivs/getAllyCiv would add tiles. + civInfo.viewableTiles = emptySet() + return + } // while spectating all map is visible if (civInfo.isSpectator() || DebugUtils.VISIBLE_MAP) {