Duantao/liberate city (#1097)

* Allow to liberate city to its founder.

* Workaround : Avoid exception on conquering city with infantry unit.

* Liberate button actually works.

* Fix trade resources check.

* Postpone the 2nd part of postBattleActions until choice is made.

* Add puppet option.

* Puppet city cannot be controlled directly.

* Add annex and puppet happiness/culture/science bonus.

* Add courthouse. Icon is missing.

* Icon for courthouse.

* Update png.
This commit is contained in:
Duan Tao 2019-09-23 13:37:53 +08:00 committed by Yair Morgenstern
parent a3889a549e
commit 65b8fe531e
16 changed files with 735 additions and 564 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1,007 KiB

After

Width:  |  Height:  |  Size: 1,011 KiB

View file

@ -178,6 +178,14 @@
requiredTech:"Mathematics",
quote:"'I think that if ever a mortal heard the word of God it would be in a garden at the cool of the day.' - F. Frankfort Moore"
},
{
name:"Courthouse",
maintenance:4,
hurryCostModifier:25,
uniques:["Remove extra unhappiness from annexed cities",
"Can only be built in annexed cities"],
requiredTech:"Mathematics"
},
{
name:"Colosseum",
maintenance:1,

View file

@ -185,7 +185,9 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
}
private fun addHappinessBuildingChoice() {
val happinessBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Happiness) }
val happinessBuilding = buildableNotWonders
.filter { it.isStatRelated(Stat.Happiness)
|| it.uniques.contains("Remove extra unhappiness from annexed cities") }
.minBy { it.cost }
if (happinessBuilding != null) {
var modifier = 1f

View file

@ -429,10 +429,7 @@ class NextTurnAutomation{
private fun reassignWorkedTiles(civInfo: CivilizationInfo) {
for (city in civInfo.cities) {
city.workedTiles = hashSetOf()
city.population.specialists.clear()
for (i in 0..city.population.population)
city.population.autoAssignPopulation()
city.reassignWorkers()
city.cityConstructions.chooseNextConstruction()
if (city.health < city.getMaxHealth())

View file

@ -100,8 +100,11 @@ class Battle(val gameInfo:GameInfo) {
&& defender is CityCombatant
&& attacker.isMelee()){
conquerCity(defender.city, attacker)
} else
postBattleActionsPart2(attacker, defender, attackedTile)
}
fun postBattleActionsPart2(attacker: ICombatant, defender: ICombatant, attackedTile:TileInfo) {
// German unique - needs to be checked before we try to move to the enemy tile, since the encampment disappears after we move in
if(defender.isDefeated() && defender.getCivInfo().isBarbarian()
@ -204,69 +207,16 @@ class Battle(val gameInfo:GameInfo) {
}
private fun conquerCity(city: CityInfo, attacker: ICombatant) {
val cityCiv = city.civInfo
val attackerCiv = attacker.getCivInfo()
attackerCiv.addNotification("We have conquered the city of [${city.name}]!", city.location, Color.RED)
city.conquerer = attacker
if (attacker.getCivInfo().isPlayerCivilization()) {
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.name))
city.getCenterTile().apply {
if(militaryUnit!=null) militaryUnit!!.destroy()
if(civilianUnit!=null) captureCivilianUnit(attacker,MapUnitCombatant(civilianUnit!!))
for(airUnit in airUnits.toList()) airUnit.destroy()
} else {
city.AnnexCity()
}
if (!attackerCiv.isMajorCiv()){
city.destroyCity()
}
else {
val currentPopulation = city.population.population
val percentageOfCivPopulationInThatCity = currentPopulation*100f / cityCiv.cities.sumBy { it.population.population }
val aggroGenerated = 10f+percentageOfCivPopulationInThatCity.roundToInt()
cityCiv.getDiplomacyManager(attacker.getCivInfo())
.addModifier(DiplomaticModifiers.CapturedOurCities, -aggroGenerated)
for(thirdPartyCiv in attackerCiv.getKnownCivs().filter { it.isMajorCiv() }){
val aggroGeneratedForOtherCivs = (aggroGenerated/10).roundToInt().toFloat()
if(thirdPartyCiv.isAtWarWith(cityCiv)) // You annoyed our enemy?
thirdPartyCiv.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.SharedEnemy, aggroGeneratedForOtherCivs) // Cool, keep at at! =D
else thirdPartyCiv.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.WarMongerer, -aggroGeneratedForOtherCivs) // Uncool bro.
}
if(currentPopulation>1) city.population.population -= 1 + currentPopulation/4 // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
city.population.unassignExtraPopulation()
city.health = city.getMaxHealth() / 2 // I think that cities recover to half health when conquered?
if(!attacker.getCivInfo().policies.isAdopted("Police State")) {
city.expansion.cultureStored = 0
city.expansion.reset()
}
city.moveToCiv(attacker.getCivInfo())
city.resistanceCounter = city.population.population
city.workedTiles = hashSetOf() //reassign 1st working tile
city.population.specialists.clear()
for (i in 0..city.population.population)
city.population.autoAssignPopulation()
city.cityStats.update()
}
if(city.cityConstructions.isBuilt("Palace")){
city.cityConstructions.removeBuilding("Palace")
if(cityCiv.isDefeated()) {
cityCiv.destroy()
attacker.getCivInfo().popupAlerts.add(PopupAlert(AlertType.Defeated,cityCiv.civName))
}
else if(cityCiv.cities.isNotEmpty()){
cityCiv.cities.first().cityConstructions.addBuilding("Palace") // relocate palace
}
}
(attacker as MapUnitCombatant).unit.movement.moveToTile(city.getCenterTile())
}
fun getMapCombatantOfTile(tile:TileInfo): ICombatant? {

View file

@ -3,8 +3,13 @@ package com.unciv.logic.city
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2
import com.unciv.Constants
import com.unciv.UnCivGame
import com.unciv.logic.battle.*
import com.unciv.logic.civilization.AlertType
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.PopupAlert
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
import com.unciv.logic.map.RoadStatus
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap
@ -13,7 +18,9 @@ import com.unciv.models.gamebasics.tile.ResourceSupplyList
import com.unciv.models.gamebasics.tile.ResourceType
import com.unciv.models.stats.Stats
import com.unciv.ui.utils.withoutItem
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
class CityInfo {
@Transient lateinit var civInfo: CivilizationInfo
@ -38,6 +45,8 @@ class CityInfo {
var isBeingRazed = false
var attackedThisTurn = false
var hasSoldBuildingThisTurn = false
var conquerer : ICombatant? = null
var isPuppet = false
constructor() // for json parsing, we need to have a default constructor
constructor(civInfo: CivilizationInfo, cityLocation: Vector2) { // new city!
@ -99,6 +108,9 @@ class CityInfo {
toReturn.isBeingRazed=isBeingRazed
toReturn.attackedThisTurn = attackedThisTurn
toReturn.resistanceCounter = resistanceCounter
toReturn.foundingCiv = foundingCiv
toReturn.conquerer = conquerer
toReturn.isPuppet = isPuppet
return toReturn
}
@ -210,6 +222,17 @@ class CityInfo {
tryUpdateRoadStatus()
attackedThisTurn = false
if (resistanceCounter > 0) resistanceCounter--
if (isPuppet) {
reassignWorkers()
}
}
fun reassignWorkers() {
workedTiles = hashSetOf()
population.specialists.clear()
for (i in 0..population.population)
population.autoAssignPopulation()
}
fun endTurn() {
@ -254,6 +277,136 @@ class CityInfo {
getCenterTile().improvement="City ruins"
}
fun AnnexCity() {
if (conquerer == null) return
val attackerCiv = conquerer!!.getCivInfo()
val defenderCiv = civInfo
getCenterTile().apply {
if(militaryUnit!=null) militaryUnit!!.destroy()
if(civilianUnit!=null) Battle(civInfo.gameInfo).captureCivilianUnit(conquerer!!, MapUnitCombatant(civilianUnit!!))
for(airUnit in airUnits.toList()) airUnit.destroy()
}
if (!attackerCiv.isMajorCiv()){
destroyCity()
}
else {
val currentPopulation = population.population
val percentageOfCivPopulationInThatCity = currentPopulation*100f / civInfo.cities.sumBy { it.population.population }
val aggroGenerated = 10f+percentageOfCivPopulationInThatCity.roundToInt()
civInfo.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.CapturedOurCities, -aggroGenerated)
for(thirdPartyCiv in attackerCiv.getKnownCivs().filter { it.isMajorCiv() }){
val aggroGeneratedForOtherCivs = (aggroGenerated/10).roundToInt().toFloat()
if(thirdPartyCiv.isAtWarWith(civInfo)) // You annoyed our enemy?
thirdPartyCiv.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.SharedEnemy, aggroGeneratedForOtherCivs) // Cool, keep at at! =D
else thirdPartyCiv.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.WarMongerer, -aggroGeneratedForOtherCivs) // Uncool bro.
}
if(currentPopulation>1) population.population -= 1 + currentPopulation/4 // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
population.unassignExtraPopulation()
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
if(!attackerCiv.policies.isAdopted("Police State")) {
expansion.cultureStored = 0
expansion.reset()
}
moveToCiv(attackerCiv)
resistanceCounter = population.population
workedTiles = hashSetOf() //reassign 1st working tile
population.specialists.clear()
for (i in 0..population.population)
population.autoAssignPopulation()
cityStats.update()
}
if(cityConstructions.isBuilt("Palace")){
cityConstructions.removeBuilding("Palace")
if(defenderCiv.isDefeated()) {
defenderCiv.destroy()
attackerCiv.popupAlerts.add(PopupAlert(AlertType.Defeated,defenderCiv.civName))
}
else if(defenderCiv.cities.isNotEmpty()){
defenderCiv.cities.first().cityConstructions.addBuilding("Palace") // relocate palace
}
}
Battle(civInfo.gameInfo).postBattleActionsPart2(conquerer as MapUnitCombatant, CityCombatant(this), ccenterTile)
conquerer = null
UnCivGame.Current.worldScreen.shouldUpdate=true
}
fun RazeCity() {
AnnexCity()
isBeingRazed = true
}
fun PuppetCity() {
AnnexCity()
isPuppet = true
resistanceCounter = 0
}
fun LiberateCity() {
if (foundingCiv == "") {
AnnexCity()
return
}
val attackerCiv = conquerer!!.getCivInfo()
val defenderCiv = civInfo
val foundingCiv = civInfo.gameInfo.civilizations.first { it.civName == foundingCiv }
getCenterTile().apply {
if(militaryUnit!=null) militaryUnit!!.destroy()
if(civilianUnit!=null) civilianUnit!!.destroy()
for(airUnit in airUnits.toList()) airUnit.destroy()
}
val currentPopulation = population.population
val percentageOfCivPopulationInThatCity = currentPopulation*100f / (foundingCiv.cities.sumBy { it.population.population } + currentPopulation)
val aggroGenerated = 10f+percentageOfCivPopulationInThatCity.roundToInt()
foundingCiv.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.CapturedOurCities, aggroGenerated)
for(thirdPartyCiv in attackerCiv.getKnownCivs().filter { it.isMajorCiv() }){
val aggroGeneratedForOtherCivs = (aggroGenerated/10).roundToInt().toFloat()
thirdPartyCiv.getDiplomacyManager(attackerCiv)
.addModifier(DiplomaticModifiers.WarMongerer, aggroGeneratedForOtherCivs) // Cool, keep at at! =D
}
population.unassignExtraPopulation()
health = getMaxHealth() // I think that cities recover to half health when conquered?
moveToCiv(foundingCiv)
workedTiles = hashSetOf() //reassign 1st working tile
population.specialists.clear()
for (i in 0..population.population)
population.autoAssignPopulation()
cityStats.update()
if(foundingCiv.cities.size == 1) {
cityConstructions.addBuilding("Palace")
}
Battle(civInfo.gameInfo).postBattleActionsPart2(conquerer as MapUnitCombatant, CityCombatant(this), ccenterTile)
conquerer = null
UnCivGame.Current.worldScreen.shouldUpdate=true
}
fun hasExtraAnnexUnhappiness() : Boolean {
if (civInfo.civName == foundingCiv || foundingCiv == "" || isPuppet) return false
return !containsBuildingUnique("Remove extra unhappiness from annexed cities")
}
fun moveToCiv(newCivInfo: CivilizationInfo){
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
newCivInfo.cities = newCivInfo.cities.toMutableList().apply { add(this@CityInfo) }

View file

@ -165,6 +165,14 @@ class CityStats {
return stats
}
private fun getStatPercentBonusesFromPuppetCity(): Stats {
val stats = Stats()
if (cityInfo.isPuppet) {
stats.science -= 25f
stats.culture -= 25f
}
return stats
}
fun getGrowthBonusFromPolicies(): Float {
var bonus = 0f
@ -186,6 +194,7 @@ class CityStats {
unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier
var unhappinessFromCity = -3f
if (cityInfo.hasExtraAnnexUnhappiness()) unhappinessFromCity -= 2f //annexed city
if (civInfo.nation.unique == "Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved.")
unhappinessFromCity *= 2f//doubled for the Indian
@ -194,6 +203,11 @@ class CityStats {
var unhappinessFromCitizens = cityInfo.population.population.toFloat()
if (civInfo.policies.isAdopted("Democracy"))
unhappinessFromCitizens -= cityInfo.population.getNumberOfSpecialists() * 0.5f
if (cityInfo.isPuppet)
unhappinessFromCitizens *= 1.5f
else if (cityInfo.hasExtraAnnexUnhappiness())
unhappinessFromCitizens *= 2f
if (civInfo.containsBuildingUnique("Unhappiness from population decreased by 10%"))
unhappinessFromCitizens *= 0.9f
if (civInfo.policies.isAdopted("Meritocracy"))
@ -373,6 +387,7 @@ class CityStats {
newStatPercentBonusList["Computers"]=getStatPercentBonusesFromComputers()
newStatPercentBonusList["Difficulty"]=getStatPercentBonusesFromDifficulty()
newStatPercentBonusList["National ability"]=getStatPercentBonusesFromNationUnique()
newStatPercentBonusList["Puppet City"]=getStatPercentBonusesFromPuppetCity()
if(UnCivGame.Current.superchargedForDebug) {
val stats = Stats()

View file

@ -240,6 +240,11 @@ class Building : NamedStats(), IConstruction{
&& !construction.cityInfo.getCenterTile().neighbors.any { it.baseTerrain==Constants.coast })
return "Can only be built in coastal cities"
if("Can only be built in annexed cities" in uniques
&& (construction.cityInfo.isPuppet || construction.cityInfo.foundingCiv == ""
|| construction.cityInfo.civInfo.civName == construction.cityInfo.foundingCiv))
return "Can only be built in annexed cities"
val civInfo = construction.cityInfo.civInfo
if (uniqueTo!=null && uniqueTo!=civInfo.civName) return "Unique to $uniqueTo"
if (GameBasics.Buildings.values.any { it.uniqueTo==civInfo.civName && it.replaces==name }) return "Our unique building replaces this"

View file

@ -176,7 +176,10 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
if(specificStatValue==0f) continue
statValuesTable.add(entry.key.toLabel())
val decimal = DecimalFormat("0.#").format(specificStatValue)
if (specificStatValue > 0)
statValuesTable.add("+$decimal%".toLabel()).row()
else
statValuesTable.add("$decimal%".toLabel()).row()
}
if(stat==Stat.Food){
statValuesTable.add("Food eaten".toLabel())
@ -223,7 +226,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
// these two are conflictingly named compared to above...
val assignedSpecialists = currentSpecialists[stat]!!.toInt()
val maxSpecialists = statToMaximumSpecialist.value.toInt()
if (assignedSpecialists > 0) {
if (assignedSpecialists > 0 && !cityInfo.isPuppet) {
val unassignButton = TextButton("-", skin)
unassignButton.label.setFontSize(24)
unassignButton.onClick {
@ -241,7 +244,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
specialistIconTable.add(icon).size(30f)
}
specialistPickerTable.add(specialistIconTable)
if (assignedSpecialists < maxSpecialists) {
if (assignedSpecialists < maxSpecialists && !cityInfo.isPuppet) {
val assignButton = TextButton("+", skin)
assignButton.label.setFontSize(24)
assignButton.onClick {

View file

@ -79,7 +79,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
cityPickerTable.centerX(stage)
constructionsTable.update()
updateRazeCityButton()
updateAnnexAndRazeCityButton()
tileTable.update(selectedTile)
tileTable.setPosition(stage.width-5, 5f,Align.bottomRight)
updateTileGroups()
@ -161,10 +161,21 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
return table.addBorder(2f, beige)
}
private fun updateRazeCityButton() {
private fun updateAnnexAndRazeCityButton() {
razeCityButtonHolder.clear()
if(!city.isBeingRazed) {
if(city.isPuppet) {
val annexCityButton = TextButton("Annex city".tr(), skin)
annexCityButton.labelCell.pad(10f)
annexCityButton.onClick {
city.isPuppet=false
city.isBeingRazed=false
city.resistanceCounter = city.population.population
update()
}
razeCityButtonHolder.add(annexCityButton).colspan(cityPickerTable.columns)
}
else if(!city.isBeingRazed) {
val razeCityButton = TextButton("Raze city".tr(), skin)
razeCityButton.labelCell.pad(10f)
razeCityButton.onClick { city.isBeingRazed=true; update() }
@ -197,6 +208,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
val tileInfo = tileGroup.tileInfo
tileGroup.onClick {
if (!city.isPuppet) {
selectedTile = tileInfo
if (tileGroup.isWorkable && UnCivGame.Current.worldScreen.isPlayersTurn) {
if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0)
@ -206,6 +218,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
}
update()
}
}
tileGroups.add(tileGroup)

View file

@ -53,7 +53,7 @@ class CityScreenTileTable(val city: CityInfo): Table(){
city.expansion.buyTile(selectedTile)
UnCivGame.Current.screen = CityScreen(city)
}
if(goldCostOfTile>city.civInfo.gold || !UnCivGame.Current.worldScreen.isPlayersTurn)
if(goldCostOfTile>city.civInfo.gold || city.isPuppet || !UnCivGame.Current.worldScreen.isPlayersTurn)
buyTileButton.disable()
innerTable.add(buyTileButton)

View file

@ -50,12 +50,14 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
if(rejectionReason=="" && UnCivGame.Current.worldScreen.isPlayersTurn) { // no rejection reason means we can build it!
pickProductionButton.onClick {
if (!cityScreen.city.isPuppet) {
lastConstruction = cityScreen.city.cityConstructions.currentConstruction
cityScreen.city.cityConstructions.currentConstruction = construction
cityScreen.city.cityConstructions.currentConstructionIsUserSet = true
cityScreen.city.cityStats.update()
cityScreen.update()
}
}
}
else {
@ -147,7 +149,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
row()
val purchaseConstructionButton: TextButton
if (construction.canBePurchased()) {
if (construction.canBePurchased() && !city.isPuppet) {
val constructionGoldCost = construction.getGoldCost(city.civInfo)
purchaseConstructionButton = TextButton("Buy for [$constructionGoldCost] gold".tr(), CameraStageBaseScreen.skin)
purchaseConstructionButton.onClick("coin") {

View file

@ -59,11 +59,26 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
}
}
AlertType.CityConquered -> {
val city = worldScreen.gameInfo.civilizations.flatMap { it->it.cities }.first { it.name == popupAlert.value}
addGoodSizedLabel("What would you like to do with the city?").row()
add(getCloseButton("Annex")).row()
if (city.foundingCiv != ""
&& city.civInfo.civName != city.foundingCiv
&& city.conquerer!!.getCivInfo().civName != city.foundingCiv) {
add(TextButton("Liberate".tr(), skin).onClick {
city.LiberateCity()
close()
}).row()
}
add(TextButton("Annex".tr(), skin).onClick {
city.AnnexCity()
close()
}).row()
add(TextButton("Puppet City".tr(), skin).onClick {
city.PuppetCity()
close()
}).row()
add(TextButton("Raze".tr(), skin).onClick {
worldScreen.viewingCiv.cities.first { it.name==popupAlert.value }.isBeingRazed=true
worldScreen.shouldUpdate=true
city.RazeCity()
close()
})
}

View file

@ -41,6 +41,7 @@ Unless otherwise specified, all the following are from [the Noun Project](https:
* [Roman Helmet](https://thenounproject.com/search/?q=legion&i=440134) By parkjisun for Legion
* [Horse](https://thenounproject.com/search/?q=Horse&i=1373793) By AFY Studio for Horseman
* [Horse Head](https://thenounproject.com/search/?q=Cavalry&i=374037) By Juan Pablo Bravo for Companion Cavalry
* [Judge](https://thenounproject.com/search/?q=judge&i=1076388) By Krisztián Mátyás for Courthouse
### Medieval Era