mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Unit filtering actually comes in 2 flavors - one for "unit templates", BaseUnit, and one for "actual units in the field", MapUnit. This should be reflected in the parameter names.
This commit is contained in:
parent
fa939e15d9
commit
1f05239275
@ -6,6 +6,7 @@ import com.unciv.models.metadata.BASE_GAME_DURATION_TURNS
|
|||||||
import com.unciv.models.ruleset.BeliefType
|
import com.unciv.models.ruleset.BeliefType
|
||||||
import com.unciv.models.ruleset.Policy
|
import com.unciv.models.ruleset.Policy
|
||||||
import com.unciv.models.ruleset.Unique
|
import com.unciv.models.ruleset.Unique
|
||||||
|
import com.unciv.models.ruleset.UniqueType
|
||||||
import com.unciv.models.ruleset.tile.ResourceType
|
import com.unciv.models.ruleset.tile.ResourceType
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.StatMap
|
import com.unciv.models.stats.StatMap
|
||||||
@ -22,7 +23,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
|||||||
private fun getUnitMaintenance(): Int {
|
private fun getUnitMaintenance(): Int {
|
||||||
val baseUnitCost = 0.5f
|
val baseUnitCost = 0.5f
|
||||||
var freeUnits = 3
|
var freeUnits = 3
|
||||||
for (unique in civInfo.getMatchingUniques("[] units cost no maintenance")) {
|
for (unique in civInfo.getMatchingUniquesByEnum(UniqueType.FreeUnits)) {
|
||||||
freeUnits += unique.params[0].toInt()
|
freeUnits += unique.params[0].toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,6 +943,8 @@ class MapUnit {
|
|||||||
return filter.removePrefix("{").removeSuffix("}").split("} {")
|
return filter.removePrefix("{").removeSuffix("}").split("} {")
|
||||||
.all { matchesFilter(it) }
|
.all { matchesFilter(it) }
|
||||||
return when (filter) {
|
return when (filter) {
|
||||||
|
// todo: unit filters should be adjectives, fitting "[filterType] units"
|
||||||
|
// This means converting "wounded units" to "Wounded", "Barbarians" to "Barbarian"
|
||||||
"Wounded", "wounded units" -> health < 100
|
"Wounded", "wounded units" -> health < 100
|
||||||
"Barbarians", "Barbarian" -> civInfo.isBarbarian()
|
"Barbarians", "Barbarian" -> civInfo.isBarbarian()
|
||||||
"City-State" -> civInfo.isCityState()
|
"City-State" -> civInfo.isCityState()
|
||||||
|
@ -15,11 +15,29 @@ enum class UniqueParameterType(val parameterName:String) {
|
|||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UnitFilter("unitType") {
|
MapUnitFilter("mapUnitFilter"){
|
||||||
|
val knownValues = setOf("Wounded", "Barbarians", "City-State", "Embarked", "Non-City")
|
||||||
override fun getErrorType(parameterText: String, ruleset: Ruleset):
|
override fun getErrorType(parameterText: String, ruleset: Ruleset):
|
||||||
UniqueType.UniqueComplianceErrorSeverity? {
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
if(ruleset.unitTypes.containsKey(parameterText) || unitTypeStrings.contains(parameterText)) return null
|
if (parameterText in knownValues) return null
|
||||||
return UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific
|
return BaseUnitFilter.getErrorType(parameterText, ruleset)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BaseUnitFilter("baseUnitFilter"){
|
||||||
|
// As you can see there is a difference between these and what's in unitTypeStrings (for translation) -
|
||||||
|
// the goal is to unify, but for now this is the "real" list
|
||||||
|
val knownValues = setOf("Melee", "Ranged", "Civilian", "Military", "Land", "Water", "Air",
|
||||||
|
"non-air", "Nuclear Weapon", "Great Person", "Religious")
|
||||||
|
override fun getErrorType(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
if (parameterText in knownValues) return null
|
||||||
|
if (ruleset.unitTypes.containsKey(parameterText)) return null
|
||||||
|
if (ruleset.units.containsKey(parameterText)) return null
|
||||||
|
|
||||||
|
// We could add a giant hashset of all uniques used by units,
|
||||||
|
// so we could accept that unique-targeting uniques are OK. Maybe later.
|
||||||
|
|
||||||
|
return UniqueType.UniqueComplianceErrorSeverity.WarningOnly
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Unknown("param") {
|
Unknown("param") {
|
||||||
|
@ -493,11 +493,13 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
|||||||
"non-air" -> !movesLikeAirUnits()
|
"non-air" -> !movesLikeAirUnits()
|
||||||
|
|
||||||
"Nuclear Weapon" -> isNuclearWeapon()
|
"Nuclear Weapon" -> isNuclearWeapon()
|
||||||
|
// "Great" should be deprecated, replaced by "Great Person".
|
||||||
"Great Person", "Great" -> isGreatPerson()
|
"Great Person", "Great" -> isGreatPerson()
|
||||||
"Religious" -> uniques.contains("Religious Unit")
|
"Religious" -> uniques.contains("Religious Unit")
|
||||||
else -> {
|
else -> {
|
||||||
if (getType().matchesFilter(filter)) return true
|
if (getType().matchesFilter(filter)) return true
|
||||||
if (
|
if (
|
||||||
|
// Uniques using these kinds of filters should be deprecated and replaced ith adjective-only parameters
|
||||||
filter.endsWith(" units")
|
filter.endsWith(" units")
|
||||||
// "military units" --> "Military", using invariant locale
|
// "military units" --> "Military", using invariant locale
|
||||||
&& matchesFilter(filter.removeSuffix(" units").lowercase().replaceFirstChar { it.uppercaseChar() })
|
&& matchesFilter(filter.removeSuffix(" units").lowercase().replaceFirstChar { it.uppercaseChar() })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user