mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-12-18 01:55:41 +01:00
Check for regular behavior too
- HAAAAAAAANDS
This commit is contained in:
parent
d63f8ae024
commit
cbe0ab9770
@ -163,6 +163,11 @@ function boost_cart:pathfinder(pos_, expected_pos, old_dir, ctrl, pf_switch, rai
|
|||||||
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
|
||||||
|
-- Success! Cart moved on correctly
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
pf_dir, pf_switch = boost_cart:get_rail_direction(pf_pos, pf_dir, ctrl, pf_switch, railtype)
|
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
|
||||||
@ -170,10 +175,6 @@ function boost_cart:pathfinder(pos_, expected_pos, old_dir, ctrl, pf_switch, rai
|
|||||||
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
|
||||||
|
22
init.lua
22
init.lua
@ -168,8 +168,8 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
|
|
||||||
if self.old_pos and not self.punched then
|
if self.old_pos and not self.punched then
|
||||||
local flo_pos = vector.floor(pos)
|
local flo_pos = vector.round(pos)
|
||||||
local flo_old = vector.floor(self.old_pos)
|
local flo_old = vector.round(self.old_pos)
|
||||||
if vector.equals(flo_pos, flo_old) then
|
if vector.equals(flo_pos, flo_old) then
|
||||||
-- Do not check one node multiple times
|
-- Do not check one node multiple times
|
||||||
return
|
return
|
||||||
@ -268,7 +268,16 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if mesecon then
|
if mesecon then
|
||||||
boost_cart:signal_detector_rail(vector.floor(pos))
|
boost_cart:signal_detector_rail(vector.round(pos))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Limits
|
||||||
|
for _,v in ipairs({"x","y","z"}) do
|
||||||
|
if math.abs(vel[v]) > max_vel then
|
||||||
|
vel[v] = boost_cart:get_sign(vel[v]) * max_vel
|
||||||
|
new_acc[v] = 0
|
||||||
|
update.vel = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.object:setacceleration(new_acc)
|
self.object:setacceleration(new_acc)
|
||||||
@ -276,13 +285,6 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
self.old_dir = vector.new(dir)
|
self.old_dir = vector.new(dir)
|
||||||
self.old_switch = last_switch
|
self.old_switch = last_switch
|
||||||
|
|
||||||
-- Limits
|
|
||||||
for _,v in ipairs({"x","y","z"}) do
|
|
||||||
if math.abs(vel[v]) > max_vel then
|
|
||||||
vel[v] = boost_cart:get_sign(vel[v]) * max_vel
|
|
||||||
update.vel = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.punched then
|
if self.punched then
|
||||||
-- Collect dropped items
|
-- Collect dropped items
|
||||||
|
Loading…
Reference in New Issue
Block a user