Bugfix: Building 'improvement to create' no longer cached across rulesets

This commit is contained in:
yairm210 2025-08-06 09:55:52 +03:00
parent da908106de
commit 666c2056f3
2 changed files with 12 additions and 15 deletions

View File

@ -529,24 +529,20 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
}
// This can be 'by lazy' across all rulesets because it only checks building uniques
private val _hasCreatesOneImprovementUnique by lazy {
hasUnique(UniqueType.CreatesOneImprovement)
private val improvementToCreate: String? by lazy {
val unique = getMatchingUniques(UniqueType.CreatesOneImprovement).firstOrNull()
if (unique == null) null
else unique.params[0]
}
@Readonly fun hasCreateOneImprovementUnique() = _hasCreatesOneImprovementUnique
@Cache private var _getImprovementToCreate: TileImprovement? = null
@Readonly fun hasCreateOneImprovementUnique() = improvementToCreate != null
@Readonly
// This CANNOT be cached across rulesets, because the improvement itself is retrieved. Currently a bug!
// TODO: Clean up - retrieve only the *name* of the improvement
// Only the name can be cached across rulesets.
// The improvement itself CANNOT be cached because it's ruleset-dependent.
private fun getImprovementToCreate(ruleset: Ruleset): TileImprovement? {
if (!hasCreateOneImprovementUnique()) return null
if (_getImprovementToCreate == null) {
val improvementUnique = getMatchingUniques(UniqueType.CreatesOneImprovement)
.firstOrNull() ?: return null
_getImprovementToCreate = ruleset.tileImprovements[improvementUnique.params[0]]
}
return _getImprovementToCreate
if (improvementToCreate == null) return null
return ruleset.tileImprovements[improvementToCreate]
}
@Readonly

View File

@ -360,7 +360,8 @@ enum class UniqueType(
CreatesOneImprovement("Creates a [improvementName] improvement on a specific tile", UniqueTarget.Building,
docDescription = "When choosing to construct this building, the player must select a tile where the improvement can be built." +
" Upon building completion, the tile will gain this improvement."),
" Upon building completion, the tile will gain this improvement." +
" Limited to one per building."),
//endregion
///////////////////////////////////////// region 04 UNIT UNIQUES /////////////////////////////////////////