mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
perf: Improvement filter cache, other small things
This commit is contained in:
@ -56,7 +56,7 @@ object Automation {
|
||||
yieldStats.food -= (unique.params[0].toFloat() / 100f) * 2f // base 2 food per Pop
|
||||
// Specialist Happiness Percentage Change 0f-1f
|
||||
for (unique in localUniqueCache.forCityGetMatchingUniques(city, UniqueType.UnhappinessFromPopulationTypePercentageChange))
|
||||
if (city.matchesFilter(unique.params[2]) && unique.params[1] == "Specialists")
|
||||
if (unique.params[1] == "Specialists" && city.matchesFilter(unique.params[2]))
|
||||
yieldStats.happiness -= (unique.params[0].toFloat() / 100f) // relative val is negative, make positive
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,10 @@ enum class CityFocus(
|
||||
fun applyWeightTo(stats: Stats) {
|
||||
for (stat in Stat.values()) {
|
||||
val currentStat = stats[stat]
|
||||
if (currentStat != 0f) stats[stat] *= getStatMultiplier(stat)
|
||||
if (currentStat == 0f) continue
|
||||
val statMultiplier = getStatMultiplier(stat)
|
||||
if (statMultiplier == 1f) continue
|
||||
stats[stat] = currentStat * statMultiplier
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ class CityPopulationManager : IsPartOfGameInfoSerialization {
|
||||
if (valueBestTile > valueBestSpecialist) {
|
||||
if (bestTile != null) {
|
||||
city.workedTiles = city.workedTiles.withItem(bestTile.position)
|
||||
cityStats.food += bestTile.stats.getTileStats(city, city.civ, localUniqueCache).food
|
||||
cityStats.food += tileStats[bestTile]!!.food
|
||||
}
|
||||
} else if (bestJob != null) {
|
||||
specialistAllocations.add(bestJob, 1)
|
||||
|
@ -67,10 +67,12 @@ class TileImprovement : RulesetStatsObject() {
|
||||
fun isAllowedOnFeature(terrain: Terrain) = canBeBuiltOn(terrain)
|
||||
|| getMatchingUniques(UniqueType.NoFeatureRemovalNeeded).any { terrain.matchesFilter(it.params[0]) }
|
||||
|
||||
|
||||
private val cachedMatchesFilterResult = HashMap<String, Boolean>()
|
||||
|
||||
/** Implements [UniqueParameterType.ImprovementFilter][com.unciv.models.ruleset.unique.UniqueParameterType.ImprovementFilter] */
|
||||
fun matchesFilter(filter: String): Boolean {
|
||||
return MultiFilter.multiFilter(filter, ::matchesSingleFilter)
|
||||
}
|
||||
fun matchesFilter(filter: String): Boolean =
|
||||
cachedMatchesFilterResult.getOrPut(filter) { MultiFilter.multiFilter(filter, ::matchesSingleFilter ) }
|
||||
|
||||
private fun matchesSingleFilter(filter: String): Boolean {
|
||||
return when (filter) {
|
||||
|
Reference in New Issue
Block a user