mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 11:34:54 -04:00
perf(cpu): Optimized Civilization.getResourceAmount
This commit is contained in:
parent
de12183c53
commit
84459bb7b7
@ -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 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user