mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 16:28:40 +07:00
Fix issues when transferring capitals (#9801)
* Revert previous patches * Fix the unit test, I guess
This commit is contained in:
@ -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")
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user