Resolved edge case crash when conquering the capital of a civ that has a unique capital city indicator

This commit is contained in:
yairm210 2021-11-24 18:33:51 +02:00
parent 5d160508d3
commit 15cbf8359f
2 changed files with 14 additions and 10 deletions

View File

@ -230,10 +230,21 @@ class CityInfoConquestFunctions(val city: CityInfo){
fun moveToCiv(newCivInfo: CivilizationInfo) {
city.apply {
val oldCiv = civInfo
// 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
val capitalCityIndicator = capitalCityIndicator()
if (cityConstructions.isBuilt(capitalCityIndicator)) {
cityConstructions.removeBuilding(capitalCityIndicator)
val firstOtherCity = oldCiv.cities.firstOrNull { it != this }
if (firstOtherCity != null)
firstOtherCity.cityConstructions.addBuilding(capitalCityIndicator) // relocate palace
}
civInfo.cities = civInfo.cities.toMutableList().apply { remove(city) }
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(city) }
civInfo = newCivInfo
if (isOriginalCapital) civInfo.hasEverOwnedOriginalCapital = true
hasJustBeenConquered = false
turnAcquired = civInfo.gameInfo.turns
previousOwner = oldCiv.civName
@ -244,14 +255,6 @@ class CityInfoConquestFunctions(val city: CityInfo){
population.autoAssignPopulation()
}
// Remove/relocate palace for old Civ
val capitalCityIndicator = capitalCityIndicator()
if (cityConstructions.isBuilt(capitalCityIndicator)) {
cityConstructions.removeBuilding(capitalCityIndicator)
if (oldCiv.cities.isNotEmpty()) {
oldCiv.cities.first().cityConstructions.addBuilding(capitalCityIndicator) // relocate palace
}
}
// Remove their free buildings from this city and remove free buildings provided by the city from their cities
removeBuildingsOnMoveToCiv(oldCiv)

View File

@ -166,6 +166,7 @@ class CivilizationInfo {
// To correctly determine "game over" condition as clarified in #4707
// Nullable type meant to be deprecated and converted to non-nullable,
// default false once we no longer want legacy save-game compatibility
// This parameter means they owned THEIR OWN capital btw, not other civs'.
var hasEverOwnedOriginalCapital: Boolean? = null
val passableImpassables = HashSet<String>() // For Carthage-like uniques
@ -676,7 +677,7 @@ class CivilizationInfo {
* */
fun setNationTransient() {
nation = gameInfo.ruleSet.nations[civName]
?: throw java.lang.Exception("Nation $civName is not found!")
?: throw UncivShowableException("Nation $civName is not found!")
}
fun setTransients() {