Capital movement tweaks (#6800)

* Capital movement changes

* Cleanup

* Fix liberation condition

* Cleanup

* Fix wrong condition

* Fixed oversights

* One more

Co-authored-by: OptimizedForDensity <>
This commit is contained in:
OptimizedForDensity 2022-05-14 16:39:49 -04:00 committed by GitHub
parent e73b73ed87
commit 4e72906488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 23 deletions

View File

@ -504,16 +504,27 @@ object Battle {
return return
} }
if (attackerCiv.isPlayerCivilization()) { if (city.isOriginalCapital && city.foundingCiv == attackerCiv.civName) {
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.id)) // retaking old capital
UncivGame.Current.settings.addCompletedTutorialTask("Conquer a city")
} else {
city.puppetCity(attackerCiv) city.puppetCity(attackerCiv)
if (city.population.population < 4 && city.canBeDestroyed(justCaptured = true)) { city.annexCity()
} else if (attackerCiv.isPlayerCivilization()) {
// we're not taking our former capital
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.id))
} else {
// ideally here we would do some AI thinking for liberation vs. razing
// e.g., valueCityStateAlliance() > 0 to determine if we should liberate a city-state
city.puppetCity(attackerCiv)
if ((city.population.population < 4 || attackerCiv.isCityState())
&& city.canBeDestroyed(justCaptured = true)) {
// raze if attacker is a city state
city.annexCity() city.annexCity()
city.isBeingRazed = true city.isBeingRazed = true
} }
} }
if (attackerCiv.isPlayerCivilization())
UncivGame.Current.settings.addCompletedTutorialTask("Conquer a city")
} }
fun getMapCombatantOfTile(tile: TileInfo): ICombatant? { fun getMapCombatantOfTile(tile: TileInfo): ICombatant? {

View File

@ -632,11 +632,15 @@ class CityInfo {
flagsCountdown[flag.name] = amount flagsCountdown[flag.name] = amount
} }
fun removeFlag(flag: CityFlags) {
flagsCountdown.remove(flag.name)
}
fun resetWLTKD() { fun resetWLTKD() {
// Removes the flags for we love the king & resource demand // Removes the flags for we love the king & resource demand
// The resource demand flag will automatically be readded with 15 turns remaining, see startTurn() // The resource demand flag will automatically be readded with 15 turns remaining, see startTurn()
flagsCountdown.remove(CityFlags.WeLoveTheKing.name) removeFlag(CityFlags.WeLoveTheKing)
flagsCountdown.remove(CityFlags.ResourceDemand.name) removeFlag(CityFlags.ResourceDemand)
demandedResource = "" demandedResource = ""
} }
@ -712,7 +716,7 @@ class CityInfo {
} }
if (isCapital() && civInfo.cities.isNotEmpty()) { // Move the capital if destroyed (by a nuke or by razing) if (isCapital() && civInfo.cities.isNotEmpty()) { // Move the capital if destroyed (by a nuke or by razing)
civInfo.cities.first().cityConstructions.addBuilding(capitalCityIndicator()) civInfo.moveCapitalToNextLargest()
} }
// Update proximity rankings for all civs // Update proximity rankings for all civs

View File

@ -12,7 +12,6 @@ import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeType import com.unciv.logic.trade.TradeType
import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.ui.utils.withoutItem import com.unciv.ui.utils.withoutItem
import java.util.*
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -111,10 +110,17 @@ class CityInfoConquestFunctions(val city: CityInfo){
if (population.population > 1) population.addPopulation(-1 - population.population / 4) // so from 2-4 population, remove 1, from 5-8, remove 2, etc. if (population.population > 1) population.addPopulation(-1 - population.population / 4) // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
reassignPopulation() reassignPopulation()
setFlag(CityFlags.Resistance, if (!reconqueredCityWhileStillInResistance && foundingCiv != receivingCiv.civName) {
if (reconqueredCityWhileStillInResistance || foundingCiv == receivingCiv.civName) 0 // add resistance
else population.population // I checked, and even if you puppet there's resistance for conquering setFlag(
) CityFlags.Resistance,
population.population // I checked, and even if you puppet there's resistance for conquering
)
} else {
// reconquering or liberating city in resistance so eliminate it
removeFlag(CityFlags.Resistance)
}
} }
conqueringCiv.updateViewableTiles() // Might see new tiles from this city conqueringCiv.updateViewableTiles() // Might see new tiles from this city
} }
@ -249,15 +255,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
// Remove/relocate palace for old Civ - need to do this BEFORE we move the cities between // 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 // civs so the capitalCityIndicator recognizes the unique buildings of the conquered civ
val capitalCityIndicator = capitalCityIndicator() if (oldCiv.getCapital() == this) oldCiv.moveCapitalToNextLargest()
if (cityConstructions.isBuilt(capitalCityIndicator)) {
cityConstructions.removeBuilding(capitalCityIndicator)
val firstOtherCity = oldCiv.cities.firstOrNull { it != this }
if (firstOtherCity != null) {
firstOtherCity.cityConstructions.addBuilding(capitalCityIndicator) // relocate palace
firstOtherCity.isBeingRazed = false // Do not allow it to continue being razed if it was!
}
}
civInfo.cities = civInfo.cities.toMutableList().apply { remove(city) } civInfo.cities = civInfo.cities.toMutableList().apply { remove(city) }
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(city) } newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(city) }
@ -282,7 +280,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
// This needs to happen _before_ free buildings are added, as somtimes these should // This needs to happen _before_ free buildings are added, as somtimes these should
// only be placed in the capital, and then there needs to be a capital. // only be placed in the capital, and then there needs to be a capital.
if (newCivInfo.cities.count() == 1) { if (newCivInfo.cities.count() == 1) {
cityConstructions.addBuilding(capitalCityIndicator) newCivInfo.moveCapitalTo(this)
} }
// Add our free buildings to this city and add free buildings provided by the city to other cities // Add our free buildings to this city and add free buildings provided by the city to other cities

View File

@ -1302,6 +1302,26 @@ class CivilizationInfo {
return proximity return proximity
} }
/**
* Removes current capital then moves capital to argument city if not null
*/
fun moveCapitalTo(city: CityInfo?) {
if (cities.isNotEmpty()) {
getCapital().cityConstructions.removeBuilding(getCapital().capitalCityIndicator())
}
if (city == null) return // can't move a non-existent city but we can always remove our old capital
// move new capital
city.cityConstructions.addBuilding(city.capitalCityIndicator())
city.isBeingRazed = false // stop razing the new capital if it was being razed
}
fun moveCapitalToNextLargest() {
moveCapitalTo(cities
.filterNot { it == getCapital() }
.maxByOrNull { it.population.population})
}
//////////////////////// City State wrapper functions //////////////////////// //////////////////////// City State wrapper functions ////////////////////////
fun receiveGoldGift(donorCiv: CivilizationInfo, giftAmount: Int) = fun receiveGoldGift(donorCiv: CivilizationInfo, giftAmount: Int) =