mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
Resolve #8371 - prioritize pathfinding direction
This commit is contained in:
parent
22f9936a34
commit
4a8b949df8
@ -7,6 +7,8 @@ import com.unciv.logic.civilization.CivilizationInfo
|
|||||||
import com.unciv.models.helpers.UnitMovementMemoryType
|
import com.unciv.models.helpers.UnitMovementMemoryType
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
|
|
||||||
|
var totalPathfindingMilis:Long = 0
|
||||||
|
|
||||||
class UnitMovementAlgorithms(val unit: MapUnit) {
|
class UnitMovementAlgorithms(val unit: MapUnit) {
|
||||||
|
|
||||||
private val pathfindingCache = PathfindingCache(unit)
|
private val pathfindingCache = PathfindingCache(unit)
|
||||||
@ -221,13 +223,22 @@ class UnitMovementAlgorithms(val unit: MapUnit) {
|
|||||||
val newTilesToCheck = ArrayList<TileInfo>()
|
val newTilesToCheck = ArrayList<TileInfo>()
|
||||||
var considerZoneOfControl = true // only for first distance!
|
var considerZoneOfControl = true // only for first distance!
|
||||||
val visitedTiles: HashSet<TileInfo> = hashSetOf(currentTile)
|
val visitedTiles: HashSet<TileInfo> = hashSetOf(currentTile)
|
||||||
|
|
||||||
|
val startTime = System.currentTimeMillis()
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (distance == 2) { // only set this once after distance > 1
|
if (distance == 2) { // only set this once after distance > 1
|
||||||
movementThisTurn = unit.getMaxMovement().toFloat()
|
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!
|
considerZoneOfControl = false // by then units would have moved around, we don't need to consider untenable futures when it harms performance!
|
||||||
}
|
}
|
||||||
newTilesToCheck.clear()
|
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) {
|
val distanceToTilesThisTurn = if (distance == 1) {
|
||||||
getDistanceToTiles(considerZoneOfControl) // check cache
|
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
|
path.reverse() // and reverse in order to get the list in chronological order
|
||||||
pathfindingCache.setShortestPathCache(destination, path)
|
pathfindingCache.setShortestPathCache(destination, path)
|
||||||
|
|
||||||
|
val totalTime = System.currentTimeMillis() - startTime
|
||||||
|
|
||||||
|
totalPathfindingMilis += totalTime
|
||||||
return path
|
return path
|
||||||
} else {
|
} else {
|
||||||
if (movementTreeParents.containsKey(reachableTile)) continue // We cannot be faster than anything existing...
|
if (movementTreeParents.containsKey(reachableTile)) continue // We cannot be faster than anything existing...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user