Show which cities are missing required buildings for National Wonders. (#5718)

This commit is contained in:
will-ca
2021-11-29 05:57:36 -08:00
committed by GitHub
parent 6296f6917f
commit f86b765d38
2 changed files with 54 additions and 29 deletions

View File

@ -56,6 +56,7 @@ Requires at least one of the following resources worked near the city: =
Wonder is being built elsewhere =
National Wonder is being built elsewhere =
Requires a [buildingName] in all cities =
[buildingName] required: =
Requires a [buildingName] in this city =
Cannot be built with [buildingName] =
Consumes 1 [resource] =

View File

@ -82,9 +82,12 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
return infoList.joinToString("; ") { it.tr() }
}
private fun getUniquesStrings() = sequence {
/**
* @param filterUniques If provided, include only uniques for which this function returns true.
*/
private fun getUniquesStrings(filterUniques: ((Unique) -> Boolean)? = null) = sequence {
val tileBonusHashmap = HashMap<String, ArrayList<String>>()
for (unique in uniqueObjects) when {
for (unique in uniqueObjects) if (filterUniques == null || filterUniques(unique)) when {
unique.isOfType(UniqueType.StatsFromTiles) && unique.params[2] == "in this city" -> {
val stats = unique.params[0]
if (!tileBonusHashmap.containsKey(stats)) tileBonusHashmap[stats] = ArrayList()
@ -101,7 +104,10 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (value.size == 1) value[0] else value.joinToString { it.tr() }
))
}
private fun getUniquesStringsWithoutDisablers() = getUniquesStrings()
/**
* @param filterUniques If provided, include only uniques for which this function returns true.
*/
private fun getUniquesStringsWithoutDisablers(filterUniques: ((Unique) -> Boolean)? = null) = getUniquesStrings(filterUniques=filterUniques)
.filterNot {
it.startsWith("Hidden ") && it.endsWith(" disabled") ||
it == UniqueType.Unbuildable.text ||
@ -116,6 +122,15 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
else (name in cityInfo.civInfo.civConstructions.getFreeBuildings(cityInfo.id))
if (uniqueTo != null) lines += if (replaces == null) "Unique to [$uniqueTo]"
else "Unique to [$uniqueTo], replaces [$replaces]"
val missingunique = uniqueObjects.firstOrNull{ it.placeholderText == "Requires a [] in all cities" }
// Inefficient in theory. In practice, buildings seem to have only a small handful of uniques.
val missingcities = if (cityInfo != null && missingunique != null)
// TODO: Unify with rejection reasons?
cityInfo.civInfo.cities.filterNot {
it.isPuppet
|| it.cityConstructions.containsBuildingOrEquivalent(missingunique.params[0])
}
else listOf<CityInfo>()
if (isWonder) lines += "Wonder"
if (isNationalWonder) lines += "National Wonder"
if (!isFree) {
@ -126,13 +141,17 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
}
if (uniques.isNotEmpty()) {
if (replacementTextForUniques != "") lines += replacementTextForUniques
else lines += getUniquesStringsWithoutDisablers()
else lines += getUniquesStringsWithoutDisablers(
filterUniques=if (missingcities.isEmpty()) null
else { unique -> unique.placeholderText != "Requires a [] in all cities" }
// Filter out the "Requires a [] in all cities" unique if any cities are still missing the required building, since in that case the list of cities will be appended at the end.
)
}
if (!stats.isEmpty())
lines += stats.toString()
for ((stat, value) in getStatPercentageBonuses(cityInfo))
if (value != 0f) lines += "+${value.toInt()}% {${stat.name}}\n"
if (value != 0f) lines += "+${value.toInt()}% {${stat.name}}"
for ((greatPersonName, value) in greatPersonPoints)
lines += "+$value " + "[$greatPersonName] points".tr()
@ -146,6 +165,11 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (cityStrength != 0) lines += "{City strength} +$cityStrength"
if (cityHealth != 0) lines += "{City health} +$cityHealth"
if (maintenance != 0 && !isFree) lines += "{Maintenance cost}: $maintenance {Gold}"
if (!missingcities.isEmpty()) {
// Could be red. But IMO that should be done by enabling GDX's ColorMarkupLanguage globally instead of adding a separate label.
lines += "\n" + "[${cityInfo?.civInfo?.getEquivalentBuilding(missingunique!!.params!![0])}] required:".tr() + " " + missingcities.map{ "{${it.name}}" }.joinToString(", ")
// Can't nest square bracket placeholders inside curlies, and don't see any way to define wildcard placeholders. So run translation explicitly on base text.
}
return lines.joinToString("\n") { it.tr() }.trim()
}