mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Minor code reorg
This commit is contained in:
parent
548078fb37
commit
cb06253584
@ -239,22 +239,21 @@ class CityInfo {
|
|||||||
|
|
||||||
cityConstructions.endTurn(stats)
|
cityConstructions.endTurn(stats)
|
||||||
expansion.nextTurn(stats.culture)
|
expansion.nextTurn(stats.culture)
|
||||||
if(isBeingRazed){
|
if (isBeingRazed) {
|
||||||
population.population--
|
population.population--
|
||||||
if(population.population<=0){ // there are strange cases where we geet to -1
|
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.
|
||||||
civInfo.cities.first().cityConstructions.addBuilding("Palace")
|
civInfo.cities.first().cityConstructions.addBuilding("Palace")
|
||||||
}else{//if not razed yet:
|
} else {//if not razed yet:
|
||||||
if(population.foodStored>=population.getFoodToNextPopulation()) {//if surplus in the granary...
|
if (population.foodStored >= population.getFoodToNextPopulation()) {//if surplus in the granary...
|
||||||
population.foodStored=population.getFoodToNextPopulation()-1//...reduce below the new growth treshold
|
population.foodStored = population.getFoodToNextPopulation() - 1//...reduce below the new growth treshold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else population.nextTurn(stats.food)
|
||||||
else population.nextTurn(stats.food)
|
|
||||||
|
|
||||||
if(this in civInfo.cities) { // city was not destroyed
|
if (this in civInfo.cities) { // city was not destroyed
|
||||||
health = min(health + 20, getMaxHealth())
|
health = min(health + 20, getMaxHealth())
|
||||||
population.unassignExtraPopulation()
|
population.unassignExtraPopulation()
|
||||||
}
|
}
|
||||||
@ -298,19 +297,17 @@ class CityInfo {
|
|||||||
conqueringCiv.popupAlerts.add(PopupAlert(AlertType.Defeated,oldCiv.civName))
|
conqueringCiv.popupAlerts.add(PopupAlert(AlertType.Defeated,oldCiv.civName))
|
||||||
}
|
}
|
||||||
|
|
||||||
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
diplomaticRepercussionsForConqueringCity(oldCiv, conqueringCiv)
|
||||||
|
|
||||||
diplomaticReprecussionsForConqueringCity(oldCiv, conqueringCiv)
|
|
||||||
|
|
||||||
if(population.population>1) population.population -= 1 + population.population/4 // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
|
if(population.population>1) population.population -= 1 + population.population/4 // so from 2-4 population, remove 1, from 5-8, remove 2, etc.
|
||||||
|
|
||||||
resistanceCounter = population.population // I checked, and even if you puppet there's resistance for conquering
|
|
||||||
reassignWorkers()
|
reassignWorkers()
|
||||||
|
|
||||||
|
resistanceCounter = population.population // I checked, and even if you puppet there's resistance for conquering
|
||||||
isPuppet = true
|
isPuppet = true
|
||||||
|
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun diplomaticReprecussionsForConqueringCity(oldCiv: CivilizationInfo, conqueringCiv: CivilizationInfo) {
|
private fun diplomaticRepercussionsForConqueringCity(oldCiv: CivilizationInfo, conqueringCiv: CivilizationInfo) {
|
||||||
val currentPopulation = population.population
|
val currentPopulation = population.population
|
||||||
val percentageOfCivPopulationInThatCity = currentPopulation * 100f / civInfo.cities.sumBy { it.population.population }
|
val percentageOfCivPopulationInThatCity = currentPopulation * 100f / civInfo.cities.sumBy { it.population.population }
|
||||||
val aggroGenerated = 10f + percentageOfCivPopulationInThatCity.roundToInt()
|
val aggroGenerated = 10f + percentageOfCivPopulationInThatCity.roundToInt()
|
||||||
@ -334,38 +331,35 @@ class CityInfo {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val oldOwningCiv = civInfo
|
|
||||||
|
diplomaticRepercussionsForLiberatingCity(conqueringCiv)
|
||||||
|
|
||||||
val foundingCiv = civInfo.gameInfo.civilizations.first { it.civName == foundingCiv }
|
val foundingCiv = civInfo.gameInfo.civilizations.first { it.civName == foundingCiv }
|
||||||
|
|
||||||
val currentPopulation = population.population
|
|
||||||
|
|
||||||
val percentageOfCivPopulationInThatCity = currentPopulation*100f / (foundingCiv.cities.sumBy { it.population.population } + currentPopulation)
|
|
||||||
val respecForLiberatingOurCity = 10f+percentageOfCivPopulationInThatCity.roundToInt()
|
|
||||||
foundingCiv.getDiplomacyManager(conqueringCiv)
|
|
||||||
.addModifier(DiplomaticModifiers.CapturedOurCities, respecForLiberatingOurCity)
|
|
||||||
|
|
||||||
val otherCivsRespecForLiberating = (respecForLiberatingOurCity/10).roundToInt().toFloat()
|
|
||||||
for(thirdPartyCiv in conqueringCiv.getKnownCivs().filter { it.isMajorCiv() && it != oldOwningCiv }){
|
|
||||||
thirdPartyCiv.getDiplomacyManager(conqueringCiv)
|
|
||||||
.addModifier(DiplomaticModifiers.WarMongerer, otherCivsRespecForLiberating) // Cool, keep at at! =D
|
|
||||||
}
|
|
||||||
|
|
||||||
moveToCiv(foundingCiv)
|
moveToCiv(foundingCiv)
|
||||||
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
health = getMaxHealth() / 2 // I think that cities recover to half health when conquered?
|
||||||
|
|
||||||
reassignWorkers()
|
reassignWorkers()
|
||||||
|
|
||||||
if(foundingCiv.cities.size == 1) { // Resurrection!
|
if(foundingCiv.cities.size == 1) cityConstructions.addBuilding("Palace") // Resurrection!
|
||||||
cityConstructions.addBuilding("Palace")
|
|
||||||
}
|
|
||||||
|
|
||||||
UnCivGame.Current.worldScreen.shouldUpdate=true
|
UnCivGame.Current.worldScreen.shouldUpdate=true
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo should be in cityStats
|
private fun diplomaticRepercussionsForLiberatingCity(conqueringCiv: CivilizationInfo) {
|
||||||
fun hasExtraAnnexUnhappiness() : Boolean {
|
val oldOwningCiv = civInfo
|
||||||
if (civInfo.civName == foundingCiv || foundingCiv == "" || isPuppet) return false
|
val foundingCiv = civInfo.gameInfo.civilizations.first { it.civName == foundingCiv }
|
||||||
return !containsBuildingUnique("Remove extra unhappiness from annexed cities")
|
val percentageOfCivPopulationInThatCity = population.population *
|
||||||
|
100f / (foundingCiv.cities.sumBy { it.population.population } + population.population)
|
||||||
|
val respecForLiberatingOurCity = 10f + percentageOfCivPopulationInThatCity.roundToInt()
|
||||||
|
foundingCiv.getDiplomacyManager(conqueringCiv)
|
||||||
|
.addModifier(DiplomaticModifiers.CapturedOurCities, respecForLiberatingOurCity)
|
||||||
|
|
||||||
|
val otherCivsRespecForLiberating = (respecForLiberatingOurCity / 10).roundToInt().toFloat()
|
||||||
|
for (thirdPartyCiv in conqueringCiv.getKnownCivs().filter { it.isMajorCiv() && it != oldOwningCiv }) {
|
||||||
|
thirdPartyCiv.getDiplomacyManager(conqueringCiv)
|
||||||
|
.addModifier(DiplomaticModifiers.WarMongerer, otherCivsRespecForLiberating) // Cool, keep at at! =D
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun moveToCiv(newCivInfo: CivilizationInfo){
|
fun moveToCiv(newCivInfo: CivilizationInfo){
|
||||||
@ -401,8 +395,6 @@ class CityInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tryUpdateRoadStatus()
|
tryUpdateRoadStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,6 @@ class CityStats {
|
|||||||
unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier
|
unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier
|
||||||
|
|
||||||
var unhappinessFromCity = -3f
|
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.")
|
if (civInfo.nation.unique == "Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved.")
|
||||||
unhappinessFromCity *= 2f//doubled for the Indian
|
unhappinessFromCity *= 2f//doubled for the Indian
|
||||||
|
|
||||||
@ -206,7 +205,7 @@ class CityStats {
|
|||||||
|
|
||||||
if (cityInfo.isPuppet)
|
if (cityInfo.isPuppet)
|
||||||
unhappinessFromCitizens *= 1.5f
|
unhappinessFromCitizens *= 1.5f
|
||||||
else if (cityInfo.hasExtraAnnexUnhappiness())
|
else if (hasExtraAnnexUnhappiness())
|
||||||
unhappinessFromCitizens *= 2f
|
unhappinessFromCitizens *= 2f
|
||||||
if (civInfo.containsBuildingUnique("Unhappiness from population decreased by 10%"))
|
if (civInfo.containsBuildingUnique("Unhappiness from population decreased by 10%"))
|
||||||
unhappinessFromCitizens *= 0.9f
|
unhappinessFromCitizens *= 0.9f
|
||||||
@ -229,6 +228,8 @@ class CityStats {
|
|||||||
|
|
||||||
newHappinessList["Policies"] = happinessFromPolicies
|
newHappinessList["Policies"] = happinessFromPolicies
|
||||||
|
|
||||||
|
if (hasExtraAnnexUnhappiness()) newHappinessList["Occupied City"] = -2f //annexed city
|
||||||
|
|
||||||
val happinessFromBuildings = cityInfo.cityConstructions.getStats().happiness.toInt().toFloat()
|
val happinessFromBuildings = cityInfo.cityConstructions.getStats().happiness.toInt().toFloat()
|
||||||
newHappinessList["Buildings"] = happinessFromBuildings
|
newHappinessList["Buildings"] = happinessFromBuildings
|
||||||
|
|
||||||
@ -240,6 +241,12 @@ class CityStats {
|
|||||||
happinessList = newHappinessList
|
happinessList = newHappinessList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun hasExtraAnnexUnhappiness() : Boolean {
|
||||||
|
if (cityInfo.civInfo.civName == cityInfo.foundingCiv || cityInfo.foundingCiv == "" || cityInfo.isPuppet) return false
|
||||||
|
return !cityInfo.containsBuildingUnique("Remove extra unhappiness from annexed cities")
|
||||||
|
}
|
||||||
|
|
||||||
fun getStatsOfSpecialist(stat: Stat, policies: HashSet<String>): Stats {
|
fun getStatsOfSpecialist(stat: Stat, policies: HashSet<String>): Stats {
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
if (stat == Stat.Culture || stat == Stat.Science) stats.add(stat, 3f)
|
if (stat == Stat.Culture || stat == Stat.Science) stats.add(stat, 3f)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user