Mod land units with missile and nuke uniques no longer crash the game

This commit is contained in:
Yair Morgenstern
2022-04-20 12:32:40 +03:00
parent c5c06a2456
commit 18be173ab8
2 changed files with 19 additions and 14 deletions

View File

@ -425,7 +425,11 @@ object SpecificUnitAutomation {
//todo: maybe group by size and choose highest priority within the same size turns //todo: maybe group by size and choose highest priority within the same size turns
val closestCityThatCanAttackFrom = citiesThatCanAttackFrom.minByOrNull { pathsToCities[it]!!.size }!! val closestCityThatCanAttackFrom = citiesThatCanAttackFrom.minByOrNull { pathsToCities[it]!!.size }!!
val firstStepInPath = pathsToCities[closestCityThatCanAttackFrom]!!.first() val firstStepInPath = pathsToCities[closestCityThatCanAttackFrom]!!.first()
try {
airUnit.movement.moveToTile(firstStepInPath) airUnit.movement.moveToTile(firstStepInPath)
}catch (ex:java.lang.Exception){
println()
}
} }
fun automateNukes(unit: MapUnit) { fun automateNukes(unit: MapUnit) {
@ -451,17 +455,18 @@ object SpecificUnitAutomation {
val immediatelyReachableCities = tilesInRange val immediatelyReachableCities = tilesInRange
.filter { unit.movement.canMoveTo(it) } .filter { unit.movement.canMoveTo(it) }
for (city in immediatelyReachableCities) { for (city in immediatelyReachableCities) if (city.getTilesInDistance(unit.getRange())
if (city.getTilesInDistance(unit.getRange()) .any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) }
.any { it.isCityCenter() && it.getOwner()!!.isAtWarWith(unit.civInfo) }) { ) {
unit.movement.moveToTile(city) unit.movement.moveToTile(city)
return return
} }
}
if (unit.baseUnit.isAirUnit()) {
val pathsToCities = unit.movement.getAerialPathsToCities() val pathsToCities = unit.movement.getAerialPathsToCities()
if (pathsToCities.isEmpty()) return // can't actually move anywhere else if (pathsToCities.isEmpty()) return // can't actually move anywhere else
tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit) tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit)
} else UnitAutomation.tryHeadTowardsEnemyCity(unit)
} }
private fun tryRelocateToCitiesWithEnemyNearBy(unit: MapUnit): Boolean { private fun tryRelocateToCitiesWithEnemyNearBy(unit: MapUnit): Boolean {

View File

@ -389,7 +389,7 @@ object UnitAutomation {
return false return false
} }
private fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean { fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean {
if (unit.civInfo.cities.isEmpty()) return false if (unit.civInfo.cities.isEmpty()) return false
// only focus on *attacking* 1 enemy at a time otherwise you'll lose on both fronts // only focus on *attacking* 1 enemy at a time otherwise you'll lose on both fronts