mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Unified ranking tiles for healing logic
This commit is contained in:
parent
5873ccc848
commit
36781e4b55
@ -92,15 +92,6 @@ class UnitAutomation{
|
|||||||
// if both failed, then... there aren't any reachable tiles. Which is possible.
|
// if both failed, then... there aren't any reachable tiles. Which is possible.
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rankTileForHealing(tileInfo: TileInfo, unit: MapUnit): Int {
|
|
||||||
val tileOwner = tileInfo.getOwner()
|
|
||||||
when{
|
|
||||||
tileInfo.isCityCenter() -> return 3
|
|
||||||
tileOwner!=null && !unit.civInfo.isAtWarWith(tileOwner)-> return 2
|
|
||||||
tileOwner==null -> return 1
|
|
||||||
else -> return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun healUnit(unit: MapUnit, unitDistanceToTiles: HashMap<TileInfo, Float>) {
|
fun healUnit(unit: MapUnit, unitDistanceToTiles: HashMap<TileInfo, Float>) {
|
||||||
val tilesInDistance = unitDistanceToTiles.keys.filter { unit.canMoveTo(it) }
|
val tilesInDistance = unitDistanceToTiles.keys.filter { unit.canMoveTo(it) }
|
||||||
@ -108,13 +99,15 @@ class UnitAutomation{
|
|||||||
|
|
||||||
if (pillageImprovement(unit, unitDistanceToTiles)) return
|
if (pillageImprovement(unit, unitDistanceToTiles)) return
|
||||||
|
|
||||||
val tilesByHealingRate = tilesInDistance.groupBy { rankTileForHealing(it,unit) }
|
val tilesByHealingRate = tilesInDistance.groupBy { unit.rankTileForHealing(it) }
|
||||||
if(tilesByHealingRate.isEmpty()) return
|
if(tilesByHealingRate.isEmpty()) return
|
||||||
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
|
||||||
val bestTileForHealing = bestTilesForHealing.maxBy { it.getDefensiveBonus() }!!
|
val bestTileForHealing = bestTilesForHealing.maxBy { it.getDefensiveBonus() }!!
|
||||||
if(unitTile!=bestTileForHealing && rankTileForHealing(bestTileForHealing,unit)>rankTileForHealing(unitTile,unit))
|
|
||||||
|
if(unitTile!=bestTileForHealing && unit.rankTileForHealing(bestTileForHealing)>unit.rankTileForHealing(unitTile))
|
||||||
unit.moveToTile(bestTileForHealing)
|
unit.moveToTile(bestTileForHealing)
|
||||||
|
|
||||||
if(unit.currentMovement>0 && unit.canFortify()){
|
if(unit.currentMovement>0 && unit.canFortify()){
|
||||||
unit.action="Fortify 0"
|
unit.action="Fortify 0"
|
||||||
}
|
}
|
||||||
|
@ -330,14 +330,18 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun heal(){
|
private fun heal(){
|
||||||
val tile = getTile()
|
health += rankTileForHealing(getTile())
|
||||||
health += when{
|
if(health>100) health=100
|
||||||
tile.isCityCenter() -> 20
|
}
|
||||||
tile.getOwner()?.civName == owner -> 15 // home territory
|
|
||||||
tile.getOwner() == null -> 10 // no man's land (neutral)
|
fun rankTileForHealing(tileInfo:TileInfo): Int {
|
||||||
|
if(isEmbarked()) return 0 // embarked units can't heal
|
||||||
|
return when{
|
||||||
|
tileInfo.getOwner() == null -> 10 // no man's land (neutral)
|
||||||
|
tileInfo.isCityCenter() -> 20
|
||||||
|
!civInfo.isAtWarWith(tileInfo.getOwner()!!) -> 15 // home or allied territory
|
||||||
else -> 5 // enemy territory
|
else -> 5 // enemy territory
|
||||||
}
|
}
|
||||||
if(health>100) health=100
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user