Resolved #11200 - Add AI for land-based nukes

This commit is contained in:
Yair Morgenstern 2024-02-26 22:13:20 +02:00
parent e6a132a9d7
commit a0f710b885
2 changed files with 28 additions and 24 deletions

View File

@ -1,6 +1,7 @@
package com.unciv.logic.automation.unit
import com.unciv.logic.battle.AirInterception
import com.unciv.logic.battle.Battle
import com.unciv.logic.battle.MapUnitCombatant
import com.unciv.logic.battle.Nuke
import com.unciv.logic.battle.TargetHelper
@ -124,20 +125,22 @@ object AirUnitAutomation {
fun automateNukes(unit: MapUnit) {
if (!unit.civ.isAtWar()) return
// We should *Almost* never want to nuke our own city, so don't consider it
val tilesInRange = unit.currentTile.getTilesInDistanceRange(2..unit.getRange())
var highestTileNukeValue = 0
var tileToNuke: Tile? = null
tilesInRange.forEach {
val value = getNukeLocationValue(unit, it)
if (value > highestTileNukeValue) {
highestTileNukeValue = value
tileToNuke = it
}
if (unit.type.isAirUnit()) {
val tilesInRange = unit.currentTile.getTilesInDistanceRange(2..unit.getRange())
val highestTileNukeValue = tilesInRange.map { it to getNukeLocationValue(unit, it) }
.maxByOrNull { it.second }
if (highestTileNukeValue != null && highestTileNukeValue.second > 0)
Nuke.NUKE(MapUnitCombatant(unit), highestTileNukeValue.first)
tryRelocateMissileToNearbyAttackableCities(unit)
} else {
val attackableTiles = TargetHelper.getAttackableEnemies(unit, unit.movement.getDistanceToTiles())
val highestTileNukeValue = attackableTiles.map { it to getNukeLocationValue(unit, it.tileToAttack) }
.maxByOrNull { it.second }
if (highestTileNukeValue != null && highestTileNukeValue.second > 0)
Battle.moveAndAttack(MapUnitCombatant(unit), highestTileNukeValue.first)
HeadTowardsEnemyCityAutomation.tryHeadTowardsEnemyCity(unit)
}
if (highestTileNukeValue > 0) {
Nuke.NUKE(MapUnitCombatant(unit), tileToNuke!!)
}
tryRelocateMissileToNearbyAttackableCities(unit)
}
/**

View File

@ -194,14 +194,15 @@ object UnitAutomation {
return
}
// Note that not all nukes have to be air units
if (unit.baseUnit.isNuclearWeapon()) {
return AirUnitAutomation.automateNukes(unit)
}
if (unit.baseUnit.isAirUnit()) {
if (unit.canIntercept())
return AirUnitAutomation.automateFighter(unit)
// Note that not all nukes have to be air units
if (unit.baseUnit.isNuclearWeapon())
return AirUnitAutomation.automateNukes(unit)
if (unit.hasUnique(UniqueType.SelfDestructs))
return AirUnitAutomation.automateMissile(unit)