mirror of
https://github.com/yairm210/Unciv.git
synced 2025-08-03 00:29:18 +07:00
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:

committed by
GitHub

parent
e73b73ed87
commit
4e72906488
@ -504,16 +504,27 @@ object Battle {
|
||||
return
|
||||
}
|
||||
|
||||
if (attackerCiv.isPlayerCivilization()) {
|
||||
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.id))
|
||||
UncivGame.Current.settings.addCompletedTutorialTask("Conquer a city")
|
||||
} else {
|
||||
if (city.isOriginalCapital && city.foundingCiv == attackerCiv.civName) {
|
||||
// retaking old capital
|
||||
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.isBeingRazed = true
|
||||
}
|
||||
}
|
||||
|
||||
if (attackerCiv.isPlayerCivilization())
|
||||
UncivGame.Current.settings.addCompletedTutorialTask("Conquer a city")
|
||||
}
|
||||
|
||||
fun getMapCombatantOfTile(tile: TileInfo): ICombatant? {
|
||||
|
@ -631,12 +631,16 @@ class CityInfo {
|
||||
fun setFlag(flag: CityFlags, amount: Int) {
|
||||
flagsCountdown[flag.name] = amount
|
||||
}
|
||||
|
||||
fun removeFlag(flag: CityFlags) {
|
||||
flagsCountdown.remove(flag.name)
|
||||
}
|
||||
|
||||
fun resetWLTKD() {
|
||||
// Removes the flags for we love the king & resource demand
|
||||
// The resource demand flag will automatically be readded with 15 turns remaining, see startTurn()
|
||||
flagsCountdown.remove(CityFlags.WeLoveTheKing.name)
|
||||
flagsCountdown.remove(CityFlags.ResourceDemand.name)
|
||||
removeFlag(CityFlags.WeLoveTheKing)
|
||||
removeFlag(CityFlags.ResourceDemand)
|
||||
demandedResource = ""
|
||||
}
|
||||
|
||||
@ -712,7 +716,7 @@ class CityInfo {
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -12,7 +12,6 @@ import com.unciv.logic.trade.TradeOffer
|
||||
import com.unciv.logic.trade.TradeType
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.ui.utils.withoutItem
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
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.
|
||||
reassignPopulation()
|
||||
|
||||
setFlag(CityFlags.Resistance,
|
||||
if (reconqueredCityWhileStillInResistance || foundingCiv == receivingCiv.civName) 0
|
||||
else population.population // I checked, and even if you puppet there's resistance for conquering
|
||||
)
|
||||
if (!reconqueredCityWhileStillInResistance && foundingCiv != receivingCiv.civName) {
|
||||
// add resistance
|
||||
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
|
||||
}
|
||||
@ -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
|
||||
// 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
|
||||
firstOtherCity.isBeingRazed = false // Do not allow it to continue being razed if it was!
|
||||
}
|
||||
}
|
||||
if (oldCiv.getCapital() == this) oldCiv.moveCapitalToNextLargest()
|
||||
|
||||
civInfo.cities = civInfo.cities.toMutableList().apply { remove(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
|
||||
// only be placed in the capital, and then there needs to be a capital.
|
||||
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
|
||||
|
@ -1302,6 +1302,26 @@ class CivilizationInfo {
|
||||
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 ////////////////////////
|
||||
|
||||
fun receiveGoldGift(donorCiv: CivilizationInfo, giftAmount: Int) =
|
||||
|
Reference in New Issue
Block a user