Specific automation for Missile units means they won't try to move to tiles that they can't move to

This commit is contained in:
Yair Morgenstern 2020-01-02 19:36:19 +02:00
parent d254838278
commit 52165e692f
3 changed files with 28 additions and 1 deletions

View File

@ -252,4 +252,28 @@ class SpecificUnitAutomation{
airUnit.movement.moveToTile(firstStepInPath)
}
// This really needs to be changed, to have better targetting for missiles
fun automateMissile(unit: MapUnit) {
if (UnitAutomation().tryAttackNearbyEnemy(unit)) return
val tilesInRange = unit.currentTile.getTilesInDistance(unit.getRange())
val immediatelyReachableCities = tilesInRange
.filter { it.isCityCenter() && it.getOwner() == unit.civInfo && unit.movement.canMoveTo(it) }
for (city in immediatelyReachableCities) {
if (city.getTilesInDistance(unit.getRange())
.any { UnitAutomation().containsAttackableEnemy(it, MapUnitCombatant(unit)) }) {
unit.movement.moveToTile(city)
return
}
}
val pathsToCities = unit.movement.getArialPathsToCities()
if (pathsToCities.isEmpty()) return // can't actually move anywhere else
tryMoveToCitiesToArialAttackFrom(pathsToCities, unit)
}
}

View File

@ -45,6 +45,9 @@ class UnitAutomation{
if(unit.type==UnitType.Bomber)
return SpecificUnitAutomation().automateBomber(unit)
if(unit.type==UnitType.Missile)
return SpecificUnitAutomation().automateMissile(unit)
if(unit.name.startsWith("Great")
&& unit.name in GreatPersonManager().statToGreatPersonMapping.values){ // So "Great War Infantry" isn't caught here
return SpecificUnitAutomation().automateGreatPerson(unit)

View File

@ -214,7 +214,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
class CantEnterThisTileException(msg: String) : Exception(msg)
if(!canMoveTo(destination))
throw CantEnterThisTileException("$this can't enter $destination")
throw CantEnterThisTileException("$unit can't enter $destination")
if(unit.type.isAirUnit()){ // they move differently from all other units
unit.action=null