From 2594777b52f7648a4a89896c0e69dd910923d2eb Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Thu, 16 Apr 2020 10:33:58 +0300 Subject: [PATCH] The original capital can not be razed (#2412) * Civ is not defeated while at least 1 settler is alive * The original capital cannot be razed * Revert "Civ is not defeated while at least 1 settler is alive" Defeat condition is: no cities remained --- core/src/com/unciv/logic/city/CityInfo.kt | 8 +++++++- core/src/com/unciv/logic/civilization/CivilizationInfo.kt | 4 ++-- core/src/com/unciv/ui/cityscreen/CityScreen.kt | 4 +++- core/src/com/unciv/ui/worldscreen/AlertPopup.kt | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 88436be8d6..8a3c144e4a 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -56,6 +56,10 @@ class CityInfo { var attackedThisTurn = false var hasSoldBuildingThisTurn = false var isPuppet = false + /** The very first found city is the _original_ capital, + * while the _current_ capital can be any other city after the original one is captured. + * It is important to distinct them since the original cannot be razed and defines the Domination Victory. */ + var isOriginalCapital = false constructor() // for json parsing, we need to have a default constructor constructor(civInfo: CivilizationInfo, cityLocation: Vector2) { // new city! @@ -76,6 +80,7 @@ class CityInfo { name = cityNamePrefix + cityName + isOriginalCapital = civInfo.citiesCreated == 0 civInfo.citiesCreated++ civInfo.cities = civInfo.cities.toMutableList().apply { add(this@CityInfo) } @@ -125,6 +130,7 @@ class CityInfo { toReturn.foundingCiv = foundingCiv toReturn.turnAcquired = turnAcquired toReturn.isPuppet = isPuppet + toReturn.isOriginalCapital = isOriginalCapital return toReturn } @@ -139,7 +145,7 @@ class CityInfo { val mediumTypes = civInfo.citiesConnectedToCapitalToMediums[this] ?: return false return connectionTypePredicate(mediumTypes) } - fun isInResistance() = resistanceCounter>0 + fun isInResistance() = resistanceCounter > 0 fun getRuleset() = civInfo.gameInfo.ruleSet diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 49d9fb7959..e169a92bf2 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -262,8 +262,8 @@ class CivilizationInfo { override fun toString(): String {return civName} // for debug - /** Returns true if the civ was fully initialized and has no cities or settlers remaining */ - fun isDefeated()= cities.isEmpty() + /** Returns true if the civ was fully initialized and has no cities remaining */ + fun isDefeated()= cities.isEmpty() // No cities && exploredTiles.isNotEmpty() // Dirty hack: exploredTiles are empty only before starting units are placed && !isBarbarian() // Barbarians can be never defeated && (citiesCreated > 0 || !getCivUnits().any { it.name == Constants.settler }) diff --git a/core/src/com/unciv/ui/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/cityscreen/CityScreen.kt index b3a97f2337..063d94748b 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreen.kt @@ -125,7 +125,9 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() { val razeCityButton = "Raze city".toTextButton() razeCityButton.labelCell.pad(10f) razeCityButton.onClick { city.isBeingRazed=true; update() } - if(!UncivGame.Current.worldScreen.isPlayersTurn) razeCityButton.disable() + if(!UncivGame.Current.worldScreen.isPlayersTurn || city.isOriginalCapital) + razeCityButton.disable() + razeCityButtonHolder.add(razeCityButton).colspan(cityPickerTable.columns) } else { val stopRazingCityButton = "Stop razing city".toTextButton() diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index 5021d5c3cf..565c1d4aaa 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -99,13 +99,15 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu addSeparator() - add("Raze".toTextButton().onClick { + add("Raze".toTextButton().apply { + if (city.isOriginalCapital) disable() + else onClick { city.puppetCity(conqueringCiv) city.annexCity() city.isBeingRazed = true worldScreen.shouldUpdate=true close() - }).row() + }}).row() addGoodSizedLabel("Razing the city annexes it, and starts razing the city to the ground.").row() addGoodSizedLabel("The population will gradually dwindle until the city is destroyed.").row() } else {