diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 790628b0e0..8d0833a042 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -7,6 +7,8 @@ import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.helpers.UnitMovementMemoryType import com.unciv.models.ruleset.unique.UniqueType +var totalPathfindingMilis:Long = 0 + class UnitMovementAlgorithms(val unit: MapUnit) { private val pathfindingCache = PathfindingCache(unit) @@ -221,13 +223,22 @@ class UnitMovementAlgorithms(val unit: MapUnit) { val newTilesToCheck = ArrayList() var considerZoneOfControl = true // only for first distance! val visitedTiles: HashSet = hashSetOf(currentTile) + + val startTime = System.currentTimeMillis() + while (true) { if (distance == 2) { // only set this once after distance > 1 movementThisTurn = unit.getMaxMovement().toFloat() considerZoneOfControl = false // by then units would have moved around, we don't need to consider untenable futures when it harms performance! } newTilesToCheck.clear() - for (tileToCheck in tilesToCheck) { + + var tilesByPreference = tilesToCheck //.sortedBy { it.aerialDistanceTo(destination) } + // Avoid embarkation when possible +// if (unit.type.isLandUnit()) tilesByPreference = tilesByPreference.sortedByDescending { it.isLand } + + + for (tileToCheck in tilesByPreference) { val distanceToTilesThisTurn = if (distance == 1) { getDistanceToTiles(considerZoneOfControl) // check cache } @@ -248,6 +259,10 @@ class UnitMovementAlgorithms(val unit: MapUnit) { } path.reverse() // and reverse in order to get the list in chronological order pathfindingCache.setShortestPathCache(destination, path) + + val totalTime = System.currentTimeMillis() - startTime + + totalPathfindingMilis += totalTime return path } else { if (movementTreeParents.containsKey(reachableTile)) continue // We cannot be faster than anything existing...