diff --git a/pathfinder.cpp b/pathfinder.cpp index 5a90cf7..e16da1e 100644 --- a/pathfinder.cpp +++ b/pathfinder.cpp @@ -101,7 +101,8 @@ std::vector> Pathfinder::findPath( int startPacked = packCoord(startX, startY); 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 iterations = 0; @@ -126,21 +127,23 @@ std::vector> Pathfinder::findPath( if (nx < 0 || nx >= MAP_WIDTH || ny < 0 || ny >= MAP_HEIGHT) continue; - // Check if neighbor hex is passable for this unit's domain - if (!TerrainMovementManager::instance().isHexPassable(nx, ny, domain, mapPoints, numPoints05, unitConfig)) { + // Calculate step cost taking into account terrain penalty and slope (uphill penalty or downhill bonus) + 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; } - // Step cost from configurable terrain movement manager - float stepCost = TerrainMovementManager::instance().getHexMovementCost(nx, ny, mapPoints, numPoints05); - float tentativeG = current.g + stepCost; int nPacked = packCoord(nx, ny); if (!gScore.count(nPacked) || tentativeG < gScore[nPacked]) { gScore[nPacked] = tentativeG; 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}); } }