mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-28 08:30:31 +07:00
getMatchingUnique for UniqueType - will allow us to convert most of the uniques painlessly
This commit is contained in:
parent
34cb48aa31
commit
fa939e15d9
@ -730,6 +730,13 @@ class CityInfo {
|
||||
// Note that we don't query religion here, as those only have local effects (for now at least)
|
||||
}
|
||||
|
||||
|
||||
fun getMatchingUniquesWithNonLocalEffectsByEnum(uniqueType: UniqueType): Sequence<Unique> {
|
||||
return cityConstructions.builtBuildingUniqueMap.getUniques(uniqueType)
|
||||
.filter { it.params.none { param -> param == "in this city" } }
|
||||
// Note that we don't query religion here, as those only have local effects (for now at least)
|
||||
}
|
||||
|
||||
// Get all uniques that don't apply to only this city
|
||||
fun getAllUniquesWithNonLocalEffects(): Sequence<Unique> {
|
||||
return cityConstructions.builtBuildingUniqueMap.getAllUniques()
|
||||
|
@ -306,6 +306,27 @@ class CivilizationInfo {
|
||||
|
||||
fun hasUnique(unique: String) = getMatchingUniques(unique).any()
|
||||
|
||||
/** Destined to replace getMatchingUniques, gradually, as we fill the enum */
|
||||
fun getMatchingUniquesByEnum(uniqueType: UniqueType, cityToIgnore: CityInfo?=null): Sequence<Unique> {
|
||||
val ruleset = gameInfo.ruleSet
|
||||
return nation.uniqueObjects.asSequence().filter { it.matches(uniqueType, ruleset) } +
|
||||
cities.asSequence().filter { it != cityToIgnore }.flatMap { city ->
|
||||
city.getMatchingUniquesWithNonLocalEffectsByEnum(uniqueType)
|
||||
} +
|
||||
policies.policyUniques.getUniques(uniqueType) +
|
||||
tech.techUniques.getUniques(uniqueType) +
|
||||
temporaryUniques
|
||||
.asSequence().map { it.first }
|
||||
.filter { it.matches(uniqueType, ruleset) } +
|
||||
getEra().getMatchingUniques(uniqueType) +
|
||||
(
|
||||
if (religionManager.religion != null)
|
||||
religionManager.religion!!.getFounderUniques()
|
||||
.filter { it.isOfType(uniqueType) }
|
||||
else sequenceOf()
|
||||
)
|
||||
}
|
||||
|
||||
// Does not return local uniques, only global ones.
|
||||
fun getMatchingUniques(uniqueTemplate: String, cityToIgnore: CityInfo? = null): Sequence<Unique> {
|
||||
return nation.uniqueObjects.asSequence().filter { it.placeholderText == uniqueTemplate } +
|
||||
|
@ -8,6 +8,8 @@ interface IHasUniques {
|
||||
val uniqueObjects: List<Unique>
|
||||
|
||||
fun getMatchingUniques(uniqueTemplate: String) = uniqueObjects.asSequence().filter { it.placeholderText == uniqueTemplate }
|
||||
fun getMatchingUniques(uniqueType: UniqueType) = uniqueObjects.asSequence().filter { it.isOfType(uniqueType) }
|
||||
|
||||
fun hasUnique(uniqueTemplate: String) = uniqueObjects.any { it.placeholderText == uniqueTemplate }
|
||||
fun hasUnique(uniqueType: UniqueType) = uniqueObjects.any { it.isOfType(uniqueType) }
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ enum class UniqueParameterType(val parameterName:String) {
|
||||
Number("amount") {
|
||||
override fun getErrorType(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueComplianceErrorSeverity? {
|
||||
return if (parameterText.toIntOrNull() != null) UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
||||
return if (parameterText.toIntOrNull() == null) UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
||||
else null
|
||||
}
|
||||
},
|
||||
@ -60,7 +60,8 @@ class UniqueComplianceError(
|
||||
|
||||
enum class UniqueType(val text:String) {
|
||||
|
||||
ConsumesResources("Consumes [amount] [resource]");
|
||||
ConsumesResources("Consumes [amount] [resource]"),
|
||||
FreeUnits("[amount] units cost no maintenance");
|
||||
|
||||
/** For uniques that have "special" parameters that can accept multiple types, we can override them manually
|
||||
* For 95% of cases, auto-matching is fine. */
|
||||
@ -132,6 +133,7 @@ class Unique(val text:String) {
|
||||
&& uniqueType.getComplianceErrors(this, ruleset).isEmpty()
|
||||
}
|
||||
|
||||
|
||||
class UniqueMap:HashMap<String, ArrayList<Unique>>() {
|
||||
fun addUnique(unique: Unique) {
|
||||
if (!containsKey(unique.placeholderText)) this[unique.placeholderText] = ArrayList()
|
||||
@ -144,5 +146,7 @@ class UniqueMap:HashMap<String, ArrayList<Unique>>() {
|
||||
else return result.asSequence()
|
||||
}
|
||||
|
||||
fun getUniques(uniqueType: UniqueType) = getUniques(uniqueType.placeholderText)
|
||||
|
||||
fun getAllUniques() = this.asSequence().flatMap { it.value.asSequence() }
|
||||
}
|
Loading…
Reference in New Issue
Block a user