summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controller.lua4
-rw-r--r--controllerfw.lua20
-rw-r--r--doors.lua31
-rw-r--r--drive_entity.lua40
-rw-r--r--drive_null.lua23
5 files changed, 104 insertions, 14 deletions
diff --git a/controller.lua b/controller.lua
index 5322e22..ee9a3b5 100644
--- a/controller.lua
+++ b/controller.lua
@@ -414,6 +414,10 @@ function celevator.controller.finish(pos,mem)
celevator.drives[drivetype].resetpos(drivepos)
elseif command.command == "estop" then
celevator.drives[drivetype].estop(drivepos)
+ elseif command.command == "open" then
+ celevator.drives[drivetype].movedoors(drivepos,"open")
+ elseif command.command == "close" then
+ celevator.drives[drivetype].movedoors(drivepos,"close")
end
end
end
diff --git a/controllerfw.lua b/controllerfw.lua
index 4ac888c..9491396 100644
--- a/controllerfw.lua
+++ b/controllerfw.lua
@@ -160,15 +160,15 @@ local function gethighestdowncall()
end
local function open()
- --TODO: Door operator interface
mem.doorstate = "opening"
- interrupt(2,"opened")
+ drivecmd({command = "open"})
+ interrupt(0.2,"checkopen")
end
local function close()
- --TODO: Door operator interface
mem.doorstate = "closing"
- interrupt(2,"closed")
+ drivecmd({command = "close"})
+ interrupt(0.2,"checkclosed")
end
mem.formspec = ""
@@ -406,6 +406,18 @@ elseif event.type == "callbutton" and mem.carstate == "normal" then
elseif event.dir == "down" and event.landing > 1 and event.landing <= #mem.params.floornames then
mem.dncalls[event.landing] = true
end
+elseif event.iid == "checkopen" then
+ if mem.drive.status.doorstate == "open" then
+ interrupt(0,"opened")
+ else
+ interrupt(0.2,"checkopen")
+ end
+elseif event.iid == "checkclosed" then
+ if mem.drive.status.doorstate == "closed" then
+ interrupt(0,"closed")
+ else
+ interrupt(0.2,"checkclosed")
+ end
end
local oldstate = mem.carstate
diff --git a/doors.lua b/doors.lua
index 07c135e..47254f3 100644
--- a/doors.lua
+++ b/doors.lua
@@ -14,6 +14,7 @@ minetest.register_node("celevator:hwdoor_fast_glass_bottom",{
},
groups = {
dig_immediate = 2,
+ _celevator_hwdoor_root = 1,
},
paramtype = "light",
paramtype2 = "4dir",
@@ -159,6 +160,18 @@ minetest.register_node("celevator:hwdoor_placeholder",{
},
paramtype = "light",
drawtype = "airlike",
+ collision_box = {
+ type = "fixed",
+ fixed = {
+ {0,0,0,0,0,0}
+ }
+ },
+ selection_box = {
+ type = "fixed",
+ fixed = {
+ {0,0,0,0,0,0}
+ }
+ },
})
minetest.register_entity("celevator:hwdoor_moving",{
@@ -190,7 +203,7 @@ function celevator.doors.hwopen(pos)
for i,position in ipairs(positions) do
oldnodes[i] = minetest.get_node(position)
end
- local erefs = celevator.drives.entity.nodestoentities(positions)
+ local erefs = celevator.drives.entity.nodestoentities(positions,"celevator:hwdoor_moving")
hwdoors_moving[hash] = {
direction = "open",
positions = positions,
@@ -285,11 +298,19 @@ function celevator.doors.step(dtime)
end
end
else
- for i=1,6,1 do
- celevator.doors.erefs[hash][i]:remove()
+ if data.direction == "open" then
+ for i=1,6,1 do
+ celevator.doors.erefs[hash][i]:remove()
+ end
+ minetest.get_meta(data.positions[1]):set_string("state","open")
+ hwdoors_moving[hash] = nil
+ elseif data.direction == "close" then
+ for i=1,6,1 do
+ minetest.set_node(data.positions[i],data.nodes[i])
+ end
+ minetest.get_meta(data.positions[1]):set_string("state","closed")
+ hwdoors_moving[hash] = nil
end
- minetest.get_meta(data.positions[1]):set_string("state","open")
- hwdoors_moving[hash] = nil
end
end
if save then
diff --git a/drive_entity.lua b/drive_entity.lua
index 29d6550..6438f40 100644
--- a/drive_entity.lua
+++ b/drive_entity.lua
@@ -91,6 +91,7 @@ minetest.register_node("celevator:drive",{
meta:set_string("maxvel","0.2")
meta:set_string("state","uninit")
meta:set_string("startpos","0")
+ meta:set_string("doorstate","closed")
update_ui(pos)
end,
on_destruct = stopbuzz,
@@ -142,10 +143,12 @@ function celevator.drives.entity.nodestoentities(nodes,ename)
wield_item = node.name,
})
eref:set_yaw(minetest.dir_to_yaw(minetest.fourdir_to_dir(node.param2)))
- for _,attachref in ipairs(attachobjs) do
- local attachpos = attachref:get_pos()
- local attachoffset = vector.subtract(pos,attachpos)
- attachref:set_attach(eref,"",attachoffset)
+ if not ename then --If ename is set, something other than the car is moving
+ for _,attachref in ipairs(attachobjs) do
+ local attachpos = attachref:get_pos()
+ local attachoffset = vector.multiply(vector.subtract(pos,attachpos),1/0.667)
+ attachref:set_attach(eref,"",attachoffset)
+ end
end
minetest.remove_node(pos)
table.insert(refs,eref)
@@ -331,6 +334,7 @@ function celevator.drives.entity.estop(pos)
if meta:get_string("state") ~= "running" then return end
local apos = math.floor(tonumber(meta:get_string("apos"))+0.5)
meta:set_string("dpos",tostring(apos))
+ meta:set_string("apos",tostring(apos))
local hash = minetest.hash_node_position(pos)
local handles = celevator.drives.entity.entityinfo[hash].handles
meta:set_string("state","stopped")
@@ -366,10 +370,38 @@ function celevator.drives.entity.getstatus(pos,call2)
ret.vel = tonumber(meta:get_string("vel")) or 0
ret.maxvel = tonumber(meta:get_string("maxvel")) or 0.2
ret.state = meta:get_string("state")
+ ret.doorstate = meta:get_string("doorstate")
return ret
end
end
+function celevator.drives.entity.movedoors(drivepos,direction)
+ local drivehash = minetest.hash_node_position(drivepos)
+ local entitydrives_running = minetest.deserialize(celevator.storage:get_string("entitydrives_running")) or {}
+ for _,hash in pairs(entitydrives_running) do
+ if drivehash == hash then return end
+ end
+ local drivemeta = minetest.get_meta(drivepos)
+ local origin = minetest.string_to_pos(drivemeta:get_string("origin"))
+ local apos = tonumber(drivemeta:get_string("apos")) or 0
+ local carpos = vector.add(origin,vector.new(0,apos,0))
+ local carnode = minetest.get_node(carpos)
+ local hwdoorpos = vector.add(carpos,vector.rotate_around_axis(minetest.fourdir_to_dir(carnode.param2),vector.new(0,1,0),math.pi))
+ if direction == "open" and minetest.get_item_group(minetest.get_node(hwdoorpos).name,"_celevator_hwdoor_root") == 1 then
+ celevator.doors.hwopen(hwdoorpos)
+ drivemeta:set_string("doorstate","opening")
+ minetest.after(math.pi+0.5,function()
+ minetest.get_meta(drivepos):set_string("doorstate","open")
+ end)
+ elseif direction == "close" and minetest.get_node(hwdoorpos).name == "celevator:hwdoor_placeholder" then
+ celevator.doors.hwclose(hwdoorpos)
+ drivemeta:set_string("doorstate","closing")
+ minetest.after((math.pi/0.66)+0.5,function()
+ minetest.get_meta(drivepos):set_string("doorstate","closed")
+ end)
+ end
+end
+
local function carsearch(pos)
for i=1,500,1 do
local searchpos = vector.subtract(pos,vector.new(0,i,0))
diff --git a/drive_null.lua b/drive_null.lua
index 17ed649..28c7e04 100644
--- a/drive_null.lua
+++ b/drive_null.lua
@@ -82,6 +82,7 @@ minetest.register_node("celevator:drive_null",{
meta:set_string("dpos","0")
meta:set_string("vel","0")
meta:set_string("maxvel","0.2")
+ meta:set_string("doorstate","closed")
update_ui(pos)
end,
on_destruct = stopbuzz,
@@ -185,6 +186,26 @@ function celevator.drives.null.rezero(pos)
celevator.drives.null.moveto(pos,0)
end
+function celevator.drives.null.movedoors(drivepos,direction)
+ local drivehash = minetest.hash_node_position(drivepos)
+ local nulldrives_running = minetest.deserialize(celevator.storage:get_string("nulldrives_running")) or {}
+ for _,hash in pairs(nulldrives_running) do
+ if drivehash == hash then return end
+ end
+ local drivemeta = minetest.get_meta(drivepos)
+ if direction == "open" then
+ drivemeta:set_string("doorstate","opening")
+ minetest.after(math.pi+0.5,function()
+ minetest.get_meta(drivepos):set_string("doorstate","open")
+ end)
+ elseif direction == "close" then
+ drivemeta:set_string("doorstate","closing")
+ minetest.after((math.pi/0.66)+0.5,function()
+ minetest.get_meta(drivepos):set_string("doorstate","closed")
+ end)
+ end
+end
+
function celevator.drives.null.getstatus(pos,call2)
local node = minetest.get_node(pos)
if node.name == "ignore" and not call2 then
@@ -200,7 +221,7 @@ function celevator.drives.null.getstatus(pos,call2)
ret.dpos = tonumber(meta:get_string("dpos")) or 0
ret.vel = tonumber(meta:get_string("vel")) or 0
ret.maxvel = tonumber(meta:get_string("maxvel")) or 0.2
- ret.neareststop = ret.apos
+ ret.doorstate = meta:get_string("doorstate")
return ret
end
end