Skip to content

Commit 9af7f38

Browse files
obneqkwolekr
obneq
authored andcommittedMay 4, 2015
Fix pathfinder to produce more useful paths
- Fix unintended negation of condition - Remove line_of_sight 'optimization'
1 parent 8f38f82 commit 9af7f38

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed
 

‎src/pathfinder.cpp

+7-18
Original file line numberDiff line numberDiff line change
@@ -310,27 +310,16 @@ std::vector<v3s16> pathfinder::get_Path(ServerEnvironment* env,
310310
print_path(path);
311311
#endif
312312

313-
//optimize path
314-
std::vector<v3s16> optimized_path;
315-
316-
std::vector<v3s16>::iterator startpos = path.begin();
317-
optimized_path.push_back(source);
318-
313+
//finalize path
314+
std::vector<v3s16> full_path;
319315
for (std::vector<v3s16>::iterator i = path.begin();
320316
i != path.end(); i++) {
321-
if (!m_env->line_of_sight(
322-
tov3f(getIndexElement(*startpos).pos),
323-
tov3f(getIndexElement(*i).pos))) {
324-
optimized_path.push_back(getIndexElement(*(i-1)).pos);
325-
startpos = (i-1);
326-
}
317+
full_path.push_back(getIndexElement(*i).pos);
327318
}
328319

329-
optimized_path.push_back(destination);
330-
331320
#ifdef PATHFINDER_DEBUG
332-
std::cout << "Optimized path:" << std::endl;
333-
print_path(optimized_path);
321+
std::cout << "full path:" << std::endl;
322+
print_path(full_path);
334323
#endif
335324
#ifdef PATHFINDER_CALC_TIME
336325
timespec ts2;
@@ -344,7 +333,7 @@ std::vector<v3s16> pathfinder::get_Path(ServerEnvironment* env,
344333
std::cout << "Calculating path took: " << (ts2.tv_sec - ts.tv_sec) <<
345334
"s " << ms << "ms " << us << "us " << ns << "ns " << std::endl;
346335
#endif
347-
return optimized_path;
336+
return full_path;
348337
}
349338
else {
350339
#ifdef PATHFINDER_DEBUG
@@ -532,7 +521,7 @@ path_cost pathfinder::calc_cost(v3s16 pos,v3s16 dir) {
532521
if ((testpos.Y >= m_limits.Y.min) &&
533522
(node_at_pos.param0 != CONTENT_IGNORE) &&
534523
(node_at_pos.param0 != CONTENT_AIR)) {
535-
if (((pos2.Y - testpos.Y)*-1) <= m_maxdrop) {
524+
if ((pos2.Y - testpos.Y - 1) <= m_maxdrop) {
536525
retval.valid = true;
537526
retval.value = 2;
538527
//difference of y-pos +1 (target node is ABOVE solid node)

0 commit comments

Comments
 (0)
Please sign in to comment.