
------------------------------------------ Scripting del sistema de chechpoints
-- Chechpoints

function init_CheckPointTriggersVariables( )

	isEnter_CheckPoint00 = false;
	isEnter_CheckPoint01 = false;
	isEnter_CheckPoint02 = false;
	isEnter_CheckPoint03 = false;
	isEnter_CheckPoint04 = false;
	isEnter_CheckPoint05 = false;
	isEnter_CheckPoint06 = false;
	isEnter_CheckPoint07 = false;
	isEnter_CheckPoint08 = false;
	isEnter_CheckPoint09 = false;
	isEnter_CheckPoint10 = false;
	isEnter_CheckPoint11 = false;
	isEnter_CheckPoint12 = false;
	isEnter_CheckPoint13 = false;
	isEnter_CheckPoint14 = false;
	isEnter_CheckPoint15 = false;
	isEnter_CheckPoint16 = false;
	isEnter_CheckPoint18 = false;
	
	-- No recuperem estat del checkpoint17 
	-- isEnter_CheckPoint17 = flase;
	
	isEnter_posSave11 = false;
	
return 0;
end

function On_Enter_trigger_checkPoint00( )

	if( isEnter_CheckPoint00 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint00");
		saveStateOfAllGameInstances();
		isEnter_CheckPoint00 = true;
	end
	
return 0;
end

function On_Enter_trigger_checkPoint01( )

	if( isEnter_CheckPoint01 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint01");
		setCameraMode( 4, "", "trackerCamera_checkPoint01", 4.0 );
		saveStateOfAllGameInstances();
		isEnter_CheckPoint01 = true;
	end
	
return 0;
end

function On_Exit_trigger_checkPoint01( )
	setCameraMode( 0, "", "", 0.0 );
return 0;
end

function On_Enter_trigger_checkPoint02( )
	
	if( isEnter_CheckPoint02 == false ) then
		isFirstEnter_trigger_cutScene03 = true;

		setPlayerLastCheckPoint("trigger_checkPoint02");
		setCameraMode( 4, "", "trackerCamera_checkPoint02", 4.0 );
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint02 = true;
	end
	
return 0;
end

function On_Exit_trigger_checkPoint02( )
	setCameraMode( 0, "", "", 0.0 );
return 0;
end

function On_Enter_trigger_checkPoint03( )

	if( isEnter_CheckPoint03 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint03");
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint03 = true;
	end
	
	setCameraMode( 4, "", "trackerCamera_checkPoint03", 4.0 );
	
return 0;
end

function On_Enter_trigger_checkPoint04( )
	
	-- Throw Line Player
    playSound( "Animated_entities/Player/Lines/guiHelp", getPlayerPosition() );
	
	if( isEnter_CheckPoint04 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint04");
		
		-- Dialeg per donar pista de fer caure l'arbre
		local player = getMainPlayer();
		setComicDialog( player, "info_default");
		
		saveStateOfAllGameInstances();	
		
		isEnter_CheckPoint04 = true;
	end
	
return 0;
end

function On_Exit_trigger_checkPoint04( )
	local player = getMainPlayer();
	setVisiblityComicDialog( player, false );
return 0;
end

function On_Enter_trigger_checkPoint05( )
	
	if( isEnter_CheckPoint05 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint05");
		setCameraMode( 4, "", "trackerCamera_checkPoint05", 4.0 );
		
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint05 = true;
	end
	
return 0;
end

function On_Exit_trigger_checkPoint05( )
	
	isFirstStep_trackerPlatform_translate_04 = false;
	--setCameraMode( 0, "", "", 0.0 );
	
return 0;
end

function On_Enter_trigger_checkPoint06( )

	if( isEnter_CheckPoint06 == false ) then
		-- Restablim narrativa
		isFirstStep_trackerPlatform_static_01 = false;
		
		setPlayerLastCheckPoint("trigger_checkPoint06");
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint06 = true;
	end
	
	-- Dialeg per donar pista de activar la palanca
	-- local player = getMainPlayer();
	-- setComicDialog( player, "info_default");
	
return 0;
end

function On_Exit_trigger_checkPoint06( )
	local player = getMainPlayer();
	setVisiblityComicDialog( player, false );
return 0;
end

function On_Enter_trigger_checkPoint07( )

	if( isEnter_CheckPoint07 == false ) then
		isFirstStep_trackerPlatform_static_01 = false;
		isFirstStep_trackerPlatform_static_02 = false;
		
		setPlayerLastCheckPoint("trigger_checkPoint07");
		setCameraMode( 4, "", "trackerCamera_checkPoint07", 4.0 );
		
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint07 = true;
	end
	
return 0;
end

function On_Exit_trigger_checkPoint07( )
	setCameraMode( 0, "", "", 4.0 );
return 0;
end

function On_Enter_trigger_posSave08( )
	
	if( isEnter_CheckPoint08 == false ) then
		isFirstStep_trackerPlatform_static_02 = false;
		isEnter_CheckPoint08 = true;
	end
	
return 0;
end

-- Kill all enemies in static01
function On_Reached_checkPointStatic01( )

	setPlayerLastCheckPoint("trigger_posSave08");
	saveStateOfAllGameInstances();
	
return 0;
end

-- Kill all enemies in static02
function On_Reached_checkPointStatic02( )

	setPlayerLastCheckPoint("trigger_posSave09");
	saveStateOfAllGameInstances();
	
return 0;
end

function On_Enter_trigger_posSave09( )
return 0;
end

function On_Enter_trigger_checkPoint10( )

	setCameraMode( 4, "", "trackerCamera_checkPoint10", 4.0 );
	
	if( isEnter_CheckPoint10 == false ) then
		
		setPlayerLastCheckPoint("trigger_checkPoint10");
		saveStateOfAllGameInstances();
	
		-- Cal tornar a iniciar el baseball
		isEnabled_BaseBallGameplay = false;
		isEnter_posSave11 = false;
		
		setVisiblityComicDialog( getMainPlayer(), false );
		
		unHidePlatform("trackerPlatform_translate_27");
		unHidePlatform("trackerPlatform_translate_28");
		unHidePlatform("trackerPlatform_sinTranslate_02");
		
		--unHidePlatform("trackerPlatform_sinTranslate_01");
		
		isEnter_CheckPoint10 = true;
	end
	
return 0;
end

function On_Enter_trigger_posSave11( )

 if( isEnter_posSave11 == false ) then
 
	 if( isReached_BaseBallGameplay == false ) then
	 
		if( isEnabled_BaseBallGameplay == false ) then
  			isEnabled_BaseBallGameplay = true;
			startBaseBallGamePlay( );
		else
			if( isReached_SecondStep_BaseBallGameplay == true ) then
			    -- Recuperem la musica en aquest punt
			    start_BaseballBattleSeq_Lvl2();
				throwThirdBattalion_baseballGamePlay( );
			else
				if( isReached_FirstStep_BaseBallGameplay == true ) then
				    -- Recuperem la musica en aquest punt
			        start_BaseballBattleSeq_Lvl2();
					throwSecondBattalion_baseballGamePlay( );
				else
					isEnabled_BaseBallGameplay = true;
					startBaseBallGamePlay( );
				end
			end
		end
		
	  end
	
	isEnter_posSave11 = true;
  end
  
  if( isReached_BaseBallGameplay == false ) then
	setCameraModeBlendInfo( 6, "Octopus38_king", "trackerCamera_26", 0.0, 0.0, 0.9 );
  else
	setCameraMode( 4, "", "trackerCamera_17", 4.0 );
  end

return 0;
end

function On_Exit_trigger_posSave11( )
	
	if( isReached_BaseBallGameplay == true ) then
		setCameraMode( 4, "", "trackerCamera_17", 4.0 );
	end

return 0;
end

function On_Enter_trigger_checkPoint12( )
	
	if( isEnter_CheckPoint12 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint12");	
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint12 = true;
	end
	
return 0;
end

function On_Enter_trigger_checkPoint13( )
	
	if( isEnter_CheckPoint13 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint13");
		saveStateOfAllGameInstances();
		
		isEnter_CheckPoint13 = true;
	end
	
return 0;
end

function On_Exit_trigger_checkPoint13( )
    setCameraMode( 0, "", "", 4.0 );
return 0;
end

function On_Enter_trigger_checkPoint14( )
	
	setChangeFOV( false );
	
	if( isEnter_CheckPoint14 == false ) then
		isFirstStep_platform_horitzontal_2_08_rock = false;
		setPlayerLastCheckPoint("trigger_checkPoint14");
		
		restoreFinalBattleGameplay();
		saveStateOfAllGameInstances();
		isEnter_CheckPoint14 = true;
	end
	
return 0;
end

function On_Enter_trigger_checkPoint15( )
	
	if( isReached_FinalBattle == false ) then
		if( isEnter_CheckPoint15 == false ) then
			setPlayerLastCheckPoint("trigger_checkPoint14");
			
			-- Comença la gameplay de finalBattle
			StartCutScene12();
			
			isEnter_CheckPoint15 = true;
		end
	end
	
return 0;
end

function On_Enter_trigger_checkPoint16( )
	
	if( isReached_FinalBattle == true ) then
		if( isEnter_CheckPoint16 == false ) then
			setPlayerLastCheckPoint("trigger_checkPoint16");
			saveStateOfAllGameInstances();
			isEnter_CheckPoint16 = true;
		end
	end
	
return 0;
end

function On_Exit_trigger_checkPoint16( )
	
	if( isReached_FinalBattle == true ) then
		if( isEnter_CheckPoint16 == false ) then
			setPlayerLastCheckPoint("trigger_checkPoint16");
			saveStateOfAllGameInstances();
			isEnter_CheckPoint16 = true;
		end
	end
	
return 0;
end

function On_Enter_trigger_checkPoint17( )
	
	if( isEnter_CheckPoint17 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint17");
		saveStateOfAllGameInstances();
		isEnter_CheckPoint17 = true;
	end
	
return 0;
end

function On_Enter_trigger_checkPoint18( )
	
	if( isEnter_CheckPoint18 == false ) then
		setPlayerLastCheckPoint("trigger_checkPoint18");
		
		-- Activem la colisió per no poder tornar
        setEntityValidByName("platform_vertical_block_acces_Lvl1", true);
        setEntityVisibleByName("platform_vertical_block_acces_Lvl1", false);
		
		saveStateOfAllGameInstances();
		isEnter_CheckPoint18 = true;
	end
	
return 0;
end