mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Solved rare teleport bug
This commit is contained in:
parent
7abaa11fd4
commit
eb7cf85482
@ -479,7 +479,7 @@ class CityInfo {
|
||||
|
||||
// Edge case! What if a water unit is in a city, and you raze the city?
|
||||
// Well, the water unit has to return to the water!
|
||||
for (unit in getCenterTile().getUnits()) {
|
||||
for (unit in getCenterTile().getUnits().toList()) {
|
||||
if (!unit.movement.canPassThrough(getCenterTile()))
|
||||
unit.movement.teleportToClosestMoveableTile()
|
||||
}
|
||||
|
@ -340,7 +340,8 @@ class DiplomacyManager() {
|
||||
hasOpenBorders = newHasOpenBorders
|
||||
|
||||
if (bordersWereClosed) { // borders were closed, get out!
|
||||
for (unit in civInfo.getCivUnits().filter { it.currentTile.getOwner()?.civName == otherCivName }) {
|
||||
for (unit in civInfo.getCivUnits()
|
||||
.filter { it.currentTile.getOwner()?.civName == otherCivName }.toList()) {
|
||||
unit.movement.teleportToClosestMoveableTile()
|
||||
}
|
||||
}
|
||||
@ -597,7 +598,7 @@ class DiplomacyManager() {
|
||||
diplomaticStatus = DiplomaticStatus.Peace
|
||||
val otherCiv = otherCiv()
|
||||
// Get out of others' territory
|
||||
for (unit in civInfo.getCivUnits().filter { it.getTile().getOwner() == otherCiv })
|
||||
for (unit in civInfo.getCivUnits().filter { it.getTile().getOwner() == otherCiv }.toList())
|
||||
unit.movement.teleportToClosestMoveableTile()
|
||||
|
||||
for (thirdCiv in civInfo.getKnownCivs()) {
|
||||
|
@ -291,6 +291,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
* This will not use movement points or check for a possible route.
|
||||
* It is used e.g. if an enemy city expands its borders, or trades or diplomacy change a unit's
|
||||
* allowed position.
|
||||
* CAN DESTROY THE UNIT.
|
||||
*/
|
||||
fun teleportToClosestMoveableTile() {
|
||||
var allowedTile: TileInfo? = null
|
||||
@ -310,13 +311,16 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
if (allowedTile != null) break
|
||||
}
|
||||
}
|
||||
unit.removeFromTile() // we "teleport" them away
|
||||
if (allowedTile != null) { // it's possible that there is no close tile, and all the guy's cities are full. Screw him then.
|
||||
if (allowedTile != null) {
|
||||
unit.removeFromTile() // we "teleport" them away
|
||||
unit.putInTile(allowedTile)
|
||||
// Cancel sleep or fortification if forcibly displaced - for now, leave movement / auto / explore orders
|
||||
if (unit.isSleeping() || unit.isFortified())
|
||||
unit.action = null
|
||||
}
|
||||
// it's possible that there is no close tile, and all the guy's cities are full.
|
||||
// Nothing we can do.
|
||||
else unit.destroy()
|
||||
}
|
||||
|
||||
fun moveToTile(destination: TileInfo) {
|
||||
|
Loading…
Reference in New Issue
Block a user