Added ability to raze cities
This commit is contained in:
parent
0dab2d6dca
commit
0959cc3b69
5 changed files with 39 additions and 9 deletions
|
@ -27,7 +27,7 @@ class CityInfo {
|
|||
|
||||
var tiles = HashSet<Vector2>()
|
||||
var workedTiles = HashSet<Vector2>()
|
||||
|
||||
var isBeingRazed = false
|
||||
|
||||
internal val tileMap: TileMap
|
||||
get() = civInfo.gameInfo.tileMap
|
||||
|
@ -132,6 +132,14 @@ class CityInfo {
|
|||
population.nextTurn(stats.food)
|
||||
cityConstructions.nextTurn(stats)
|
||||
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()
|
||||
health = min(health+maxHealth/10, maxHealth)
|
||||
|
|
|
@ -46,12 +46,7 @@ class PopulationManager {
|
|||
// starvation!
|
||||
{
|
||||
population--
|
||||
if(cityInfo.workedTiles.size>population) {
|
||||
val lowestRankedWorkedTile = cityInfo.workedTiles
|
||||
.map { cityInfo.tileMap[it] }
|
||||
.minBy { Automation().rankTile(it, cityInfo.civInfo) }!!
|
||||
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
||||
}
|
||||
unassignExtraPopulation()
|
||||
foodStored = 0
|
||||
cityInfo.civInfo.addNotification(cityInfo.name + " is starving!", cityInfo.location, Color.RED)
|
||||
}
|
||||
|
@ -74,4 +69,13 @@ class PopulationManager {
|
|||
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())
|
||||
|
||||
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()
|
||||
greatPeople.addGreatPersonPoints(city.getGreatPersonPoints())
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
cityPickerTable.add(prevCityButton)
|
||||
}
|
||||
|
||||
val currentCityLabel = Label(city.name, CameraStageBaseScreen.skin)
|
||||
val currentCityLabel = Label(city.name+" ("+city.population.population+")", CameraStageBaseScreen.skin)
|
||||
currentCityLabel.setFontScale(2f)
|
||||
cityPickerTable.add(currentCityLabel)
|
||||
|
||||
|
@ -137,6 +137,19 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
}
|
||||
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.centerX(stage)
|
||||
stage.addActor(cityPickerTable)
|
||||
|
|
|
@ -49,6 +49,11 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||
}
|
||||
|
||||
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 (cityButton == null) {
|
||||
cityButton = Table()
|
||||
|
|
Loading…
Reference in a new issue