mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 19:43:13 -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.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<TileInfo>()
|
||||
var considerZoneOfControl = true // only for first distance!
|
||||
val visitedTiles: HashSet<TileInfo> = 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...
|
||||
|
Loading…
x
Reference in New Issue
Block a user