diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index 671d00e148..a52f2ae459 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -13,8 +13,6 @@ import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stats import com.unciv.ui.victoryscreen.RankingType -import kotlin.math.max -import kotlin.math.sqrt object Automation { @@ -99,9 +97,10 @@ object Automation { militaryUnits = militaryUnits.filter { !it.isWaterUnit() } - val carryingUnits = militaryUnits.filter { it.hasUnique(UniqueType.CarryAirUnits) }.toList() + val carryingOnlyUnits = militaryUnits.filter { it.hasUnique(UniqueType.CarryAirUnits) + && it.hasUnique(UniqueType.CannotAttack) }.toList() - for (unit in carryingUnits) + for (unit in carryingOnlyUnits) if (providesUnneededCarryingSlots(unit, city.civInfo)) militaryUnits = militaryUnits.filterNot { it == unit } diff --git a/core/src/com/unciv/logic/automation/BattleHelper.kt b/core/src/com/unciv/logic/automation/BattleHelper.kt index 25d1df9c31..2a429492ad 100644 --- a/core/src/com/unciv/logic/automation/BattleHelper.kt +++ b/core/src/com/unciv/logic/automation/BattleHelper.kt @@ -8,11 +8,12 @@ import com.unciv.logic.map.MapUnit import com.unciv.logic.map.PathsToTilesWithinTurn import com.unciv.logic.map.TileInfo import com.unciv.models.AttackableTile +import com.unciv.models.ruleset.unique.UniqueType object BattleHelper { fun tryAttackNearbyEnemy(unit: MapUnit, stayOnTile: Boolean = false): Boolean { - if (unit.hasUnique("Cannot attack")) return false + if (unit.hasUnique(UniqueType.CannotAttack)) return false val attackableEnemies = getAttackableEnemies(unit, unit.movement.getDistanceToTiles(), stayOnTile=stayOnTile) // Only take enemies we can fight without dying .filter { diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index cf69764dfd..ea8d10c42f 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -377,7 +377,7 @@ class Ruleset { lines += "${unit.name} upgrades to itself!" if (!unit.isCivilian() && unit.strength == 0) lines += "${unit.name} is a military unit but has no assigned strength!" - if (unit.isRanged() && unit.rangedStrength == 0 && "Cannot attack" !in unit.uniques) + if (unit.isRanged() && unit.rangedStrength == 0 && !unit.hasUnique(UniqueType.CannotAttack)) lines += "${unit.name} is a ranged unit but has no assigned rangedStrength!" checkUniques(unit, lines, UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 4909363123..065207b96a 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -171,6 +171,7 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) { MayFoundReligion("May found a religion", UniqueTarget.Unit), MayEnhanceReligion("May enhance a religion", UniqueTarget.Unit), NormalVisionWhenEmbarked("Normal vision when embarked", UniqueTarget.Unit, UniqueTarget.Global), + CannotAttack("Cannot attack", UniqueTarget.Unit), @Deprecated("As of 3.17.5", ReplaceWith("[amount] Movement "), DeprecationLevel.WARNING) MovementUnits("+[amount] Movement for all [mapUnitFilter] units", UniqueTarget.Global), diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 2c43a87272..357e73091f 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -59,7 +59,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() { val unitTable = worldScreen.bottomUnitTable return if (unitTable.selectedUnit != null && !unitTable.selectedUnit!!.isCivilian() - && !unitTable.selectedUnit!!.hasUnique("Cannot attack")) + && !unitTable.selectedUnit!!.hasUnique(UniqueType.CannotAttack)) MapUnitCombatant(unitTable.selectedUnit!!) else if (unitTable.selectedCity != null) CityCombatant(unitTable.selectedCity!!)