mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Minor performance improvements
This commit is contained in:
parent
0065d1052b
commit
25cad3aef2
@ -6,10 +6,8 @@ import com.unciv.logic.map.TileInfo
|
|||||||
import com.unciv.models.ruleset.Belief
|
import com.unciv.models.ruleset.Belief
|
||||||
import com.unciv.models.ruleset.BeliefType
|
import com.unciv.models.ruleset.BeliefType
|
||||||
import com.unciv.models.ruleset.VictoryType
|
import com.unciv.models.ruleset.VictoryType
|
||||||
import com.unciv.models.ruleset.unique.Unique
|
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.Stats
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
@ -63,13 +61,13 @@ object ChooseBeliefsAutomation {
|
|||||||
val ruleSet = civInfo.gameInfo.ruleSet
|
val ruleSet = civInfo.gameInfo.ruleSet
|
||||||
for (unique in belief.uniqueObjects) {
|
for (unique in belief.uniqueObjects) {
|
||||||
var modifier = 1f
|
var modifier = 1f
|
||||||
if (unique.conditionals.any { it.placeholderText == "when at war" || it.placeholderText == "when not at war" })
|
if (unique.conditionals.any { it.isOfType(UniqueType.ConditionalWar) || it.isOfType(UniqueType.ConditionalNotWar) })
|
||||||
modifier *= 0.5f
|
modifier *= 0.5f
|
||||||
// Multiply by 3/10 if has an obsoleted era
|
// Multiply by 3/10 if has an obsoleted era
|
||||||
// Multiply by 2 if enough pop/followers (best implemented with conditionals, so left open for now)
|
// Multiply by 2 if enough pop/followers (best implemented with conditionals, so left open for now)
|
||||||
// If obsoleted, continue
|
// If obsoleted, continue
|
||||||
score += modifier * when (unique.placeholderText) {
|
score += modifier * when (unique.placeholderText) {
|
||||||
"[] growth []" -> unique.params[0].toFloat() / 3f
|
UniqueType.GrowthPercentBonus.placeholderText -> unique.params[0].toFloat() / 3f
|
||||||
"[]% cost of natural border growth" -> -unique.params[0].toFloat() * 2f / 10f
|
"[]% cost of natural border growth" -> -unique.params[0].toFloat() * 2f / 10f
|
||||||
"[]% attacking Strength for cities" -> unique.params[0].toFloat() / 10f // Modified by personality
|
"[]% attacking Strength for cities" -> unique.params[0].toFloat() / 10f // Modified by personality
|
||||||
"[] Units adjacent to this city heal [] HP per turn when healing" -> unique.params[1].toFloat() / 10f
|
"[] Units adjacent to this city heal [] HP per turn when healing" -> unique.params[1].toFloat() / 10f
|
||||||
@ -78,7 +76,8 @@ object ChooseBeliefsAutomation {
|
|||||||
if (city.getCenterTile().matchesFilter(unique.params[1]))
|
if (city.getCenterTile().matchesFilter(unique.params[1]))
|
||||||
unique.stats.values.sum() // Modified by personality
|
unique.stats.values.sum() // Modified by personality
|
||||||
else 0f
|
else 0f
|
||||||
UniqueType.StatsFromObject.placeholderText, "[] from every [] in cities where this religion has at least [] followers" ->
|
UniqueType.StatsFromObject.placeholderText,
|
||||||
|
"[] from every [] in cities where this religion has at least [] followers" ->
|
||||||
when {
|
when {
|
||||||
ruleSet.buildings.containsKey(unique.params[1]) -> {
|
ruleSet.buildings.containsKey(unique.params[1]) -> {
|
||||||
unique.stats.values.sum() /
|
unique.stats.values.sum() /
|
||||||
@ -93,7 +92,7 @@ object ChooseBeliefsAutomation {
|
|||||||
}
|
}
|
||||||
else -> 0f
|
else -> 0f
|
||||||
}
|
}
|
||||||
"[] in cities with [] or more population", "[] if this city has at least [] specialists" ->
|
"[] in cities with [] or more population" ->
|
||||||
unique.stats.values.sum() // Modified by personality
|
unique.stats.values.sum() // Modified by personality
|
||||||
"[] from each Trade Route" ->
|
"[] from each Trade Route" ->
|
||||||
unique.stats.values.sum() *
|
unique.stats.values.sum() *
|
||||||
@ -101,7 +100,7 @@ object ChooseBeliefsAutomation {
|
|||||||
else 1f
|
else 1f
|
||||||
"[]% [] from every follower, up to []%" ->
|
"[]% [] from every follower, up to []%" ->
|
||||||
min(unique.params[0].toFloat() * city.population.population, unique.params[2].toFloat())
|
min(unique.params[0].toFloat() * city.population.population, unique.params[2].toFloat())
|
||||||
"[] []" ->
|
UniqueType.StatsPerCity.placeholderText ->
|
||||||
if (city.matchesFilter(unique.params[1]))
|
if (city.matchesFilter(unique.params[1]))
|
||||||
unique.stats.values.sum()
|
unique.stats.values.sum()
|
||||||
else 0f
|
else 0f
|
||||||
@ -168,13 +167,13 @@ object ChooseBeliefsAutomation {
|
|||||||
unique.stats.values.sum() / 2f
|
unique.stats.values.sum() / 2f
|
||||||
"[]% Natural religion spread to []" ->
|
"[]% Natural religion spread to []" ->
|
||||||
unique.params[0].toFloat() / 4f
|
unique.params[0].toFloat() / 4f
|
||||||
"[]% Strength" ->
|
UniqueType.Strength.placeholderText ->
|
||||||
unique.params[0].toInt() / 4f
|
unique.params[0].toInt() / 4f
|
||||||
"Religion naturally spreads to cities [] tiles away" ->
|
"Religion naturally spreads to cities [] tiles away" ->
|
||||||
(10 + unique.params[0].toInt()) / goodEarlyModifier
|
(10 + unique.params[0].toInt()) / goodEarlyModifier
|
||||||
"[]% Natural religion spread []", "[]% Natural religion spread [] with []" ->
|
"[]% Natural religion spread []", "[]% Natural religion spread [] with []" ->
|
||||||
(10 + unique.params[0].toInt()) / goodEarlyModifier
|
(10 + unique.params[0].toInt()) / goodEarlyModifier
|
||||||
"[]% Spread Religion Strength" ->
|
UniqueType.SpreadReligionStrength.placeholderText ->
|
||||||
unique.params[0].toInt() / goodLateModifier
|
unique.params[0].toInt() / goodLateModifier
|
||||||
"[]% Faith cost of generating Great Prophet equivalents" ->
|
"[]% Faith cost of generating Great Prophet equivalents" ->
|
||||||
unique.params[0].toInt() / goodLateModifier / 2f
|
unique.params[0].toInt() / goodLateModifier / 2f
|
||||||
|
@ -635,7 +635,7 @@ class CityInfo {
|
|||||||
*/
|
*/
|
||||||
private fun triggerCitiesSettledNearOtherCiv() {
|
private fun triggerCitiesSettledNearOtherCiv() {
|
||||||
val citiesWithin6Tiles =
|
val citiesWithin6Tiles =
|
||||||
civInfo.gameInfo.civilizations
|
civInfo.gameInfo.civilizations.asSequence()
|
||||||
.filter { it.isMajorCiv() && it != civInfo }
|
.filter { it.isMajorCiv() && it != civInfo }
|
||||||
.flatMap { it.cities }
|
.flatMap { it.cities }
|
||||||
.filter { it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 6 }
|
.filter { it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 6 }
|
||||||
@ -652,7 +652,7 @@ class CityInfo {
|
|||||||
val tile = getCenterTile()
|
val tile = getCenterTile()
|
||||||
return when {
|
return when {
|
||||||
construction.isCivilian() -> tile.civilianUnit == null
|
construction.isCivilian() -> tile.civilianUnit == null
|
||||||
construction.movesLikeAirUnits() -> tile.airUnits.filter { !it.isTransported }.size < 6
|
construction.movesLikeAirUnits() -> tile.airUnits.count { !it.isTransported } < 6
|
||||||
else -> tile.militaryUnit == null
|
else -> tile.militaryUnit == null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -709,9 +709,7 @@ class CityInfo {
|
|||||||
// The localUniques might not be filtered when passed as a parameter, so we filter it anyway
|
// The localUniques might not be filtered when passed as a parameter, so we filter it anyway
|
||||||
// The time loss shouldn't be that large I don't think
|
// The time loss shouldn't be that large I don't think
|
||||||
return civInfo.getMatchingUniques(placeholderText, this) +
|
return civInfo.getMatchingUniques(placeholderText, this) +
|
||||||
localUniques.filter {
|
localUniques.filter { it.placeholderText == placeholderText }
|
||||||
!it.isAntiLocalEffect && it.placeholderText == placeholderText
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds matching uniques provided from both local and non-local sources.
|
// Finds matching uniques provided from both local and non-local sources.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user