update
This commit is contained in:
+17
-17
@@ -1,4 +1,6 @@
|
||||
#include "pathfinder.h"
|
||||
#include "terrainmovementmanager.h"
|
||||
#include "unitconfig.h"
|
||||
#include <cmath>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
@@ -74,7 +76,9 @@ std::vector<std::pair<int, int>> Pathfinder::findPath(
|
||||
int startX, int startY,
|
||||
int goalX, int goalY,
|
||||
Matrix2D<TerrainPoint> *mapPoints,
|
||||
int numPoints05)
|
||||
int numPoints05,
|
||||
MovementDomain domain,
|
||||
const UnitConfig *unitConfig)
|
||||
{
|
||||
std::vector<std::pair<int, int>> path;
|
||||
if (startX == goalX && startY == goalY) {
|
||||
@@ -86,6 +90,11 @@ std::vector<std::pair<int, int>> Pathfinder::findPath(
|
||||
return path;
|
||||
}
|
||||
|
||||
// Goal hex must be passable for this unit/domain
|
||||
if (!TerrainMovementManager::instance().isHexPassable(goalX, goalY, domain, mapPoints, numPoints05, unitConfig)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
std::priority_queue<Node, std::vector<Node>, std::greater<Node>> openSet;
|
||||
std::unordered_map<int, float> gScore;
|
||||
std::unordered_map<int, int> cameFrom;
|
||||
@@ -94,7 +103,7 @@ std::vector<std::pair<int, int>> Pathfinder::findPath(
|
||||
gScore[startPacked] = 0.0f;
|
||||
openSet.push({startX, startY, 0.0f, (float)hexDistance(startX, startY, goalX, goalY)});
|
||||
|
||||
int maxIterations = 3000;
|
||||
int maxIterations = 5000;
|
||||
int iterations = 0;
|
||||
|
||||
bool found = false;
|
||||
@@ -117,23 +126,14 @@ std::vector<std::pair<int, int>> Pathfinder::findPath(
|
||||
|
||||
if (nx < 0 || nx >= MAP_WIDTH || ny < 0 || ny >= MAP_HEIGHT) continue;
|
||||
|
||||
float stepCost = 1.0f;
|
||||
|
||||
// Elevation check if terrain points are available
|
||||
if (mapPoints && numPoints05 > 0) {
|
||||
float scaleX = numPoints05 * 2.0f;
|
||||
float scaleY = numPoints05 / LOD_0_SIZE_Y;
|
||||
QVector2D nCenter = hexToWorld(nx, ny);
|
||||
int mapX = (int) std::round(nCenter.x() * scaleX);
|
||||
int mapY = (int) std::round(nCenter.y() * scaleY);
|
||||
if (mapX >= 0 && mapX < (int)mapPoints->getWidth() && mapY >= 0 && mapY < (int)mapPoints->getHeight()) {
|
||||
unsigned char h = mapPoints->operator()(mapX, mapY).height;
|
||||
// Slightly penalize water tiles or high mountains
|
||||
if (h < 5) stepCost += 4.0f;
|
||||
else if (h > 220) stepCost += 2.0f;
|
||||
}
|
||||
// Check if neighbor hex is passable for this unit's domain
|
||||
if (!TerrainMovementManager::instance().isHexPassable(nx, ny, domain, mapPoints, numPoints05, unitConfig)) {
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user