mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
More reorg, first unique with cityFilter
This commit is contained in:
parent
55a77096c1
commit
38231bf937
@ -218,8 +218,7 @@ class CityStats(val cityInfo: CityInfo) {
|
|||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
|
|
||||||
for (unique in uniques.toList()) { // Should help mitigate getConstructionButtonDTOs concurrency problems.
|
for (unique in uniques.toList()) { // Should help mitigate getConstructionButtonDTOs concurrency problems.
|
||||||
// "[stats] [cityFilter]"
|
if (unique.isOfType(UniqueType.StatsPerCity) && cityInfo.matchesFilter(unique.params[1]))
|
||||||
if (unique.placeholderText == "[] []" && cityInfo.matchesFilter(unique.params[1]))
|
|
||||||
stats.add(unique.stats)
|
stats.add(unique.stats)
|
||||||
|
|
||||||
// "[stats] per [amount] population [cityFilter]"
|
// "[stats] per [amount] population [cityFilter]"
|
||||||
|
@ -5,68 +5,6 @@ import com.unciv.models.translations.getPlaceholderParameters
|
|||||||
import com.unciv.models.translations.getPlaceholderText
|
import com.unciv.models.translations.getPlaceholderText
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum class UniqueType(val text:String, val replacedBy: UniqueType? = null) {
|
|
||||||
|
|
||||||
ConsumesResources("Consumes [amount] [resource]"),
|
|
||||||
FreeUnits("[amount] units cost no maintenance"),
|
|
||||||
UnitMaintenanceDiscount("[amount]% maintenance costs for [mapUnitFilter] units"),
|
|
||||||
@Deprecated("As of 3.16.16")
|
|
||||||
DecreasedUnitMaintenanceCostsByFilter("-[amount]% [mapUnitFilter] unit maintenance costs", UnitMaintenanceDiscount),
|
|
||||||
@Deprecated("As of 3.16.16")
|
|
||||||
DecreasedUnitMaintenanceCostsGlobally("-[amount]% unit upkeep costs", UnitMaintenanceDiscount),
|
|
||||||
StatBonusForNumberOfSpecialists("[stats] if this city has at least [amount] specialists")
|
|
||||||
;
|
|
||||||
|
|
||||||
/** For uniques that have "special" parameters that can accept multiple types, we can override them manually
|
|
||||||
* For 95% of cases, auto-matching is fine. */
|
|
||||||
private val parameterTypeMap = ArrayList<List<UniqueParameterType>>()
|
|
||||||
|
|
||||||
init {
|
|
||||||
for (placeholder in text.getPlaceholderParameters()) {
|
|
||||||
val matchingParameterType =
|
|
||||||
UniqueParameterType.values().firstOrNull { it.parameterName == placeholder }
|
|
||||||
?: UniqueParameterType.Unknown
|
|
||||||
parameterTypeMap.add(listOf(matchingParameterType))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val placeholderText = text.getPlaceholderText()
|
|
||||||
|
|
||||||
/** Ordinal determines severity - ordered from most severe at 0 */
|
|
||||||
enum class UniqueComplianceErrorSeverity {
|
|
||||||
|
|
||||||
/** This is a problem like "numbers don't parse", "stat isn't stat", "city filter not applicable" */
|
|
||||||
RulesetInvariant,
|
|
||||||
|
|
||||||
/** This is a problem like "unit/resource/tech name doesn't exist in ruleset" - definite bug */
|
|
||||||
RulesetSpecific,
|
|
||||||
|
|
||||||
/** This is for filters that can also potentially accept free text, like UnitFilter and TileFilter */
|
|
||||||
WarningOnly
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Maps uncompliant parameters to their required types */
|
|
||||||
fun getComplianceErrors(
|
|
||||||
unique: Unique,
|
|
||||||
ruleset: Ruleset
|
|
||||||
): List<UniqueComplianceError> {
|
|
||||||
val errorList = ArrayList<UniqueComplianceError>()
|
|
||||||
for ((index, param) in unique.params.withIndex()) {
|
|
||||||
val acceptableParamTypes = parameterTypeMap[index]
|
|
||||||
val errorTypesForAcceptableParameters =
|
|
||||||
acceptableParamTypes.map { it.getErrorSeverity(param, ruleset) }
|
|
||||||
if (errorTypesForAcceptableParameters.any { it == null }) continue // This matches one of the types!
|
|
||||||
val leastSevereWarning =
|
|
||||||
errorTypesForAcceptableParameters.maxByOrNull { it!!.ordinal }!!
|
|
||||||
errorList += UniqueComplianceError(param, acceptableParamTypes, leastSevereWarning)
|
|
||||||
}
|
|
||||||
return errorList
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Unique(val text:String) {
|
class Unique(val text:String) {
|
||||||
val placeholderText = text.getPlaceholderText()
|
val placeholderText = text.getPlaceholderText()
|
||||||
val params = text.getPlaceholderParameters()
|
val params = text.getPlaceholderParameters()
|
||||||
|
64
core/src/com/unciv/models/ruleset/UniqueType.kt
Normal file
64
core/src/com/unciv/models/ruleset/UniqueType.kt
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package com.unciv.models.ruleset
|
||||||
|
|
||||||
|
import com.unciv.models.translations.getPlaceholderParameters
|
||||||
|
import com.unciv.models.translations.getPlaceholderText
|
||||||
|
|
||||||
|
enum class UniqueType(val text:String, val replacedBy: UniqueType? = null) {
|
||||||
|
|
||||||
|
ConsumesResources("Consumes [amount] [resource]"),
|
||||||
|
FreeUnits("[amount] units cost no maintenance"),
|
||||||
|
UnitMaintenanceDiscount("[amount]% maintenance costs for [mapUnitFilter] units"),
|
||||||
|
@Deprecated("As of 3.16.16")
|
||||||
|
DecreasedUnitMaintenanceCostsByFilter("-[amount]% [mapUnitFilter] unit maintenance costs", UnitMaintenanceDiscount),
|
||||||
|
@Deprecated("As of 3.16.16")
|
||||||
|
DecreasedUnitMaintenanceCostsGlobally("-[amount]% unit upkeep costs", UnitMaintenanceDiscount),
|
||||||
|
StatBonusForNumberOfSpecialists("[stats] if this city has at least [amount] specialists"),
|
||||||
|
StatsPerCity("[stats] [cityFilter]")
|
||||||
|
;
|
||||||
|
|
||||||
|
/** For uniques that have "special" parameters that can accept multiple types, we can override them manually
|
||||||
|
* For 95% of cases, auto-matching is fine. */
|
||||||
|
private val parameterTypeMap = ArrayList<List<UniqueParameterType>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
for (placeholder in text.getPlaceholderParameters()) {
|
||||||
|
val matchingParameterType =
|
||||||
|
UniqueParameterType.values().firstOrNull { it.parameterName == placeholder }
|
||||||
|
?: UniqueParameterType.Unknown
|
||||||
|
parameterTypeMap.add(listOf(matchingParameterType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val placeholderText = text.getPlaceholderText()
|
||||||
|
|
||||||
|
/** Ordinal determines severity - ordered from most severe at 0 */
|
||||||
|
enum class UniqueComplianceErrorSeverity {
|
||||||
|
|
||||||
|
/** This is a problem like "numbers don't parse", "stat isn't stat", "city filter not applicable" */
|
||||||
|
RulesetInvariant,
|
||||||
|
|
||||||
|
/** This is a problem like "unit/resource/tech name doesn't exist in ruleset" - definite bug */
|
||||||
|
RulesetSpecific,
|
||||||
|
|
||||||
|
/** This is for filters that can also potentially accept free text, like UnitFilter and TileFilter */
|
||||||
|
WarningOnly
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Maps uncompliant parameters to their required types */
|
||||||
|
fun getComplianceErrors(
|
||||||
|
unique: Unique,
|
||||||
|
ruleset: Ruleset
|
||||||
|
): List<UniqueComplianceError> {
|
||||||
|
val errorList = ArrayList<UniqueComplianceError>()
|
||||||
|
for ((index, param) in unique.params.withIndex()) {
|
||||||
|
val acceptableParamTypes = parameterTypeMap[index]
|
||||||
|
val errorTypesForAcceptableParameters =
|
||||||
|
acceptableParamTypes.map { it.getErrorSeverity(param, ruleset) }
|
||||||
|
if (errorTypesForAcceptableParameters.any { it == null }) continue // This matches one of the types!
|
||||||
|
val leastSevereWarning =
|
||||||
|
errorTypesForAcceptableParameters.maxByOrNull { it!!.ordinal }!!
|
||||||
|
errorList += UniqueComplianceError(param, acceptableParamTypes, leastSevereWarning)
|
||||||
|
}
|
||||||
|
return errorList
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user