mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Added ability to raze cities
This commit is contained in:
@ -27,7 +27,7 @@ class CityInfo {
|
|||||||
|
|
||||||
var tiles = HashSet<Vector2>()
|
var tiles = HashSet<Vector2>()
|
||||||
var workedTiles = HashSet<Vector2>()
|
var workedTiles = HashSet<Vector2>()
|
||||||
|
var isBeingRazed = false
|
||||||
|
|
||||||
internal val tileMap: TileMap
|
internal val tileMap: TileMap
|
||||||
get() = civInfo.gameInfo.tileMap
|
get() = civInfo.gameInfo.tileMap
|
||||||
@ -132,6 +132,14 @@ class CityInfo {
|
|||||||
population.nextTurn(stats.food)
|
population.nextTurn(stats.food)
|
||||||
cityConstructions.nextTurn(stats)
|
cityConstructions.nextTurn(stats)
|
||||||
expansion.nextTurn(stats.culture)
|
expansion.nextTurn(stats.culture)
|
||||||
|
if(isBeingRazed){
|
||||||
|
population.population--
|
||||||
|
population.unassignExtraPopulation()
|
||||||
|
if(population.population==0){
|
||||||
|
civInfo.addNotification("$name has been razed to the ground!",location, Color.RED)
|
||||||
|
civInfo.cities.remove(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val maxHealth =getMaxHealth()
|
val maxHealth =getMaxHealth()
|
||||||
health = min(health+maxHealth/10, maxHealth)
|
health = min(health+maxHealth/10, maxHealth)
|
||||||
|
@ -46,12 +46,7 @@ class PopulationManager {
|
|||||||
// starvation!
|
// starvation!
|
||||||
{
|
{
|
||||||
population--
|
population--
|
||||||
if(cityInfo.workedTiles.size>population) {
|
unassignExtraPopulation()
|
||||||
val lowestRankedWorkedTile = cityInfo.workedTiles
|
|
||||||
.map { cityInfo.tileMap[it] }
|
|
||||||
.minBy { Automation().rankTile(it, cityInfo.civInfo) }!!
|
|
||||||
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
|
||||||
}
|
|
||||||
foodStored = 0
|
foodStored = 0
|
||||||
cityInfo.civInfo.addNotification(cityInfo.name + " is starving!", cityInfo.location, Color.RED)
|
cityInfo.civInfo.addNotification(cityInfo.name + " is starving!", cityInfo.location, Color.RED)
|
||||||
}
|
}
|
||||||
@ -74,4 +69,13 @@ class PopulationManager {
|
|||||||
cityInfo.workedTiles.add(toWork.position)
|
cityInfo.workedTiles.add(toWork.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun unassignExtraPopulation() {
|
||||||
|
while (cityInfo.workedTiles.size > population) {
|
||||||
|
val lowestRankedWorkedTile = cityInfo.workedTiles
|
||||||
|
.map { cityInfo.tileMap[it] }
|
||||||
|
.minBy { Automation().rankTile(it, cityInfo.civInfo) }!!
|
||||||
|
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ class CivilizationInfo {
|
|||||||
|
|
||||||
if (cities.size > 0) tech.nextTurn(nextTurnStats.science.toInt())
|
if (cities.size > 0) tech.nextTurn(nextTurnStats.science.toInt())
|
||||||
|
|
||||||
for (city in cities) {
|
for (city in cities.toList()) { // a city can be removed while iterating (if it's being razed) so we need to iterate over a copy
|
||||||
city.endTurn()
|
city.endTurn()
|
||||||
greatPeople.addGreatPersonPoints(city.getGreatPersonPoints())
|
greatPeople.addGreatPersonPoints(city.getGreatPersonPoints())
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||||||
cityPickerTable.add(prevCityButton)
|
cityPickerTable.add(prevCityButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentCityLabel = Label(city.name, CameraStageBaseScreen.skin)
|
val currentCityLabel = Label(city.name+" ("+city.population.population+")", CameraStageBaseScreen.skin)
|
||||||
currentCityLabel.setFontScale(2f)
|
currentCityLabel.setFontScale(2f)
|
||||||
cityPickerTable.add(currentCityLabel)
|
cityPickerTable.add(currentCityLabel)
|
||||||
|
|
||||||
@ -137,6 +137,19 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
cityPickerTable.add(nextCityButton)
|
cityPickerTable.add(nextCityButton)
|
||||||
}
|
}
|
||||||
|
cityPickerTable.row()
|
||||||
|
|
||||||
|
if(!city.isBeingRazed) {
|
||||||
|
val razeCityButton = TextButton("Raze city", skin)
|
||||||
|
razeCityButton.addClickListener { city.isBeingRazed=true; update() }
|
||||||
|
cityPickerTable.add(razeCityButton)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
val stopRazingCityButton = TextButton("Stop razing city", skin)
|
||||||
|
stopRazingCityButton.addClickListener { city.isBeingRazed=false; update() }
|
||||||
|
cityPickerTable.add(stopRazingCityButton)
|
||||||
|
}
|
||||||
|
|
||||||
cityPickerTable.pack()
|
cityPickerTable.pack()
|
||||||
cityPickerTable.centerX(stage)
|
cityPickerTable.centerX(stage)
|
||||||
stage.addActor(cityPickerTable)
|
stage.addActor(cityPickerTable)
|
||||||
|
@ -49,6 +49,11 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateCityButton(city: CityInfo?) {
|
private fun updateCityButton(city: CityInfo?) {
|
||||||
|
if(city==null && cityButton!=null)// there used to be a city here but it was razed
|
||||||
|
{
|
||||||
|
cityButton!!.remove()
|
||||||
|
cityButton=null
|
||||||
|
}
|
||||||
if (city != null && tileInfo.isCityCenter()) {
|
if (city != null && tileInfo.isCityCenter()) {
|
||||||
if (cityButton == null) {
|
if (cityButton == null) {
|
||||||
cityButton = Table()
|
cityButton = Table()
|
||||||
|
Reference in New Issue
Block a user