- }
- else {
- DEBUG_OUT("Pathfinder: didn't find any valid direction clearing"
- << std::endl);
- directions.clear();
- }
- DEBUG_OUT("Pathfinder: remaining dirs at end:" << directions.size()
- << std::endl);
- return retdir;
-}
-
-/******************************************************************************/
-bool Pathfinder::updateCostHeuristic( v3s16 ipos,
- v3s16 srcdir,
- int current_cost,
- int level)
-{
-
- PathGridnode &g_pos = getIndexElement(ipos);
- g_pos.totalcost = current_cost;
- g_pos.sourcedir = srcdir;
-
- level ++;
-
- //check if target has been found
- if (g_pos.target) {
- m_min_target_distance = current_cost;
- DEBUG_OUT(LVL " Pathfinder: target found!" << std::endl);
- return true;
- }
-
- bool retval = false;
-
- std::vector<v3s16> directions;
-
- directions.push_back(v3s16( 1, 0, 0));
- directions.push_back(v3s16(-1, 0, 0));
- directions.push_back(v3s16( 0, 0, 1));
- directions.push_back(v3s16( 0, 0, -1));
-
- v3s16 direction = getDirHeuristic(directions, g_pos);
-
- while (direction != v3s16(0, 0, 0) && (!retval)) {
-
- if (direction != srcdir) {
- PathCost cost = g_pos.getCost(direction);
-
- if (cost.valid) {
- direction.Y = cost.direction;
-
- v3s16 ipos2 = ipos + direction;
-
- if (!isValidIndex(ipos2)) {
- DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) <<
- " out of range, max=" << PP(m_limits.MaxEdge) << std::endl);
- direction = getDirHeuristic(directions, g_pos);
- continue;
- }
-
- PathGridnode &g_pos2 = getIndexElement(ipos2);
-
- if (!g_pos2.valid) {
- VERBOSE_TARGET << LVL "Pathfinder: no data for new position: "
- << PP(ipos2) << std::endl;
- direction = getDirHeuristic(directions, g_pos);
- continue;
- }
-
- assert(cost.value > 0);