mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
perf: small 1% cpu optimizations
This commit is contained in:
@ -105,7 +105,8 @@ object Automation {
|
|||||||
if (city.civ.wantsToFocusOn(stat))
|
if (city.civ.wantsToFocusOn(stat))
|
||||||
yieldStats[stat] *= 2f
|
yieldStats[stat] *= 2f
|
||||||
|
|
||||||
yieldStats[stat] *= civPersonality.scaledFocus(PersonalityValue[stat])
|
val scaledFocus = civPersonality.scaledFocus(PersonalityValue[stat])
|
||||||
|
if (scaledFocus != 1f) yieldStats[stat] *= scaledFocus
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply City focus
|
// Apply City focus
|
||||||
@ -184,7 +185,7 @@ object Automation {
|
|||||||
}
|
}
|
||||||
// Only now do we filter out the constructable units because that's a heavier check
|
// Only now do we filter out the constructable units because that's a heavier check
|
||||||
.filter { it.isBuildable(city.cityConstructions) }
|
.filter { it.isBuildable(city.cityConstructions) }
|
||||||
.toList()
|
.toList().asSequence()
|
||||||
|
|
||||||
val chosenUnit: BaseUnit
|
val chosenUnit: BaseUnit
|
||||||
if (!city.civ.isAtWar()
|
if (!city.civ.isAtWar()
|
||||||
|
@ -66,12 +66,15 @@ enum class CityFocus(
|
|||||||
else -> 1f
|
else -> 1f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val statValuesForFocus: List<Stat> by lazy {
|
||||||
|
Stat.values().filter { getStatMultiplier(it) != 1f }
|
||||||
|
}
|
||||||
|
|
||||||
fun applyWeightTo(stats: Stats) {
|
fun applyWeightTo(stats: Stats) {
|
||||||
for (stat in Stat.values()) {
|
for (stat in statValuesForFocus) {
|
||||||
val currentStat = stats[stat]
|
val currentStat = stats[stat]
|
||||||
if (currentStat == 0f) continue
|
if (currentStat == 0f) continue
|
||||||
val statMultiplier = getStatMultiplier(stat)
|
val statMultiplier = getStatMultiplier(stat)
|
||||||
if (statMultiplier == 1f) continue
|
|
||||||
stats[stat] = currentStat * statMultiplier
|
stats[stat] = currentStat * statMultiplier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,9 @@ class TileImprovementFunctions(val tile: Tile) {
|
|||||||
.any { civInfo.getResourceAmount(it.params[1]) < it.params[0].toInt() })
|
.any { civInfo.getResourceAmount(it.params[1]) < it.params[0].toInt() })
|
||||||
yield(ImprovementBuildingProblem.MissingResources)
|
yield(ImprovementBuildingProblem.MissingResources)
|
||||||
|
|
||||||
val knownFeatureRemovals = tile.ruleset.tileRemovals
|
val knownFeatureRemovals = tile.ruleset.nonRoadTileRemovals
|
||||||
.filter { rulesetImprovement ->
|
.filter { rulesetImprovement ->
|
||||||
RoadStatus.values().none { it.removeAction == rulesetImprovement.name }
|
rulesetImprovement.techRequired == null || civInfo.tech.isResearched(rulesetImprovement.techRequired!!)
|
||||||
&& (rulesetImprovement.techRequired == null || civInfo.tech.isResearched(rulesetImprovement.techRequired!!))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canImprovementBeBuiltHere(improvement, tile.hasViewableResource(civInfo), knownFeatureRemovals, stateForConditionals))
|
if (!canImprovementBeBuiltHere(improvement, tile.hasViewableResource(civInfo), knownFeatureRemovals, stateForConditionals))
|
||||||
|
@ -88,6 +88,8 @@ class Ruleset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val tileRemovals by lazy { tileImprovements.values.filter { it.name.startsWith(Constants.remove) } }
|
val tileRemovals by lazy { tileImprovements.values.filter { it.name.startsWith(Constants.remove) } }
|
||||||
|
val nonRoadTileRemovals by lazy { tileRemovals.filter { rulesetImprovement ->
|
||||||
|
RoadStatus.values().none { it.removeAction == rulesetImprovement.name } } }
|
||||||
|
|
||||||
/** Contains all happiness levels that moving *from* them, to one *below* them, can change uniques that apply */
|
/** Contains all happiness levels that moving *from* them, to one *below* them, can change uniques that apply */
|
||||||
val allHappinessLevelsThatAffectUniques by lazy {
|
val allHappinessLevelsThatAffectUniques by lazy {
|
||||||
|
Reference in New Issue
Block a user