Solved a super-rare bug where the game would get stuck if you expanded the city onto a tile with an enemy that couldn't be teleported anywhere else - kudos Groundless Name!

This commit is contained in:
Yair Morgenstern 2018-12-04 11:45:16 +02:00
parent c12906f63b
commit bc1b1e7672
2 changed files with 16 additions and 5 deletions

View File

@ -20,9 +20,9 @@ android {
defaultConfig {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 27
versionCode 172
versionName "2.10.9"
targetSdkVersion 28
versionCode 173
versionName "2.10.10"
}
// Had to add this crap for Travis to build, it wanted to sign the app

View File

@ -183,13 +183,24 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
fun teleportToClosestMoveableTile(){
var allowedTile:TileInfo? = null
var distance=0
while(allowedTile==null){
while(allowedTile==null && distance<5){
distance++
allowedTile = unit.getTile().getTilesAtDistance(distance)
.firstOrNull{unit.canMoveTo(it)}
}
// No tile within 4 spaces? move him to a city.
// When we didn't limit the allowed distance the game would sometimes spend a whole minute looking for a suitable tile.
if(allowedTile==null){
for(city in unit.civInfo.cities){
allowedTile = city.getCenterTile().getTilesInDistance(1)
.firstOrNull { unit.canMoveTo(it) }
if(allowedTile!=null) break
}
}
unit.removeFromTile() // we "teleport" them away
unit.putInTile(allowedTile)
if(allowedTile!=null) // it's possible that there is no close tile, and all the guy's cities are full. Screw him then.
unit.putInTile(allowedTile)
}
}