diff --git a/hud.lua b/hud.lua index 72f7375..b2d834c 100644 --- a/hud.lua +++ b/hud.lua @@ -7,10 +7,10 @@ function ham_radio.toggle_hud(player) if item:get_name() ~= "ham_radio:receiver" then if ham_radio.is_receiver_wielded[name] then player:hud_remove(ham_radio.playerhuds[name].background) - player:hud_remove(ham_radio.playerhuds[name].frequency) + player:hud_remove(ham_radio.playerhuds[name].frequency) player:hud_remove(ham_radio.playerhuds[name].signal_meter) player:hud_remove(ham_radio.playerhuds[name].signal_level) - ham_radio.is_receiver_wielded[name] = false + ham_radio.is_receiver_wielded[name] = false end return false end @@ -31,14 +31,14 @@ function ham_radio.toggle_hud(player) position = hud_pos, offset = { x = -250, y = 20 }, text = "ham_radio_hud_bg.png", - scale = { x = 2, y = 3 }, + scale = { x = 2, y = 2 }, alignment = { x = 1, y = 0 }, }), frequency = player:hud_add({ hud_elem_type = "text", text = "", position = hud_pos, - offset = { x = 0, y = 0 }, + offset = { x = 0, y = 5 }, alignment = 0, number = 0xFFFFFF, scale= { x = 100, y = 20 }, @@ -46,17 +46,17 @@ function ham_radio.toggle_hud(player) signal_meter = player:hud_add({ hud_elem_type = "image", position = hud_pos, - offset = { x = -220, y = 30 }, + offset = { x = -220, y = 35 }, text = "ham_radio_hud_indicator_empty.png", - scale = { x = 2, y = 2 }, + scale = { x = 2, y = 1 }, alignment = { x = 1, y = 0 }, }), signal_level = player:hud_add({ hud_elem_type = "image", position = hud_pos, - offset = { x = -220, y = 30 }, + offset = { x = -220, y = 35 }, text = "ham_radio_hud_indicator_full.png", - scale = { x = 0, y = 2 }, + scale = { x = 0, y = 1 }, alignment = { x = 1, y = 0 }, }) } @@ -77,20 +77,17 @@ function ham_radio:update_hud_display(player) if frequency ~= nil and frequency ~= "" then local transmitter = self.read_transmitter(frequency) - -- minetest.chat_send_player(player:get_player_name(), "Found transmitter:"..minetest.serialize(transmitter)) if transmitter.pos then transmitter_signal = self:locate_transmitter(player, transmitter.pos) end end - -- local target_pos = {x=-407, y = 59, z = 70} - - --local indicator = string.rep('|', transmitter.distance)..string.rep('|', transmitter.signal)..string.rep(':', 25-(transmitter.distance + transmitter.signal)) - local indicator = string.rep('|', transmitter_signal)..string.rep(':', 20 - transmitter_signal) - - --local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]"..indicator - local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]" + local text = "FQ "..tostring(meta:get_string("frequency")) player:hud_change(self.playerhuds[name].frequency, "text", text) - player:hud_change(self.playerhuds[name].signal_level, "scale", { x = (transmitter_signal * 20) / 200 or 0.1, y = 2 }) + player:hud_change( + self.playerhuds[name].signal_level, + "scale", + { x = transmitter_signal/50 or 0.1, y = 1 } -- x scale should be 0-2 + ) end minetest.register_on_newplayer(ham_radio.toggle_hud) diff --git a/receiver.lua b/receiver.lua index 8497fb1..7308c21 100644 --- a/receiver.lua +++ b/receiver.lua @@ -38,18 +38,23 @@ function ham_radio:locate_transmitter(player, transmitter_pos) local player_look_vector = player:get_look_dir() local player_direction = vector.add(player_pos, player_look_vector) - local distance = vector.distance(player_pos, transmitter_pos) + local coeff = 0.9 + local distance_to_target = 0 - -- local distance_to_target = 13 - math.floor(math.log(distance*30)) - local distance_to_target = 24 - math.floor(2 * math.log(distance*10)) + local distance = vector.distance(player_pos, transmitter_pos) + if distance < 3 then + distance_to_target = 100 + coeff = 0.99 + else + distance_to_target = -0.0000000001*math.pow(distance,3)+0.00000145*math.pow(distance,2)-0.03*distance+100 + if distance_to_target < 3 then + distance_to_target = 3 + end + end local distance2 = vector.distance(player_direction, transmitter_pos) - local signal_power = 1 - ((1 + distance2 - distance) / 2) + local signal_power = distance - distance2; - return math.floor(distance_to_target * signal_power); - - --return { - -- distance = distance_to_target, - -- signal = signal_power - -- } + -- 0-100 + return distance_to_target * coeff + distance_to_target * (1 - coeff) * signal_power; end