mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 17:59:11 +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["Transportation upkeep"] = Stats().apply { gold=- getTransportationUpkeep().toFloat()}
|
||||||
statMap["Unit upkeep"] = Stats().apply { gold=- getUnitUpkeep().toFloat()}
|
statMap["Unit upkeep"] = Stats().apply { gold=- getUnitUpkeep().toFloat()}
|
||||||
|
|
||||||
if (civInfo.policies.hasEffect("50% of excess happiness added to culture towards policies")) {
|
if (civInfo.policies.hasEffect("50% of excess happiness added to culture towards policies")) {
|
||||||
val happiness = statMap.values.map { it.happiness }.sum()
|
val happiness = civInfo.getHappiness()
|
||||||
if(happiness>0) statMap.add("Policies", Stats().apply { culture=happiness/2 })
|
if(happiness>0) statMap.add("Policies", Stats().apply { culture=happiness/2f })
|
||||||
}
|
}
|
||||||
|
|
||||||
// negative gold hurts science
|
// negative gold hurts science
|
||||||
@ -127,7 +123,7 @@ class CivInfoStats(val civInfo: CivilizationInfo){
|
|||||||
statMap["Luxury resources"]= civInfo.getCivResources().map { it.resource }
|
statMap["Luxury resources"]= civInfo.getCivResources().map { it.resource }
|
||||||
.count { it.resourceType === ResourceType.Luxury } * happinessPerUniqueLuxury
|
.count { it.resourceType === ResourceType.Luxury } * happinessPerUniqueLuxury
|
||||||
|
|
||||||
for(city in civInfo.cities.toList()){
|
for(city in civInfo.cities){
|
||||||
for(keyvalue in city.cityStats.happinessList){
|
for(keyvalue in city.cityStats.happinessList){
|
||||||
if(statMap.containsKey(keyvalue.key))
|
if(statMap.containsKey(keyvalue.key))
|
||||||
statMap[keyvalue.key] = statMap[keyvalue.key]!!+keyvalue.value
|
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 */
|
/** This is for performance since every movement calculation depends on this, see MapUnit comment */
|
||||||
@Transient var hasActiveGreatWall = false
|
@Transient var hasActiveGreatWall = false
|
||||||
@Transient var statsForNextTurn = Stats()
|
@Transient var statsForNextTurn = Stats()
|
||||||
|
@Transient var happinessForNextTurn = 0
|
||||||
@Transient var detailedCivResources = ResourceSupplyList()
|
@Transient var detailedCivResources = ResourceSupplyList()
|
||||||
|
|
||||||
var playerType = PlayerType.AI
|
var playerType = PlayerType.AI
|
||||||
@ -147,10 +148,11 @@ class CivilizationInfo {
|
|||||||
fun transients() = CivInfoTransientUpdater(this)
|
fun transients() = CivInfoTransientUpdater(this)
|
||||||
|
|
||||||
fun updateStatsForNextTurn() {
|
fun updateStatsForNextTurn() {
|
||||||
statsForNextTurn = stats().getStatMapForNextTurn().values.toList().reduce{a,b->a+b}
|
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 {
|
fun getCivResources(): ResourceSupplyList {
|
||||||
|
Reference in New Issue
Block a user