mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Embarked units at sea which need to heal now go find land to heal on, and don't stay stuck in the same place
This commit is contained in:
parent
9559894a86
commit
9ad7b976d5
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 269
|
versionCode 270
|
||||||
versionName "2.17.14"
|
versionName "2.17.15"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||||
|
@ -110,12 +110,21 @@ class UnitAutomation{
|
|||||||
|
|
||||||
fun tryHealUnit(unit: MapUnit, unitDistanceToTiles: HashMap<TileInfo, Float>):Boolean {
|
fun tryHealUnit(unit: MapUnit, unitDistanceToTiles: HashMap<TileInfo, Float>):Boolean {
|
||||||
val tilesInDistance = unitDistanceToTiles.keys.filter { unit.canMoveTo(it) }
|
val tilesInDistance = unitDistanceToTiles.keys.filter { unit.canMoveTo(it) }
|
||||||
|
if(unitDistanceToTiles.isEmpty()) return true // can't move, so...
|
||||||
val unitTile = unit.getTile()
|
val unitTile = unit.getTile()
|
||||||
|
|
||||||
if (tryPillageImprovement(unit, unitDistanceToTiles)) return true
|
if (tryPillageImprovement(unit, unitDistanceToTiles)) return true
|
||||||
|
|
||||||
val tilesByHealingRate = tilesInDistance.groupBy { unit.rankTileForHealing(it) }
|
val tilesByHealingRate = tilesInDistance.groupBy { unit.rankTileForHealing(it) }
|
||||||
if(tilesByHealingRate.isEmpty()) return false
|
|
||||||
|
if(tilesByHealingRate.keys.none { it!=0 }){// We can't heal here at all! We're probably embarked
|
||||||
|
val reachableCityTile = unit.civInfo.cities.map { it.getCenterTile() }
|
||||||
|
.sortedBy { it.arialDistanceTo(unit.currentTile) }
|
||||||
|
.firstOrNull{unit.movementAlgs().canReach(it)}
|
||||||
|
if(reachableCityTile!=null) unit.movementAlgs().headTowards(reachableCityTile)
|
||||||
|
else wander(unit,unitDistanceToTiles)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
val bestTilesForHealing = tilesByHealingRate.maxBy { it.key }!!.value
|
val bestTilesForHealing = tilesByHealingRate.maxBy { it.key }!!.value
|
||||||
// within the tiles with best healing rate, we'll prefer one which has defensive bonuses
|
// within the tiles with best healing rate, we'll prefer one which has defensive bonuses
|
||||||
@ -276,13 +285,27 @@ class UnitAutomation{
|
|||||||
val reachableTilesNotInBombardRange = unitDistanceToTiles.keys.filter { it !in tilesInBombardRange }
|
val reachableTilesNotInBombardRange = unitDistanceToTiles.keys.filter { it !in tilesInBombardRange }
|
||||||
val canMoveIntoBombardRange = tilesInBombardRange.any { unitDistanceToTiles.containsKey(it)}
|
val canMoveIntoBombardRange = tilesInBombardRange.any { unitDistanceToTiles.containsKey(it)}
|
||||||
|
|
||||||
if(!canMoveIntoBombardRange) // no need to worry, keep going as the movement alg. says
|
val suitableGatheringGroundTiles = closestReachableEnemyCity.getTilesAtDistance(4)
|
||||||
unit.movementAlgs().headTowards(closestReachableEnemyCity)
|
.union(closestReachableEnemyCity.getTilesAtDistance(3))
|
||||||
|
.filter { it.isLand }
|
||||||
|
val closestReachableLandingGroundTile = suitableGatheringGroundTiles
|
||||||
|
.sortedBy { it.arialDistanceTo(unit.currentTile) }
|
||||||
|
.firstOrNull { unit.movementAlgs().canReach(it) }
|
||||||
|
|
||||||
|
// don't head straight to the city, try to head to landing grounds -
|
||||||
|
// this is against tha AI's brilliant plan of having everyone embarked and attacking via sea when unnecessary.
|
||||||
|
val tileToHeadTo = if(closestReachableLandingGroundTile!=null) closestReachableLandingGroundTile
|
||||||
|
else closestReachableEnemyCity
|
||||||
|
|
||||||
|
|
||||||
|
if(tileToHeadTo !in tilesInBombardRange) // no need to worry, keep going as the movement alg. says
|
||||||
|
unit.movementAlgs().headTowards(tileToHeadTo)
|
||||||
|
|
||||||
else{
|
else{
|
||||||
if(unit.getRange()>2){ // should never be in a bombardable position
|
if(unit.getRange()>2){ // should never be in a bombardable position
|
||||||
val tilesCanAttackFromButNotInBombardRange =
|
val tilesCanAttackFromButNotInBombardRange =
|
||||||
reachableTilesNotInBombardRange.filter{it.arialDistanceTo(closestReachableEnemyCity) <= unit.getRange()}
|
reachableTilesNotInBombardRange.filter{it.arialDistanceTo(closestReachableEnemyCity) <= unit.getRange()}
|
||||||
|
|
||||||
// move into position far away enough that the bombard doesn't hurt
|
// move into position far away enough that the bombard doesn't hurt
|
||||||
if(tilesCanAttackFromButNotInBombardRange.any())
|
if(tilesCanAttackFromButNotInBombardRange.any())
|
||||||
unit.movementAlgs().headTowards(tilesCanAttackFromButNotInBombardRange.minBy { unitDistanceToTiles[it]!! }!!)
|
unit.movementAlgs().headTowards(tilesCanAttackFromButNotInBombardRange.minBy { unitDistanceToTiles[it]!! }!!)
|
||||||
|
@ -407,6 +407,7 @@ class MapUnit {
|
|||||||
|
|
||||||
fun rankTileForHealing(tileInfo:TileInfo): Int {
|
fun rankTileForHealing(tileInfo:TileInfo): Int {
|
||||||
return when{
|
return when{
|
||||||
|
tileInfo.isWater && type.isLandUnit() -> 0 // Can't heal in water!
|
||||||
tileInfo.getOwner() == null -> 10 // no man's land (neutral)
|
tileInfo.getOwner() == null -> 10 // no man's land (neutral)
|
||||||
tileInfo.isCityCenter() -> 20
|
tileInfo.isCityCenter() -> 20
|
||||||
!civInfo.isAtWarWith(tileInfo.getOwner()!!) -> 15 // home or allied territory
|
!civInfo.isAtWarWith(tileInfo.getOwner()!!) -> 15 // home or allied territory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user