Unreachable tiles for air units merged with the rest of the 'can move tile to' logic

This commit is contained in:
Yair Morgenstern 2020-09-11 15:57:23 +03:00
parent 7e36b51db5
commit b9938eb116
2 changed files with 5 additions and 6 deletions

View file

@ -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<TileInfo> {
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*

View file

@ -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 {