Validate unique parameters for mods

This commit is contained in:
Yair Morgenstern
2023-01-01 15:55:41 +02:00
parent 9cf47e9f48
commit d20f8a53f8
5 changed files with 12 additions and 7 deletions

View File

@ -599,7 +599,6 @@
"uniques": [ "uniques": [
"[+25]% Strength <when attacking> <for [Military] units> <for [50] turns>", "[+25]% Strength <when attacking> <for [Military] units> <for [50] turns>",
"May buy [Great General] units for [1000] [Faith] [in all cities in which the majority religion is a major religion] at an increasing price ([500]) <starting from the [Industrial era]>", "May buy [Great General] units for [1000] [Faith] [in all cities in which the majority religion is a major religion] at an increasing price ([500]) <starting from the [Industrial era]>",
"May buy [Great Admiral] units for [1000] [Faith] [in all cities in which the majority religion is a major religion] at an increasing price ([500]) <starting from the [Industrial era]>"
] ]
} }
] ]

View File

@ -455,10 +455,14 @@ class RulesetValidator(val ruleset: Ruleset) {
val typeComplianceErrors = unique.type.getComplianceErrors(unique, ruleset) val typeComplianceErrors = unique.type.getComplianceErrors(unique, ruleset)
for (complianceError in typeComplianceErrors) { for (complianceError in typeComplianceErrors) {
if (complianceError.errorSeverity == severityToReport) // TODO: Make this Error eventually, this is Not Good
rulesetErrors += "$name's unique \"${unique.text}\" contains parameter ${complianceError.parameterName}," + if (complianceError.errorSeverity <= severityToReport)
rulesetErrors.add(RulesetError("$name's unique \"${unique.text}\" contains parameter ${complianceError.parameterName}," +
" which does not fit parameter type" + " which does not fit parameter type" +
" ${complianceError.acceptableParameterTypes.joinToString(" or ") { it.parameterName }} !" " ${complianceError.acceptableParameterTypes.joinToString(" or ") { it.parameterName }} !",
RulesetErrorSeverity.Warning
)
)
} }
for (conditional in unique.conditionals) { for (conditional in unique.conditionals) {

View File

@ -78,6 +78,8 @@ enum class UniqueParameterType(
if ('{' in parameterText) // "{filter} {filter}" for and logic if ('{' in parameterText) // "{filter} {filter}" for and logic
return parameterText.filterCompositeLogic({ getErrorSeverity(it, ruleset) }) { a, b -> maxOf(a, b) } return parameterText.filterCompositeLogic({ getErrorSeverity(it, ruleset) }) { a, b -> maxOf(a, b) }
if (parameterText in knownValues) return null if (parameterText in knownValues) return null
if (ruleset.unitPromotions.values.any { it.hasUnique(parameterText) })
return null
return BaseUnitFilter.getErrorSeverity(parameterText, ruleset) return BaseUnitFilter.getErrorSeverity(parameterText, ruleset)
} }
override fun getTranslationWriterStringsForOutput() = knownValues override fun getTranslationWriterStringsForOutput() = knownValues

View File

@ -389,7 +389,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
NoMovementToPillage("No movement cost to pillage", UniqueTarget.Unit, UniqueTarget.Global), NoMovementToPillage("No movement cost to pillage", UniqueTarget.Unit, UniqueTarget.Global),
CanMoveAfterAttacking("Can move after attacking", UniqueTarget.Unit), CanMoveAfterAttacking("Can move after attacking", UniqueTarget.Unit),
TransferMovement("Transfer Movement to [unit]", UniqueTarget.Unit), TransferMovement("Transfer Movement to [mapUnitFilter]", UniqueTarget.Unit),
MoveImmediatelyOnceBought("Can move immediately once bought", UniqueTarget.Unit), MoveImmediatelyOnceBought("Can move immediately once bought", UniqueTarget.Unit),
MayParadrop("May Paradrop up to [amount] tiles from inside friendly territory", UniqueTarget.Unit), MayParadrop("May Paradrop up to [amount] tiles from inside friendly territory", UniqueTarget.Unit),

View File

@ -1080,8 +1080,8 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "Can move after attacking" ??? example "Can move after attacking"
Applicable to: Unit Applicable to: Unit
??? example "Transfer Movement to [unit]" ??? example "Transfer Movement to [mapUnitFilter]"
Example: "Transfer Movement to [Musketman]" Example: "Transfer Movement to [Wounded]"
Applicable to: Unit Applicable to: Unit