3 Copyright (C) 2013 sapier, sapier at gmx dot net
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /******************************************************************************/
22 /******************************************************************************/
24 #include "pathfinder.h"
26 #ifdef PATHFINDER_DEBUG
29 #ifdef PATHFINDER_CALC_TIME
33 /******************************************************************************/
34 /* Typedefs and macros */
35 /******************************************************************************/
37 //#define PATHFINDER_CALC_TIME
39 /** shortcut to print a 3d pos */
40 #define PPOS(pos) "(" << pos.X << "," << pos.Y << "," << pos.Z << ")"
42 #define LVL "(" << level << ")" <<
44 #ifdef PATHFINDER_DEBUG
45 #define DEBUG_OUT(a) std::cout << a
46 #define INFO_TARGET std::cout
47 #define VERBOSE_TARGET std::cout
48 #define ERROR_TARGET std::cout
50 #define DEBUG_OUT(a) while(0)
51 #define INFO_TARGET infostream
52 #define VERBOSE_TARGET verbosestream
53 #define ERROR_TARGET errorstream
56 /******************************************************************************/
58 /******************************************************************************/
60 std::vector<v3s16> get_Path(ServerEnvironment* env,
63 unsigned int searchdistance,
64 unsigned int max_jump,
65 unsigned int max_drop,
68 pathfinder searchclass;
70 return searchclass.get_Path(env,
72 searchdistance,max_jump,max_drop,algo);
75 /******************************************************************************/
76 path_cost::path_cost()
85 /******************************************************************************/
86 path_cost::path_cost(const path_cost& b) {
88 direction = b.direction;
93 /******************************************************************************/
94 path_cost& path_cost::operator= (const path_cost& b) {
96 direction = b.direction;
103 /******************************************************************************/
104 path_gridnode::path_gridnode()
109 sourcedir(v3s16(0,0,0)),
118 /******************************************************************************/
119 path_gridnode::path_gridnode(const path_gridnode& b)
123 totalcost(b.totalcost),
124 sourcedir(b.sourcedir),
125 surfaces(b.surfaces),
127 is_element(b.is_element),
131 directions[DIR_XP] = b.directions[DIR_XP];
132 directions[DIR_XM] = b.directions[DIR_XM];
133 directions[DIR_ZP] = b.directions[DIR_ZP];
134 directions[DIR_ZM] = b.directions[DIR_ZM];
137 /******************************************************************************/
138 path_gridnode& path_gridnode::operator= (const path_gridnode& b) {
142 is_element = b.is_element;
143 totalcost = b.totalcost;
144 sourcedir = b.sourcedir;
145 surfaces = b.surfaces;
149 directions[DIR_XP] = b.directions[DIR_XP];
150 directions[DIR_XM] = b.directions[DIR_XM];
151 directions[DIR_ZP] = b.directions[DIR_ZP];
152 directions[DIR_ZM] = b.directions[DIR_ZM];
157 /******************************************************************************/
158 path_cost path_gridnode::get_cost(v3s16 dir) {
160 return directions[DIR_XP];
163 return directions[DIR_XM];
166 return directions[DIR_ZP];
169 return directions[DIR_ZM];
175 /******************************************************************************/
176 void path_gridnode::set_cost(v3s16 dir,path_cost cost) {
178 directions[DIR_XP] = cost;
181 directions[DIR_XM] = cost;
184 directions[DIR_ZP] = cost;
187 directions[DIR_ZM] = cost;
191 /******************************************************************************/
192 std::vector<v3s16> pathfinder::get_Path(ServerEnvironment* env,
195 unsigned int searchdistance,
196 unsigned int max_jump,
197 unsigned int max_drop,
199 #ifdef PATHFINDER_CALC_TIME
201 clock_gettime(CLOCK_REALTIME, &ts);
203 std::vector<v3s16> retval;
207 std::cout << "missing environment pointer" << std::endl;
211 m_searchdistance = searchdistance;
213 m_maxjump = max_jump;
214 m_maxdrop = max_drop;
216 m_destination = destination;
217 m_min_target_distance = -1;
220 if (algo == A_PLAIN_NP) {
224 int min_x = MYMIN(source.X,destination.X);
225 int max_x = MYMAX(source.X,destination.X);
227 int min_y = MYMIN(source.Y,destination.Y);
228 int max_y = MYMAX(source.Y,destination.Y);
230 int min_z = MYMIN(source.Z,destination.Z);
231 int max_z = MYMAX(source.Z,destination.Z);
233 m_limits.X.min = min_x - searchdistance;
234 m_limits.X.max = max_x + searchdistance;
235 m_limits.Y.min = min_y - searchdistance;
236 m_limits.Y.max = max_y + searchdistance;
237 m_limits.Z.min = min_z - searchdistance;
238 m_limits.Z.max = max_z + searchdistance;
240 m_max_index_x = m_limits.X.max - m_limits.X.min;
241 m_max_index_y = m_limits.Y.max - m_limits.Y.min;
242 m_max_index_z = m_limits.Z.max - m_limits.Z.min;
245 if (!build_costmap()) {
246 std::cout << "failed to build costmap" << std::endl;
249 #ifdef PATHFINDER_DEBUG
255 //validate and mark start and end pos
256 v3s16 StartIndex = getIndexPos(source);
257 v3s16 EndIndex = getIndexPos(destination);
259 path_gridnode& startpos = getIndexElement(StartIndex);
260 path_gridnode& endpos = getIndexElement(EndIndex);
262 if (!startpos.valid) {
263 std::cout << "invalid startpos" <<
264 "Index: " << PPOS(StartIndex) <<
265 "Realpos: " << PPOS(getRealPos(StartIndex)) << std::endl;
269 std::cout << "invalid stoppos" <<
270 "Index: " << PPOS(EndIndex) <<
271 "Realpos: " << PPOS(getRealPos(EndIndex)) << std::endl;
275 endpos.target = true;
276 startpos.source = true;
277 startpos.totalcost = 0;
279 bool update_cost_retval = false;
283 update_cost_retval = update_all_costs(StartIndex,v3s16(0,0,0),0,0);
287 update_cost_retval = update_cost_heuristic(StartIndex,v3s16(0,0,0),0,0);
290 std::cout << "missing algorithm"<< std::endl;
294 if (update_cost_retval) {
296 #ifdef PATHFINDER_DEBUG
297 std::cout << "Path to target found!" << std::endl;
302 std::vector<v3s16> path;
303 build_path(path,EndIndex,0);
305 #ifdef PATHFINDER_DEBUG
306 std::cout << "Full index path:" << std::endl;
311 std::vector<v3s16> optimized_path;
313 std::vector<v3s16>::iterator startpos = path.begin();
314 optimized_path.push_back(source);
316 for (std::vector<v3s16>::iterator i = path.begin();
317 i != path.end(); i++) {
318 if (!m_env->line_of_sight(
319 tov3f(getIndexElement(*startpos).pos),
320 tov3f(getIndexElement(*i).pos))) {
321 optimized_path.push_back(getIndexElement(*(i-1)).pos);
326 optimized_path.push_back(destination);
328 #ifdef PATHFINDER_DEBUG
329 std::cout << "Optimized path:" << std::endl;
330 print_path(optimized_path);
332 #ifdef PATHFINDER_CALC_TIME
334 clock_gettime(CLOCK_REALTIME, &ts2);
336 int ms = (ts2.tv_nsec - ts.tv_nsec)/(1000*1000);
337 int us = ((ts2.tv_nsec - ts.tv_nsec) - (ms*1000*1000))/1000;
338 int ns = ((ts2.tv_nsec - ts.tv_nsec) - ( (ms*1000*1000) + (us*1000)));
341 std::cout << "Calculating path took: " << (ts2.tv_sec - ts.tv_sec) <<
342 "s " << ms << "ms " << us << "us " << ns << "ns " << std::endl;
344 return optimized_path;
347 #ifdef PATHFINDER_DEBUG
350 std::cout << "failed to update cost map"<< std::endl;
358 /******************************************************************************/
359 pathfinder::pathfinder() :
366 m_min_target_distance(0),
369 m_destination(0,0,0),
377 /******************************************************************************/
378 v3s16 pathfinder::getRealPos(v3s16 ipos) {
382 retval.X += m_limits.X.min;
383 retval.Y += m_limits.Y.min;
384 retval.Z += m_limits.Z.min;
389 /******************************************************************************/
390 bool pathfinder::build_costmap()
392 INFO_TARGET << "Pathfinder build costmap: (" << m_limits.X.min << ","
393 << m_limits.Z.min << ") ("
394 << m_limits.X.max << ","
395 << m_limits.Z.max << ")"
397 m_data.resize(m_max_index_x);
398 for (int x = 0; x < m_max_index_x; x++) {
399 m_data[x].resize(m_max_index_z);
400 for (int z = 0; z < m_max_index_z; z++) {
401 m_data[x][z].resize(m_max_index_y);
404 for (int y = 0; y < m_max_index_y; y++) {
407 v3s16 realpos = getRealPos(ipos);
409 MapNode current = m_env->getMap().getNodeNoEx(realpos);
410 MapNode below = m_env->getMap().getNodeNoEx(realpos + v3s16(0,-1,0));
413 if ((current.param0 == CONTENT_IGNORE) ||
414 (below.param0 == CONTENT_IGNORE)) {
415 DEBUG_OUT("Pathfinder: " << PPOS(realpos) <<
416 " current or below is invalid element" << std::endl);
417 if (current.param0 == CONTENT_IGNORE) {
418 m_data[x][z][y].type = 'i';
419 DEBUG_OUT(x << "," << y << "," << z << ": " << 'i' << std::endl);
424 //don't add anything if it isn't an air node
425 if ((current.param0 != CONTENT_AIR) ||
426 (below.param0 == CONTENT_AIR )) {
427 DEBUG_OUT("Pathfinder: " << PPOS(realpos)
428 << " not on surface" << std::endl);
429 if (current.param0 != CONTENT_AIR) {
430 m_data[x][z][y].type = 's';
431 DEBUG_OUT(x << "," << y << "," << z << ": " << 's' << std::endl);
434 m_data[x][z][y].type = '-';
435 DEBUG_OUT(x << "," << y << "," << z << ": " << '-' << std::endl);
442 m_data[x][z][y].valid = true;
443 m_data[x][z][y].pos = realpos;
444 m_data[x][z][y].type = 'g';
445 DEBUG_OUT(x << "," << y << "," << z << ": " << 'a' << std::endl);
448 m_data[x][z][y].directions[DIR_XP] =
449 calc_cost(realpos,v3s16( 1,0, 0));
450 m_data[x][z][y].directions[DIR_XM] =
451 calc_cost(realpos,v3s16(-1,0, 0));
452 m_data[x][z][y].directions[DIR_ZP] =
453 calc_cost(realpos,v3s16( 0,0, 1));
454 m_data[x][z][y].directions[DIR_ZM] =
455 calc_cost(realpos,v3s16( 0,0,-1));
460 if (surfaces >= 1 ) {
461 for (int y = 0; y < m_max_index_y; y++) {
462 if (m_data[x][z][y].valid) {
463 m_data[x][z][y].surfaces = surfaces;
472 /******************************************************************************/
473 path_cost pathfinder::calc_cost(v3s16 pos,v3s16 dir) {
476 retval.updated = true;
478 v3s16 pos2 = pos + dir;
481 if ( (pos2.X < m_limits.X.min) ||
482 (pos2.X >= m_limits.X.max) ||
483 (pos2.Z < m_limits.Z.min) ||
484 (pos2.Z >= m_limits.Z.max)) {
485 DEBUG_OUT("Pathfinder: " << PPOS(pos2) <<
486 " no cost -> out of limits" << std::endl);
490 MapNode node_at_pos2 = m_env->getMap().getNodeNoEx(pos2);
492 //did we get information about node?
493 if (node_at_pos2.param0 == CONTENT_IGNORE ) {
494 VERBOSE_TARGET << "Pathfinder: (1) area at pos: "
495 << PPOS(pos2) << " not loaded";
499 if (node_at_pos2.param0 == CONTENT_AIR) {
500 MapNode node_below_pos2 =
501 m_env->getMap().getNodeNoEx(pos2 + v3s16(0,-1,0));
503 //did we get information about node?
504 if (node_below_pos2.param0 == CONTENT_IGNORE ) {
505 VERBOSE_TARGET << "Pathfinder: (2) area at pos: "
506 << PPOS((pos2 + v3s16(0,-1,0))) << " not loaded";
510 if (node_below_pos2.param0 != CONTENT_AIR) {
513 retval.direction = 0;
514 DEBUG_OUT("Pathfinder: "<< PPOS(pos)
515 << " cost same height found" << std::endl);
518 v3s16 testpos = pos2 - v3s16(0,-1,0);
519 MapNode node_at_pos = m_env->getMap().getNodeNoEx(testpos);
521 while ((node_at_pos.param0 != CONTENT_IGNORE) &&
522 (node_at_pos.param0 == CONTENT_AIR) &&
523 (testpos.Y > m_limits.Y.min)) {
524 testpos += v3s16(0,-1,0);
525 node_at_pos = m_env->getMap().getNodeNoEx(testpos);
528 //did we find surface?
529 if ((testpos.Y >= m_limits.Y.min) &&
530 (node_at_pos.param0 != CONTENT_IGNORE) &&
531 (node_at_pos.param0 != CONTENT_AIR)) {
532 if (((pos2.Y - testpos.Y)*-1) <= m_maxdrop) {
535 //difference of y-pos +1 (target node is ABOVE solid node)
536 retval.direction = ((testpos.Y - pos2.Y) +1);
537 DEBUG_OUT("Pathfinder cost below height found" << std::endl);
540 INFO_TARGET << "Pathfinder:"
541 " distance to surface below to big: "
542 << (testpos.Y - pos2.Y) << " max: " << m_maxdrop
547 DEBUG_OUT("Pathfinder: no surface below found" << std::endl);
552 v3s16 testpos = pos2;
553 MapNode node_at_pos = m_env->getMap().getNodeNoEx(testpos);
555 while ((node_at_pos.param0 != CONTENT_IGNORE) &&
556 (node_at_pos.param0 != CONTENT_AIR) &&
557 (testpos.Y < m_limits.Y.max)) {
558 testpos += v3s16(0,1,0);
559 node_at_pos = m_env->getMap().getNodeNoEx(testpos);
562 //did we find surface?
563 if ((testpos.Y <= m_limits.Y.max) &&
564 (node_at_pos.param0 == CONTENT_AIR)) {
566 if (testpos.Y - pos2.Y <= m_maxjump) {
569 retval.direction = (testpos.Y - pos2.Y);
570 DEBUG_OUT("Pathfinder cost above found" << std::endl);
573 DEBUG_OUT("Pathfinder: distance to surface above to big: "
574 << (testpos.Y - pos2.Y) << " max: " << m_maxjump
579 DEBUG_OUT("Pathfinder: no surface above found" << std::endl);
585 /******************************************************************************/
586 v3s16 pathfinder::getIndexPos(v3s16 pos) {
589 retval.X -= m_limits.X.min;
590 retval.Y -= m_limits.Y.min;
591 retval.Z -= m_limits.Z.min;
596 /******************************************************************************/
597 path_gridnode& pathfinder::getIndexElement(v3s16 ipos) {
598 return m_data[ipos.X][ipos.Z][ipos.Y];
601 /******************************************************************************/
602 bool pathfinder::valid_index(v3s16 index) {
603 if ( (index.X < m_max_index_x) &&
604 (index.Y < m_max_index_y) &&
605 (index.Z < m_max_index_z) &&
614 /******************************************************************************/
615 v3s16 pathfinder::invert(v3s16 pos) {
625 /******************************************************************************/
626 bool pathfinder::update_all_costs( v3s16 ipos,
631 path_gridnode& g_pos = getIndexElement(ipos);
632 g_pos.totalcost = current_cost;
633 g_pos.sourcedir = srcdir;
637 //check if target has been found
639 m_min_target_distance = current_cost;
640 DEBUG_OUT(LVL " Pathfinder: target found!" << std::endl);
646 std::vector<v3s16> directions;
648 directions.push_back(v3s16( 1,0, 0));
649 directions.push_back(v3s16(-1,0, 0));
650 directions.push_back(v3s16( 0,0, 1));
651 directions.push_back(v3s16( 0,0,-1));
653 for (unsigned int i=0; i < directions.size(); i++) {
654 if (directions[i] != srcdir) {
655 path_cost cost = g_pos.get_cost(directions[i]);
658 directions[i].Y = cost.direction;
660 v3s16 ipos2 = ipos + directions[i];
662 if (!valid_index(ipos2)) {
663 DEBUG_OUT(LVL " Pathfinder: " << PPOS(ipos2) <<
664 " out of range (" << m_limits.X.max << "," <<
665 m_limits.Y.max << "," << m_limits.Z.max
670 path_gridnode& g_pos2 = getIndexElement(ipos2);
673 VERBOSE_TARGET << LVL "Pathfinder: no data for new position: "
674 << PPOS(ipos2) << std::endl;
678 assert(cost.value > 0);
680 int new_cost = current_cost + cost.value;
682 // check if there already is a smaller path
683 if ((m_min_target_distance > 0) &&
684 (m_min_target_distance < new_cost)) {
688 if ((g_pos2.totalcost < 0) ||
689 (g_pos2.totalcost > new_cost)) {
690 DEBUG_OUT(LVL "Pathfinder: updating path at: "<<
691 PPOS(ipos2) << " from: " << g_pos2.totalcost << " to "<<
692 new_cost << std::endl);
693 if (update_all_costs(ipos2,invert(directions[i]),
699 DEBUG_OUT(LVL "Pathfinder:"
700 " already found shorter path to: "
701 << PPOS(ipos2) << std::endl);
705 DEBUG_OUT(LVL "Pathfinder:"
706 " not moving to invalid direction: "
707 << PPOS(directions[i]) << std::endl);
714 /******************************************************************************/
715 int pathfinder::get_manhattandistance(v3s16 pos) {
717 int min_x = MYMIN(pos.X,m_destination.X);
718 int max_x = MYMAX(pos.X,m_destination.X);
719 int min_z = MYMIN(pos.Z,m_destination.Z);
720 int max_z = MYMAX(pos.Z,m_destination.Z);
722 return (max_x - min_x) + (max_z - min_z);
725 /******************************************************************************/
726 v3s16 pathfinder::get_dir_heuristic(std::vector<v3s16>& directions,path_gridnode& g_pos) {
728 v3s16 retdir = v3s16(0,0,0);
729 v3s16 srcpos = g_pos.pos;
730 DEBUG_OUT("Pathfinder: remaining dirs at beginning:"
731 << directions.size() << std::endl);
733 for (std::vector<v3s16>::iterator iter = directions.begin();
734 iter != directions.end();
737 v3s16 pos1 = v3s16(srcpos.X + iter->X,0,srcpos.Z+iter->Z);
739 int cur_manhattan = get_manhattandistance(pos1);
740 path_cost cost = g_pos.get_cost(*iter);
743 cost = calc_cost(g_pos.pos,*iter);
744 g_pos.set_cost(*iter,cost);
748 int score = cost.value + cur_manhattan;
750 if ((minscore < 0)|| (score < minscore)) {
757 if (retdir != v3s16(0,0,0)) {
758 for (std::vector<v3s16>::iterator iter = directions.begin();
759 iter != directions.end();
761 if(*iter == retdir) {
762 DEBUG_OUT("Pathfinder: removing return direction" << std::endl);
763 directions.erase(iter);
769 DEBUG_OUT("Pathfinder: didn't find any valid direction clearing"
773 DEBUG_OUT("Pathfinder: remaining dirs at end:" << directions.size()
778 /******************************************************************************/
779 bool pathfinder::update_cost_heuristic( v3s16 ipos,
784 path_gridnode& g_pos = getIndexElement(ipos);
785 g_pos.totalcost = current_cost;
786 g_pos.sourcedir = srcdir;
790 //check if target has been found
792 m_min_target_distance = current_cost;
793 DEBUG_OUT(LVL " Pathfinder: target found!" << std::endl);
799 std::vector<v3s16> directions;
801 directions.push_back(v3s16( 1,0, 0));
802 directions.push_back(v3s16(-1,0, 0));
803 directions.push_back(v3s16( 0,0, 1));
804 directions.push_back(v3s16( 0,0,-1));
806 v3s16 direction = get_dir_heuristic(directions,g_pos);
808 while (direction != v3s16(0,0,0) && (!retval)) {
810 if (direction != srcdir) {
811 path_cost cost = g_pos.get_cost(direction);
814 direction.Y = cost.direction;
816 v3s16 ipos2 = ipos + direction;
818 if (!valid_index(ipos2)) {
819 DEBUG_OUT(LVL " Pathfinder: " << PPOS(ipos2) <<
820 " out of range (" << m_limits.X.max << "," <<
821 m_limits.Y.max << "," << m_limits.Z.max
826 path_gridnode& g_pos2 = getIndexElement(ipos2);
829 VERBOSE_TARGET << LVL "Pathfinder: no data for new position: "
830 << PPOS(ipos2) << std::endl;
834 assert(cost.value > 0);
836 int new_cost = current_cost + cost.value;
838 // check if there already is a smaller path
839 if ((m_min_target_distance > 0) &&
840 (m_min_target_distance < new_cost)) {
841 DEBUG_OUT(LVL "Pathfinder:"
842 " already longer than best already found path "
843 << PPOS(ipos2) << std::endl);
847 if ((g_pos2.totalcost < 0) ||
848 (g_pos2.totalcost > new_cost)) {
849 DEBUG_OUT(LVL "Pathfinder: updating path at: "<<
850 PPOS(ipos2) << " from: " << g_pos2.totalcost << " to "<<
851 new_cost << " srcdir=" <<
852 PPOS(invert(direction))<< std::endl);
853 if (update_cost_heuristic(ipos2,invert(direction),
859 DEBUG_OUT(LVL "Pathfinder:"
860 " already found shorter path to: "
861 << PPOS(ipos2) << std::endl);
865 DEBUG_OUT(LVL "Pathfinder:"
866 " not moving to invalid direction: "
867 << PPOS(direction) << std::endl);
871 DEBUG_OUT(LVL "Pathfinder:"
873 << PPOS(direction) << std::endl);
875 direction = get_dir_heuristic(directions,g_pos);
880 /******************************************************************************/
881 void pathfinder::build_path(std::vector<v3s16>& path,v3s16 pos, int level) {
885 << LVL "Pathfinder: path is too long aborting" << std::endl;
889 path_gridnode& g_pos = getIndexElement(pos);
892 << LVL "Pathfinder: invalid next pos detected aborting" << std::endl;
896 g_pos.is_element = true;
898 //check if source reached
904 build_path(path,pos + g_pos.sourcedir,level);
908 /******************************************************************************/
909 v3f pathfinder::tov3f(v3s16 pos) {
910 return v3f(BS*pos.X,BS*pos.Y,BS*pos.Z);
913 #ifdef PATHFINDER_DEBUG
915 /******************************************************************************/
916 void pathfinder::print_cost() {
923 /******************************************************************************/
924 void pathfinder::print_ydir() {
931 /******************************************************************************/
932 void pathfinder::print_cost(path_directions dir) {
934 std::cout << "Cost in direction: " << dir_to_name(dir) << std::endl;
935 std::cout << std::setfill('-') << std::setw(80) << "-" << std::endl;
936 std::cout << std::setfill(' ');
937 for (int y = 0; y < m_max_index_y; y++) {
939 std::cout << "Level: " << y << std::endl;
941 std::cout << std::setw(4) << " " << " ";
942 for (int x = 0; x < m_max_index_x; x++) {
943 std::cout << std::setw(4) << x;
945 std::cout << std::endl;
947 for (int z = 0; z < m_max_index_z; z++) {
948 std::cout << std::setw(4) << z <<": ";
949 for (int x = 0; x < m_max_index_x; x++) {
950 if (m_data[x][z][y].directions[dir].valid)
951 std::cout << std::setw(4)
952 << m_data[x][z][y].directions[dir].value;
954 std::cout << std::setw(4) << "-";
956 std::cout << std::endl;
958 std::cout << std::endl;
962 /******************************************************************************/
963 void pathfinder::print_ydir(path_directions dir) {
965 std::cout << "Height difference in direction: " << dir_to_name(dir) << std::endl;
966 std::cout << std::setfill('-') << std::setw(80) << "-" << std::endl;
967 std::cout << std::setfill(' ');
968 for (int y = 0; y < m_max_index_y; y++) {
970 std::cout << "Level: " << y << std::endl;
972 std::cout << std::setw(4) << " " << " ";
973 for (int x = 0; x < m_max_index_x; x++) {
974 std::cout << std::setw(4) << x;
976 std::cout << std::endl;
978 for (int z = 0; z < m_max_index_z; z++) {
979 std::cout << std::setw(4) << z <<": ";
980 for (int x = 0; x < m_max_index_x; x++) {
981 if (m_data[x][z][y].directions[dir].valid)
982 std::cout << std::setw(4)
983 << m_data[x][z][y].directions[dir].direction;
985 std::cout << std::setw(4) << "-";
987 std::cout << std::endl;
989 std::cout << std::endl;
993 /******************************************************************************/
994 void pathfinder::print_type() {
995 std::cout << "Type of node:" << std::endl;
996 std::cout << std::setfill('-') << std::setw(80) << "-" << std::endl;
997 std::cout << std::setfill(' ');
998 for (int y = 0; y < m_max_index_y; y++) {
1000 std::cout << "Level: " << y << std::endl;
1002 std::cout << std::setw(3) << " " << " ";
1003 for (int x = 0; x < m_max_index_x; x++) {
1004 std::cout << std::setw(3) << x;
1006 std::cout << std::endl;
1008 for (int z = 0; z < m_max_index_z; z++) {
1009 std::cout << std::setw(3) << z <<": ";
1010 for (int x = 0; x < m_max_index_x; x++) {
1011 char toshow = m_data[x][z][y].type;
1012 std::cout << std::setw(3) << toshow;
1014 std::cout << std::endl;
1016 std::cout << std::endl;
1018 std::cout << std::endl;
1021 /******************************************************************************/
1022 void pathfinder::print_pathlen() {
1023 std::cout << "Pathlen:" << std::endl;
1024 std::cout << std::setfill('-') << std::setw(80) << "-" << std::endl;
1025 std::cout << std::setfill(' ');
1026 for (int y = 0; y < m_max_index_y; y++) {
1028 std::cout << "Level: " << y << std::endl;
1030 std::cout << std::setw(3) << " " << " ";
1031 for (int x = 0; x < m_max_index_x; x++) {
1032 std::cout << std::setw(3) << x;
1034 std::cout << std::endl;
1036 for (int z = 0; z < m_max_index_z; z++) {
1037 std::cout << std::setw(3) << z <<": ";
1038 for (int x = 0; x < m_max_index_x; x++) {
1039 std::cout << std::setw(3) << m_data[x][z][y].totalcost;
1041 std::cout << std::endl;
1043 std::cout << std::endl;
1045 std::cout << std::endl;
1048 /******************************************************************************/
1049 std::string pathfinder::dir_to_name(path_directions dir) {
1068 /******************************************************************************/
1069 void pathfinder::print_path(std::vector<v3s16> path) {
1071 unsigned int current = 0;
1072 for (std::vector<v3s16>::iterator i = path.begin();
1073 i != path.end(); i++) {
1074 std::cout << std::setw(3) << current << ":" << PPOS((*i)) << std::endl;