diff --git a/beacon.lua b/beacon.lua new file mode 100644 index 0000000..4448658 --- /dev/null +++ b/beacon.lua @@ -0,0 +1,38 @@ +minetest.register_node("ham_radio:beacon", { + description = "Ham Radio Beacon", + tiles = { + "ham_radio_transmitter_top.png", + "ham_radio_transmitter_top.png", + "ham_radio_transmitter_side.png", + "ham_radio_transmitter_side.png", + "ham_radio_transmitter_side.png", + "ham_radio_beacon_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 = 5, + after_place_node = function(pos, placer) + local meta = minetest.get_meta(pos); + local name = placer:get_player_name() + meta:set_string('operated_by', name) + meta:set_string("frequency", ham_radio.find_free_frequency(ham_radio.settings.beacon_frequency)) + ham_radio.transmitter_update_infotext(meta) + ham_radio.save_transmitter(pos, 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, + after_dig_node = function(pos, oldnode, oldmetadata, player) + ham_radio.delete_transmitter(pos) + end, +}); diff --git a/helpers.lua b/helpers.lua index 0cb26bc..ea93137 100644 --- a/helpers.lua +++ b/helpers.lua @@ -18,10 +18,10 @@ function ham_radio.find_transmitters(frequency) return transmitter_list end -function ham_radio.find_free_frequency() +function ham_radio.find_free_frequency(range) local frequency = -1 while frequency == -1 do - frequency = tostring(math.floor(math.random(ham_radio.settings.frequency.min, ham_radio.settings.frequency.max))); + frequency = tostring(math.floor(math.random(range.min, range.max))); local are_there_transmitters = ham_radio.find_transmitters(frequency) if next(are_there_transmitters) then frequency = -1 diff --git a/init.lua b/init.lua index 6cdec91..876ccca 100644 --- a/init.lua +++ b/init.lua @@ -16,6 +16,10 @@ ham_radio = { min = 0, max = 9999999 }, + beacon_frequency = { -- sub-range of frequency range + min = 1000000, + max = 9999999 + }, digiline_channel = "ham_radio", } } @@ -48,6 +52,7 @@ dofile(modpath.."/craft.lua") dofile(modpath.."/digiline.lua") dofile(modpath.."/transmitter.lua") dofile(modpath.."/receiver.lua") +dofile(modpath.."/beacon.lua") dofile(modpath.."/broadcast.lua") dofile(modpath.."/hud.lua") @@ -82,8 +87,3 @@ minetest.register_globalstep(function(dtime) broadcasttimer = 0 end end) - --- TODO: craft transmitter --- TODO: configure transmitter --- TODO: craft pelengator --- TODO: set pelengator frequency diff --git a/textures/ham_radio_beacon_front.png b/textures/ham_radio_beacon_front.png index 7876b91..8b40ddd 100644 Binary files a/textures/ham_radio_beacon_front.png and b/textures/ham_radio_beacon_front.png differ