Pathfinder: Make initial drop collide with climb

This commit is contained in:
Wuzzy 2024-03-28 15:24:48 +01:00
parent 657a4320a9
commit 09f665614e

View File

@ -115,9 +115,9 @@ end
-- Simulate falling with a given drop_height limit -- Simulate falling with a given drop_height limit
-- and returns the final node we land *in* -- and returns the final node we land *in*
local function drop_down(pos, drop_height, nh, get_node) local function drop_down(pos, drop_height, stop_at_climb, nh, get_node)
local blocking_or_walkable = function(node) local stop = function(node)
return nh.blocking(node) or nh.walkable(node) return nh.blocking(node) or nh.walkable(node) or (stop_at_climb and climbable(node))
end end
local dpos = table.copy(pos) local dpos = table.copy(pos)
-- Get the first blocking or walkable node below neighbor -- Get the first blocking or walkable node below neighbor
@ -126,7 +126,7 @@ local function drop_down(pos, drop_height, nh, get_node)
-- we need an 1 node offset for the floor (on which we drop on top) -- we need an 1 node offset for the floor (on which we drop on top)
drop_height = drop_height + 1 drop_height = drop_height + 1
local floor = vertical_walk(dpos, -1, drop_height, blocking_or_walkable, true, get_node) local floor = vertical_walk(dpos, -1, drop_height, stop, true, get_node)
if not floor then if not floor then
return nil return nil
end end
@ -161,7 +161,7 @@ local function get_neighbor_floor_pos(neighbor_pos, current_pos, clear_height, j
end end
-- Drop down -- Drop down
if not nh.walkable(nnode) then if not nh.walkable(nnode) then
local floor = drop_down(npos, drop_height, nh, get_node) local floor = drop_down(npos, drop_height, false, nh, get_node)
return floor return floor
-- Jump -- Jump
else else
@ -305,7 +305,8 @@ function rp_pathfinder.find_path(pos1, pos2, searchdistance, options, timeout)
return nil, "pos1_blocked" return nil, "pos1_blocked"
end end
pos1 = drop_down(pos1, max_drop, nh, get_node) -- Simulate an initial drop from pos1
pos1 = drop_down(pos1, max_drop, climb, nh, get_node)
if not pos1 then if not pos1 then
return nil, "pos1_too_high" return nil, "pos1_too_high"
end end