#define ERROR_TARGET std::cout
#else
#define DEBUG_OUT(a) while(0)
-#define INFO_TARGET infostream
-#define VERBOSE_TARGET verbosestream
-#define ERROR_TARGET errorstream
+#define INFO_TARGET infostream << "pathfinder: "
+#define VERBOSE_TARGET verbosestream << "pathfinder: "
+#define ERROR_TARGET errorstream << "pathfinder: "
#endif
/******************************************************************************/
path_gridnode& endpos = getIndexElement(EndIndex);
if (!startpos.valid) {
- ERROR_TARGET << "invalid startpos" <<
+ VERBOSE_TARGET << "invalid startpos" <<
"Index: " << PPOS(StartIndex) <<
"Realpos: " << PPOS(getRealPos(StartIndex)) << std::endl;
return retval;
}
if (!endpos.valid) {
- ERROR_TARGET << "invalid stoppos" <<
+ VERBOSE_TARGET << "invalid stoppos" <<
"Index: " << PPOS(EndIndex) <<
"Realpos: " << PPOS(getRealPos(EndIndex)) << std::endl;
return retval;
print_path(path);
#endif
- //optimize path
- std::vector<v3s16> optimized_path;
-
- std::vector<v3s16>::iterator startpos = path.begin();
- optimized_path.push_back(source);
-
+ //finalize path
+ std::vector<v3s16> full_path;
for (std::vector<v3s16>::iterator i = path.begin();
- i != path.end(); i++) {
- if (!m_env->line_of_sight(
- tov3f(getIndexElement(*startpos).pos),
- tov3f(getIndexElement(*i).pos))) {
- optimized_path.push_back(getIndexElement(*(i-1)).pos);
- startpos = (i-1);
- }
+ i != path.end(); ++i) {
+ full_path.push_back(getIndexElement(*i).pos);
}
- optimized_path.push_back(destination);
-
#ifdef PATHFINDER_DEBUG
- std::cout << "Optimized path:" << std::endl;
- print_path(optimized_path);
+ std::cout << "full path:" << std::endl;
+ print_path(full_path);
#endif
#ifdef PATHFINDER_CALC_TIME
timespec ts2;
std::cout << "Calculating path took: " << (ts2.tv_sec - ts.tv_sec) <<
"s " << ms << "ms " << us << "us " << ns << "ns " << std::endl;
#endif
- return optimized_path;
+ return full_path;
}
else {
#ifdef PATHFINDER_DEBUG
if ((testpos.Y >= m_limits.Y.min) &&
(node_at_pos.param0 != CONTENT_IGNORE) &&
(node_at_pos.param0 != CONTENT_AIR)) {
- if (((pos2.Y - testpos.Y)*-1) <= m_maxdrop) {
+ if ((pos2.Y - testpos.Y - 1) <= m_maxdrop) {
retval.valid = true;
retval.value = 2;
//difference of y-pos +1 (target node is ABOVE solid node)
for (std::vector<v3s16>::iterator iter = directions.begin();
iter != directions.end();
- iter ++) {
+ ++iter) {
v3s16 pos1 = v3s16(srcpos.X + iter->X,0,srcpos.Z+iter->Z);
if (retdir != v3s16(0,0,0)) {
for (std::vector<v3s16>::iterator iter = directions.begin();
iter != directions.end();
- iter ++) {
+ ++iter) {
if(*iter == retdir) {
DEBUG_OUT("Pathfinder: removing return direction" << std::endl);
directions.erase(iter);
" out of range (" << m_limits.X.max << "," <<
m_limits.Y.max << "," << m_limits.Z.max
<<")" << std::endl);
+ direction = get_dir_heuristic(directions,g_pos);
continue;
}
if (!g_pos2.valid) {
VERBOSE_TARGET << LVL "Pathfinder: no data for new position: "
<< PPOS(ipos2) << std::endl;
+ direction = get_dir_heuristic(directions,g_pos);
continue;
}
unsigned int current = 0;
for (std::vector<v3s16>::iterator i = path.begin();
- i != path.end(); i++) {
+ i != path.end(); ++i) {
std::cout << std::setw(3) << current << ":" << PPOS((*i)) << std::endl;
current++;
}