mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 07:16:54 +07:00
chore: moved citiesConnectedToCapitalToMediums to cache
This commit is contained in:
parent
5da46e727c
commit
8565762df3
@ -149,7 +149,7 @@ class City : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
fun isConnectedToCapital(connectionTypePredicate: (Set<String>) -> Boolean = { true }): Boolean {
|
||||
val mediumTypes = civ.citiesConnectedToCapitalToMediums[this] ?: return false
|
||||
val mediumTypes = civ.cache.citiesConnectedToCapitalToMediums[this] ?: return false
|
||||
return connectionTypePredicate(mediumTypes)
|
||||
}
|
||||
|
||||
|
@ -99,10 +99,6 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
@Transient
|
||||
var viewableInvisibleUnitsTiles = setOf<Tile>()
|
||||
|
||||
/** Contains mapping of cities to travel mediums from ALL civilizations connected by trade routes to the capital */
|
||||
@Transient
|
||||
var citiesConnectedToCapitalToMediums = mapOf<City, Set<String>>()
|
||||
|
||||
/** This is for performance since every movement calculation depends on this, see MapUnit comment */
|
||||
@Transient
|
||||
var hasActiveEnemyMovementPenalty = false
|
||||
@ -396,7 +392,7 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
return newResourceSupplyList
|
||||
}
|
||||
|
||||
fun isCapitalConnectedToCity(city: City): Boolean = citiesConnectedToCapitalToMediums.keys.contains(city)
|
||||
fun isCapitalConnectedToCity(city: City): Boolean = cache.citiesConnectedToCapitalToMediums.keys.contains(city)
|
||||
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.logic.civilization.transients
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.city.City
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.civilization.NotificationCategory
|
||||
import com.unciv.logic.civilization.NotificationIcon
|
||||
@ -34,6 +35,10 @@ class CivInfoTransientCache(val civInfo: Civilization) {
|
||||
@Transient
|
||||
val uniqueBuildings = hashSetOf<Building>()
|
||||
|
||||
/** Contains mapping of cities to travel mediums from ALL civilizations connected by trade routes to the capital */
|
||||
@Transient
|
||||
var citiesConnectedToCapitalToMediums = mapOf<City, Set<String>>()
|
||||
|
||||
fun setTransients(){
|
||||
val ruleset = civInfo.gameInfo.ruleset
|
||||
for (resource in ruleset.tileResources.values.asSequence().filter { it.resourceType == ResourceType.Strategic }.map { it.name }) {
|
||||
@ -235,20 +240,20 @@ class CivInfoTransientCache(val civInfo: Civilization) {
|
||||
|
||||
if (!initialSetup) { // In the initial setup we're loading an old game state, so it doesn't really count
|
||||
for (city in citiesReachedToMediums.keys)
|
||||
if (city !in civInfo.citiesConnectedToCapitalToMediums && city.civ == civInfo && city != civInfo.getCapital()!!)
|
||||
if (city !in citiesConnectedToCapitalToMediums && city.civ == civInfo && city != civInfo.getCapital()!!)
|
||||
civInfo.addNotification("[${city.name}] has been connected to your capital!",
|
||||
city.location, NotificationCategory.Cities, NotificationIcon.Gold
|
||||
)
|
||||
|
||||
// This may still contain cities that have just been destroyed by razing - thus the population test
|
||||
for (city in civInfo.citiesConnectedToCapitalToMediums.keys)
|
||||
for (city in citiesConnectedToCapitalToMediums.keys)
|
||||
if (!citiesReachedToMediums.containsKey(city) && city.civ == civInfo && city.population.population > 0)
|
||||
civInfo.addNotification("[${city.name}] has been disconnected from your capital!",
|
||||
city.location, NotificationCategory.Cities, NotificationIcon.Gold
|
||||
)
|
||||
}
|
||||
|
||||
civInfo.citiesConnectedToCapitalToMediums = citiesReachedToMediums
|
||||
citiesConnectedToCapitalToMediums = citiesReachedToMediums
|
||||
}
|
||||
|
||||
fun updateCivResources() {
|
||||
|
@ -488,7 +488,7 @@ class WorldScreen(
|
||||
"\n Click 'Construct improvement' (above the unit table, bottom left)" +
|
||||
"\n > Choose the farm > \n Leave the worker there until it's finished"
|
||||
if (!completedTasks.contains("Create a trade route")
|
||||
&& viewingCiv.citiesConnectedToCapitalToMediums.any { it.key.civ == viewingCiv })
|
||||
&& viewingCiv.cache.citiesConnectedToCapitalToMediums.any { it.key.civ == viewingCiv })
|
||||
game.settings.addCompletedTutorialTask("Create a trade route")
|
||||
if (viewingCiv.cities.size > 1 && !completedTasks.contains("Create a trade route"))
|
||||
return "Create a trade route!\nConstruct roads between your capital and another city" +
|
||||
|
Loading…
Reference in New Issue
Block a user