Resolved #8991 #8985 - Solved capital conquest crash

This commit is contained in:
Yair Morgenstern
2023-03-22 10:40:37 +02:00
parent d24d8b3d84
commit 79fd3a8f7a
2 changed files with 11 additions and 9 deletions

View File

@ -275,7 +275,7 @@ class CityInfoConquestFunctions(val city: City){
// civs so the capitalCityIndicator recognizes the unique buildings of the conquered civ // civs so the capitalCityIndicator recognizes the unique buildings of the conquered civ
if (oldCiv.getCapital() == this) oldCiv.moveCapitalToNextLargest() if (oldCiv.getCapital() == this) oldCiv.moveCapitalToNextLargest()
civ.cities = civ.cities.toMutableList().apply { remove(city) } oldCiv.cities = oldCiv.cities.toMutableList().apply { remove(city) }
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(city) } newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(city) }
civ = newCivInfo civ = newCivInfo
hasJustBeenConquered = false hasJustBeenConquered = false

View File

@ -772,15 +772,17 @@ class Civilization : IsPartOfGameInfoSerialization {
* Removes current capital then moves capital to argument city if not null * Removes current capital then moves capital to argument city if not null
*/ */
fun moveCapitalTo(city: City?) { fun moveCapitalTo(city: City?) {
if (cities.isNotEmpty() && getCapital() != null) {
val oldCapital = getCapital()!!
oldCapital.cityConstructions.removeBuilding(oldCapital.capitalCityIndicator())
}
if (city == null) return // can't move a non-existent city but we can always remove our old capital val oldCapital = getCapital()
// move new capital
city.cityConstructions.addBuilding(city.capitalCityIndicator()) // Add new capital first so the civ doesn't get stuck in a state where it has cities but no capital
city.isBeingRazed = false // stop razing the new capital if it was being razed if (city != null) {
// move new capital
city.cityConstructions.addBuilding(city.capitalCityIndicator())
city.isBeingRazed = false // stop razing the new capital if it was being razed
}
if (oldCapital != null)
oldCapital.cityConstructions.removeBuilding(oldCapital.capitalCityIndicator())
} }
fun moveCapitalToNextLargest() { fun moveCapitalToNextLargest() {