mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 07:16:54 +07:00
Mod land units with missile and nuke uniques no longer crash the game
This commit is contained in:
parent
c5c06a2456
commit
18be173ab8
@ -425,7 +425,11 @@ object SpecificUnitAutomation {
|
||||
//todo: maybe group by size and choose highest priority within the same size turns
|
||||
val closestCityThatCanAttackFrom = citiesThatCanAttackFrom.minByOrNull { pathsToCities[it]!!.size }!!
|
||||
val firstStepInPath = pathsToCities[closestCityThatCanAttackFrom]!!.first()
|
||||
airUnit.movement.moveToTile(firstStepInPath)
|
||||
try {
|
||||
airUnit.movement.moveToTile(firstStepInPath)
|
||||
}catch (ex:java.lang.Exception){
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
fun automateNukes(unit: MapUnit) {
|
||||
@ -449,19 +453,20 @@ object SpecificUnitAutomation {
|
||||
private fun tryRelocateToNearbyAttackableCities(unit: MapUnit) {
|
||||
val tilesInRange = unit.currentTile.getTilesInDistance(unit.getRange())
|
||||
val immediatelyReachableCities = tilesInRange
|
||||
.filter { unit.movement.canMoveTo(it) }
|
||||
|
||||
for (city in immediatelyReachableCities) {
|
||||
if (city.getTilesInDistance(unit.getRange())
|
||||
.any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) }) {
|
||||
unit.movement.moveToTile(city)
|
||||
return
|
||||
}
|
||||
}
|
||||
.filter { unit.movement.canMoveTo(it) }
|
||||
|
||||
val pathsToCities = unit.movement.getAerialPathsToCities()
|
||||
if (pathsToCities.isEmpty()) return // can't actually move anywhere else
|
||||
tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit)
|
||||
for (city in immediatelyReachableCities) if (city.getTilesInDistance(unit.getRange())
|
||||
.any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) }
|
||||
) {
|
||||
unit.movement.moveToTile(city)
|
||||
return
|
||||
}
|
||||
|
||||
if (unit.baseUnit.isAirUnit()) {
|
||||
val pathsToCities = unit.movement.getAerialPathsToCities()
|
||||
if (pathsToCities.isEmpty()) return // can't actually move anywhere else
|
||||
tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit)
|
||||
} else UnitAutomation.tryHeadTowardsEnemyCity(unit)
|
||||
}
|
||||
|
||||
private fun tryRelocateToCitiesWithEnemyNearBy(unit: MapUnit): Boolean {
|
||||
|
@ -389,7 +389,7 @@ object UnitAutomation {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean {
|
||||
fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean {
|
||||
if (unit.civInfo.cities.isEmpty()) return false
|
||||
|
||||
// only focus on *attacking* 1 enemy at a time otherwise you'll lose on both fronts
|
||||
|
Loading…
Reference in New Issue
Block a user