perf(cpu): Optimized Civilization.getResourceAmount

This commit is contained in:
yairm210 2025-09-08 10:02:42 +03:00
parent de12183c53
commit 84459bb7b7

View File

@ -488,7 +488,9 @@ class Civilization : IsPartOfGameInfoSerialization {
* Returns 0 for undefined resources */ * Returns 0 for undefined resources */
@Readonly @Readonly
fun getResourceAmount(resourceName: String): Int { fun getResourceAmount(resourceName: String): Int {
return getCivResourcesByName()[resourceName] ?: 0 val stockpileValue= resourceStockpiles[resourceName]
if (stockpileValue != 0) return stockpileValue
return getCivResourceSupply().firstOrNull { !it.resource.isStockpiled && it.resource.name == resourceName }?.amount ?: 0
} }
/** Gets modifiers for ALL resources */ /** Gets modifiers for ALL resources */