dofile('Scripts/World/Radio/Beacons.lua')

--radio receiver paramteres
min_frequency = 150000.0
max_frequency = 1750000.0
sensitivity = 0.0000000000066
frequency_accuracy = 100.0
max_distance = 350000.0

agr={} --automatic gain regulator
agr["input_signal_deviation"] = 37.0
agr["output_signal_deviation"]  = 0.3
agr["input_signal_linear_zone"] = 5.0
agr["regulation_time"] = 0.20

goniometer_bias			= {{math.rad(0.0), math.rad(360.0), math.rad(1.0)}} -- radians
goniometer_K1			= 1.1
goniometer_K2			= 0.45

--ADF paramenters
accuracy = 2.0
frequency_step = 100
band_width_tlg = 100.0
band_width_tlf = 3000.0
starting_time = 90.0
test_bearing_deviation = 45.0
frequency_changing_time = 2.0
min_elev_angle = -90.0
max_elev_angle = 10.0

mountainEffect = true
shorelineEffect = false --not implemented
nightEffect = true

--ADF constants
ADF_ADF = 0
ADF_ANTENNA = 1

ADF_RECEIVER_TLF = 0
ADF_RECEIVER_TLG = 1

ADF_HOMER_SELECTION_FAR_HOMER = 0
ADF_HOMER_SELECTION_AUTO = 1
ADF_HOMER_SELECTION_NEAR_HOMER	= 2

ADF_HOMER_FAR = 1
ADF_HOMER_NEAR = 2

--ADF channel data make functions

function NDB(homer)
	--NDB (non-airdrome beacons)
	return {
		name = homer.name,
		callsign = homer.callsign,
		frequency = homer.frequency
	}
end

function runway_homer(airdrome, runway_name, homer_subtype)
	--airdrome runway homer
	local homer_data = nil
	for ir, r in pairs(airdrome.runway) do
		if not runway_name or runway_name == ir then
			for irs, rs in pairs(r.side) do
				for ih, h in pairs(rs) do
					if not homer_subtype or h.subtype == homer_subtype then
						if homer_data == nil then
							homer_data = {							
								airdrome_id = airdrome.id,
								name = airdrome.name,
								frequency = h.frequency,
								callsign = ''}
						end
						if string.len(homer_data.callsign) > 0 then
							homer_data.callsign = homer_data.callsign..','
						end
						homer_data.callsign = homer_data.callsign..h.callsign
					end
				end
			end
		end
	end
	return homer_data
end

function runway_homer_pair(airdrome, runway)
	--airdrome runway homers pair
	return {
		[ADF_HOMER_FAR] = runway_homer(airdrome, runway, FAR_HOMER),
		[ADF_HOMER_NEAR] = runway_homer(airdrome, runway, NEAR_HOMER)
	}
end

function airdrome_homer(airdrome, homer)
	--airdrome (non-runway) homer
	return {	airdrome_id = airdrome.id,
				name = airdrome.name,
				frequency = homer.frequency,
				callsign = homer.callsign}
end

--ADF saved state

function Load_ADF_State()
    copy_to_mission_and_dofile(LockOn_Options.script_path.."ARK/ARK.lua")
end

RECEIVER_FAILURE = 0
DIRECTIONAL_ANTENNA_FAILURE = 1
NON_DIRECTIONAL_ANTENNA_FAILURE = 2
Damage = {	{Failure = RECEIVER_FAILURE, Element = 4, Intergrity_Treshold = 0.3}, 
			{Failure = NON_DIRECTIONAL_ANTENNA_FAILURE, Element = 5, Intergrity_Treshold = 0.3}, 
			{Failure = DIRECTIONAL_ANTENNA_FAILURE, Element = 56}, 
			{Failure = DIRECTIONAL_ANTENNA_FAILURE, Element = 57}}
