Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 474f3fb

Browse files
authoredMar 5, 2020
Fix pathfinder bugs: returning nil frequently, broken A*, jump through solid nodes (#9339)
* Fix pathfinder fail when startpos is over air * Note down pathfinder restrictions * Implement real A* search * Pathfinder: Implement buildPath non-recursively * Update find_path documentation * Pathfinder: Check if jump path is unobstructed * Pathfinder: Fix drop check first checking upwards * Pathfinder: Return nil if source or dest are solid * Pathfinder: Use priority queue for open list
1 parent 6d8e2d2 commit 474f3fb

File tree

4 files changed

+354
-251
lines changed

4 files changed

+354
-251
lines changed
 

‎builtin/game/features.lua

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ core.features = {
1515
httpfetch_binary_data = true,
1616
formspec_version_element = true,
1717
area_store_persistent_ids = true,
18+
pathfinder_works = true,
1819
}
1920

2021
function core.has_feature(arg)

‎doc/lua_api.txt

+16-5
Original file line numberDiff line numberDiff line change
@@ -4045,6 +4045,8 @@ Utilities
40454045
formspec_version_element = true,
40464046
-- Whether AreaStore's IDs are kept on save/load (5.1.0)
40474047
area_store_persistent_ids = true,
4048+
-- Whether minetest.find_path is functional (5.2.0)
4049+
pathfinder_works = true,
40484050
}
40494051

40504052
* `minetest.has_feature(arg)`: returns `boolean, missing_features`
@@ -4709,16 +4711,25 @@ Environment access
47094711
* `objects`: if false, only nodes will be returned. Default is `true`.
47104712
* `liquids`: if false, liquid nodes won't be returned. Default is `false`.
47114713
* `minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)`
4712-
* returns table containing path
4714+
* returns table containing path that can be walked on
47134715
* returns a table of 3D points representing a path from `pos1` to `pos2` or
4714-
`nil`.
4716+
`nil` on failure.
4717+
* Reasons for failure:
4718+
* No path exists at all
4719+
* No path exists within `searchdistance` (see below)
4720+
* Start or end pos is buried in land
47154721
* `pos1`: start position
47164722
* `pos2`: end position
4717-
* `searchdistance`: number of blocks to search in each direction using a
4718-
maximum metric.
4723+
* `searchdistance`: maximum distance from the search positions to search in.
4724+
In detail: Path must be completely inside a cuboid. The minimum
4725+
`searchdistance` of 1 will confine search between `pos1` and `pos2`.
4726+
Larger values will increase the size of this cuboid in all directions
47194727
* `max_jump`: maximum height difference to consider walkable
47204728
* `max_drop`: maximum height difference to consider droppable
4721-
* `algorithm`: One of `"A*_noprefetch"` (default), `"A*"`, `"Dijkstra"`
4729+
* `algorithm`: One of `"A*_noprefetch"` (default), `"A*"`, `"Dijkstra"`.
4730+
Difference between `"A*"` and `"A*_noprefetch"` is that
4731+
`"A*"` will pre-calculate the cost-data, the other will calculate it
4732+
on-the-fly
47224733
* `minetest.spawn_tree (pos, {treedef})`
47234734
* spawns L-system tree at given `pos` with definition in `treedef` table
47244735
* `minetest.transforming_liquid_add(pos)`

‎src/pathfinder.cpp

+336-245
Large diffs are not rendered by default.

‎src/script/lua_api/l_env.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
11941194
unsigned int max_jump = luaL_checkint(L, 4);
11951195
unsigned int max_drop = luaL_checkint(L, 5);
11961196
PathAlgorithm algo = PA_PLAIN_NP;
1197-
if (!lua_isnil(L, 6)) {
1197+
if (!lua_isnoneornil(L, 6)) {
11981198
std::string algorithm = luaL_checkstring(L,6);
11991199

12001200
if (algorithm == "A*")

0 commit comments

Comments
 (0)
Please sign in to comment.