From 1b397f0583c03f3da2ff43e5a0bbf298762c996f Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Tue, 20 Jul 2021 08:26:06 +0200 Subject: [PATCH] Unify all those (isWonder || isNationalWonder) cases (#4574) --- .../logic/automation/ConstructionAutomation.kt | 4 ++-- core/src/com/unciv/logic/city/CityConstructions.kt | 5 ++--- core/src/com/unciv/logic/city/CityStats.kt | 2 +- core/src/com/unciv/models/ruleset/Building.kt | 13 +++++++------ core/src/com/unciv/models/ruleset/Ruleset.kt | 2 +- .../src/com/unciv/models/ruleset/tech/Technology.kt | 4 ++-- core/src/com/unciv/ui/cityscreen/CityInfoTable.kt | 2 +- .../com/unciv/ui/civilopedia/CivilopediaScreen.kt | 4 ++-- .../com/unciv/ui/worldscreen/unit/UnitActions.kt | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt index b50d04858a..618590b553 100644 --- a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt @@ -21,9 +21,9 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ val civInfo = cityInfo.civInfo val buildableNotWonders = cityConstructions.getBuildableBuildings() - .filterNot { it.isWonder || it.isNationalWonder } + .filterNot { it.isAnyWonder() } private val buildableWonders = cityConstructions.getBuildableBuildings() - .filter { it.isWonder || it.isNationalWonder } + .filter { it.isAnyWonder() } val civUnits = civInfo.getCivUnits() val militaryUnits = civUnits.count { !it.type.isCivilian() } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index d26ce90b21..d561d8252c 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -70,7 +70,7 @@ class CityConstructions { .asSequence().filter { it.isBuildable(this) } fun getBasicCultureBuildings() = cityInfo.getRuleset().buildings.values - .asSequence().filter { it.culture > 0f && !it.isWonder && !it.isNationalWonder && it.replaces == null } + .asSequence().filter { it.culture > 0f && !it.isAnyWonder() && it.replaces == null } /** * @return [Stats] provided by all built buildings in city plus the bonus from Library @@ -179,8 +179,7 @@ class CityConstructions { val currentConstructionSnapshot = currentConstructionFromQueue if (currentConstructionSnapshot.isEmpty()) return FormattedLine() val category = when { - ruleset.buildings[currentConstructionSnapshot] - ?.let{ it.isWonder || it.isNationalWonder } == true -> + ruleset.buildings[currentConstructionSnapshot]?.isAnyWonder() == true -> CivilopediaCategories.Wonder.name currentConstructionSnapshot in ruleset.buildings -> CivilopediaCategories.Building.name diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index 375045cbda..1a006e71e2 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -306,7 +306,7 @@ class CityStats { // Since this is sometimes run from a different thread (getConstructionButtonDTOs), // this helps mitigate concurrency problems. - if (currentConstruction is Building && !currentConstruction.isWonder && !currentConstruction.isNationalWonder) + if (currentConstruction is Building && !currentConstruction.isAnyWonder()) for (unique in uniques.filter { it.placeholderText == "+[]% Production when constructing [] buildings" }) { val stat = Stat.valueOf(unique.params[1]) if (currentConstruction.isStatRelated(stat)) diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index ba216cd881..12c806e698 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -48,6 +48,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { private var hurryCostModifier = 0 var isWonder = false var isNationalWonder = false + fun isAnyWonder() = isWonder || isNationalWonder var requiredBuilding: String? = null var requiredBuildingInAllCities: String? = null @@ -195,7 +196,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { return stats } - fun makeLink() = if (isWonder || isNationalWonder) "Wonder/$name" else "Building/$name" + fun makeLink() = if (isAnyWonder()) "Wonder/$name" else "Building/$name" override fun getCivilopediaTextHeader() = FormattedLine(name, header=2, icon=makeLink()) override fun hasCivilopediaTextLines() = true override fun replacesCivilopediaDescription() = true @@ -204,7 +205,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { val textList = ArrayList() - if (isWonder || isNationalWonder) { + if (isAnyWonder()) { textList += FormattedLine( if (isWonder) "Wonder" else "National Wonder", color="#CA4", header=3 ) } @@ -321,7 +322,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { override fun canBePurchased(): Boolean { - return !isWonder && !isNationalWonder && "Cannot be purchased" !in uniques + return !isAnyWonder() && "Cannot be purchased" !in uniques } @@ -580,8 +581,8 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { return when (filter) { "All" -> true name -> true - "Building", "Buildings" -> !(isWonder || isNationalWonder) - "Wonder", "Wonders" -> isWonder || isNationalWonder + "Building", "Buildings" -> !isAnyWonder() + "Wonder", "Wonders" -> isAnyWonder() replaces -> true else -> { if (uniques.contains(filter)) return true @@ -609,7 +610,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { return ruleset.tileImprovements[improvementUnique.params[0]] } - fun isSellable() = !isWonder && !isNationalWonder && !uniques.contains("Unsellable") + fun isSellable() = !isAnyWonder() && !uniques.contains("Unsellable") override fun getResourceRequirements(): HashMap { val resourceRequirements = HashMap() diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index 2cafa3c4e1..b182355c49 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -221,7 +221,7 @@ class Ruleset { if (building.cost == 0) { val column = technologies[building.requiredTech]?.column ?: throw UncivShowableException("Building (${building.name}) must either have an explicit cost or reference an existing tech") - building.cost = if (building.isWonder || building.isNationalWonder) column.wonderCost else column.buildingCost + building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost } } } diff --git a/core/src/com/unciv/models/ruleset/tech/Technology.kt b/core/src/com/unciv/models/ruleset/tech/Technology.kt index d0b1826851..3c8d2f0311 100644 --- a/core/src/com/unciv/models/ruleset/tech/Technology.kt +++ b/core/src/com/unciv/models/ruleset/tech/Technology.kt @@ -45,7 +45,7 @@ class Technology { val enabledBuildings = getEnabledBuildings(viewingCiv) val regularBuildings = enabledBuildings.filter { - !it.isWonder && !it.isNationalWonder + !it.isAnyWonder() && "Will not be displayed in Civilopedia" !in it.uniques && !(!viewingCiv.gameInfo.hasReligionEnabled() && it.uniques.contains("Hidden when religion is disabled")) } @@ -56,7 +56,7 @@ class Technology { } val wonders = enabledBuildings.filter { - (it.isWonder || it.isNationalWonder) + it.isAnyWonder() && "Will not be displayed in Civilopedia" !in it.uniques } if (wonders.isNotEmpty()) { diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index d4709a4cc6..4439f0b471 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -103,7 +103,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS for (building in cityInfo.cityConstructions.getBuiltBuildings()) { when { - building.isWonder || building.isNationalWonder -> wonders.add(building) + building.isAnyWonder() -> wonders.add(building) !building.newSpecialists().isEmpty() -> specialistBuildings.add(building) else -> otherBuildings.add(building) } diff --git a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt index 0fa7539f6a..199616cdba 100644 --- a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt @@ -174,7 +174,7 @@ class CivilopediaScreen( .filter { "Will not be displayed in Civilopedia" !in it.uniques && !(hideReligionItems && "Hidden when religion is disabled" in it.uniques) && !(noCulturalVictory && "Hidden when cultural victory is disabled" in it.uniques) - && !(it.isWonder || it.isNationalWonder) } + && !it.isAnyWonder() } .map { CivilopediaEntry( it.name, @@ -187,7 +187,7 @@ class CivilopediaScreen( .filter { "Will not be displayed in Civilopedia" !in it.uniques && !(hideReligionItems && "Hidden when religion is disabled" in it.uniques) && !(noCulturalVictory && "Hidden when cultural victory is disabled" in it.uniques) - && (it.isWonder || it.isNationalWonder) } + && it.isAnyWonder() } .map { CivilopediaEntry( it.name, diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 9368767d62..a5a278642a 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -377,7 +377,7 @@ object UnitActions { else { val currentConstruction = tile.getCity()!!.cityConstructions.getCurrentConstruction() if (currentConstruction !is Building) false - else currentConstruction.isWonder || currentConstruction.isNationalWonder + else currentConstruction.isAnyWonder() } actionList += UnitAction(UnitActionType.HurryWonder, uncivSound = UncivSound.Chimes,