mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
chore: Removed vestigal city.apply{} for CityInfoConquestFunctions, for clarity on what is actually for the city and what is not
No logic changes
This commit is contained in:
parent
42a9c3af57
commit
bef1843cd9
@ -35,58 +35,52 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun destroyBuildingsOnCapture() {
|
private fun destroyBuildingsOnCapture() {
|
||||||
city.apply {
|
|
||||||
// Possibly remove other buildings
|
// Possibly remove other buildings
|
||||||
for (building in cityConstructions.getBuiltBuildings()) {
|
for (building in city.cityConstructions.getBuiltBuildings()) {
|
||||||
when {
|
when {
|
||||||
building.hasUnique(UniqueType.NotDestroyedWhenCityCaptured) || building.isWonder -> continue
|
building.hasUnique(UniqueType.NotDestroyedWhenCityCaptured) || building.isWonder -> continue
|
||||||
building.hasUnique(UniqueType.IndicatesCapital) -> continue // Palace needs to stay a just a bit longer so moveToCiv isn't confused
|
building.hasUnique(UniqueType.IndicatesCapital) -> continue // Palace needs to stay a just a bit longer so moveToCiv isn't confused
|
||||||
building.hasUnique(UniqueType.DestroyedWhenCityCaptured) ->
|
building.hasUnique(UniqueType.DestroyedWhenCityCaptured) ->
|
||||||
cityConstructions.removeBuilding(building.name)
|
city.cityConstructions.removeBuilding(building.name)
|
||||||
else -> {
|
// Regular buildings have a 34% chance of removal
|
||||||
if (tileBasedRandom.nextInt(100) < 34) {
|
tileBasedRandom.nextInt(100) < 34 -> city.cityConstructions.removeBuilding(building.name)
|
||||||
cityConstructions.removeBuilding(building.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeBuildingsOnMoveToCiv(oldCiv: Civilization) {
|
private fun removeBuildingsOnMoveToCiv(oldCiv: Civilization) {
|
||||||
city.apply {
|
|
||||||
// Remove all buildings provided for free to this city
|
// Remove all buildings provided for free to this city
|
||||||
for (building in civ.civConstructions.getFreeBuildings(id)) {
|
for (building in city.civ.civConstructions.getFreeBuildings(city.id)) {
|
||||||
cityConstructions.removeBuilding(building)
|
city.cityConstructions.removeBuilding(building)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all buildings provided for free from here to other cities (e.g. CN Tower)
|
// Remove all buildings provided for free from here to other cities (e.g. CN Tower)
|
||||||
for ((cityId, buildings) in cityConstructions.freeBuildingsProvidedFromThisCity) {
|
for ((cityId, buildings) in city.cityConstructions.freeBuildingsProvidedFromThisCity) {
|
||||||
val city = oldCiv.cities.firstOrNull { it.id == cityId } ?: continue
|
val city = oldCiv.cities.firstOrNull { it.id == cityId } ?: continue
|
||||||
debug("Removing buildings %s from city %s", buildings, city.name)
|
debug("Removing buildings %s from city %s", buildings, city.name)
|
||||||
for (building in buildings) {
|
for (building in buildings) {
|
||||||
city.cityConstructions.removeBuilding(building)
|
city.cityConstructions.removeBuilding(building)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cityConstructions.freeBuildingsProvidedFromThisCity.clear()
|
city.cityConstructions.freeBuildingsProvidedFromThisCity.clear()
|
||||||
|
|
||||||
for (building in cityConstructions.getBuiltBuildings()) {
|
for (building in city.cityConstructions.getBuiltBuildings()) {
|
||||||
// Remove national wonders
|
// Remove national wonders
|
||||||
if (building.isNationalWonder && !building.hasUnique(UniqueType.NotDestroyedWhenCityCaptured)
|
if (building.isNationalWonder && !building.hasUnique(UniqueType.NotDestroyedWhenCityCaptured)
|
||||||
&& building.name != capitalCityIndicator()) // If we have just made this city the capital, don't remove that
|
&& building.name != city.capitalCityIndicator()
|
||||||
cityConstructions.removeBuilding(building.name)
|
) // If we have just made this city the capital, don't remove that
|
||||||
|
city.cityConstructions.removeBuilding(building.name)
|
||||||
|
|
||||||
// Check if we exceed MaxNumberBuildable for any buildings
|
// Check if we exceed MaxNumberBuildable for any buildings
|
||||||
for (unique in building.getMatchingUniques(UniqueType.MaxNumberBuildable)) {
|
for (unique in building.getMatchingUniques(UniqueType.MaxNumberBuildable)) {
|
||||||
if (civ.cities
|
if (city.civ.cities
|
||||||
.count {
|
.count {
|
||||||
it.cityConstructions.containsBuildingOrEquivalent(building.name)
|
it.cityConstructions.containsBuildingOrEquivalent(building.name)
|
||||||
|| it.cityConstructions.isBeingConstructedOrEnqueued(building.name)
|
|| it.cityConstructions.isBeingConstructedOrEnqueued(building.name)
|
||||||
} >= unique.params[0].toInt()
|
} >= unique.params[0].toInt()
|
||||||
) {
|
) {
|
||||||
// For now, just destroy in new city. Even if constructing in own cities
|
// For now, just destroy in new city. Even if constructing in own cities
|
||||||
city.cityConstructions.removeBuilding(building.name)
|
this.city.cityConstructions.removeBuilding(building.name)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,35 +92,33 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
*/
|
*/
|
||||||
private fun conquerCity(conqueringCiv: Civilization, conqueredCiv: Civilization, receivingCiv: Civilization) {
|
private fun conquerCity(conqueringCiv: Civilization, conqueredCiv: Civilization, receivingCiv: Civilization) {
|
||||||
val goldPlundered = getGoldForCapturingCity(conqueringCiv)
|
val goldPlundered = getGoldForCapturingCity(conqueringCiv)
|
||||||
city.apply {
|
|
||||||
conqueringCiv.addGold(goldPlundered)
|
conqueringCiv.addGold(goldPlundered)
|
||||||
conqueringCiv.addNotification("Received [$goldPlundered] Gold for capturing [$name]",
|
conqueringCiv.addNotification("Received [$goldPlundered] Gold for capturing [${city.name}]",
|
||||||
getCenterTile().position, NotificationCategory.General, NotificationIcon.Gold)
|
city.getCenterTile().position, NotificationCategory.General, NotificationIcon.Gold)
|
||||||
|
|
||||||
val reconqueredCityWhileStillInResistance = previousOwner == receivingCiv.civName && isInResistance()
|
val reconqueredCityWhileStillInResistance = city.previousOwner == receivingCiv.civName && city.isInResistance()
|
||||||
|
|
||||||
destroyBuildingsOnCapture()
|
destroyBuildingsOnCapture()
|
||||||
|
|
||||||
moveToCiv(receivingCiv)
|
city.moveToCiv(receivingCiv)
|
||||||
|
|
||||||
Battle.destroyIfDefeated(conqueredCiv, conqueringCiv)
|
Battle.destroyIfDefeated(conqueredCiv, conqueringCiv)
|
||||||
|
|
||||||
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
city.health = city.getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
||||||
if (population.population > 1)
|
if (city.population.population > 1)
|
||||||
population.addPopulation(-1 - population.population / 4) // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
|
city.population.addPopulation(-1 - city.population.population / 4) // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
|
||||||
reassignAllPopulation()
|
city.reassignAllPopulation()
|
||||||
|
|
||||||
if (!reconqueredCityWhileStillInResistance && foundingCiv != receivingCiv.civName) {
|
if (!reconqueredCityWhileStillInResistance && city.foundingCiv != receivingCiv.civName) {
|
||||||
// add resistance
|
// add resistance
|
||||||
// I checked, and even if you puppet there's resistance for conquering
|
// I checked, and even if you puppet there's resistance for conquering
|
||||||
setFlag(CityFlags.Resistance, population.population)
|
city.setFlag(CityFlags.Resistance, city.population.population)
|
||||||
} else {
|
} else {
|
||||||
// reconquering or liberating city in resistance so eliminate it
|
// reconquering or liberating city in resistance so eliminate it
|
||||||
removeFlag(CityFlags.Resistance)
|
city.removeFlag(CityFlags.Resistance)
|
||||||
}
|
}
|
||||||
|
|
||||||
espionage.removeAllPresentSpies(SpyFleeReason.CityCaptured)
|
city.espionage.removeAllPresentSpies(SpyFleeReason.CityCaptured)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -135,9 +127,7 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
// Gain gold for plundering city
|
// Gain gold for plundering city
|
||||||
@Suppress("UNUSED_VARIABLE") // todo: use this val
|
@Suppress("UNUSED_VARIABLE") // todo: use this val
|
||||||
val goldPlundered = getGoldForCapturingCity(conqueringCiv)
|
val goldPlundered = getGoldForCapturingCity(conqueringCiv)
|
||||||
city.apply {
|
val oldCiv = city.civ
|
||||||
|
|
||||||
val oldCiv = civ
|
|
||||||
|
|
||||||
// must be before moving the city to the conquering civ,
|
// must be before moving the city to the conquering civ,
|
||||||
// so the repercussions are properly checked
|
// so the repercussions are properly checked
|
||||||
@ -145,13 +135,12 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
|
|
||||||
conquerCity(conqueringCiv, oldCiv, conqueringCiv)
|
conquerCity(conqueringCiv, oldCiv, conqueringCiv)
|
||||||
|
|
||||||
isPuppet = true
|
city.isPuppet = true
|
||||||
cityStats.update()
|
city.cityStats.update()
|
||||||
// The city could be producing something that puppets shouldn't, like units
|
// The city could be producing something that puppets shouldn't, like units
|
||||||
cityConstructions.currentConstructionIsUserSet = false
|
city.cityConstructions.currentConstructionIsUserSet = false
|
||||||
cityConstructions.constructionQueue.clear()
|
city.cityConstructions.constructionQueue.clear()
|
||||||
cityConstructions.chooseNextConstruction()
|
city.cityConstructions.chooseNextConstruction()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun annexCity() {
|
fun annexCity() {
|
||||||
@ -187,20 +176,19 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun liberateCity(conqueringCiv: Civilization) {
|
fun liberateCity(conqueringCiv: Civilization) {
|
||||||
city.apply {
|
if (city.foundingCiv == "") { // this should never happen but just in case...
|
||||||
if (foundingCiv == "") { // this should never happen but just in case...
|
this.puppetCity(conqueringCiv)
|
||||||
this@CityInfoConquestFunctions.puppetCity(conqueringCiv)
|
this.annexCity()
|
||||||
this@CityInfoConquestFunctions.annexCity()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val foundingCiv = civ.gameInfo.getCivilization(foundingCiv)
|
val foundingCiv = city.civ.gameInfo.getCivilization(city.foundingCiv)
|
||||||
if (foundingCiv.isDefeated()) // resurrected civ
|
if (foundingCiv.isDefeated()) // resurrected civ
|
||||||
for (diploManager in foundingCiv.diplomacy.values)
|
for (diploManager in foundingCiv.diplomacy.values)
|
||||||
if (diploManager.diplomaticStatus == DiplomaticStatus.War)
|
if (diploManager.diplomaticStatus == DiplomaticStatus.War)
|
||||||
diploManager.makePeace()
|
diploManager.makePeace()
|
||||||
|
|
||||||
val oldCiv = civ
|
val oldCiv = city.civ
|
||||||
|
|
||||||
diplomaticRepercussionsForLiberatingCity(conqueringCiv, oldCiv)
|
diplomaticRepercussionsForLiberatingCity(conqueringCiv, oldCiv)
|
||||||
|
|
||||||
@ -208,8 +196,8 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
|
|
||||||
if (foundingCiv.cities.size == 1) {
|
if (foundingCiv.cities.size == 1) {
|
||||||
// Resurrection!
|
// Resurrection!
|
||||||
cityConstructions.addBuilding(capitalCityIndicator())
|
city.cityConstructions.addBuilding(city.capitalCityIndicator())
|
||||||
for (civ in civ.gameInfo.civilizations) {
|
for (civ in city.civ.gameInfo.civilizations) {
|
||||||
if (civ == foundingCiv || civ == conqueringCiv) continue // don't need to notify these civs
|
if (civ == foundingCiv || civ == conqueringCiv) continue // don't need to notify these civs
|
||||||
when {
|
when {
|
||||||
civ.knows(conqueringCiv) && civ.knows(foundingCiv) ->
|
civ.knows(conqueringCiv) && civ.knows(foundingCiv) ->
|
||||||
@ -222,16 +210,16 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isPuppet = false
|
city.isPuppet = false
|
||||||
cityStats.update()
|
city.cityStats.update()
|
||||||
|
|
||||||
// Move units out of the city when liberated
|
// Move units out of the city when liberated
|
||||||
for (unit in getCenterTile().getUnits().toList())
|
for (unit in city.getCenterTile().getUnits().toList())
|
||||||
unit.movement.teleportToClosestMoveableTile()
|
unit.movement.teleportToClosestMoveableTile()
|
||||||
for (unit in getTiles().flatMap { it.getUnits() }.toList())
|
for (unit in city.getTiles().flatMap { it.getUnits() }.toList())
|
||||||
if (!unit.movement.canPassThrough(unit.currentTile))
|
if (!unit.movement.canPassThrough(unit.currentTile))
|
||||||
unit.movement.teleportToClosestMoveableTile()
|
unit.movement.teleportToClosestMoveableTile()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -269,69 +257,69 @@ class CityInfoConquestFunctions(val city: City){
|
|||||||
|
|
||||||
fun moveToCiv(newCiv: Civilization) {
|
fun moveToCiv(newCiv: Civilization) {
|
||||||
val oldCiv = city.civ
|
val oldCiv = city.civ
|
||||||
city.apply {
|
|
||||||
// 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
|
||||||
if (oldCiv.getCapital() == this) oldCiv.moveCapitalToNextLargest()
|
if (city.isCapital()) oldCiv.moveCapitalToNextLargest()
|
||||||
|
|
||||||
oldCiv.cities = oldCiv.cities.toMutableList().apply { remove(city) }
|
oldCiv.cities = oldCiv.cities.toMutableList().apply { remove(city) }
|
||||||
newCiv.cities = newCiv.cities.toMutableList().apply { add(city) }
|
newCiv.cities = newCiv.cities.toMutableList().apply { add(city) }
|
||||||
civ = newCiv
|
city.civ = newCiv
|
||||||
hasJustBeenConquered = false
|
city.hasJustBeenConquered = false
|
||||||
turnAcquired = civ.gameInfo.turns
|
city.turnAcquired = city.civ.gameInfo.turns
|
||||||
previousOwner = oldCiv.civName
|
city.previousOwner = oldCiv.civName
|
||||||
|
|
||||||
// now that the tiles have changed, we need to reassign population
|
// now that the tiles have changed, we need to reassign population
|
||||||
for (workedTile in workedTiles.filterNot { tiles.contains(it) }) {
|
for (workedTile in city.workedTiles.filterNot { city.tiles.contains(it) }) {
|
||||||
population.stopWorkingTile(workedTile)
|
city.population.stopWorkingTile(workedTile)
|
||||||
population.autoAssignPopulation()
|
city.population.autoAssignPopulation()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop WLTKD if it's still going
|
// Stop WLTKD if it's still going
|
||||||
resetWLTKD()
|
city.resetWLTKD()
|
||||||
|
|
||||||
// Place palace for newCiv if this is the only city they have.
|
// Place palace for newCiv if this is the only city they have.
|
||||||
// This needs to happen _before_ buildings are added or removed,
|
// This needs to happen _before_ buildings are added or removed,
|
||||||
// as any building change triggers a reevaluation of stats which assumes there to be a capital
|
// as any building change triggers a reevaluation of stats which assumes there to be a capital
|
||||||
if (newCiv.cities.size == 1) newCiv.moveCapitalTo(this)
|
if (newCiv.cities.size == 1) newCiv.moveCapitalTo(city)
|
||||||
|
|
||||||
// Remove their free buildings from this city and remove free buildings provided by the city from their cities
|
// Remove their free buildings from this city and remove free buildings provided by the city from their cities
|
||||||
removeBuildingsOnMoveToCiv(oldCiv)
|
removeBuildingsOnMoveToCiv(oldCiv)
|
||||||
|
|
||||||
// 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
|
||||||
civ.civConstructions.tryAddFreeBuildings()
|
city.civ.civConstructions.tryAddFreeBuildings()
|
||||||
|
|
||||||
isBeingRazed = false
|
city.isBeingRazed = false
|
||||||
|
|
||||||
// Transfer unique buildings
|
// Transfer unique buildings
|
||||||
for (building in cityConstructions.getBuiltBuildings()) {
|
for (building in city.cityConstructions.getBuiltBuildings()) {
|
||||||
val civEquivalentBuilding = newCiv.getEquivalentBuilding(building.name)
|
val civEquivalentBuilding = newCiv.getEquivalentBuilding(building.name)
|
||||||
if (building != civEquivalentBuilding) {
|
if (building != civEquivalentBuilding) {
|
||||||
cityConstructions.removeBuilding(building.name)
|
city.cityConstructions.removeBuilding(building.name)
|
||||||
cityConstructions.addBuilding(civEquivalentBuilding.name)
|
city.cityConstructions.addBuilding(civEquivalentBuilding.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (civ.gameInfo.isReligionEnabled()) religion.removeUnknownPantheons()
|
if (city.civ.gameInfo.isReligionEnabled()) city.religion.removeUnknownPantheons()
|
||||||
|
|
||||||
if (newCiv.hasUnique(UniqueType.MayNotAnnexCities)) {
|
if (newCiv.hasUnique(UniqueType.MayNotAnnexCities)) {
|
||||||
isPuppet = true
|
city.isPuppet = true
|
||||||
cityConstructions.currentConstructionIsUserSet = false
|
city.cityConstructions.currentConstructionIsUserSet = false
|
||||||
cityConstructions.constructionQueue.clear()
|
city.cityConstructions.constructionQueue.clear()
|
||||||
cityConstructions.chooseNextConstruction()
|
city.cityConstructions.chooseNextConstruction()
|
||||||
}
|
}
|
||||||
|
|
||||||
tryUpdateRoadStatus()
|
city.tryUpdateRoadStatus()
|
||||||
cityStats.update()
|
city.cityStats.update()
|
||||||
|
|
||||||
// Update proximity rankings
|
// Update proximity rankings
|
||||||
civ.updateProximity(oldCiv, oldCiv.updateProximity(civ))
|
city.civ.updateProximity(oldCiv, oldCiv.updateProximity(city.civ))
|
||||||
|
|
||||||
// Update history
|
// Update history
|
||||||
city.getTiles().forEach { tile ->
|
city.getTiles().forEach { tile ->
|
||||||
tile.history.recordTakeOwnership(tile)
|
tile.history.recordTakeOwnership(tile)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
newCiv.cache.updateOurTiles()
|
newCiv.cache.updateOurTiles()
|
||||||
oldCiv.cache.updateOurTiles()
|
oldCiv.cache.updateOurTiles()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user