mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 01:39:40 +07:00
Correct swapping of the carriers with payloads (#6594)
* Comments are added * Correct swap of carriers with payloads
This commit is contained in:
@ -535,13 +535,30 @@ class UnitMovementAlgorithms(val unit: MapUnit) {
|
|||||||
val ourOldPosition = unit.getTile()
|
val ourOldPosition = unit.getTile()
|
||||||
val theirOldPosition = otherUnit.getTile()
|
val theirOldPosition = otherUnit.getTile()
|
||||||
|
|
||||||
|
val ourPayload = ourOldPosition.getUnits().filter { it.isTransported && unit.canTransport(it) }.toList()
|
||||||
|
val theirPayload = theirOldPosition.getUnits().filter { it.isTransported && otherUnit.canTransport(it) }.toList()
|
||||||
|
|
||||||
// Swap the units
|
// Swap the units
|
||||||
|
// Step 1: Release the destination tile
|
||||||
otherUnit.removeFromTile()
|
otherUnit.removeFromTile()
|
||||||
|
for (payload in theirPayload)
|
||||||
|
payload.removeFromTile()
|
||||||
|
// Step 2: Perform the movement
|
||||||
unit.movement.moveToTile(destination)
|
unit.movement.moveToTile(destination)
|
||||||
|
// Step 3: Release the newly taken tile
|
||||||
unit.removeFromTile()
|
unit.removeFromTile()
|
||||||
|
for (payload in ourPayload)
|
||||||
|
payload.removeFromTile()
|
||||||
|
// Step 4: Perform the another movement
|
||||||
otherUnit.putInTile(theirOldPosition)
|
otherUnit.putInTile(theirOldPosition)
|
||||||
|
for (payload in theirPayload)
|
||||||
|
payload.putInTile(theirOldPosition)
|
||||||
otherUnit.movement.moveToTile(ourOldPosition)
|
otherUnit.movement.moveToTile(ourOldPosition)
|
||||||
|
// Step 5: Restore the position in the new tile
|
||||||
unit.putInTile(theirOldPosition)
|
unit.putInTile(theirOldPosition)
|
||||||
|
for (payload in ourPayload)
|
||||||
|
payload.putInTile(theirOldPosition)
|
||||||
|
// Step 6: Update states
|
||||||
otherUnit.mostRecentMoveType = UnitMovementMemoryType.UnitMoved
|
otherUnit.mostRecentMoveType = UnitMovementMemoryType.UnitMoved
|
||||||
unit.mostRecentMoveType = UnitMovementMemoryType.UnitMoved
|
unit.mostRecentMoveType = UnitMovementMemoryType.UnitMoved
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user