--------------------------------------------------------------------------------
--
--	TUTORIAL 12 FINAL 22.01.01 16:57
--
--------------------------------------------------------------------------------

gActiveMenu = -1
gWantedMenu = -1		
gTutorialStep =1		
gSpaceOk= 1
gPrevTutStep = -1
gTextStep = 1
gWantedBuilding = -1
gCommandOk = 1
gSettlerCount = 0
gSetText0 = "TUT_11_001_R"
gSetText1 = "TUT_NEXT" 
LastText0 = 0
LastText1 = 0

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

function DummyVictoryCheck()
end
	
----------------------------------------------------------------------------------
function OnWoodcutterGetGood(buildingtype, goodtype, amount)
	
	if (goodtype == Goods.LOG) then
		gTutorialStep = gTutorialStep + 1
		unrequest_event( OnWoodcutterGetGood, Events.GOODARRIVE)
	end
		
end
-------------------------------------------------------------------------------

function OnCommand(command)

   	if (command == Control.DLG_TUTORIAL_CMD_NEXT ) then
		OnSpace()
	end
	
	if (command == Control.DLG_TUTORIAL_CMD_RESET ) then
		Tutorial.ShowText(gSetText0,0)
		Tutorial.ShowText(gSetText1,1)
		Map.SetScreenPos(208,121)
		Tutorial.SetZoom(17)
		gCommandOk = 0
		Tutorial.PressButton(Dialog.DLG_MINIMAP, Control.DLG_MINIMAP_CMD_BUILD)
    		Tutorial.PressButton(Dialog.DLG_BUILDSUBMENU, Control.DLG_BUILDSUBMENU_CMD_BASIC)
    		Tutorial.ClearMarker()
    		
    		   		
    		if (gTutorialStep == 3) or (gTutorialStep == 4)  then
    			Tutorial.PressButton (Dialog.DLG_MINIMAP, Control.DLG_MINIMAP_CMD_FIGURES)                        
			Tutorial.PressButton (Dialog.DLG_FIGURESSUBMENU, Control.DLG_FIGURESSUBMENU_CMD_SETTLERPRODUCTION)
			Tutorial.SetMarker(83,363)
		end
	end
	
	if (command == 0 )  then
		if (gCommandOk == 1) then
			Tutorial.ClearMarker()
		end
	end
end
-------------------------------------------------------------------------------

function OnSpace()
	if (gSpaceOk == 1) then
		gTutorialStep = gTutorialStep + 1
	end
end

--//-----------------------------------------------------------------------------
--// WHEN SETTLERTYPE IN PRODUCTION, the gTutorialStep will be increased
--//-----------------------------------------------------------------------------
function OnSettlerProduction(settlertype)
	if (settlertype == Settlers.GARDENER) then
		if gSettlerCount <= 10 then
			gSettlerCount = gSettlerCount +1
		end
	end
	if gSettlerCount >= 10 then
		Tutorial.DisableExcept()
		Tutorial.ClearMarker() 
	end	
	
end
-------------------------------------------------------------------------------
--
--	main tutorial function
--
--------------------------------------------------------------------------------
function tutorial_main()

	gCommandOk = 1
	
	--// Text rein schreiben //-- 
	if (gSetText0 ~= LastText0 ) or (gSetText1 ~= LastText1 )then
		Tutorial.ShowText(gSetText0,0)
		Tutorial.ShowText(gSetText1,1)
		LastText0 = gSetText0
		LastText1 = gSetText1
	end	

	
	if (gPrevTutStep == gTutorialStep) then
		return
	end

	if gTutorialStep == 1 then
		Tutorial.DisableExcept()
		gSetText0 = "TUT_11_001_R"
		gSetText1 = "TUT_NEXT"
		gSpaceOk = 1
	
	elseif gTutorialStep == 2 then
		gSetText0 = "TUT_11_002_R"
		gSetText1 = "TUT_NEXT"
		gSpaceOk = 1
		
			
	elseif gTutorialStep == 3 then
		gSetText0 = "TUT_11_003_R"
		gSetText1 = "TUT_11_003_N"
		Tutorial.DisableExcept
		(
			Control.DLG_MINIMAP_CMD_FIGURES,
			Control.DLG_FIGURESSUBMENU_CMD_SETTLERPRODUCTION,
			Control.DLG_SETTLERPRODUCTIONMENU_CMD_GARDENER,
			Control.DLG_SETTLERPRODUCTIONMENU_CMD_8UP
		)
		Tutorial.PressButton (Dialog.DLG_MINIMAP, Control.DLG_MINIMAP_CMD_FIGURES)
		Tutorial.PressButton (Dialog.DLG_FIGURESSUBMENU, Control.DLG_FIGURESSUBMENU_CMD_SETTLERPRODUCTION)
		Tutorial.SetMarker(83,363)
		gCommandOk = 0
		gSpaceOk = 0
		gTutorialStep = gTutorialStep +1
		return
		
	
	elseif gTutorialStep == 4 then
		Tutorial.PressButton (Dialog.DLG_SETTLERPRODUCTIONMENU, Control.DLG_SETTLERPRODUCTIONMENU_CMD_GARDENER)
		gSpaceOk = 0
		gTutorialStep = gTutorialStep +1
		return
		--//gWantedSettler = Settlers.GARDENER
			
		
	elseif gTutorialStep == 5 then
		if Settlers.Amount( Game.LocalPlayer(), Settlers.GARDENER ) >= 10 then
			Tutorial.DisableExcept()
			Tutorial.ClearMarker()
			--Tutorial.PressButton(Dialog.DLG_MINIMAP, Control.DLG_MINIMAP_CMD_BUILD)
    			--Tutorial.PressButton(Dialog.DLG_BUILDSUBMENU, Control.DLG_BUILDSUBMENU_CMD_BASIC)
			gSetText0 = "TUT_11_004_R"
			gSetText1 = "TUT_11_004_N"
			Tutorial.SetWorldCursor(201,120)
			gSpaceOk = 0
			gTutorialStep = gTutorialStep +1
		end
		return
		
	elseif gTutorialStep == 6 then
		if Settlers.AmountInArea( Game.LocalPlayer(), Settlers.GARDENER,201,120,1) == 1 then
			gSetText0 = "TUT_11_005_R"
			gSetText1 = "TUT_11_005_N"
			Tutorial.PressButton(Dialog.DLG_MINIMAP, Control.DLG_MINIMAP_CMD_BUILD)
    			Tutorial.PressButton(Dialog.DLG_BUILDSUBMENU, Control.DLG_BUILDSUBMENU_CMD_BASIC)
			Tutorial.DeleteWorldCursor()
			gSpaceOk = 0
			gTutorialStep = gTutorialStep +1
		end
		return
	
	elseif gTutorialStep == 7 then
		if Game.IsAreaGreen( 205,120, 2) == 1 then
			gSetText0 = "TUT_11_006_R"
			gSetText1 = "TUT_11_006_N"
			gSpaceOk = 0
			gTutorialStep = gTutorialStep +1
		end
		return
		
		
	elseif gTutorialStep == 8 then
		if Game.IsAreaGreen( 209,130, 1) == 1 then
			gSetText0 = "TUT_11_007_R"
			gSetText1 = "TUT_11_007_N"
			gSpaceOk = 0
			gTutorialStep = gTutorialStep +1
		end
		return
	
	elseif gTutorialStep == 9 then
		gSpaceOk = 0
		request_event( OnWoodcutterGetGood, Events.GOODARRIVE)
	
	elseif gTutorialStep == 10 then
		gSetText0 = "TUT_11_009_R"
		gSetText1 = "TUT_END"
		Tutorial.Won()
		gSpaceOk = 1
	
					
	elseif gTutorialStep == 11 then
		Tutorial.Exit()
	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( DummyVictoryCheck, Events.VICTORY_CONDITION_CHECK )
	request_event( OnSettlerProduction, Events.SETTLER_CHANGE_TYPE)
end

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

function register_functions()
	reg_func( DummyVictoryCheck )
	reg_func( tutorial_main )
	reg_func( OnWoodcutterGetGood )
	reg_func( OnSpace )
	reg_func( OnCommand )
	reg_func(OnSettlerProduction)
end

