void Pathfinding::AddChild(PathNode childNode, PathNode* currNode, PathNode* goal, Direction::DIRECTION facing) { int col = round(childNode.xPos + 14.5f) - 1; int row = (MazeLoader::GetMazeHeight()) - round(childNode.zPos + 15.5f); //Check surroundings for walkable tiles and if in closed list if ((col >= 0 && row >= 0) && ((UINT)col <= MazeLoader::GetMazeWidth() && (UINT)row <= MazeLoader::GetMazeHeight())) { if (!MazeLoader::IsBlocked(row, col)) { if (!InClosedList(&childNode)) { childNode.facing = facing; int g = currNode->gCost + childNode.getDistanceFromParent(childNode, currNode); int f = g + childNode.getDistance(goal, childNode.xPos, childNode.zPos); //If it's already in the open list if (InOpenList(&childNode)) { if (childNode.gCost > g) { childNode.setParent(currNode); childNode.fCost = f; childNode.gCost = g; } } else { //Add it to the openList with the current node as the parent PathNode* newChildNode = new PathNode(childNode.xPos, childNode.zPos, g, f, currNode, facing); mOpenList.push_back(newChildNode); } } } } }