mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 18:28:42 +07:00
AI tweaks for better targeting
This commit is contained in:
@ -70,6 +70,9 @@ object BattleHelper {
|
|||||||
else reachableTile.tileMap.getViewableTiles(reachableTile.position, rangeOfAttack, true).asSequence()
|
else reachableTile.tileMap.getViewableTiles(reachableTile.position, rangeOfAttack, true).asSequence()
|
||||||
|
|
||||||
for (tile in tilesInAttackRange) {
|
for (tile in tilesInAttackRange) {
|
||||||
|
// Since military units can technically enter tiles with enemy civilians,
|
||||||
|
// some try to move to to the tile and then attack the unit it contains, which is silly
|
||||||
|
if (tile == reachableTile) continue
|
||||||
if (tile in tilesWithEnemies) attackableTiles += AttackableTile(
|
if (tile in tilesWithEnemies) attackableTiles += AttackableTile(
|
||||||
reachableTile,
|
reachableTile,
|
||||||
tile,
|
tile,
|
||||||
@ -197,8 +200,9 @@ object BattleHelper {
|
|||||||
).toFloat().coerceAtLeast(1f) }
|
).toFloat().coerceAtLeast(1f) }
|
||||||
|
|
||||||
// kill a unit if possible, prioritizing by attack strength
|
// kill a unit if possible, prioritizing by attack strength
|
||||||
val canKill = attacksToKill.filter { it.value <= 1 }
|
val canKill = attacksToKill.filter { it.value <= 1 }.keys
|
||||||
.maxByOrNull { MapUnitCombatant(it.key.tileToAttack.militaryUnit!!).getAttackingStrength() }?.key
|
.sortedByDescending { it.movementLeftAfterMovingToAttackTile } // Among equal kills, prioritize the closest unit
|
||||||
|
.maxByOrNull { MapUnitCombatant(it.tileToAttack.militaryUnit!!).getAttackingStrength() }
|
||||||
if (canKill != null) return canKill
|
if (canKill != null) return canKill
|
||||||
|
|
||||||
// otherwise pick the unit we can kill the fastest
|
// otherwise pick the unit we can kill the fastest
|
||||||
@ -216,7 +220,7 @@ object BattleHelper {
|
|||||||
return unitsToConsider.maxByOrNull { it.movementLeftAfterMovingToAttackTile }!!
|
return unitsToConsider.maxByOrNull { it.movementLeftAfterMovingToAttackTile }!!
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're ranged, prioritize what we can kill
|
// We're ranged, prioritize that we can kill
|
||||||
return unitsToConsider.minByOrNull {
|
return unitsToConsider.minByOrNull {
|
||||||
Battle.getMapCombatantOfTile(it.tileToAttack)!!.getHealth()
|
Battle.getMapCombatantOfTile(it.tileToAttack)!!.getHealth()
|
||||||
}!!
|
}!!
|
||||||
|
Reference in New Issue
Block a user