Fixed bug that occured when city was being razed and managed to reach -1 population somehow

This commit is contained in:
Yair Morgenstern
2018-08-27 12:41:16 +03:00
parent 94e9098ac0
commit c5e4a75505
2 changed files with 7 additions and 3 deletions

View File

@ -161,7 +161,7 @@ class CityInfo {
expansion.nextTurn(stats.culture) expansion.nextTurn(stats.culture)
if(isBeingRazed){ if(isBeingRazed){
population.population-- population.population--
if(population.population==0){ if(population.population<=0){ // there are strange cases where we geet to -1
civInfo.addNotification("$name {has been razed to the ground}!",location, Color.RED) civInfo.addNotification("$name {has been razed to the ground}!",location, Color.RED)
destroyCity() destroyCity()
if(isCapital() && civInfo.cities.isNotEmpty()) // Yes, we actually razed the capital. Some people do this. if(isCapital() && civInfo.cities.isNotEmpty()) // Yes, we actually razed the capital. Some people do this.
@ -170,8 +170,10 @@ class CityInfo {
} }
else population.nextTurn(stats.food) else population.nextTurn(stats.food)
health = min(health+20, getMaxHealth()) if(this in civInfo.cities) { // city was not destroyed
population.unassignExtraPopulation() health = min(health + 20, getMaxHealth())
population.unassignExtraPopulation()
}
} }
fun destroyCity() { fun destroyCity() {

View File

@ -131,6 +131,8 @@ class CityStats {
val happinessFromBuildings = cityInfo.cityConstructions.getStats().happiness.toInt().toFloat() val happinessFromBuildings = cityInfo.cityConstructions.getStats().happiness.toInt().toFloat()
newHappinessList ["Buildings"] = happinessFromBuildings newHappinessList ["Buildings"] = happinessFromBuildings
// we don't want to modify the existing happiness list because that leads
// to concurrency problems if we iterate on it while changing
happinessList=newHappinessList happinessList=newHappinessList
return newHappinessList return newHappinessList
} }