mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
Resolved #11200 - Add AI for land-based nukes
This commit is contained in:
parent
e6a132a9d7
commit
a0f710b885
@ -1,6 +1,7 @@
|
|||||||
package com.unciv.logic.automation.unit
|
package com.unciv.logic.automation.unit
|
||||||
|
|
||||||
import com.unciv.logic.battle.AirInterception
|
import com.unciv.logic.battle.AirInterception
|
||||||
|
import com.unciv.logic.battle.Battle
|
||||||
import com.unciv.logic.battle.MapUnitCombatant
|
import com.unciv.logic.battle.MapUnitCombatant
|
||||||
import com.unciv.logic.battle.Nuke
|
import com.unciv.logic.battle.Nuke
|
||||||
import com.unciv.logic.battle.TargetHelper
|
import com.unciv.logic.battle.TargetHelper
|
||||||
@ -124,20 +125,22 @@ object AirUnitAutomation {
|
|||||||
fun automateNukes(unit: MapUnit) {
|
fun automateNukes(unit: MapUnit) {
|
||||||
if (!unit.civ.isAtWar()) return
|
if (!unit.civ.isAtWar()) return
|
||||||
// We should *Almost* never want to nuke our own city, so don't consider it
|
// We should *Almost* never want to nuke our own city, so don't consider it
|
||||||
val tilesInRange = unit.currentTile.getTilesInDistanceRange(2..unit.getRange())
|
if (unit.type.isAirUnit()) {
|
||||||
var highestTileNukeValue = 0
|
val tilesInRange = unit.currentTile.getTilesInDistanceRange(2..unit.getRange())
|
||||||
var tileToNuke: Tile? = null
|
val highestTileNukeValue = tilesInRange.map { it to getNukeLocationValue(unit, it) }
|
||||||
tilesInRange.forEach {
|
.maxByOrNull { it.second }
|
||||||
val value = getNukeLocationValue(unit, it)
|
if (highestTileNukeValue != null && highestTileNukeValue.second > 0)
|
||||||
if (value > highestTileNukeValue) {
|
Nuke.NUKE(MapUnitCombatant(unit), highestTileNukeValue.first)
|
||||||
highestTileNukeValue = value
|
|
||||||
tileToNuke = it
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,14 +194,15 @@ object UnitAutomation {
|
|||||||
return
|
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.baseUnit.isAirUnit()) {
|
||||||
if (unit.canIntercept())
|
if (unit.canIntercept())
|
||||||
return AirUnitAutomation.automateFighter(unit)
|
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))
|
if (unit.hasUnique(UniqueType.SelfDestructs))
|
||||||
return AirUnitAutomation.automateMissile(unit)
|
return AirUnitAutomation.automateMissile(unit)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user