Replace calls to clone with calls to cloneStats when that is clearer (#5656)

This commit is contained in:
Xander Lenstra 2021-11-09 10:59:24 +01:00 committed by GitHub
parent 003f2434c1
commit cda34bf23f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 18 deletions

View File

@ -167,7 +167,7 @@ class CityStats(val cityInfo: CityInfo) {
fun getStatsOfSpecialist(specialistName: String): Stats { fun getStatsOfSpecialist(specialistName: String): Stats {
val specialist = cityInfo.getRuleset().specialists[specialistName] val specialist = cityInfo.getRuleset().specialists[specialistName]
?: return Stats() ?: return Stats()
val stats = specialist.clone() val stats = specialist.cloneStats()
for (unique in cityInfo.getMatchingUniques(UniqueType.StatsFromSpecialist)) for (unique in cityInfo.getMatchingUniques(UniqueType.StatsFromSpecialist))
if (cityInfo.matchesFilter(unique.params[1])) if (cityInfo.matchesFilter(unique.params[1]))
stats.add(unique.stats) stats.add(unique.stats)

View File

@ -240,19 +240,19 @@ open class TileInfo {
fun getTileStats(observingCiv: CivilizationInfo): Stats = getTileStats(getCity(), observingCiv) fun getTileStats(observingCiv: CivilizationInfo): Stats = getTileStats(getCity(), observingCiv)
fun getTileStats(city: CityInfo?, observingCiv: CivilizationInfo): Stats { fun getTileStats(city: CityInfo?, observingCiv: CivilizationInfo): Stats {
var stats = getBaseTerrain().clone() var stats = getBaseTerrain().cloneStats()
for (terrainFeatureBase in getTerrainFeatures()) { for (terrainFeatureBase in getTerrainFeatures()) {
when { when {
terrainFeatureBase.hasUnique(UniqueType.NullifyYields) -> terrainFeatureBase.hasUnique(UniqueType.NullifyYields) ->
return terrainFeatureBase.clone() return terrainFeatureBase.cloneStats()
terrainFeatureBase.overrideStats -> stats = terrainFeatureBase.clone() terrainFeatureBase.overrideStats -> stats = terrainFeatureBase.cloneStats()
else -> stats.add(terrainFeatureBase) else -> stats.add(terrainFeatureBase)
} }
} }
if (naturalWonder != null) { if (naturalWonder != null) {
val wonderStats = getNaturalWonder().clone() val wonderStats = getNaturalWonder().cloneStats()
// Spain doubles tile yield // Spain doubles tile yield
if (city != null && city.civInfo.hasUnique("Tile yields from Natural Wonders doubled")) { if (city != null && city.civInfo.hasUnique("Tile yields from Natural Wonders doubled")) {
@ -335,11 +335,11 @@ open class TileInfo {
} }
private fun getTileStartYield(isCenter: Boolean): Float { private fun getTileStartYield(isCenter: Boolean): Float {
var stats = getBaseTerrain().clone() var stats = getBaseTerrain().cloneStats()
for (terrainFeatureBase in getTerrainFeatures()) { for (terrainFeatureBase in getTerrainFeatures()) {
if (terrainFeatureBase.overrideStats) if (terrainFeatureBase.overrideStats)
stats = terrainFeatureBase.clone() stats = terrainFeatureBase.cloneStats()
else else
stats.add(terrainFeatureBase) stats.add(terrainFeatureBase)
} }

View File

@ -151,7 +151,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
fun getStats(city: CityInfo?): Stats { fun getStats(city: CityInfo?): Stats {
// Calls the clone function of the NamedStats this class is derived from, not a clone function of this class // Calls the clone function of the NamedStats this class is derived from, not a clone function of this class
val stats = this.clone() val stats = cloneStats()
if (city == null) return stats if (city == null) return stats
val civInfo = city.civInfo val civInfo = city.civInfo
@ -246,7 +246,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
} }
} }
val stats = this.clone() val stats = cloneStats()
val percentStats = getStatPercentageBonuses(null) val percentStats = getStatPercentageBonuses(null)
val specialists = newSpecialists() val specialists = newSpecialists()
if (uniques.isNotEmpty() || !stats.isEmpty() || !percentStats.isEmpty() || this.greatPersonPoints.isNotEmpty() || specialists.isNotEmpty()) if (uniques.isNotEmpty() || !stats.isEmpty() || !percentStats.isEmpty() || this.greatPersonPoints.isNotEmpty() || specialists.isNotEmpty())

View File

@ -276,10 +276,10 @@ class Nation : RulesetObject() {
private fun addUniqueImprovementsText(textList: ArrayList<FormattedLine>, ruleset: Ruleset) { private fun addUniqueImprovementsText(textList: ArrayList<FormattedLine>, ruleset: Ruleset) {
for (improvement in ruleset.tileImprovements.values) { for (improvement in ruleset.tileImprovements.values) {
if (improvement.uniqueTo != name ) continue if (improvement.uniqueTo != name) continue
textList += FormattedLine(improvement.name, link = "Improvement/${improvement.name}") textList += FormattedLine(improvement.name, link = "Improvement/${improvement.name}")
textList += FormattedLine(improvement.clone().toString(), indent = 1) // = (improvement as Stats).toString minus import plus copy overhead textList += FormattedLine(improvement.cloneStats().toString(), indent = 1) // = (improvement as Stats).toString minus import plus copy overhead
if (improvement.terrainsCanBeBuiltOn.isNotEmpty()) { if (improvement.terrainsCanBeBuiltOn.isNotEmpty()) {
improvement.terrainsCanBeBuiltOn.withIndex().forEach { improvement.terrainsCanBeBuiltOn.withIndex().forEach {
textList += FormattedLine(if (it.index == 0) "{Can be built on} {${it.value}}" else "or [${it.value}]", textList += FormattedLine(if (it.index == 0) "{Can be built on} {${it.value}}" else "or [${it.value}]",

View File

@ -72,7 +72,7 @@ class Terrain : RulesetStatsObject() {
textList += FormattedLine("Natural Wonder", header=3, color="#3A0") textList += FormattedLine("Natural Wonder", header=3, color="#3A0")
} }
val stats = this.clone() val stats = cloneStats()
if (!stats.isEmpty()) { if (!stats.isEmpty()) {
textList += FormattedLine() textList += FormattedLine()
textList += FormattedLine("$stats") textList += FormattedLine("$stats")

View File

@ -37,7 +37,7 @@ class TileImprovement : RulesetStatsObject() {
fun getDescription(ruleset: Ruleset): String { fun getDescription(ruleset: Ruleset): String {
val lines = ArrayList<String>() val lines = ArrayList<String>()
val statsDesc = this.clone().toString() val statsDesc = cloneStats().toString()
if (statsDesc.isNotEmpty()) lines += statsDesc if (statsDesc.isNotEmpty()) lines += statsDesc
if (!terrainsCanBeBuiltOn.isEmpty()) { if (!terrainsCanBeBuiltOn.isEmpty()) {
val terrainsCanBeBuiltOnString: ArrayList<String> = arrayListOf() val terrainsCanBeBuiltOnString: ArrayList<String> = arrayListOf()
@ -96,7 +96,7 @@ class TileImprovement : RulesetStatsObject() {
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> { override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
val textList = ArrayList<FormattedLine>() val textList = ArrayList<FormattedLine>()
val statsDesc = this.clone().toString() val statsDesc = cloneStats().toString()
if (statsDesc.isNotEmpty()) textList += FormattedLine(statsDesc) if (statsDesc.isNotEmpty()) textList += FormattedLine(statsDesc)
if (uniqueTo!=null) { if (uniqueTo!=null) {

View File

@ -28,7 +28,7 @@ class TileResource : RulesetStatsObject() {
textList += FormattedLine("${resourceType.name} resource", header = 4, color = resourceType.color) textList += FormattedLine("${resourceType.name} resource", header = 4, color = resourceType.color)
textList += FormattedLine() textList += FormattedLine()
textList += FormattedLine(this.clone().toString()) textList += FormattedLine(cloneStats().toString())
if (terrainsCanBeFoundOn.isNotEmpty()) { if (terrainsCanBeFoundOn.isNotEmpty()) {
textList += FormattedLine() textList += FormattedLine()

View File

@ -143,7 +143,7 @@ class MapEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraS
} }
} }
val improvementIcon = getHex(ImageGetter.getImprovementIcon(improvement.name, 40f)) val improvementIcon = getHex(ImageGetter.getImprovementIcon(improvement.name, 40f))
setCurrentHex(improvementIcon, improvement.name.tr() + "\n" + improvement.clone().toString()) setCurrentHex(improvementIcon, improvement.name.tr() + "\n" + improvement.cloneStats().toString())
} }
improvementsTable.add(improvementImage).row() improvementsTable.add(improvementImage).row()
} }
@ -309,7 +309,7 @@ class MapEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraS
tileInfo.resource = resource.name tileInfo.resource = resource.name
tileInfo.setTerrainTransients() tileInfo.setTerrainTransients()
setCurrentHex(tileInfo, resource.name.tr() + "\n" + resource.clone().toString()) setCurrentHex(tileInfo, resource.name.tr() + "\n" + resource.cloneStats().toString())
} }
resources.add(resourceHex) resources.add(resourceHex)
} }
@ -340,7 +340,7 @@ class MapEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraS
else -> it.baseTerrain = terrain.name else -> it.baseTerrain = terrain.name
} }
} }
setCurrentHex(tileInfo, terrain.name.tr() + "\n" + terrain.clone().toString()) setCurrentHex(tileInfo, terrain.name.tr() + "\n" + terrain.cloneStats().toString())
} }
if (terrain.type == TerrainType.TerrainFeature) if (terrain.type == TerrainType.TerrainFeature)