"there does not exist any constructor to convert from const creature to creature"
have been stuck on this pls help
bool Map::getPathTo(const Creature* creature, const Position& destPos,
std::list<Direction>& listDir, int32_t maxSearchDist /*= -1*/)
{
if (canWalkTo(creature, destPos) == NULL) {
return false;
}
listDir.clear();
Position startPos = destPos;
Position endPos = creature->getPosition();
if (startPos.z != endPos.z) {
return false;
}
//AStarNodes nodes(pos.x, pos.y);
AStarNodes nodes;
AStarNode* startNode = nodes.createOpenNode();
startNode->x = startPos.x;
startNode->y = startPos.y;
startNode->g = 0;
startNode->h = nodes.getEstimatedDistance(startPos.x, startPos.y, endPos.x, endPos.y);
startNode->f = startNode->g + startNode->h;
startNode->parent = NULL;
Position pos;
pos.z = startPos.z;
static int32_t neighbourOrderList[8][2] =
{
{-1, 0},
{0, 1},
{1, 0},
{0, -1},
//diagonal
{-1, -1},
{1, -1},
{1, 1},
{-1, 1},
};
const Tile* tile = NULL;
AStarNode* found = NULL;
while (maxSearchDist != -1 || nodes.countClosedNodes() < 100) {
AStarNode* n = nodes.getBestNode();
if (!n) {
listDir.clear();
return false; //no path found
}
if (n->x == endPos.x && n->y == endPos.y) {
found = n;
break;
}
else {
for (int i = 0; i < 8; ++i) {
pos.x = n->x + neighbourOrderList[i][0];
pos.y = n->y + neighbourOrderList[i][1];
bool outOfRange = false;
if (maxSearchDist != -1 && (std::abs(endPos.x - pos.x) > maxSearchDist ||
std::abs(endPos.y - pos.y) > maxSearchDist)) {
outOfRange = true;
}
if (!outOfRange && (tile = canWalkTo(creature, pos))) {
//The cost (g) for this neighbour
int32_t cost = nodes.getMapWalkCost(creature, n, tile, pos);
int32_t extraCost = nodes.getTileWalkCost(creature, tile);
int32_t newg = n->g + cost + extraCost;
//Check if the node is already in the closed/open list
//If it exists and the nodes already on them has a lower cost (g) then we can ignore this neighbour node
AStarNode* neighbourNode = nodes.getNodeInList(pos.x, pos.y);
if (neighbourNode) {
if (neighbourNode->g <= newg) {
//The node on the closed/open list is cheaper than this one
continue;
}
nodes.openNode(neighbourNode);
}
else {
//Does not exist in the open/closed list, create a new node
neighbourNode = nodes.createOpenNode();
if (!neighbourNode) {
//seems we ran out of nodes
listDir.clear();
return false;
}
}
//This node is the best node so far with this state
neighbourNode->x = pos.x;
neighbourNode->y = pos.y;
neighbourNode->parent = n;
neighbourNode->g = newg;
neighbourNode->h = nodes.getEstimatedDistance(neighbourNode->x, neighbourNode->y,
endPos.x, endPos.y);
neighbourNode->f = neighbourNode->g + neighbourNode->h;
}
}
nodes.closeNode(n);
}
}
int32_t prevx = endPos.x;
int32_t prevy = endPos.y;
int32_t dx, dy;
while (found) {
pos.x = found->x;
pos.y = found->y;
found = found->parent;
dx = pos.x - prevx;
dy = pos.y - prevy;
prevx = pos.x;
prevy = pos.y;
if (dx == -1 && dy == -1) {
listDir.push_back(DIRECTION_NORTHWEST);
}
else if (dx == 1 && dy == -1) {
listDir.push_back(DIRECTION_NORTHEAST);
}
else if (dx == -1 && dy == 1) {
listDir.push_back(DIRECTION_SOUTHWEST);
}
else if (dx == 1 && dy == 1) {
listDir.push_back(DIRECTION_SOUTHEAST);
}
else if (dx == -1) {
listDir.push_back(DIRECTION_WEST);
}
else if (dx == 1) {
listDir.push_back(DIRECTION_EAST);
}
else if (dy == -1) {
listDir.push_back(DIRECTION_NORTH);
}
else if (dy == 1) {
listDir.push_back(DIRECTION_SOUTH);
}
}
return !listDir.empty();
}