mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-11 16:29:48 +07:00
Resolved #12522 - fixed crash when swapping while retreating
This commit is contained in:
@ -319,13 +319,12 @@ object UnitAutomation {
|
|||||||
val otherUnit = retreatTile.militaryUnit
|
val otherUnit = retreatTile.militaryUnit
|
||||||
if (otherUnit == null) {
|
if (otherUnit == null) {
|
||||||
// See if we can retreat to the tile
|
// See if we can retreat to the tile
|
||||||
if (unit.movement.canMoveTo(retreatTile)) {
|
if (!unit.movement.canMoveTo(retreatTile)) continue
|
||||||
unit.movement.moveToTile(retreatTile)
|
unit.movement.moveToTile(retreatTile)
|
||||||
return true
|
return true
|
||||||
}
|
|
||||||
} else if (otherUnit.civ == unit.civ) {
|
} else if (otherUnit.civ == unit.civ) {
|
||||||
// The tile is taken, lets see if we want to swap retreat to it
|
// The tile is taken, lets see if we want to swap retreat to it
|
||||||
if (otherUnit.health > 80) {
|
if (otherUnit.health <= 80) continue
|
||||||
if (otherUnit.baseUnit.isRanged()) {
|
if (otherUnit.baseUnit.isRanged()) {
|
||||||
// Don't swap ranged units closer than they have to be
|
// Don't swap ranged units closer than they have to be
|
||||||
val range = otherUnit.baseUnit.range
|
val range = otherUnit.baseUnit.range
|
||||||
@ -333,9 +332,11 @@ object UnitAutomation {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (unit.movement.canUnitSwapTo(retreatTile)) {
|
if (unit.movement.canUnitSwapTo(retreatTile)) {
|
||||||
|
unit.movement.headTowards(retreatTile) // we need to move through the intermediate tiles
|
||||||
|
if (unit.currentTile.neighbors.contains(otherUnit.currentTile)) {
|
||||||
unit.movement.swapMoveToTile(retreatTile)
|
unit.movement.swapMoveToTile(retreatTile)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -526,6 +526,7 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Swaps this unit with the unit on the given tile
|
* Swaps this unit with the unit on the given tile
|
||||||
|
* Limited to neighboring tiles only
|
||||||
* Precondition: this unit can swap-move to the given tile, as determined by canUnitSwapTo
|
* Precondition: this unit can swap-move to the given tile, as determined by canUnitSwapTo
|
||||||
*/
|
*/
|
||||||
fun swapMoveToTile(destination: Tile) {
|
fun swapMoveToTile(destination: Tile) {
|
||||||
|
Reference in New Issue
Block a user