mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
Added tests to ensure that resources from buildings behave as expected (#9860)
* Added tests to ensure that resources from buildings behave as expected * More tests suggested by @SeventhM * Caught an edge case - if you pillage your own tile improvement, your resources would not have updated! * Actually every time an improvement changes you could have a resource change * Update resources eon every improvement change because they could be providing resources via uniques
This commit is contained in:
@ -21,8 +21,8 @@ import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.unique.LocalUniqueCache
|
||||
import com.unciv.models.ruleset.unique.StateForConditionals
|
||||
import com.unciv.models.ruleset.unique.UniqueMap
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
@ -513,11 +513,11 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
UniqueType.StatsFromTiles, UniqueType.StatsFromTilesWithout, UniqueType.StatsFromObject,
|
||||
UniqueType.StatPercentFromObject, UniqueType.AllStatsPercentFromObject
|
||||
)
|
||||
|
||||
|
||||
updateUniques()
|
||||
|
||||
|
||||
// Happiness is global, so it could affect all cities
|
||||
if(building.isStatRelated(Stat.Happiness)) {
|
||||
if (building.isStatRelated(Stat.Happiness)) {
|
||||
for (city in civ.cities) {
|
||||
city.reassignPopulationDeferred()
|
||||
}
|
||||
@ -525,8 +525,6 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
else if(uniqueTypesModifyingYields.any { building.hasUnique(it) })
|
||||
city.reassignPopulationDeferred()
|
||||
|
||||
city.civ.cache.updateCivResources() // this building could be a resource-requiring one
|
||||
|
||||
addFreeBuildings()
|
||||
}
|
||||
|
||||
@ -556,14 +554,16 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
builtBuildings.remove(buildingName)
|
||||
city.civ.cache.updateCitiesConnectedToCapital(false) // could be a connecting building, like a harbor
|
||||
updateUniques()
|
||||
city.civ.cache.updateCivResources() // this building could be a resource-requiring one
|
||||
}
|
||||
|
||||
fun updateUniques(onLoadGame:Boolean = false) {
|
||||
builtBuildingUniqueMap.clear()
|
||||
for (building in getBuiltBuildings())
|
||||
builtBuildingUniqueMap.addUniques(building.uniqueObjects)
|
||||
if (!onLoadGame) city.cityStats.update()
|
||||
if (!onLoadGame) {
|
||||
city.cityStats.update()
|
||||
city.civ.cache.updateCivResources()
|
||||
}
|
||||
}
|
||||
|
||||
fun addFreeBuildings() {
|
||||
|
@ -689,6 +689,8 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
|
||||
tacticalAI.init(this)
|
||||
|
||||
cache.updateCivResources()
|
||||
|
||||
cache.setTransients()
|
||||
}
|
||||
|
||||
|
@ -311,6 +311,11 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
fun changeImprovement(improvementStr: String?) {
|
||||
improvementIsPillaged = false
|
||||
improvement = improvementStr
|
||||
|
||||
|
||||
if (owningCity != null){
|
||||
owningCity!!.civ.cache.updateCivResources()
|
||||
}
|
||||
}
|
||||
|
||||
// function handling when adding a road to the tile
|
||||
@ -931,6 +936,8 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
owningCity?.reassignPopulationDeferred()
|
||||
if (owningCity != null)
|
||||
owningCity!!.civ.cache.updateCivResources()
|
||||
}
|
||||
|
||||
fun isPillaged(): Boolean {
|
||||
|
Reference in New Issue
Block a user