mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
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:
parent
d254838278
commit
52165e692f
@ -252,4 +252,28 @@ class SpecificUnitAutomation{
|
|||||||
airUnit.movement.moveToTile(firstStepInPath)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -45,6 +45,9 @@ class UnitAutomation{
|
|||||||
if(unit.type==UnitType.Bomber)
|
if(unit.type==UnitType.Bomber)
|
||||||
return SpecificUnitAutomation().automateBomber(unit)
|
return SpecificUnitAutomation().automateBomber(unit)
|
||||||
|
|
||||||
|
if(unit.type==UnitType.Missile)
|
||||||
|
return SpecificUnitAutomation().automateMissile(unit)
|
||||||
|
|
||||||
if(unit.name.startsWith("Great")
|
if(unit.name.startsWith("Great")
|
||||||
&& unit.name in GreatPersonManager().statToGreatPersonMapping.values){ // So "Great War Infantry" isn't caught here
|
&& unit.name in GreatPersonManager().statToGreatPersonMapping.values){ // So "Great War Infantry" isn't caught here
|
||||||
return SpecificUnitAutomation().automateGreatPerson(unit)
|
return SpecificUnitAutomation().automateGreatPerson(unit)
|
||||||
|
@ -214,7 +214,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
|
|
||||||
class CantEnterThisTileException(msg: String) : Exception(msg)
|
class CantEnterThisTileException(msg: String) : Exception(msg)
|
||||||
if(!canMoveTo(destination))
|
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
|
if(unit.type.isAirUnit()){ // they move differently from all other units
|
||||||
unit.action=null
|
unit.action=null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user