Pathfinder: Auto-correct position on failure (smoother)

Dynamic pathfinder distance, depending on speed and dtime
Replace various deprecated function names
This commit is contained in:
SmallJoker
2017-10-09 10:58:11 +02:00
parent 2229ededa5
commit e3688b5380
3 changed files with 49 additions and 33 deletions

View File

@ -160,33 +160,37 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
return {x=0, y=0, z=0}
end
function boost_cart:pathfinder(pos_, old_pos, old_dir, ctrl, pf_switch, railtype)
if vector.equals(old_pos, pos_) then
return true
end
function boost_cart:pathfinder(pos_, old_pos, old_dir, distance, ctrl,
pf_switch, railtype)
local pos = vector.round(pos_)
if vector.equals(old_pos, pos) then
return
end
local pf_pos = vector.round(old_pos)
local pf_dir = vector.new(old_dir)
distance = math.min(boost_cart.path_distance_max,
math.floor(distance + 1))
for i = 1, 3 do
for i = 1, distance do
pf_dir, pf_switch = boost_cart:get_rail_direction(
pf_pos, pf_dir, ctrl, pf_switch, railtype)
if vector.equals(pf_dir, {x=0, y=0, z=0}) then
-- No way forwards
return false
return pf_pos, pf_dir
end
pf_pos = vector.add(pf_pos, pf_dir)
if vector.equals(pf_pos, pos) then
-- Success! Cart moved on correctly
return true
return
end
end
-- Cart not found
return false
-- Not found. Put cart to predicted position
return pf_pos, pf_dir
end
function boost_cart:boost_rail(pos, amount)