ICombatant.matchesCategory -> matchesFilter, standardization

This commit is contained in:
Yair Morgenstern 2024-01-25 00:06:44 +02:00
parent c93b440fde
commit 414a11a2d6
10 changed files with 15 additions and 15 deletions

View File

@ -161,7 +161,7 @@ object AirInterception {
// Can't intercept if we have a unique preventing it
val conditionalState = StateForConditionals(interceptingCiv, ourCombatant = MapUnitCombatant(unit), theirCombatant = attacker, combatAction = CombatAction.Intercept, attackedTile = attackedTile)
unit.getMatchingUniques(UniqueType.CannotInterceptUnits, conditionalState)
.none { attacker.matchesCategory(it.params[0]) }
.none { attacker.matchesFilter(it.params[0]) }
// Defender can't intercept either
&& unit != (defender as? MapUnitCombatant)?.unit
}

View File

@ -215,7 +215,7 @@ object Battle {
val bonusUniques = getKillUnitPlunderUniques(civUnit, defeatedUnit)
for (unique in bonusUniques) {
if (!defeatedUnit.matchesCategory(unique.params[1])) continue
if (!defeatedUnit.matchesFilter(unique.params[1])) continue
val yieldPercent = unique.params[0].toFloat() / 100
val defeatedUnitYieldSourceType = unique.params[2]
@ -331,7 +331,7 @@ object Battle {
val plunderedGoods = Stats()
for (unique in plunderingUnit.unit.getMatchingUniques(UniqueType.DamageUnitsPlunder, checkCivInfoUniques = true)) {
if (plunderedUnit.matchesCategory(unique.params[1])) {
if (plunderedUnit.matchesFilter(unique.params[1])) {
val percentage = unique.params[0].toFloat()
plunderedGoods.add(Stat.valueOf(unique.params[2]), percentage / 100f * damageDealt)
}
@ -483,7 +483,7 @@ object Battle {
if (!otherIsBarbarian && civ.isMajorCiv()) { // Can't get great generals from Barbarians
var greatGeneralUnits = civ.gameInfo.ruleset.greatGeneralUnits
.filter { it.hasUnique(UniqueType.GreatPersonFromCombat, stateForConditionals) &&
.filter { it.hasUnique(UniqueType.GreatPersonFromCombat, stateForConditionals) &&
// Check if the unit is allowed for the Civ, ignoring build constrants
it.getRejectionReasons(civ).none { reason ->
!reason.isConstructionRejection() &&
@ -491,7 +491,7 @@ object Battle {
!reason.techPolicyEraWonderRequirements() }
}.asSequence()
// For compatibility with older rulesets
if (civ.gameInfo.ruleset.greatGeneralUnits.isEmpty() &&
if (civ.gameInfo.ruleset.greatGeneralUnits.isEmpty() &&
civ.gameInfo.ruleset.units["Great General"] != null)
greatGeneralUnits += civ.gameInfo.ruleset.units["Great General"]!!

View File

@ -104,7 +104,7 @@ object BattleDamage {
// e.g., Maori Warrior - https://civilization.fandom.com/wiki/Maori_Warrior_(Civ5)
val strengthMalus = adjacentUnits.filter { it.civ.isAtWarWith(combatant.getCivInfo()) }
.flatMap { it.getMatchingUniques(UniqueType.StrengthForAdjacentEnemies) }
.filter { combatant.matchesCategory(it.params[1]) && combatant.getTile().matchesFilter(it.params[2]) }
.filter { combatant.matchesFilter(it.params[1]) && combatant.getTile().matchesFilter(it.params[2]) }
.maxByOrNull { it.params[0] }
if (strengthMalus != null) {
modifiers.add("Adjacent enemy units", strengthMalus.params[0].toInt())

View File

@ -45,7 +45,7 @@ object BattleUnitCapture {
private fun unitCapturedPrizeShipsUnique(attacker: MapUnitCombatant, defender: MapUnitCombatant): Boolean {
if (attacker.unit.getMatchingUniques(UniqueType.KillUnitCapture)
.none { defender.matchesCategory(it.params[0]) }
.none { defender.matchesFilter(it.params[0]) }
) return false
val captureChance = min(

View File

@ -23,7 +23,7 @@ class CityCombatant(val city: City) : ICombatant {
override fun isDefeated(): Boolean = city.health == 1
override fun isInvisible(to: Civilization): Boolean = false
override fun canAttack(): Boolean = city.canBombard()
override fun matchesCategory(category: String) = category == "City" || category == "All"
override fun matchesFilter(filter: String) = filter == "City" || filter == "All"
override fun getAttackSound() = UncivSound.Bombard
override fun takeDamage(damage: Int) {

View File

@ -19,7 +19,7 @@ interface ICombatant {
fun isInvisible(to: Civilization): Boolean
fun canAttack(): Boolean
/** Implements [UniqueParameterType.CombatantFilter][com.unciv.models.ruleset.unique.UniqueParameterType.CombatantFilter] */
fun matchesCategory(category: String): Boolean
fun matchesFilter(filter: String): Boolean
fun getAttackSound(): UncivSound
fun isMelee(): Boolean = !isRanged()

View File

@ -18,7 +18,7 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant {
override fun isDefeated(): Boolean = unit.health <= 0
override fun isInvisible(to: Civilization): Boolean = unit.isInvisible(to)
override fun canAttack(): Boolean = unit.canAttack()
override fun matchesCategory(category: String) = unit.matchesFilter(category)
override fun matchesFilter(filter: String) = unit.matchesFilter(filter)
override fun getAttackSound() = unit.baseUnit.attackSound.let {
if (it == null) UncivSound.Click else UncivSound(it)
}

View File

@ -107,7 +107,7 @@ object TargetHelper {
if (combatant is MapUnitCombatant &&
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits).run {
any() && none { tileCombatant.matchesCategory(it.params[0]) }
any() && none { tileCombatant.matchesFilter(it.params[0]) }
}
)
return false

View File

@ -299,8 +299,8 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
UniqueType.ConditionalWhenGarrisoned ->
checkOnCity { getCenterTile().militaryUnit?.canGarrison() == true }
UniqueType.ConditionalVsCity -> state.theirCombatant?.matchesCategory("City") == true
UniqueType.ConditionalVsUnits -> state.theirCombatant?.matchesCategory(condition.params[0]) == true
UniqueType.ConditionalVsCity -> state.theirCombatant?.matchesFilter("City") == true
UniqueType.ConditionalVsUnits -> state.theirCombatant?.matchesFilter(condition.params[0]) == true
UniqueType.ConditionalOurUnit, UniqueType.ConditionalOurUnitOnUnit ->
relevantUnit?.matchesFilter(condition.params[0]) == true
UniqueType.ConditionalUnitWithPromotion -> relevantUnit?.promotions?.promotions?.contains(condition.params[0]) == true

View File

@ -80,7 +80,7 @@ enum class UniqueParameterType(
if (parameterText == "All") null else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant
},
/** Implemented by [ICombatant.matchesCategory][com.unciv.logic.battle.ICombatant.matchesCategory] */
/** Implemented by [ICombatant.matchesCategory][com.unciv.logic.battle.ICombatant.matchesFilter] */
CombatantFilter("combatantFilter", "City", "This indicates a combatant, which can either be a unit or a city (when bombarding). Must either be `City` or a `mapUnitFilter`") {
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueParameterErrorSeverity? {
@ -309,7 +309,7 @@ enum class UniqueParameterType(
TerrainFilter("terrainFilter", Constants.freshWaterFilter, null, "Terrain Filters") {
private val knownValues = setOf(
"All", "Terrain",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
"resource", "Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy",
"Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder",
"Impassable", "Land", "Water"