perf(memory): Save stateForConditionals on tile for single-create

This commit is contained in:
yairm210 2024-11-05 08:53:09 +02:00
parent ba37be8641
commit 6cc5a87f42

View File

@ -366,16 +366,17 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
fun isRoughTerrain() = allTerrains.any { it.isRough() }
private val stateThisTile: StateForConditionals = StateForConditionals(tile = this)
/** Checks whether any of the TERRAINS of this tile has a certain unique */
fun terrainHasUnique(uniqueType: UniqueType, state: StateForConditionals = StateForConditionals(tile = this)) =
fun terrainHasUnique(uniqueType: UniqueType, state: StateForConditionals = stateThisTile) =
terrainUniqueMap.getMatchingUniques(uniqueType, state).any()
/** Get all uniques of this type that any TERRAIN on this tile has */
fun getTerrainMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = StateForConditionals(tile = this) ): Sequence<Unique> {
fun getTerrainMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = stateThisTile ): Sequence<Unique> {
return terrainUniqueMap.getMatchingUniques(uniqueType, stateForConditionals)
}
/** Get all uniques of this type that any part of this tile has: terrains, improvement, resource */
fun getMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = StateForConditionals(tile=this)): Sequence<Unique> {
fun getMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = stateThisTile): Sequence<Unique> {
var uniques = getTerrainMatchingUniques(uniqueType, stateForConditionals)
if (getUnpillagedImprovement() != null) {
val tileImprovement = getTileImprovement()
@ -549,7 +550,7 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
if (naturalWonder != null) bonus += getNaturalWonder().defenceBonus
val tileImprovement = getUnpillagedTileImprovement()
if (tileImprovement != null && includeImprovementBonus) {
for (unique in tileImprovement.getMatchingUniques(UniqueType.DefensiveBonus, StateForConditionals(tile = this)))
for (unique in tileImprovement.getMatchingUniques(UniqueType.DefensiveBonus, stateThisTile))
bonus += unique.params[0].toFloat() / 100
}
return bonus
@ -766,7 +767,7 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
return
}
for (unique in newResource.getMatchingUniques(UniqueType.ResourceAmountOnTiles, StateForConditionals(tile = this))) {
for (unique in newResource.getMatchingUniques(UniqueType.ResourceAmountOnTiles, stateThisTile)) {
if (matchesTerrainFilter(unique.params[0])) {
resourceAmount = unique.params[1].toInt()
return