mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 01:08:25 +07:00
Happiness is now a saved transient - saves about 10% of all runtime! Can't believe I hadn't thought of that before! 0_0
This commit is contained in:
@ -89,16 +89,12 @@ class CivInfoStats(val civInfo: CivilizationInfo){
|
||||
}
|
||||
}
|
||||
|
||||
for (entry in getHappinessBreakdown()) {
|
||||
statMap.add(entry.key, Stats().apply { happiness=entry.value })
|
||||
}
|
||||
|
||||
statMap["Transportation upkeep"] = Stats().apply { gold=- getTransportationUpkeep().toFloat()}
|
||||
statMap["Unit upkeep"] = Stats().apply { gold=- getUnitUpkeep().toFloat()}
|
||||
|
||||
if (civInfo.policies.hasEffect("50% of excess happiness added to culture towards policies")) {
|
||||
val happiness = statMap.values.map { it.happiness }.sum()
|
||||
if(happiness>0) statMap.add("Policies", Stats().apply { culture=happiness/2 })
|
||||
val happiness = civInfo.getHappiness()
|
||||
if(happiness>0) statMap.add("Policies", Stats().apply { culture=happiness/2f })
|
||||
}
|
||||
|
||||
// negative gold hurts science
|
||||
@ -127,7 +123,7 @@ class CivInfoStats(val civInfo: CivilizationInfo){
|
||||
statMap["Luxury resources"]= civInfo.getCivResources().map { it.resource }
|
||||
.count { it.resourceType === ResourceType.Luxury } * happinessPerUniqueLuxury
|
||||
|
||||
for(city in civInfo.cities.toList()){
|
||||
for(city in civInfo.cities){
|
||||
for(keyvalue in city.cityStats.happinessList){
|
||||
if(statMap.containsKey(keyvalue.key))
|
||||
statMap[keyvalue.key] = statMap[keyvalue.key]!!+keyvalue.value
|
||||
|
@ -50,6 +50,7 @@ class CivilizationInfo {
|
||||
/** This is for performance since every movement calculation depends on this, see MapUnit comment */
|
||||
@Transient var hasActiveGreatWall = false
|
||||
@Transient var statsForNextTurn = Stats()
|
||||
@Transient var happinessForNextTurn = 0
|
||||
@Transient var detailedCivResources = ResourceSupplyList()
|
||||
|
||||
var playerType = PlayerType.AI
|
||||
@ -146,11 +147,12 @@ class CivilizationInfo {
|
||||
fun stats() = CivInfoStats(this)
|
||||
fun transients() = CivInfoTransientUpdater(this)
|
||||
|
||||
fun updateStatsForNextTurn(){
|
||||
statsForNextTurn = stats().getStatMapForNextTurn().values.toList().reduce{a,b->a+b}
|
||||
fun updateStatsForNextTurn() {
|
||||
happinessForNextTurn = stats().getHappinessBreakdown().values.sum().roundToInt()
|
||||
statsForNextTurn = stats().getStatMapForNextTurn().values.reduce { a, b -> a + b }
|
||||
}
|
||||
|
||||
fun getHappiness() = stats().getHappinessBreakdown().values.sum().roundToInt()
|
||||
fun getHappiness() = happinessForNextTurn
|
||||
|
||||
|
||||
fun getCivResources(): ResourceSupplyList {
|
||||
|
Reference in New Issue
Block a user