diff --git a/craft.lua b/craft.lua index f261a6a..c81cb1a 100644 --- a/craft.lua +++ b/craft.lua @@ -40,6 +40,15 @@ minetest.register_craft({ } }) +minetest.register_craft({ + output = "ham_radio:receiver", + recipe = { + {body, antenna, body}, + {glass,'ham_radio:circuit', glass}, + {body, body, body} + } +}) + minetest.register_craft({ output = "ham_radio:transmitter", recipe = { diff --git a/init.lua b/init.lua index 1254b9c..fed9d7d 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ ham_radio = rawget(_G, "ham_radio") or {} ham_radio = { playerhuds = {}, player_rds = {}, + receiver_rds = {}, is_receiver_wielded = {}, transmitters = {}, } @@ -53,6 +54,7 @@ dofile(modpath.."/transmitter.lua") dofile(modpath.."/receiver.lua") dofile(modpath.."/beacon.lua") dofile(modpath.."/rds.lua") +dofile(modpath.."/receiver_station.lua") dofile(modpath.."/hud.lua") -- globals diff --git a/rds.lua b/rds.lua index d38e9ec..d340ee4 100644 --- a/rds.lua +++ b/rds.lua @@ -1,4 +1,4 @@ -function ham_radio.get_rds_messages(frequency) +function ham_radio.get_rds_messages(frequency, is_receiver_station) local transmitters = ham_radio.find_transmitters(frequency) local rds_messages = {} for position, transmitter in pairs(transmitters) do @@ -10,6 +10,15 @@ function ham_radio.get_rds_messages(frequency) ' ] ', transmitter.rds_message, }, "") + if is_receiver_station then + message = table.concat({ + '[ ', + transmitter.operated_by, + ' ] ', + transmitter.rds_message + }, "") + end + table.insert(rds_messages, message) end end diff --git a/receiver_station.lua b/receiver_station.lua new file mode 100644 index 0000000..acc3135 --- /dev/null +++ b/receiver_station.lua @@ -0,0 +1,111 @@ +ham_radio.receiver_update_infotext = function(meta) + local rds_message = meta:get_string("rds_message") + local infotext = 'Radio Receiver' + if rds_message ~= "" then + infotext = rds_message + end + meta:set_string("infotext", infotext) +end + +minetest.register_node("ham_radio:receiver", { + description = "Ham Radio Receiver", + tiles = { + "ham_radio_receiver_top.png", + "ham_radio_receiver_top.png", + "ham_radio_receiver_side.png", + "ham_radio_receiver_side.png", + "ham_radio_receiver_side.png", + "ham_radio_receiver_front.png" + }, + groups = {cracky=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_metal_defaults(), + paramtype2 = "facedir", + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + light_source = 3, + after_place_node = function(pos, placer) + local meta = minetest.get_meta(pos); + local name = placer:get_player_name() + meta:set_string("formspec", + table.concat({ + "size[7,4]", + "image[0,0;1,1;ham_radio_receiver_front.png]", + "field[0.25,2;7,1;frequency;Frequency;${frequency}]", + "tooltip[frequency;Integer number ", + ham_radio.settings.frequency.min,"-", + ham_radio.settings.frequency.max, "]", + "button_exit[2,3.5;3,1;;Done]" + },'') + ) + meta:set_string("infotext", 'Radio Receiver') + end, + on_receive_fields = function(pos, formname, fields, sender) + if not minetest.is_player(sender) then + return + end + + if ( + fields.quit ~= "true" + or minetest.is_protected(pos, sender:get_player_name()) + or not ham_radio.validate_frequency(fields.frequency) + ) then + return + end + + local meta = minetest.get_meta(pos) + meta:set_string("frequency", fields.frequency) + ham_radio.receiver_update_infotext(meta) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + local name = player:get_player_name() + return inv:is_empty("main") and not minetest.is_protected(pos, name) + end, + -- digiline + digiline = { + receptor = {action = function() end}, + effector = { + action = ham_radio.digiline_effector + }, + }, +}); + +minetest.register_abm( + { + label = "Listen Ham Radion Broadcast", + nodenames = {"ham_radio:receiver"}, + interval = 10, + chance = 1, + catch_up = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + local frequency = meta:get_string("frequency") + + if frequency == "" then + return + end + + local poshash = minetest.pos_to_string(pos, 0) + + if ham_radio.receiver_rds[poshash] == nil then + ham_radio.receiver_rds[poshash] = ham_radio.get_rds_messages(frequency, true) + end + + local message = table.remove(ham_radio.receiver_rds[poshash]) + if message ~= nil then + meta:set_string('rds_message', message) + ham_radio.receiver_update_infotext(meta) + + -- when all RDS messages are shown, reload them again + if not next(ham_radio.receiver_rds[poshash]) then + ham_radio.receiver_rds[poshash] = ham_radio.get_rds_messages(frequency, true) + end + end + end + } +); diff --git a/textures/ham_radio_receiver_front.png b/textures/ham_radio_receiver_front.png new file mode 100644 index 0000000..52d43fa Binary files /dev/null and b/textures/ham_radio_receiver_front.png differ diff --git a/textures/ham_radio_receiver_side.png b/textures/ham_radio_receiver_side.png new file mode 100644 index 0000000..b9b6486 Binary files /dev/null and b/textures/ham_radio_receiver_side.png differ diff --git a/textures/ham_radio_receiver_top.png b/textures/ham_radio_receiver_top.png new file mode 100644 index 0000000..c520203 Binary files /dev/null and b/textures/ham_radio_receiver_top.png differ