Construction automation constructs attacking units even if they provide unneeded slots

This commit is contained in:
yairm210 2021-10-12 19:45:21 +03:00
parent 9abc3ddb6e
commit 038c501ac8
5 changed files with 8 additions and 7 deletions

View File

@ -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 }

View File

@ -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 {

View File

@ -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)

View File

@ -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 <for [mapUnitFilter] units>"), DeprecationLevel.WARNING)
MovementUnits("+[amount] Movement for all [mapUnitFilter] units", UniqueTarget.Global),

View File

@ -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!!)