add beacons (self-configurable transmitters)

This commit is contained in:
techniX 2019-12-08 03:10:27 +02:00
parent 59e29f5e3a
commit 3a1b5cde9d
4 changed files with 45 additions and 7 deletions

38
beacon.lua Normal file

@ -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,
});

@ -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

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB