mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-03 13:30:51 +07:00
perf(memory): Save stateForConditionals on tile for single-create
This commit is contained in:
parent
ba37be8641
commit
6cc5a87f42
@ -366,16 +366,17 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
|
|||||||
|
|
||||||
fun isRoughTerrain() = allTerrains.any { it.isRough() }
|
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 */
|
/** 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()
|
terrainUniqueMap.getMatchingUniques(uniqueType, state).any()
|
||||||
/** Get all uniques of this type that any TERRAIN on this tile has */
|
/** 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)
|
return terrainUniqueMap.getMatchingUniques(uniqueType, stateForConditionals)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get all uniques of this type that any part of this tile has: terrains, improvement, resource */
|
/** 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)
|
var uniques = getTerrainMatchingUniques(uniqueType, stateForConditionals)
|
||||||
if (getUnpillagedImprovement() != null) {
|
if (getUnpillagedImprovement() != null) {
|
||||||
val tileImprovement = getTileImprovement()
|
val tileImprovement = getTileImprovement()
|
||||||
@ -549,7 +550,7 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
|
|||||||
if (naturalWonder != null) bonus += getNaturalWonder().defenceBonus
|
if (naturalWonder != null) bonus += getNaturalWonder().defenceBonus
|
||||||
val tileImprovement = getUnpillagedTileImprovement()
|
val tileImprovement = getUnpillagedTileImprovement()
|
||||||
if (tileImprovement != null && includeImprovementBonus) {
|
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
|
bonus += unique.params[0].toFloat() / 100
|
||||||
}
|
}
|
||||||
return bonus
|
return bonus
|
||||||
@ -766,7 +767,7 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unique in newResource.getMatchingUniques(UniqueType.ResourceAmountOnTiles, StateForConditionals(tile = this))) {
|
for (unique in newResource.getMatchingUniques(UniqueType.ResourceAmountOnTiles, stateThisTile)) {
|
||||||
if (matchesTerrainFilter(unique.params[0])) {
|
if (matchesTerrainFilter(unique.params[0])) {
|
||||||
resourceAmount = unique.params[1].toInt()
|
resourceAmount = unique.params[1].toInt()
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user