From b9938eb116b35f3f2f639c2e210b48a0ee545b21 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 11 Sep 2020 15:57:23 +0300 Subject: [PATCH] Unreachable tiles for air units merged with the rest of the 'can move tile to' logic --- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 1 + core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 410545f9..7928bd3f 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -99,6 +99,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { return distanceToTiles } + /** Returns an empty list if there's no way to get there */ fun getShortestPath(destination: TileInfo): List { val currentTile = unit.getTile() if (currentTile.position == destination) return listOf(currentTile) // edge case that's needed, so that workers will know that they can reach their own tile. *sigh* diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index 6f11c010..2df141b2 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -147,18 +147,16 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap private fun addTileOverlaysWithUnitMovement(selectedUnit: MapUnit, tileInfo: TileInfo) { - // some code is copied from canReach not to call getShortestPath on the main thread before calling it on this thread - if (selectedUnit.type.isAirUnit() && selectedUnit.currentTile.aerialDistanceTo(tileInfo) > selectedUnit.getRange()*2) { - addTileOverlays(tileInfo) - return - } thread(name="TurnsToGetThere") { /** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate threads. * And so, all UI editing will be done on the main thread. * The only "heavy lifting" that needs to be done is getting the turns to get there, * so that and that alone will be relegated to the concurrent thread. */ - val turnsToGetThere = if(selectedUnit.type.isAirUnit()) 1 + val turnsToGetThere = if(selectedUnit.type.isAirUnit()){ + if (selectedUnit.movement.canReach(tileInfo)) 1 + else 0 + } else selectedUnit.movement.getShortestPath(tileInfo).size // this is what takes the most time, tbh Gdx.app.postRunnable {