mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-12-11 15:03:14 +01:00
Pathfinder: Also use the last computed position prediction
This commit is contained in:
parent
af25c5411b
commit
3c646ee4df
@ -159,23 +159,29 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function boost_cart:pathfinder(pos_, old_pos, old_dir, ctrl, pf_switch, railtype)
|
function boost_cart:pathfinder(pos_, old_pos, old_dir, ctrl, pf_switch, railtype)
|
||||||
|
if vector.equals(old_pos, pos_) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local pos = vector.round(pos_)
|
local pos = vector.round(pos_)
|
||||||
local pf_pos = vector.round(old_pos)
|
local pf_pos = vector.round(old_pos)
|
||||||
local pf_dir = vector.new(old_dir)
|
local pf_dir = vector.new(old_dir)
|
||||||
|
|
||||||
for i = 1, 3 do
|
for i = 1, 3 do
|
||||||
if vector.equals(pf_pos, pos) then
|
pf_dir, pf_switch = boost_cart:get_rail_direction(
|
||||||
-- Success! Cart moved on correctly
|
pf_pos, pf_dir, ctrl, pf_switch, railtype)
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
if vector.equals(pf_dir, {x=0, y=0, z=0}) then
|
||||||
-- No way forwards
|
-- No way forwards
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
pf_pos = vector.add(pf_pos, pf_dir)
|
pf_pos = vector.add(pf_pos, pf_dir)
|
||||||
|
|
||||||
|
if vector.equals(pf_pos, pos) then
|
||||||
|
-- Success! Cart moved on correctly
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- Cart not found
|
-- Cart not found
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user