diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index 7c9efd7296..b11e569bbf 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -61,15 +61,16 @@ object SpecificUnitAutomation { } // try to revenge and capture their tiles - val enemyCities = unit.civInfo.gameInfo.civilizations - .filter { unit.civInfo.knows(it) && - unit.civInfo.getDiplomacyManager(it).hasModifier(DiplomaticModifiers.StealingTerritory) } + val enemyCities = unit.civInfo.getKnownCivs() + .filter { unit.civInfo.getDiplomacyManager(it).hasModifier(DiplomaticModifiers.StealingTerritory) } .flatMap { it.cities }.asSequence() // find the suitable tiles (or their neigbours) - val tileToSteal = enemyCities.flatMap { it.getTiles() }.flatMap { it.neighbors.asSequence() } + val tileToSteal = enemyCities.flatMap { it.getTiles() } // City tiles + .filter { it.neighbors.any { it.getOwner()!=unit.civInfo } } // Edge city tiles + .flatMap { it.neighbors.asSequence() } // Neighbors of edge city tiles .filter { it in unit.civInfo.viewableTiles // we can see them - && unit.movement.canReach(it) // we can reach it - && it.neighbors.any { tile -> tile.getOwner() == unit.civInfo} } // they are close to our borders + && it.neighbors.any { tile -> tile.getOwner() == unit.civInfo}// they are close to our borders + } .sortedBy { // get closest tiles val distance = it.aerialDistanceTo(unit.currentTile) @@ -77,7 +78,8 @@ object SpecificUnitAutomation { val owner = it.getOwner() if (owner != null) distance - WorkerAutomation(unit).getPriority(it, owner) - else distance }.firstOrNull() + else distance } + .firstOrNull{ unit.movement.canReach(it) } // canReach is perfrmance-heavy and always a last resort // if there is a good tile to steal - go there if (tileToSteal != null) { unit.movement.headTowards(tileToSteal) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 6c9fcb4f30..4038c775b4 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -189,6 +189,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { return destinationTileThisTurn } + /** This is performance-heavy - use as last resort, only after checking everything else! */ fun canReach(destination: TileInfo): Boolean { if (unit.type.isAirUnit()) return unit.currentTile.aerialDistanceTo(destination) <= unit.getRange()*2