Typed "Unbuildable"

This commit is contained in:
yairm210 2021-10-17 23:42:09 +03:00
parent 8b2bb8e59b
commit d4205cb405
6 changed files with 16 additions and 9 deletions

View File

@ -205,7 +205,7 @@ class CityConstructions {
val turnsToConstruction = turnsToConstruction(constructionName, useStoredProduction) val turnsToConstruction = turnsToConstruction(constructionName, useStoredProduction)
val currentProgress = if (useStoredProduction) getWorkDone(constructionName) else 0 val currentProgress = if (useStoredProduction) getWorkDone(constructionName) else 0
val lines = ArrayList<String>() val lines = ArrayList<String>()
val buildable = construction.uniques.none{ it == "Unbuildable" } val buildable = construction.uniqueObjects.none{ it.isOfType(UniqueType.Unbuildable) }
if (buildable) if (buildable)
lines += (if (currentProgress == 0) "" else "$currentProgress/") + lines += (if (currentProgress == 0) "" else "$currentProgress/") +
"$cost${Fonts.production} $turnsToConstruction${Fonts.turn}" "$cost${Fonts.production} $turnsToConstruction${Fonts.turn}"

View File

@ -2,6 +2,7 @@ package com.unciv.logic.city
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.ruleset.IHasUniques import com.unciv.models.ruleset.IHasUniques
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.stats.INamed import com.unciv.models.stats.INamed
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.ui.utils.Fonts import com.unciv.ui.utils.Fonts
@ -27,7 +28,7 @@ interface INonPerpetualConstruction : IConstruction, INamed, IHasUniques {
fun canBePurchasedWithStat(cityInfo: CityInfo?, stat: Stat): Boolean { fun canBePurchasedWithStat(cityInfo: CityInfo?, stat: Stat): Boolean {
if (stat in listOf(Stat.Production, Stat.Happiness)) return false if (stat in listOf(Stat.Production, Stat.Happiness)) return false
if ("Cannot be purchased" in uniques) return false if ("Cannot be purchased" in uniques) return false
if (stat == Stat.Gold) return !uniques.contains("Unbuildable") if (stat == Stat.Gold) return !hasUnique(UniqueType.Unbuildable)
// Can be purchased with [Stat] [cityFilter] // Can be purchased with [Stat] [cityFilter]
if (getMatchingUniques("Can be purchased with [] []") if (getMatchingUniques("Can be purchased with [] []")
.any { it.params[0] == stat.name && (cityInfo != null && cityInfo.matchesFilter(it.params[1])) } .any { it.params[0] == stat.name && (cityInfo != null && cityInfo.matchesFilter(it.params[1])) }

View File

@ -107,7 +107,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
private fun getUniquesStringsWithoutDisablers() = getUniquesStrings() private fun getUniquesStringsWithoutDisablers() = getUniquesStrings()
.filterNot { .filterNot {
it.startsWith("Hidden ") && it.endsWith(" disabled") || it.startsWith("Hidden ") && it.endsWith(" disabled") ||
it == "Unbuildable" || it == UniqueType.Unbuildable.text ||
it == Constants.hideFromCivilopediaUnique it == Constants.hideFromCivilopediaUnique
} }
@ -403,7 +403,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
rejectionReasons.add(RejectionReason.AlreadyBuilt) rejectionReasons.add(RejectionReason.AlreadyBuilt)
// for buildings that are created as side effects of other things, and not directly built, // for buildings that are created as side effects of other things, and not directly built,
// or for buildings that can only be bought // or for buildings that can only be bought
if (uniques.contains("Unbuildable")) if (hasUnique(UniqueType.Unbuildable))
rejectionReasons.add(RejectionReason.Unbuildable) rejectionReasons.add(RejectionReason.Unbuildable)
for (unique in uniqueObjects) { for (unique in uniqueObjects) {
@ -467,7 +467,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (civInfo.tech.isResearched(unique.params[0])) if (civInfo.tech.isResearched(unique.params[0]))
rejectionReasons.add(RejectionReason.Obsoleted.apply { errorMessage = unique.text }) rejectionReasons.add(RejectionReason.Obsoleted.apply { errorMessage = unique.text })
"Hidden when religion is disabled" -> UniqueType.HiddenWithoutReligion.text ->
if (!civInfo.gameInfo.isReligionEnabled()) if (!civInfo.gameInfo.isReligionEnabled())
rejectionReasons.add(RejectionReason.DisabledBySetting) rejectionReasons.add(RejectionReason.DisabledBySetting)
} }

View File

@ -256,7 +256,7 @@ class Ruleset {
* */ * */
fun updateBuildingCosts() { fun updateBuildingCosts() {
for (building in buildings.values) { for (building in buildings.values) {
if (building.cost == 0 && !building.uniques.contains("Unbuildable")) { if (building.cost == 0 && !building.hasUnique(UniqueType.Unbuildable)) {
val column = technologies[building.requiredTech]?.column val column = technologies[building.requiredTech]?.column
?: throw UncivShowableException("Building (${building.name}) is buildable and therefore must either have an explicit cost or reference an existing tech") ?: throw UncivShowableException("Building (${building.name}) is buildable and therefore must either have an explicit cost or reference an existing tech")
building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost
@ -393,7 +393,7 @@ class Ruleset {
} }
for (building in buildings.values) { for (building in buildings.values) {
if (building.requiredTech == null && building.cost == 0 && !building.uniques.contains("Unbuildable")) if (building.requiredTech == null && building.cost == 0 && !building.hasUnique(UniqueType.Unbuildable))
lines += "${building.name} is buildable and therefore must either have an explicit cost or reference an existing tech!" lines += "${building.name} is buildable and therefore must either have an explicit cost or reference an existing tech!"
checkUniques(building, lines, UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant) checkUniques(building, lines, UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant)

View File

@ -138,6 +138,12 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) {
MayanGainGreatPerson("Receive a free Great Person at the end of every [comment] (every 394 years), after researching [tech]. Each bonus person can only be chosen once.", UniqueTarget.Nation), MayanGainGreatPerson("Receive a free Great Person at the end of every [comment] (every 394 years), after researching [tech]. Each bonus person can only be chosen once.", UniqueTarget.Nation),
MayanCalendarDisplay("Once The Long Count activates, the year on the world screen displays as the traditional Mayan Long Count.", UniqueTarget.Nation), MayanCalendarDisplay("Once The Long Count activates, the year on the world screen displays as the traditional Mayan Long Count.", UniqueTarget.Nation),
///////////////////////////////////////// BUILDING UNIQUES /////////////////////////////////////////
Unbuildable("Unbuildable", UniqueTarget.Building),
///////////////////////////////////////// UNIT UNIQUES ///////////////////////////////////////// ///////////////////////////////////////// UNIT UNIQUES /////////////////////////////////////////
FoundCity("Founds a new city", UniqueTarget.Unit), FoundCity("Founds a new city", UniqueTarget.Unit),

View File

@ -90,7 +90,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
if (replacementTextForUniques != "") lines += replacementTextForUniques if (replacementTextForUniques != "") lines += replacementTextForUniques
else for (unique in uniques.filterNot { else for (unique in uniques.filterNot {
it.startsWith("Hidden ") && it.endsWith(" disabled") || it == "Unbuildable" it.startsWith("Hidden ") && it.endsWith(" disabled") || it == UniqueType.Unbuildable.text
}) })
lines += unique.tr() lines += unique.tr()
@ -382,7 +382,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
val rejectionReasons = RejectionReasons() val rejectionReasons = RejectionReasons()
val ruleSet = civInfo.gameInfo.ruleSet val ruleSet = civInfo.gameInfo.ruleSet
if (uniques.contains("Unbuildable")) if (hasUnique(UniqueType.Unbuildable))
rejectionReasons.add(RejectionReason.Unbuildable) rejectionReasons.add(RejectionReason.Unbuildable)
if (requiredTech != null && !civInfo.tech.isResearched(requiredTech!!)) if (requiredTech != null && !civInfo.tech.isResearched(requiredTech!!))