dofile(LockOn_Options.script_path.."command_defs.lua")
dofile(LockOn_Options.script_path.."devices.lua")

local Dev = GetSelf()

local rate = 0.001
make_default_activity(rate)

local Data = get_base_data()

Dev:listen_command(9000)
Dev:listen_command(7004) -- on
Dev:listen_command(7005) -- increase strength
Dev:listen_command(7006) -- decrease strength
SPRING_PARAM = get_param_handle("SPRING_PARAM")
SPRING_OP = get_param_handle("SPRING_OP")


function post_initialize()
PIZZA = false
    print("post_initialize called in Spring.lua")
	sndhost 		= create_sound_host("SPRING","2D",0,0,0)
	attach		= sndhost:create_sound("Aircrafts/F-16C/Cockpit/spon")  -- refers to sdef file, and sdef file content refers to sound file, see DCSWorld/Sounds/sdef/_example.sdef
	detach		= sndhost:create_sound("Aircrafts/F-16C/Cockpit/spoff")
	timer = 0
	
	-- SPRING AMOUNT -- CHANGE "mod_pitch" if you wish to have a permanent value when you enter the jet. --
	mod_pitch = .1

end

function SetCommand(command,value)
	if (command == 9000) then
		input_pitch = value
	end
		
	if (command == 7004) and PIZZA == false then --on
			--print_message_to_user(input_pitch)
			--print_message_to_user("GO ON THE SPRINGS")
			attach:play_once()
			PIZZA = true
			timer = 0
	elseif (command == 7004) and PIZZA == true then	--off
			--attachlo:play_once()
			--print_message_to_user("DETACH THE SPRINGS")
			detach:play_once()
			PIZZA = false
			timer = 3
	end
	
	if (command == 7005) then -- INCREASE
		timer = 0
		if mod_pitch < .2 then
		mod_pitch = mod_pitch + .0025
		end
		--print_message_to_user("SPRING STRENGTH INCREASE:  "..mod_pitch,0.1)
	end
	
	if (command == 7006) then -- DECREASE
		timer = 0
		if mod_pitch > 0.0025 then
		mod_pitch = mod_pitch - .0025
		end
		--print_message_to_user("SPRING STRENGTH DECREASE:  "..mod_pitch,0.1)
	end
end
--sfm_exnteder.LUA
---------------	$drivervalue = $drivervalue * (1 + ($percentdiff / 100))
--	dispatch_action(nil, 2001,(input_pitch	* auth_pitch) 	+ mod_pitch) - preserves neg
--	dispatch_action(nil, 2002,(input_roll	* auth_roll) 	+ mod_roll)
---------------	
 -- full aft not avail add correction
function update()
	timer = timer + .001
	if timer < 3 then
	SPRING_OP:set(1)
	else
	SPRING_OP:set(0)
	end
--mod_pitchround = (math.floor(((mod_pitch*1000)+0.5))/1000)
--print_message_to_user(timer)
SPRING_PARAM:set(mod_pitch)
	percentcorrection = math.abs(input_pitch * mod_pitch)
	--print_message_to_user(percentcorrection)
	if PIZZA then
		dispatch_action(nil, 2001,percentcorrection+input_pitch-mod_pitch)			-- preserve negative
		--print_message_to_user(percentcorrection+input_pitch-mod_pitch
		else
		dispatch_action(nil, 2001,input_pitch)
		--print_message_to_user(input_pitch)
	end
end
--((mod_pitch-auth_pitch(SET)) -  Set in dispatch to stop loop. Causes trim to inverse.

-- A-4 file specifies a device in default.lua adds device number to value?

-- dispatch_action(nil, 2004,-1) wrong value
need_to_be_closed = false


