--------------------------------------------------------------------------------
--
--	TUTORIAL 3
--
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
--
--	globals
--
--------------------------------------------------------------------------------

gActiveMenu = -1		
gTutorialStep =1		
gTemp = 0			

gSpaceOk= 1
gPrevTutStep = -1

gTextStep = 1

gWantedBuilding = -1

----------------------------------------------------------------------------------

function OnDragBuilding(type)
    if gWantedBuilding == -1 then
        return
    end

	if (gWantedBuilding == type) then
        gTutorialStep = gTutorialStep+1
        gWantedBuilding = -1
    end
end

-------------------------------------------------------------------------------

function OnCommand(command)
   	if (command == Control-DLG_TUTORIAL_CMD_NEXT ) then
		OnSpace()
	end
end
-------------------------------------------------------------------------------

function OnSpace()
	if (gSpaceOk == 1) then
		gTutorialStep = gTutorialStep + 1
	end
end
-------------------------------------------------------------------------------
function OnReady()
    
    --if gTutorialStep == 11 then
	--	if Buildings.Amount( Game.LocalPlayer(), Buildings.WOODCUTTERHUT, Buildings.READY) > 0 then
	--	
	  --      	unrequest_event( OnReady, Events.TICK )
		--        request_event( tutorial_main, Events.TICK )
		--end
		
    --elseif gTutorialStep == 15 then
	--	if Buildings.Amount( Game.LocalPlayer(), Buildings.STONECUTTERHUT, Buildings.READY)
	--	and Buildings.Amount( Game.LocalPlayer(), Buildings.SAWMILL, Buildings.READY) > 0 then
	--		Tutorial.DisableExcept()
	--		Tutorial.ShowText("TUT_03_015")
	--		Tutorial.Won()
	--		gSpaceOk = 1
          --  		unrequest_event( OnReady, Events.TICK )
	    --    	request_event( tutorial_main, Events.TICK )
		--end
    --end		
    
end
--------------------------------------------------------------------------------

function WaitForReady()
    	gSpaceOk = 0
    	unrequest_event( tutorial_main, Events.TICK )
	request_event( OnReady, Events.TICK )
end;

--------------------------------------------------------------------------------
--
--	main tutorial function, called every tick
--
--------------------------------------------------------------------------------
function tutorial_main()
	if (gPrevTutStep == gTutorialStep) then
		return
	end

	if gTutorialStep == 1 then
		Tutorial.DisableExcept()
		Tutorial.ShowText("TUT_03_001")
		gSpaceOk = 1
			
	elseif gTutorialStep == 2 then
		Tutorial.ShowText("TUT_03_002")
		gSpaceOk = 1
		
	elseif gTutorialStep == 3 then
		Tutorial.ShowText("TUT_03_003")
		gSpaceOk = 1
			
	elseif gTutorialStep == 4 then
		Tutorial.ShowText("TUT_03_004")
		gSpaceOk = 1
	
	elseif gTutorialStep == 5 then
		Tutorial.ShowText("TUT_03_005")
		gSpaceOk = 1
	
	elseif gTutorialStep == 6 then
		Tutorial.ShowText("TUT_03_006")
		gSpaceOk = 1
	
	elseif gTutorialStep == 7 then
		Tutorial.ShowText("TUT_03_007")
		gSpaceOk = 1
	
	elseif gTutorialStep == 8 then
		Tutorial.ShowText("TUT_03_008")
		gSpaceOk = 1
	
	elseif gTutorialStep == 9 then
		Tutorial.ShowText("TUT_03_009")
		gSpaceOk = 1
	
	elseif gTutorialStep == 10 then
		Tutorial.ShowText("TUT_03_010")
		gSpaceOk = 1
	
	elseif gTutorialStep == 11 then
		Tutorial.ShowText("TUT_03_011")
		gSpaceOk = 1
	
	elseif gTutorialStep == 12 then
		Tutorial.ShowText("TUT_03_0012")
		gSpaceOk = 1
	
	elseif gTutorialStep == 13 then
		Tutorial.ShowText("TUT_03_013")
		gSpaceOk = 1
	
	elseif gTutorialStep == 14 then
		Tutorial.ShowText("TUT_03_014")
		gSpaceOk = 1
	
	elseif gTutorialStep == 15 then
		Tutorial.ShowText("TUT_03_015")
		gSpaceOk = 1
	
	elseif gTutorialStep == 16 then
		Tutorial.ShowText("TUT_03_016")
		gSpaceOk = 1
	
	elseif gTutorialStep == 17 then
		Tutorial.ShowText("TUT_03_017")
		gSpaceOk = 1
	
	elseif gTutorialStep == 18 then
		Tutorial.ShowText("TUT_03_018")
		gSpaceOk = 1

	elseif gTutorialStep == 19 then
		Tutorial.ShowText("TUT_03_019")
		gSpaceOk = 1
	end
	
	gPrevTutStep = gTutorialStep
end



--------------------------------------------------------------------------------
--
--	function which is called when a new map started
--
--------------------------------------------------------------------------------
function new_game()
	request_event( tutorial_main, Events.TICK )
	request_event( OnCommand, Events.COMMAND )
	request_event( OnSpace, Events.SPACE )
	request_event( OnDragBuilding, Events.DRAG_BUILDING)
end

--------------------------------------------------------------------------------
--
--	register functions which could request Events
--
--------------------------------------------------------------------------------

function register_functions()
	reg_func( tutorial_main )
	reg_func(OnDragBuilding)
	--reg_func( check_zoom )
	reg_func( OnSpace )
	reg_func ( OnCommand )
    	reg_func(OnReady)
end

