diff options
author | cheapie <no-email-for-you@example.com> | 2018-08-31 23:28:21 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2018-08-31 23:28:21 -0500 |
commit | b1419ed0906cfc912add7f53ac4dc67d64becef4 (patch) | |
tree | ee2c97ffddbc2645c1879e7dd2f6f449fb8a79df | |
parent | 6dc64c7050c410e0979e520bbbd6b60ba46fb485 (diff) | |
download | firealarm-b1419ed0906cfc912add7f53ac4dc67d64becef4.tar firealarm-b1419ed0906cfc912add7f53ac4dc67d64becef4.tar.gz firealarm-b1419ed0906cfc912add7f53ac4dc67d64becef4.tar.bz2 firealarm-b1419ed0906cfc912add7f53ac4dc67d64becef4.tar.xz firealarm-b1419ed0906cfc912add7f53ac4dc67d64becef4.zip |
Add annunciator and re-alarm
-rw-r--r-- | firealarm_annunciator/depends.txt | 2 | ||||
-rw-r--r-- | firealarm_annunciator/init.lua | 421 | ||||
-rw-r--r-- | firealarm_annunciator/sounds/firealarm_annunciator_piezo.ogg | bin | 0 -> 5318 bytes | |||
-rw-r--r-- | firealarm_annunciator/textures/firealarm_annunciator_front_normal.png | bin | 0 -> 3337 bytes | |||
-rw-r--r-- | firealarm_common/init.lua | 4 | ||||
-rw-r--r-- | firealarm_panel/init.lua | 36 |
6 files changed, 459 insertions, 4 deletions
diff --git a/firealarm_annunciator/depends.txt b/firealarm_annunciator/depends.txt new file mode 100644 index 0000000..e8acc00 --- /dev/null +++ b/firealarm_annunciator/depends.txt @@ -0,0 +1,2 @@ +firealarm_common +firealarm_panel diff --git a/firealarm_annunciator/init.lua b/firealarm_annunciator/init.lua new file mode 100644 index 0000000..59c1b77 --- /dev/null +++ b/firealarm_annunciator/init.lua @@ -0,0 +1,421 @@ +local function setFormspec(pos) + local annInfo = firealarm.getDevInfo("annunciator",pos) + if not annInfo or not annInfo.associated then return end + local panelPos = minetest.get_position_from_hash(annInfo.associated) + local devInfo = firealarm.getDevInfo("panel",panelPos) + if not devInfo then return end + local meta = minetest.get_meta(pos) + local fs = "size[10,10]label[0.5,0.5;MineAlert 851+ Fire Alarm Annunciator]" + if #devInfo.alarm > 0 then + if devInfo.silenced then + fs = fs.."label[0.5,2;Alarm Silenced]" + else + if devInfo.acked then + fs = fs.."label[0.5,2;Alarm Acknowledged]" + else + fs = fs.."label[0.5,2;ALARM! - "..minetest.formspec_escape(devInfo.alarm[#devInfo.alarm].name).."]" + end + end + elseif #devInfo.supervisory > 0 then + if devInfo.acked then + fs = fs.."label[0.5,2;Supervisory Acknowledged]" + else + fs = fs.."label[0.5,2;Supervisory - "..minetest.formspec_escape(devInfo.supervisory[#devInfo.supervisory].name).."]" + end + elseif #devInfo.trouble > 0 then + if devInfo.acked then + fs = fs.."label[0.5,2;Trouble Acknowledged]" + else + fs = fs.."label[0.5,2;Trouble - "..minetest.formspec_escape(devInfo.trouble[#devInfo.trouble].name).."]" + end + else + fs = fs.."label[0.5,2;System Normal]" + end + fs = fs.."button[0.5,3;3,1;ack;Acknowledge]" + fs = fs.."button[0.5,4;3,1;silence;Silence]" + fs = fs.."button[0.5,5;3,1;reset;Reset]" + fs = fs.."button[0.5,6;3,1;drill;Drill]" + meta:set_string("formspec",fs) +end + +local function handleFields(pos,_,fields,sender) + local annInfo = firealarm.getDevInfo("annunciator",pos) + if not annInfo or not annInfo.associated then return end + local panelPos = minetest.get_position_from_hash(annInfo.associated) + firealarm.loadNode(panelPos) + local devInfo = firealarm.getDevInfo("panel",panelPos) + if fields.quit or not devInfo then return end + local name = sender:get_player_name() + if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,"protection_bypass") then + minetest.chat_send_player(name,"You are not authorized to use this annunciator.") + minetest.record_protection_violation(pos,name) + return + end + if fields.ack then + devInfo.acked = true + elseif fields.silence and #devInfo.alarm > 0 and devInfo.acked then + devInfo.silenced = true + elseif fields.reset and devInfo.acked then + devInfo.alarm = {} + devInfo.supervisory = {} + devInfo.trouble = {} + devInfo.acked = false + devInfo.silenced = false + for i in pairs(devInfo.associatedSignalingDevices) do + local dev = firealarm.getDevInfo("signaling",minetest.get_position_from_hash(i)) + if dev and not dev.manualReset then + dev.active = false + end + end + elseif fields.drill then + table.insert(devInfo.alarm,{initiator = annInfo.associated,name = "Panel Drill Switch"}) + devInfo.acked = false + devInfo.silenced = false + end + firealarm.setDevInfo("panel",pos,devInfo) + setFormspec(pos) +end + +minetest.register_node(":firealarm:annunciator",{ + description = "Fire Alarm Annunciator", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_annunciator_front_normal.png", + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_place_node = function(pos) + firealarm.setDevInfo("annunciator",pos,{}) + setFormspec(pos) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_alarm",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:panel", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_alarm.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_supervisory",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:annunciator", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_supervisory.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_trouble",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:annunciator", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_trouble.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_alarm_trouble",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:annunciator", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_alarm.png:0,64=firealarm_panel_led_trouble.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_alarm_supervisory",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:annunciator", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_alarm.png:0,64=firealarm_panel_led_supervisory.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_supervisory_trouble",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:annunciator", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_supervisory.png:0,64=firealarm_panel_led_trouble.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +minetest.register_node(":firealarm:annunciator_alarm_supervisory_trouble",{ + description = "Fire Alarm Annunciator (LEDs on - you hacker you!)", + drop = "firealarm:panel", + groups = { oddly_breakable_by_hand = 1,firealarm_annunciator = 1,not_in_creative_inventory = 1}, + tiles = { + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + "firealarm_panel_sides.png", + { + name = "[combine:64x128:0,0=firealarm_annunciator_front_normal.png:0,64=firealarm_annunciator_front_normal.png:0,64=firealarm_panel_led_alarm.png:0,64=firealarm_panel_led_supervisory.png:0,64=firealarm_panel_led_trouble.png", + animation = + { + type = "vertical_frames", + aspect_w = 64, + aspect_h = 64, + length = 0.5, + }, + } + }, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2,0.13,0.4,0.2,0.34,0.5}, + }, + }, + on_punch = function(pos,_,player) + local name = player:get_player_name() + minetest.chat_send_player(name,string.format("Position: %d,%d,%d",pos.x,pos.y,pos.z)) + end, + after_dig_node = function(pos) + firealarm.setDevInfo("annunciator",pos,nil) + end, + on_receive_fields = handleFields, +}) + +function firealarm.annunciatorABM(pos) + local annInfo = firealarm.getDevInfo("annunciator",pos) + if not annInfo or not annInfo.associated then return end + local panelPos = minetest.get_position_from_hash(annInfo.associated) + local devInfo = firealarm.getDevInfo("panel",panelPos) + if not devInfo then return end + local node = minetest.get_node(pos) + local currentName = node.name + local newName = "firealarm:annunciator" + if #devInfo.alarm > 0 then newName = newName.."_alarm" end + if #devInfo.supervisory > 0 then newName = newName.."_supervisory" end + if #devInfo.trouble > 0 then newName = newName.."_trouble" end + if newName ~= "firealarm:annunciator" and not devInfo.acked then + minetest.sound_play("firealarm_annunciator_piezo",{pos = pos,gain = 0.5}) + end + if currentName ~= newName then + node.name = newName + minetest.set_node(pos,node) + end + setFormspec(pos) +end + +minetest.register_abm({ + label = "Poll devices and update panel status", + nodenames = {"group:firealarm_annunciator"}, + interval = 1, + chance = 1, + action = firealarm.annunciatorABM, +}) diff --git a/firealarm_annunciator/sounds/firealarm_annunciator_piezo.ogg b/firealarm_annunciator/sounds/firealarm_annunciator_piezo.ogg Binary files differnew file mode 100644 index 0000000..6f87642 --- /dev/null +++ b/firealarm_annunciator/sounds/firealarm_annunciator_piezo.ogg diff --git a/firealarm_annunciator/textures/firealarm_annunciator_front_normal.png b/firealarm_annunciator/textures/firealarm_annunciator_front_normal.png Binary files differnew file mode 100644 index 0000000..319be21 --- /dev/null +++ b/firealarm_annunciator/textures/firealarm_annunciator_front_normal.png diff --git a/firealarm_common/init.lua b/firealarm_common/init.lua index 34ab2ca..b8806b3 100644 --- a/firealarm_common/init.lua +++ b/firealarm_common/init.lua @@ -44,7 +44,7 @@ function firealarm.saveDevLists() end function firealarm.getDevInfo(devType,pos) - if devType ~= "panel" and devType ~= "signaling" and devType ~= "notification" then + if devType ~= "panel" and devType ~= "signaling" and devType ~= "notification" and devType ~= "annunciator" then error("Invalid device type specified") end local hash = minetest.hash_node_position(pos) @@ -52,7 +52,7 @@ function firealarm.getDevInfo(devType,pos) end function firealarm.setDevInfo(devType,pos,info) - if devType ~= "panel" and devType ~= "signaling" and devType ~= "notification" then + if devType ~= "panel" and devType ~= "signaling" and devType ~= "notification" and devType ~= "annunciator" then error("Invalid device type specified") end local hash = minetest.hash_node_position(pos) diff --git a/firealarm_panel/init.lua b/firealarm_panel/init.lua index 7adc1ea..3071e31 100644 --- a/firealarm_panel/init.lua +++ b/firealarm_panel/init.lua @@ -66,6 +66,11 @@ local function setFormspec(pos) table.insert(devInfo.removeMenuDevList,dev) fs = fs..minetest.formspec_escape(v.name).."," end + for k,v in pairs(devInfo.associatedAnnunciators) do + local dev = {type = "annunciator",hash = k} + table.insert(devInfo.removeMenuDevList,dev) + fs = fs..minetest.formspec_escape(v.name).."," + end fs = string.sub(fs,1,-1).."]" else fs = fs.."label[0.5,5;No Devices Associated]" @@ -90,6 +95,7 @@ local function alarm(pos,initiator) end table.insert(devInfo.alarm,{initiator = initiatorHash,name = name}) devInfo.acked = false + devInfo.silenced = false firealarm.setDevInfo("panel",pos,devInfo) setFormspec(pos) end @@ -125,6 +131,9 @@ local function trouble(pos,initiator) if devInfo.associatedNotificationDevices[initiatorHash] then name = devInfo.associatedNotificationDevices[initiatorHash].name end + if devInfo.associatedAnnunciators[initiatorHash] then + name = devInfo.associatedAnnunciators[initiatorHash].name + end table.insert(devInfo.trouble,{initiator = initiatorHash,name = name}) devInfo.acked = false firealarm.setDevInfo("panel",pos,devInfo) @@ -197,7 +206,22 @@ local function handleFields(pos,_,fields,sender) devInfo.associatedNotificationDevices[minetest.hash_node_position(targetPos)] = devParams end else - minetest.chat_send_player(name,"Not a valid fire alarm device") + targetInfo = firealarm.getDevInfo("annunciator",targetPos) + if targetInfo then + if (minetest.is_protected(pos,name) and not minetest.check_player_privs(name,"protection_bypass")) or targetInfo.associated then + minetest.chat_send_player(name,"Device is protected or already associated") + else + targetInfo.associated = minetest.hash_node_position(pos) + local devParams = {} + devParams.name = fields.name + if not devInfo.associatedAnnunciators then + devInfo.associatedAnnunciators = {} + end + devInfo.associatedAnnunciators[minetest.hash_node_position(targetPos)] = devParams + end + else + minetest.chat_send_player(name,"Not a valid fire alarm device") + end end end else @@ -229,6 +253,14 @@ local function handleFields(pos,_,fields,sender) targetInfo.strobeActive = false firealarm.setDevInfo("notification",targetPos,targetInfo) end + elseif dev.type == "annunciator" then + devInfo.associatedAnnunciators[dev.hash] = nil + local targetPos = minetest.get_position_from_hash(dev.hash) + local targetInfo = firealarm.getDevInfo("annunciator",targetPos) + if targetInfo then + targetInfo.associated = nil + firealarm.setDevInfo("annunciator",targetPos,targetInfo) + end end end end @@ -579,8 +611,8 @@ function firealarm.panelABM(pos) if currentName ~= newName then node.name = newName minetest.set_node(pos,node) - setFormspec(pos) end + setFormspec(pos) end minetest.register_abm({ |