diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index ff987ee9a1..4730e2bc0a 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -467,7 +467,7 @@ class City : IsPartOfGameInfoSerialization { // Move the capital if destroyed (by a nuke or by razing) // Must be before removing existing capital because we may be annexing a puppet which means city stats update - see #8337 - if (isCapital()) civ.moveCapitalToNextLargest() + if (isCapital()) civ.moveCapitalToNextLargest(null) civ.cities = civ.cities.toMutableList().apply { remove(this@City) } getCenterTile().changeImprovement("City ruins") diff --git a/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt b/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt index 893c82d478..2e00ab3fc5 100644 --- a/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt +++ b/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt @@ -66,9 +66,7 @@ class CityConquestFunctions(val city: City){ for (building in city.cityConstructions.getBuiltBuildings()) { // Remove national wonders - if (building.isNationalWonder && !building.hasUnique(UniqueType.NotDestroyedWhenCityCaptured) - && building.name != city.capitalCityIndicator() - ) // If we have just made this city the capital, don't remove that + if (building.isNationalWonder && !building.hasUnique(UniqueType.NotDestroyedWhenCityCaptured)) city.cityConstructions.removeBuilding(building.name) // Check if we exceed MaxNumberBuildable for any buildings @@ -260,7 +258,7 @@ class CityConquestFunctions(val city: City){ // Remove/relocate palace for old Civ - need to do this BEFORE we move the cities between // civs so the capitalCityIndicator recognizes the unique buildings of the conquered civ - if (city.isCapital()) oldCiv.moveCapitalToNextLargest() + if (city.isCapital()) oldCiv.moveCapitalToNextLargest(city) oldCiv.cities = oldCiv.cities.toMutableList().apply { remove(city) } newCiv.cities = newCiv.cities.toMutableList().apply { add(city) } @@ -278,14 +276,12 @@ class CityConquestFunctions(val city: City){ // Stop WLTKD if it's still going city.resetWLTKD() - // Place palace for newCiv if this is the only city they have. - // This needs to happen _before_ buildings are added or removed, - // as any building change triggers a reevaluation of stats which assumes there to be a capital - if (newCiv.cities.size == 1) newCiv.moveCapitalTo(city) - // Remove their free buildings from this city and remove free buildings provided by the city from their cities removeBuildingsOnMoveToCiv(oldCiv) + // Place palace for newCiv if this is the only city they have. + if (newCiv.cities.size == 1) newCiv.moveCapitalTo(city, null) + // Add our free buildings to this city and add free buildings provided by the city to other cities city.civ.civConstructions.tryAddFreeBuildings() diff --git a/core/src/com/unciv/logic/civilization/Civilization.kt b/core/src/com/unciv/logic/civilization/Civilization.kt index c7ca7bde1c..4720fe1f93 100644 --- a/core/src/com/unciv/logic/civilization/Civilization.kt +++ b/core/src/com/unciv/logic/civilization/Civilization.kt @@ -813,25 +813,20 @@ class Civilization : IsPartOfGameInfoSerialization { /** * Removes current capital then moves capital to argument city if not null */ - fun moveCapitalTo(city: City?) { - - val oldCapital = getCapital() - + fun moveCapitalTo(city: City?, oldCapital: City?) { // Add new capital first so the civ doesn't get stuck in a state where it has cities but no capital if (city != null) { // move new capital city.cityConstructions.addBuilding(city.capitalCityIndicator()) city.isBeingRazed = false // stop razing the new capital if it was being razed } - // Don't use removeBuilding, since that rebuilds uniques and can generate errors when we have no capital - // We're going to recalc the uniques anyway once we move it to the new civ - oldCapital?.cityConstructions?.builtBuildings?.remove(oldCapital.capitalCityIndicator()) + oldCapital?.cityConstructions?.removeBuilding(oldCapital.capitalCityIndicator()) } - fun moveCapitalToNextLargest() { + fun moveCapitalToNextLargest(oldCapital: City?) { val availableCities = cities.filterNot { it.isCapital() } if (availableCities.none()) { - moveCapitalTo(null) + moveCapitalTo(null, oldCapital) return } @@ -841,7 +836,7 @@ class Civilization : IsPartOfGameInfoSerialization { newCapital = availableCities.maxByOrNull { it.population.population }!! newCapital.annexCity() } - moveCapitalTo(newCapital) + moveCapitalTo(newCapital, oldCapital) } fun getAllyCiv() = allyCivName diff --git a/tests/src/com/unciv/logic/civilization/CityMovingTests.kt b/tests/src/com/unciv/logic/civilization/CityMovingTests.kt index 2018459535..9c9475d21b 100644 --- a/tests/src/com/unciv/logic/civilization/CityMovingTests.kt +++ b/tests/src/com/unciv/logic/civilization/CityMovingTests.kt @@ -54,7 +54,7 @@ class CityMovingTests { theirCapital.moveToCiv(civInfo) Assert.assertTrue(theirOtherCity.isCapital()) - Assert.assertTrue(theirCapital.isCapital()) + Assert.assertTrue(!theirCapital.isCapital()) Assert.assertTrue(theirCapital.civ == civInfo) }