mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Display Movement Paths (#4114)
This commit is contained in:
parent
7a9f111125
commit
a99cca5b28
@ -113,7 +113,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not consider if the destination tile can actually be entered, use canMoveTo for that.
|
||||
* Does not consider if the [destination] tile can actually be entered, use [canMoveTo] for that.
|
||||
* Returns an empty list if there's no way to get to the destination.
|
||||
*/
|
||||
fun getShortestPath(destination: TileInfo): List<TileInfo> {
|
||||
@ -152,7 +152,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
val path = mutableListOf(destination) // Traverse the tree upwards to get the list of tiles leading to the destination,
|
||||
// Get the tile from which the distance to the final tile in least -
|
||||
// this is so that when we finally get there, we'll have as many movement points as possible
|
||||
var intermediateTile = distanceToDestination.minBy { it.value }!!.key
|
||||
var intermediateTile = distanceToDestination.minByOrNull { it.value }!!.key
|
||||
while (intermediateTile != currentTile) {
|
||||
path.add(intermediateTile)
|
||||
intermediateTile = movementTreeParents[intermediateTile]!!
|
||||
|
@ -44,6 +44,8 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
|
||||
private val unitActionOverlays: ArrayList<Actor> = ArrayList()
|
||||
|
||||
private val unitMovementPaths: HashMap<MapUnit, ArrayList<TileInfo>> = HashMap()
|
||||
|
||||
init {
|
||||
if (Gdx.app.type == Application.ApplicationType.Desktop) this.setFlingTime(0f)
|
||||
continuousScrollingX = tileMap.mapParameters.worldWrap
|
||||
@ -135,6 +137,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
private fun onTileClicked(tileInfo: TileInfo) {
|
||||
removeUnitActionOverlay()
|
||||
selectedTile = tileInfo
|
||||
unitMovementPaths.clear()
|
||||
|
||||
val unitTable = worldScreen.bottomUnitTable
|
||||
val previousSelectedUnits = unitTable.selectedUnits.toList() // create copy
|
||||
@ -160,6 +163,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
else {
|
||||
// this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread
|
||||
addTileOverlaysWithUnitMovement(previousSelectedUnits, tileInfo)
|
||||
|
||||
}
|
||||
} else addTileOverlays(tileInfo) // no unit movement but display the units in the tile etc.
|
||||
|
||||
@ -251,14 +255,19 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
|
||||
val unitToTurnsToTile = HashMap<MapUnit, Int>()
|
||||
for (unit in selectedUnits) {
|
||||
val shortestPath = ArrayList<TileInfo>()
|
||||
val turnsToGetThere = if (unit.type.isAirUnit()) {
|
||||
if (unit.movement.canReach(tileInfo)) 1
|
||||
else 0
|
||||
} else if (unit.action == Constants.unitActionParadrop) {
|
||||
if (unit.movement.canReach(tileInfo)) 1
|
||||
else 0
|
||||
} else
|
||||
unit.movement.getShortestPath(tileInfo).size // this is what takes the most time, tbh
|
||||
} else {
|
||||
// this is the most time-consuming call
|
||||
shortestPath.addAll(unit.movement.getShortestPath(tileInfo))
|
||||
shortestPath.size
|
||||
}
|
||||
unitMovementPaths[unit] = shortestPath
|
||||
unitToTurnsToTile[unit] = turnsToGetThere
|
||||
}
|
||||
|
||||
@ -518,6 +527,14 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
}
|
||||
}
|
||||
|
||||
// Movement paths
|
||||
if (unitMovementPaths.containsKey(unit)) {
|
||||
for (tile in unitMovementPaths[unit]!!) {
|
||||
for (tileToColor in tileGroups[tile]!!)
|
||||
tileToColor.showCircle(Color.SKY, 0.8f)
|
||||
}
|
||||
}
|
||||
|
||||
if(unit.isMoving()) {
|
||||
val destinationTileGroups = tileGroups[unit.getMovementDestination()]!!
|
||||
for (tileGroup in destinationTileGroups)
|
||||
|
Loading…
x
Reference in New Issue
Block a user