summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2024-04-14 13:51:26 -0500
committercheapie <no-email-for-you@example.com>2024-04-14 13:51:26 -0500
commit8fc57f0535946351de94066e71b02b16b2c81bf9 (patch)
tree17f796049df3da276552b86fe3c12755e48b8050
parent4f04035bc45719872d07326599628429192bcc5b (diff)
downloadcelevator-8fc57f0535946351de94066e71b02b16b2c81bf9.tar
celevator-8fc57f0535946351de94066e71b02b16b2c81bf9.tar.gz
celevator-8fc57f0535946351de94066e71b02b16b2c81bf9.tar.bz2
celevator-8fc57f0535946351de94066e71b02b16b2c81bf9.tar.xz
celevator-8fc57f0535946351de94066e71b02b16b2c81bf9.zip
Add fire service phase 1
(no phase 2 yet)
-rw-r--r--controller.lua18
-rw-r--r--controllerfw.lua44
-rw-r--r--fs1switch.lua168
-rw-r--r--init.lua1
-rw-r--r--textures/celevator_fs1switch_led.pngbin0 -> 5509 bytes
-rw-r--r--textures/celevator_fs1switch_off.pngbin0 -> 10777 bytes
-rw-r--r--textures/celevator_fs1switch_on.pngbin0 -> 10715 bytes
-rw-r--r--textures/celevator_fs1switch_reset.pngbin0 -> 10882 bytes
8 files changed, 226 insertions, 5 deletions
diff --git a/controller.lua b/controller.lua
index b4c36c7..90fd841 100644
--- a/controller.lua
+++ b/controller.lua
@@ -157,7 +157,7 @@ minetest.register_node("celevator:controller",{
local carid = celevator.storage:get_int("maxcarid")+1
meta:set_int("carid",carid)
celevator.storage:set_int("maxcarid",carid)
- celevator.storage:set_string(string.format("car%d",carid),minetest.serialize({controllerpos=pos,pis={},lanterns={},callbuttons={}}))
+ celevator.storage:set_string(string.format("car%d",carid),minetest.serialize({controllerpos=pos,pis={},lanterns={},callbuttons={},fs1switches={}}))
celevator.controller.run(pos,event)
end,
on_punch = function(pos,node,puncher)
@@ -507,6 +507,14 @@ function celevator.controller.finish(pos,mem,changedinterrupts)
celevator.lantern.setlight(lantern.pos,"down",newlanterns[lantern.landing] == "down")
end
end
+ local oldfs1led = oldmem.fs1led
+ local newfs1led = mem.fs1led
+ local fs1switches = carinfo.fs1switches or {}
+ if oldfs1led ~= newfs1led then
+ for _,fs1switch in pairs(fs1switches) do
+ celevator.fs1switch.setled(fs1switch.pos,newfs1led)
+ end
+ 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
@@ -583,6 +591,14 @@ function celevator.controller.handlecallbutton(controllerpos,landing,dir)
celevator.controller.run(controllerpos,event)
end
+function celevator.controller.handlefs1switch(controllerpos,on)
+ local event = {
+ type = "fs1switch",
+ state = on,
+ }
+ 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 4d95aea..8e5cb2d 100644
--- a/controllerfw.lua
+++ b/controllerfw.lua
@@ -209,6 +209,8 @@ if event.type == "program" then
mem.activefaults = {}
mem.faultlog = {}
mem.fatalfault = false
+ mem.fs1sw = false
+ mem.fs1led = false
mem.fs2sw = "off"
mem.indsw = false
mem.lightsw = true
@@ -222,6 +224,7 @@ if event.type == "program" then
floornames = {"1","2","3"},
doortimer = 5,
groupmode = "simplex",
+ mainlanding = 1,
}
end
elseif event.type == "ui" then
@@ -327,6 +330,10 @@ elseif event.type == "ui" then
if contractspeed and contractspeed >= 0.1 and contractspeed <= 20 then
mem.params.contractspeed = contractspeed
end
+ local mainlanding = tonumber(event.fields.mainlanding)
+ if mainlanding and mainlanding >= 1 and mainlanding <= #mem.params.floorheights then
+ mem.params.mainlanding = math.floor(mainlanding)
+ end
elseif event.fields.floortable then
mem.screenstate = "floortable"
elseif event.fields.cancel then
@@ -428,7 +435,7 @@ elseif event.type == "callbutton" and mem.carstate == "normal" then
elseif event.iid == "checkopen" then
if mem.drive.status.doorstate == "open" then
interrupt(0,"opened")
- if mem.carstate == "normal" or mem.carstate == "indep" then interrupt(nil,"opentimeout") end
+ if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs1" then interrupt(nil,"opentimeout") end
else
interrupt(0.2,"checkopen")
end
@@ -475,6 +482,9 @@ elseif event.type == "copswitches" then
elseif fields.indoff then
mem.indsw = false
end
+elseif event.type == "fs1switch" then
+ mem.fs1switch = event.state
+ mem.fs1led = event.state
end
local oldstate = mem.carstate
@@ -500,6 +510,25 @@ elseif mem.controllerinspectsw and not mem.cartopinspectsw then
mem.dncalls = {}
mem.direction = nil
if oldstate ~= "mrinspect" then drivecmd({command="estop"}) end
+elseif mem.fs1switch and mem.fs2switch ~= "on" then
+ mem.carstate = "fs1"
+ mem.carcalls = {}
+ mem.upcalls = {}
+ mem.dncalls = {}
+ interrupt(nil,"close")
+ if getpos() ~= (mem.params.mainlanding or 1) then
+ if not (mem.carmotion or juststarted) then
+ if mem.doorstate == "closed" then
+ gotofloor(mem.params.mainlanding or 1)
+ elseif mem.doorstate == "open" then
+ close()
+ end
+ end
+ elseif mem.doorstate == "closed" then
+ if not (mem.carmotion or juststarted) then
+ open()
+ end
+ end
elseif mem.indsw then
if mem.carstate ~= "resync" then mem.carstate = "indep" end
mem.upcalls = {}
@@ -533,7 +562,10 @@ else
if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then
mem.carstate = "resync"
gotofloor(getpos())
- elseif oldstate == "test" or oldstate == "capture" then
+ elseif oldstate == "test" or oldstate == "capture" or oldstate == "fs1" then
+ if oldstate == "fs1" and mem.doorstate == "open" then
+ interrupt(mem.params.doortimer,"close")
+ end
mem.carstate = "normal"
elseif oldstate == "indep" then
mem.carstate = "normal"
@@ -546,7 +578,7 @@ if mem.carmotion then
if mem.carmotion then
interrupt(0.1,"checkdrive")
else
- if mem.carstate == "normal" or mem.carstate == "indep" then
+ if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs1" then
mem.carcalls[getpos()] = nil
if mem.direction == "up" then
mem.upcalls[getpos()] = nil
@@ -558,7 +590,10 @@ if mem.carmotion then
elseif getpos() <= 1 then
mem.direction = "up"
end
- open()
+ if mem.carstate ~= "fs1" or getpos() == (mem.params.mainlanding or 1) then open() end
+ if mem.carstate == "fs1" and getpos() ~= (mem.params.mainlanding or 1) then
+ gotofloor(mem.params.mainlanding or 1)
+ end
elseif mem.carstate == "test" then
mem.carcalls[getpos()] = nil
mem.doorstate = "testtiming"
@@ -785,6 +820,7 @@ elseif mem.screenstate == "parameters" then
fs("button[8,10;3,1;floortable;Edit Floor Table]")
fs(string.format("field[1,3;3,1;doortimer;Door Dwell Timer;%0.1f]",mem.params.doortimer))
fs(string.format("field[1,5;3,1;contractspeed;Contract Speed (m/s);%0.1f]",mem.params.contractspeed))
+ fs(string.format("field[1,7;3,1;mainlanding;Main Landing;%d]",mem.params.mainlanding or 1))
elseif mem.screenstate == "faults" then
fs("label[1,1;FAULT HISTORY]")
if #mem.faultlog > 0 then
diff --git a/fs1switch.lua b/fs1switch.lua
new file mode 100644
index 0000000..d63d2f1
--- /dev/null
+++ b/fs1switch.lua
@@ -0,0 +1,168 @@
+celevator.fs1switch = {}
+
+local function maketex(switchpos,lit)
+ local tex = "celevator_fs1switch_"..switchpos..".png"
+ if lit then tex = tex.."^celevator_fs1switch_led.png" end
+ return tex
+end
+
+local nodebox = {
+ {-0.219,-0.198,0.475,0.214,0.464,0.5},
+ {-0.188,-0.349,0.49,0.182,-0.229,0.5},
+}
+
+local function resetspring(pos)
+ local node = minetest.get_node(pos)
+ local offstates = {
+ ["celevator:fs1switch_reset"] = "celevator:fs1switch_off",
+ ["celevator:fs1switch_reset_lit"] = "celevator:fs1switch_off_lit",
+ }
+ if offstates[node.name] then
+ node.name = offstates[node.name]
+ minetest.swap_node(pos,node)
+ end
+end
+
+local function rightclick(pos,node,player)
+ if not (player and player:is_player()) then return end
+ local meta = minetest.get_meta(pos)
+ if meta:get_string("formspec") ~= "" then return end
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.chat_send_player(name,"You don't have a key for this switch.")
+ minetest.record_protection_violation(pos,name)
+ return
+ end
+ if node.name == "celevator:fs1switch_off" then
+ node.name = "celevator:fs1switch_on"
+ minetest.swap_node(pos,node)
+ elseif node.name == "celevator:fs1switch_on" then
+ node.name = "celevator:fs1switch_reset"
+ minetest.swap_node(pos,node)
+ minetest.after(0.5,resetspring,pos)
+ elseif node.name == "celevator:fs1switch_off_lit" or node.name == "celevator:fs1switch_on_lit" then
+ node.name = "celevator:fs1switch_reset_lit"
+ minetest.swap_node(pos,node)
+ minetest.after(0.5,resetspring,pos)
+ end
+ 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 then return end
+ local controllerpos = carinfo.controllerpos
+ local controllermeta = minetest.get_meta(controllerpos)
+ if controllermeta:get_int("carid") ~= carid then return end
+ if node.name == "celevator:fs1switch_reset" or node.name == "celevator:fs1switch_reset_lit" then
+ celevator.controller.handlefs1switch(controllerpos,false)
+ elseif node.name == "celevator:fs1switch_on" or node.name == "celevator:fs1switch_on_lit" then
+ celevator.controller.handlefs1switch(controllerpos,true)
+ end
+end
+
+function celevator.fs1switch.setled(pos,on)
+ local offstates = {
+ ["celevator:fs1switch_on_lit"] = "celevator:fs1switch_on",
+ ["celevator:fs1switch_off_lit"] = "celevator:fs1switch_off",
+ ["celevator:fs1switch_reset_lit"] = "celevator:fs1switch_reset",
+ }
+ local onstates = {
+ ["celevator:fs1switch_on"] = "celevator:fs1switch_on_lit",
+ ["celevator:fs1switch_off"] = "celevator:fs1switch_off_lit",
+ ["celevator:fs1switch_reset"] = "celevator:fs1switch_reset_lit",
+ }
+ local node = minetest.get_node(pos)
+ if on and onstates[node.name] then
+ node.name = onstates[node.name]
+ minetest.swap_node(pos,node)
+ elseif (not on) and offstates[node.name] then
+ node.name = offstates[node.name]
+ minetest.swap_node(pos,node)
+ end
+end
+
+local function unpair(pos)
+ 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.fs1switches) then return end
+ for i,fs1switch in pairs(carinfo.fs1switches) do
+ if vector.equals(pos,fs1switch.pos) then
+ table.remove(carinfo.fs1switches,i)
+ celevator.storage:set_string(string.format("car%d",carid),minetest.serialize(carinfo))
+ end
+ end
+end
+
+local switchstates = {"off","on","reset"}
+
+for _,switchpos in ipairs(switchstates) do
+ minetest.register_node("celevator:fs1switch_"..switchpos,{
+ description = "Fire Service Phase 1 Keyswitch"..(switchpos == "off" and "" or string.format(" (%s state - you hacker you!)",switchpos)),
+ groups = {
+ dig_immediate = 2,
+ not_in_creative_inventory = (switchpos == "off" and 0 or 1),
+ _celevator_fs1switch = 1,
+ },
+ drop = "celevator:fs1switch_off",
+ tiles = {
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ maketex(switchpos,false),
+ },
+ paramtype = "light",
+ paramtype2 = "facedir",
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = nodebox,
+ },
+ after_place_node = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("formspec","formspec_version[7]size[8,5]field[0.5,0.5;7,1;carid;Car ID;]button[3,3.5;2,1;save;Save]")
+ end,
+ on_receive_fields = function(pos,_,fields)
+ local carid = tonumber(fields.carid or 0)
+ if not (carid and carid >= 1 and carid == math.floor(carid)) then return end
+ local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid)))
+ if not carinfo then return end
+ if not carinfo.fs1switches then carinfo.fs1switches = {} end
+ table.insert(carinfo.fs1switches,{pos=pos})
+ celevator.storage:set_string(string.format("car%d",carid),minetest.serialize(carinfo))
+ local meta = minetest.get_meta(pos)
+ meta:set_int("carid",carid)
+ meta:set_string("formspec","")
+ end,
+ on_rightclick = rightclick,
+ on_destruct = unpair,
+ })
+ minetest.register_node("celevator:fs1switch_"..switchpos.."_lit",{
+ description = "Fire Service Phase 1 Keyswitch"..string.format(" (%s state, lit - you hacker you!)",switchpos),
+ groups = {
+ dig_immediate = 2,
+ not_in_creative_inventory = 1,
+ _celevator_fs1switch = 1,
+ },
+ drop = "celevator:fs1switch_off",
+ tiles = {
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ "celevator_cabinet_sides.png",
+ maketex(switchpos,true),
+ },
+ paramtype = "light",
+ paramtype2 = "facedir",
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = nodebox,
+ },
+ on_rightclick = rightclick,
+ on_destruct = unpair,
+ })
+end
diff --git a/init.lua b/init.lua
index 0b59dae..855b6a9 100644
--- a/init.lua
+++ b/init.lua
@@ -7,6 +7,7 @@ local components = {
"controller",
"callbuttons",
"pilantern",
+ "fs1switch",
}
for _,v in ipairs(components) do
diff --git a/textures/celevator_fs1switch_led.png b/textures/celevator_fs1switch_led.png
new file mode 100644
index 0000000..827ff7c
--- /dev/null
+++ b/textures/celevator_fs1switch_led.png
Binary files differ
diff --git a/textures/celevator_fs1switch_off.png b/textures/celevator_fs1switch_off.png
new file mode 100644
index 0000000..774ee62
--- /dev/null
+++ b/textures/celevator_fs1switch_off.png
Binary files differ
diff --git a/textures/celevator_fs1switch_on.png b/textures/celevator_fs1switch_on.png
new file mode 100644
index 0000000..5dd55c3
--- /dev/null
+++ b/textures/celevator_fs1switch_on.png
Binary files differ
diff --git a/textures/celevator_fs1switch_reset.png b/textures/celevator_fs1switch_reset.png
new file mode 100644
index 0000000..92459ec
--- /dev/null
+++ b/textures/celevator_fs1switch_reset.png
Binary files differ