mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-25 21:03:15 -04:00
Added religion city counters and spread of religion between cities - none of this is yet user-visible
This commit is contained in:
parent
faac24a2a5
commit
a2aab6f071
@ -6,6 +6,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.ruleset.tile.ResourceSupplyList
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
@ -46,6 +47,7 @@ class CityInfo {
|
||||
var health = 200
|
||||
var resistanceCounter = 0
|
||||
|
||||
var religion = CityInfoReligionManager()
|
||||
var population = PopulationManager()
|
||||
var cityConstructions = CityConstructions()
|
||||
var expansion = CityExpansionManager()
|
||||
@ -149,6 +151,7 @@ class CityInfo {
|
||||
toReturn.turnAcquired = turnAcquired
|
||||
toReturn.isPuppet = isPuppet
|
||||
toReturn.isOriginalCapital = isOriginalCapital
|
||||
toReturn.religion = CityInfoReligionManager().apply { putAll(religion) }
|
||||
return toReturn
|
||||
}
|
||||
|
||||
@ -315,6 +318,7 @@ class CityInfo {
|
||||
cityStats.cityInfo = this
|
||||
cityConstructions.cityInfo = this
|
||||
cityConstructions.setTransients()
|
||||
religion.cityInfo = this
|
||||
}
|
||||
|
||||
fun startTurn() {
|
||||
@ -365,6 +369,8 @@ class CityInfo {
|
||||
}
|
||||
} else population.nextTurn(foodForNextTurn())
|
||||
|
||||
if (getRuleset().hasReligion()) religion.getAffectedBySurroundingCities()
|
||||
|
||||
if (this in civInfo.cities) { // city was not destroyed
|
||||
health = min(health + 20, getMaxHealth())
|
||||
population.unassignExtraPopulation()
|
||||
@ -476,3 +482,47 @@ class CityInfo {
|
||||
//endregion
|
||||
}
|
||||
|
||||
class CityInfoReligionManager: Counter<String>(){
|
||||
@Transient
|
||||
lateinit var cityInfo: CityInfo
|
||||
|
||||
fun getNumberOfFollowers(): Counter<String> {
|
||||
val totalInfluence = values.sum()
|
||||
val population = cityInfo.population.population
|
||||
if (totalInfluence > 100 * population) {
|
||||
val toReturn = Counter<String>()
|
||||
for ((key, value) in this)
|
||||
if (value > 100)
|
||||
toReturn.add(key, value / 100)
|
||||
return toReturn
|
||||
}
|
||||
|
||||
val toReturn = Counter<String>()
|
||||
|
||||
for ((key, value) in this) {
|
||||
val percentage = value.toFloat() / totalInfluence
|
||||
val relativePopulation = (percentage * population).roundToInt()
|
||||
toReturn.add(key, relativePopulation)
|
||||
}
|
||||
return toReturn
|
||||
}
|
||||
|
||||
fun getMajorityReligion():String? {
|
||||
val followersPerReligion = getNumberOfFollowers()
|
||||
if (followersPerReligion.isEmpty()) return null
|
||||
val religionWithMaxFollowers = followersPerReligion.maxByOrNull { it.value }!!
|
||||
if (religionWithMaxFollowers.value >= cityInfo.population.population) return religionWithMaxFollowers.key
|
||||
else return null
|
||||
}
|
||||
|
||||
fun getAffectedBySurroundingCities() {
|
||||
val allCitiesWithin10Tiles = cityInfo.civInfo.gameInfo.civilizations.asSequence().flatMap { it.cities }
|
||||
.filter { it != cityInfo && it.getCenterTile().aerialDistanceTo(cityInfo.getCenterTile()) <= 10 }
|
||||
for (city in allCitiesWithin10Tiles) {
|
||||
val majorityReligionOfCity = city.religion.getMajorityReligion()
|
||||
if (majorityReligionOfCity == null) continue
|
||||
else add(majorityReligionOfCity, 6) // todo - when holy cities are implemented, *5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.unciv.models
|
||||
|
||||
import java.util.*
|
||||
|
||||
class Counter<K> : LinkedHashMap<K, Int>() {
|
||||
open class Counter<K> : LinkedHashMap<K, Int>() {
|
||||
|
||||
override operator fun get(key: K): Int? { // don't return null if empty
|
||||
if (containsKey(key))
|
||||
|
Loading…
x
Reference in New Issue
Block a user