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

// includes:
#include "../../basicScripts/LevelBase.as"


class Level: LevelBase
{
	// count this version-number up. This is for later version tracking, when the QA plays the map.
	string m_stgVersion = "0.193 - 07.12.2017 - 23:03";
	//string m_stgVersion = "0.192 - 07.12.2017 - 17:50";
	//string m_stgVersion = "0.191 - 07.12.2017 - 11:27";
	//string m_stgVersion = "0.190 - 06.12.2017 - 21:44";
	//string m_stgVersion = "0.189 - 05.12.2017 - 19:17";
	

	// -------------------------------------------------------------------------------------------------------------------
	// --- Member Variables ----------------------------------------------------------------------------------------------
	int m_iPartyLevel_Visit_0 	= 			11;
	///int m_iLS1_PartyLevel 	= 1;

	string m_stgEntrance_LS_GC = 			"MapTransitions_LS_GC";

	string m_stgSect_Leafshade = 			"Sector_Leafshade";
	string m_stgBannerLeafshade = 			"banner_location";
	int m_iHeroesInLeafshade = 				0;

	// ---  L E A F S H A D E  1  ----------------------------------------------------------------------------------------
	// Faction
	uint m_iLS1_FactionElven = 				1;
	uint m_iLS1_FactionHumans = 			2;
	uint m_iLS1_FactionHumansBane = 		3;
	uint m_iLS1_FactionHumansBaneRTS = 		4;
	uint m_iLS1_FactionIanna =		 		5;

	string m_stgGlobal_bQuestFinished_GC = 	m_glbCat_QuestTrack+".SQ_GrasslandCoast";
	string m_stgLS1_HerbPackage = 			"GC1_HerbPackage";

	// RTS Data's
	string m_stgLS1_RTSstartSector = 		"Sector_0";
	// Planks, Brick, Iron, IronBar, BlackAshPackage, BlackAshPotion, Food, LenyaPackage, LenyaEssence, AriaCask, DistilledAria
	// dictionary m_dictLS1_RTSres_Player = 	{{'Planks', 10}, {'Food', 10} };

	// Characters
	string m_stgLS1_crtArlanFinrior = 		"Arlan_Finrior";
	string m_stgLS1_crtVardenMerilith = 	"Varden_Merilith";
	string m_stgLS1_crtSpwnGroupArlan = 	"LS1_GroupArlan";
	string m_stgLS1_crtSpwnGroupVarden = 	"LS1_GroupVarden";
	string m_stgLS1_crtElf_1 = 				"LS1_Elf_1";
	string m_stgLS1_crtElf_2 = 				"LS1_Elf_2";
	string m_stgLS1_crtElf_3 = 				"LS1_Elf_3";
	string m_stgLS1_crtElf_4 = 				"LS1_Elf_4";
	string m_stgLS1_crtOldElf = 			"LS1_OldElf";

	// Human Camp
	string m_stgLS1_crtLiliath = 				"Liliath";
	string m_stgLS1_crtHumanLeader = 			"LS1_HumanLeader";
	string m_stgLS1_crtHumanGuard = 			"LS1_HumanGuard_1";

	string m_stgLS1_HumanSector = 				"Sector_5";
	int m_iLS1_BaneRebellion_Timer = 			2*60;
	int m_iLS1_HumanLeader_Timer = 				3*60;
	bool m_bLS1_TalkedWithHumanLeader = 		false;
	bool m_bLS1_BaneDefeated = 					false;
	string m_stgLS1_areaHumanCamp = 			"HumanCamp";
	string m_stgLS1_spwnHumanArlanGift =  		"LS1_HumanSoldiers_ArlanGift";
	array <string> m_arrLS1_ArlanDudesInNoNoZone = {};
	string m_stgLS1_posArlanGift = 				"LS1_PosArlanGift";
	array <string> m_arrStgLS1_HumanSpawns = 	{ "LS1_HumanGuard_1", "LS1_HumanGuard_2", "LS1_HumanSoldiers_1"};
	array <string> m_arrStgLS1_BaneSpawns = 	{ "LS1_BaneCorporal", "LS1_BaneSoldiers_1" };
	string m_stgLS1_pathHumanLeaderFlee = 		"LS1_HumanLeaderToCapital";
	string m_stgLS1_pathHumanLeaderLeaves = 	"LS1_HumanLeaderGoesAway";
	bool m_bLS1_TreantShoutoutDone = 			false;

	bool m_bHerbsGathered =						false;

	// Corrupted Wildlife stuff
	bool m_bLS1SOcorruptedElf = 				false;
	string m_stgLS1_spawnCorruptedElves = 		"LS1_CrazedElves_1"; // corrupted elves
	string m_stgLS1_desCorruptElv = 			"LS1_CorruptedElf_01"; // description of the corrupted elves
	// treant
	bool m_bLS1_TalkedWithTreant = 				false;
	string m_stgLS1_crtTreant = 				"LS1_CorruptedTreant";
	int m_iLS1_TreantSpellHP = 					20; // number is percentage, NOT the actual HP
	int m_iLS1_CorruptedCondition = 			10210;
	int m_iLS1_CorruptedCleanseCondition = 		10211;
	string m_stgLS1_CleanseSpell = 				"CorruptedTreantCleanseSpell";
	array <string> m_arrStgLS1_TreantCorruptedAttack = { "LS1_CorruptedAttack_1", "LS1_CorruptedAttack_2" };
	string m_stgLS1_pathCorruptedElves = 		"LS1_PathCorruptedAttack";
	array <string> m_arrStgLS1_SW_AttackWave = { "LS1_SW_CorruptedAmbush_1", "LS1_SW_CorruptedAmbush_2", "LS1_SW_CorruptedAmbush_3", "LS1_SW_CorruptedAmbush_4" };
	array <string> m_arrStgLS1_NE_AttackWave = { "LS1_NE_CorruptedAmbush_1", "LS1_NE_CorruptedAmbush_2", "LS1_NE_CorruptedAmbush_3" };

	// Ianna
	bool m_bLS1_IannaAmbush = 					false;
	array <string> m_arrStgLS1_IannaSpawns = 	{ "LS1_Ianna", "LS1_Ianna_Scoundrel_1", "LS1_Ianna_Scoundrel_2" };
	array <string> m_arrStgLS1_IannaSpawns_Aggro = 	{ "LS1_Ianna_Scoundrel_1", "LS1_Ianna_Scoundrel_2" };
	string m_stgLS1_IannaAttack = 				"LS1_IannaAttackArea";
	string m_stgLS1_IannaScroundrel_1 = 		"LS1_Ianna_Scroundel";
	string m_stgLS1_IannaScroundrel_2 = 		"LS1_Ianna_Scroundel_02";
	//string m_stgLS1_spwnIanna = 				"LS1_Ianna";
	//string m_stgLS1_trgAttackTargets = 		"LS1_IannaAttackTargets";
	//array <string> m_arrLS1_heroTargetsIanna;

	// general stuff
	bool m_bRTSActive =				false;

	// Corrupted Shrines
	int m_iShrineCleanedNmbr = 		0;
	int m_iShrineState_1 = 			0;
	int m_iShrineState_2 = 			33;
	int m_iShrineState_3 = 			66;
	bool m_bInteractedWithAShrine =	false;
	bool m_bGotPoolQuest = 			false;
	// Nothing: Northwest
	// Corrupted: Southeastern, Southwest,
	// Waves: Southeastern, Northeast
	array <string> m_arrStgLS1_CorruptedShrines = { "Shrine_Southwest", "Shrine_Southeast", "Shrine_Northeast", "Shrine_Northwest" };

	array <string> m_arrStgLS1_CorruptedShrine_NE_FadeOut = { "Shrine_Northeast_Corrupted_Deco1", "Shrine_Northeast_Corrupted_Deco2", "Shrine_Northeast_Corrupted_Deco3",
	 	"Shrine_Northeast_Corrupted_Deco4", "Shrine_Northeast_Corrupted_Deco5", "Shrine_Northeast_Corrupted_Deco6",
		"Shrine_Northeast_Corrupted_Deco8", "Shrine_Northeast_Corrupted_Deco9", "Shrine_Northeast_Corrupted_Deco10",
		"Shrine_Northeast_Corrupted_Deco11", "Shrine_Northeast_Corrupted_Deco12", "Shrine_Northeast_Corrupted_Deco13",
		"Shrine_Northeast_Corrupted_Deco14", "Shrine_Northeast_Corrupted_Deco15", "Shrine_Northeast_Corrupted_Deco16",
		"Shrine_Northeast_Corrupted_Deco17", "Shrine_Northeast_Corrupted_Deco18", "Shrine_Northeast_Corrupted_Deco19",
		"Shrine_Northeast_Corrupted_Deco20", "Shrine_Northeast_Corrupted_Deco21", "Shrine_Northeast_Corrupted_Deco22",
		"Shrine_Northeast_Corrupted_Deco23",
		"Shrine_Northeast_Corrupted_FX1", "Shrine_Northeast_Corrupted_FX2", "Shrine_Northeast_Corrupted_FX3",
		"Shrine_Northeast_Corrupted_FX4", "Shrine_Northeast_Corrupted_FX5", "Shrine_Northeast_Corrupted_FX6",
		"Shrine_Northeast_Corrupted_FX7", "Shrine_Northeast_Corrupted_FX8", "Shrine_Northeast_Corrupted_FX9",
		"Shrine_Northeast_Corrupted_FX10", "Shrine_Northeast_Corrupted_FX11", "Shrine_Northeast_Corrupted_FX12"
	};
	array <string> m_arrStgLS1_CorruptedShrine_NE_FadeIn = 	{ "" };

	array <string> m_arrStgLS1_CorruptedShrine_NW_FadeOut = { "Shrine_Northwest_Corrupted_Deco1", "Shrine_Northwest_Corrupted_Deco2", "Shrine_Northwest_Corrupted_Deco3",
 		"Shrine_Northwest_Corrupted_Deco4", "Shrine_Northwest_Corrupted_Deco5", "Shrine_Northwest_Corrupted_Deco6",
		"Shrine_Northwest_Corrupted_Deco7", "Shrine_Northwest_Corrupted_Deco8", "Shrine_Northwest_Corrupted_Deco9",
		"Shrine_Northwest_Corrupted_Deco10", "Shrine_Northwest_Corrupted_Deco11", "Shrine_Northwest_Corrupted_Deco12",
		"Shrine_Northwest_Corrupted_Deco13", "Shrine_Northwest_Corrupted_Deco14", "Shrine_Northwest_Corrupted_Deco15",
		"Shrine_Northwest_Corrupted_Deco16", "Shrine_Northwest_Corrupted_Deco17", "Shrine_Northwest_Corrupted_Deco18",
		"Shrine_Northwest_Corrupted_Deco19", "Shrine_Northwest_Corrupted_Deco20", "Shrine_Northwest_Corrupted_Deco21",
		"Shrine_Northwest_Corrupted_Deco22", "Shrine_Northwest_Corrupted_Deco23", "Shrine_Northwest_Corrupted_Deco24",
		"Shrine_Northwest_Corrupted_Deco25", "Shrine_Northwest_Corrupted_Deco26", "Shrine_Northwest_Corrupted_Deco27",
		"Shrine_Northwest_Corrupted_Deco28", "Shrine_Northwest_Corrupted_Deco29", "Shrine_Northwest_Corrupted_Deco30",
		"Shrine_Northwest_Corrupted_Deco31", "Shrine_Northwest_Corrupted_Deco32", "Shrine_Northwest_Corrupted_Deco34",
		"Shrine_Northwest_Corrupted_Deco35", "Shrine_Northwest_Corrupted_Deco36", "Shrine_Northwest_Corrupted_Deco37",
		"Shrine_Northwest_Corrupted_Deco38", "Shrine_Northwest_Corrupted_Deco39", "Shrine_Northwest_Corrupted_Deco40",
		"Shrine_Northwest_Corrupted_Deco41", "Shrine_Northwest_Corrupted_Deco42",
		"Shrine_Northwest_Corrupted_FX1", "Shrine_Northwest_Corrupted_FX2", "Shrine_Northwest_Corrupted_FX3",
		"Shrine_Northwest_Corrupted_FX4", "Shrine_Northwest_Corrupted_FX5", "Shrine_Northwest_Corrupted_FX6",
		"Shrine_Northwest_Corrupted_FX7", "Shrine_Northwest_Corrupted_FX8", "Shrine_Northwest_Corrupted_FX9",
		"Shrine_Northwest_Corrupted_FX10", "Shrine_Northwest_Corrupted_FX11", "Shrine_Northwest_Corrupted_FX12",
		"Shrine_Northwest_Corrupted_FX13", "Shrine_Northwest_Corrupted_FX15", "Shrine_Northwest_Corrupted_FX16"
	};
	array <string> m_arrStgLS1_CorruptedShrine_NW_FadeIn = 	{ "" };

	array <string> m_arrStgLS1_CorruptedShrine_SE_FadeOut = { "Shrine_Southeast_Corrupted_Deco1", "Shrine_Southeast_Corrupted_Deco2", "Shrine_Southeast_Corrupted_Deco3",
  		"Shrine_Southeast_Corrupted_Deco4", "Shrine_Southeast_Corrupted_Deco5", "Shrine_Southeast_Corrupted_Deco6",
		"Shrine_Southeast_Corrupted_Deco7", "Shrine_Southeast_Corrupted_Deco8", "Shrine_Southeast_Corrupted_Deco9",
		"Shrine_Southeast_Corrupted_Deco10", "Shrine_Southeast_Corrupted_Deco11", "Shrine_Southeast_Corrupted_Deco12",
		"Shrine_Southeast_Corrupted_Deco13", "Shrine_Southeast_Corrupted_Deco14", "Shrine_Southeast_Corrupted_Deco15",
		"Shrine_Southeast_Corrupted_Deco16", "Shrine_Southeast_Corrupted_Deco17", "Shrine_Southeast_Corrupted_Deco18",
		"Shrine_Southeast_Corrupted_Deco19", "Shrine_Southeast_Corrupted_Deco20", "Shrine_Southeast_Corrupted_Deco21",
		"Shrine_Southeast_Corrupted_Deco22", "Shrine_Southeast_Corrupted_Deco23", "Shrine_Southeast_Corrupted_Deco24",
		"Shrine_Southeast_Corrupted_Deco25", "Shrine_Southeast_Corrupted_Deco26", "Shrine_Southeast_Corrupted_Deco27",
		"Shrine_Southeast_Corrupted_Deco28", "Shrine_Southeast_Corrupted_Deco29", "Shrine_Southeast_Corrupted_Deco30",
		"Shrine_Southeast_Corrupted_Deco31", "Shrine_Southeast_Corrupted_Deco32",
		"Shrine_Southeast_Corrupted_FX1", "Shrine_Southeast_Corrupted_FX2", "Shrine_Southeast_Corrupted_FX3",
		"Shrine_Southeast_Corrupted_FX4", "Shrine_Southeast_Corrupted_FX5", "Shrine_Southeast_Corrupted_FX6",
		"Shrine_Southeast_Corrupted_FX7", "Shrine_Southeast_Corrupted_FX8", "Shrine_Southeast_Corrupted_FX9",
		"Shrine_Southeast_Corrupted_FX10", "Shrine_Southeast_Corrupted_FX11", "Shrine_Southeast_Corrupted_FX12",
		"Shrine_Southeast_Corrupted_FX13", "Shrine_Southeast_Corrupted_FX14", "Shrine_Southeast_Corrupted_FX15"
	};
	array <string> m_arrStgLS1_CorruptedShrine_SE_FadeIn = 	{ "" };

	array <string> m_arrStgLS1_CorruptedShrine_SW_FadeOut = { "Shrine_Southwest_Corrupted_Deco1", "Shrine_Southwest_Corrupted_Deco2", "Shrine_Southwest_Corrupted_Deco3",
 		"Shrine_Southwest_Corrupted_Deco4", "Shrine_Southwest_Corrupted_Deco5", "Shrine_Southwest_Corrupted_Deco6",
		"Shrine_Southwest_Corrupted_Deco7", "Shrine_Southwest_Corrupted_Deco8", "Shrine_Southwest_Corrupted_Deco9",
		"Shrine_Southwest_Corrupted_Deco10", "Shrine_Southwest_Corrupted_Deco11", "Shrine_Southwest_Corrupted_Deco12",
		"Shrine_Southwest_Corrupted_Deco13", "Shrine_Southwest_Corrupted_Deco14", "Shrine_Southwest_Corrupted_Deco15",
		"Shrine_Southwest_Corrupted_Deco16", "Shrine_Southwest_Corrupted_Deco17", "Shrine_Southwest_Corrupted_Deco18",
		"Shrine_Southwest_Corrupted_Deco19", "Shrine_Southwest_Corrupted_Deco20", "Shrine_Southwest_Corrupted_Deco21"
		"Shrine_Southwest_Corrupted_Deco22", "Shrine_Southwest_Corrupted_Deco23", "Shrine_Southwest_Corrupted_Deco24",
		"Shrine_Southwest_Corrupted_Deco25",
		"Shrine_Southwest_Corrupted_FX1", "Shrine_Southwest_Corrupted_FX2", "Shrine_Southwest_Corrupted_FX3",
		"Shrine_Southwest_Corrupted_FX4", "Shrine_Southwest_Corrupted_FX5", "Shrine_Southwest_Corrupted_FX6",
		"Shrine_Southwest_Corrupted_FX7", "Shrine_Southwest_Corrupted_FX8", "Shrine_Southwest_Corrupted_FX9",
		"Shrine_Southwest_Corrupted_FX10", "Shrine_Southwest_Corrupted_FX11", "Shrine_Southwest_Corrupted_FX12"
	};
	array <string> m_arrStgLS1_CorruptedShrine_SW_FadeIn = 	{ "" };


	string m_stgLS1_bldgNortheast_Waves = 		"LS1_Northeast_Waves";
	string m_stgLS1_bldgSoutheast_Waves = 		"LS1_Southeast_Waves";
	string m_stgLS1_bldgDesc_wave_0 = 			"S_LS1_CorruptedWaves_0"; // no waves
	string m_stgLS1_bldgDesc_wave_1 = 			"S_LS1_CorruptedWaves_1"; // sending out waves
	string m_stgLS1_secNortheast = 				"Sector_4";
	string m_stgLS1_secSoutheast = 				"Sector_8";
	string m_stgLS1_secNorthwest = 				"Sector_1";
	string m_stgLS1_secSouthwest = 				"Sector_7";

	// The bickering shoutouts from the two fighting elven parties
	string m_stgLS1_trgBickeringScene = 		"LS1_Bickering";
	bool m_bLS1_EnteredLeafshade = 				false;
	bool m_bLS1_StartBickering = 				false;
	bool m_bLS1_StopBickering = 				false;
	bool m_bLS1_PauseBickering = 				false;
	int m_iLS1_bickeringCountingUp = 			0;
	int m_iLS1_bickeringCountingUp_Last = 		0;
	int m_iLS1_bickeringCountingUp_LastLast =	0;
	int m_iLS1_bickeringMin = 					10;
	int m_iLS1_bickeringMax = 					20;

	bool m_bLS1_TalkedWithArlan = 				false;
	bool m_bLS1_TalkedWithVarden = 				false;

	bool m_bLS1_ChoosenArlan = 					false;
	bool m_bLS1_ChoosenVarden = 				false;

	bool m_bLS1_GotCleanseSpell = 				false;

	// sidecontent stuff
	//string m_stgLS1_objManuscirpt = 			"LS1_Manuscript";
	//string m_stgLS1_itemManuscirpt = 			"LS1_ElfManuscript";

	string m_stgLS1_posTalkingHere = 			"LS1_PosLeader";
	string m_stgLS1_posTalkingMainSquare =		"LS1_PosPlaza";
	string m_stgLS1_posTalkingMainSquare_path =	"LS1_PosPlaza_Path";
	string m_stgLS1_posLiliathDespawn =			"LS1_PosLiliath";

	// Human Camp in the North
	bool m_bLS1_EnterHumanCamp = 				false;
	string m_stgLS1_spwnHumanGuards_1 = 		"LS1_HumanGuard_1";
	string m_stgLS1_spwnHumanGuards_2 = 		"LS1_HumanGuard_2";
	string m_stgLS1_posGateWalkAway_1 = 		"LS1_PosGate_1";
	string m_stgLS1_posGateWalkAway_2 = 		"LS1_PosGate_2";
	string m_stgLS1_trgHumanGate_1 = 			"LS1_Gate_1";
	string m_stgLS1_trgHumanGate_2 = 			"LS1_Gate_2";



	// --------------------------------------------------------------------------------------------------------------------
	// --- constructor --- dont make any changes here
	Level (LevelReference@ _Reference)
	{
		super(_Reference);
	}
	// -------------------------------------------------------------------------------------------------------------------
	// overriden:

	// Function that is called when the Level is created for the first time - only called once within the campaign
	void OnCreated () override
	{
		printImportant("V E R S I O N : LevelBase: "+m_LevelBaseVersion+", Map Script: " + m_stgVersion+" (Level was just created)");
		printImportant("M A P : Map: "+ m_Reference.GetMapId() +", setting: " + m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) +".");

		// Call the original OnCreated
		LevelBase::OnCreated();

		// Calling the final functions
		InitEvents(); // register all neutral events
		InitCommon(); // script and set everything up for starting the level

		// setting specific calls
		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 0 ) // First setting
		{
			InitEvents_0(); // (setting 0)
			InitCommon_0(); // (setting 0)
		}
	}

	// level data had been restored from savegame - ensure version compability here
	void OnLoaded (const uint _uVersion) override
	{
		printImportant("V E R S I O N : LevelBase: "+m_LevelBaseVersion+", Map Script: " + m_stgVersion+" (Level was loaded)");
		LevelBase::OnLoaded(_uVersion);


		if ( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems(m_stgLS1_HerbPackage, 1))
		{
			printNote("arrived from Grassland Coast with the herb package");
			LS1_GrasslandCoast_Finished();
		}

		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 0 ) // Second setting
			OnCheck_0();
		
	}

	// level has been entered
	void OnEntered () override
	{
		printImportant("V E R S I O N : LevelBase: "+m_LevelBaseVersion+", Map Script: " + m_stgVersion+" (Level was entered)");
		LevelBase::OnEntered();

		//D E B U G  F O R  P R E 3 - E V E N T
		// m_Reference.GetHeroParty(m_iPlayerFaction).AddItems(m_stgLS1_HerbPackage, 1);
		//D E B U G  F O R  P R E 3 - E V E N T


	}

	// -------------------------------------------------------------------------------------------------------------------
	// ---  A L L  B A S I C S  E V E N T S  -----------------------------------------------------------------------------

	void InitEvents ()
	{
		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.OnEnterLeafshade), m_stgSect_Leafshade, m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyOutsideSector, TOnHeroPartyEvent(@this.OnLeaveLeafshade), m_stgSect_Leafshade, m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLS1_StartBickering), "LS1_PlazaBickering", m_iPlayerFaction);

		// this is temp, remove it later again
		//m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnEnterLeafshade), "LS1_Bickering", m_iPlayerFaction);

	}
	// for the first map setting
	void InitEvents_0 ()
	{
		LS1_ChangeAllShrines_State1();

		//m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLS1_PickUpManuscript), m_stgLS1_objManuscirpt, m_iPlayerFaction);

		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_EnteredArea_Arlen), m_stgLS1_crtArlanFinrior, "LS1_LeaderArea");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_EnteredArea_Varden), m_stgLS1_crtVardenMerilith, "LS1_LeaderArea");

		// Human Camp
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_HumanGuard_1), m_stgLS1_trgHumanGate_1, m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_HumanGuard_2), m_stgLS1_trgHumanGate_2, m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_HumanLeaderWait), m_stgLS1_crtHumanLeader, "LS1_HumanLeaderWait");

		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.OnLS1_DefeatedBane), m_stgLS1_crtLiliath, "");
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLS1_DefeatedBane_Sector), m_stgLS1_HumanSector );
		//m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.OnLS1_DefeatedBane), m_stgLS1_crtLiliath, "");

		// Elven Shrines
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
		{
			m_Reference.RegisterBuildingEventByIndividual(Charging, TOnBuildingEvent(@this.OnLS1_ShrineCharging), m_arrStgLS1_CorruptedShrines[_iTmp]);
			m_Reference.RegisterBuildingEventByIndividual(Charged, TOnBuildingEvent(@this.OnLS1_ShrineCharged), m_arrStgLS1_CorruptedShrines[_iTmp]);
			//m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LS1_OnInteract_CorruptedShrine), m_arrStgLS1_CorruptedShrines[_iTmp], m_iPlayerFaction);
		}
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLS1_ShrineSectChangeOwner_northeast), m_stgLS1_secNortheast );
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLS1_ShrineSectChangeOwner_northwest), m_stgLS1_secNorthwest );
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLS1_ShrineSectChangeOwner_southeast), m_stgLS1_secSoutheast );
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLS1_ShrineSectChangeOwner_southwest), m_stgLS1_secSouthwest );
		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnLS1_SendCorruptedAttack_NE), m_stgLS1_bldgNortheast_Waves);
		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnLS1_SendCorruptedAttack_SE), m_stgLS1_bldgSoutheast_Waves);

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_HumanBickering), m_stgLS1_areaHumanCamp, m_iPlayerFaction);

		// corrupted elf, treant and so on
		m_Reference.RegisterCreatureEventByIndividual(EnteredAggroRange, TOnCreatureEvent(@this.OnLS1_TreantShoutout), m_stgLS1_crtTreant, m_stgAvatar);
		//m_Reference.RegisterHeroPartyEvent(AnyInAggroRange, TOnHeroPartyEvent(@this.OnLS1_TreantShoutout), m_stgLS1_crtTreant, m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnLS1_SOCorruptedElf_AfterBattle), m_Reference.FindCreaturesByDescription( kFactionMob, m_stgLS1_desCorruptElv ), false, "");

		m_Reference.RegisterCreatureEventByIndividual(Damaged, TOnCreatureEvent(@this.OnLS1_FightingAgainstTreant), m_stgLS1_crtTreant, "");

		// Ianna
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnCreatureEvent(@this.OnLS1_IannaAssassinAmbush), m_stgLS1_IannaAttack, m_iPlayerFaction);
		//m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLS1_IannaAssassinAmbush), m_stgAvatar, m_stgLS1_IannaAttack);

		// artifact
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LS1_OnInteract_Artifactillar), "LS_Artifact_ResurrectionArmor_Shrine", m_iPlayerFaction);
	}

	void InitCommon ()
	{
		m_Reference.EnableGroup( "LS1_GodstoneHumanCamp_OLD", false );

		// --- Inspections
		m_Reference.GetLogicObjectByName("LS_GuttedDeer").SetInspectionText(10003);
		m_Reference.GetLogicObjectByName("LS1_BloodburnDead").SetInspectionText(10004);
		m_Reference.GetLogicObjectByName("LS1_BrokenStatueElf").SetInspectionText(10005);
		m_Reference.GetLogicObjectByName("LS1_ElfBurialGrave").SetInspectionText(10006);
		m_Reference.GetLogicObjectByName("LS1_ElfSpears").SetInspectionText(10007);
		m_Reference.GetLogicObjectByName("LS1_FishingCabinWeir").SetInspectionText(10008);
		m_Reference.GetLogicObjectByName("LS1_HermitShed").SetInspectionText(10009);
		m_Reference.GetLogicObjectByName("LS1_LenyaBaskets").SetInspectionText(10010);
		m_Reference.GetLogicObjectByName("LS1_Manuscript").SetInspectionText(10011);
		m_Reference.GetLogicObjectByName("LS1_MyticalElfBanner").SetInspectionText(10012);
		m_Reference.GetLogicObjectByName("LS1_TorturedHuman_1").SetInspectionText(10013);
		m_Reference.GetLogicObjectByName("LS1_TorturedHuman_2").SetInspectionText(10014);

		m_Reference.GetLogicObjectByName("LS_Artifact_ResurrectionArmor_Shrine").Enable(true);
		m_Reference.GetLogicObjectByName("LS_Artifact_ResurrectionArmor_PossibleEnemySpawnFX").Enable(false);
		//m_Reference.GetLogicObjectByName("LS_Artifact_ResurrectionArmor_PossibleEnemySpawnFX").SetInspectionText(10002);
	}
	// for the first map version
	void InitCommon_0 ()
	{
		print('Neutral is Faction Id: ' + kFactionNeutral +'');
		RTSchangeBuildingFactions( m_stgLS1_HumanSector, m_iLS1_FactionHumans );
		// TESTING
		/*ArticyLS1_StartRTSGame();
		m_Reference.SetTimer( TOnTimerEvent(@this.LS1_BaneRebellion), 5 );
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("HealthPotion",6);
		LS1_DisbandGroups();*/
		// m_Reference.SetTimer( TOnTimerEvent(@this.OnLS1_tempTesting), 10 );
		//m_Reference.GetCreatureByName(m_stgLS1_crtArlanFinrior).EnablePOIVisitingBehavior( false );
		//m_Reference.GetCreatureByName(m_stgLS1_crtVardenMerilith).EnablePOIVisitingBehavior( false );
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("HealthPotion", 5);
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("FocusPotion", 5);

		m_Reference.GetCreatureByName(m_stgLS1_crtArlanFinrior).SetImmovable(true);
		m_Reference.GetCreatureByName(m_stgLS1_crtSpwnGroupVarden).SetImmovable(true);
		/*EnablePOIVisitingBehaviorSpawn( m_stgLS1_crtSpwnGroupArlan, false );
		EnablePOIVisitingBehaviorSpawn( m_stgLS1_crtSpwnGroupVarden, false );*/

		m_Reference.GetBuildingByName( m_stgLS1_bldgNortheast_Waves ).SetSelectable(false);
		m_Reference.GetBuildingByName( m_stgLS1_bldgSoutheast_Waves ).SetSelectable(false);

		m_Reference.GetCreatureByName( m_stgLS1_crtTreant ).SetImmortal(true);
		m_Reference.GetCreatureByName(m_stgLS1_crtTreant).PlayAnimation( m_Reference, TalkCalm, 0, uint(-1), true, false, m_Reference.GetLogicObjectByName( "LS1_TreantPos" ) );

		//m_Reference.GetCreatureByName( m_stgLS1_crtHumanLeader ).SetImmortal(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtArlanFinrior ).SetImmortal(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtVardenMerilith ).SetImmortal(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtArlanFinrior ).SetImmovable(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtVardenMerilith ).SetImmovable(true);

		m_Reference.GetCreatureByName( m_stgLS1_crtHumanLeader ).SetImmovable(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtHumanLeader ).SetImmortal(true);

		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).SetImmortal(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).SetImmovable(true);
		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).GoTo(m_Reference, m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader), 0, 10, false, false);
		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).EnablePOIVisitingBehavior(false);


		//SHRINES NOT ATTACKABLE BY CREEPS
		for(uint i = 0; i < m_arrStgLS1_CorruptedShrines.length();i++){
			m_Reference.GetBuildingByName(m_arrStgLS1_CorruptedShrines[i]).SetAttackable(false);
		}

		// These are all objects that can be activated and disabled.
		// These are all for the elven shrines
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_NE_FadeOut.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NE_FadeOut[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NE_FadeOut[_iTmp] ).Enable(true);
		}
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_NE_FadeIn.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NE_FadeIn[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NE_FadeIn[_iTmp] ).Enable(false);
		}

		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_NW_FadeOut.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NW_FadeOut[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NW_FadeOut[_iTmp] ).Enable(true);
		}
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_NW_FadeIn.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NW_FadeIn[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_NW_FadeIn[_iTmp] ).Enable(false);
		}

		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_SW_FadeOut.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SW_FadeOut[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SW_FadeOut[_iTmp] ).Enable(true);
		}
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_SW_FadeIn.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SW_FadeIn[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SW_FadeIn[_iTmp] ).Enable(false);
		}

		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_SE_FadeOut.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SE_FadeOut[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SE_FadeOut[_iTmp] ).Enable(true);
		}
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrine_SE_FadeIn.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SE_FadeIn[_iTmp] ).SetInteractive(false);
			m_Reference.GetLogicObjectByName( m_arrStgLS1_CorruptedShrine_SE_FadeIn[_iTmp] ).Enable(false);
		}

		// Grassland Coast connection
		m_Reference.GetLogicObjectByName(m_stgEntrance_LS_GC).SetInteractive(false);

		// setup visual effects for treant barrier
		m_Reference.GetLogicObjectByName( "LS_TreantBarrier_Effect" ).Enable( false );
		m_Reference.EnableGroup( "LS_TreantBarrier", false );
		// setup logical part of the barrier
		m_Reference.BlockNavMesh( "LS_TreantBarrier_PhysicBlocker", false );
	}

	void OnCheck_0()
	{
		printNote( "PATCH 'OnCheck_0'" );

		// RTS officially finished, but still there
		if ( m_Reference.GetSectorsByOwner( m_iPlayerFaction ).length() > 0 && m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P3_Q5a_GainElves") == Completed )
			TransferRTS( m_iPlayerFaction, m_iLS1_FactionElven );
		
	}

	// -------------------------------------------------------------------------------------------------------------------
	// --- E V E N T  F U N C T I O N S ---------------------------------------------------------------------------------

	bool OnLS1_tempTesting ()
	{
		printNote("temporary test function.");
		HeroPartyGorTransform(true);
		return true;
	}

	bool OnEnterLeafshade(Creature& in _Creature)
	{
		if (m_bLS1_EnteredLeafshade == false)
		{
			DialogShoutoutTimed( m_stgAvatar, m_stgAvatar, "LS1_SO_EnterLeafshade", false, 1);
			m_bLS1_EnteredLeafshade = true;
		}

		m_iHeroesInLeafshade = m_iHeroesInLeafshade + 1;
		if ( _Creature.GetDescriptionName() == m_stgAvatar)
		{
			printNote("Avatar entered the elven village, playing the banner");
			Banner_Humans(1);
		}
		m_Reference.AddVisibleSector( m_iPlayerFaction, m_Reference.GetSectorByName(m_stgSect_Leafshade).GetIndex() );

		return false;
	}
	bool OnLS1_StartBickering (Creature& in _Creature)
	{
		m_Reference.GetHeroParty(m_iPlayerFaction).Stop();
		CutsceneLS1_StartCutscene_Leafshade();

		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, 	"LS1_FirstContact", true);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_FirstContact", true);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtElf_1, "LS1_FirstContact", true);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtElf_2, "LS1_FirstContact", true);

		LS1_StartBickering();

		return true;
	}
	bool OnLeaveLeafshade(Creature& in _Creature)
	{
		m_iHeroesInLeafshade = m_iHeroesInLeafshade - 1 ;
		if ( m_iHeroesInLeafshade == 0)
			m_Reference.RemoveVisibleSector( m_iPlayerFaction, m_Reference.GetSectorByName(m_stgSect_Leafshade).GetIndex() );

		return false;
	}

	bool LS1_StartBickering()
	{
		if (m_bLS1_StartBickering)
			return true;

		printNote("Bickering is starting.");
		m_bLS1_StartBickering = true;

		OnLS1_NextBickering();

		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.OnLS1_NextBickering_StartAgain), m_stgSect_Leafshade, m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AllOutsideSector, TOnHeroPartyEvent(@this.OnLS1_NextBickering_StopTemporarily), m_stgSect_Leafshade, m_iPlayerFaction);

		return true;
	}
	bool OnLS1_NextBickering_StartAgain(Creature& in _Creature)
	{
		LS1_PauseBickering( false );
		return false;
	}
	bool OnLS1_NextBickering_StopTemporarily(Creature& in _Creature)
	{
		LS1_PauseBickering( true );
		return false;
	}


	bool OnLS1_NextBickering()
	{
		// Stop the bickering completely
		if (m_bLS1_StopBickering)
			return true;
		else if (m_bLS1_PauseBickering)
			return false;

		// check if Varden or Arlan in a dialogue - if yes, give false back and come back later
		if ( m_Reference.GetCreatureByName(m_stgLS1_crtVardenMerilith).IsInDialogue()
			|| m_Reference.GetCreatureByName(m_stgLS1_crtArlanFinrior).IsInDialogue()
			|| m_Reference.GetCreatureByName(m_stgLS1_crtElf_1).IsInDialogue()
			|| m_Reference.GetCreatureByName(m_stgLS1_crtElf_2).IsInDialogue()
		)
			return false;

		int _iAdditional = 0;
		switch( m_iLS1_bickeringCountingUp )
		{
			case 0:
				DialogShoutout_Special( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_DiscussionVardenArlan", true, false, false, false, false, false, false, 0 );
			    //DialogShoutout( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_DiscussionVardenArlan", false);
			    _iAdditional = 20;
			    break;
			case 1:
				DialogShoutout_Special( m_stgLS1_crtArlanFinrior, m_stgLS1_crtArlanFinrior, "LS1_SO_Debate_2", true, false, false, false, false, false, false, 0 );
			  	//DialogShoutout( m_stgLS1_crtArlanFinrior, m_stgLS1_crtArlanFinrior, "LS1_SO_Debate_2", false);
			  	break;
		  	case 2:
		  		if(m_bLS1_TalkedWithArlan || m_bLS1_TalkedWithVarden)
		  			DialogShoutout_Special( m_stgLS1_crtArlanFinrior, m_stgLS1_crtArlanFinrior, "LS1_SO_Debate_1", true, false, false, false, false, false, false, 0 );
			  		//DialogShoutout( m_stgLS1_crtArlanFinrior, m_stgLS1_crtArlanFinrior, "LS1_SO_Debate_1", false);
			  	break;
			case 3:
				DialogShoutout_Special( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_SO_Debate_2", true, false, false, false, false, false, false, 0 );
			  	//DialogShoutout( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_SO_Debate_2", false);
			  	break;
			case 4:
				if(m_bLS1_TalkedWithArlan || m_bLS1_TalkedWithVarden)
			  		DialogShoutout_Special( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_SO_Debate_1", true, false, false, false, false, false, false, 0 );
			  		//DialogShoutout( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_SO_Debate_1", false);
			  	break;
			case 5:
				DialogShoutout_Special( m_stgLS1_crtElf_1, m_stgLS1_crtElf_1, "LS1_SO_Debate_Varden_1", true, false, false, false, false, false, false, 0 );
			  	//DialogShoutout( m_stgLS1_crtElf_1, m_stgLS1_crtElf_1, "LS1_SO_Debate_Varden_1", false);
			  	break;
			case 6:
				DialogShoutout_Special( m_stgLS1_crtElf_2, m_stgLS1_crtElf_2, "LS1_SO_Debate_Arlan_1", true, false, false, false, false, false, false, 0 );
			  	//DialogShoutout( m_stgLS1_crtElf_2, m_stgLS1_crtElf_2, "LS1_SO_Debate_Arlan_1", false);
			  	break;
		}

		// find the next bickering, without picking the same as the last two's
		m_iLS1_bickeringCountingUp_LastLast = m_iLS1_bickeringCountingUp_Last;
		m_iLS1_bickeringCountingUp_Last = m_iLS1_bickeringCountingUp;
		while( m_iLS1_bickeringCountingUp == m_iLS1_bickeringCountingUp_Last || m_iLS1_bickeringCountingUp == m_iLS1_bickeringCountingUp_LastLast )
		{
			m_iLS1_bickeringCountingUp = m_Reference.GetRandom().GetInteger( 1, 7 ) ;
		}

		// start off the next bickering part.
		printNote("Next bickering: "+m_iLS1_bickeringCountingUp+" last one was "+ m_iLS1_bickeringCountingUp_Last +" and last last one "+m_iLS1_bickeringCountingUp_LastLast );
		m_Reference.SetTimer( TOnTimerEvent(@this.OnLS1_NextBickering), (m_Reference.GetRandom().GetInteger( m_iLS1_bickeringMin, m_iLS1_bickeringMax ) + _iAdditional) );

		return true;
	}

	bool m_bLS1_TriggeredElfenLeader = false;
	bool OnLC2_EnteredArea_Arlen(Creature& in _Creature)
	{
		if (m_bLS1_TriggeredElfenLeader)
			return true;

		printNote("corrupted elves died -> triggering the Shoutout.");
		_Creature.SetPOICategories(m_Reference, array<string>={"LS1_Leafshade_Leader"});
		_Creature.EnablePOIVisitingBehavior( true );

		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_ArlansMission", true);
		m_bLS1_TriggeredElfenLeader = true;

		return true;
	}

	bool OnLS1_TreantShoutout(Creature& in _Creature)
	{
		printNote("Treant shoutout to come closer");
		//DialogShoutout_Special( m_stgLS1_crtTreant, m_stgLS1_crtTreant, "LS1_SO_ComeCloser", false, false, false, true, false, true, false, 1 );
		DialogShoutoutReveal( m_stgLS1_crtTreant, m_stgLS1_crtTreant, "LS1_SO_ComeCloser" );

		return true;
	}

	bool OnLC2_EnteredArea_Varden(Creature& in _Creature)
	{
		if (m_bLS1_TriggeredElfenLeader)
			return true;

		printNote("corrupted elves died -> triggering the Shoutout.");
		_Creature.SetPOICategories(m_Reference, array<string>={"LS1_Leafshade_Leader"});
		_Creature.EnablePOIVisitingBehavior( true );

		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_VardensMission", true);
		m_bLS1_TriggeredElfenLeader = true;

		return true;
	}

	bool OnLC2_EnteredMainSquare_Arlen(Creature& in _Creature)
	{
		printNote("Both elven leaders are in the main square again -> enabling the next quest step.");

		// enabling the next dialogue
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_GainElvesBase", true);

		string m_stgTmp = "";
		if (m_bLS1_ChoosenArlan)
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "81532B2E");
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "2CF4EE8C");
			DialogShoutout( m_stgLS1_crtArlanFinrior, m_stgLS1_crtArlanFinrior, "LS1_SO_StartNewDiscussion", false);
			
		}
		else if (m_bLS1_ChoosenVarden)
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "2CF4EE8C");
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "81532B2E");
			DialogShoutout( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_SO_StartNewDisussionV", false);
		}
		return true;
	}

	bool OnLS1_SOCorruptedElf_AfterBattle(Creature& in _Creature)
	{
		if ( m_bLS1SOcorruptedElf )
			return true;

		printNote("triggering the shoutout. Its gonna be played, after the fight ended.");
		m_Reference.SetTimer( TOnTimerEvent(@this.OnLS1_SOCorruptedElf_AfterBattleTimed), 1 );

		return true;
	}
	bool OnLS1_SOCorruptedElf_AfterBattleTimed()
	{
		if (m_bLS1SOcorruptedElf)
			return true;

		else if ( HeroPartyReadyForDialogue() )
		{
			printNote("Doing the shoutout.");
			DialogShoutout( m_stgAvatar, m_stgAvatar, "LS1_SO_ElfAttack", true);
			m_bLS1SOcorruptedElf = true;
			return true;
		}
		return false;
	}

	bool OnLS1_SOCorruptedElf(Creature& in _Creature)
	{
		// ToDo: check if MQ_12A is active
		printNote("corrupted elves died -> triggering the Shoutout.");
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LS1_SO_ElfAttack", true);

		return true;
	}

	/*bool OnLS1_PickUpManuscript(Creature& in _Creature)
	{
		printNote("picking up the manuscript.");
		HeroPickUpObject( m_stgLS1_objManuscirpt, m_stgLS1_itemManuscirpt );
		m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtOldElf, "F818E482");

		return true;
	}*/

	bool OnLC2_HumanGuard_1 (Creature& in _Creature)
	{
		printNote("Trying to enter the Human Guards, 1 - "+m_bLS1_EnterHumanCamp+", "+m_bLS1_TalkedWithHumanLeader+", "+m_bLS1_IannaAmbush);
		if ( m_bLS1_EnterHumanCamp && m_bLS1_TalkedWithHumanLeader && m_bLS1_IannaAmbush )
			return true;
		else if ( m_bLS1_EnterHumanCamp && m_bLS1_TalkedWithHumanLeader && m_bLS1_IannaAmbush == false )
			LS1_HumanGuardTalking_Ianna( m_stgLS1_spwnHumanGuards_1, _Creature.GetDescriptionName() );
		else if ( m_bLS1_EnterHumanCamp == false )
			LS1_HumanGuardTalking(m_stgLS1_spwnHumanGuards_1, m_stgLS1_posGateWalkAway_1, _Creature.GetDescriptionName() );

		/*if ( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems(m_stgLS1_HerbPackage, 1) == true )
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtHumanLeader, "LS1_HerbsGathered", true);
		else
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtHumanLeader, "LS1_HerbsGathered", false);*/

		return false;
	}

	bool OnLC2_HumanGuard_2 (Creature& in _Creature)
	{
		printNote("Trying to enter the Human Guards, 2 - "+m_bLS1_EnterHumanCamp+", "+m_bLS1_TalkedWithHumanLeader+", "+m_bLS1_IannaAmbush);
		if ( m_bLS1_EnterHumanCamp && m_bLS1_TalkedWithHumanLeader && m_bLS1_IannaAmbush )
			return true;
		else if ( m_bLS1_EnterHumanCamp && m_bLS1_TalkedWithHumanLeader && m_bLS1_IannaAmbush == false )
			LS1_HumanGuardTalking_Ianna( m_stgLS1_spwnHumanGuards_2, _Creature.GetDescriptionName() );
		else if ( m_bLS1_EnterHumanCamp == false )
			LS1_HumanGuardTalking(m_stgLS1_spwnHumanGuards_2, m_stgLS1_posGateWalkAway_2, _Creature.GetDescriptionName() );

		/*if ( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems(m_stgLS1_HerbPackage, 1) == true )
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtHumanLeader, "LS1_HerbsGathered", true);
		else
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtHumanLeader, "LS1_HerbsGathered", false);*/

		return false;
	}
	bool OnLC2_HumanLeaderWait(Creature& in _Creature)
	{
		_Creature.SetPOICategories(m_Reference, array<string>={"LS1_HumansAtBase_Leader"});
		_Creature.EnablePOIVisitingBehavior(true);

		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_HumanSpawns.length() ; _iTmp++ )
		{
			array <Creature>@ _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[_iTmp] );
			CreatureGroup _crtGroup ( m_Reference );
			_crtGroup.Set( _arrCrt );
			_crtGroup.Stop();

			EnablePOIVisitingBehaviorSpawn( m_arrStgLS1_HumanSpawns[_iTmp], true );
			SetPOICategoriesSpawn( m_arrStgLS1_HumanSpawns[_iTmp], array<string>={"LS1_HumansAtBase"} );
		}
		
		return true;
	}
	bool OnLS1_DefeatedBane_Sector (Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		if(_iNewOwner != m_iLS1_FactionHumansBaneRTS && !m_bLS1_BaneDefeated)
		{
			m_bLS1_BaneDefeated = true;
			m_Reference.LoseGame( m_iLS1_FactionHumansBaneRTS );
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_SO_BaneCampDestroyed", false);
			Autosave();
		}

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_SQ3_DefeatBane", "P3_Q5_DefeatBane", Completed );
		return true;
	}
	bool OnLS1_DefeatedBane(Creature& in _Creature)
	{
		m_bLS1_BaneDefeated = true;

		return true;
	}
	bool LS1_HumanLeaderGoesAway()
	{
		m_Reference.GetCreatureByName( m_stgLS1_crtHumanLeader ).FollowPath( m_Reference, m_stgLS1_pathHumanLeaderLeaves, true, true, false );
		return true;
	}

	bool OnLS1_ShrineCharging(Building& in _Building)
	{
		string _stgTmp = m_Reference.FindEntityName(_Building);

		// Check the visual satate of the shrine
		//printNote("Boulder: GetCharge, "+_Building.GetCharge()+" and MaxCharge is "+_Building.GetMaxCharge());
		if ( _Building.GetCharge() == PercentOf(_Building.GetMaxCharge(), m_iShrineState_3) )
		{
			//printNote(""+_stgTmp+": Changing to state 1");
			LS1_ChangeShrine_State3(_stgTmp);
		}
		else if ( _Building.GetCharge() == PercentOf(_Building.GetMaxCharge(), m_iShrineState_2) )
		{
			//printNote(""+_stgTmp+": Changing to state 1");
			LS1_ChangeShrine_State2(_stgTmp);
		}
		else if ( _Building.GetCharge() == PercentOf(_Building.GetMaxCharge(), m_iShrineState_1) )
		{
			//printNote(""+_stgTmp+": Changing to state 1");
			LS1_ChangeShrine_State1(_stgTmp);
		}


		// Activate the Waves
		// first: check if the Building is one of the two, where Waves should spawn
		if ( _stgTmp == "Shrine_Southeast" || _stgTmp == "Shrine_Northeast" ) // check if the sector belongs to anyone ( "Shrine_Southeast", "Shrine_Northeast")
		{
			string _stgSect = "";
			string _stgBldg = "";
			if (_stgTmp == "Shrine_Southeast")
			{
				_stgSect = m_stgLS1_secSoutheast;
				_stgBldg = m_stgLS1_bldgSoutheast_Waves;
			}
			else if (_stgTmp == "Shrine_Northeast")
			{
				_stgSect = m_stgLS1_secNortheast;
				_stgBldg = m_stgLS1_bldgNortheast_Waves;
			}

			// activating, or deactivating the wave-spawner
			/*if ( m_Reference.GetSectorByName(_stgSect).GetOwner() == kFactionNeutral )
				m_Reference.GetBuildingByName( _stgBldg ).Upgrade(m_Reference, m_stgLS1_bldgDesc_wave_0, true);
			else
				m_Reference.GetBuildingByName( _stgBldg ).Upgrade(m_Reference, m_stgLS1_bldgDesc_wave_1, true);*/
		}
		//m_Reference.GetBuildingByName( m_stgLS1_bldgNortheast_Waves ).Upgrade(m_Reference, m_stgLS1_bldgDesc_wave_1, true);
		//m_Reference.GetBuildingByName( m_stgLS1_bldgSoutheast_Waves ).Upgrade(m_Reference, m_stgLS1_bldgDesc_wave_1, true);

		return false;
	}

	bool OnLS1_ShrineCharged(Building& in _Building)
	{
		m_iShrineCleanedNmbr ++;
		m_Reference.GetWorld().SetGlobalInt( m_glbCat_Questlog+"LS1_PoolsCleansed", m_iShrineCleanedNmbr );

		string _stgTmp = m_Reference.FindEntityName(_Building);
		printNote(""+_stgTmp+" shrine cleaned, now "+m_iShrineCleanedNmbr+" cleanded shrines in total.");
		LS1_ChangeShrine_Cleansed(_stgTmp);

		if ( _stgTmp == "Shrine_Southeast" || _stgTmp == "Shrine_Northeast" ) // check if the sector belongs to anyone ( "Shrine_Southeast", "Shrine_Northeast")
		{
			string _stgBldg = "";
			if (_stgTmp == "Shrine_Southeast")
				_stgBldg = m_stgLS1_bldgSoutheast_Waves;
			else if (_stgTmp == "Shrine_Northeast")
				_stgBldg = m_stgLS1_bldgNortheast_Waves;

			m_Reference.GetBuildingByName( _stgBldg ).Upgrade(m_Reference, m_stgLS1_bldgDesc_wave_0, true);
		}


		// complete appropriate quest steps depending on shrine
		if(_stgTmp == "Shrine_Southwest")
		{
			if (m_bLS1_ChoosenVarden)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Varden_Pool1", Completed );
			else 
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Pool1", Completed );
		}
		else if(_stgTmp == "Shrine_Southeast")
		{
			if (m_bLS1_ChoosenVarden)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Varden_Pool2", Completed );
			else
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Pool2", Completed );
		}
		else if(_stgTmp == "Shrine_Northeast")
		{
			if (m_bLS1_ChoosenVarden)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Varden_Pool3", Completed );
			else 
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Pool3", Completed );
		}
		else 
		{
			if (m_bLS1_ChoosenVarden)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Varden_Pool4", Completed );
			else
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_CleansePools_Pool4", Completed );
		}
		
		if (m_iShrineCleanedNmbr == 1)
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_FirstPoolCleansed", true);
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_SO_PoolCleared_01", false);
		}
		else if (m_iShrineCleanedNmbr == 2)
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_FirstPoolCleansed", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_SecondPoolCleansed", true);
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_SO_PoolCleared_02", false);
		}
		else if (m_iShrineCleanedNmbr == 3)
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_FirstPoolCleansed", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_SecondPoolCleansed", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_ThirdPoolCleansed", true);
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_SO_PoolCleared_02", false);
		}
		else if (m_iShrineCleanedNmbr == 4) // Finishing the quest
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_FirstPoolCleansed", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_SecondPoolCleansed", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_ThirdPoolCleansed", false);

			DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_SO_PoolCleared_03", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_AllPoolsCleansed", true);
			AutosaveTimed(1);
		}

		return true;
	}

	bool LS1_OnInteract_CorruptedShrine(Creature& in _Creature)
	{
		if( !DialogCheck_NotInCombat(true) )
			return false;
		
		printNote( "LS1_OnInteract_CorruptedShrine" );
		//if( !m_bInteractedWithAShrine )
		//{
		m_Reference.GetWorld().SetGlobalInt( m_glbCat_Questlog+"LS1_CluesFound", m_Reference.GetWorld().GetGlobalInt( m_glbCat_Questlog+"LS1_CluesFound", -1) + 1);
		m_bInteractedWithAShrine = true;
		if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_InvestigateNorth_Varden")) 			
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden_Pool1", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden_Pool2", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden_Pool3", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden_Pool4", Completed );
		}
		if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_InvestigateNorth")) 	
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Pool1", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Pool2", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Pool3", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Pool4", Completed );
		}

		//DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_Pools", false);
		DialogShoutout_Special( m_stgAvatar, m_stgAvatar, "LS1_Pools", false, true, false, false, false, false, true, 0 );
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves" , "P3_Q5_InvestigateNorth_CheckPool", Completed );
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves" , "P3_Q5_InvestigateNorth_Varden_CheckPool", Completed );

		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
			m_Reference.GetBuildingByName(m_arrStgLS1_CorruptedShrines[_iTmp]).SetInteractive( false );
		
		//}
		return true;
	}

	// I so friggin hate it. This was scripted SO many damn friggin times now. 
	// - how about we script each map simply 10x times. I mean. Why not?
	// what could possibly go wrong with ~60 map/settings, and reworking eacht and everyone multiple times? 

	int m_iShrineSectorInEnemyPossession = 		0;
	int m_iNE_AttackWave = 						0;
	// in case the player has lost the sector
	bool OnLS1_ShrineSectChangeOwner_northeast(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner) // activates a Wave
	{
		LS1_CheckPoolSector(_iPreviousOwner, _iNewOwner);
		if ( _iNewOwner == m_iPlayerFaction )
		{
			for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_NE_AttackWave.length(); _iTmp++ )
				m_Reference.SetTimer( TOnTimerEvent(@this.OnLS1_ShrineSectChangeOwner_northeast_wave), _iTmp );
			
			return true;
		}
		return false;
	}
	bool OnLS1_ShrineSectChangeOwner_northeast_wave()
	{
		m_Reference.ActivateSpawn(m_arrStgLS1_NE_AttackWave[m_iNE_AttackWave], true);
		array <Creature> _arrCrts = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_NE_AttackWave[m_iNE_AttackWave] );
		for ( uint _iTmp = 0; _iTmp < _arrCrts.length() ; _iTmp++ )
			_arrCrts[_iTmp].GoTo(m_Reference, m_Reference.GetSectorByName(m_stgLS1_secNortheast).GetMainBuilding(), 0, 0, true, false );
		m_iNE_AttackWave++; 
		
		return true;
	}

	bool OnLS1_ShrineSectChangeOwner_northwest(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		LS1_CheckPoolSector(_iPreviousOwner, _iNewOwner);
		return true;
	}
	bool OnLS1_ShrineSectChangeOwner_southeast(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner) // activates a Wave
	{
		LS1_CheckPoolSector(_iPreviousOwner, _iNewOwner);
		return true;
	}
	bool OnLS1_ShrineSectChangeOwner_southwest(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		LS1_CheckPoolSector(_iPreviousOwner, _iNewOwner);

		// Corrupted attack
		if ( _iNewOwner == m_iPlayerFaction )
		{
			// activate the three wildlife spawns, and send all of them to the center of the sector
			for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_SW_AttackWave.length() ; _iTmp++ )
				m_Reference.ActivateSpawn(m_arrStgLS1_SW_AttackWave[_iTmp], true);
			
			array <Creature> _arrCrts = GetCreaturesFromSpawns(m_arrStgLS1_SW_AttackWave);
			for ( uint _iTmp = 0; _iTmp < _arrCrts.length() ; _iTmp++ )
				_arrCrts[_iTmp].GoTo(m_Reference, _Sector.GetMainBuilding(), 0, 0, true, false );

			return true;
		}
		return false;
	}


	bool OnLS1_SendCorruptedAttack_NE(Building&in _Building, Creature[]&in _Creatures)
	{
		for (uint _iTmp = 0; _iTmp < _Creatures.length(); _iTmp++ )
			_Creatures[_iTmp].FollowPath(m_Reference, "LS1_Northeast_Waves", false, true);
		return false;
	}
	bool OnLS1_SendCorruptedAttack_SE(Building&in _Building, Creature[]&in _Creatures)
	{
		for (uint _iTmp = 0; _iTmp < _Creatures.length(); _iTmp++ )
			_Creatures[_iTmp].FollowPath(m_Reference, "LS1_Southeast_Waves", false, true);
		return false;
	}

	bool OnLC2_HumanBickering(Creature& in _Creature)
	{
		if (m_bLS1_EnterHumanCamp == true && m_Reference.GetHeroParty(m_iPlayerFaction).HasItems(m_stgLS1_HerbPackage, 1) == false )
		{
			DialogShoutout( m_stgLS1_crtHumanLeader, m_stgLS1_crtHumanLeader, "LS1_DebateInitiate", false);
			return true;
		}

		return false;
	}

	bool OnStartTreantFight(Creature& in _Creature)
	{
		if ( _Creature.GetDescriptionName() == m_stgAvatar )
		{
			DialogShoutout( m_stgAvatar, m_stgAvatar, "LS1_SO_TreantAttack", false);
			return true;
		}
		return false;
	}

	// call cutscene to dispell the barrier in front of treant
	bool LS1_OnAnyInside_DispellBarrier(Creature& in _Creature)
	{
		if(_Creature.GetDescriptionName() == m_stgAvatar)
		{
			m_Reference.PlayCutScene("LS1_BarrierVanishes");
			m_Reference.GetCreatureByName(m_stgLS1_crtTreant).Stop(m_Reference);
			return true;
		}

		return false;
	} 

	bool OnLS1_FightingAgainstTreant(Creature& in _Creature)
	{
		// shoutout that triggers, when the Treant is low enough.
		if (_Creature.GetCurrentHP() <= PercentOf(_Creature.GetMaxHP(), m_iLS1_TreantSpellHP))
		{
			//if ( _Creature.HasCondition( m_iLS1_CorruptedCondition ) && m_bLS1_TreantShoutoutDone == false && m_bLS1_GotCleanseSpell )
			if ( _Creature.GetCurrentHP() <= PercentOf( _Creature.GetMaxHP(), 25 ) && !m_bLS1_TreantShoutoutDone )
			{
				printNote("Has the corrupted Condition - doing the shoutout once");
				DialogShoutout( m_stgAvatar, m_stgAvatar, "LS1_SO_TreantHealthLowEnough", false);
				m_bLS1_TreantShoutoutDone = true;
			}
			else if ( _Creature.HasCondition( m_iLS1_CorruptedCleanseCondition ) ) // triggers the sec when the treant has been cleansed
			{
				PlaySound("", "events/l1_corruption_ends");
				printNote("Cleanse condition! Ending the battle");
				m_Reference.GetCreatureByName(m_stgAvatar).RemoveSpell(m_Reference, m_stgLS1_CleanseSpell);
				
				_Creature.RemoveCondition( m_iLS1_CorruptedCondition );
				_Creature.AllowAttacks(false);
				_Creature.SetAttackable(false);
				_Creature.SetFaction(kFactionNeutral);


				DialogShoutoutTimed( m_stgLS1_crtTreant, m_stgLS1_crtTreant, "LS1_SO_Freed", false, 1 );
				_Creature.GoTo( m_Reference, m_Reference.GetLogicObjectByName("LS1_TreantTalkPos"), 0, 0, false, false );
				m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtTreant, "LS1_Cured", true);

				OnLS1_CheckFinalQuestDialogue();
				AutosaveTimed(1);

				return true;
			}
			else
				printNote("Health is below "+m_iLS1_TreantSpellHP+" percent, waiting for the treant to be cleansed.");
		}

		return false;
	}

	void OnLS1_CheckFinalQuestDialogue()
	{
		printNote("Health is below .");
		if ( m_bLS1_BaneDefeated )
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_Cured_HumansDefeated", true);
		else
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_Cured_HumansAlive", true);
	}

	int m_iLS1_ScoundrelKilled = 0;
	bool OnLS1_IannaAssassinAmbush(Creature& in _Creature)
	{
		printNote("IANNA AMBUSH '"+m_bLS1_IannaAmbush+"'");
		if ( m_bLS1_IannaAmbush )
		{
			// Spawn and attack the player
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_SQ4_Assassins_MeetBertrand", Completed );
			m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "music/characters/ianna_combat");

			for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_IannaSpawns.length(); _iTmp++ )
			{
				m_Reference.ActivateSpawn(m_arrStgLS1_IannaSpawns[_iTmp], true);
				CreatureGroup _crtFakeHeroGrp ( m_Reference );
				_crtFakeHeroGrp.Set( m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_IannaSpawns[_iTmp] ) );
				//_crtFakeHeroGrp.AttackPosition( m_Reference.GetLogicObjectByName("LS1_BertrandMeeting"), true, false );
				_crtFakeHeroGrp.AttackPosition( _Creature, true, false );
			}

			for ( uint _iTmp1 = 0; _iTmp1 < m_arrStgLS1_IannaSpawns_Aggro.length(); _iTmp1++ )
				m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnLS1_IannaScoundrellKilled), m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_IannaSpawns_Aggro[_iTmp1] ), false, "");

			//m_Reference.ActivateSpawn( "LS1_Ianna", true );
			m_Reference.GetCreatureByName(m_stgHero_Ianna).EnablePOIVisitingBehavior(false);
			m_Reference.GetCreatureByName(m_stgHero_Ianna).EnablePOIVisitingBehavior(false);
			m_Reference.GetCreatureByName(m_stgHero_Ianna).SetImmortal(true);
			
			DialogShoutout( m_stgLS1_IannaScroundrel_1, m_stgLS1_IannaScroundrel_1, "LS1_SO_Attack", false );
			m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "music/characters/ianna_combat");

			return true;
		}
		return false;
	}

	bool OnLS1_IannaScoundrellKilled(Creature& in _Creature)
	{
		m_iLS1_ScoundrelKilled++;
		if ( m_iLS1_ScoundrelKilled == 2 )
		{
			m_Reference.GetCreatureByName(m_stgHero_Ianna).SetFaction( m_iLS1_FactionIanna );
			m_Reference.GetCreatureByName(m_stgHero_Ianna).GoTo( m_Reference, m_Reference.GetLogicObjectByName("LS1_BertrandMeeting"), 0, 0, false, false);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_SQ4_Assassins_FendOff", Completed );
			m_Reference.GetWorld().EnableDialogueTopic( m_stgHero_Ianna, "LS1_IannaDefeat", true );
		}

		return true;
	}

	bool OnLS1_TimedSO_IannaAttack()
	{
		if ( m_Reference.GetCreatureByName(m_stgLS1_IannaScroundrel_2).GetCurrentHP() > 0 )
			DialogShoutout( m_stgLS1_IannaScroundrel_2, m_stgLS1_IannaScroundrel_2, "LS1_SO_Perplexed", true );

		return true;
	}

	/*bool OnLS1_IannaAggro(Creature& in _Creature)
	{
		if ( m_Reference.GetCreatureByName(m_stgHero_Ianna).GetFaction() == m_iPlayerFaction )
			return true;

		m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "music/characters/ianna_combat");

		return false;
	}*/

	/*bool OnLS1_IannaIsAttacked(Creature& in _Creature)
	{
		if ( _Creature.GetCurrentHP() < PercentOf(_Creature.GetMaxHP(), 30 ) ) // TODO later, dont forget
		{
			_Creature.AllowAttacks(false);
			_Creature.SetAttackable(false);
			m_Reference.GetCreatureByName( m_stgHero_Ianna ).SetFaction( kFactionNeutral );
			DialogTalkTo( m_stgHero_Ianna, m_stgAvatar, m_stgHero_Ianna, "LS1_IannaDefeat" );

			return true;
		}
		return false;
	}*/

	bool OnLS1_TreantAggro ()
	{
		m_Reference.GetCreatureByName( m_stgLS1_crtTreant ).SetFaction(kFactionMob);

		return true;
	}

	bool LS1_OnCutsceneFinished_EscapeFromTreant (const uint8 _uPlayerFaction )
	{
		if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth") != Completed || m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden") != Completed )
			DialogShoutoutTimed( m_stgAvatar, m_stgAvatar, "LS1_SO_AfterFirstTreant", false, 3 );
		AutosaveTimed(1);

		return true;
	}

	bool OnLS1_WentWell(Creature& in _Creature)
	{
		DialogShoutoutWhenReady( m_stgAvatar, m_stgAvatar, "LS1_SO_WentWell", true);
		return true;
	}

	bool OnLS1_IannaAtGCBorder(Creature& in _Creature)
	{
		printNote( "Ianna is at the end " );
		m_Reference.GetCreatureByName(m_stgHero_Ianna).Enable(false);

		// check, if the player already was at GC
		/*if ( m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bQuestFinished_GC) == true || m_Reference.GetHeroParty(m_iPlayerFaction).HasItems(m_stgLS1_HerbPackage, 1))
		{
			
			return true;
		}

		// check
		m_Reference.GetCreatureByName(m_stgHero_Ianna).EnablePOIVisitingBehavior(true);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLS1_ToGrasslandCoast), m_stgAvatar, "LS1_EnterGCBorder");
		*/

		return true;
	}

	bool OnLS1_ToGrasslandCoast(Creature& in _Creature)
	{
		DialogTalkTo( m_stgHero_Ianna, m_stgAvatar, m_stgHero_Ianna, "LS1_GrasslandRoad");
		m_Reference.GetWorld().EnableDialogueTopic( m_stgHero_Ianna, "LS1_GrasslandRoad", true );

		return true;
	}

	// -------------------------------------------------------------------------------------------------------------------
	// --- A R T I C Y  F U N C T I O N S --------------------------------------------------------------------------------

	void ArticyFadeToBlack()
	{
		LS1_PauseBickering( true );
		m_Reference.FadeToBlack(m_iPlayerFaction, uint8(-1), 1000);
	}

	void ArticyFadeFromBlack()
	{
		m_Reference.FadeFromBlack(m_iPlayerFaction, uint8(-1), 1000);
		LS1_PauseBickering( false );
	}

	void ArticyStopVardenDialogue()
	{
		m_Reference.FadeToBlack(m_iPlayerFaction, uint8(-1), 1000);
		m_Reference.SetTimer(TOnTimerEvent(@this.LS1_OnTimer_ContinueVardenDialogue), 2);
	}

	bool LS1_OnTimer_ContinueVardenDialogue()
	{
		m_Reference.FadeFromBlack(m_iPlayerFaction, uint8(-1), 1000);
		DialogShoutoutTimed( m_stgLS1_crtVardenMerilith, m_stgLS1_crtVardenMerilith, "LS1_FirstContact", false, 1 );
		//DialogTalkTo("Varden_Merilith", m_stgAvatar, "Varden_Merilith", "LS1_FirstContact");
		return true;
	}

	void ArticyStopArlanDialogue()
	{
		m_Reference.FadeToBlack(m_iPlayerFaction, uint8(-1), 1000);
		m_Reference.SetTimer(TOnTimerEvent(@this.LS1_OnTimer_ContinueArlanDialogue), 2);
	}

	bool LS1_OnTimer_ContinueArlanDialogue()
	{
		m_Reference.FadeFromBlack(m_iPlayerFaction, uint8(-1), 1000);
		DialogShoutoutTimed( m_stgLS1_crtArlanFinrior, m_stgLS1_crtArlanFinrior, "LS1_FirstContact", false, 1 );
		//DialogTalkTo("Arlan_Finrior", m_stgAvatar, "Arlan_Finrior", "LS1_FirstContact");

		return true;
	}

	void ArticyLS1_FinishedReflect ()
	{
		LS1_PauseBickering ( false );
	}

	void ArticyLS1_HumandLeaderStop ()
	{
		m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader).Stop(m_Reference);
		//PlayerHeroControlDisable();
		//m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader).PlayAnimation(m_Reference, BleedingOutLoop, 0, 50000, true, false);
	}

	void ArticyLS1_IannaSwitchAggro()
	{
		m_Reference.GetCreatureByName(m_stgHero_Ianna).SetFaction( m_iLS1_FactionIanna );
		m_Reference.GetCreatureByName(m_stgHero_Ianna).Stop(m_Reference);
		Creature _stgTmp1 = m_Reference.GetCreatureByName(m_stgLS1_IannaScroundrel_1);
		Creature _stgTmp2 = m_Reference.GetCreatureByName(m_stgLS1_IannaScroundrel_2);
		if ( _stgTmp1.GetCurrentHP() > 0 )
			m_Reference.GetCreatureByName(m_stgHero_Ianna).Attack(m_Reference, _stgTmp1, true);
		else if ( _stgTmp2.GetCurrentHP() > 0 )
		{
			m_Reference.GetCreatureByName(m_stgHero_Ianna).Attack(m_Reference, _stgTmp2, true);
			m_Reference.SetTimer( TOnTimerEvent(@this.OnLS1_TimedSO_IannaAttack), 3 );
		}
	}

	void ArticyLS1_CheckTreantQuest()
	{
		printNote("Checking treant quest: "+m_bLS1_TalkedWithTreant+", talked with Arlan/Varden: "+m_bLS1_ChoosenArlan+"/"+m_bLS1_ChoosenVarden+", and already went to meet Ianna '"+m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q5a_GainElves", "P3_SQ4_Assassings_TalkTo")+"'");
		printNote("var1: " + m_Reference.GetWorld().GetGlobalInt( m_glbCat_Questlog+"LS1_CluesFound", -1) + ", var 2: " + m_Reference.GetWorld().GetGlobalInt(m_glbCat_Questlog+"LS1_MaxCluesFound", -1));
		
		/*if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_IannaDone_Varden"))
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_IannaDone_Varden", Completed );
		else if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_IannaDone"))
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_IannaDone", Completed );
		*/

		if ( m_bLS1_TalkedWithTreant &&  m_Reference.GetWorld().GetGlobalInt(m_glbCat_Questlog+"LS1_CluesFound", 1) == m_Reference.GetWorld().GetGlobalInt(m_glbCat_Questlog+"LS1_MaxCluesFound", 1) )
		{
			if(m_bLS1_ChoosenArlan)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth", Completed );
			if(m_bLS1_ChoosenVarden)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden", Completed );
			
			if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q5a_GainElves", "P3_SQ4_Assassins_TalkTo") == Completed )
			{
				//DialogShoutoutTimed(m_stgAvatar, m_stgAvatar, "LS1_Reflect_Proof", false, 3);
				if (m_bLS1_ChoosenArlan)
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_IannaDone", Completed );
				else if (m_bLS1_ChoosenVarden)
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_IannaDone_Varden", Completed );

				if (m_bLS1_ChoosenArlan)
				{
					//printNote("chose Arlan");
					//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth", Completed);
					m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_FoundTreant", true);
					m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_HumanMissionDone", false);
					m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "6A4C68D0"); // dialogue node in the human dialogue
					m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "786AC91C"); // dialogue node in the human dialogue
				}
				else if (m_bLS1_ChoosenVarden)
				{
					//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden", Completed);
					m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_TreantFound", true);
					m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_HumanMissionDone", false);
					m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtVardenMerilith, "DCA0D4A0"); // dialogue node in the human dialogue
					m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtVardenMerilith, "939344DA"); // dialogue node in the human dialogue
				}
			}
			// m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q5a_GainElves", "P3_SQ4_Assassings_TalkTo") == Completed
			
		}

		if(!m_bGotPoolQuest)
		{
			DialogBantern(m_stgAvatar, m_stgAvatar, "LS1_SO_Scout", m_Reference.GetRandom().GetInteger( 4, 12));
			m_bGotPoolQuest = true;
			for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
			{
				m_Reference.GetBuildingByName(m_arrStgLS1_CorruptedShrines[_iTmp]).SetInteractive( true );
				m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LS1_OnInteract_CorruptedShrine), m_arrStgLS1_CorruptedShrines[_iTmp], m_iPlayerFaction);
			}
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "D24F9A38");
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgAvatar, "08AB23F6");
		}
	}



	// LS1_TreantTalkPos
	// LS1_NoNoZone
	void ArticyLS1_CorruptedAttack ()
	{
		// ToDo: dunno when and when not this is activated. Meh.
		printNote("corrupted attack at the treant. Whoop whoop!");
		m_Reference.PlayCutScene("LS1_EscapeFromTreant");

		// check if there are RTS dudes from Human
		/*if( m_Reference.GetCreaturesFromSpawn( "LS1_NoNoZone_TeleporPos" )[0].Exists() && m_Reference.GetCreaturesFromSpawn( "LS1_NoNoZone_TeleporPos" )[0].GetFaction() == m_iPlayerFaction ) 
		{
			/*array <Creature> _arrCreatures = {};
			for( uint _iTmp = 0; _iTmp < m_arrLS1_ArlanDudesInNoNoZone.length(); _iTmp++ )
				_arrCreatures.insertLast( m_Reference.GetCreatureByName( m_arrLS1_ArlanDudesInNoNoZone[_iTmp] ) );
			
			CreatureGroup _arrCrt ( m_Reference );
			_arrCrt.Set( m_Reference.GetCreaturesFromSpawn( m_stgLS1_spwnHumanArlanGift ) );
			_arrCrt.Teleport( m_Reference.GetLogicObjectByName( "LS1_NoNoZone_TeleporPos" ), false );
		}*/
		
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.LS1_OnCutsceneFinished_EscapeFromTreant), m_iPlayerFaction);
		

		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_TreantCorruptedAttack.length() ; _iTmp++ )
		{
			m_Reference.ActivateSpawn(m_arrStgLS1_TreantCorruptedAttack[_iTmp], true);
			CreatureGroup _arrCrt ( m_Reference );
			_arrCrt.Set( m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_TreantCorruptedAttack[_iTmp] ) );
			_arrCrt.FollowPathSmooth(m_stgLS1_pathCorruptedElves, true, true);
		}

		// Quest stuff
		m_bLS1_TalkedWithTreant = true;
		m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.LS1_CluesFound", m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LS1_CluesFound", -1) + 1);
		
		if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_InvestigateNorth_Varden")) 
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Varden_Treant", Completed );
		else if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_InvestigateNorth")) 	
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvestigateNorth_Treant", Completed );
		
		ArticyLS1_CheckTreantQuest();

		// activating the condition on the treant
		m_Reference.GetCreatureByName( m_stgLS1_crtTreant ).ApplyCondition( m_iLS1_CorruptedCondition, -1);
		m_Reference.GetCreatureByName( m_stgLS1_crtTreant ).SetImmortal(true);


		m_Reference.SetTimer( TOnTimerEvent(@this.OnLS1_TreantAggro), 5);
	}

	void ArticyLS1_HumanLeaderLiliathDebateEnd ()
	{
		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).EnablePOIVisitingBehavior(true);
	}
	/*void ArticyLS1_TreantAggro()
	{
		m_Reference.GetCreatureByName( m_stgLS1_crtTreant ).SetFaction(kFactionMob);
	}*/
	void ArticyLS1_StartCleansePools()
	{
		if(m_bLS1_ChoosenArlan)
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_FollowSeer", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask( "P3_Q5a_GainElves", "P3_Q5_CleansePools", true );
		}
		else if (m_bLS1_ChoosenVarden)
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_Q5a_GainElves", "P3_Q5_FollowSeer_Varden", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P3_Q5a_GainElves", "P3_Q5_CleansePools_Varden", true);
		}
	}

	void ArticyLS1_TalkedWithArlanFinrior ()
	{
		printNote("Player talked with Arlan");
		m_bLS1_TalkedWithArlan = true;
		PlayerHeroControlEnable();
		if(!m_bLS1_TalkedWithVarden)
			DialogShoutout_Special( m_stgAvatar, m_stgAvatar, "LS1_SO_TalkToTheOtherDude", true, false, false, false, false, false, false, 1 );
		
		if ( m_bLS1_TalkedWithArlan && m_bLS1_TalkedWithVarden)
		{
			// pause the bickering while this step is active
			LS1_PauseBickering( true );
			m_Reference.SetTimer( TOnTimerEvent(@this.LS1_CheckDialogueStage_1), 2 );
		}
	}

	void ArticyLS1_TalkedWithVardenMerilith ()
	{
		printNote("Player talked with Varden");
		m_bLS1_TalkedWithVarden = true;
		PlayerHeroControlEnable();
		if(!m_bLS1_TalkedWithArlan)
			DialogShoutout_Special( m_stgAvatar, m_stgAvatar, "LS1_SO_TalkToTheOtherDude", true, false, false, false, false, false, false, 1 );
		
		if ( m_bLS1_TalkedWithArlan && m_bLS1_TalkedWithVarden)
		{
			LS1_PauseBickering( true );
			m_Reference.SetTimer( TOnTimerEvent(@this.LS1_CheckDialogueStage_1), 2 );
		}
	}

	void ArticyLS1_ChoosenArlan()
	{
		printNote("Player CHOOSED with Arlan");
		m_bLS1_ChoosenArlan = true;

		//m_Reference.GetCreatureByName( m_stgLS1_crtArlanFinrior ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLS1_posTalkingHere ).GetId() ), 0, 0, false );
		m_Reference.GetCreatureByName( m_stgLS1_crtArlanFinrior ).FollowPath( m_Reference, m_stgLS1_posTalkingMainSquare_path, false, false, false );
		m_Reference.GetCreatureByName(m_stgLS1_crtVardenMerilith).EnablePOIVisitingBehavior( true );

		LS1_DisbandGroups();
		AutosaveTimed(1);
	}

	void ArticyLS1_ChoosenVarden()
	{
		printNote("Player CHOOSED with Varden");
		m_bLS1_ChoosenVarden = true;

		//m_Reference.GetCreatureByName( m_stgLS1_crtVardenMerilith ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLS1_posTalkingHere ).GetId() ), 0, 0, false );
		m_Reference.GetCreatureByName( m_stgLS1_crtVardenMerilith ).FollowPath( m_Reference, m_stgLS1_posTalkingMainSquare_path, false, false, false );
		m_Reference.GetCreatureByName(m_stgLS1_crtArlanFinrior).EnablePOIVisitingBehavior( true );

		LS1_DisbandGroups();
		AutosaveTimed(1);
	}

	void ArticyLS1_GotSpell_CheckQuest()
	{
		if(m_bLS1_ChoosenArlan)
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_NextStepSeer", Completed );
		else if(m_bLS1_ChoosenVarden)
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_NextStepSeer_Varden", Completed );
	}

	/*void ArticyLS1_ElvenManuscript()
	{
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems(m_stgLS1_itemManuscirpt, 1);
	}*/

	void ArticyLS1_EnteredHumanCamp()
	{
		printNote("ArticyLS1_EnteredHumanCamp");
		m_bLS1_EnterHumanCamp = true;
		DialogShoutout_Special( m_stgAvatar, m_stgAvatar, "LS1_SO_EnterCamp", true, false, false, false, false, false, true, 0 );
		//DialogShoutoutTimed(m_stgAvatar, m_stgAvatar, "LS1_SO_EnterCamp", false, 2 );
	}

	void ArticyLS1_HumanLeader_AfterDialogue()
	{
		printNote("Check, if the player joined Arlan, if yes Human Leader talks to the player");
		m_bLS1_TalkedWithHumanLeader = true;
		if (m_bLS1_ChoosenArlan)
		{
			m_Reference.GetHeroParty(m_iPlayerFaction).Stop();
			DialogTalkTo( m_stgLS1_crtHumanLeader, m_stgAvatar, m_stgLS1_crtHumanLeader, "LS1_ArlanAlliance");

			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_HumanMissionDone", true); // Human dialogue
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_FoundTreant", false);
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "A2EF4534"); // dialogue node in the treant dialogue
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtArlanFinrior, "C1023511"); // dialogue node in the treant dialogue
		}
		else
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_HumanMissionDone", true);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_TreantFound", false);
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtVardenMerilith, "BAF5B261"); // dialogue node in the treant dialogue
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtVardenMerilith, "B74E08E3"); // dialogue node in the treant dialogue

			// add the Arlan Gift Soldiers to the human array, that is later send to the player.
			m_arrStgLS1_HumanSpawns.insertLast( m_stgLS1_spwnHumanArlanGift );
		}

		m_Reference.RegisterHeroPartyEvent(AnyCanSee, TOnHeroPartyEvent(@this.OnLS1_WentWell), m_stgLS1_areaHumanCamp, m_iPlayerFaction);

		EnableWorldMap(false);
	}

	void ArticyLS1_SignOfFriendshipWithArlan()
	{
		printNote("Player gets the Arlan Gift");
		CreatureGroup _crtGrp_Soldiers ( m_Reference );
		_crtGrp_Soldiers.Set( m_Reference.GetCreaturesFromSpawn( m_stgLS1_spwnHumanArlanGift ) );
		_crtGrp_Soldiers.Move( m_Reference.GetLogicObjectByName( m_stgLS1_posArlanGift ), true, false );

		DialogShoutout( m_stgLS1_crtLiliath, m_stgLS1_crtLiliath, "LS1_SO_Pissed", false );
		EnablePOIVisitingBehaviorSpawn( m_stgLS1_spwnHumanArlanGift, false );
		SetFactionSpawn( m_stgLS1_spwnHumanArlanGift, m_iPlayerFaction );

		//
		m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.OnLS1_NoNoZone_Entered), m_Reference.GetCreaturesFromSpawn( m_stgLS1_spwnHumanArlanGift ), true, "LS1_NoNoZone" );
		m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.OnLS1_NoNoZone_Left), m_Reference.GetCreaturesFromSpawn( m_stgLS1_spwnHumanArlanGift ), true, "LS1_NoNoZone" );
	}
	bool OnLS1_NoNoZone_Entered(Creature& in _Creature)
	{
		printNote( "NO NO ZONE:  '"+m_Reference.FindEntityName(_Creature)+"' entered" );
		m_arrLS1_ArlanDudesInNoNoZone.insertLast( m_Reference.FindEntityName(_Creature) );
		return false;
	}
	bool OnLS1_NoNoZone_Left(Creature& in _Creature)
	{
		printNote( "NO NO ZONE:  '"+m_Reference.FindEntityName(_Creature)+"' left" );
		m_arrLS1_ArlanDudesInNoNoZone.removeAt( m_arrLS1_ArlanDudesInNoNoZone.find( m_Reference.FindEntityName(_Creature) ) );
		return false;
	}

	void ArticyLS1_UnlockSideQuest_GrasslandCoast()
	{
		printNote("Unlock sidecontent");
		m_Reference.GetLogicObjectByName( m_stgEntrance_LS_GC ).SetInteractive( true );
		m_Reference.GetWorld().SetMapAccessible( m_iMap_GC, true, m_Reference.GetWorld().GetCurrentMapSetting(m_iMap_GC));
	}

	void ArticyLS1_BackToMainSquare()
	{
		printNote( "Back to the mainsquare" );
		string _stgTmp = "";
		string _stgTmp_GoTo = "";
		if (m_bLS1_ChoosenArlan)
		{
			_stgTmp = m_stgLS1_crtArlanFinrior;
			_stgTmp_GoTo = m_stgLS1_crtVardenMerilith;
		}
		else
		{
			_stgTmp = m_stgLS1_crtVardenMerilith;
			_stgTmp_GoTo = m_stgLS1_crtArlanFinrior;
		}

		//m_Reference.GetCreatureByName( _stgTmp ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLS1_posTalkingMainSquare ).GetId() ), 0, 0, false );
		m_Reference.GetCreatureByName( _stgTmp ).FollowPath( m_Reference, m_stgLS1_posTalkingMainSquare_path, true, false, false );
		m_Reference.RegisterCreatureEventByIndividual(FollowPathFinished, TOnCreatureEvent(@this.OnLC2_EnteredMainSquare_Arlen), _stgTmp, "");

		//m_Reference.GetCreatureByName( _stgTmp ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName( _stgTmp_GoTo ).GetId() ), 20, 10, false );
		//m_Reference.GetCreatureByName( _stgTmp ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLS1_posTalkingHere ).GetId() ), 0, 0, false );

		//m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_EnteredMainSquare_Arlen), _stgTmp, "LS1_MainSquareArea");
		//m_Reference.GetWorld().SetMapAccessible( m_iMap_GC, true, m_Reference.GetWorld().GetCurrentMapSetting(m_iMap_GC));
	}

	void ArticyLS1_GivePackageItem()
	{
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems(m_stgLS1_HerbPackage, 1);
	}
	void ArticyLS1_HumanLeaderFullfilled()
	{
		//m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems(m_stgLS1_HerbPackage, 1);
		Autosave();
	}

	void ArticyLS1_StartRTSGame ()
	{
		printNote("RTS game starts");
		DialogBantern(m_stgAvatar, m_stgAvatar, "LS1_BN_LeafshadeLore", m_Reference.GetRandom().GetInteger( 10*60, 20*60));
		
		// giving the player the sector, and adding the starting ressources
		m_Reference.GetSectorByName( m_stgLS1_RTSstartSector ).SetOwner(m_iPlayerFaction);
		// RTSRessourcesToSector( m_stgLS1_RTSstartSector, m_dictLS1_RTSres_Player );
		m_bRTSActive = true;
		LS1_GetBlueprintsTmpUnlock();
		// setting up the factions
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLS1_FactionElven, Allied);
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLS1_LostRTS), m_stgLS1_RTSstartSector);
		LS1_ChangeAllShrines_changeInspecton();

		// handling the enemy
		printNote( "Bane rebellion starts in "+m_iLS1_BaneRebellion_Timer+" Seconds." );
		m_Reference.SetTimer( TOnTimerEvent(@this.LS1_BaneRebellion_Start), 1 );
		//m_Reference.SetTimer( TOnTimerEvent(@this.LS1_BaneRebellion_Start), m_iLS1_BaneRebellion_Timer );
		
		DialogShoutoutTimed( m_stgAvatar, m_stgAvatar, "LS1_SO_EstablishRoute", false, 5 );
		AutosaveTimed(1);
	}
	bool OnLS1_LostRTS(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		LS1_PlayerLost();
		return true;
	}

	void ArticyLS1_RecieveSpell ()
	{
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.LS1_OnAnyInside_DispellBarrier), "LS1_DispellBarrier", m_iPlayerFaction);
		m_Reference.GetCreatureByName(m_stgAvatar).AddSpell(m_Reference, m_stgLS1_CleanseSpell);
		m_Reference.GetCreatureByName(m_stgAvatar).PrepareSpell(m_Reference, m_stgLS1_CleanseSpell, 0);

		m_Reference.RegisterHeroPartyEvent(AnyInAggroRange, TOnHeroPartyEvent(@this.OnStartTreantFight), m_stgLS1_crtTreant, m_iPlayerFaction);
		m_bLS1_GotCleanseSpell = true;

		PlaySound("Avatar", "events/l1_player_learns_cleansing_spell");
	}

	void ArticyLS1_IannaJoins()
	{
		printNote("Ianna talks with the player and explained herself. She now goes to the GC transition");
		ArticyLS1_CheckTreantQuest();

		m_Reference.GetCreatureByName(m_stgHero_Ianna).FollowPath(m_Reference, "LS1_IannaWalkPath", false, false, false);
		m_Reference.GetCreatureByName(m_stgHero_Ianna).SetAttackable(false);
		m_Reference.GetCreatureByName(m_stgHero_Ianna).AllowAttacks(false);

		
		m_Reference.RegisterHeroPartyEvent(AllCannotSee, TOnHeroPartyEvent(@this.OnLS1_IannaWentAway), m_stgHero_Ianna, m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividual( FollowPathFinished, TOnCreatureEvent(@this.OnLS1_IannaAtGCBorder), m_stgHero_Ianna, "" );
	}
	bool OnLS1_IannaWentAway( Creature& in _Creature )
	{
		DialogShoutout_Special( m_stgAvatar, m_stgAvatar, "LS1_SO_Ianna_Joined", true, false, true, false, false, false, false, 2 );
		return true;
	}

	void ArticyLS1_HumanLeaderJoins()
	{
		printNote("SQ in Grassland Coast was done, Human people join the player.");
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLS1_FactionHumans, Allied );

		// LS1_PosHumansToPlayer
		array <Creature>@ _arrCrt_AllSoldiers = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[0] );
		EnablePOIVisitingBehaviorSpawn( m_arrStgLS1_HumanSpawns[0], false );
		SetFactionSpawn( m_arrStgLS1_HumanSpawns[0], m_iPlayerFaction );

		for ( uint _iTmp = 1; _iTmp < m_arrStgLS1_HumanSpawns.length() ; _iTmp++ )
		{
			EnablePOIVisitingBehaviorSpawn( m_arrStgLS1_HumanSpawns[_iTmp], false );
			SetFactionSpawn( m_arrStgLS1_HumanSpawns[_iTmp], m_iPlayerFaction );

			array <Creature>@ _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[_iTmp] );
			for ( uint _iTmp2 = 2; _iTmp2 < _arrCrt.length() ; _iTmp2++ )
				_arrCrt_AllSoldiers.insertLast( _arrCrt[_iTmp2] );
		}
		m_Reference.GetCreatureByName( m_stgLS1_crtHumanLeader ).EnablePOIVisitingBehavior( false );
		_arrCrt_AllSoldiers.insertLast( m_Reference.GetCreatureByName( m_stgLS1_crtHumanLeader ) );

		CreatureGroup _crtGroup ( m_Reference );
		_crtGroup.Set( _arrCrt_AllSoldiers );
		_crtGroup.Move( m_Reference.GetLogicObjectByName("LS1_PosHumansToPlayer"), false, false, false);

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_SQ3_DefeatBane", "P3_Q5_DefeatBane_TalkToHumanCommander", Completed );
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_SQ3_DefeatBane", "P3_Q5_DefeatBane_InvTriggerHerbsDone", Completed );
		
		DialogShoutout(m_stgAvatar, m_stgAvatar, "LS1_SO_BaneThreat", false);
	}

	void ArticyLS1_HumanLeaderDies()
	{
		printNote("SQ in Grassland Coast was NOT done, Human people ALL GONNA DIE!");
		m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader).SetImmortal(false);
		m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader).Kill();
		m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader).GoTo(m_Reference, m_Reference.GetLogicObjectByName(m_stgLS1_posTalkingMainSquare), 5, 20, false);
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_HumanSpawns.length() ; _iTmp++ )
		{
			SpawnKill(m_arrStgLS1_HumanSpawns[_iTmp]);
		}
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_SQ3_DefeatBane", "P3_Q5_DefeatBane_TalkToHumanCommander", Completed );		
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_SQ3_DefeatBane", "P3_Q5_DefeatBane_InvTriggerHerbsNOTDone", Completed );		
	}

	void ArticyLS1_SendToWaterfall ()
	{
		m_bLS1_IannaAmbush = true;
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5a_GainElves_InvTriggerIannaLine", Completed );
		EnableWorldMap(true);
		//m_Reference.ActivateSpawn( "LS1_Ianna", true );
		//m_Reference.GetCreatureByName(m_stgHero_Ianna).EnablePOIVisitingBehavior(false);
		/*for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_IannaSpawns.length(); _iTmp++)
			m_Reference.ActivateSpawn(m_arrStgLS1_IannaSpawns[_iTmp], true);
		*/
		AutosaveTimed(1);
	}

	// artifact
	bool LS1_OnInteract_Artifactillar(Creature& in _Creature)
	{
		DialogShoutoutWhenReady(m_stgAvatar, m_stgAvatar, "LS1_ShrineTopic", false);
		return false;
	}

	void Articy_ArmorOfResurrection_Correct()
	{
		printNote("Setting pillar 1 to correct state");
		Artifact_ArmorOfResurrection_SetPillar(1, true);

		if(m_Reference.GetWorld().GetGlobalBool("MapVariables.ArmorOfResurrection_Ready"))
		{
			m_Reference.ActivateSpawn("LS_Artifact_ResurrectionArmor_PossibleEnemySpawn", true);
			m_Reference.GetLogicObjectByName("LS_Artifact_ResurrectionArmor_PossibleEnemySpawnFX").Enable(true);
			m_Reference.SetTimer(TOnTimerEvent(@this.LS1_OnTimer_DisableArtifactFX_ArmorOfResurrection), 2);
		}
	}

	bool LS1_OnTimer_DisableArtifactFX_ArmorOfResurrection()
	{
		m_Reference.GetLogicObjectByName("LS_Artifact_ResurrectionArmor_PossibleEnemySpawnFX").Enable(false);
		return true;
	}

	void Articy_ArmorOfResurrection_Incorrect()
	{
		printNote("Setting pillar 1 to incorrect state");
		Artifact_ArmorOfResurrection_SetPillar(1, false);
	}


	// -------------------------------------------------------------------------------------------------------------------
	// --- C U S T O M   F U N C T I O N S -------------------------------------------------------------------------------

	bool LS1_ChangeAllShrines_State1()
	{
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
		{
			//m_Reference.GetBuildingByName( m_arrStgLS1_CorruptedShrines[_iTmp] ).SetInspectionText(60);
			LS1_ChangeShrine_State1(m_arrStgLS1_CorruptedShrines[_iTmp]);
		}
		return true;
	}
	bool LS1_ChangeAllShrines_changeInspecton()
	{
		//for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
			//m_Reference.GetBuildingByName( m_arrStgLS1_CorruptedShrines[_iTmp] ).SetInspectionText(61);
		return true;
	}

	bool LS1_ChangeAllShrines_State2 ()
	{
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
			LS1_ChangeShrine_State2( m_arrStgLS1_CorruptedShrines[_iTmp] );

		return true;
	}
	bool LS1_ChangeAllShrines_State3 ()
	{
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
			LS1_ChangeShrine_State3( m_arrStgLS1_CorruptedShrines[_iTmp] );

		return true;
	}
	bool LS1_ChangeAllShrines_Cleansed ()
	{
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_CorruptedShrines.length() ; _iTmp++ )
			LS1_ChangeShrine_Cleansed( m_arrStgLS1_CorruptedShrines[_iTmp] );

		if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_CleansePools_Varden"))
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_CleansePools_Varden", Completed );
		else if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5a_GainElves","P3_Q5_CleansePools"))
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_CleansePools", Completed );
		
		return true;
	}

	bool LS1_ChangeShrine_State1(string _stgShrine)
	{
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script1, true );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script2, false );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script3, false );

		return true;
	}

	bool LS1_ChangeShrine_State2(string _stgShrine)
	{
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script1, false );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script2, true );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script3, false );

		return true;
	}

	bool LS1_ChangeShrine_State3(string _stgShrine)
	{
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script1, false );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script2, false );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script3, true );

		return true;
	}

	bool LS1_ChangeShrine_Cleansed(string _stgShrine)
	{
		PlaySound("", "events/l1_cleanse_corrupted_magic_pool");
		m_Reference.GetBuildingByName( _stgShrine ).SetInspectionText(62);
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script1, false );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script2, false );
		m_Reference.GetBuildingByName( _stgShrine ).SetCustomState( Script3, false );

		// now enabling and disabling the effects and objects around the temple
		array <string> _arrStgLS1_TMP_FadeOut;
		array <string> _arrStgLS1_TMP_FadeIn;
		if ( _stgShrine == "Shrine_Northeast" )
		{
			_arrStgLS1_TMP_FadeOut = m_arrStgLS1_CorruptedShrine_NE_FadeOut;
			_arrStgLS1_TMP_FadeIn = m_arrStgLS1_CorruptedShrine_NE_FadeIn;
		}
		else if ( _stgShrine == "Shrine_Northwest" )
		{
			_arrStgLS1_TMP_FadeOut = m_arrStgLS1_CorruptedShrine_NW_FadeOut;
			_arrStgLS1_TMP_FadeIn = m_arrStgLS1_CorruptedShrine_NW_FadeIn;
		}
		else if ( _stgShrine == "Shrine_Southeast" )
		{
			_arrStgLS1_TMP_FadeOut = m_arrStgLS1_CorruptedShrine_SE_FadeOut;
			_arrStgLS1_TMP_FadeIn = m_arrStgLS1_CorruptedShrine_SE_FadeIn;
		}
		else if ( _stgShrine == "Shrine_Southwest" )
		{
			_arrStgLS1_TMP_FadeOut = m_arrStgLS1_CorruptedShrine_SW_FadeOut;
			_arrStgLS1_TMP_FadeIn = m_arrStgLS1_CorruptedShrine_SW_FadeIn;
		}

		for ( uint _iTmp = 0; _iTmp < _arrStgLS1_TMP_FadeOut.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( _arrStgLS1_TMP_FadeOut[_iTmp] ).Enable(false);
		}
		for ( uint _iTmp = 0; _iTmp < _arrStgLS1_TMP_FadeIn.length() ; _iTmp++ )
		{
			m_Reference.GetLogicObjectByName( _arrStgLS1_TMP_FadeIn[_iTmp] ).Enable(true);
		}

		return true;
	}

	bool LS1_CheckDialogueStage_1()
	{
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LS1_SO_Reflect", true );
		
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5a_GainElves", "P3_Q5_InvTriggerChooseSeer", Completed);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_JoinArlan", true );
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_JoinVarden", true );

		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtArlanFinrior, "LS1_FirstContact", false );
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtVardenMerilith, "LS1_FirstContact", false );

		return true;
	}

	void LS1_PauseBickering( bool _bEnable )
	{
		if( _bEnable )
		{
			m_Reference.GetCreatureByName(m_stgLS1_crtArlanFinrior).CancelDialogue();
			m_Reference.GetCreatureByName(m_stgLS1_crtVardenMerilith).CancelDialogue();
			m_bLS1_PauseBickering = true;
		}
		else
			m_bLS1_PauseBickering = false;	
	}

	void LS1_DisbandGroups ()
	{
		printNote("Disbanding the groups");
		m_bLS1_StopBickering = true;

		SetPOICategoriesSpawn( m_stgLS1_crtSpwnGroupArlan, array<string>={"LS_LS_Guards_1"});
		SetPOICategoriesSpawn( m_stgLS1_crtSpwnGroupVarden, array<string>={"LS_LS_Guards_2"});
		/*EnablePOIVisitingBehaviorSpawn( m_stgLS1_crtSpwnGroupArlan, true );
		EnablePOIVisitingBehaviorSpawn( m_stgLS1_crtSpwnGroupVarden, true );*/

		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtElf_1, "LS1_FirstContact", false);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtElf_2, "LS1_FirstContact", false);
	}

	void LS1_HumanGuardTalking( string _stgSpawn, string _stgPoint, string _stgCreatureSteppedIn )
	{
		// get the guard from the spawn

		string _stgTmp = "";
		array <Creature>@ _arrCrt_Guards = m_Reference.GetCreaturesFromSpawn( _stgSpawn );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Guards.length() ; _iTmp++ )
			if ( _arrCrt_Guards[_iTmp].GetDescriptionName() == m_stgLS1_crtHumanGuard )
				_stgTmp = m_Reference.FindEntityName(_arrCrt_Guards[_iTmp]);

		// printNote("found "+_stgTmp+", as he is a "+m_stgLS1_crtHumanGuard+" and now going to talk to player");

		// let the hero walk back
		m_Reference.GetCreatureByName(_stgCreatureSteppedIn).Stop( m_Reference );
		m_Reference.GetCreatureByName(_stgCreatureSteppedIn).ForceGoTo( m_Reference, m_Reference.GetLogicObjectByName(_stgPoint), 0, 0, false );

		// check, if the dude is already talking.
		if ( m_Reference.GetCreatureByName(_stgTmp).IsInDialogue() == true )
			return;

		printNote("found "+_stgTmp+", as he is a "+m_stgLS1_crtHumanGuard+" and now going to talk to player");

		// start SO or the dialogue
		// now, let the soldier talk to the wanted
		//if ( _stgCreatureSteppedIn == m_stgAvatar )
		if ( _stgCreatureSteppedIn == m_stgAvatar || DialogCheck_IsGathered( false ) )
		{
			PlayerHeroControlDisable();
			HeroPartyGatherAtAvatar();
			DialogShoutout( _stgTmp, m_stgLS1_crtHumanGuard, "LS1_NoEntry", false );
			//DialogTalkTo( _stgTmp, m_stgAvatar, m_stgLS1_crtHumanGuard, "LS1_NoEntry" );
		}
		else
		{
			DialogShoutout( _stgTmp, m_stgLS1_crtHumanGuard, "LS1_SO_NoEntry", false );			
			DialogCheck_IsGathered( true );
		}

		//else if ( m_Reference.GetCreatureByName( _stgTmp ).IsInDialogue() == false )
			//DialogTalkTo( _stgTmp, _stgCreatureSteppedIn, m_stgLS1_crtHumanGuard, "LS1_SO_NoEntry");

		//m_Reference.GetCreatureByName(_stgCreatureSteppedIn).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName(_stgPoint).GetId() ), 0, 0, false );
		//m_Reference.GetCreatureByName(_stgCreatureSteppedIn).GoTo( m_Reference, m_Reference.GetLogicObjectByName(_stgPoint), 0, 0, false );
	}
	void LS1_HumanGuardTalking_Ianna( string _stgSpawn, string _stgCreatureSteppedIn )
	{
		//m_Reference.GetHeroParty( m_iPlayerFaction ).Stop();
		string _stgTmp = "";
		
		// get the guard from the spawn
		array <Creature>@ _arrCrt_Guards = m_Reference.GetCreaturesFromSpawn( _stgSpawn );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Guards.length() ; _iTmp++ )
			if ( _arrCrt_Guards[_iTmp].GetDescriptionName() == m_stgLS1_crtHumanGuard )
				_stgTmp = m_Reference.FindEntityName(_arrCrt_Guards[_iTmp]);

		printNote("found "+_stgTmp+", as he is a "+m_stgLS1_crtHumanGuard+" and now going to talk to player about Ianna");

		// now, let the soldier talk to the wanted
		if ( _stgCreatureSteppedIn == m_stgAvatar )
		{
			m_Reference.GetCreatureByName( m_stgAvatar ).Stop( m_Reference );
			m_Reference.GetCreatureByName( _stgTmp ).ForceGoTo( m_Reference, m_Reference.GetCreatureByName( m_stgAvatar ), 10, 20, false, false );
			DialogShoutout( _stgTmp, m_stgLS1_crtHumanGuard, "LS1_SendToIanna", false );

			m_Reference.GetHeroParty( m_iPlayerFaction ).Stop();
		}

	}

	bool LS1_BaneRebellion_Start()
	{
		//if( m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_SQ1_GetHerbs") || m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P3_SQ1_GetHerbs") == Completed )
		m_Reference.SetTimer( TOnTimerEvent(@this.LS1_BaneRebellion), 1 );
		return true;
	}
	bool m_bLS1_BaneStarted = false;
	bool LS1_BaneRebellion()
	{	
		if( m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_SQ1_GetHerbs") && m_Reference.GetCreatureByName(m_stgLS1_crtHumanLeader).IsInDialogue() )
			return false;
		
		printNote( "STARTING BANE REBELLION" );
		if( m_bLS1_BaneStarted )
			return true;
		
		m_bLS1_BaneStarted = true;
		m_Reference.GetWorld().EnableDialogueTopic("LS1_BaneSoldier_1", "LS1_FirstContact", false);
		m_Reference.GetWorld().EnableDialogueTopic("LS1_BaneSoldier_2", "LS1_SO_Disgusted", false);
		m_Reference.GetWorld().EnableDialogueTopic("LS1_NortanderSoldier_1", "LS1_FirstContact", false);

		// .. had to change for AI setup, bane faction gets hostile now. Else active heroes didnt work
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLS1_FactionHumansBane, Hostile);
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLS1_FactionHumansBaneRTS, Hostile);
		m_Reference.SetFactionRelation( m_iLS1_FactionElven, m_iLS1_FactionHumansBane, Hostile);
		m_Reference.SetFactionRelation( m_iLS1_FactionElven, m_iLS1_FactionHumansBaneRTS, Hostile);

		// seperate the bane characters form the other
		// change their faction, give them the sector and start RTS
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_BaneSpawns.length() ; _iTmp++ )
			SetFactionSpawn( m_arrStgLS1_BaneSpawns[_iTmp], m_iLS1_FactionHumansBane );

		m_Reference.GetSectorByName( m_stgLS1_HumanSector ).SetOwner(m_iLS1_FactionHumansBaneRTS);
		m_Reference.GetSectorByName( m_stgLS1_HumanSector ).GetMainBuilding().SetFaction(m_iLS1_FactionHumansBaneRTS);
		RTSchangeBuildingFactions( m_stgLS1_HumanSector, m_iLS1_FactionHumansBaneRTS );
		EnemyAI_Start(m_iLS1_FactionHumansBaneRTS);

		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).GoTo(m_Reference, m_Reference.GetLogicObjectByName(m_stgLS1_posLiliathDespawn), 0, 0, false, false);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnDespawnCreature), m_stgLS1_crtLiliath, "LS1_DespawnLiliath");

		// Get the dudes from the normal human faction, and let them walk to the players capital
		// enable all the people form the human leader
		Creature _tmpHumanLeader = m_Reference.GetCreatureByName(  m_stgLS1_crtHumanLeader);
		_tmpHumanLeader.EnablePOIVisitingBehavior(false);
		_tmpHumanLeader.FollowPath( m_Reference, m_stgLS1_pathHumanLeaderFlee, true, true, false );

		if ( m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bQuestFinished_GC) == true )
		{
			_tmpHumanLeader.FollowPath( m_Reference, m_stgLS1_pathHumanLeaderFlee, true, true, false );
		}
		else // case of them
		{
			_tmpHumanLeader.FollowPath( m_Reference, m_stgLS1_pathHumanLeaderFlee, true, true, true );
		}

		int _iDistance = 5;
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_HumanSpawns.length() ; _iTmp++ )
		{
			CreatureGroup _arrTmpCrts ( m_Reference );
			_arrTmpCrts.Set( m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[_iTmp] ) );
			_arrTmpCrts.FollowCreature(_tmpHumanLeader, _iDistance+5, _iDistance, true);
			EnablePOIVisitingBehaviorSpawn( m_arrStgLS1_HumanSpawns[_iTmp], false );
			SetPOICategoriesSpawn( m_arrStgLS1_HumanSpawns[_iTmp], array<string>={"LS1_HSoldiers_Fleed"});
			SpawnAttackable(m_arrStgLS1_HumanSpawns[_iTmp], false);
			_iDistance += 10;

			if ( m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bQuestFinished_GC) == true )
			{
				array <Creature>@ _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[_iTmp] );
				for ( uint _iTmp1 = 0; _iTmp1 < _arrCrt.length(); _iTmp1++ )
					_arrCrt[_iTmp1].Heal(100);
			}
			else
			{
				array <Creature>@ _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[_iTmp] );
				for ( uint _iTmp1 = 0; _iTmp1 < _arrCrt.length(); _iTmp1++ )
				{
					printNote("damage soldiers "+ _arrCrt[_iTmp1].GetDescriptionName());
					_arrCrt[_iTmp1].ApplyCondition (6, 120, 2);
					m_Reference.SetTimer(TOnTimerEvent(@this.LS1_OnTimer_SetAttackableHumans), 20);
				}
			}
		}

		m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P3_SQ3_DefeatBane", true );
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState( "P3_SQ3_DefeatBane", "P3_Q5_DefeatBane_InvTriggerTalkToHumanLeader", Completed );		
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask( "P3_SQ3_DefeatBane", "P3_Q5_DefeatBane_InvTriggerTalkToHumanLeader", true );		
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtHumanLeader, "LS1_BaneTakeOver", true);
		
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P3_SQ1_GetHerbs") != Completed )
			m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "P3_SQ1_GetHerbs", Failed );
		
		return true;
	}

	bool LS1_OnTimer_SetAttackableHumans()
	{
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_HumanSpawns.length() ; _iTmp++ )
		{
			SpawnAttackable(m_arrStgLS1_HumanSpawns[_iTmp], true);
		}
		return true;
	}

	void LS1_CheckPoolSector (uint _iPreviousOwner, uint _iNewOwner )
	{
		if ( _iNewOwner == m_iLS1_FactionHumansBaneRTS ) // enemy gained a pool sector
		{
			m_iShrineSectorInEnemyPossession++;
			printNote("Pool sector was TAKEN by enemy RTS, now they have "+m_iShrineSectorInEnemyPossession+" in total.");
			if (m_iShrineSectorInEnemyPossession == 4)
				LS1_PlayerLost();
		}
		else if ( _iPreviousOwner == m_iLS1_FactionHumansBaneRTS ) // enemy lost a pool sector
		{
			m_iShrineSectorInEnemyPossession--;
			printNote("Pool sector was LOST by enemy RTS, now they have "+m_iShrineSectorInEnemyPossession+" in total.");
		}
	}

	void LS1_GrasslandCoast_Finished()
	{
		// m_stgGlobal_bQuestFinished_GC
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLS1_crtHumanLeader, "LS1_HerbsGathered", true);

		// do the appropriate things for this map
		m_Reference.GetWorld().BlockDialogueTopicNode(m_stgLS1_crtHumanLeader, "14FB8BA6"); // Block the dying part
		m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgLS1_crtHumanLeader, "BDBEA4D9"); // Unblock the part where he lives and joins the player

		m_Reference.GetWorld().SetGlobalBool(m_stgGlobal_bQuestFinished_GC, true);

		m_bHerbsGathered = true;
	}

	void LS1_PlayerLost()
	{
		if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState( "P3_Q5a_GainElves", "P3_Q5_CureTreant" ) != Completed )
			m_Reference.LoseGame( m_iPlayerFaction );
	}

	void LS1_GetBlueprintsTmpUnlock()
	{
		LS1_GetBlueprintsTmpUnlock_Add("BP_ElvenRace");

		// Elven T1/T2 - Buildings
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Barracks");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Capital_I");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Capital_II");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Expansion_0");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Expansion_I");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Expansion_I_Tower");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Expansion_II");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Expansion_II_Tower");

		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Farm");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_FishingCabin");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_HuntingCabin");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_IronMine");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_IronSmeltery");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Stonecutter");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Woodcutter");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_WoodenTower_I");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_WoodenTower_II");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Arcanesmith");

		// Elven T1/T2 - Units
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Novice");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Ranger");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Guardian");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Pathfinder");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Wanderer");
		LS1_GetBlueprintsTmpUnlock_Add("BP_E_Warder");
	}

	void LS1_GetBlueprintsTmpUnlock_Add( string _stgBpUnlock)
	{
		// Permanent
		m_Reference.GetWorld().UnlockBlueprint(_stgBpUnlock, false);
	}

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

	void CutsceneLS1_StartCutscene_Leafshade()
	{
		printCutscene("going to start: OUTRO OF LEAFSHADE");
		HeroPartyStopDialogues();
		m_Reference.PlayCutScene("LS1_EnterLeafshade");
	}

	void CutsceneLS1_StartCutscene_Outro()
	{
		printCutscene("going to start: OUTRO OF LEAFSHADE");
		TransferRTS( m_iPlayerFaction, m_iLS1_FactionElven );

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_SQ3_DefeatBane", "P3_Q5_DefeatBane", Failed );
		m_Reference.PlayCutScene("LS1_MapOutro");
	}

	void Cutscene_EnableBarrier( )
	{
		m_Reference.EnableGroup( "LS_TreantBarrier", true );
		m_Reference.BlockNavMesh( "LS_TreantBarrier_PhysicBlocker", true );
	}

	void Cutscene_DisableBarrier( )
	{
		m_Reference.EnableGroup( "LS_TreantBarrier", false );
		m_Reference.BlockNavMesh( "LS_TreantBarrier_PhysicBlocker", false );
	}

	void Cutscene_EnableEffect( )
	{
		m_Reference.GetLogicObjectByName( "LS_TreantBarrier_Effect" ).Enable( true );
	}

	void Cutscene_DisableEffect( )
	{
		m_Reference.GetLogicObjectByName( "LS_TreantBarrier_Effect" ).Enable( false );
	}
	// -------------------------------------------------------------------------------------------------------------------
	// -------------------------------------------------------------------------------------------------------------------

	void LS1_PreE3_Cheat()
	{
		// give the herbpackage
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems(m_stgLS1_HerbPackage, 1);
		LS1_GrasslandCoast_Finished();

		m_Reference.GetCreatureByName( m_stgLS1_crtLiliath ).EnablePOIVisitingBehavior(true);

		// getting ianna
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_IannaSpawns.length(); _iTmp++)
			m_Reference.ActivateSpawn(m_arrStgLS1_IannaSpawns[_iTmp], true);
		m_Reference.GetCreatureByName(m_stgHero_Ianna).EnablePOIVisitingBehavior(false);
		m_iLS1_ScoundrelKilled = 10;

		m_Reference.GetCreatureByName(m_stgLS1_IannaScroundrel_1).Kill();
		m_Reference.GetCreatureByName(m_stgLS1_IannaScroundrel_2).Kill();
		//IannaPresetAvatarPreEvent(m_stgHero_Ianna, 11);
		HeroPartyJoin(m_stgHero_Ianna);
		//IannaPresetAvatarPreEvent(m_stgHero_Ianna, m_iPartyLevel_Visit_0);

		m_bLS1_EnterHumanCamp = true;
		m_bLS1_TalkedWithHumanLeader = true;
		m_bLS1_IannaAmbush = true;

		m_arrStgLS1_HumanSpawns.insertLast( m_stgLS1_spwnHumanArlanGift );
		for ( uint _iTmp = 0; _iTmp < m_arrStgLS1_HumanSpawns.length() ; _iTmp++ )
		{
			array <Creature>@ _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStgLS1_HumanSpawns[_iTmp] );
			for ( uint _iTmp1 = 0; _iTmp1 < _arrCrt.length(); _iTmp1++ )
				_arrCrt[_iTmp1].Damage( Pierce, m_Reference.GetRandom().GetInteger(5, 100) );

		}
	}
}
