--******************************************************************
-- Scouts Honour Client Side mission script 
--
--
--  TEAM_RED	0,
--	TEAM_BLUE	1,
--	TEAM_GREEN	2,
--	TEAM_YELLOW 3,
--
--
--
--	SHAPE_SCISSORS	= 0,
--  SHAPE_PAPER		= 1,
--  SHAPE_ROCK		= 2,
--
--
--	RACE_MALTHERIANS	= 1,
--  RACE_CYNOMAS		= 2,
--  RACE_NEOLITHICANS	= 3,
--  RACE_EMPERORBOMB	= 4,
--	RACE_VARANUS		= 5,
--	RACE_PHYTAS			= 6,
--	RACE_GRAEMIN		= 7,                                                        
--******************************************************************

nTowerCaptureCounter = 0
bIgnoreTowerCapture = false
nEnemyKillCount = 0
bAtLeastTenTowersHeldMsg = false



function Tutorial_Fifth_B( )
	UTIL.TogglePlayerCaptureTower( true ) 
	UTIL.ShowHudMsg( "Remember to capture at least 10 towers before your time runs out." )
	UTIL.CreateCallback( 8.0, "TurnOffHUDMsg" )
	Spawn_Enemy( )
	UTIL.TutorialEnded( )
end



function Tutorial_Fifth( )
	TurnOffHUDMsg( );
	UTIL.CreateCallback( 0.5, "Tutorial_Fifth_B" )
end

--////////////////////////////////////////////////////////////////////////

function Tutorial_Fourth_E( )
	TurnOffHUDMsg( )
end


function Tutorial_Fourth_D( )
	UTIL.ShowHudMsg( "                                 ATTACKING\nMove over to the enemy that just spawned and repeatedly tap the\nattack key." )
	UTIL.TogglePlayerInput( true )
	
	local SPAWN_SHAPE = SHAPE_ROCK
	local PLAYER_SHAPE = UTIL.GetArmyFormation(0)
	if PLAYER_SHAPE == SHAPE_ROCK then
		SPAWN_SHAPE = SHAPE_SCISSORS
	elseif PLAYER_SHAPE == SHAPE_PAPER then
		SPAWN_SHAPE = SHAPE_ROCK
	elseif PLAYER_SHAPE == SHAPE_SCISSORS then
		SPAWN_SHAPE = SHAPE_PAPER
	end
	
	if UTIL.SpawnEnemy( RACE_CYNOMAS, SPAWN_SHAPE, TEAM_BLUE, true, -487.0, 1793.0, 0.0, "Mission_Testing", "dumb.lua" ) == true then
		return
	else --Kill the tutorial
		UTIL.TogglePlayerCaptureTower( true ) 
	end
	
	--UTIL.CreateCallback( 4.0, "Tutorial_Fourth_E" )
end





function Tutorial_Fourth_C( )
	TurnOffHUDMsg( )
	UTIL.WarpArmyTo( 0, 784.0, 2132.0, 0.0 )
	UTIL.TogglePlayerInput( false )
	UTIL.CreateCallback( 0.5, "Tutorial_Fourth_D" )
end

function Tutorial_Fourth_B( )
	UTIL.ShowHudMsg( "You can change your power by pressing the tower capture button\nnext to a tower that is under your control." )
	UTIL.CreateCallback( 6.0, "Tutorial_Fourth_C" )
end


function Tutorial_Fourth( )
	TurnOffHUDMsg( )
	UTIL.TogglePlayerCaptureTower( false ) 
	UTIL.CreateCallback( 0.5, "Tutorial_Fourth_B" )	
end



--////////////////////////////////////////////////

function Tutorial_Third( )
	UTIL.ShowHudMsg( "                              CAPTURE A TOWER\nMove to any tower. Then press and hold the tower capture button." )
	UTIL.TogglePlayerCaptureTower( true )
end


--/////////////////////////////////////////////////

function Start_Tutorial( )
	UTIL.TogglePlayerInput( true )
	if UTIL.IsGamePad( ) == true then
		UTIL.ShowHudMsg( "Welcome to the Epoch Wars Tutorial. Use your gamepad's thumb\nstick to move your lord around the map." )
	else
		UTIL.ShowHudMsg( "Welcome to the Epoch Wars Tutorial. Use your keyboard's\nDirection Keys to move your lord around the map." )
	end
	UTIL.CreateCallback( 6.0, "Tutorial_PlayerInput1" )	
end



--////////////////////////////////////////////////////////////////////////////////

function Tutorial_PlayerInput1(  )
	TurnOffHUDMsg( )
	UTIL.CreateCallback( 1.0, "Tutorial_Third" )
end	

function Tutorial_PlayerInput3( )
	TurnOffHUDMsg( )
end




--////////////////////////////////////////////////////////////////////////////////

function Start_NonTutorial( )
	Spawn_Quadrant_Enemy_Count2( )
end

--////////////////////////////////////////////////////////////////////////////////

function Start_Test( )
	UTIL.SpawnEnemy( RACE_CYNOMAS, SHAPE_PAPER, TEAM_BLUE, true, -1772.716, 1431.216, -0.1, "Mission_Testing", "semi_aggressive.lua" ) 
	UTIL.SpawnEnemy( RACE_CYNOMAS, SHAPE_ROCK, TEAM_BLUE, true, -1772.716, 1431.216, -0.1, "Mission_Testing", "semi_aggressive.lua" ) 
end


--////////////////////////////////////////////////////////////////////////////////

function Spawn_Quadrant_Enemy_Count1( )
	nPlayerQuad = UTIL.GetPlayerQuadrant( )
	Debug.Print("Player In Quadrant"..nPlayerQuad.."\n")
	if nPlayerQuad == 1 then
		Spawn_Enemy_3( )
	elseif nPlayerQuad == 2 then
		Spawn_Enemy_4( )
	elseif nPlayerQuad == 3 then
		Spawn_Enemy_1( )
	else
		Spawn_Enemy_2( )
	end
end

function Spawn_Quadrant_Enemy_Count2( )
	nPlayerQuad = UTIL.GetPlayerQuadrant( )
	Debug.Print("Player In Quadrant"..nPlayerQuad.."\n")
	if nPlayerQuad == 1 then
		Spawn_Enemy_3( )
		Spawn_Enemy_2( )
	elseif nPlayerQuad == 2 then
		Spawn_Enemy_4( )
		Spawn_Enemy_3( )
	elseif nPlayerQuad == 3 then
		Spawn_Enemy_1( )
		Spawn_Enemy_4( )
	else
		Spawn_Enemy_1( )
		Spawn_Enemy_2( )
	end
end

function Spawn_Enemy( )
	local SPAWN_SHAPE = SHAPE_ROCK
	local PLAYER_SHAPE = UTIL.GetArmyFormation(0)
	if PLAYER_SHAPE == SHAPE_ROCK then
		SPAWN_SHAPE = SHAPE_PAPER
	elseif PLAYER_SHAPE == SHAPE_PAPER then
		SPAWN_SHAPE = SHAPE_SCISSORS
	elseif PLAYER_SHAPE == SHAPE_SCISSORS then
		SPAWN_SHAPE = SHAPE_ROCK
	end
	UTIL.SpawnEnemy( RACE_CYNOMAS, SPAWN_SHAPE, TEAM_BLUE, true, -3636.0, -3330.0, 0.0, "Mission_Testing", "stupid.lua" )
end


function Spawn_Enemy_1( )
	local SPAWN_SHAPE = SHAPE_ROCK
	local PLAYER_SHAPE = UTIL.GetArmyFormation(0)
	if PLAYER_SHAPE == SHAPE_ROCK then
		SPAWN_SHAPE = SHAPE_PAPER
	elseif PLAYER_SHAPE == SHAPE_PAPER then
		SPAWN_SHAPE = SHAPE_SCISSORS
	elseif PLAYER_SHAPE == SHAPE_SCISSORS then
		SPAWN_SHAPE = SHAPE_ROCK
	end
	UTIL.SpawnEnemy( RACE_CYNOMAS, SPAWN_SHAPE, TEAM_BLUE, true, 4178.0, 3884.0, 0.0, "Mission_Testing", "stupid.lua" )
end

function Spawn_Enemy_2( )
	local SPAWN_SHAPE = SHAPE_ROCK
	local PLAYER_SHAPE = UTIL.GetArmyFormation(0)
	if PLAYER_SHAPE == SHAPE_ROCK then
		SPAWN_SHAPE = SHAPE_PAPER
	elseif PLAYER_SHAPE == SHAPE_PAPER then
		SPAWN_SHAPE = SHAPE_SCISSORS
	elseif PLAYER_SHAPE == SHAPE_SCISSORS then
		SPAWN_SHAPE = SHAPE_ROCK
	end
	UTIL.SpawnEnemy( RACE_CYNOMAS, SPAWN_SHAPE, TEAM_BLUE, true, -3962.0, 2876.0, 0.0, "Mission_Testing", "stupid.lua" )
end

function Spawn_Enemy_3( )
	local SPAWN_SHAPE = SHAPE_ROCK
	local PLAYER_SHAPE = UTIL.GetArmyFormation(0)
	if PLAYER_SHAPE == SHAPE_ROCK then
		SPAWN_SHAPE = SHAPE_PAPER
	elseif PLAYER_SHAPE == SHAPE_PAPER then
		SPAWN_SHAPE = SHAPE_SCISSORS
	elseif PLAYER_SHAPE == SHAPE_SCISSORS then
		SPAWN_SHAPE = SHAPE_ROCK
	end
	UTIL.SpawnEnemy( RACE_CYNOMAS, SPAWN_SHAPE, TEAM_BLUE, true, -3636.0, -3330.0, 0.0, "Mission_Testing", "stupid.lua" )
end

function Spawn_Enemy_4( )
	local SPAWN_SHAPE = SHAPE_ROCK
	local PLAYER_SHAPE = UTIL.GetArmyFormation(0)
	if PLAYER_SHAPE == SHAPE_ROCK then
		SPAWN_SHAPE = SHAPE_PAPER
	elseif PLAYER_SHAPE == SHAPE_PAPER then
		SPAWN_SHAPE = SHAPE_SCISSORS
	elseif PLAYER_SHAPE == SHAPE_SCISSORS then
		SPAWN_SHAPE = SHAPE_ROCK
	end
	UTIL.SpawnEnemy( RACE_CYNOMAS, SPAWN_SHAPE, TEAM_BLUE, true, 3007.0, -3620.0, 0.0, "Mission_Testing", "stupid.lua" )
end

function Lord_Died( nWhoDied )

	if nWhoDied == 0 then
		return
	else
		if TUTORIAL_IS_ON == true then
			nEnemyKillCount = nEnemyKillCount + 1
			if nEnemyKillCount > 1 then
				return
			elseif nEnemyKillCount == 1 then
				Tutorial_Fifth( )
			end
		end
	end
end

function Player_Died( nWhoDied )
	
end

function Enemy_Died( nWhoDied )
	
end

function Tower_Captured( nTowerID, nArmyID )

	if nArmyID == 0 then
		nTowerCaptureCounter = nTowerCaptureCounter + 1
		
		if TUTORIAL_IS_ON == true then
			if nTowerCaptureCounter == 1 then
				Tutorial_Fourth( )
			end
			
			if nTowerCaptureCounter == 3 then
				Spawn_Quadrant_Enemy_Count1( )
			end
			
			if nTowerCaptureCounter == 5 then
				Spawn_Quadrant_Enemy_Count1( )
			end
			
			if nTowerCaptureCounter == 6 then
				Spawn_Quadrant_Enemy_Count1( )
			end
			
			if nTowerCaptureCounter == 7 then
				Spawn_Quadrant_Enemy_Count2( )
				UTIL.ShowHudMsg( "You have captured 7 towers... Only 3 towers left!" )
				UTIL.CreateCallback( 5.0, "TurnOffHUDMsg" )
			end
			
			if nTowerCaptureCounter == 8 then
				Spawn_Quadrant_Enemy_Count2( )
			end
			
			if nTowerCaptureCounter == 9 then
				--UTIL.ShowHudMsg( "You have captured 9 towers... Only 1 tower left!" )
				--UTIL.CreateCallback( 5.0, "TurnOffHUDMsg" )
				Spawn_Quadrant_Enemy_Count2( )
			end
		else
		
			if nTowerCaptureCounter == 3 then
				Spawn_Quadrant_Enemy_Count1( )
			end
			
			if nTowerCaptureCounter == 5 then
				Spawn_Quadrant_Enemy_Count1( )
			end
			
			if nTowerCaptureCounter == 6 then
				Spawn_Quadrant_Enemy_Count1( )
			end
			
			if nTowerCaptureCounter == 7 then
				Spawn_Quadrant_Enemy_Count2( )
				
			end
			
			if nTowerCaptureCounter == 8 then
				Spawn_Quadrant_Enemy_Count2( )
			end
			
			if nTowerCaptureCounter == 9 then
				Spawn_Quadrant_Enemy_Count2( )
			end
		end
		
	end
end


function TurnOffHUDMsg( )
	UTIL.HideHudMsg( )
end


function Level_Started( )
	nTowerCaptureCounter = 0;
	if UTIL.CanPlayTutorial() == true then
		TUTORIAL_IS_ON = true
		UTIL.TogglePlayerInput( true )
		UTIL.TogglePlayerCaptureTower( false )
		UTIL.CreateCallback( 0.5, "Start_Tutorial" )
	else
		TUTORIAL_IS_ON = false
		UTIL.CreateCallback( 0.5, "Start_NonTutorial" )
	end
	
end