dofile(LockOn_Options.script_path.."command_defs.lua")
dofile(LockOn_Options.script_path.."devices.lua") -- "script_path" is main scripts folder. common is local.

local rate = 0.5
make_default_activity(rate) -- gets plane info

local Data = get_base_data() 

local dev = GetSelf()

-- Start VAG

function post_initialize()
	smoke_on = false
	smoke_press = false
	smoke_armed = false
	smoke_equipped0 = false
	smoke_equipped1 = false
	smoke_equipped2 = false
	smoke_equipped3 = false
	smoke_equipped = false
	messagesent = false
	safemessagesent = false
	
	--Smokes


	Smoke1 = "{D3F65166-1AB8-490f-AF2F-2FB6E22568B1}"
	Smoke2 = "{D3F65166-1AB8-490f-AF2F-2FB6E22568B2}"
	Smoke3 = "{D3F65166-1AB8-490f-AF2F-2FB6E22568B3}"
	Smoke4 = "{D3F65166-1AB8-490f-AF2F-2FB6E22568B4}"
	Smoke5 = "{D3F65166-1AB8-490f-AF2F-2FB6E22568B5}"
	Smoke6 = "{D3F65166-1AB8-490f-AF2F-2FB6E22568B6}"

-- End VAG	
	
	CSmoke1 = "{INV-SMOKE-RED}"
	CSmoke2 = "{INV-SMOKE-GREEN}"
	CSmoke3 = "{INV-SMOKE-BLUE}"
	CSmoke4 = "{INV-SMOKE-WHITE}"
	CSmoke5 = "{INV-SMOKE-YELLOW}"
	CSmoke6 = "{INV-SMOKE-ORANGE}"
	

end

dev:listen_command(7010)

--Start VAG

function Logic()
	
	ST0 = dev:get_station_info(0)
	ST0CLSID = ST0.CLSID
	
	if((ST0CLSID == Smoke1) or (ST0CLSID == Smoke2) or (ST0CLSID == Smoke3) or (ST0CLSID == Smoke4) or (ST0CLSID == Smoke5) or (ST0CLSID == Smoke6) ) then --If a smoke pod is on the 1 pylon
		smoke_equipped0 = true
	else
		smoke_equipped0 = false
	end
		
	ST1 = dev:get_station_info(1)
	ST1CLSID = ST1.CLSID
	
	if((ST1CLSID == Smoke1) or (ST1CLSID == Smoke2) or (ST1CLSID == Smoke3) or (ST1CLSID == Smoke4) or (ST1CLSID == Smoke5) or (ST1CLSID == Smoke6)) then --If a smoke pod is on the 2 pylon
		smoke_equipped1 = true
	else
		smoke_equipped1 = false
	end

		
	ST4 = dev:get_station_info(4)
	ST4CLSID = ST4.CLSID
	
	if((ST4CLSID == Smoke1) or (ST4CLSID == Smoke2) or (ST4CLSID == Smoke3) or (ST4CLSID == Smoke4) or (ST4CLSID == Smoke5) or (ST4CLSID == Smoke6)) then --If a smoke pod is on the 3 pylon
	smoke_equipped4 = true
	else
		smoke_equipped4 = false
	end
		
	ST5 = dev:get_station_info(5)
	ST5CLSID = ST5.CLSID
	
	if((ST5CLSID == Smoke1) or (ST5CLSID == Smoke2) or (ST5CLSID == Smoke3) or (ST5CLSID == Smoke4) or (ST5CLSID == Smoke5) or (ST5CLSID == Smoke6)) then --If a smoke pod is on the 4 pylon
		smoke_equipped5 = true
	else
		smoke_equipped5 = false
	end
	
				
	if smoke_equipped0 == true or smoke_equipped1 == true or smoke_equipped4 == true or smoke_equipped5 == true then --If a smoke pod is on any pylon
		smoke_equipped = true
	else
		smoke_equipped = false
	end

	
	if get_cockpit_draw_argument_value(569) >= 1 and smoke_equipped == true then
		smoke_armed = true
		safemessagesent = false
	
		if smoke_equipped0 == true and messagesent == false then --If a smoke pod is on the 1 pylon
			print_message_to_user("Smoke armed on pylon 1")
		end
		if smoke_equipped1 == true and messagesent == false then --If a smoke pod is on the 2 pylon
			print_message_to_user("Smoke armed on pylon 2")
		end		
		if smoke_equipped4 == true and messagesent == false then --If a smoke pod is on the 4 pylon
			print_message_to_user("Smoke armed on pylon 4")
		end		
		if smoke_equipped5 == true and messagesent == false then --If a smoke pod is on the 5 pylon
			print_message_to_user("Smoke armed on pylon 5")
		end			
		
		
		messagesent = true
	elseif get_cockpit_draw_argument_value(569) <= 1 and smoke_equipped == true then
		smoke_armed = false
		messagesent = false
	
		if smoke_on == true then

			if smoke_equipped0 == true and safemessagesent == false then --If a smoke pod is on the 1 pylon
				dev:launch_station(0);
			end
			if smoke_equipped1 == true and safemessagesent == false then --If a smoke pod is on the 2 pylon
				dev:launch_station(1);
			end		
			if smoke_equipped4 == true and safemessagesent == false then --If a smoke pod is on the 4 pylon
				dev:launch_station(4);
			end		
			if smoke_equipped5 == true and safemessagesent == false then --If a smoke pod is on the 5 pylon
				dev:launch_station(5);	
			end		
	
			smoke_on = false			
		end		
		
		if smoke_equipped == true and safemessagesent == false then --If a smoke pod is on any pylon
			print_message_to_user("Smoke Safe")
			safemessagesent = true	
		end	
		
	end

	if smoke_press == true and smoke_armed == true then 
		if smoke_equipped0 == true then --If a smoke pod is on the 1 pylon
			dev:launch_station(0);
		end
		if smoke_equipped1 == true then --If a smoke pod is on the 2 pylon
			dev:launch_station(1);
		end		
		if smoke_equipped4 == true then --If a smoke pod is on the 4 pylon
			dev:launch_station(4);
		end		
		if smoke_equipped5 == true then --If a smoke pod is on the 5 pylon
			dev:launch_station(5);	
		end		
	
		
		if smoke_on == true then
			smoke_on = false
			print_message_to_user("Smoke Off")
		else --If the smoke is off
			smoke_on = true
			print_message_to_user("Smoke On")
		end
	end
	smoke_press=false
end

-- End VAG

function SetCommand(command,value)
	
	if (command == 7010) and smoke_equipped == true then --and track_is_reading() == false then
		smoke_press = true  -- Record key press
	end
end

function update() -- Ties into "local rate" at top. Updates twice a second
	Logic()
end

need_to_be_closed = false