diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-02-28 16:25:32 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-02-28 16:25:32 +0100 |
commit | 71ff39637f414f1be91ae97aedc6c00f4ba37ec0 (patch) | |
tree | 8d28b163400d6fd22da94ba42edd9ab0041edf90 /advtrains/advtrains/wagons.lua | |
parent | d51a00c8232e2500783f1a04ec7ad1bf01cadd8b (diff) | |
download | advtrains-71ff39637f414f1be91ae97aedc6c00f4ba37ec0.tar.gz advtrains-71ff39637f414f1be91ae97aedc6c00f4ba37ec0.tar.bz2 advtrains-71ff39637f414f1be91ae97aedc6c00f4ba37ec0.zip |
Only get on by walking in when there's a platform, improve get off handling
Diffstat (limited to 'advtrains/advtrains/wagons.lua')
-rw-r--r-- | advtrains/advtrains/wagons.lua | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index 4b080a5..e87b50a 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -348,16 +348,18 @@ function wagon:on_step(dtime) local add = { x = (ix2.z-ix1.z)*gp.door_open, y = 0, z = (ix1.x-ix2.x)*gp.door_open }
local pts1=vector.round(vector.add(ix1, add))
local pts2=vector.round(vector.add(ix2, add))
- local ckpts={
- pts1,
- pts2,
- vector.add(pts1, {x=0, y=1, z=0}),
- vector.add(pts2, {x=0, y=1, z=0}),
- }
- for _,ckpos in ipairs(ckpts) do
- local cpp=minetest.pos_to_string(ckpos)
- if advtrains.playersbypts[cpp] then
- self:on_rightclick(advtrains.playersbypts[cpp])
+ if minetest.get_item_group(minetest.get_node(pts1).name, "platform")>0 then
+ local ckpts={
+ pts1,
+ pts2,
+ vector.add(pts1, {x=0, y=1, z=0}),
+ vector.add(pts2, {x=0, y=1, z=0}),
+ }
+ for _,ckpos in ipairs(ckpts) do
+ local cpp=minetest.pos_to_string(ckpos)
+ if advtrains.playersbypts[cpp] then
+ self:on_rightclick(advtrains.playersbypts[cpp])
+ end
end
end
end
@@ -591,24 +593,49 @@ function wagon:get_off(seatno) local clicker = minetest.get_player_by_name(pname)
advtrains.player_to_train_mapping[pname]=nil
advtrains.clear_driver_hud(pname)
+ self.seatp[seatno]=nil
+ self.seatpc[seatno]=nil
if clicker then
atprint("get_off: detaching",clicker:get_player_name())
clicker:set_detach()
clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
- local objpos=advtrains.round_vector_floor_y(self.object:getpos())
- local yaw=self.object:getyaw()
- local isx=(yaw < math.pi/4) or (yaw > 3*math.pi/4 and yaw < 5*math.pi/4) or (yaw > 7*math.pi/4)
- --abuse helper function
- for _,r in ipairs({-1, 1}) do
- local p=vector.add({x=isx and r or 0, y=0, z=not isx and r or 0}, objpos)
- local offp=vector.add({x=isx and r*2 or 0, y=1, z=not isx and r*2 or 0}, objpos)
- if minetest.get_item_group(minetest.get_node(p).name, "platform")>0 then
- minetest.after(0.2, function() clicker:setpos(offp) end)
+ local gp=self:train()
+ --code as in step - automatic get on
+ if self.door_entry and gp.door_open and gp.door_open~=0 and gp.velocity==0 then
+ local index=advtrains.get_real_path_index(gp, self.pos_in_train)
+ --using the mapping created by the trainlogic globalstep
+ for i, ino in ipairs(self.door_entry) do
+ local aci = index + ino*(self.wagon_flipped and -1 or 1)
+ local ix1=gp.path[math.floor(aci)]
+ local ix2=gp.path[math.floor(aci+1)]
+ -- the two wanted positions are ix1 and ix2 + (2nd-1st rotated by 90deg)
+ -- (x z) rotated by 90deg is (-z x) (http://stackoverflow.com/a/4780141)
+ -- multiplied by 2 here, to place off on platform, y of add is 1.
+ local add = { x = (ix2.z-ix1.z)*gp.door_open, y = 0, z = (ix1.x-ix2.x)*gp.door_open}
+ local oadd = { x = (ix2.z-ix1.z)*gp.door_open*2, y = 1, z = (ix1.x-ix2.x)*gp.door_open*2}
+ local platpos=vector.round(vector.add(ix1, add))
+ local offpos=vector.round(vector.add(ix1, oadd))
+ atprint("platpos:", platpos, "offpos:", offpos)
+ if minetest.get_item_group(minetest.get_node(platpos).name, "platform")>0 then
+ minetest.after(0.2, function() clicker:setpos(offpos) end)
+ return
+ end
+ end
+ else--if not door_entry, use old method
+ local objpos=advtrains.round_vector_floor_y(self.object:getpos())
+ local yaw=self.object:getyaw()
+ local isx=(yaw < math.pi/4) or (yaw > 3*math.pi/4 and yaw < 5*math.pi/4) or (yaw > 7*math.pi/4)
+ --abuse helper function
+ for _,r in ipairs({-1, 1}) do
+ local p=vector.add({x=isx and r or 0, y=0, z=not isx and r or 0}, objpos)
+ local offp=vector.add({x=isx and r*2 or 0, y=1, z=not isx and r*2 or 0}, objpos)
+ if minetest.get_item_group(minetest.get_node(p).name, "platform")>0 then
+ minetest.after(0.2, function() clicker:setpos(offp) end)
+ return
+ end
end
end
end
- self.seatp[seatno]=nil
- self.seatpc[seatno]=nil
end
function wagon:show_get_on_form(pname)
if not self.initialized then return end
|