2019-12-07 20:24:49 +01:00
|
|
|
function ham_radio.validate_frequency(frequency)
|
2019-12-07 20:54:21 +01:00
|
|
|
local num_freq = tonumber(frequency)
|
2019-12-07 20:24:49 +01:00
|
|
|
local freq = tostring(num_freq)
|
|
|
|
return freq == frequency
|
2019-12-07 20:54:21 +01:00
|
|
|
and num_freq ~= nil
|
|
|
|
and num_freq == math.floor(num_freq)
|
2019-12-07 20:24:49 +01:00
|
|
|
and num_freq >= ham_radio.settings.frequency.min
|
|
|
|
and num_freq <= ham_radio.settings.frequency.max
|
|
|
|
end
|
2019-12-07 23:46:20 +01:00
|
|
|
|
|
|
|
function ham_radio.find_transmitters(frequency)
|
|
|
|
local transmitter_list = {}
|
|
|
|
for key, transmitter in pairs(ham_radio.transmitters) do
|
|
|
|
if transmitter.frequency == frequency then
|
|
|
|
transmitter_list[key] = transmitter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return transmitter_list
|
|
|
|
end
|
|
|
|
|
2019-12-08 02:10:27 +01:00
|
|
|
function ham_radio.find_free_frequency(range)
|
2019-12-07 23:46:20 +01:00
|
|
|
local frequency = -1
|
|
|
|
while frequency == -1 do
|
2019-12-08 02:10:27 +01:00
|
|
|
frequency = tostring(math.floor(math.random(range.min, range.max)));
|
2019-12-07 23:46:20 +01:00
|
|
|
local are_there_transmitters = ham_radio.find_transmitters(frequency)
|
|
|
|
if next(are_there_transmitters) then
|
|
|
|
frequency = -1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return frequency
|
|
|
|
end
|