summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--car.lua132
-rw-r--r--controller.lua14
-rw-r--r--controllerfw.lua42
-rw-r--r--drive_entity.lua8
-rw-r--r--textures/celevator_cartopinsp_off.pngbin0 -> 10059 bytes
-rw-r--r--textures/celevator_cartopinsp_on.pngbin0 -> 10065 bytes
6 files changed, 195 insertions, 1 deletions
diff --git a/car.lua b/car.lua
index b127767..61937fc 100644
--- a/car.lua
+++ b/car.lua
@@ -1,5 +1,61 @@
celevator.car = {}
+local function disambiguatebutton(pos,facedir,player)
+ if player and not player.is_fake_player then
+ local eyepos = vector.add(player:get_pos(),vector.add(player:get_eye_offset(),vector.new(0,1.5,0)))
+ local lookdir = player:get_look_dir()
+ local distance = vector.distance(eyepos,pos)
+ local endpos = vector.add(eyepos,vector.multiply(lookdir,distance+1))
+ local ray = minetest.raycast(eyepos,endpos,true,false)
+ local pointed,button,hitpos
+ repeat
+ pointed = ray:next()
+ if pointed and pointed.type == "node" then
+ local node = minetest.get_node(pointed.under)
+ if node.name == "celevator:car_021" then
+ button = pointed.under
+ hitpos = vector.subtract(pointed.intersection_point,button)
+ end
+ end
+ until button or not pointed
+ if not hitpos then return end
+ hitpos = vector.rotate_around_axis(hitpos,vector.new(0,-1,0),minetest.dir_to_yaw(facedir)+(math.pi/2))
+ if hitpos.y < 0.55 then return end
+ if hitpos.z > 0.36 or hitpos.z < 0.09 then return end
+ if hitpos.x >= -0.36 and hitpos.x <= -0.16 then
+ return "inspectswitch"
+ elseif hitpos.x > -0.16 and hitpos.x <= 0.03 then
+ return "up"
+ elseif hitpos.x > 0.03 and hitpos.x <= 0.2 then
+ return "down"
+ end
+ end
+end
+
+local function updatecartopbox(pos)
+ local toppos = vector.add(pos,vector.new(0,1.1,0))
+ local entitiesnearby = minetest.get_objects_inside_radius(toppos,0.5)
+ for _,i in pairs(entitiesnearby) do
+ if i:get_luaentity() and i:get_luaentity().name == "celevator:car_top_box" then
+ i:remove()
+ end
+ end
+ local carmeta = minetest.get_meta(pos)
+ local carid = carmeta:get_int("carid")
+ if carid == 0 then return end
+ local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid)))
+ if not carinfo then return end
+ local entity = minetest.add_entity(pos,"celevator:car_top_box")
+ local inspon = carinfo.cartopinspect
+ entity:set_properties({
+ wield_item = inspon and "celevator:car_top_box_on" or "celevator:car_top_box_off",
+ })
+ local fdir = minetest.fourdir_to_dir(minetest.get_node(pos).param2)
+ fdir = vector.rotate_around_axis(fdir,vector.new(0,1,0),math.pi/2)
+ entity:set_yaw(minetest.dir_to_yaw(fdir))
+ entity:set_pos(toppos)
+end
+
local pieces = {
{
_position = "000",
@@ -237,6 +293,25 @@ local pieces = {
"celevator_car_wallpaper.png",
"celevator_cabinet_sides.png",
},
+ on_rightclick = function(pos,node,clicker)
+ local fdir = minetest.fourdir_to_dir(node.param2)
+ local control = disambiguatebutton(pos,fdir,clicker)
+ local meta = minetest.get_meta(pos)
+ local carid = meta:get_int("carid")
+ if carid == 0 then return end
+ local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid)))
+ if not (carinfo and carinfo.controllerpos) then return end
+ celevator.controller.handlecartopbox(carinfo.controllerpos,control)
+ end,
+ after_dig_node = function(pos)
+ local toppos = vector.add(pos,vector.new(0,1.1,0))
+ local entitiesnearby = minetest.get_objects_inside_radius(toppos,0.5)
+ for _,i in pairs(entitiesnearby) do
+ if i:get_luaentity() and i:get_luaentity().name == "celevator:car_top_box" then
+ i:remove()
+ end
+ end
+ end,
},
{
_position = "022",
@@ -427,3 +502,60 @@ minetest.register_abm({
end,
})
+minetest.register_node("celevator:car_top_box_off",{
+ description = "Car-top Inspection Box, Off State (you hacker you!)",
+ drop = "",
+ groups = {
+ not_in_creative_inventory = 1,
+ },
+ paramtype = "light",
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.422,-0.5,0.086,0.414,-0.45,0.359},
+ },
+ },
+ tiles = {
+ "celevator_cartopinsp_off.png",
+ "celevator_cabinet_sides.png",
+ },
+})
+
+minetest.register_node("celevator:car_top_box_on",{
+ description = "Car-top Inspection Box, On State (you hacker you!)",
+ drop = "",
+ groups = {
+ not_in_creative_inventory = 1,
+ },
+ paramtype = "light",
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.422,-0.5,0.086,0.414,-0.45,0.359},
+ },
+ },
+ tiles = {
+ "celevator_cartopinsp_on.png",
+ "celevator_cabinet_sides.png",
+ },
+})
+
+minetest.register_entity("celevator:car_top_box",{
+ initial_properties = {
+ visual = "wielditem",
+ visual_size = vector.new(0.667,0.667,0.667),
+ wield_item = "celevator:car_top_box_off",
+ static_save = false,
+ pointable = false,
+ },
+})
+
+minetest.register_abm({
+ label = "Respawn car-top inspection boxes",
+ nodenames = {"celevator:car_021"},
+ interval = 1,
+ chance = 1,
+ action = updatecartopbox,
+})
diff --git a/controller.lua b/controller.lua
index 0912776..d60e2be 100644
--- a/controller.lua
+++ b/controller.lua
@@ -517,6 +517,12 @@ function celevator.controller.finish(pos,mem,changedinterrupts)
celevator.fs1switch.setled(fs1switch.pos,newfs1led)
end
end
+ local oldcartopinsp = oldmem.cartopinspectsw
+ local newcartopinsp = mem.cartopinspectsw
+ if oldcartopinsp ~= newcartopinsp then
+ carinfodirty = true
+ carinfo.cartopinspect = newcartopinsp
+ end
meta:set_string("copformspec",mem.copformspec)
meta:set_string("switchformspec",mem.switchformspec)
if (mem.copformspec ~= oldmem.copformspec or mem.switchformspec ~= oldmem.switchformspec) and drivetype then
@@ -601,6 +607,14 @@ function celevator.controller.handlefs1switch(controllerpos,on)
celevator.controller.run(controllerpos,event)
end
+function celevator.controller.handlecartopbox(controllerpos,control)
+ local event = {
+ type = "cartopbox",
+ control = control,
+ }
+ celevator.controller.run(controllerpos,event)
+end
+
function celevator.controller.checkiqueue(dtime)
for hash,iqueue in pairs(celevator.controller.iqueue) do
local pos = minetest.get_position_from_hash(hash)
diff --git a/controllerfw.lua b/controllerfw.lua
index 6401c03..07ba86a 100644
--- a/controllerfw.lua
+++ b/controllerfw.lua
@@ -496,6 +496,32 @@ elseif event.type == "copswitches" then
elseif event.type == "fs1switch" then
mem.fs1switch = event.state
mem.fs1led = event.state
+elseif event.type == "cartopbox" then
+ if event.control == "inspectswitch" then
+ mem.cartopinspectsw = not mem.cartopinspectsw
+ elseif event.control == "up" and mem.carstate == "carinspect" and mem.doorstate == "closed" and getpos() < #mem.params.floornames then
+ mem.carmotion = true
+ juststarted = true
+ drivecmd({
+ command = "setmaxvel",
+ maxvel = 0.2,
+ })
+ drivecmd({
+ command = "moveto",
+ pos = math.floor(mem.drive.status.apos)+1
+ })
+ elseif event.control == "down" and mem.carstate == "carinspect" and mem.doorstate == "closed" and mem.drive.status.apos-1 >= 0 then
+ mem.carmotion = true
+ juststarted = true
+ drivecmd({
+ command = "setmaxvel",
+ maxvel = 0.2,
+ })
+ drivecmd({
+ command = "moveto",
+ pos = math.floor(mem.drive.status.apos)-1
+ })
+ end
end
local oldstate = mem.carstate
@@ -514,6 +540,13 @@ elseif mem.controllerstopsw or mem.screenstate == "floortable" or mem.screenstat
mem.upcalls = {}
mem.dncalls = {}
mem.direction = nil
+elseif mem.controllerinspectsw and mem.cartopinspectsw then
+ mem.carstate = "inspconflict"
+ mem.carcalls = {}
+ mem.upcalls = {}
+ mem.dncalls = {}
+ mem.direction = nil
+ drivecmd({command="estop"})
elseif mem.controllerinspectsw and not mem.cartopinspectsw then
mem.carstate = "mrinspect"
mem.carcalls = {}
@@ -521,6 +554,13 @@ elseif mem.controllerinspectsw and not mem.cartopinspectsw then
mem.dncalls = {}
mem.direction = nil
if oldstate ~= "mrinspect" then drivecmd({command="estop"}) end
+elseif mem.cartopinspectsw and not mem.controllerinspectsw then
+ mem.carstate = "carinspect"
+ mem.carcalls = {}
+ mem.upcalls = {}
+ mem.dncalls = {}
+ mem.direction = nil
+ if oldstate ~= "carinspect" then drivecmd({command="estop"}) end
elseif mem.fs2sw == "on" then
mem.carstate = "fs2"
mem.upcalls = {}
@@ -582,7 +622,7 @@ elseif mem.capturesw then
mem.carstate = "capture"
end
else
- if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then
+ if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "carinspect" or oldstate == "fault" then
mem.carstate = "resync"
gotofloor(getpos())
elseif oldstate == "test" or oldstate == "capture" or oldstate == "fs1" or oldstate == "fs2" or oldstate == "fs2hold" then
diff --git a/drive_entity.lua b/drive_entity.lua
index 35a4e71..8799b2f 100644
--- a/drive_entity.lua
+++ b/drive_entity.lua
@@ -223,10 +223,18 @@ function celevator.drives.entity.nodestoentities(nodes,ename)
})
eref:set_yaw(minetest.dir_to_yaw(minetest.fourdir_to_dir(node.param2)))
table.insert(refs,eref)
+ if node.name == "celevator:car_021" then
+ local toppos = vector.add(pos,vector.new(0,1,0))
+ local topattach = minetest.get_objects_inside_radius(toppos,0.9)
+ for _,ref in pairs(topattach) do
+ table.insert(attach,ref)
+ end
+ end
if not ename then --If ename is set, something other than the car is moving
for _,attachref in ipairs(attach) do
local included = {
["celevator:incar_pi_entity"] = true,
+ ["celevator:car_top_box"] = true,
["celevator:car_door"] = true,
}
if attachref:get_luaentity() and included[attachref:get_luaentity().name] then
diff --git a/textures/celevator_cartopinsp_off.png b/textures/celevator_cartopinsp_off.png
new file mode 100644
index 0000000..16de1dd
--- /dev/null
+++ b/textures/celevator_cartopinsp_off.png
Binary files differ
diff --git a/textures/celevator_cartopinsp_on.png b/textures/celevator_cartopinsp_on.png
new file mode 100644
index 0000000..d393eef
--- /dev/null
+++ b/textures/celevator_cartopinsp_on.png
Binary files differ