Use calculateStepCost with slope penalties in Pathfinder::findPath
This commit is contained in:
+10
-7
@@ -101,7 +101,8 @@ std::vector<std::pair<int, int>> Pathfinder::findPath(
|
|||||||
|
|
||||||
int startPacked = packCoord(startX, startY);
|
int startPacked = packCoord(startX, startY);
|
||||||
gScore[startPacked] = 0.0f;
|
gScore[startPacked] = 0.0f;
|
||||||
openSet.push({startX, startY, 0.0f, (float)hexDistance(startX, startY, goalX, goalY)});
|
float minCost = TerrainMovementManager::instance().getConfig().minStepCost;
|
||||||
|
openSet.push({startX, startY, 0.0f, (float)hexDistance(startX, startY, goalX, goalY) * minCost});
|
||||||
|
|
||||||
int maxIterations = 5000;
|
int maxIterations = 5000;
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
@@ -126,21 +127,23 @@ std::vector<std::pair<int, int>> Pathfinder::findPath(
|
|||||||
|
|
||||||
if (nx < 0 || nx >= MAP_WIDTH || ny < 0 || ny >= MAP_HEIGHT) continue;
|
if (nx < 0 || nx >= MAP_WIDTH || ny < 0 || ny >= MAP_HEIGHT) continue;
|
||||||
|
|
||||||
// Check if neighbor hex is passable for this unit's domain
|
// Calculate step cost taking into account terrain penalty and slope (uphill penalty or downhill bonus)
|
||||||
if (!TerrainMovementManager::instance().isHexPassable(nx, ny, domain, mapPoints, numPoints05, unitConfig)) {
|
float stepCost = TerrainMovementManager::instance().calculateStepCost(
|
||||||
|
current.x, current.y, nx, ny, domain, mapPoints, numPoints05, unitConfig
|
||||||
|
);
|
||||||
|
|
||||||
|
// If impassable or cliff too steep
|
||||||
|
if (stepCost < 0.0f) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step cost from configurable terrain movement manager
|
|
||||||
float stepCost = TerrainMovementManager::instance().getHexMovementCost(nx, ny, mapPoints, numPoints05);
|
|
||||||
|
|
||||||
float tentativeG = current.g + stepCost;
|
float tentativeG = current.g + stepCost;
|
||||||
int nPacked = packCoord(nx, ny);
|
int nPacked = packCoord(nx, ny);
|
||||||
|
|
||||||
if (!gScore.count(nPacked) || tentativeG < gScore[nPacked]) {
|
if (!gScore.count(nPacked) || tentativeG < gScore[nPacked]) {
|
||||||
gScore[nPacked] = tentativeG;
|
gScore[nPacked] = tentativeG;
|
||||||
cameFrom[nPacked] = currPacked;
|
cameFrom[nPacked] = currPacked;
|
||||||
float h = (float) hexDistance(nx, ny, goalX, goalY);
|
float h = (float) hexDistance(nx, ny, goalX, goalY) * minCost;
|
||||||
openSet.push({nx, ny, tentativeG, tentativeG + h});
|
openSet.push({nx, ny, tentativeG, tentativeG + h});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user