mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-12 00:39:56 +07:00
Avoid first contact alerts for dead City-States (#9269)
* Avoid first contact alerts for dead City-States * Clearer simpler (hopefully) updateOurTiles
This commit is contained in:
@ -143,19 +143,26 @@ class CivInfoTransientCache(val civInfo: Civilization) {
|
|||||||
/** Our tiles update pretty infrequently - most 'viewable tile' changes are due to unit movements,
|
/** 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
|
* 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 */
|
* a unit moves */
|
||||||
fun updateOurTiles(){
|
fun updateOurTiles() {
|
||||||
val newOurTilesAndNeighboring = HashSet<Tile>()
|
ourTilesAndNeighboringTiles = civInfo.cities.asSequence()
|
||||||
val ownedTiles = civInfo.cities.asSequence().flatMap { it.getTiles() }
|
.flatMap { it.getTiles() } // our owned tiles, still distinct
|
||||||
newOurTilesAndNeighboring.addAll(ownedTiles)
|
.flatMap { sequenceOf(it) + it.neighbors }
|
||||||
val neighboringUnownedTiles = ownedTiles.flatMap { tile -> tile.neighbors.filter { it.getOwner() != civInfo } }
|
// now we got a mix of owned, unowned and competitor-owned tiles, and **duplicates**
|
||||||
newOurTilesAndNeighboring.addAll(neighboringUnownedTiles)
|
// but Sequence.toSet is just as good at making them distinct as any other operation
|
||||||
ourTilesAndNeighboringTiles = newOurTilesAndNeighboring
|
.toSet()
|
||||||
|
|
||||||
updateViewableTiles()
|
updateViewableTiles()
|
||||||
updateCivResources()
|
updateCivResources()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setNewViewableTiles() {
|
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
|
// while spectating all map is visible
|
||||||
if (civInfo.isSpectator() || DebugUtils.VISIBLE_MAP) {
|
if (civInfo.isSpectator() || DebugUtils.VISIBLE_MAP) {
|
||||||
|
Reference in New Issue
Block a user