// ------------------------------------------------------------------------------------------------------------------------------------
// Loyalist Camp

// 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.352 - 07.12.2017 - 22:39";
	//string m_stgVersion = "0.351 - 07.12.2017 - 16:46";
	//string m_stgVersion = "0.348 - 29.11.2017 - 19:15";
	//string m_stgVersion = "0.347 - 28.11.2017 - 18:04";
	

	// -------------------------------------------------------------------------------------------------------------------
	// --- G E N E R A L  V A R I A B L E S --------------------------------------------------------------------------------------------
	// variable for initializing the hero party to a special level.
	// this is later going to be ignoring, this is only for the current level testing, etc.

	string m_stgEntrance_FH_LC = 					"MapTransitions_FH_LC";
	string m_stgEntrance_LC_EL = 					"MapTransitions_LC_EL";

	//string m_stgGlobal_iSavedVillagers = 			"MapVariables.FH_CountVillagersSaved";
	string m_stgGlobal_bNortanderFactionDefeated =  "MapVariables.LC_NortanderDefeated";
	string m_stgGlobal_iSavedVillagers = 			"MapVariables.LC_CountVillagersSaved";
	string m_stgGlobal_iVillagersDied = 			"MapVariables.LC_CountVillagersWhoDied";
	string m_stgGlobal_iNortanderSoldeiers = 		"MapVariables.LC_CountNortanderSoldiers";
	string m_stgGlobal_bRefugeesSaved = 			"MapVariables.LC_RefugeesSaved";
	string m_stgGlobal_iRefugeesDied = 				"MapVariables.LC_RefugeesDied";

	string m_stgGlobal_bLostTraderSaved = 			"MapVariables.FH_LostTraderInFarlornsHope";

	string m_stgLC_crtSentenza = 					"Sentenza_Noria";

	bool m_bLC2_RTSfinished = 						false;
	
// --- V E R S I O N  0  -----------------------------------------------------------------------------------------------------------
	string m_stgLC1_crtCrowdDummyNPC =				"Crowd_NPC_Small";
	string m_stgEntrance_LC_LCC1 = 					"MapTransitions_LC_LCC1";

	array <string> m_arrLC1_GuardsSpawns = 			{ "LC1_GuardsOutpost_0", "LC1_GuardsOutpost_1", "LC1_GuardsOutpost_2", "LC1_GuardsOutpost_3", "LC1_GuardsOutpost_4" };
	uint m_iOutpostGuardSpawns =					5;
	uint m_iRuinGuardSpawns = 						7;
	uint m_iKilledGuardsCounter = 					0;

	bool m_bAssignedWorkersHunter =					false;
	bool m_bAssignedWorkersFisher =					false;
	bool m_bAssignedWorkersWoodcutter =				false;

	bool m_bKilledRuinGuards01 = 					false;
	bool m_bKilledRuinGuards02 = 					false;

	bool m_bBarricadeDestroyable = 					false;

	bool m_bBarracksComplete =						false;

	bool m_bArsonistsBuilt = 						false;
	bool m_bRecruitsBuilt = 						false;

	bool m_bLC1_lootedForTheFirstTime = 			false;
	bool m_bLC1_nearCampPlayed = 					false;
	bool m_bLC1_reachedCampPlayed = 				false;


// --- V E R S I O N  1  -----------------------------------------------------------------------------------------------------------
	uint8 m_iLC2_FactionFHRefugees = 			1;
	uint8 m_iLC2_FactionUtran = 				3;
	uint8 m_iLC2_FactionBorderRefugees = 		4;
	uint8 m_iLC2_FactionNortanderArmy = 		5;
	uint8 m_iLC2_FactionNortanderAssault =		6;
	uint8 m_iLC2_FactionPurity = 				7;
	uint8 m_iLC2_FactionIskanderLoyalists = 	8;

	string m_stgLC2_crtClaraFarlorn = 			"Clara_Farlorn";
	string m_stgLC2_crtBertrandCarpel = 		"Bertrand_Carpel";
	string m_stgLC2_crtLoyalistCommander = 		"LC2_Loyalist_Commander";
	string m_stgLC2_crtLoyalistLeader = 		"LC2_Loyalist_Leader";

	string m_stgLC2_tmpSentenzaCutscene = 		"Sentenza_Arrives";

	bool m_bLC2_NortanderDeafeated = 			false;
	bool m_bLC2_CaravanWentToNextMap = 			false;
	bool m_bLC2_stateCaravanArrived = 			false;

	//
	string m_stgLC2_bldgNeutral_Iskander = 		"LC2_Neutral_IskanderWaves";
 	string m_stgLC2_bldgNeutral_Nortander = 	"LC2_Neutral_NortanderWaves";
 	string m_stgLC2_pathNeutralAttack = 		"LC2_Path_NeutralAttack";

	// Villagers and Militia
	array <string> m_arrStg_IskanderMilitiaSpawns = { "LC2_LoyalistsHelp" };
	array <string> m_arrStg_FHMilitiaSpawns = 	{ "FH2_CapturedMilitia_1", "FH2_CapturedMilitia_2" };
	array <string> m_arrStg_FHVillagerSpawns = 	{ "FH_Villagers_01", "FH_Villagers_02", "FH_Villagers_03", "FH_Villagers_04", "FH_Villagers_Traders", "FH2_Carriages" };
	///{ "FH2_Villagers_01", "FH2_Villagers_02", "FH2_VillageLeaders_LostTrader", "FH2_Carriages" };
	//array <string> m_arrStgFH2_VillagerSpawns = { "FH_Villagers_01", "FH_Villagers_02", "FH_Villagers_03", "FH_Villagers_04", "FH_Villagers_Traders" };

	string m_stgLC2_crtLoyalistSoldier_1 = 		"LC2_NPC_LoyalistSoldier_1";
	string m_stgLC2_crtLoyalistSoldier_2 = 		"LC2_NPC_LoyalistSoldier_2";
	string m_stgLC2_crtLoyalistSoldier_3 = 		"LC2_NPC_LoyalistSoldier_3";
	string m_stgLC2_crtLoyalistCampGuard = 		"LC2_LoyalistCampGuard";
	string m_stgLC2_crtLoyalistScout =			"LC2_IskanderScout";

	string m_stgLC2_crtNortanderGuard_1 = 		"LC2_NortanderGuard_1";
	string m_stgLC2_crtNortanderGuard_2 = 		"LC2_NortanderGuard_2";
	string m_stgLC2_crtNortanderSoldier_1 = 	"LC2_NPC_NortanderSoldier_1";
	string m_stgLC2_crtNortanderSoldier_2 = 	"LC2_NPC_NortanderSoldier_2";
	string m_stgLC2_crtNortanderSoldier_3 = 	"LC2_NPC_NortanderSoldier_3";
	string m_stgLC2_crtNortanderSoldier_4 = 	"LC2_NPC_NortanderSoldier_4";

	string m_stgLC2_crtUtranSoldier_1 = 		"LC2_UtranSoldier_1";
	string m_stgLC2_crtUtranRefugeeMan = 		"LC2_RefugeeMan";

	//bool m_bLC2_EnteredLoyalistCamp = 			false;
	bool m_bLC2_EnteredNortanderCamp = 			false;
	string m_stgLC2_ItemMedicine = 				"LC2_Medicine";
	string m_stgLC2_ItemSecretLetter =  		"LC2_SecretLetter";

	string m_stgCrtLC2_LostTrader = 			"FH2_LostTrader";

	bool m_bLC2_AmbushHappened = 				false;
	bool m_bLC2_NearRuinsTriggered = 			false;

	bool m_bLC2_ClaraAmbush = 					false;

	// Meeting with Bertrand Carpel
	string m_stgLC2_PosBertrandCarpel_Meeting = "LC2_PosBertrandCarpel_Meeting";
	string m_stgLC2_PosSentenza_Ambush =		"LC2_PosSentenza_Ambush";
	string m_stgLC2_PosPurityCamp = 			"LC2_PosPurityCamp";
	string m_stgLC2_PosIskanderCamp = 			"LC2_PosIskanderCamp";
	string m_stgLC2_PathSentenza_Fleeing = 		"LC2_PathSentenza_Fleeing";

	string m_stgLC2_SpwnLoyalistAmbush = 		"LC2_LoyalistsHelp";
	string m_stgLC2_PathLoyalistAmbush = 		"Path_LoyalistsHelp";
	string m_stgLC2_SpwnSentenzaAmbush = 		"LC2_SentenzaAmbush";
	string m_stgLC2_TrgSmallCmap_Ent_1 = 		"LC2_TrgAmbush";

	// RTS
	//int m_iStartingPlanks = 					30; // function that adds those commented out, using levelbase_gameplay now
	//int m_iStartingFood = 						20;
	string m_stgLC2_SectLoyalistCamp_Center = 	"LoyalistIskander_Outpost";
	string m_stgLC2_SectLoyalistCamp = 			"Sector_Player_LoyalistCamp_01";
	string m_stgLC2_SectNortanderCamp = 		"Sector_Enemy_NortanderCamp_14";
	string m_stgLC2_SectFHhideout = 			"Sector_Player_Hideout_02";

	// Secure the road
	array <string> m_arrStgLC2_SectorsRouteOne = { "Sector_13", "Sector_09", "Sector_08", "Sector_05", "Sector_04", "Sector_01" };
	array <string> m_arrStgLC2_SectorsRouteTwo = { "Sector_15", "Sector_11", "Sector_07", "Sector_03", "Sector_04",  "Sector_01" };
	uint m_iLC2_SectorRouteOne_freed = 			0;
	uint m_iLC2_SectorRouteTwo_freed = 			0;
	string m_stgLC2_PathSectorRouteOne = 		"LC2_CaravanRouteOne";
	string m_stgLC2_PathSectorRouteTwo = 		"LC2_CaravanRouteTwo";
	string m_stgLC2_StartedOnRoute = 			"";
	bool m_bLC2_CaravanStarted = 				false;
	string m_stgSendVillagerTo = 				"";
	int m_iSendVillagerGroup = 					0;


	// Caravan Escape
	string m_stgLC2_TrgCaravanEscape =  		"LC2_CaravanEscape";
	string m_stgLC2_SpwnAssault_01 = 			"LC2_CaravanAssault_01";
	string m_stgLC2_SpwnAssault_02 = 			"LC2_CaravanAssault_02";
	string m_stgLC2_SpwnAssault_03 = 			"LC2_CaravanAssault_03";
	string m_stgLC2_PathSectorRouteOneAssault =	"LC2_CaravanAssaultOne";
	string m_stgLC2_PathSectorRouteTwoAssault =	"LC2_CaravanAssaultTwo";
	uint m_iLC2_CaravanFollow_gotoMin = 		10;
	uint m_iLC2_CaravanFollow_gotoMax = 		20;
	int m_iLC2_AssaultTime_01 = 				10*60;
	int m_iLC2_AssaultTime_02 = 				20*60;
	string m_stgLC2_AssaultSpawn = 				"";
	string m_stgLC2_RouteAssault = 				"";
	int m_iLC2_VillagersDied = 					0;
	int m_iLC2_VillagersDied_Max = 				10;

	// Caravan is followed by Nortander Army
	uint m_iLC2_NortanderFollowAssault =  		5*60;
	uint m_iLC2_NortanderFollowAssault_SO1 =  	2*60;
	uint m_iLC2_NortanderFollowAssault_SO2 =  	4*60;
	uint m_iLC2_NortanderFollowSoldiers = 		0;
	uint m_iLC2_NortanderFollowSoldiers_Max = 	10;
	string m_stgLC2_bldgDescription = 			"S_LC2_NortanderChaseWaves_01";
	string m_stgLC2_bldgNortanderChaseWave = 	"LC2_NortanderChaseWaves";
	string m_stgLC2_pathNortanderChase = 		"LC2_NortanderChaseWaves_Path";

	// Border Refugees
	array <string> m_arrStg_BorderRefugees = 		{ "LC2_Refugees_01", "LC2_Refugees_02", "LC2_Refugees_03" };
	string m_stgLC2_BldgNortanderAttackRefugees = 	"LC2_NortanderRefugeesWaves_01";
	string m_stgLC2_PathgNortanderAttackRefugees = 	"LC2_PathNortanderRefugeesWaves_01";
	string m_stgLC2_objFortEntrangeDoor = 			"LC2_FortEntranceDoor";
	int m_iLC2_RefugeesDied = 						0;
	int m_iLC2_RefugeesTotal = 						0; // is going to check automatically how many there are at the start of the map

	// --- REVISIT ---
	// purity
	array <string> m_arrStg_PuritySpawns = 		{ "LC2_PurityCamp_Wounded", "LC2_PurityCamp"};
	string m_stgPurityClutter = 				"LC2_RevPur_clutter_";
	int m_iPurityClutter = 						96;
	//array <string> m_arrStg_PurityObjects = 	{ "LC2_RevPur_clutter_1", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };

	// Bandits
	array <string> m_arrStg_Bandits = 			{ "LC2_RevisitBandits_01", "LC2_RevisitBandits_02", "LC2_RevisitBandits_03" };
	array <string> m_arrStg_BanditsObjects = 	{ "LC2_RevBan_tent_1", "LC2_RevBan_tent_2", "LC2_RevBan_tent_3", "LC2_RevBan_tent_4", "LC2_RevBan_tent_5",
	"LC2_RevBan_Clutter_1", "LC2_RevBan_Clutter_2", "LC2_RevBan_Clutter_3", "LC2_RevBan_Clutter_4", "LC2_RevBan_Clutter_5", "LC2_RevBan_Clutter_6",
	"LC2_RevBan_Clutter_7", "LC2_RevBan_Clutter_8", "LC2_RevBan_Clutter_9", "LC2_RevBan_Clutter_10",
	"LC2_RevBan_Cage_1", "LC2_RevBan_CageCorpse_1", "LC2_RevBan_Fireplace" };

	// Nortander
	array <string> m_arrStg_NortanderRevisit = 	{ "LC2_NortanderPatrol_01", "LC2_NortanderPatrol_02", "LC2_NortanderGroup_01", "LC2_NortanderGroup_02" };

	// Utran border refugees
	array <string> m_arrStg_BorderRefugeesObjects_toVanish = { "LC2_RevRefugeesDis_Tent_1", "" };
	array <string> m_arrStg_BorderRefugeesObjects_toAppear = { "LC2_RevRefugeesApp_Smoke_1", "" };

	// Utran refugee line
	array <string> m_arrLC2_UtranVillagers_CurrentLine(5);
	string m_stgLC2_UtranVillagersPositions = "LC2_UGuard_Line_0";
	uint m_iLC2_UtranRefugees_Timer_min = 15;
	uint m_iLC2_UtranRefugees_Timer_max = 30;
	dictionary m_dictLC2_UtranLine;


	//Thorsten Variables
	string m_stgLC2_SpawnBearAmbush = "LC2_thw_BearAmbush";
	string m_stgLC2_SpawnVillagerBandits1 = "LC2_thw_BanditSpawnVillagers1";
	string m_stgLC2_SpawnVillagerBandits2 = "LC2_thw_BanditSpawnVillagers2";
	string m_stgLC2_BearTrigger = "LC2_thw_BearAmbushTrigger";
	bool m_bLC2_BearSwitch = false;

// --- V E R S I O N  2  -----------------------------------------------------------------------------------------------------------
	//  *Trigger*

	//  *Switch*
	string m_stgLC3_Switch_TunnelEntry_01 = 				"LC3_Switch_TunnelEntry01";
	string m_stgLC3_Switch_TunnelEntry_02 = 				"LC3_Switch_TunnelEntry02";

	// *Creatures*
	string m_stgLC3_Crt_Angar =								"Angar_Arandir";
	array<uint> m_arrLC3_Crt_SpawnedUtran_Units_01 = 		{};
	array<uint> m_arrLC3_Crt_SpawnedUtran_Units_02 = 		{};
	array<uint> m_arrLC3_Crt_SpawnedUtran_Units_03 = 		{};

	array<uint> m_arrLC3_Crt_AttackingPlayerBase =			{};

	array<uint> m_arrLC3_Crt_FleeingPurity01 = 				{};
	array<uint> m_arrLC3_Crt_FleeingPurity02 = 				{};

	array<string> m_arrLC3_Stg_PurityPatrolsSpawns = 		{"LC3_SP_PurityPatrol_01", "LC3_SP_PurityPatrol_02", "LC3_SP_PurityPatrol_03", "LC3_SP_PurityPatrol_04", "LC3_SP_PurityPatrol_05"};
	array<string> m_arrLC3_Stg_GateGuardSpawns = 			{"LC3_SP_PurityGate01Guards_01", "LC3_SP_PurityGate01Guards_02", "LC3_SP_PurityGate02Guards_01", "LC3_SP_PurityGate02Guards_02", "LC3_SP_PurityGate03Guards_01", "LC3_SP_PurityGate03Guards_02"};

	// *Buildings*
	string m_stgLC3_Bldg_PurityWaveSpawn01 = 				"LC3_PurityWaveSpawn_01";
	string m_stgLC3_Bldg_UtranSiegeSpawn01 = 				"LC3_UtranSiegeSpawn_01";
	array <string> m_arrStgLC3_Bldg_PuritySiegeSpawns = 	{"LC3_PuritySiegeSpawn_01", "LC3_PuritySiegeSpawn_02", "LC3_PuritySiegeSpawn_03"};

	// *Sectors*
	string m_stgLC3_Sector_Playerbase = 					"Sector_13";
	string m_stgLC3_Sector_PurityCastle = 					"Sector_Enemy_NortanderCamp_14";

	//  *Bool*
	bool m_bLC3_SO_AngarAttack = 							false;
	bool m_bLC3_FoundTunnel = 								false;
	bool m_bLC3_UsedTunnel = 								false;
	bool m_bLC3_AllBehindWall = 							false;
	bool m_bLC3_SO_BehindWallStarted = 						false;
	bool m_bLC3_MyrahFound =		 						false;
	bool m_bLC3_RuneGuardsAggro01 = 						false;
	bool m_bLC3_RuneGuardsAggro02 = 						false;
	bool m_bLC3_RefugeeGone = 								false;
	bool m_bLC3_RTSOver = 									false;
	bool m_bLC3_BridgeRepaired = 							false;
	bool m_bLC3_FoundRefugee = 								false;
	bool m_bLC3_GateOpen = 									false;
	//  *Int*
		//Factions
	uint m_iLC3_Faction_PlayerAllied_AI =					1; // TODO: remove / change neutral faction from map, asap
	uint m_iLC3_Faction_Purity =							4;
	uint m_iLC3_Faction_Purity_AI =							5;
	uint m_iLC3_Faction_Utran_AI =							6;

		//Timer
	uint m_iLC3_Timer_FortifyTime = 						1200;  //10min = 600 //20min = 1200
	uint m_iLC3_TimerFunc_FortifyCountdown = 				0;

		//Stuff
	uint m_iLC3_PurityWaves =								0;
	uint m_iLC3_PuritySiegeWaves = 							0;
	uint m_iLC3_UtranSiegeWaves = 							0;
	uint m_iLC3_UtranSiegeOutsideGate_01 = 					0;
	uint m_iLC3_UtranSiegeOutsideGate_02 = 					0;
	uint m_iLC3_UtranSiegeOutsideGate_03 = 					0;

	array<string> m_arrStgLC3_SiegeCampLights = 			{ "LC3_Light_SiegeCamp_01", "LC3_Light_SiegeCamp_02", "LC3_Light_SiegeCamp_03" };

	//Testing for Thorsten
	//This array dynamically stores heroes that will be automatically revived via 'ReviveTalisman'
//	array<string> m_arrStg_RevivingTalismanHeroes = 		{};
//	uint m_iTimer_ReviveTalisman = 							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() ) +".");
		
		// disable the Hero Intro for the first Version of this map.
		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 0 ) // First setting
			m_bIntro = false;

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

		// Calling the final functions
		InitEvents(); // register all neutral events
		InitCommon(); // start all neutral script lines


		SetHeroParty(0);

		// setting specific calls
		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 0 ) // First setting
		{
			InitEvents_0(); // (setting 0)
			InitCommon_0(); // (setting 0)
		}
		else if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 1 ) // Second setting
		{
			InitEvents_1(); // (setting 1)
			InitCommon_1(); // (setting 1)
		}
		else if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 2 ) // Third setting
		{
			InitEvents_2(); // (setting 2)
			InitCommon_2(); // (setting 2)
		}
	}

	// 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("LC1_DungeonKey", 1) &&
			m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P1_Q2_DefeatTraitors", "P1_Q2_LootUndeadGuardian") != Completed)
		{
			OnLootedKey(0, "LC1_DungeonKey", 1);
		}

		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 1 ) // Second setting
		{
			OnCheck_1();
		}
		else if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 2 ) // Third setting
		{
			OnCheck_2();	
		}
		
	}

	// 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();
	}

// -------------------------------------------------------------------------------------------------------------------
// --- C H E A T  F U N C T I O N S ----------------------------------------------------------------------------------

	void CheatLC2_State_01 ()
	{
		printCheat("");
		// TEST
		/*
		// State 1
		m_Reference.GetWorld().SetGlobalBool(m_stgGlobal_bNortanderFactionDefeated, true);
		m_Reference.GetWorld().SetGlobalBool( m_stgGlobal_bRefugeesSaved, true);

		// State 2
		m_Reference.GetWorld().SetGlobalBool(m_stgGlobal_bNortanderFactionDefeated, true);
		m_Reference.GetWorld().SetGlobalBool( m_stgGlobal_bRefugeesSaved, false);

		// State 3
		m_Reference.GetWorld().SetGlobalBool(m_stgGlobal_bNortanderFactionDefeated, false);
		m_Reference.GetWorld().SetGlobalBool( m_stgGlobal_bRefugeesSaved, false);

		LC2SetRevisitState();
		*/
	}

	void CheatLC2_FHConnection ()
	{
		printCheat("");
		// BEGIN TEMP
		// LC2_MeetBertrandCarpel();
		// m_Reference.SetTimer( TOnTimerEvent(@this.LC2_StartCaravan), 10 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Pillager", 6 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Recruit", 5 );
		/*m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"FH2_Villager_Leader", 4 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"FH2_VillagerCarriage", 3 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Female_FatSkirt_01", 5 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Female_FatSkirt_02", 3 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Female_FatSkirt_03", 1 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Female_Skirt_01", 0 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Female_Skirt_02", 2 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Female_Skirt_03", 4 );
		m_Reference.GetWorld().SetGlobalInt(m_glbCat_FH_savedVillagers+"."+"NPC_Male_FatBrown", 6 );*/
		// *** END TEMP
	}

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

	void InitEvents ()
	{
		//m_Reference.RegisterHeroPartyEvent("PartyEnteredArea", TOnHeroPartyEvent(@this.OnTestTriggerbox), "GC2016_TestTriggerbox", 0);
		if( m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChest").Exists() )
		{
			m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC2_LC3_OnInteract_DefilersBaneLoot), "LC2_LC3_Artifact_DefilersBane_LootChest", m_iPlayerFaction);
		}

		if( m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial").Exists() )
		{
			m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnInteract_Memorial), "LC_ArmorOfStatusImmunity_Q4_Memorial", m_iPlayerFaction);
		}
		
	}



// for the first map setting
	void InitEvents_0 ()
	{
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLC1_InteractBarrier), "LC1_Barricade", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC1_BarricadeShoutoutArsonists), "LC1_BarricadeArea", m_iPlayerFaction);
		m_Reference.RegisterBuildingEventByIndividual(Destroyed, TOnBuildingEvent(@this.OnDestroyedBarricade), "LC1_Barricade");

		//m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnInteractGuard), "LC1_Outpost_Guard_01", m_iPlayerFaction);

		// Note by Marc: Use the HeropartyEvent 'Killed'
		//m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnLC1_HeroPartyMemberKilled), m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers(), false, "");
		m_Reference.RegisterHeroPartyEvent( Killed, TOnHeroPartyEvent(@this.OnLC1_HeroPartyMemberKilled), "LC1_Barricade", m_iPlayerFaction);
		for ( uint _iTmp = 0 ; _iTmp < 9; _iTmp++)
			m_Reference.RegisterHeroPartyEvent( Loot, TOnHeroPartyEvent(@this.OnLC1_HeroPartyIsLooting), "LC1_HiddenLoot_"+_iTmp, m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnTriggerWolfAttack), "LC1_TriggerWolfAttack", m_iPlayerFaction);
		array <string> _arrTmp_Guards = GetCreaturesFromSpawns_stg( m_arrLC1_GuardsSpawns );
		for ( uint _iTmp = 0; _iTmp < _arrTmp_Guards.length() ; _iTmp++ )
			m_Reference.RegisterHeroPartyEvent(AnyInAggroRange, TOnHeroPartyEvent(@this.OnNearCamp), _arrTmp_Guards[_iTmp], m_iPlayerFaction);
			//m_Reference.RegisterHeroPartyEvent(AnyInAggroRange, TOnHeroPartyEvent(@this.OnReachedCamp), _arrTmp_Guards[_iTmp], m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnNearCamp), "LC1_Outpost", m_iPlayerFaction);

		//Thorsten Change: Changed to Creature Event individual as Sentenza has the shoutout, so he should be the only one who can trigger it
		//m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnSeeHangman), "LC1_HangMan", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnSeeHangman), "LC1_HangMan", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnMainEntrance), "LC1_MainEntrance", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC1_InteractMainGate), "LC1_MainGateTrigger", m_iPlayerFaction);
		//m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLC1_InteractMainGate), "LC1_MainGateSwitch", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLC1_MutilatedMerchant), "LC1_MutilatedMerchant", m_iPlayerFaction);

		//m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnEnterRuins_1), "LC1_EnterRuins_1", m_iPlayerFaction);
		//m_Reference.RegisterHeroPartyEvent( AnyInAggroRange, TOnHeroPartyEvent(@this.OnEnterRuins_2), "LC1_Rebel_Guard_02", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent( AnyInAggroRange, TOnHeroPartyEvent(@this.OnEnterRuins_1), "LC1_Rebel_Guard_01", m_iPlayerFaction );
		m_Reference.RegisterHeroPartyEvent( AnyInside, TOnHeroPartyEvent(@this.OnEnterRuins_2), "LC1_EnterRuins_2", m_iPlayerFaction );

		for(uint i = 1; i <= m_iRuinGuardSpawns; i++)
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnRuinGuardsKilled), m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_0" + i), false, "");


		//Thorsten Exploration Points
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnMainExploration01), "LC1_Exploration_01", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnMainExploration02), "LC1_Exploration_02", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnMainExploration03), "LC1_Exploration_03", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnMainExploration04), "LC1_Exploration_04", m_iPlayerFaction);

		// glitter effects
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLootObject_5), "LC1_HiddenLoot_5", m_iPlayerFaction);
		//m_Reference.RegisterLogicObjectEvent(Looted, TOnLogicObjectEvent(@this.OnLootObject_5), "LC1_HiddenLoot_5", m_iPlayerFaction);

		m_Reference.RegisterBuildingEventByDescription(Completed, TOnBuildingEvent(@this.OnBarracksCompleted), "H_Barracks_I", m_iPlayerFaction);
		// m_Reference.RegisterBuildingEventByIndividual(WorkerAssignmentChanged, TOnBuildingEvent(@this.OnWorkerForCapitol), "");

		//  Handling new Worker Shoutout
		// m_arrStg_Worker comes from the LeveBase
		for ( uint _iTmp = 0; _iTmp < m_arrStg_Worker.length(); _iTmp++ )
			m_Reference.RegisterUIEventByDescription( EntitySelected, TOnUIEntityEvent(@this.OnLC1_WorkerShoutout), m_arrStg_Worker[_iTmp], m_iPlayerFaction );
		

		LC1_OpenerCutscene();
	}
// for the second map setting
	void InitEvents_1 ()
	{
		// --- Beginning of map
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_IskanGuard_1), "LC2_IGuard_1", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_IskanGuard_2), "LC2_IGuard_2", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_UtranGuard), "LC2_UGuard", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyCanSee, TOnHeroPartyEvent(@this.OnLC2_nearUtranBorder), m_stgLC2_crtUtranRefugeeMan, m_iPlayerFaction);

		//m_Reference.RegisterHeroPartyEvent(EnteredAggroRange, TOnHeroPartyEvent(@this.OnLC2_Guard_1), "LC2_NGuardTrg_1", m_iPlayerFaction);
		// First guard, which is also going to be the one to talk to for the quest
		string _stgTmp = "";
		array <Creature>@ _arrCrt_Guards = m_Reference.GetCreaturesFromSpawn( "LC2_CastleGuard_1" );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Guards.length() ; _iTmp++ )
		{
			if ( _arrCrt_Guards[_iTmp].GetDescriptionName() == m_stgLC2_crtNortanderGuard_1 )
				_stgTmp = m_Reference.FindEntityName(_arrCrt_Guards[_iTmp]);
		}
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLC2_Guard_1), _stgTmp, m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_Guard_2), "LC2_NGuardTrg_2", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_Guard_3), "LC2_NGuardTrg_3", m_iPlayerFaction);

		m_Reference.RegisterBuildingCreatureEventByIndividual( CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnLC2_WaveSpawn_IskAtkNortander), m_stgLC2_bldgNeutral_Iskander );
		m_Reference.RegisterBuildingCreatureEventByIndividual( CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnLC2_WaveSpawn_NorAtkIskander), m_stgLC2_bldgNeutral_Nortander );

		m_Reference.RegisterBuildingEventByIndividual(Destroyed, TOnBuildingEvent(@this.LC2_NortanderBarakcsDestroyed), "LC2_NortanderBaracks");

		m_Reference.RegisterInventoryEvent(Used, TOnInventoryEvent(@this.OnLC2_ItemMedicine), m_stgLC2_ItemMedicine, m_iPlayerFaction);
		m_Reference.RegisterInventoryEvent(Read, TOnInventoryEvent(@this.OnLC2_ItemLetter), m_stgLC2_ItemSecretLetter, m_iPlayerFaction);

		// on leaving the map
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnLC2_leaveMapToEverlight), m_stgEntrance_LC_EL, m_iPlayerFaction);

		//
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_NearTheRuins), m_stgAvatar, "LC2_Ruins_1");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_NearTheRuins), m_stgAvatar, "LC2_Ruins_2");


		// Thorsten Ambushes
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC2_BearAmbush), m_stgLC2_BearTrigger, m_iPlayerFaction);

		// --- C O R E  --------------------- - Works
		for ( uint _iTmp = 0; _iTmp < m_arrStgLC2_SectorsRouteOne.length(); _iTmp++ )
			m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLC2_ChangeOwnerRouteOne), m_arrStgLC2_SectorsRouteOne[_iTmp]);

		for ( uint _iTmp = 0; _iTmp < m_arrStgLC2_SectorsRouteTwo.length(); _iTmp++ )
			m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLC2_ChangeOwnerRouteTwo), m_arrStgLC2_SectorsRouteTwo[_iTmp]);

		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.OnLC2_NortanderWasDefeated), m_stgLC2_SectNortanderCamp );

		// Milita and Villagers
		m_Reference.RegisterCreatureEventByIndividual(LeftArea, TOnCreatureEvent(@this.OnLC2_StartMilitiaFollow), m_stgLC2_crtClaraFarlorn, "LC2_StartMilitiaFollowing");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_CaravanArrived), m_stgLC2_crtClaraFarlorn, "LC2_EndCaravan");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnDespawnCreature), m_stgLC2_crtClaraFarlorn, m_stgLC2_TrgCaravanEscape);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_IskanderLeaderCheck), m_stgLC2_crtClaraFarlorn, "LC2_IskanderCheck");
		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHMilitiaSpawns.length() ; _iTmp++ )
		{
			m_Reference.RegisterCreatureEventByIndividuals( EnteredArea, TOnCreatureEvent(@this.OnLC2_DespawnMilitia), m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp] ), true, m_stgLC2_TrgCaravanEscape );
		}
		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHVillagerSpawns.length() ; _iTmp++ )
		{
			m_Reference.RegisterCreatureEventByIndividuals( EnteredArea, TOnCreatureEvent(@this.OnLC2_DespawnVillagers), m_Reference.GetCreaturesFromSpawn( m_arrStg_FHVillagerSpawns[_iTmp] ), true, m_stgLC2_TrgCaravanEscape );
			m_Reference.RegisterCreatureEventByIndividuals( Killed, TOnCreatureEvent(@this.OnLC2_VillagerDied), m_Reference.GetCreaturesFromSpawn( m_arrStg_FHVillagerSpawns[_iTmp] ), true, "" );
		}

		// Border Refugees
		m_Reference.RegisterBuildingCreatureEventByIndividual( CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnLC2_WaveSpawn_NorAtkRefugees), m_stgLC2_BldgNortanderAttackRefugees );
		for ( uint _iTmp = 0; _iTmp < m_arrStg_BorderRefugees.length() ; _iTmp++ )
		{
			m_Reference.RegisterCreatureEventByIndividuals( Killed, TOnCreatureEvent(@this.OnLC2_RefugeeDied), m_Reference.GetCreaturesFromSpawn( m_arrStg_BorderRefugees[_iTmp] ), true, "" );
			m_iLC2_RefugeesTotal = m_iLC2_RefugeesTotal + m_Reference.GetCreaturesFromSpawn( m_arrStg_BorderRefugees[_iTmp] ).length();
		}
		printNote("Refugees in total: " + m_iLC2_RefugeesTotal);

		// trigger opener cutscene
		LC2_StartOpenerCutscene();

		m_Reference.RegisterCreatureEventByIndividual(Resurrected, TOnCreatureEvent(@this.LC2_OnResurrected_ClaraFarlorn), m_stgLC2_crtClaraFarlorn, "");
		m_Reference.RegisterCreatureEventByIndividual(RevivePeriodEnded , TOnCreatureEvent(@this.LC2_OnRevivePeriodEnded_ClaraFarlorn), m_stgLC2_crtClaraFarlorn, "");

		m_Reference.GetWorld().SetGlobalInt("MapVariables.LC_CountNortanderSoldiersMax", m_iLC2_NortanderFollowSoldiers_Max);
	}

	
// for the third map setting
	void InitEvents_2 ()
	{
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.LC3_OnTriggerEnter_SO_Pallisade), "LC3_Trigger_SO_Pallisade01", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.LC3_OnEnterSector_Playerbase), "Sector_13", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_TunnelEntry), m_stgLC3_Switch_TunnelEntry_01, m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_TunnelEntry), m_stgLC3_Switch_TunnelEntry_02, m_iPlayerFaction);
		//m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_RuneChest), "LC3_Loot_RuneChest", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.LC3_OnTriggerEnter_CheckChest), "LC3_Trigger_CheckChest", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(AllInside, TOnHeroPartyEvent(@this.LC3_OnTriggerEnter_BehindTheWall), "LC3_Trigger_BehindTheWall", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyOutside, TOnHeroPartyEvent(@this.LC3_OnTriggerLeave_BehindTheWall), "LC3_Trigger_BehindTheWall", m_iPlayerFaction);

	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.LC3_OnTriggerEnter_RuneGuardsAggro_01), "LC3_Trigger_RuneGuardsAggro_01", m_iPlayerFaction);
	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.LC3_OnTriggerEnter_RuneGuardsAggro_02), "LC3_Trigger_RuneGuardsAggro_02", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnInteract_Door_01), "LC3_InnerFortDoor_1_Switch", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnInteract_Door_02), "LC3_InnerFortDoor_2_Switch", m_iPlayerFaction);

	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.this.LC3_OnTriggerEnter_GatherAtMyrah), "LC3_Trigger_GatherAtMyrah_01", m_iPlayerFaction);
	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.this.LC3_OnTriggerEnter_GatherAtMyrah), "LC3_Trigger_GatherAtMyrah_02", m_iPlayerFaction);

		m_Reference.RegisterCreatureEventByIndividual(CanSee, TOnCreatureEvent(@this.LC3_OnCansee_AvatarMyrah), m_stgAvatar, "Myrah_Utran");

		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_SO_Bridge), m_stgAvatar, "LC3_Trigger_SO_Bridge");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_SO_OldPurityCamp), m_stgAvatar, "LC3_Trigger_SO_RefugeeGone");

		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_SO_AngarAttack), m_stgLC3_Crt_Angar, "LC3_Trigger_CastleEntrance_01");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_SO_AngarAttack), m_stgLC3_Crt_Angar, "LC3_Trigger_CastleEntrance_02");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_SO_AngarAttack), m_stgLC3_Crt_Angar, "LC3_Trigger_CastleEntrance_03");

		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.LC3_OnSectorOwnerChanged_PlayerBase), m_stgLC3_Sector_Playerbase);
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.LC3_OnSectorOwnerChanged_PurityBase), m_stgLC3_Sector_PurityCastle);

		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.LC3_OnWaveSpawned_PurityWaves), m_stgLC3_Bldg_PurityWaveSpawn01);

		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_AngarMyrah), 120); // exchange with bantern function
		// DialogBantern ( m_stgAvatar, m_stgAvatar, "LC3_10_BN_AngarMyrah", 50); // needs check if participant is part of heroparty

		m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.LC3_OnLoot_TunnelKey), "LC3_TunnelKey", m_iPlayerFaction);
		m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.LC3_OnLoot_Rune), "LC3_Rune", m_iPlayerFaction);

		m_Reference.RegisterBuildingEventByIndividual(Charged, TOnBuildingEvent(@this.LC3_OnBuildingCharged_Bridge), "LC3_BrokenBridge");

		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_Inspection_LC_Grave), "LC_Grave", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_Inspection_LC_EmptyCage), "LC_EmptyCage", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_Inspection_LC_Inspect_OldShrine), "LC_ArmorOfStatusImmunity_Q4_Memorial", m_iPlayerFaction);

		// ARTIFACT EVENTS
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_PurityShrine), "LC3_PurityShrine", m_iPlayerFaction);
	}

	bool LC3_OnInteract_PurityShrine( Creature& in _Creature )
	{
		if( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("AP_FragmentOfPurityShield", 1) )
		{
			m_Reference.GetWorld().SetGlobalInt("MapVariables.Artifact_FragmentsOfPurityShield", m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_FragmentsOfPurityShield") + m_Reference.GetHeroParty(m_iPlayerFaction).GetItemAmount("AP_FragmentOfPurityShield"));
			m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems("AP_FragmentOfPurityShield", m_Reference.GetHeroParty(m_iPlayerFaction).GetItemAmount("AP_FragmentOfPurityShield"));			

			if( m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_FragmentsOfPurityShield") >= 3 )
			{
				m_Reference.GetLogicObjectByName("LC3_PurityShrine_Chest").Enable(true);
				m_Reference.GetLogicObjectByName("LC3_PurityShrine_ChestFX").Enable(true);
				return true;
			}

		}
		return false;
	}


	// General
	void InitCommon ()
	{
		// INSPECTIONS
		m_Reference.GetLogicObjectByName("LC_EmptyCage").SetInspectionText(5001);
		m_Reference.GetLogicObjectByName("LC_Grave").SetInspectionText(5002);
		m_Reference.GetLogicObjectByName("LC_Scaffolding").SetInspectionText(5003);
		m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial").SetInspectionText(5004);

		// DefilersBane Artifact for LC2 and LC3
		if( m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChest").Exists() )
		{
			m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChest").SetInspectionText( 6004 );
			m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChest").Lock(m_Reference, "");
			m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChestFX").Enable(false);
		}
		// Memorial Artifact for LC2 and LC3
		if( m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial").Exists() )
		{
			m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_Chest").Enable(false);	
			m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_ChestFX").Enable(false);
			m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_Flame").Enable(false);
		}

	}

// for the 1st map version
	void InitCommon_0 ()
	{
		// unlock glossary stuff
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Abilities' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Blueprints' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Fast Travel' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Leveling System' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Neutral Buildings' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Resistance System' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Revive System' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Status Effects' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Terminology' );
		m_Reference.GetWorld().UnlockAllGlossaryTargetParagraphs( 'Worldmap' );
		
		//Disable XP Gain
		//m_Reference.GetHeroParty(0).EnableExperienceGain(false);
		//DialogShoutout( m_stgHero_Sentenza, m_stgHero_Sentenza, "MapIntro_1", true );

		m_Reference.GetBuildingByName("LC1_Barricade").SetFaction(7);
		m_Reference.GetBuildingByName("LC1_Barricade").SetAttackable(false);
		m_Reference.GetBuildingByName("LC1_Barricade").SetInteractive(true);
		m_Reference.GetCreatureByName( m_stgLC1_crtCrowdDummyNPC ).Enable(false);

		// Main Gat at the fort
		m_Reference.GetLogicObjectByName( "LC1_MainGateSwitch" ).SetInteractive( false );
		//m_Reference.GetLogicObjectByName( "LC_FortEntranceDoor_1" ).SetInteractive(false);
		m_Reference.GetLogicObjectByName( "LC_FortEntranceDoor_2" ).SetInteractive(false);

		//Patrolling Routes
		/*for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_02").size(); i++)
			m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_02")[i].Patrol(m_Reference, "LC1_PatrollPath", true, true, true, false, true);
		for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_05").size(); i++)
			m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_05")[i].Patrol(m_Reference, "LC1_PatrollPath2", true, true, true, false, true);
		for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_06").size(); i++)
			m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_06")[i].Patrol(m_Reference, "LC1_PatrollPath3", true, true, true, false, true);
		for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_07").size(); i++)
			m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_07")[i].Patrol(m_Reference, "LC1_PatrollPath4", true, true, true, false, true);
		*/

		//Add Revive Talismans to Sentenza
		//m_Reference.GetCreatureByName(m_stgHero_Sentenza).Equip(m_Reference, Item, "ReviveTalisman", Give, 5);

		m_Reference.GetEntitiesByName("MapTransitions_LC_LCC1")[0].Enable(false);

		// INSPECTIONS
		m_Reference.GetLogicObjectByName( "Godstone_South_Inspection" ).SetInspectionText(31016);
		m_Reference.GetLogicObjectByName( "Godstone_Fort_Inspection" ).SetInspectionText(31016);
		m_Reference.GetLogicObjectByName("LC1_Waysign").SetInspectionText(8000);
		m_Reference.GetLogicObjectByName("LC1_Skeleton").SetInspectionText(8002);
		//m_Reference.GetLogicObjectByName("LC1_HangMan").SetInspectionText(8001);
		
		m_Reference.GetCreatureByName( m_stgHero_Sentenza ).LockItemSlot( Torso, true );
		m_Reference.GetCreatureByName( m_stgHero_Sentenza ).LockItemSlot( PrimaryHand, true );
		m_Reference.GetCreatureByName( m_stgHero_Sentenza ).LockItemSlot( SecondaryHand, true );
		m_Reference.GetCreatureByName( m_stgHero_Sentenza ).LockItemSlot( Item, true );

//Assign skills party members
		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Sentenza), "CloseCombatPerk");
		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Sentenza), "Whirlwind");

		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Anselm), "DefensiveTechniquePerk");
		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Anselm), "ShieldBash");

		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Gwen), "WhiteMagicPerk");
		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Gwen), "Heal");		

		//StartingPotions
		m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "HealthPotion", 5 );
		m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "FocusPotion", 5 );
	}


// for the 2nd map version
	void InitCommon_1 ()
	{
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ("MQ_011", true );
		m_Reference.GetLogicObjectByName( m_stgEntrance_LC_EL ).SetInteractive( false );

		// Set up the Path to Farlorns Hope - making sure, the player cant go back right now
		m_Reference.GetLogicObjectByName( m_stgEntrance_FH_LC ).SetInteractive( true );
		MapUnlock( "LC", false );

		//m_Reference.GetCreatureByName( m_stgLC2_crtUtranRefugeeMan).Enable(false);
		// *** TEMPORARY for testing - dont forget to delete this later

		m_Reference.GetBuildingByName("UtranBorder_Barricade").SetFaction( m_iLC2_FactionUtran );

		// Set up the Militia and the rescued villagers
		LC2_CheckSurvivedMilitia();
		LC2_CheckSurvivedVillagers();
		array <Creature> _arrFHVillagers = GetCreaturesFromSpawns( m_arrStg_FHVillagerSpawns );
		for ( uint _iTmp = 0; _iTmp < _arrFHVillagers.length() ; _iTmp++ )
			_arrFHVillagers[_iTmp].SetInteractive( false );
		
		m_Reference.AddVisibleSector( m_iPlayerFaction, m_Reference.GetSectorByName("Sector_Player_Hideout_02").GetIndex() );

		// Godstones
		m_Reference.GetBuildingByName( "Godstone_Fort" ).SetFaction( kFactionNeutral );
		m_Reference.GetBuildingByName( "Godstone_Iskander" ).SetFaction( kFactionNeutral );
		m_Reference.GetBuildingByName( "Godstone_Entrance" ).SetFaction( kFactionNeutral );

		// set up NPCS
		//m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).SetImmortal( true );
		m_Reference.GetCreatureByName(m_stgLC2_crtClaraFarlorn).SetHelpUpAllowed (true);
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).SetImmovable( true );

		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).SetImmortal( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).SetImmovable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).SetAttackable ( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).AllowAttacks ( false );

		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).SetAttackable ( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).AllowAttacks( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).SetImmovable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).SetImmortal( true );

		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).SetImmortal( true );
		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).SetImmovable( true );
		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).Enable( false );

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

		m_Reference.GetCreatureByName( m_stgLC2_crtUtranSoldier_1 ).SetInteractive( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtUtranSoldier_1 ).EnablePOIVisitingBehavior(false);

		m_Reference.GetCreatureByName( m_stgLC2_crtNortanderGuard_1 ).SetInteractive( true );

		m_Reference.GetBuildingByName( m_stgLC2_BldgNortanderAttackRefugees).SetFaction( m_iLC2_FactionNortanderAssault );
		m_Reference.GetBuildingByName( m_stgLC2_BldgNortanderAttackRefugees).Enable( false );
		m_Reference.GetBuildingByName( m_stgLC2_BldgNortanderAttackRefugees).SetSelectable(false);
		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Nortander).SetFaction( m_iLC2_FactionNortanderAssault );
		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Nortander).SetSelectable( false );
		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Iskander).SetFaction( m_iLC2_FactionIskanderLoyalists );
		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Iskander).SetSelectable( false );

		SetSpawnImmovable(m_arrStg_PuritySpawns[0], true);

		// disable switch position markers
		m_Reference.GetLogicObjectByName( m_stgLC2_PosSentenza_Ambush ).SetInteractive( false );
		m_Reference.GetLogicObjectByName( m_stgLC2_PosPurityCamp ).SetInteractive( false );
		m_Reference.GetLogicObjectByName( m_stgLC2_PosBertrandCarpel_Meeting ).SetInteractive( false );
		m_Reference.GetLogicObjectByName( m_stgLC2_PosIskanderCamp ).SetInteractive( false );

		// Nortander Chase
		m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave).Enable( false );
		m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave).SetInteractive( false );
		m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave).SetFaction( m_iLC2_FactionNortanderAssault );
		m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave).SetSelectable( false );


		// Utran Refugee Line
		// get a big array of all the villagers that can roam around here - and randomly pick some of them and send them to the line.
		m_Reference.GetCreatureByName( m_stgLC2_crtUtranRefugeeMan ).EnablePOIVisitingBehavior(false);
		m_Reference.GetCreatureByName( m_stgLC2_crtUtranRefugeeMan).GoTo( m_Reference, m_Reference.GetLogicObjectByName( m_stgLC2_UtranVillagersPositions+"0" ) , 0, 0, false, false );
		m_arrLC2_UtranVillagers_CurrentLine[0] = m_stgLC2_crtUtranRefugeeMan;

		// get the array with all the utran refugees
		array <string> _arrTmp = GetCreaturesFromSpawns_stg( m_arrStg_BorderRefugees );
		for ( uint _iTmp = 1; _iTmp < m_arrLC2_UtranVillagers_CurrentLine.length() ; _iTmp++ )
		{
			uint _iRandom =  m_Reference.GetRandom().GetInteger(0, _arrTmp.length());

			// handle the villager, and let him go there
			Creature _crtTmp = m_Reference.GetCreatureByName( _arrTmp[_iRandom] );
			_crtTmp.Teleport( m_Reference, m_Reference.GetLogicObjectByName( m_stgLC2_UtranVillagersPositions + (_iTmp + 1) ));
			_crtTmp.GoTo( m_Reference, m_Reference.GetLogicObjectByName( m_stgLC2_UtranVillagersPositions + (_iTmp) ), 0, 0, true, false);; // this is so, that they look into the correct direction
			_crtTmp.EnablePOIVisitingBehavior( false );
			_crtTmp.SetImmovable( true );

			m_arrLC2_UtranVillagers_CurrentLine[ _iTmp ] = _arrTmp[_iRandom];
			printNote("UTRAN BORDER LINE: Pos '"+m_stgLC2_UtranVillagersPositions+_iTmp+"' has villager '"+_arrTmp[_iRandom]+"' standing there.");
			_arrTmp.removeAt( _iRandom );
		}


		// --- Revisits
		for ( uint _iTmp = 0; _iTmp < m_arrStg_BanditsObjects.length() ; _iTmp++ )
			m_Reference.GetLogicObjectByName(m_arrStg_BanditsObjects[_iTmp]).Enable(false);

		// Purity revisit
		for ( uint _iTmp = 0; _iTmp < m_arrStg_BorderRefugeesObjects_toAppear.length() ; _iTmp++ )
			m_Reference.GetLogicObjectByName(m_arrStg_BorderRefugeesObjects_toAppear[_iTmp]).Enable(false);

		m_Reference.GetCreatureByName( m_stgCrtLC2_LostTrader ).Enable(false);

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_010", "MQ_010_F", Completed );

		m_Reference.GetLogicObjectByName( "LC_FortEntranceDoor_1" ).SetInteractive(false);
		m_Reference.GetLogicObjectByName( "LC_FortEntranceDoor_2" ).SetInteractive(false);

		// set up loyalist camp guards
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_01")[0].SetHelpUpAllowed (true);
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_02")[0].SetHelpUpAllowed (true);
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_01")[0].SetAutoRevive(true);
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_02")[0].SetAutoRevive(true);

		// INSPECTIONS
		m_Reference.GetLogicObjectByName("LC2_BrokenCart").SetInspectionText(6000);
		m_Reference.GetLogicObjectByName("LC2_Cage").SetInspectionText(6001);
		m_Reference.GetLogicObjectByName("LC2_DeadRefugee").SetInspectionText(6002);
		m_Reference.GetLogicObjectByName("LC2_Inspect_OpenHayBarn").SetInspectionText(6003);
		m_Reference.GetLogicObjectByName("LC2_Inspect_Tent").SetInspectionText(6006);
		
		// ARTIFACTS

		m_Reference.GetBuildingByName("LC2_NortanderChaseWaves").Enable(false);
		m_Reference.GetBuildingByName("LC2_NortanderRefugeesWaves_01").Enable(false);


	}
// for the 3rd map version
	void InitCommon_2 ()
	{

		if( m_bDebuggingMode )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_Q1_FreeMyrah", true);
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q1_FreeMyrah", "P4_Q1_FreeMyrah_ToLoyalistCamp", true);
		}

		// RESET the godstones
		DisableAllGodstonesForFaction( m_iPlayerFaction );

		PlayTrack("music/characters/angar");
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "cutscene", 1);

		LC3_CheckInitialPlayerUnits(); // Check the player army

		m_Reference.GetLogicObjectByName(m_stgLC3_Switch_TunnelEntry_01).Lock(m_Reference, "LC3_TunnelKey");
	//	m_Reference.GetLogicObjectByName("LC3_Loot_RuneChest").Lock(m_Reference, "");
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_PurityWaveSpawn01).SetFaction(m_iLC3_Faction_Purity);
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_PurityWaveSpawn01).SetSelectable(false);
		//m_Reference.ActivateAI(m_iLC3_Faction_Purity_AI);
		LC3_Cutscene_MapIntro();

		//Testing for Thorsten
	//	m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("ReviveTalisman", 20);
	//	m_Reference.GetCreatureByName(m_stgAvatar).Equip(m_Reference, Item, "ReviveTalisman", FromInventory);
		CheckHeroPartyMembers();

		//Disable the siege camps + firelights there
		m_Reference.EnableGroup("LC3_Grp_SiegeCamp_01", false);
		m_Reference.EnableGroup("LC3_Grp_SiegeCamp_02", false);
		for( uint i = 0; i < m_arrStgLC3_SiegeCampLights.length(); i++){
			m_Reference.EnableLight(m_arrStgLC3_SiegeCampLights[i], false);
		}

		//disable siege wavespawns (purity and utran)
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).Enable(false);
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).SetSelectable(false);
		for( uint i = 0; i < m_arrStgLC3_Bldg_PuritySiegeSpawns.length(); i++ )
			m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).SetSelectable(false);
		

		//Set Relation between player and Utran to Hostile
		m_Reference.SetFactionRelation(m_iPlayerFaction, 3, Hostile);
		//Set Relation between allied AI and Utran to Hostile
		m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, 3, Hostile);

		m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_01", true);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_02", true);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_03", true);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Bridge_01", true);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Bridge_02", true);

		//Disable the repaired bridge entity
		m_Reference.GetLogicObjectByName("LC3_RepairedBridge").Enable(false);

		//Disable the refugees belongings for the first map part
		m_Reference.GetLogicObjectByName("LC3_Loot_RefugeeBelongings").Enable(false);

		//Key should be enabled when you takled to the dude
		m_Reference.GetLogicObjectByName("LC3_Loot_TunnelKey").Enable(false);

		//INSPECTIONS
		m_Reference.GetLogicObjectByName("LC3_PurityShrine").SetInspectionText(5000);

		//ARTIFACT
		m_Reference.GetLogicObjectByName("LC3_PurityShrine_Chest").Enable(false);
		m_Reference.GetLogicObjectByName("LC3_PurityShrine_ChestFX").Enable(false);

		m_Reference.BlockNavMesh("LC3_PhysBlocker_GatherAtMyrah_01", true);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_GatherAtMyrah_02", true);

	}



	// FOR PATCHES 
	void OnCheck_1()
	{
		printNote( "PATCH 'OnCheck_1'" );

		// RTS officially finished, but still there
		if( m_Reference.GetSectorsByOwner( m_iPlayerFaction ).length() > 0 && (m_Reference.GetJournal(m_iPlayerFaction).GetTaskState( "P3_Q5c_GainHumans", "SQ_011_G") == Completed || m_Reference.GetJournal(m_iPlayerFaction).GetTaskState( "P3_Q5c_GainHumans", "SQ_011_E_a") == Completed) )
		{
			EnableWorldMap( true );
			m_Reference.RegisterHeroPartyEvent(LeavingMap, TOnHeroPartyEvent(@this.OnLC2_LeavingMap), "", m_iPlayerFaction);
		}

	}

	void OnCheck_2()
	{
		printNote( "PATCH 'OnCheck_2'" );
	}



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

	bool OnInteract_Memorial( Creature& in _Creature )
	{
		m_Reference.GetWorld().SetGlobalInt("MapVariables.Artifact_MemorialFlamesLit", m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_MemorialFlamesLit") +1);
		m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_Flame").Enable(true);
		if( m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_MemorialFlamesLit") >= 3 )
		{
			m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_Chest").Enable(true);	
			m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_ChestFX").Enable(true);
			m_Reference.SetTimer(TOnTimerEvent(@this.OnTimer_DisableMemorialChestFX), 1);
		} 
		return true;
	}

	bool OnTimer_DisableMemorialChestFX()
	{
		m_Reference.GetLogicObjectByName("LC_ArmorOfStatusImmunity_Q4_Memorial_ChestFX").Enable(false);
		return true;
	} 

	bool LC2_LC3_OnInteract_DefilersBaneLoot( Creature& in _Creature )
	{
		if( _Creature.GetAttribute(Dexterity) >= 8 )
		{
			m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChest").Unlock();
			m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChest").SetInspectionText( uint(-1) );
			m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChestFX").Enable(true);
			m_Reference.SetTimer(TOnTimerEvent(@this.LC2_LC3_OnTimer_Artifact_DefilersBane_LootChestFX), 3);
			return true;
		}
		return false;
	}
	bool LC2_LC3_OnTimer_Artifact_DefilersBane_LootChestFX()
	{
		m_Reference.GetLogicObjectByName("LC2_LC3_Artifact_DefilersBane_LootChestFX").Enable(false);
		return true;
	}

// -------------------------------------------------------------------------------------------------------------------
// --- E V E N T  F U N C T I O N S  V E R S I O N  1 ----------------------------------------------------------------
	bool OnLC1_InteractBarrier(Creature& in Creatures)
	{
		printNote("Touched the Barrier, barricade destroyable: "+m_bBarricadeDestroyable+", and barracks complete: "+m_bBarracksComplete+"");
		if( !m_bBarricadeDestroyable )
		{
			DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_Barrier", true);
			m_Reference.GetBuildingByName("LC1_Barricade").SetInteractive( false );
			m_Reference.EnableGroup( "LC1_Barricade_effect", false );
		}

		return true;
	}
	bool OnLC1_BarricadeShoutoutArsonists(Creature& in Creatures)
	{
		if( m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P1_Q2_DefeatTraitors", "P1_Q2_DestroyBarricade") && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P1_Q2_DefeatTraitors", "P1_Q2_DestroyBarricade") != Completed )
			TutorialExtern('Item_Talismans');

		// Thorstens Solution
		if ( m_bBarricadeDestroyable && m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_arsonists") >= 2 )
		{
			DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_Barricade_HasPillagers", false);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q3_BuildAnArmy", "P1_Q1_RecruitArsonists", Completed );
			return true;
		}
		else if( m_bBarracksComplete )
		{
			if ( m_Reference.GetCreatureByName(m_stgHero_Sentenza).IsInDialogue() == false )
				DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_Barricade_NeedPillagers", false);
		}

		return false;
	}


	bool OnLC1_InteractMainGate(Creature& in Creatures)
	{
		printNote("Standing near the MainGate");
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_MainGate", true);
		m_Reference.GetJournal( m_iPlayerFaction ).SetTaskState("P1_Q2_DefeatTraitors", "P1_Q2_CheckMainEntrance", Completed );

		m_Reference.GetLogicObjectByName( "LC1_MainGateSwitch" ).SetInteractive( false );
		m_Reference.EnableGroup( "LC1_MainGateSwitch_effect", false );

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnLC1_SOalternateRoute), "LC1_AlternativeRoute", m_iPlayerFaction);

		return true;
	}
	bool OnLC1_SOalternateRoute(Creature& in Creatures)
	{
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_TakeThePath", false);
		m_Reference.AddVisiblePath( m_iPlayerFaction, "LC1_path" );
		m_Reference.SetTimer( TOnTimerEvent(@this.OnLC1_SOalternateRoute_timer), 4 );
		return true;
	}
	bool OnLC1_SOalternateRoute_timer ()
	{
		m_Reference.RemoveVisiblePath( m_iPlayerFaction, "LC1_path");
		return true;
	}

	bool OnLC1_MutilatedMerchant(Creature& in Creatures)
	{
		printNote("Looting the merchant at the south-east (LC1_HiddenLoot_1)");
		DialogShoutout(m_stgHero_Gwen, m_stgHero_Gwen, "LC1_MerchantCorpse", false);
		m_Reference.GetLogicObjectByName( "LC1_MutilatedMerchant" ).SetInteractive( false );
		m_Reference.EnableGroup( "LC1_MutilatedMerchant_effect", false );

		return true;
	}

	bool OnLC1_HeroPartyMemberKilled(Creature& in Creatures)
	{
		printNote(Creatures.GetDescriptionName() + " died");

		// Gwen died, the only female hero
		if ( Creatures.GetDescriptionName() == m_stgHero_Gwen )
		{
			string _stgRandomHero = HeroPartyGetRandomThatIsAlive();
			DialogShoutout(_stgRandomHero, _stgRandomHero, "LC1_SO_PartyMemberDown_Female", false);
		}
		else if ( Creatures.GetDescriptionName() != m_stgHero_Sentenza )
		{
			string _stgRandomHero = HeroPartyGetRandomThatIsAlive();
			DialogShoutout(_stgRandomHero, _stgRandomHero, "LC1_SO_PartyMemberDown_Male", false);
		}

		return false;
	}
	bool OnLC1_HeroPartyIsLooting(Creature& in Creatures)
	{
		if ( m_bLC1_lootedForTheFirstTime )
			return true;

		printNote("Looting an object for the first time - and hero party commenting on that");
		if ( !m_Reference.GetCreatureByName(m_stgHero_Sentenza).IsInDialogue() )
		{
			DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_Loot", false);
			m_bLC1_lootedForTheFirstTime = true;
		}
		return true;
	}

	bool OnTriggerWolfAttack(Creature& in Creatures)
	{
		printNote("Spawning Wolfs");
		TutorialExtern( 'ClickAndFight' );

		m_Reference.ActivateSpawn("LC1_WolfSpawn", true);
		// Note by Marc: Use a Creaturegroup and AttackPosition here (instead of iterating through that array)
		for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("LC1_WolfSpawn").size(); i++)
			m_Reference.GetCreaturesFromSpawn("LC1_WolfSpawn")[i].GoTo(m_Reference, m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[0], 5, 5, true, false);

		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnWolvesKilled), m_Reference.GetCreaturesFromSpawn("LC1_WolfSpawn"), false, "");
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_SpotWolves", true);
		return true;
	}
	bool OnWolvesKilled(Creature& in Creatures)
	{
		printNote("Wolves killed");
		//DialogShoutoutTimed(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_WolvesDefeated", false, 1);
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_WolvesDefeated", false);
		TutorialExtern( 'Glossary' );
		return true;
	}

	bool OnNearCamp(Creature& in Creatures)
	{
		if ( m_bLC1_nearCampPlayed )
			return true;

		m_bLC1_nearCampPlayed = true;
		printNote("Near Camp");
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_OutpostInSight", false);
		TutorialExtern('Quests');

		return true;
	}

	bool OnReachedCamp(Creature& in Creatures)
	{
		if ( m_bLC1_reachedCampPlayed )
			return true;

		printNote("Reached Camp");
		
		m_bLC1_reachedCampPlayed = true;
		DialogShoutout("LC1_Outpost_Guard_01", "LC1_Outpost_Guard", "LC1_SentenzaIsHere", false);
		m_Reference.AddVisiblePath( m_iPlayerFaction, "LC1_Outpost");
		
		return true;
	}

	/*bool OnInteractGuard(Creature& in Creatures)
	{
		DialogShoutoutWhenReady("LC1_Outpost_Guard_01", "LC1_Outpost_Guard", "LC1_SO_Greeting", true);
		return true;
	}*/

	bool OnAttackersKilled(Creature& in Creatures)
	{
		m_Reference.SetTimer(TOnTimerEvent(@this.OnAttackersKilledTimer), 2);
		return true;
	}
	bool OnAttackersKilledTimer()
	{
		LC1_BuildTheBaseCutscene();
		return true;
	}

	bool OnLC1_ZeroWorkerAtMainBuilding(Building&in _Building)
	{
		printNote("Worker assigment on the main building changed '"+_Building.GetAssignedWorkers()+"'");
		if ( _Building.GetAssignedWorkers() == 0 )
		{
			DialogShoutout( m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_WorkersFree", false);
			return true;
		}
		return false;
	}

	bool OnAssignedWorkersToFisher(Building&in _Building)
	{
		m_bAssignedWorkersFisher = true;
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q1_Foothold", "P1_Q1_AssignWorkersFisher", Completed );
		CheckForOtherBuildings();
		return true;
	}

	bool OnAssignedWorkersToHunter(Building&in _Building)
	{
		m_bAssignedWorkersHunter = true;
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q1_Foothold", "P1_Q1_AssignWorkersHunter", Completed );
		CheckForOtherBuildings();
		return true;
	}

	bool OnAssignedWorkersToWoodcutter(Building&in _Building)
	{
		m_bAssignedWorkersWoodcutter = true;
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q1_Foothold", "P1_Q1_AssignWorkersWoodCutter", Completed );
		CheckForOtherBuildings();
		return true;
	}

	bool OnBarracksCompleted(Building&in _Building)
	{
		printNote("Completed Barracks");
		//DialogShoutout(m_stgHero_Bertrand, m_stgHero_Bertrand, "LC1_SO_BuildUnits", false);
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_ManBarracks", false);

		//m_Reference.RegisterBuildingEventByDescription(ProductionFinished, TOnBuildingEvent(@this.OnUnitsRecruted), "H_Barracks_I", m_iPlayerFaction);
		m_Reference.RegisterBuildingCreatureEventByDescription(CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnUnitsRecruted), "H_Barracks_I", m_iPlayerFaction);
		m_Reference.RegisterBuildingCreatureEventByDescription(CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnUnitsRecrutedCapital), "H_Capital_II", m_iPlayerFaction);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q1_Foothold", "P1_Q1_BuildBarracks", Completed );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Recruit", 1);
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Pillager", 1);

		m_Reference.GetWorld().UnlockBlueprint("BP_H_Pillager", true);
		
		m_bBarracksComplete = true;
		//m_Reference.RegisterBuildingEventByDescription(WorkerAssignmentChanged, TOnBuildingEvent(@this.OnMannedBarrickades), "H_Barracks_I", m_iPlayerFaction);
		return true;
	}

	bool m_bLC1_WorkerSOplayed = false;
	bool OnLC1_WorkerShoutout(const uint8 _uPlayerFaction, Entity& in _Entity)
	{
		if( m_bLC1_WorkerSOplayed )
			return true;

		m_bLC1_WorkerSOplayed = true;
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_DontClickWorkers", false);

		return true;
	}

	bool m_bLC1_enableBertrandDialoge = false;
	void LC1_CheckQuestState()
	{
		if (m_bLC1_enableBertrandDialoge)
			return;

		if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P1_Q3_BuildAnArmy", "P1_Q1_RecruitArsonists") == Completed )
			//&& m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P1_Q1_Foothold", "P1_Q1_RecruitRecruits") == Completed  )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P1_Q1_Foothold", "P1_Q1_TalkToBertrand", true );
			m_Reference.GetWorld().EnableDialogueTopic(m_stgHero_Bertrand, "LC1_LetsGo", true);
			m_bLC1_enableBertrandDialoge = true;
		}

	}

	bool OnUnitsRecruted(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote(_Creatures[0].GetDescriptionName() + " spawned");
		if (m_bArsonistsBuilt)
			return true;

		if(_Creatures[0].GetDescriptionName() == "H_Pillager")
		{
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.LC1_built_arsonists", m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_arsonists") + (_Creatures.length()/3));
			if ( m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_arsonists") >= 2 )
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q3_BuildAnArmy", "P1_Q1_RecruitArsonists", Completed );
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q1_Foothold", "P1_Q1_InvBuildSoldiers", Completed );
				m_bArsonistsBuilt = true;
				LC1_BuildRecruits();
				LC1_CheckQuestState();

				return true;
			}
		}

		return false;
	}

	bool OnUnitsRecrutedCapital(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote(_Creatures[0].GetDescriptionName() + " spawned");
		if (m_bArsonistsBuilt)
			return true;

		if(_Creatures[0].GetDescriptionName() == "H_Pillager")
		{
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.LC1_built_arsonists", m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_arsonists") + (_Creatures.length()/3));
			if (m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_arsonists") >= 2 )
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q3_BuildAnArmy", "P1_Q1_RecruitArsonists", Completed );
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q1_Foothold", "P1_Q1_InvBuildSoldiers", Completed );
				m_bArsonistsBuilt = true;
				LC1_BuildRecruits();
				LC1_CheckQuestState();
				return true;
			}
		}

		return false;
	}

	void LC1_BuildRecruits()
	{
		m_Reference.RegisterBuildingCreatureEventByDescription(CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnUnitsRecruted2), "H_Barracks_I", m_iPlayerFaction);
		m_Reference.RegisterBuildingCreatureEventByDescription(CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnUnitsRecrutedCapital2), "H_Capital_II", m_iPlayerFaction);
		print ("Activate Recuit Quest!");
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P1_Q1_Foothold", "P1_Q1_RecruitRecruits", true );
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Recruit", true);
	}

	bool OnUnitsRecruted2(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote(_Creatures[0].GetDescriptionName() + " spawned");
		if (m_bRecruitsBuilt)
			return true;

		if(_Creatures[0].GetDescriptionName() == "H_Recruit")
		{
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.LC1_built_recruits", m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_recruits") + (_Creatures.length()/3));
			if (m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_recruits") >= 2)
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q3_BuildAnArmy", "P1_Q1_RecruitRecruits", Completed );
				m_bRecruitsBuilt = true;
				LC1_CheckQuestState();
				return true;
			}
		}
		return false;
	}

	bool OnUnitsRecrutedCapital2(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote(_Creatures[0].GetDescriptionName() + " spawned");
		if (m_bRecruitsBuilt)
			return true;

		if(_Creatures[0].GetDescriptionName() == "H_Recruit")
		{
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.LC1_built_recruits", m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_recruits") + (_Creatures.length()/3));
			if (m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.LC1_built_recruits") >= 2)
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q3_BuildAnArmy", "P1_Q1_RecruitRecruits", Completed );
				m_bRecruitsBuilt = true;
				LC1_CheckQuestState();
				return true;
			}
		}
		return false;
	}

	/*bool OnLeaveCampWithArmy(Creature& in Creatures)
	{
		DialogShoutout("LC1_Gwen", "LC1_Gwen", "LC1_SO_Banter", true);
		return true;
	}*/

	bool OnSeeHangman(Creature& in Creatures)
	{
		printNote("Sentenza Hanged man shoutout should play");
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_HangedMan", false);
		m_Reference.GetLogicObjectByName("LC1_HangMan").SetInspectionText(8001);

		return true;
	}


	bool OnDestroyedBarricade(Building& in Buildings)
	{
		Autosave();
		DialogShoutoutTimed(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_BarricadeDestroyed", true, 1);
		DialogBantern( m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_Castle", m_Reference.GetRandom().GetInteger( 5, 6 ));
		m_Reference.GetLogicObjectByName("LC1_Barricade").Enable(false);
		return true;
	}


	bool OnEnterRuins_1(Creature& in Creatures)
	{
		DialogShoutout("LC1_Rebel_Guard_01", "LC1_Rebel_Guard_01", "LC1_SO_Guard_Gate", false);

		return true;
	}
	bool OnEnterRuins_2(Creature& in Creatures)
	{
		//DialogShoutout("LC1_Rebel_Guard_02", "LC1_Rebel_Guard_02", "LC1_SO_Guard_Gate_02", false);
		m_Reference.GetJournal( m_iPlayerFaction ).SetTaskState( "P1_Q2_DefeatTraitors", "P1_Q2_EnterRuins", Completed);
		m_Reference.GetJournal( m_iPlayerFaction ).SetTaskState( "P1_Q2_DefeatTraitors", "P1_Q2_KillDefenders", Unfinished);
		/*for(uint i = 1; i <= m_iRuinGuardSpawns; i++)
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnRuinGuardsKilled), m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_0" + i), false, "");
		*/
		return true;
	}

	bool OnMainEntrance(Creature& in Creatures)
	{
		TutorialExtern('CameraRotation');
		if ( m_Reference.GetCreatureByName("LC1_Rebel_Guard_02").GetCurrentHP() > 0 )
			DialogShoutout("LC1_Rebel_Guard_02", "LC1_Rebel_Guard_02", "LC1_SO_Guard_Gate_02", true);
		
		//DialogBantern( m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_Castle", m_Reference.GetRandom().GetInteger( 120, 200) );
		/*for(uint i = 1; i <= m_iRuinGuardSpawns; i++)
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnRuinGuardsKilled), m_Reference.GetCreaturesFromSpawn("LC1_RuinGuards_0" + i), false, "");
		*/
		return true;
	}

	bool OnMainExploration01(Creature& in Creatures)
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q2_TutorialExploration", "P1_Q1_Exploration_01", Completed );
		return true;
	}

	bool OnMainExploration02(Creature& in Creatures)
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q2_TutorialExploration", "P1_Q1_Exploration_02", Completed );
		return true;
	}

	bool OnMainExploration03(Creature& in Creatures)
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q2_TutorialExploration", "P1_Q1_Exploration_03", Completed );
		return true;
	}

	bool OnMainExploration04(Creature& in Creatures)
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q2_TutorialExploration", "P1_Q1_Exploration_04", Completed );
		return true;
	}

	//bool OnLootObject_5(LogicObject& in _Object, uint8 _uFaction)
	bool OnLootObject_5(Creature& in _Creature)
	{
		m_Reference.EnableGroup( "LC1_HiddenLoot_5_effect", false );
		return true;
	}

	bool OnRuinGuardsKilled(Creature& in Creatures)
	{
		m_iKilledGuardsCounter++;
		if(m_iKilledGuardsCounter == m_iRuinGuardSpawns)
			m_Reference.SetTimer(TOnTimerEvent(@this.OnRuinGuardsKilledTimer), 2);
		return true;
	}
	bool OnRuinGuardsKilledTimer()
	{
		LC1_CutsceneTakeRuins();
		return true;
	}

	bool OnZombieKilled(Creature& in Creatures)
	{
		Autosave();
		printNote("Zombie killed");
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q2_DefeatTraitors", "P1_Q2_KillUndeadGuardian", Completed );
		//m_Reference.GetCreaturesFromSpawn("LC1_Spawn_Undead")[0].DropItem(m_Reference, "LC1_DungeonKey", 1);
		m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "P1_Q3_BuildAnArmy", Completed );	
		
		return true;
	}

	bool OnTriggerUndead (Creature& in Creatures)
	{
		printNote("Undead Guardian triggered!");
		m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P1_Q2_DefeatTraitors", "P1_Q2_KillUndeadGuardian", true );

		//Put "Undead!" Shoutout of Bertrand from map 052 here

		return true;
	}

	bool OnLootedKey(const uint8 _uPlayerFaction, const string& in _ItemName, const uint _ItemCount)
	{
		printNote("Looted Key");
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P1_Q2_DefeatTraitors", "P1_Q2_LootUndeadGuardian", Completed );
		DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_EntranceFound", true);
		m_Reference.GetEntitiesByName("MapTransitions_LC_LCC1")[0].Enable(true);
		MapUnlock( "LC_C", true );

		return true;
	}

// -------------------------------------------------------------------------------------------------------------------
//----------------- V E R S I O N  2 ---------------------------------------------------------------------------------

	bool OnLC2_UtranLine_ChangeInLine()
	{
		// move the line
		// give the first dude free
		m_Reference.GetCreatureByName( m_arrLC2_UtranVillagers_CurrentLine[0] ).EnablePOIVisitingBehavior( true );
		m_Reference.GetCreatureByName( m_arrLC2_UtranVillagers_CurrentLine[0] ).SetImmovable( false );
		m_arrLC2_UtranVillagers_CurrentLine[0] = "<free>";

		for ( uint _iTmp = 1; _iTmp < m_arrLC2_UtranVillagers_CurrentLine.length() ; _iTmp++ )
		{
			// move the array
			Creature _crtTmp = m_Reference.GetCreatureByName( m_arrLC2_UtranVillagers_CurrentLine[_iTmp] );
			if ( m_arrLC2_UtranVillagers_CurrentLine[ _iTmp ] != "<free>" )
				_crtTmp.GoTo( m_Reference, m_Reference.GetLogicObjectByName( m_stgLC2_UtranVillagersPositions+(_iTmp-1) ), 0, 0, false, true );

			m_arrLC2_UtranVillagers_CurrentLine[ _iTmp-1 ] = m_arrLC2_UtranVillagers_CurrentLine[_iTmp];
			m_arrLC2_UtranVillagers_CurrentLine[ _iTmp ] = "<free>";
		}

		// check which spot is free and should get a new villager
		uint _iIndex = m_arrLC2_UtranVillagers_CurrentLine.find( "<free>" );
		if ( _iIndex > 0 )
		{
			// get the array, without getting those, that are already in line
			printNote("UTRAN BORDER LINE: next free spot: '"+m_stgLC2_UtranVillagersPositions+_iIndex+"'");

			array <string> _arrTmp = GetCreaturesFromSpawns_stg( m_arrStg_BorderRefugees );
			uint _iLength = m_arrLC2_UtranVillagers_CurrentLine.length();
			for ( uint _iTmp1 = 0; _iTmp1 < _iLength ; _iTmp1++ )
			{
				if ( m_arrLC2_UtranVillagers_CurrentLine[_iTmp1] != "<free>" )
				{
					uint _iIndex2 = _arrTmp.find( m_arrLC2_UtranVillagers_CurrentLine[_iTmp1] );
					_arrTmp.removeAt( _iIndex2 );
					_iLength = m_arrLC2_UtranVillagers_CurrentLine.length();
				}
			}

			Creature _crtTmp = m_Reference.GetCreatureByName( _arrTmp[ m_Reference.GetRandom().GetInteger(0, _arrTmp.length()) ] );
			_crtTmp.EnablePOIVisitingBehavior( false );
			_crtTmp.SetImmovable( true );
			_crtTmp.GoTo( m_Reference, m_Reference.GetLogicObjectByName( m_stgLC2_UtranVillagersPositions+_iIndex ), 0, 0, false, false);
			printNote("UTRAN BORDER LINE: Pos '"+m_stgLC2_UtranVillagersPositions+_iIndex+"' has villager '"+m_Reference.FindEntityName(_crtTmp)+"' standing there.");
		}

		m_Reference.SetTimer( TOnTimerEvent(@this.OnLC2_UtranLine_ChangeInLine), m_Reference.GetRandom().GetInteger( m_iLC2_UtranRefugees_Timer_min, m_iLC2_UtranRefugees_Timer_max) );

		return true;
	}

	bool OnLC2_NearTheRuins (Creature& in _Creature)
	{
		printNote("m_bLC2_EnteredNortanderCamp "+m_bLC2_EnteredNortanderCamp+", "+m_bLC2_AmbushHappened+" m_bLC2_AmbushHappened "+m_bLC2_NearRuinsTriggered+".");
		//if ( m_bLC2_EnteredNortanderCamp || m_bLC2_AmbushHappened || m_bLC2_NearRuinsTriggered )
		if ( m_bLC2_AmbushHappened || m_bLC2_NearRuinsTriggered )
			return true;

		if ( HeroPartyReadyForDialogue() )
		{
			m_bLC2_NearRuinsTriggered = true;
			DialogBantern( m_stgAvatar, m_stgAvatar, "LC2_BN_CloseInOnNortander", 0 );
			return true;
		}

		return false;
	}
	bool OnLC2_leaveMapToEverlight(Creature& in _Creature)
	{
		
		LC2SetRevisitState();
		//m_Reference.WinGame(m_iPlayerFaction);
		return true;
	}

	void LC2SetRevisitState()
	{
		// finishin all the revisit stuff.
		// - State 1
		if ( m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bNortanderFactionDefeated) == true ) //
		{
			m_Reference.GetBuildingByName( "Nortander_Outpost" ).Destroy();
			m_Reference.LoseGame( m_iLC2_FactionNortanderArmy );
			m_Reference.LoseGame( m_iLC2_FactionNortanderAssault );

			// State 1, Nortander defeated, and refugees saved
			if (m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bRefugeesSaved) == true)
			{
				// bandits roaming around, annoying the Refugees
				for ( uint _iTmp = 0; _iTmp < m_arrStg_Bandits.length() ; _iTmp++ )
					m_Reference.ActivateSpawn( m_arrStg_Bandits[_iTmp], true);

				for ( uint _iTmp = 0; _iTmp < m_arrStg_BanditsObjects.length() ; _iTmp++ )
					m_Reference.GetLogicObjectByName(m_arrStg_BanditsObjects[_iTmp]).Enable(true);

				// Purity
				m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel).Enable( false );
			}
			// State 2, Nortander defeated, and refugees NOT saved
			else
			{
				// corpses are still present
				// nortander is still gone, no changes, as they where destroyed by the army, and saved normally

				// purity - Betrand isn't present anymore
				m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel).Enable( false );
				for ( uint _iTmp = 0; _iTmp < m_arrStg_PuritySpawns.length() ; _iTmp++ )
					SpawnDespawn( m_arrStg_PuritySpawns[_iTmp] );
				for ( int _iTmp = 1; _iTmp <= m_iPurityClutter ; _iTmp++ )
					m_Reference.GetLogicObjectByName( m_stgPurityClutter + _iTmp ).Enable(false);
			}
		}
		// State 3, Nortander not defeated, Refugees not saved
		else
		{
			// let all the corpses of the refugees vanish
			for ( uint _iTmp = 0; _iTmp < m_arrStg_BorderRefugees.length() ; _iTmp++ )
				SpawnDespawn( m_arrStg_BorderRefugees[_iTmp] );
			for ( uint _iTmp = 0; _iTmp < m_arrStg_BorderRefugeesObjects_toVanish.length() ; _iTmp++ )
				m_Reference.GetLogicObjectByName(m_arrStg_BorderRefugeesObjects_toVanish[_iTmp]).Enable(false);
			for ( uint _iTmp = 0; _iTmp < m_arrStg_BorderRefugeesObjects_toAppear.length() ; _iTmp++ )
				m_Reference.GetLogicObjectByName(m_arrStg_BorderRefugeesObjects_toAppear[_iTmp]).Enable(true);

			// activating all the additional Nortander
			for ( uint _iTmp = 0; _iTmp < m_arrStg_NortanderRevisit.length() ; _iTmp++ )
				m_Reference.ActivateSpawn( m_arrStg_NortanderRevisit[_iTmp], true);
			m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel).Enable( false );
		}
	}

	
	bool OnLC2_IskanGuard_1(Creature& in _Creature)
	{
		return LC2IskanderGuardingSoldier( "LC2_CampGuard_01", "LC2_posIGuard_1", _Creature.GetDescriptionName() );
	}
	bool OnLC2_IskanGuard_2(Creature& in _Creature)
	{
		return LC2IskanderGuardingSoldier( "LC2_CampGuard_02", "LC2_posIGuard_2", _Creature.GetDescriptionName() );
	}

	bool OnLC2_nearUtranBorder(Creature& in _Creature)
	{
		DialogShoutout( m_stgLC2_crtUtranSoldier_1, m_stgLC2_crtUtranSoldier_1, "LC2_SO_RefugeeDiscussion", false );
		return true;
	}

	bool OnLC2_UtranGuard(Creature& in _Creature)
	{
		printNote("Nortander Guard, 1.");

		/*if ( _Creature.GetDescriptionName() == m_stgAvatar )
			DialogShoutout( m_stgLC2_crtUtranSoldier_1, m_stgLC2_crtUtranSoldier_1, "LC2_CurrentSituation", false );
		*/

		/*if ( _Creature.GetDescriptionName() == m_stgAvatar )
			DialogTalkTo( m_stgLC2_crtUtranSoldier_1, m_stgAvatar, m_stgLC2_crtUtranSoldier_1, "LC2_CurrentSituation" );
		else
			_Creature.GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_UGuardPnt" ).GetId() ), 0, 0, false );
		*/
		return false;
	}

	bool OnLC2_Guard_1 (Creature& in _Creature)
	{
		//if (m_bLC2_EnteredNortanderCamp || m_bLC2_AmbushHappened)
		if (m_bLC2_AmbushHappened)
			return true;

		printNote("Nortander Guard, 1.");
		// get the guard from the spawn
		string _stgTmp = "";
		array <Creature>@ _arrCrt_Guards = m_Reference.GetCreaturesFromSpawn( "LC2_CastleGuard_1" );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Guards.length() ; _iTmp++ )
		{
			if ( _arrCrt_Guards[_iTmp].GetDescriptionName() == m_stgLC2_crtNortanderGuard_1 )
				_stgTmp = m_Reference.FindEntityName(_arrCrt_Guards[_iTmp]);
		}
		printNote("found "+_stgTmp+", as he is a "+m_stgLC2_crtNortanderGuard_1+" and now going to talk to player");

		// now decide what should happen
		if( m_Reference.FindEntityName(_Creature) == m_stgAvatar )
		{
			DialogShoutout ( _stgTmp, m_stgLC2_crtNortanderGuard_1, "LC2_NoAccess", true );
			return true;
		}
		else 
			DialogShoutout ( _stgTmp, m_stgLC2_crtNortanderGuard_1, "LC2_NoAccess_NoAvatar", true );
		
		return false;
	}
	bool OnLC2_Guard_2 (Creature& in _Creature)
	{
		//if (m_bLC2_EnteredNortanderCamp || m_bLC2_AmbushHappened)
		if (m_bLC2_AmbushHappened)
			return true;

		printNote("Nortander Guard, 2.");
		LC2GuardingSoldier("LC2_CastleGuard_2", "LC2_NGuardPnt_2", _Creature.GetDescriptionName() );

		return false;
	}
	bool OnLC2_Guard_3 (Creature& in _Creature)
	{
		//if (m_bLC2_EnteredNortanderCamp || m_bLC2_AmbushHappened)
		if (m_bLC2_AmbushHappened)
			return true;

		printNote("Nortander Guard, 3.");
		LC2GuardingSoldier("LC2_CastleGuard_3", "LC2_NGuardPnt_3", _Creature.GetDescriptionName() );

		return false;
	}

	bool OnLC2_BearAmbush(Creature& in _Creature)
	{
		if (!m_bLC2_BearSwitch)
		{
			printNote("Bear Attack not ready yet!");
			return false;
		}

		printNote("Bear Attack!");

		// get the creature that walked into the trap
		Entity _entVictim = m_Reference.GetEntityById( _Creature.GetId() );

		// get spawned units
		CreatureGroup _crtBear01 ( m_Reference );
		_crtBear01.Set( m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpawnBearAmbush ) );

		// activate spawn
		m_Reference.ActivateSpawn (m_stgLC2_SpawnBearAmbush, true);

		//Attack Player
		_crtBear01.Move(_entVictim, false, false, false);

		return true;
	}

	bool LC2_OnResurrected_ClaraFarlorn(Creature& in _Creature)
	{
		if(m_bLC2_CaravanStarted)
		{
			LC2CaravanContinue();
		}

		return false;
	}
	bool LC2_OnRevivePeriodEnded_ClaraFarlorn(Creature& in _Creature)
	{
		printNote("OH NO! PLAYER LOST BECAUSE CLARA DIED!");
		m_Reference.LoseGame(m_iPlayerFaction);
		return true;
	}


	void LC2GuardingSoldier( string _stgSpawn, string _stgPoint, string _stgCreatureSteppedIn )
	{
		string _stgTmp = "";
		m_Reference.GetHeroParty( m_iPlayerFaction ).Stop();

		// 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_stgLC2_crtNortanderGuard_1 )
				_stgTmp = m_Reference.FindEntityName(_arrCrt_Guards[_iTmp]);
		}

		// 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, false );

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

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

		// now, let the soldier talk to the wanted
		if ( _stgCreatureSteppedIn == m_stgAvatar && m_bLC2_EnteredNortanderCamp == false )
			DialogTalkTo( _stgTmp, m_stgAvatar, m_stgLC2_crtNortanderGuard_1, "LC2_NoAccess" );
		else if ( m_Reference.GetCreatureByName( _stgTmp ).IsInDialogue() == false )
			DialogShoutout( _stgTmp, m_stgLC2_crtNortanderGuard_1, "LC2_NoAccess_NoAvatar", false);
	}
	bool LC2IskanderGuardingSoldier( string _stgSpawn, string _stgPoint, string _stgCreatureSteppedIn )
	{
		if ( m_bLC2_IskanderGuard )
			return true;

		string _stgTmp = "";
		m_Reference.GetHeroParty( m_iPlayerFaction ).Stop();
		m_Reference.GetCreatureByName(_stgCreatureSteppedIn).Stop( m_Reference );
		
		// get the guard from the spawn
		array <Creature>@ _arrCrt_Guards = m_Reference.GetCreaturesFromSpawn( _stgSpawn ); //m_Reference.FindCreaturesByDescription(8, m_stgLC2_crtLoyalistCampGuard);//m_Reference.GetCreaturesFromSpawn( _stgSpawn );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Guards.length() ; _iTmp++ )
		{
			if ( _arrCrt_Guards[_iTmp].GetDescriptionName() == m_stgLC2_crtLoyalistCampGuard )
				_stgTmp = m_Reference.FindEntityName(_arrCrt_Guards[_iTmp]);
		}
		
		printNote("Iskander Loyalist border - '"+_stgSpawn+"', '"+_stgCreatureSteppedIn+"', Party gathered '"+DialogCheck_IsGathered( false )+"' stepped in, Guard is '"+_stgTmp+"', ( generally stepped into camp: "+m_bLC2_IskanderGuard+" )");
		
		// check, if the dude is already talking.
		if ( m_Reference.GetCreatureByName(_stgTmp).IsInDialogue() == true )
			return false;

		// start dialogue, when the avatar stepped in, or if the hero party is gathered, which also means, that the avatar is present
		if ( (_stgCreatureSteppedIn == m_stgAvatar && DialogCheck_IsGathered( false )) || DialogCheck_IsGathered( false ) )
		{
			printNote("found "+_stgTmp+", as he is a "+m_stgLC2_crtLoyalistCampGuard+" and now going to talk to player");
			DialogShoutout( _stgTmp, m_stgLC2_crtLoyalistCampGuard, "LC2_LoyalistCampEntry", true );
			//m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtLoyalistCampGuard, "LC2_LoyalistCampEntry", true);
			m_bLC2_IskanderGuard = true;

			return true;
		}
		// if dialogue can't start -> simply give the gathered message, and let the hero walk back
		else 
		{
			DialogCheck_IsGathered( true );
			m_Reference.GetCreatureByName(_stgCreatureSteppedIn).ForceGoTo( m_Reference, m_Reference.GetLogicObjectByName(_stgPoint), 0, 0, false, false );
		}

		
		

		return false;
	}


	bool OnLC2_SentenzaAmbush (Creature& in _Creature)
	{
		printNote("Ambush scene from Sentenza.");

		HeroPartyUnequip_NotCutscene();
		HeroPartyAttackable(false);
		m_Reference.GetHeroParty(m_iPlayerFaction).Stop();

		array <Creature>@ _arrCrt_Ambush = m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Ambush.length() ; _iTmp++ )
			_arrCrt_Ambush[_iTmp].GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName(m_stgAvatar).GetId() ), 30, 50, true );

		// Simulate CUTSCENE. Is temporary, is going to be deleted later
		/*PlayerHeroControlDisable();
		HeroPartyUnequip_NotCutscene();
		HeroPartyAttackable(false);
		m_Reference.GetHeroParty(m_iPlayerFaction).Stop();

		DialogTalkTo( m_stgLC_crtSentenza, m_stgAvatar, m_stgLC2_tmpSentenzaCutscene, "LC2_SentenzasMotive" );

		array <Creature>@ _arrCrt_Ambush = m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Ambush.length() ; _iTmp++ )
			_arrCrt_Ambush[_iTmp].GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName(m_stgAvatar).GetId() ), 30, 50, true );

		// Cutscene with the SentenzaStroll dialogue
		// lets not script that. To lazy. Is going to be a cutscene anyway
		// i dont care how the content designers want this.
		*/

		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionNortanderArmy, Hostile);
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionNortanderAssault, Hostile);

		// State after the cutscene
		//m_Reference.SetTimer( TOnTimerEvent(@this.LC2_TMPCutsceneLoyalists), 10 );

		return true;
	}

	bool OnLC2_SentenzaAmbushDefeated (Creature& in _Creature)
	{
		printNote("Sentenza's men where defeated, Bertrand Carpel goes to the Loyalist Commander. Really this time now.");
		//HeroPartyResetToNormal();
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtLoyalistCommander, "LC2_AvatarSaved", true);

		m_Reference.SetTimer( TOnTimerEvent(@this.OnBertrandGoesToCommander), 2 );

		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).SetImmovable(false);
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).SetImmortal(false);

		return true;
	}
	bool OnBertrandGoesToCommander()
	{
		// m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).GetId() ), 10, 15, true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId() ), 5, 10, true );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId() ), 10, 15, true );

		return true;
	}

	bool OnLC2_SOiskanderAmbush(Creature& in _Creature)
	{
		printNote("IskanerAmbush");
		//DialogShoutoutReveal( m_stgLC2_crtLoyalistCommander, m_stgLC2_tmpSentenzaCutscene, "LC2_IskanderAttack" );
		//DialogShoutout( m_stgLC_crtSentenza, m_stgLC2_tmpSentenzaCutscene, "LC2_SentenzaOrders", false );

		return true;
	}

	bool OnLC2_NortanderWasDefeated(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		if ( _iPreviousOwner == m_iLC2_FactionNortanderArmy )
		{
			printNote("nortander is defeated");
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("SQ_011a_DefeatNortanderArmy", "SQ_011_C_c", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("SQ_011b_ProtectTheRefugees", "SQ_011b_ProtectRefugees", Completed );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_d", Completed );
			if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5c_GainHumans","SQ_011_InvTriggerFortressDone_Talk")) 
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "SQ_011_InvTriggerFortressDone_Talk", Completed );
			}
			
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );

			m_Reference.GetWorld().SetGlobalBool(m_stgGlobal_bNortanderFactionDefeated, true);
			
			// check if the caravan is already at the border
			//if ( m_Reference.GetWorld().GetGlobalBool( m_stgGlobal_bNortanderFactionDefeated) == true )
			if ( m_bLC2_stateCaravanArrived )
				LC2_LoyalistLeaderWalk();
			else if ( m_bLC2_CaravanStarted == false )
			{
				m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_NortanderDefeated", true);
				m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_FirstContact", false);
				m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_RouteCleared", false);
			}

			m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave ).Enable( false );

			DialogBantern( m_stgAvatar, m_stgAvatar, "LC2_BN_FortressDestroyed", 0);
			m_bLC2_NortanderDeafeated = true;

			printNote("Destroyed Nortander HQ");
			m_Reference.LoseGame( m_iLC2_FactionNortanderArmy );
			m_Reference.LoseGame( m_iLC2_FactionNortanderAssault );

			A_UnlockAchievement("SF3_SP_LC_DefeatNortander");

			if (m_bLC2_CaravanWentToNextMap)
				m_Reference.SetTimer( TOnTimerEvent(@this.OnLC2_TimedSO_FinishedHere), 10 );

			return true;
		}
		return false;
	}

	bool OnLC2_TimedSO_FinishedHere ()
	{
		if ( HeroPartyReadyForDialogue() )
		{
			DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_MapCleared", false);
			m_Reference.GetWorld().EnableDialogueTopic( "Human_Architect", "LC2_PickUp", true );
			return true;
		}
		return false;
	}

	// SECURE THE ROAD (MQ_11e)
	bool OnLC2_ChangeOwnerRouteOne(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		printNote("Route one, the sector "+_Sector.GetName()+" was taken by the faction "+_iNewOwner+", old owner was "+_iPreviousOwner);

		// Player has concuered the sector
		if (_iNewOwner == m_iPlayerFaction)
			m_iLC2_SectorRouteOne_freed++;
		// Player has lost the sector to someone else
		else if ( _iPreviousOwner == m_iPlayerFaction)
			m_iLC2_SectorRouteOne_freed--;

		if (_Sector.GetName() == "Sector_13")
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_sect_13", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_500", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_500", Completed );
		}
		else if (_Sector.GetName() == "Sector_09")
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_sect_9", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_500", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_500", Completed );
		}
		else if (_Sector.GetName() == "Sector_08")
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_sect_8", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_500", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_500", Completed );
		}
		else if (_Sector.GetName() == "Sector_05")
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_sect_5", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_500", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_500", Completed );
		}
		else if (_Sector.GetName() == "Sector_04")
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_sect_4", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_500", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_500", Completed );
		}
		else if (_Sector.GetName() == "Sector_01")
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_sect_1", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_500", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_500", Completed );
		}

		// check, if the complete route is freed (one)
		LC2_CheckCaravanRoads();

		return false;
	}

	bool OnLC2_ChangeOwnerRouteTwo(Sector@ _Sector, const uint8 _iPreviousOwner, const uint8 _iNewOwner)
	{
		printNote("Reoute two, The sector "+_Sector.GetIndex()+" was taken by the faction "+_iNewOwner+", old owner was "+_iPreviousOwner);

		// Player has concuered the sector
		if (_iNewOwner == m_iPlayerFaction)
			m_iLC2_SectorRouteTwo_freed++;
		// Player has lost the sector to someone else
		else if ( _iPreviousOwner == m_iPlayerFaction)
			m_iLC2_SectorRouteTwo_freed--;

		// check, if the complete route is freed (two)
		LC2_CheckCaravanRoads();

		return false;
	}

	bool OnLC2_DespawnMilitia (Creature& in _Creature)
	{
		_Creature.Enable( false );
		string _stgGlobal_TypeCount = m_glbCat_FH_savedMilitia+"."+_Creature.GetDescriptionName();
		// count this kind of militia dude up - used for everlight
		m_Reference.GetWorld().SetGlobalInt(_stgGlobal_TypeCount, (m_Reference.GetWorld().GetGlobalInt(_stgGlobal_TypeCount) + 1) );

		printNote("Militia dude went to everlight, type "+_Creature.GetDescriptionName()+", now having "+m_Reference.GetWorld().GetGlobalInt( _stgGlobal_TypeCount )
			+" saved of them.");

		return false;
	}
	bool OnLC2_DespawnVillagers (Creature& in _Creature)
	{
		_Creature.Enable( false );
		_Creature.Kill();

		string _stgGlobal_VillagerTypeCount = m_glbCat_FH_savedVillagers+"."+_Creature.GetDescriptionName();
		// count the whole number of villagers saved up - used by the Writer
		m_Reference.GetWorld().SetGlobalInt(m_stgGlobal_iSavedVillagers, (m_Reference.GetWorld().GetGlobalInt(m_stgGlobal_iSavedVillagers) + 1) );
		// count this kind of villager up - used for LC2
		m_Reference.GetWorld().SetGlobalInt(_stgGlobal_VillagerTypeCount, (m_Reference.GetWorld().GetGlobalInt(_stgGlobal_VillagerTypeCount) + 1) );

		printNote("Next villager went to everlight, type "+_Creature.GetDescriptionName()+", now having "+m_Reference.GetWorld().GetGlobalInt( _stgGlobal_VillagerTypeCount )
			+" saved of them and in total "+m_Reference.GetWorld().GetGlobalInt( m_stgGlobal_iSavedVillagers )+" Villagers.");

		return false;
	}

	bool OnLC2_VillagerDied (Creature& in _Creature)
	{
		if ( _Creature.IsEnabled() == true )
		{
			if(_Creature.GetDescriptionName() == "FH2_VillagerCarriage")
			{
				m_Reference.GetWorld().SetGlobalInt("MapVariables.FH_CountCarriagesLost", (m_Reference.GetWorld().GetGlobalInt("MapVariables.FH_CountCarriagesLost") + 1) );
				printNote("it was a carriage!");
			}
			else 
			{
				m_Reference.GetWorld().SetGlobalInt(m_stgGlobal_iVillagersDied, (m_Reference.GetWorld().GetGlobalInt(m_stgGlobal_iVillagersDied) + 1) );
			}
			printNote("A villager died.");
			m_iLC2_VillagersDied++;
			

			if (m_iLC2_VillagersDied == m_iLC2_VillagersDied_Max)
				m_Reference.LoseGame( m_iPlayerFaction );
		}
		return false;
	}

	bool OnLC2_RefugeeDied(Creature& in _Creature)
	{
		_Creature.SetPreserveBody( true );
		if ( _Creature.IsEnabled() == true )
		{
			printNote("Again a refugee died, now "+m_iLC2_RefugeesDied+" from "+m_iLC2_RefugeesTotal+" where killed");

			m_iLC2_RefugeesDied++;
			m_Reference.GetWorld().SetGlobalInt(m_stgGlobal_iRefugeesDied, (m_Reference.GetWorld().GetGlobalInt(m_stgGlobal_iRefugeesDied) + 1) );
			if (m_iLC2_RefugeesDied == m_iLC2_RefugeesTotal)
			{
				printNote("All refugees died");
				m_Reference.GetWorld().SetGlobalBool( m_stgGlobal_bRefugeesSaved, false);
				m_Reference.GetBuildingByName( m_stgLC2_BldgNortanderAttackRefugees).Enable( false );
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("SQ_011b_ProtectTheRefugees", "SQ_011b_ProtectRefugees", Failed );
			}
		}
		return false;
	}

	bool m_bLC2_LoyalistLeaderArrived = false;
	bool OnLC2_IskanderLeaderCheck(Creature& in _Creature)
	{
		if ( m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bNortanderFactionDefeated) == true )
			LC2_LoyalistLeaderWalk();

		return true;
	}
	void LC2_LoyalistLeaderWalk()
	{
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).Stop(m_Reference);
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).GoTo( m_Reference, m_Reference.GetLogicObjectByName( "LC2_PosEndIskanderLeader" ), 0, 0, false);
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).EnablePOIVisitingBehavior(false);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnLC2_IskanderLeaderArrived), m_stgLC2_crtLoyalistLeader, "LC2_EndCaravan");
	}
	bool OnLC2_IskanderLeaderArrived(Creature& in _Creature)
	{
		m_bLC2_LoyalistLeaderArrived = true;
		if ( m_bLC2_stateCaravanArrived && m_bLC2_LoyalistLeaderArrived)
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_BorderNortanderDefeated", true);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_BorderNortanderAlive", false);
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );
		}
		return true;
	}
	bool OnLC2_CaravanArrived(Creature& in _Creature)
	{
		printNote("Caravan arrived at the border");
		m_bLC2_stateCaravanArrived = true;

		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosEndClara" ).GetId() ), 0, 0, false );
		//m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosEndClara" ).GetId() ), 10, 20, false );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).Stop(m_Reference);
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).EnablePOIVisitingBehavior(true);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "SQ_011_E", Completed );

		if ( m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bNortanderFactionDefeated) == true )
		{
			if ( m_bLC2_stateCaravanArrived && m_bLC2_LoyalistLeaderArrived)
			{
				m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_BorderNortanderDefeated", true);
				m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_BorderNortanderAlive", false);
				//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
				//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );
			}
		}
		else
		{
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_BorderNortanderDefeated", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_BorderNortanderAlive", true);
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );
		}

		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHVillagerSpawns.length(); _iTmp++ )
		{
			CreatureGroup _crtVillagers ( m_Reference );
			_crtVillagers.Set( m_Reference.GetCreaturesFromSpawn( m_arrStg_FHVillagerSpawns[_iTmp] ) );
			_crtVillagers.Move( m_Reference.GetLogicObjectByName( "LC2_PosEndCaravan" ), false );

			if (m_arrStg_FHVillagerSpawns[_iTmp] == "FH2_Carriages")
				SetPOICategoriesSpawn( m_arrStg_FHVillagerSpawns[_iTmp], array<string>={"LC2_CaravanFinal_Carriages"});
			else
				SetPOICategoriesSpawn( m_arrStg_FHVillagerSpawns[_iTmp], array<string>={"LC2_CaravanFinal"});

			EnablePOIVisitingBehaviorSpawn( m_arrStg_FHVillagerSpawns[_iTmp], true );
		}

		SetPOICategoriesSpawn( "FH2_Carriages", array<string>={"LC2_CaravanFinal_Carriages"});

		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHMilitiaSpawns.length() ; _iTmp++ )
		{
			CreatureGroup _crtMilitia ( m_Reference );
			_crtMilitia.Set( m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp] ) );

			array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp] );
			for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length(); _iTmp2++ )
				_arrCrt[_iTmp2].GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosEndMilitia" ).GetId() ), 0, 0, false );
			// _crtMilitia.Move( m_Reference.GetLogicObjectByName( "LC2_PosEndMilitia" ), true );
		}


		return true;
	}

	bool OnLC2_StartMilitiaFollow(Creature& in _Creature)
	{
		if ( m_bLC2_CaravanStarted )
		{
			printNote("Militia starting to follow the Loyalist Leader");
			FH2_SendMilitia();
			FH2_SendCaravanWagons();
			return true;
		}

		return false;
	}

	bool OnLC2_NortanderFollowTimerRunnedOut()
	{
		printNote("Timer is through.");
		m_bLC2_CaravanWentToNextMap = true;

		if ( m_bLC2_NortanderDeafeated )
			DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_MapCleared", true);
		else
		{
			DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_NortanderChase_Finished", true);
			if (m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P3_Q5c_GainHumans","SQ_011_InvTriggerFortressNOTDone_Talk")) 
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "SQ_011_InvTriggerFortressNOTDone_Talk", Completed );
			}			
		}
			
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "SQ_011_E_a", Completed );
		LC2_CoveredRefugees();
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_3000", true );
		//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_3000", Completed );

		//m_Reference.WinGame(m_iPlayerFaction);

		return true;
	}

	bool OnLC2_NortanderChase_SO1()
	{
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_NortanderChase_HalfWay", true);
		return true;
	}
	bool OnLC2_NortanderChase_SO2()
	{
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_NortanderChase_AlmostFinished", true);
		return true;
	}

	bool OnLC2_NortanderChase_SoldierGotThrough(Creature& in _Creature)
	{
		_Creature.Enable( false );
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_NortanderChase_Danger", true);
		m_iLC2_NortanderFollowSoldiers++;
		m_Reference.GetWorld().SetGlobalInt(m_stgGlobal_iNortanderSoldeiers, (m_Reference.GetWorld().GetGlobalInt(m_stgGlobal_iNortanderSoldeiers) + 1) );

		if (m_iLC2_NortanderFollowSoldiers == m_iLC2_NortanderFollowSoldiers_Max)
			m_Reference.LoseGame( m_iPlayerFaction );

		return false;
	}

	bool OnLC2_NortanderChase_WaveSpawn(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote("Nortander chase, next wave spawned. Letting them walk to the border to everlight.");

		for( uint _iTmp2 = 0; _iTmp2 < _Creatures.length(); _iTmp2++ )
			_Creatures[_iTmp2].FollowPath(m_Reference, m_stgLC2_pathNortanderChase, true, false, false);

		/*CreatureGroup _crtGrpAttack ( m_Reference );
		_crtGrpAttack.Set( _Creatures );
		_crtGrpAttack.FollowPathSmooth( m_stgLC2_pathNortanderChase, true, true );*/

		m_Reference.RegisterCreatureEventByIndividuals( EnteredArea, TOnCreatureEvent(@this.OnLC2_NortanderChase_SoldierGotThrough), _Creatures, true, m_stgLC2_TrgCaravanEscape );

		return false;
	}

	bool OnLC2_IskanderDudesArrivedAtCamp(Creature& in _Creature)
	{
		if ( _Creature.GetFaction() == m_iLC2_FactionIskanderLoyalists)
			_Creature.EnablePOIVisitingBehavior( true );
		else
			return true;

		//EnablePOIVisitingBehaviorSpawn( m_stgLC2_SpwnLoyalistAmbush, false );
		return false;
	}


	bool OnLC2_WaveSpawn_IskAtkNortander(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote("Nortander chase, next wave spawned. Letting them walk to the border to everlight.");
		CreatureGroup _crtGrpAttack ( m_Reference );
		_crtGrpAttack.Set( _Creatures );
		_crtGrpAttack.FollowPathSmooth( m_stgLC2_pathNeutralAttack, true, true, kMaxFactions, WaitForAnyHeroes, true, false );

		m_Reference.RegisterCreatureEventByIndividuals( FollowPathFinished, TOnCreatureEvent(@this.OnLC2_WaveSpawn_StopWaves), _Creatures, true, "" );
		
		return false;
	}
	bool OnLC2_WaveSpawn_NorAtkIskander(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote("Nortander chase, next wave spawned. Letting them walk to the border to everlight.");
		CreatureGroup _crtGrpAttack ( m_Reference );
		_crtGrpAttack.Set( _Creatures );
		_crtGrpAttack.FollowPathSmooth( m_stgLC2_pathNeutralAttack, false, true, kMaxFactions, WaitForAnyHeroes, true, false );
		m_Reference.RegisterCreatureEventByIndividuals( FollowPathFinished, TOnCreatureEvent(@this.OnLC2_WaveSpawn_StopWaves), _Creatures, true, "" );

		return false;
	}
	bool OnLC2_WaveSpawn_StopWaves(Creature& in _Creature)
	{
		//m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Nortander).Enable(false);
		//m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Iskander).Enable(false);
		_Creature.Kill();
		
		return true;
	}

	bool LC2_NortanderBarakcsDestroyed(Building&in _Building)
	{
		m_Reference.GetBuildingByName( m_stgLC2_BldgNortanderAttackRefugees ).Destroy();
		m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave ).Destroy();
		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Nortander ).Destroy();
		return true;
	}

	bool OnLC2_WaveSpawn_NorAtkRefugees(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote("Nortander refugee attack, next wave spawned. ");

		CreatureGroup _crtGrpAttack ( m_Reference );
		_crtGrpAttack.Set( _Creatures );
		_crtGrpAttack.FollowPathSmooth( m_stgLC2_PathgNortanderAttackRefugees, true, true );

		// when they finish their path, trigger this event
		m_Reference.RegisterCreatureEventByIndividuals(FollowPathFinished, TOnCreatureEvent(@this.OnLC2_WaveSpawn_NorAtkRefugees_Finished), _Creatures, true, "");

		return false;
	}
	bool OnLC2_WaveSpawn_NorAtkRefugees_Finished(Creature& in _Creature)
	{
		_Creature.SetFaction( m_iLC2_FactionNortanderArmy );
		_Creature.FollowPath(m_Reference, m_stgLC2_PathgNortanderAttackRefugees, false, true, false );

		return false;
	}

	bool OnLC2_ItemMedicine( const uint8 _uPlayerFaction, const string& in _ItemName, const uint _ItemCount )
	{
		printNote("Inspected the medicine. ");
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems(m_stgLC2_ItemSecretLetter, 1);
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_FoundSecretNote", false);
		m_Reference.GetWorld().BlockDialogueTopicNode( m_stgLC2_crtClaraFarlorn, "E0E33F37" ); // when you didn't see the
		m_Reference.GetWorld().UnblockDialogueTopicNode( m_stgLC2_crtClaraFarlorn, "B0C0C23B" ); // when you saw the letter

		m_Reference.RegisterHeroPartyEvent(AllOutside, TOnHeroPartyEvent(@this.OnLC2_BN_MedicineComment), "LC2_PurityCamp", m_iPlayerFaction);

		return true;
	}

	bool OnLC2_BN_MedicineComment(Creature& in _Creature)
	{
		DialogBantern( m_stgAvatar, m_stgAvatar, "LC2_BN_MedicineComment", 0 );
		return true;
	}

	bool OnLC2_ItemLetter( const uint8 _uPlayerFaction, const string& in _ItemName, const uint _ItemCount )
	{
		printNote("Read the letter. ");
		m_Reference.GetWorld().UnblockDialogueTopicNode( m_stgHero_Bertrand, "D0EDFB76" );
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_ReadSecretNote", false );
		return true;
	}


	bool OnLC2_SOClaraAmbush(Creature& in _Creature)
	{
		if (m_bLC2_ClaraAmbush)
			return true;

		printNote("Clara Ambush Shoutout");
		m_bLC2_ClaraAmbush = true;
		DialogShoutout( m_stgLC2_crtClaraFarlorn, m_stgLC2_crtClaraFarlorn, "LC2_Caravan_Assault", false);
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnLC2_SOClaraAmbushCleared), m_Reference.GetCreaturesFromSpawn(m_stgLC2_AssaultSpawn), false, "");
		LC2CaravanStop();
		return true;
	}
	bool OnLC2_SOClaraAmbushCleared(Creature& in _Creature)
	{
		printNote("Clara Ambush Shoutout - cleared the ambush");
		DialogShoutout( m_stgLC2_crtClaraFarlorn, m_stgLC2_crtClaraFarlorn, "LC2_Caravan_AmbushSurvived", false);
		LC2CaravanContinue();
		return true;
	}


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

	void ArticyLC1_SetUpRTS()
	{
		HeroPartyJoin( m_stgHero_Bertrand );

		//Skill Bertrand
		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Bertrand), "ArcheryPerk");
		m_Reference.GetHeroParty(m_iPlayerFaction).UnlockHeroAbility( m_Reference.GetCreatureByName( m_stgHero_Bertrand), "AimedShot");		

		// Randomply initiate the bantern, after the RTS is through.
		DialogBantern( m_stgHero_Gwen, m_stgHero_Gwen, "LC1_SO_Banter", m_Reference.GetRandom().GetInteger( 180, 240 ) );
		DialogBantern( m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_BN_Rebellion", m_Reference.GetRandom().GetInteger( 300, 350 ) );

		//Initialize Bertrands Attributes
		//InitializeBertrand( m_stgHero_Bertrand );
		LC1_GuardsGatherCutscene();
	}
	void ArticyLC1_LetsGo()
	{
		printArticy( "Call, which makes the Barricade attackable" );

		m_Reference.GetBuildingByName("LC1_Barricade").SetAttackable( true );
		m_Reference.GetBuildingByName("LC1_Barricade").SetInteractive( false );
		m_Reference.EnableGroup( "LC1_Barricade_effect", false );
		m_bBarricadeDestroyable = true;
	}


	void ArticyLC2_StartExploring()
	{
		Autosave();
	}
	bool m_bLC2_IskanderGuard = false;
	void ArticyLC2_IskanderGuardFinished()
	{
		m_bLC2_IskanderGuard = true;
	}
	void ArticyLC2_UtranRefugeeFinished()
	{
		printArticy("Utran refugee dialoge is finished, lettim him walk away.");
		m_Reference.GetCreatureByName( m_stgLC2_crtUtranRefugeeMan ).EnablePOIVisitingBehavior(true);

		OnLC2_UtranLine_ChangeInLine();
	}
	void ArticyLC2_UtranBorder()
	{
		printArticy("Letting the hero party walk back to the point, after talkting with the Utron soldiers.");
		CreatureGroup _arrTmpCrts ( m_Reference );
		_arrTmpCrts.Set( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers() );
		_arrTmpCrts.Move(m_Reference.GetLogicObjectByName( "LC2_UGuardPnt" ), false, true, false);
	}

	void ArticyLC2_AfterSecretMeeting()
	{
		printArticy("Secret Meeting with Bertrand Carpel happened - now preparing the Sentenza Ambush.");
		m_bLC2_AmbushHappened = true;
		//m_Reference.RegisterHeroPartyEvent(AnyOutside, TOnHeroPartyEvent(@this.OnLC2_SentenzaAmbush), m_stgLC2_TrgSmallCmap_Ent_1, 0);

		Creature _crtSentenza = m_Reference.GetCreatureByName(m_stgLC_crtSentenza);
		_crtSentenza.Enable( true );
		_crtSentenza.EnablePOIVisitingBehavior( false );
		_crtSentenza.Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLC2_PosSentenza_Ambush).GetId()) );

		m_Reference.ActivateSpawn( m_stgLC2_SpwnSentenzaAmbush, true);
		m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel).FollowCreature(m_Reference, m_Reference.GetCreatureByName(m_stgAvatar), 10, 30, true);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtBertrandCarpel, "LC2_SecretMeeting", false);

		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnLC2_SentenzaAmbushDefeated), m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush ), false, "" );

		printCutscene("Starting to play the cutscene 'LC2_SentenzaAmbush1'.");
		m_Reference.PlayCutScene("LC2_SentenzaAmbush1");
		HeroPartyUnequip_NotCutscene();
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_011", "MQ_011_B", Completed );

		HeroPartyUnequip_NotCutscene();
		HeroPartyAttackable(false);
		m_Reference.GetHeroParty(m_iPlayerFaction).Stop();

		array <Creature>@ _arrCrt_Ambush = m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush );
		for ( uint _iTmp = 0; _iTmp < _arrCrt_Ambush.length() ; _iTmp++ )
			_arrCrt_Ambush[_iTmp].GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName(m_stgAvatar).GetId() ), 70, 90, true );

		m_Reference.GetLogicObjectByName( m_stgLC2_objFortEntrangeDoor ).SetToggleState( true );

		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionNortanderArmy, Hostile);
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionNortanderAssault, Hostile);
	}

	void ArticyLC2_CommanderTalk ()
	{
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).GetId() ), 10, 15, true );
	}
	void ArticyLC2_SentenzaFlees()
	{
		printArticy("Loyalist Ambush; Sentenza is fleeing.");
		Creature _crtSentenza = m_Reference.GetCreatureByName(m_stgLC_crtSentenza);
		_crtSentenza.FollowPath( m_Reference, m_stgLC2_PathSentenza_Fleeing, true, false, false );

		//LC2_TMPsentenzaFlees
		m_Reference.RegisterCreatureEventByIndividual(EnteredSector, TOnCreatureEvent(@this.OnDespawnCreature), m_stgLC_crtSentenza, m_stgLC2_SectNortanderCamp);

		DialogShoutout( m_stgLC_crtSentenza, m_stgLC2_tmpSentenzaCutscene, "SentenzaFlees", false );
		_crtSentenza.SetAttackable(false);
		_crtSentenza.AllowAttacks(false);
	}

	void ArticyLC2_AfterIskanderAmbushScene()
	{
		printArticy("IskanderAmbush is finished, and the dude talked with the player.");

		CreatureGroup _crtGrpLoyalists ( m_Reference );
		_crtGrpLoyalists.Set( m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ) );
		_crtGrpLoyalists.Move( m_Reference.GetEntityById( m_Reference.GetLogicObjectByName(m_stgLC2_PosIskanderCamp).GetId() ), true, false, false );

		DialogTalkTo( m_stgLC2_crtBertrandCarpel, m_stgAvatar, m_stgAvatar, "LC2_AssessSituation");
		// m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionNortanderAssault, Hostile);
	}
	void ArticyLC2_AfterIskanderAmbushScene_Bertrand()
	{
		printArticy("Now let Bertrang walk back.");
		m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).GetId() ), 10, 15, false );
		HeroPartyAttackable(true);

		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("MQ_011", "MQ_011_C_a", true );

		//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
		//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );
	}

	void ArticyLC2_TalkedWithIskanderLeader()
	{
		AutosaveTimed(1);
		printArticy("Player talked with the Leader of the Iskander and finished MQ_11d. Now starting the RTS part.");

		// Bertrand Carpel, to Purity Camp
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLC2_PosPurityCamp ).GetId() ), 10, 20, false );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).SetAttackable( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).AllowAttacks( false );

		// Iskander scout, to Clara
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).GetId() ), 10, 20, false );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).SetAttackable( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).AllowAttacks( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).EnablePOIVisitingBehavior( false );

		// starting RTS
		// Prepare the RTS gameplay later
		//m_Reference.GetBuildingByName( m_stgLC2_SectLoyalistCamp_Center ).AddResources( Planks, m_iStartingPlanks );
		//m_Reference.GetBuildingByName( m_stgLC2_SectLoyalistCamp_Center ).AddResources( Food, m_iStartingFood );
		Sector@ StartSector = m_Reference.GetSectorByName( m_stgLC2_SectLoyalistCamp );
		StartSector.SetOwner( m_iPlayerFaction );
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionIskanderLoyalists, Allied );

		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Nortander).Enable(false);
		m_Reference.GetBuildingByName( m_stgLC2_bldgNeutral_Iskander).Enable(false);

		m_Reference.GetLogicObjectByName( "LC_FortEntranceDoor_1" ).Enable(false);
		m_Reference.GetLogicObjectByName( "LC_FortEntranceDoor_2" ).SetToggleState(true);

		// managing, that this dude
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_01")[0].SetHelpUpAllowed (false);
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_02")[0].SetHelpUpAllowed (false);
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_01")[0].SetAutoRevive(false);
		m_Reference.GetCreaturesFromSpawn("LC2_CampGuard_02")[0].SetAutoRevive(false);

		// Giving blueprints
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Capital_II", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Expansion_II", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Farm", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_IronMine", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_IronSmeltery", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Smith", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_WoodenTower_II", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Helebardier", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Marksman", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Scout", 1 );
		//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Soldier", 1 );
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Capital_I", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Capital_II", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Expansion_I", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Expansion_II", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Woodcutter", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Stonecutter", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_HuntingCabin", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_FishingCabin", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Barracks", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Farm", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_IronMine", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_IronSmeltery", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Smith", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_WoodenTower_I", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_WoodenTower_II", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Helebardier", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Marksman", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Scout", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Soldier", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Recruit", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Pillager", true);


		// start the waves for the border refugees
		//m_Reference.GetBuildingByName( m_stgLC2_BldgNortanderAttackRefugees).Enable( true );

		// give the FH-Militia to the player
		// LC2_GiveMilitiaToPlayer();


		// Enemy RTS?
		EnemyAI_Start( m_iLC2_FactionNortanderArmy );
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iLC2_FactionNortanderArmy, Hostile);

		// Fill later
		// start assault timer
		m_stgLC2_AssaultSpawn = m_stgLC2_SpwnAssault_01;
		m_Reference.SetTimer( TOnTimerEvent(@this.LC2_SetAssault_2 ), m_iLC2_AssaultTime_01 );
		m_Reference.SetTimer( TOnTimerEvent(@this.LC2_SetAssault_3 ), m_iLC2_AssaultTime_02 );

		//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_011", "MQ_011_C_a", Completed );
		//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_011", "MQ_011_C_b", Completed );
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_3000", true );
		//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_3000", Completed );

		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("MQ_011", "MQ_011_C_d", true);
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("MQ_011", "MQ_011_C_d", true);
	}

	void ArticyLC2_RecievingMedicine()
	{
		//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_011", "SQ_011_A", Completed );
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
		//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );

		m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("MQ_011", "MQ_011_A_ToClara", true );

		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems(m_stgLC2_ItemMedicine, 1);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_ReturnWithMedicine", true);

		//Thorsten Ambush
		printNote("Villager Bandit spawns active!");
		m_Reference.ActivateSpawn (m_stgLC2_SpawnVillagerBandits1, true);
		m_Reference.ActivateSpawn (m_stgLC2_SpawnVillagerBandits2, true);
	}

	bool LC2_SetAssault_2 ()
	{
		m_stgLC2_AssaultSpawn = m_stgLC2_SpwnAssault_02;
		return true;
	}
	bool LC2_SetAssault_3 ()
	{
		m_stgLC2_AssaultSpawn = m_stgLC2_SpwnAssault_03;
		return true;
	}

	void ArticyLC2_StartCaravan()
	{
		printArticy("Player taltked with Clara, caravan is starting their migration to everlight.");
		printArticy("They are walking on the route '"+m_stgLC2_StartedOnRoute+"', '"+m_stgLC2_RouteAssault+"'" );
		Autosave();

		m_bLC2_CaravanStarted = true;

		if ( m_stgLC2_AssaultSpawn == "" )
			m_stgLC2_AssaultSpawn = m_stgLC2_SpwnAssault_01;

		if ( m_stgLC2_StartedOnRoute == "" )
  			m_stgLC2_StartedOnRoute = m_stgLC2_PathSectorRouteOne;

 		if ( m_stgLC2_RouteAssault == "" )
  		 	m_stgLC2_RouteAssault = m_stgLC2_PathSectorRouteOneAssault;

		// send the two NPCs after the militia, Set up the Loyalist Leader and Clara
		int _iTimer = 2;
		int _iTimerAdd = 1;

		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_FirstContact", false);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_RouteCleared", false);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_NortanderDefeated", false);
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).SetAttackable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).AllowAttacks( false );
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).EnablePOIVisitingBehavior( false );

		// sending the Loyalist Leader
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).SetAttackable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).AllowAttacks( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).EnablePOIVisitingBehavior( false );
		//m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).FollowPath( m_Reference, m_stgLC2_StartedOnRoute, true, true, false );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistScout ).FollowCreature(m_Reference, m_Reference.GetCreatureByName(m_stgLC2_crtClaraFarlorn), m_iLC2_CaravanFollow_gotoMax, m_iLC2_CaravanFollow_gotoMin, true, false);
		_iTimer = _iTimer + _iTimerAdd;

		// first distance part
		m_iLC2_CaravanFollow_gotoMin = m_iLC2_CaravanFollow_gotoMin + 45;
		m_iLC2_CaravanFollow_gotoMax = m_iLC2_CaravanFollow_gotoMax + 30;

		// Starting to Clara
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).FollowPath( m_Reference, m_stgLC2_StartedOnRoute, true, true, false );
		//m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).FollowCreature(m_Reference, m_Reference.GetCreatureByName(m_stgLC2_crtLoyalistScout), m_iLC2_CaravanFollow_gotoMax, m_iLC2_CaravanFollow_gotoMin, true, false);
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).EnablePOIVisitingBehavior( false );

		// still thinking - would it make sense, to not send the groups via followpath, but instead with follow creature?
		m_iSendVillagerGroup = 0;
		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHVillagerSpawns.length() ; _iTmp++ )
		{
			// m_Reference.SetTimer( TOnTimerEvent(@this.FH2_SendNextGroup), _iTimer );
			m_Reference.SetTimer( TOnTimerEvent(@this.FH2_SendNextGroup_Follow), _iTimer );
			_iTimer = _iTimer + _iTimerAdd;
		}

		// Start the assault, if the nortander army wasn't defeated
		if ( m_Reference.GetWorld().GetGlobalBool( m_stgGlobal_bNortanderFactionDefeated) == false )
		{
			m_Reference.ActivateSpawn( m_stgLC2_AssaultSpawn, true);
			CreatureGroup _crtNortanderAssault ( m_Reference );
			_crtNortanderAssault.Set( m_Reference.GetCreaturesFromSpawn( m_stgLC2_AssaultSpawn ) );
			_crtNortanderAssault.FollowPath( m_stgLC2_RouteAssault, true, true, false );

			array <Creature> _arrTmp = m_Reference.GetCreaturesFromSpawn( m_stgLC2_AssaultSpawn );
			for( uint _iTmp = 0; _iTmp < _arrTmp.length(); _iTmp++ )
				m_Reference.RegisterCreatureEventByIndividual(CanSee, TOnCreatureEvent(@this.OnLC2_SOClaraAmbush), m_stgLC2_crtClaraFarlorn, m_Reference.FindEntityName( _arrTmp[_iTmp] ) );
		}

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "SQ_011_D", Completed );
	}
	
	void ArticyLC2_CaravanArrivedAndTalkingFinished()
	{
		// To Everlight!
		printArticy("Militia and Villagers where saved.");
		Autosave();

		// let the loyalist dude go back to his camp
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName("LC2_PosIskanderCamp").GetId() ), 0, 0, false );
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName("LC2_PosDespawn").GetId() ), 0, 0, false );

		// let villagers and militia walk to the border and vanish
		m_iSendVillagerGroup = 0;
		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHVillagerSpawns.length() ; _iTmp++ )
		{
			CreatureGroup _crtVillagers ( m_Reference );
			_crtVillagers.Set( m_Reference.GetCreaturesFromSpawn( m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup] ) );
			_crtVillagers.Move( m_Reference.GetLogicObjectByName( "LC2_PosDespawn" ), true, false );
			EnablePOIVisitingBehaviorSpawn(m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup], false);

			m_iSendVillagerGroup++;
		}

		for ( uint _iTmp = 0; _iTmp < m_arrStg_FHMilitiaSpawns.length() ; _iTmp++ )
		{
			array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp] );
			for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length(); _iTmp2++ )
				_arrCrt[_iTmp2].GoTo( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosDespawn" ).GetId() ), 0, 0, false );
		}

		// let the Nortander chase begin - if they are still present
		if ( m_Reference.GetWorld().GetGlobalBool( m_stgGlobal_bNortanderFactionDefeated) == false )
		{
				// starting the visual timer
			//m_Reference.CreateCountdownTimer(0, m_iLC2_NortanderFollowAssault, TOnTimerEvent(@this.OnLC2_NortanderFollowTimerRunnedOut), m_iPlayerFaction);
			m_Reference.CreateCountdownTimer(0, m_iLC2_NortanderFollowAssault, TOnTimerEvent(@this.OnLC2_NortanderFollowTimerRunnedOut), m_iPlayerFaction , "LC2_Timer_NortanderChase");
			// here
			//m_Reference.settimer(TOnTimerEvent(@this.OnLC2_NortanderFollowTimerRunnedOut), m_iLC2_CoverTimer);
			// starting the nortander troops/spawns/waves/whatever
			m_Reference.SetTimer( TOnTimerEvent(@this.OnLC2_NortanderChase_SO1), m_iLC2_NortanderFollowAssault_SO1 );
			m_Reference.SetTimer( TOnTimerEvent(@this.OnLC2_NortanderChase_SO2), m_iLC2_NortanderFollowAssault_SO2 );
			m_Reference.SetTimer( TOnTimerEvent(@this.OnLC2_NortanderFollowTimerRunnedOut), m_iLC2_NortanderFollowAssault );

			// Start the attack waves from the Nortander Assault faction
			// NOT Nortander Army faction, as its controlled by the AI
			m_Reference.GetBuildingByName( m_stgLC2_bldgNortanderChaseWave ).Enable( true );
			m_Reference.RegisterBuildingCreatureEventByIndividual( CreaturesSpawned, TOnBuildingCreatureEvent(@this.OnLC2_NortanderChase_WaveSpawn), m_stgLC2_bldgNortanderChaseWave );
		}
		else
		{
			LC2_CoveredRefugees();
		}
	}
	
	void LC2_CoveredRefugees()
	{
		printNote("The player protected the refugees long enough");
		MapUnlock( "EL", true );	
		m_Reference.GetLogicObjectByName( m_stgEntrance_LC_EL ).SetInteractive( true );

		EnableWorldMap( true );
		//m_bLC2_RTSfinished = true;
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("SQ_011b_ProtectTheRefugees", "SQ_011b_ProtectRefugees1", Completed );
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "SQ_011_H", Completed );

		m_Reference.RegisterHeroPartyEvent(LeavingMap, TOnHeroPartyEvent(@this.OnLC2_LeavingMap), "", m_iPlayerFaction);
	}
	bool OnLC2_LeavingMap(Creature& in _Creature)
	{
		MapUnlock( "LC", true );	
		TransferRTS( m_iPlayerFaction, m_iLC2_FactionIskanderLoyalists);
		return false;
	}

	void ArticyLC2_GiveFHMilitiaToPlayer()
	{
		printArticy("Player is getting the Militia ");
		for ( uint _iTmp1 = 0; _iTmp1 < m_arrStg_FHMilitiaSpawns.length() ; _iTmp1++ )
		{
			array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp1] );
			for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length() ; _iTmp2++ )
				_arrCrt[_iTmp2].SetFaction( m_iPlayerFaction );
		}
	}

	void ArticyLC2_GiveIskanderMilitiaToPlayer()
	{
		printArticy("Player is getting a part of the soldiers from Iskander");

		//m_Reference.ActivateSpawn( m_stgLC2_SpwnLoyalistAmbush, true);

		CreatureGroup _crtGrp_Soldiers ( m_Reference );
		_crtGrp_Soldiers.Set( m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ) );
		_crtGrp_Soldiers.Move( m_Reference.GetLogicObjectByName( "LC2_PosIskanderArmy" ), true, false );

		EnablePOIVisitingBehaviorSpawn( m_stgLC2_SpwnLoyalistAmbush, false);
		array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush );
		for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length() ; _iTmp2++ )
		{
			_arrCrt[_iTmp2].SetFaction( m_iPlayerFaction );
			_arrCrt[_iTmp2].EnablePOIVisitingBehavior(false);
		}

		/*for ( uint _iTmp1 = 0; _iTmp1 < m_arrStg_IskanderMilitiaSpawns.length() ; _iTmp1++ )
		{
			array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStg_IskanderMilitiaSpawns[_iTmp1] );
			for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length() ; _iTmp2++ )
			{
				_arrCrt[_iTmp2].SetFaction( m_iPlayerFaction );
			}

		}*/
	}

	void ArticyLC2_EnteredNortanderCamp ()
	{
		m_bLC2_EnteredNortanderCamp = true;
		m_Reference.SetTimer( TOnTimerEvent(@this.OnLC2_SOenterFort), 5 );
	}
	bool OnLC2_SOenterFort ()
	{
		DialogShoutout( m_stgAvatar, m_stgAvatar, "LC2_SO_EnterFort", false);
		return true;
	}

	void ArticyLC2_GiveClaraMedicine ()
	{
		printArticy("Player gave the medicine to Clara");
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems(m_stgLC2_ItemMedicine, 1);

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_011", "MQ_011_A_ToClara", Completed );
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("MQ_011", "MQ_011_B", true );

		//Thorsten Bear Ambush set active.
		m_bLC2_BearSwitch = true;
	}
	void ArticyLC2_MeetPurity ()
	{
		printArticy("Teleport Bertrand for the next step");
		LC2_MeetBertrandCarpel();
	}


	void ArticyLC3_ToArchfireForge()
	{
		World_NewAlly( "Myrah_Utran" );
		m_Reference.GetJournal( m_iPlayerFaction ).SetQuestState( "P4_Q1_FreeMyrah", Completed ); // QuestState( "P4_Q1_FreeMyrah", Completed );
		m_Reference.FadeToBlack( m_iPlayerFaction, uint8(-1), 1500);
		m_Reference.SetTimer( TOnTimerEvent(@this.ArticyLC3_ToArchfireForge_timed), 2 );
	}
	bool ArticyLC3_ToArchfireForge_timed()
	{
		m_Reference.GetWorld().SetGlobalBool( m_glbCat_Map+"_AF4_MyrahRuneScene_I", true );
		m_Reference.GetWorld().TravelToMap( m_iMap_AF_T, uint8 (-1), "");
		return true;
	}


	bool FH2_SendNextGroup_Follow()
	{
		// get next Leader in Line
		printArticy("Sending Villager Group "+m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup]+" on the route "+m_stgLC2_StartedOnRoute+" to everlight. " );

		// the last group is supposed to be the carriages - adding more space between
		if ( m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup] == "FH2_Carriages" )
		{
			return true;
			//m_iLC2_CaravanFollow_gotoMin = m_iLC2_CaravanFollow_gotoMin + 30;
			//m_iLC2_CaravanFollow_gotoMax = m_iLC2_CaravanFollow_gotoMax + 20;
		}
		else if ( m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup] == "FH2_VillageLeaders_LostTrader" )
		{
			m_iLC2_CaravanFollow_gotoMin = m_iLC2_CaravanFollow_gotoMin - 15;
			m_iLC2_CaravanFollow_gotoMax = m_iLC2_CaravanFollow_gotoMax - 10;
		}

		// Sending group to somewhere
		CreatureGroup _crtVillagers ( m_Reference );
		_crtVillagers.Set( m_Reference.GetCreaturesFromSpawn( m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup] ) );
		EnablePOIVisitingBehaviorSpawn( m_arrStg_FHVillagerSpawns[m_iSendVillagerGroup], false );
		_crtVillagers.FollowCreature(m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ), m_iLC2_CaravanFollow_gotoMax, m_iLC2_CaravanFollow_gotoMin, true, false );

		m_iSendVillagerGroup++;
		m_iLC2_CaravanFollow_gotoMin = m_iLC2_CaravanFollow_gotoMin + 20;
		m_iLC2_CaravanFollow_gotoMax = m_iLC2_CaravanFollow_gotoMax + 25;

		return true;
	}
	bool FH2_SendCaravanWagons()
	{
		m_iLC2_CaravanFollow_gotoMin = m_iLC2_CaravanFollow_gotoMin + 30;
		m_iLC2_CaravanFollow_gotoMax = m_iLC2_CaravanFollow_gotoMax + 20;

		// Sending group to somewhere
		CreatureGroup _crtVillagers ( m_Reference );
		_crtVillagers.Set( m_Reference.GetCreaturesFromSpawn( "FH2_Carriages" ) );
		EnablePOIVisitingBehaviorSpawn( "FH2_Carriages", false );
		_crtVillagers.FollowCreature(m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ), m_iLC2_CaravanFollow_gotoMax, m_iLC2_CaravanFollow_gotoMin, true, false );

		return true;
	}
	bool FH2_SendMilitia()
	{
		// getting the militia together, and move it first as the caravan convoy
		CreatureGroup _crtMilitia ( m_Reference );
		array <Creature> _arrCrt_Militia;
		for ( uint _iTmp1 = 0; _iTmp1 < m_arrStg_FHMilitiaSpawns.length() ; _iTmp1++ )
		{
			array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp1] );
			for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length() ; _iTmp2++ )
			{
				_arrCrt[_iTmp2].EnablePOIVisitingBehavior(false);
				_arrCrt_Militia.insertLast( _arrCrt[_iTmp2] );
			}
		}
		_crtMilitia.Set( _arrCrt_Militia );
		_crtMilitia.FollowCreature(m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ), 20, 10, true, false );

		return true;
	}

	void ArticyLC2_MeetBertrandCarpel()
	{
		printArticy("TMP, Secret Meeting; setting up Bertrand Carpel, to be at th emeeting spot.");
		//m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("MQ_011", "MQ_011_B", true );
		LC2_MeetBertrandCarpel();

		/*m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("MQ_011", "SQ_011_A", Completed );
		m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );*/
	}
	void ArticyLC2_TMPafterCutscene_LoyalistHelp()
	{
		printArticy("TMP, LoyalistAmbush; setting everything to the state after the cutscene.");
		LC2_TMPCutsceneLoyalists();
	}

	void ArticyLC2_InviteHumanArchitect()
	{
		printArticy("Invited the Human Architect");
	}

	// -------------------------------------------------------------------------------------------------------------------
	// --- C U S T O M  F U N C T I O N S --------------------------------------------------------------------------------
	bool CheckForOtherBuildings()
	{
		if(m_bAssignedWorkersFisher && m_bAssignedWorkersHunter && m_bAssignedWorkersWoodcutter)
		{
			//if(m_bAssignedWorkersWoodcutter)
			//{
				DialogShoutout(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_BuildBarracks", false);
				//m_Reference.GetHeroParty( m_iPlayerFaction ).AddItems( "BP_H_Barracks", 1);
				m_Reference.GetWorld().UnlockBlueprint("BP_H_Barracks", true);
				TutorialExtern( 'Buildings_Placing' );
				return true;
			//}
		}
		return false;
	}


	void LC2_CheckSurvivedMilitia ()
	{
		printNote("despawning appropiate amount of units");

		// get all spawned militia
		array <Creature> _allMilitia;
		// fill array with all remaining creatures (villagers)
		for(uint i = 0; i < m_arrStg_FHMilitiaSpawns.length(); i++)
		{
			array <Creature> _tempMilitia = m_Reference.GetCreaturesFromSpawn(m_arrStg_FHMilitiaSpawns[i]);
			for(uint j = 0; j < _tempMilitia.length(); j++)
			{
				_allMilitia.insertLast(_tempMilitia[j]);
			}
		}
		// split militia into recruits/pillagers
		array <Creature> _allPillagers;
		array <Creature> _allRecruits;
		array <Creature> _allGuards;
		for(uint k = 0; k < _allMilitia.length(); k++)
		{
			if(_allMilitia[k].GetDescriptionName() == "H_Pillager")
			{
				_allPillagers.insertLast(_allMilitia[k]);
			}
			else if(_allMilitia[k].GetDescriptionName() == "H_Recruit"){
				_allRecruits.insertLast(_allMilitia[k]);
			}
			else
			{
				_allGuards.insertLast(_allMilitia[k]);
			}
		}

		// check if there is any amount of pillagers/recruits to despawn
		int _PillagersToDespawn = 0;
		int _RecruitsToDespawn = 0;

		int _PillagerLength = _allPillagers.length();
		int _RecruitLength = _allRecruits.length();
		printNote("rescued pillagers:" + m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Pillager") );
		if(_PillagerLength > m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Pillager") &&
			m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Pillager") != -1)
		{
			_PillagersToDespawn = _allPillagers.length() - m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Pillager");
		}
		if(_RecruitLength > m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Recruit") &&
			m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Recruit")  != -1)
		{
			_RecruitsToDespawn = _allRecruits.length() - m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"H_Recruit");
		}

		// if needed, despawn recruits/pillagers that were not saved
		if(_PillagersToDespawn > 0)
		{
			for(int i = 0; i < _PillagersToDespawn; i++)
			{
				_allPillagers[i].Enable(false);
			}
		}

		if(_RecruitsToDespawn > 0)
		{
			for(int i = 0; i < _RecruitsToDespawn; i++)
			{
				_allRecruits[i].Enable(false);
			}
		}

		// despawn guards if needed
		for(int i = 1; i <= 4; i++)
		{
			if(m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"FH1_Guard_0"+i) == 0 &&
				m_Reference.GetWorld().GetGlobalInt(m_glbCat_FH_savedMilitia+"."+"FH1_Guard_0"+i) != -1)
			{
				_allGuards[i-1].Enable(false);
			}
		}
	}

	//array <string> m_arrStgFH2_VillagerSpawns = { "FH_Villagers_01", "FH_Villagers_02", "FH_Villagers_03", "FH_Villagers_04" };
	void LC2_CheckSurvivedVillagers ()
	{
		array <Creature> _allVillagers;
		// fill array with all remaining creatures (villagers)
		for(uint i = 0; i < m_arrStg_FHVillagerSpawns.length()-1; i++)
		{
			array <Creature> _tempVillagers = m_Reference.GetCreaturesFromSpawn(m_arrStg_FHVillagerSpawns[i]);
			for(uint j = 0; j < _tempVillagers.length(); j++)
			{
				_allVillagers.insertLast(_tempVillagers[j]);
			}
		}

		printNote("killed: "+ m_Reference.GetWorld().GetGlobalInt("MapVariables.FH_CountVillagersThatDied") + "and have:" + _allVillagers.length() );
		for(int k = 0; k < m_Reference.GetWorld().GetGlobalInt("MapVariables.FH_CountVillagersThatDied"); k++)
		{
			_allVillagers[k].Enable(false);
		}

		printNote("killed carriages:" + m_Reference.GetWorld().GetGlobalInt("MapVariables.FH_CountCarriagesLost"));
		for(int l = 0; l < m_Reference.GetWorld().GetGlobalInt("MapVariables.FH_CountCarriagesLost"); l++)
		{
			m_Reference.GetCreaturesFromSpawn("FH2_Carriages")[l].Enable(false);
		}

		if (m_Reference.GetWorld().GetGlobalBool(m_stgGlobal_bLostTraderSaved) == false )
		{
			m_Reference.GetCreatureByName( m_stgCrtLC2_LostTrader ).Enable( false );
		}
		else
		{
			m_Reference.GetCreatureByName( m_stgCrtLC2_LostTrader ).EnableTrade(false);
		}
	}


	bool LC2_TMPsentenzaFlees ()
	{
		ArticyLC2_SentenzaFlees();

		PlayerHeroControlEnable();
		HeroPartyReequip_NotCutscene();
		HeroPartyAttackable(true);

		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).SetAttackable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).AllowAttacks( true );

		return true;
	}

	bool LC2_MeetBertrandCarpel ()
	{
		Creature _crtBertrand = m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel);
		_crtBertrand.EnablePOIVisitingBehavior( false );
		_crtBertrand.Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLC2_PosBertrandCarpel_Meeting ).GetId() ));
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtBertrandCarpel, "LC2_SecretMeeting", true);
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtBertrandCarpel, "LC2_GiveMedicine", false);

		m_Reference.RegisterCreatureEventByIndividual(Resurrected, TOnCreatureEvent(@this.OnLC2_MeetingBertrandCarpel), m_stgAvatar, "m_stgLC2_TrgSmallCmap_Ent_1");
		// dissable Bertrand Carpel POI Behavior

		return true;
	}
	bool OnLC2_MeetingBertrandCarpel (Creature& in _Creature)
	{
		Autosave();
		return true;
	}

	/*bool LC2_MeetBertrandCarpel ()
	{
		Creature _crtBertrand = m_Reference.GetCreatureByName(m_stgLC2_crtBertrandCarpel);
		_crtBertrand.EnablePOIVisitingBehavior( false );
		_crtBertrand.Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( m_stgLC2_PosBertrandCarpel_Meeting ).GetId() ));
		m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtBertrandCarpel, 	"LC2_SecretMeeting", true);

		return true;
	}*/
	bool LC2_StartCaravan()
	{
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistLeader ).Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).GetId() ));
		m_stgLC2_StartedOnRoute = m_stgLC2_PathSectorRouteOne;
		m_stgLC2_RouteAssault = m_stgLC2_PathSectorRouteOneAssault;

		ArticyLC2_StartCaravan();
		return true;
	}

	bool LC2_TMPCutsceneLoyalists ()
	{
		printNote("TEMP - placing the iskander attack." );

		// teleport everyone to the point
		HeroPartyTeleport( "LC2_PosHeroParty_LoyalistAmbush" );
		m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId() ));
		m_Reference.FocusCamera( m_iPlayerFaction, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId()) );

		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId() ));
		CreatureGroup _crtGrp_SentenzaAmbush ( m_Reference );
		_crtGrp_SentenzaAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush ) );
		_crtGrp_SentenzaAmbush.Teleport( m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId()), false );

		// activate Loyalist ambush
		m_Reference.ActivateSpawn( m_stgLC2_SpwnLoyalistAmbush, true);
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).SetImmovable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).SetImmortal( true );

		EnablePOIVisitingBehaviorSpawn( m_stgLC2_SpwnLoyalistAmbush, false );
		m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.OnLC2_IskanderDudesArrivedAtCamp), m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ), true, "LC2_LoyalistCamp");

		CreatureGroup _crtGrp_LoyalistAmbush ( m_Reference );
		_crtGrp_LoyalistAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ) );
		_crtGrp_LoyalistAmbush.FollowPathSmooth( m_stgLC2_PathLoyalistAmbush, true, true );

		// m_Reference.RegisterHeroPartyEvent(AnyInAggroRange, TOnHeroPartyEvent(@this.OnLC2_SOiskanderAmbush), m_stgLC2_crtLoyalistCommander, m_iPlayerFaction);

		// setup that sentenza flees in X seconds
		m_Reference.SetTimer( TOnTimerEvent(@this.LC2_TMPsentenzaFlees), 25 );

		return true;
	}

	void LC2_CheckCaravanRoads( )
	{
		// Caravane already started, DONT let the stuff below run, as it disables stuff
		// Seems one of the sectors where lost - check which one and react to it accordingly
		if (m_bLC2_CaravanStarted)
		{
			// could be used later, when a sector is lost, while the caravan has started to move
			printNote("Caravan already started, but a sector was lost. Currently doesn't react to that. ");
			return;
		}
		// if the nortander army was defeated, the player dan directly start the caravan
		if ( m_Reference.GetWorld().GetGlobalBool( m_stgGlobal_bNortanderFactionDefeated) == true )
		{
			//printNote("Nortander Army is defeated - Caravan can start without worries");
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_NortanderDefeated", true);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_FirstContact", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_RouteCleared", false);
			//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_d", Completed );
			m_stgLC2_StartedOnRoute = m_stgLC2_PathSectorRouteOne;

			return;
		}


		// Check if one of the two routes are free.
		// first route is free
		if ( m_iLC2_SectorRouteOne_freed == m_arrStgLC2_SectorsRouteOne.length() )
		{
			printNote("First route is free - Caravan can start");
			m_stgLC2_StartedOnRoute = m_stgLC2_PathSectorRouteOne;
			m_stgLC2_RouteAssault = m_stgLC2_PathSectorRouteOneAssault;

			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_FirstContact", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_RouteCleared", true);

			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_d", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );
		}
		// second route is free
		else if ( m_iLC2_SectorRouteTwo_freed == m_arrStgLC2_SectorsRouteTwo.length() )
		{
			printNote("Second route is free - Caravan can start");
			m_stgLC2_StartedOnRoute = m_stgLC2_PathSectorRouteTwo;
			m_stgLC2_RouteAssault = m_stgLC2_PathSectorRouteTwoAssault;

			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_FirstContact", false);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_RouteCleared", true);

			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q5c_GainHumans", "MQ_011_C_d", Completed );
			//m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest ( "LC_tExpQuest_1000", true );
			//m_Reference.GetJournal(m_iPlayerFaction).SetQuestState( "LC_tExpQuest_1000", Completed );
		}
		// no route is free, disable the posibily to start the caravan
		else
		{
			printNote("No route is free - disabling the route cleared dialogue (if it was enabled) ");
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_FirstContact", true);
			m_Reference.GetWorld().EnableDialogueTopic( m_stgLC2_crtClaraFarlorn, "LC2_RouteCleared", false);

			m_stgLC2_StartedOnRoute = "";
		}

	}

	// Cutscene Functions
	void LC1_OpenerCutscene()
	{
		printCutscene("Play Cutscene LC1_Opener");
		m_Reference.PlayCutScene("LC1_MapOpener");
		
		//m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.LC1_OpenerCutscene_end), m_iPlayerFaction);
		//There's a small cut-scene showing the environment. The camera slowly zooms in to the party. Gwendolyn comes running towards Sentenza and Anselm, who are standing at the waterfall.
	}
	bool LC1_OpenerCutscene_end(const uint8 _uPlayerFaction)
	{
		printNote( "TMP 1" );
		TutorialExternTimed( 'ControllingHeroes', 2 );
		// generally start tutorials from this point on

		return true;
	}

	void LC1_GuardsGatherCutscene()
	{
		printCutscene("Play Cutscene LC1_GuardsGather");
		m_Reference.PlayCutScene("LC1_BaseCutscene");
		//Short camera swipe over the sector
		//Guards gather near players position
		//Some guard shoutouts of them  now following sentenzas orders.
		//Battle noises can be heard
		//Another guard (LC1_Outpost_Guard_02) arrives and tells that they are being attacked
		//Sentenza orders guards to defend the camp

		m_Reference.GetWorld().EnableDialogueTopic( "LC1_Outpost_Guard", "LC1_SentenzaIsHere", false );
		m_Reference.GetWorld().EnableDialogueTopic( "LC1_Rebel_Guard_01", "LC1_SO_Greeting", false );

		SetFactionSpawns( m_arrLC1_GuardsSpawns, m_iPlayerFaction );
		EnablePOIVisitingBehaviorSpawns( m_arrLC1_GuardsSpawns, false );

		CreatureGroup _crtGroup_Guards ( m_Reference );
		_crtGroup_Guards.Set( GetCreaturesFromSpawns( m_arrLC1_GuardsSpawns ) );
		_crtGroup_Guards.Move( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[0], false, false, false);
	}
	void LC1_GuardsGatherCutsceneAttack()
	{
		//triggered by cutscene
		m_Reference.ActivateSpawn("LC1_CampAttackers", true);
		CreatureGroup _crtCampAttacker ( m_Reference );
		_crtCampAttacker.Set( m_Reference.GetCreaturesFromSpawn("LC1_CampAttackers") );
		_crtCampAttacker.FollowPathSmooth( "LC1_AttackPath", true, true, kMaxFactions ); //, WaitForAnyHeroes, false, false);// ("LC1_AttackPath", true, false, false);
		//_crtCampAttacker.FollowPath("LC1_AttackPath", true, false, false);

		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.OnAttackersKilled), m_Reference.GetCreaturesFromSpawn("LC1_CampAttackers"), false, "");
	}

	void LC1_CutsceneTakeRuins()
	{
		printCutscene("Play Cutscene LC1_CutsceneTakeRuins");
		m_Reference.PlayCutScene("LC1_RuinsTaken");

		m_Reference.ActivateSpawn("LC1_Spawn_Undead", true);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnTriggerUndead), "LC1_Trigger_Undead", m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.OnZombieKilled), m_Reference.GetCreaturesFromSpawn("LC1_Spawn_Undead")[0].GetDescriptionName(), "");

		m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.OnLootedKey), "LC1_DungeonKey", m_iPlayerFaction);
		//Camera swipe over ruins
		//Sentenza: We have the ruins. They are hiding in one of the buildings, let's find the entrance!
	}

	void LC1_BuildTheBaseCutscene()
	{
		printCutscene("Play Cutscene LC1_BuildTheBase");
		m_Reference.PlayCutScene("LC1_BuildBase");
		//After combat, the group gathers again.
		//Sentenza says that they have to improve the base to get the strength to enter the castle
		//And then they have to get access to the castle. They should immediately build a barracks but they need to gather resources first.

			// Note by Marc: Please do not use names like "Entity_Human_Fishing_Cabin_82770", if you want to touch objects via script, give them proper names, so others can find them
			// Moreover, it might be better to use  "RegisterBuildingEventByDescription" - as we do not know if the player build another building and uses that (don't know exact quest / setup)
		m_Reference.RegisterBuildingEventByIndividual(WorkerAssignmentChanged, TOnBuildingEvent(@this.OnAssignedWorkersToFisher), "Entity_Human_Fishing_Cabin_82770");
		m_Reference.RegisterBuildingEventByIndividual(WorkerAssignmentChanged, TOnBuildingEvent(@this.OnAssignedWorkersToHunter), "Entity_Human_Hunting_Cabin_82775");
		m_Reference.RegisterBuildingEventByIndividual(WorkerAssignmentChanged, TOnBuildingEvent(@this.OnAssignedWorkersToWoodcutter), "Entity_Human_Woodcutter_01_82767");
	}

	void LC1_BuildTheBaseCutsceneDialogue()
	{
		//Triggered by LC1_BuildTheBaseCutscene Cutscene
		m_Reference.GetSectorByName("Sector_13").SetOwner(m_iPlayerFaction);
		m_Reference.GetSectorByName("Sector_13").GetMainBuilding().SetFaction(m_iPlayerFaction);
		//m_Reference.GetSectorByName("Sector_13").CreateCapital( m_iPlayerFaction, true, false );

		// check, and mention if the workers hit 0
		m_Reference.RegisterBuildingEventByIndividual(WorkerAssignmentChanged, TOnBuildingEvent(@this.OnLC1_ZeroWorkerAtMainBuilding), m_Reference.FindEntityName( m_Reference.GetSectorByName("Sector_13").GetMainBuilding() ) );
		DialogShoutoutTimed(m_stgHero_Sentenza, m_stgHero_Sentenza, "LC1_SO_HunterAndFisher", false, 2);

		Tutorial_HeroPartyNowToLevel();
		TutorialExtern('AssigningWorkers');
		AutosaveTimed(1);
	}

	void LC2_StartOpenerCutscene()
	{
		printCutscene("Starting to play the cutscene 'LC2_MapOpener'.");
		m_Reference.PlayCutScene("LC2_MapOpener");
	}

	void LC1_CutPlayCombatSoundtrack()
	{
		m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "music/setting/grassland_night");
		m_Reference.SuspendAutomaticCombatMusic(m_iPlayerFaction, uint8(-1), true);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "combat", 1);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intro", 1);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intensity", 100);

	}

	void LC1_CutEndCombatSoundtrack()
	{
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "combat", 0);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intro", 0);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intensity", 0);
		m_Reference.SuspendAutomaticCombatMusic(m_iPlayerFaction, uint8(-1), false);
		m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "");
	}

	void LC2_Cutscene_MoveFHMilitia()
	{
		CreatureGroup _crtMilitia ( m_Reference );
		array <Creature> _arrCrt_Militia;
		for ( uint _iTmp1 = 0; _iTmp1 < m_arrStg_FHMilitiaSpawns.length() ; _iTmp1++ )
		{
			array <Creature> _arrCrt = m_Reference.GetCreaturesFromSpawn( m_arrStg_FHMilitiaSpawns[_iTmp1] );
			for ( uint _iTmp2 = 0; _iTmp2 < _arrCrt.length() ; _iTmp2++ )
			{
				_arrCrt[_iTmp2].EnablePOIVisitingBehavior( false );
				_arrCrt_Militia.insertLast( _arrCrt[_iTmp2] );
			}
		}
		_crtMilitia.Move( m_Reference.GetLogicObjectByName( "LC2_MilitiaCutscenePosition" ), true );
	}


	void LC2_CutMoveArmy()
	{
		printNote("TEMP - teplacing the iskander attack." );

		// teleport everyone to the point
		//HeroPartyTeleport( "LC2_PosHeroParty_LoyalistAmbush" );
		//m_Reference.GetCreatureByName( m_stgLC2_crtBertrandCarpel ).Teleport( m_Reference, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId() ));
		//m_Reference.FocusCamera( m_iPlayerFaction, m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ).GetId()) );

		CreatureGroup _crtGrp_SentenzaAmbush ( m_Reference );
		_crtGrp_SentenzaAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush ) );
		printNote("Creatures in group: " + _crtGrp_SentenzaAmbush.GetCreatures().size());
		_crtGrp_SentenzaAmbush.Teleport(m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbush" ), false );
		//_crtGrp_SentenzaAmbush.FollowCreature(m_Reference.GetCreatureByName(m_stgLC_crtSentenza), 120, 80, false, true);
		// activate Loyalist ambush
		m_Reference.ActivateSpawn( m_stgLC2_SpwnLoyalistAmbush, true);
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).SetImmovable( true );
		m_Reference.GetCreatureByName( m_stgLC2_crtLoyalistCommander ).SetImmortal( true );

		EnablePOIVisitingBehaviorSpawn( m_stgLC2_SpwnLoyalistAmbush, false );
		m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.OnLC2_IskanderDudesArrivedAtCamp), m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ), true, "LC2_LoyalistCamp");

		CreatureGroup _crtGrp_LoyalistAmbush ( m_Reference );
		_crtGrp_LoyalistAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ) );
		_crtGrp_LoyalistAmbush.FollowPathSmooth( m_stgLC2_PathLoyalistAmbush, true, true );

		// setup that sentenza flees in X seconds
	}

	void LC2_CutEscortSentenza()
	{
		CreatureGroup _SentenzasTroops ( m_Reference );
		_SentenzasTroops.Set(  m_Reference.GetCreaturesFromSpawn( "LC2_SentenzaAmbush" ) );

		//_OrcArmy1.Teleport(m_Reference.GetLogicObjectByName( "FactionvideoArme1Port") );
		_SentenzasTroops.AttackPosition(m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbushAttack" ).GetId()), true, true);	

		//CreatureGroup _crtGrp_SentenzaAmbush ( m_Reference );
		//_crtGrp_SentenzaAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush ) );
		//_crtGrp_SentenzaAmbush.FollowCreature(m_Reference.GetCreatureByName(m_stgLC_crtSentenza), 120, 80, false, true);

	}

	void LC2_CutLoyalistAttack()
	{
		printCutscene("Try to attack sentenza." );
		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).AllowAttacks( true );
		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).SetAttackable( true );
		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).SetImmortal( true );

		CreatureGroup _crtGrp_LoyalistAmbush ( m_Reference );
		_crtGrp_LoyalistAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnLoyalistAmbush ) );
		_crtGrp_LoyalistAmbush.Add( m_Reference.GetCreatureByName( m_stgLC_crtSentenza ) );
		_crtGrp_LoyalistAmbush.AttackPosition(m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbushAttack" ).GetId()), false, false);
		//_crtGrp_LoyalistAmbush.FollowCreature(m_Reference.GetCreatureByName(m_stgLC_crtSentenza), 120, 80, true, false);
		CreatureGroup _crtGrp_SentenzaAmbush ( m_Reference );
		_crtGrp_SentenzaAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush ) );
		_crtGrp_SentenzaAmbush.AttackPosition(m_Reference.GetEntityById( m_Reference.GetLogicObjectByName( "LC2_PosHeroParty_LoyalistAmbushAttack" ).GetId()), false, false);

	}

	void LC2_CutPlayCombatSoundtrack()
	{
		m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "music/setting/grassland");
		m_Reference.SuspendAutomaticCombatMusic(m_iPlayerFaction, uint8(-1), true);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "combat", 1);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intro", 1);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intensity", 9999);

	}

	void LC2_CutEndAmbushCutscene()
	{
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "combat", 0);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intro", 0);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "intensity", 0);
		m_Reference.SuspendAutomaticCombatMusic(m_iPlayerFaction, uint8(-1), false);
		CreatureGroup _crtGrp_SentenzaAmbush ( m_Reference );
		_crtGrp_SentenzaAmbush.Set(  m_Reference.GetCreaturesFromSpawn( m_stgLC2_SpwnSentenzaAmbush ) );
		_crtGrp_SentenzaAmbush.Die(true);
		m_Reference.GetCreatureByName( m_stgLC_crtSentenza ).Enable( false );
		m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "");

		HeroPartyReequip_NotCutscene();
	}
	// -------------------------------------------------------------------------------------------------------------------
	// -------------------------------------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------------------------
//----------------- V E R S I O N  3 ---------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------------------------
// --- EVENTS --------------------------------------------------------------------------------------------------------

	// --- TRIGGER EVENTS --------------------------------------------------------------------------------------------
	// Shoutout when Avatar sees the Pallisade for the first time
	bool LC3_OnTriggerEnter_SO_Pallisade(Creature& in _Creature)
	{
		if( _Creature == m_Reference.GetCreatureByName(m_stgAvatar) ){
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_35_SO_Pallisade", false);
			return true;
		}
		return false;
	}

	// Fleeing purity units despawn
	bool LC3_OnTriggerEnter_DespawnPurity(Creature& in _Creature)
	{
		_Creature.Enable(false);
		return false;
	}

	// If Angar is present at one of the entrances, while purity is there -> Attack Shoutout
	bool LC3_OnTriggerEnter_SO_AngarAttack(Creature& in _Creature)
	{
		if( m_Reference.GetSectorByName(m_stgLC3_Sector_PurityCastle).GetOwner() != m_iLC3_Faction_Purity_AI || m_bLC3_SO_AngarAttack )
		{
			return true;
		}
		m_bLC3_SO_AngarAttack = true;
		DialogShoutout(m_stgLC3_Crt_Angar, m_stgLC3_Crt_Angar, "LC3_11_SO_Attack", false);
		return true;
	}

	bool LC3_OnTriggerEnter_BehindTheWall(Creature& in _Creature)
	{
		m_bLC3_AllBehindWall = true;
		if(!m_bLC3_SO_BehindWallStarted)
		{
			m_bLC3_SO_BehindWallStarted = true;
			m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_BehindWall), 1);
		}
		return false;
	}

	bool LC3_OnTriggerLeave_BehindTheWall(Creature& in _Creature)
	{
		m_bLC3_AllBehindWall = false;
		return false;
	}


	bool LC3_OnTriggerEnter_GatherAtMyrah(Creature& in _Creature)
	{
		if(m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(true))
		{
			m_Reference.BlockNavMesh("LC3_PhysBlocker_GatherAtMyrah_01", false);
			m_Reference.BlockNavMesh("LC3_PhysBlocker_GatherAtMyrah_02", false);
			return true;
		}
		return false;
	}

	bool LC3_OnTriggerEnter_RuneGuardsAggro_01(Creature& in _Creature)
	{
		if(!m_bLC3_RuneGuardsAggro01 && !m_bLC3_RuneGuardsAggro02 )
		{
			m_bLC3_RuneGuardsAggro01 = true;
			DialogShoutout("LC3_Rune_Priest", "LC3_Rune_Priest", "LC3_31_SO_NoticePlayer", false);
		}
		return true;
	}

	bool LC3_OnTriggerEnter_RuneGuardsAggro_02(Creature& in _Creature)
	{
		if(!m_bLC3_RuneGuardsAggro01 && !m_bLC3_RuneGuardsAggro02 )
		{
			m_bLC3_RuneGuardsAggro02 = true;
			DialogShoutout("LC3_Rune_Priest", "LC3_Rune_Priest", "LC3_31_SO_NoticePlayer", false);
		}
		return true;
	}

	bool LC3_OnTriggerEnter_SO_OldPurityCamp(Creature& in _Creature)
	{
		if(!m_bLC3_RTSOver)
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_06_SO_OldPurityCamp", true);
		}
		return true;
	}

	bool LC3_OnTriggerEnter_SO_RefugeeGone(Creature& in _Creature)
	{
		if(!m_bLC3_FoundRefugee)
		{
			if(HeroPartyReadyForDialogue())
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_22_SO_RefugeeGone", false);
			}
			else
			{
				m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_RefugeeGone), 1);
			}
			m_bLC3_RefugeeGone = true;
		}
		return true;
	}

	bool LC3_OnTriggerEnter_SO_Bridge(Creature& in _Creature)
	{
		if(!m_bLC3_BridgeRepaired && !m_bLC3_RTSOver)
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_04_SO_DestroyedBridge", true);
		}
		return true;
	}

	bool LC3_OnTriggerEnter_CheckChest(Creature& in _Creature)
	{
		if( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("LC3_RuneChestKey", 1) && m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(true) )
		{
			m_Reference.GetLogicObjectByName("LC3_Loot_RuneChest").Unlock();
			return true;
		}

		return false;
	}


	// --- INTERACTION EVENTS ----------------------------------------------------------------------------------------

	bool LC3_OnInteract_Inspection_LC_EmptyCage( Creature& in _Creature )
	{
		if( m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_InvFindRefugee") )
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_RefugeePosWrong_01", Completed);
			return true;
		}
		return false;
	}

	bool LC3_OnInteract_Inspection_LC_Grave( Creature& in _Creature )
	{
		if( m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_InvFindRefugee") )
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_RefugeePosWrong_02", Completed);
			return true;
		}
		return false;
	}

	bool LC3_OnInteract_Inspection_LC_Inspect_OldShrine( Creature& in _Creature )
	{
		if( m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_InvFindRefugee") )
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_RefugeePosWrong_03", Completed);
			return true;
		}
		return false;
	}
	//Shoutout when not having the key for the Tunnel
	bool LC3_OnInteract_TunnelEntry(Creature& in _Creature)
	{
		m_bLC3_FoundTunnel = true;
		if( HeroPartyReadyForDialogue() && !m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("LC3_TunnelKey", 1) )
		{ // if !gotKey
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_09_SO_TunnelEntry", false);
		}
		else if( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("LC3_TunnelKey", 1))
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_27A_ChooseCompanion", false);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_OpenTunnel", Completed);
		}

		if(m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P4_MAP001_TheTunnel"))
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_FindTunnel", Completed);
		}
		return false;
	}

	bool LC3_OnInteract_RuneChest(Creature& in _Creature)
	{
		if( m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("LC3_RuneChestKey", 1) && m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(true) )
		{
			m_Reference.GetLogicObjectByName("LC3_Loot_RuneChest").Unlock();
			return true;
		}
		return false;
	}

	bool LC3_OnInteract_Refugee(Creature& in _Creature)
	{
		m_bLC3_FoundRefugee = true;
		return false;
	}

	bool OnInteract_Door_01(Creature& in _Creature)
	{
		if( !m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(true) )
				return false;

		m_Reference.EnableGroup("LC3_InnerFortDoor_1", false);
		m_Reference.GetLogicObjectByName("LC3_InnerFortDoor_1_Switch").Enable(false);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_GatherAtMyrah_01", false);
		/*	m_Reference.GetLogicObjectByName("InspectionHighlight_01").Enable(false);
		m_Reference.GetLogicObjectByName("InspectionHighlight_02").Enable(false);
		m_Reference.GetLogicObjectByName("InspectionHighlight_03").Enable(false);*/
		if( !m_bLC3_GateOpen )
		{
			m_bLC3_GateOpen = true;
			m_bLC3_RuneGuardsAggro01 = true;
			DialogShoutout("LC3_Rune_Priest", "LC3_Rune_Priest", "LC3_31_SO_NoticePlayer", false);
		}

		return true;
	
	}

	bool OnInteract_Door_02(Creature& in _Creature)
	{
		if( !m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(true) )
				return false;

		m_Reference.EnableGroup("LC3_InnerFortDoor_2", false);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_GatherAtMyrah_02", false);
		m_Reference.GetLogicObjectByName("LC3_InnerFortDoor_2_Switch").Enable(false);
	/*	m_Reference.GetLogicObjectByName("InspectionHighlight_01").Enable(false);
		m_Reference.GetLogicObjectByName("InspectionHighlight_02").Enable(false);
		m_Reference.GetLogicObjectByName("InspectionHighlight_03").Enable(false);*/
		if( !m_bLC3_GateOpen )
		{
			m_bLC3_GateOpen = true;
			m_bLC3_RuneGuardsAggro02 = true;
			DialogShoutout("LC3_Rune_Priest", "LC3_Rune_Priest", "LC3_31_SO_NoticePlayer", false);
		}

		return true;
	
	}

	// --- DAMAGE KILL CREATURE EVENTS -------------------------------------------------------------------------------

	bool LC3_OnKilled_PurityCommander(Creature& in _Creature)
	{
		if( _Creature == m_Reference.GetCreatureByName("LC3_PurityCommander_01") )
		{
			printNote("Commander 01 died - Spawn should be inactive now");
			m_Reference.GetBuildingByName("LC3_PuritySiegeSpawn_01").SetActive(false);
			RemovePuritySiegeSpawner( m_Reference.GetBuildingByName("LC3_PuritySiegeSpawn_01") );
			if(!m_bLC3_RefugeeGone){
				m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_CommanderKilled), 1);
			}
			//maybe disable it?
		}
		else if( _Creature == m_Reference.GetCreatureByName("LC3_PurityCommander_02") )
		{
			printNote("Commander 02 died - Spawn should be inactive now");
			m_Reference.GetBuildingByName("LC3_PuritySiegeSpawn_02").SetActive(false);
			RemovePuritySiegeSpawner(m_Reference.GetBuildingByName("LC3_PuritySiegeSpawn_02"));
			if(!m_bLC3_RefugeeGone){
				m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_CommanderKilled), 1);
			}
			//maybe disable it?
		}
		else if( _Creature == m_Reference.GetCreatureByName("LC3_PurityCommander_03") )
		{
			printNote("Commander 03 died - Spawn should be inactive now");
			m_Reference.GetBuildingByName("LC3_PuritySiegeSpawn_03").SetActive(false);
			RemovePuritySiegeSpawner(m_Reference.GetBuildingByName("LC3_PuritySiegeSpawn_03"));
			if(!m_bLC3_RefugeeGone){
				m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_CommanderKilled), 1);
			}
			//maybe disable it?
		}
		return true;
	}

	bool LC3_OnKilled_RuneGuards(Creature& in _Creature)
	{
		printNote("One Runeguard dead");
		if(m_Reference.GetCreaturesFromSpawn("LC3_SP_RuneGuards").length() == 0)
		{
			printNote("Runeguards dead");
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P4_Q1_KillPriests", Completed);
			m_Reference.PlayCutScene("LC3_LootRune");
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.LC3_OnCutsceneFinished_LootRune), m_iPlayerFaction);
			/*_Creature.DropItem(m_Reference, "LC3_RuneChestKey", 1);
			if(m_Reference.GetCreatureByName(m_stgAvatar).GetCurrentHP() > 0)
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_32_SO_PriestsKilled", true);
			}*/
			return true;
		}
		return false;
	}

	bool LC3_OnCutsceneFinished_LootRune( const uint8 _uPlayerFaction )
	{
		printNote("gangaganmgnamgansmnsmagnmsnasgm");
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("LC3_Rune", 1);
		DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_33_SO_RuneFound", true);
		m_Reference.RegisterHeroPartyEvent(AnyCanSee, TOnHeroPartyEvent(@this.LC3_OnCansee_HeropartyMyrahFinal), "Myrah_Utran", m_iPlayerFaction);
		m_Reference.GetWorld().EnableDialogueTopic("Myrah_Utran", "LC3_36_Myrah_Talk", true);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P1_Q1_FreeMyrah_GetRuneStone", Completed);

		return true;
	}


		// --- SPAWN EVENTS ----------------------------------------------------------------------------------------------


		// --- PATH EVENTS -----------------------------------------------------------------------------------------------


		// --- TIMER EVENTS ----------------------------------------------------------------------------------------------
	// Random mood Shoutout if nothing else is going on and the party is gathered
	bool LC3_OnTimer_SO_AngarMyrah()
	{
		if( HeroPartyReadyForDialogue() && m_Reference.GetHeroParty(m_iPlayerFaction).IsMember(m_Reference.GetCreatureByName(m_stgLC3_Crt_Angar)) && !m_Reference.GetCreatureByName(m_stgLC3_Crt_Angar).IsInDialogue() && m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(false))
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_10_BN_AngarMyrah", false);
		}
		else
		{
			m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_AngarMyrah), 10);
		}
		return true;
	}

	bool LC3_OnTimer_FortifyCastleEnd()
	{
		// Do we need to check if the player is fighting at the moment????
		printNote("Your time is over. now the fun begins");
		if(HeroPartyReadyForDialogue())
		{
			LC3_Cutscene_HarbingerAttacks();
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P1_Q1_FreeMyrah_Prepare", Completed);
		}
		else
		{
			m_Reference.SetTimer( TOnTimerEvent(@this.LC3_OnTimer_FortifyCastleEnd), 2);
		}
		return true;
	}

	bool LC3_OnTimer_SO_CommanderKilled()
	{
		//	DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_34_SO_CommanderKilled", false);
		DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_19_SO_BarracksDestroyed", false); // that one fits better - neither commander nor barracks are mentioned in one of the shoutouts
		return true;
	}

	bool LC3_OnTimer_SO_TunnelHint()
	{
		if(HeroPartyReadyForDialogue())
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_21_SO_TunnelHint", false);
			return true;
		}
		return false;
	}

	bool LC3_OnTimer_SO_BehindWall()
	{
		if(m_bLC3_MyrahFound)
		{
			return true;
		}
		if(HeroPartyReadyForDialogue() && m_bLC3_AllBehindWall)
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P1_Q1_FreeMyrah_FindWay", Completed);
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_29_SO_InUtranTerritory", false);
			return true;
		}
		return false;
	}

	bool LC3_OnTimer_SO_Scolding()
	{
		if(HeroPartyReadyForDialogue())
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_25_SO_Scolding", true);
			return true;
		}
		return false;
	}

	bool LC3_OnTimer_SO_RefugeeGone()
	{
		if(HeroPartyReadyForDialogue())
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_22_SO_RefugeeGone", false);
			return true;
		}
		return false;
	}


		// --- SIGHT EVENTS ----------------------------------------------------------------------------------------------
	bool LC3_OnCansee_AvatarMyrah(Creature& in _Creature)
	{
		if(!m_bLC3_RuneGuardsAggro01 && !m_bLC3_RuneGuardsAggro02)
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_30_SO_SpotMyrah", true);
		}
		return true;
	}

	bool LC3_OnCansee_HeropartyMyrahFinal(Creature& in _Creature)
	{
		if( m_Reference.GetHeroParty(m_iPlayerFaction).IsGathered(true) )
		{
			m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, m_iLC3_Faction_Purity_AI, Neutral);
			m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, m_iLC3_Faction_Purity, Neutral);

			DialogTalkTo(m_stgAvatar, "Myrah_Utran", "Myrah_Utran", "LC3_36_Myrah_Talk");
			return true;
		}
		return false;
	}

	// --- BUILDING EVENTS -------------------------------------------------------------------------------------------
	//When a purity wave spawns, upgrade to the next level of the wave spawner (stronger units), until maximum reached
	bool LC3_OnWaveSpawned_PurityWaves(Building&in _Building, Creature[]&in _Creatures)
	{
		if( m_iLC3_PurityWaves == 0 )
		{
			_Building.Upgrade(m_Reference, "S_LC3_PurityWaveSpawn_II", true);
		}
		if( m_iLC3_PurityWaves == 1 )
		{
			_Building.Upgrade(m_Reference, "S_LC3_PurityWaveSpawn_III", true);
		}
		if( m_iLC3_PurityWaves >= 2 )
		{
			_Building.Upgrade(m_Reference, "S_LC3_PurityWaveSpawn_IV", true);
		}
		CreatureGroup _GrpPurityWave = CreatureGroup(m_Reference, _Creatures);
		//_GrpPurityWave.AttackPosition(m_Reference.GetSectorByName( m_stgLC3_Sector_Playerbase ).GetMainBuilding(), false, false);
		_GrpPurityWave.AttackPosition( m_Reference.GetLogicObjectByName("LC3_Spot_Playerbase"), false, false);

		for(uint i = 0; i < _Creatures.length(); i++)
		{
			_Creatures[i].SetFaction(m_iLC3_Faction_Purity);
		}

		m_iLC3_PurityWaves++;
		return false;
	}

		// this method is called after a building spawns its units - keep that in mind while scripting here
	bool LC3_OnWaveSpawned_PuritySiegeWave(Building&in _Building, Creature[]&in _Creatures)
	{
		printNote("Purity wave spawned " + m_iLC3_PuritySiegeWaves);
		//CREATURE BEHAVIOUR
		CreatureGroup _grp = CreatureGroup(m_Reference, _Creatures);

		if( m_Reference.GetSectorByName(m_stgLC3_Sector_Playerbase).GetOwner() == m_iLC3_Faction_PlayerAllied_AI || m_Reference.GetSectorByName(m_stgLC3_Sector_Playerbase).GetOwner() == m_iPlayerFaction )
		{
			printNote("Attack the playerbase");
			_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_Playerbase"), false, false);
			for( uint i = 0; i < _grp.GetCreatures().length(); i++ )
				m_arrLC3_Crt_AttackingPlayerBase.insertLast(_grp.GetCreatures()[i].GetId() );
			
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.LC3_OnKilled_RemoveFromPlayerBaseArray), _grp.GetCreatures(), true, "");
		}
		else
			_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_CastleBase"), false, false);




		//BUILDING BEHAVIOUR
		_Building.SetActive(false); // deactivate the spawning buidling
		m_iLC3_PuritySiegeWaves++;
		// Check after the increment, so we dont get out of bounds except.
		if( m_iLC3_PuritySiegeWaves >= m_arrStgLC3_Bldg_PuritySiegeSpawns.length() )
		{
			m_iLC3_PuritySiegeWaves = 0; // reset the building array
			//Check if building can be upgraded and if so - do it for all the buildings
			if( m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[0]).GetDescriptionName() != "S_LC3_PuritySiegeSpawn_III" )
			{
				for( uint i = 0; i < m_arrStgLC3_Bldg_PuritySiegeSpawns.length(); i++)
				{
					if( m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).GetDescriptionName() == "S_LC3_PuritySiegeSpawn_I" )
					{
						m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).Upgrade(m_Reference, "S_LC3_PuritySiegeSpawn_II", true);
					}
					else
					{
						m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).Upgrade(m_Reference, "S_LC3_PuritySiegeSpawn_III", true);
					}
				}
			}
		}
		m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[m_iLC3_PuritySiegeWaves]).SetActive(true); // activate the next spawning building
		return false;
	}

	bool LC3_OnBuildingCharged_Bridge(Building& in _Building)
	{
	//	m_Reference.BlockNavMesh("LC3_PhysBlocker_Bridge_01", false);
	//	m_Reference.BlockNavMesh("LC3_PhysBlocker_Bridge_02", false);
	//	m_Reference.GetLogicObjectByName("LC3_RepairedBridge").Enable(true);
	//	_Building.Enable(false);
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_Bridge), 1);
		m_bLC3_BridgeRepaired = true;
		return true;
	}

	bool LC3_OnTimer_Bridge()
	{
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Bridge_01", false);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Bridge_02", false);
		m_Reference.GetLogicObjectByName("LC3_RepairedBridge").Enable(true);
		m_Reference.GetBuildingByName("LC3_BrokenBridge").Enable(false);
		return true;
	}

		// --- SECTOR EVENTS ---------------------------------------------------------------------------------------------
		// When entering the base sector for the first time
	bool LC3_OnEnterSector_Playerbase(Creature& in _Creature)
	{
		if( _Creature == m_Reference.GetCreatureByName(m_stgAvatar) )
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_02_BN_Camp", false);
			return true;
		}
		return false;
	}
	// If the player loses his base sector -> Player lost game
	bool LC3_OnSectorOwnerChanged_PlayerBase(Sector@ _Sector, const uint8 _uPreviousOwnerFaction, const uint8 _uNewOwnerFaction)
	{
		if( _uPreviousOwnerFaction == m_iLC3_Faction_PlayerAllied_AI  )
		{
			printNote("Your allies lost the Capital sector :/");
			CreatureGroup _grp = CreatureGroup( m_Reference, CreateArray_CreaturesFromID( m_arrLC3_Crt_AttackingPlayerBase ) );
			_grp.AttackPosition( m_Reference.GetLogicObjectByName("LC3_Spot_CastleBase"), false, false);

		}
		if( _uPreviousOwnerFaction != m_iPlayerFaction || _uNewOwnerFaction == m_iLC3_Faction_PlayerAllied_AI )
		{
			return false;
		}
		m_Reference.LoseGame(m_iPlayerFaction);
		return true;
	}
	// When the castle is owned by the playerallied AI and gets down
	bool LC3_OnSectorOwnerChanged_PlayerCastle(Sector@ _Sector, const uint8 _uPreviousOwnerFaction, const uint8 _uNewOwnerFaction)
	{
		if( _uPreviousOwnerFaction != m_iLC3_Faction_PlayerAllied_AI )
		{
			return false;
		}
		//m_Reference.LoseGame(m_iPlayerFaction);
		return true;
	}

	// If the purity loses their camp -> rest of their units flee and despawn at map border
	bool LC3_OnSectorOwnerChanged_PurityBase(Sector@ _Sector, const uint8 _uPreviousOwnerFaction, const uint8 _uNewOwnerFaction)
	{
		printNote("Castle changed owner");
		if( _uPreviousOwnerFaction != m_iLC3_Faction_Purity_AI )
		{
			return false;
		}
		printNote("Purity lost their castle");
		  
		m_arrLC3_Crt_FleeingPurity01 = CreateArray_IDFromCreatures( m_Reference.FindCreaturesByFaction(m_iLC3_Faction_Purity_AI, false) );
		m_arrLC3_Crt_FleeingPurity02 = CreateArray_IDFromCreatures( m_Reference.FindCreaturesByFaction(m_iLC3_Faction_Purity, true) );

		CreatureGroup _GrpPurityUnits01 = CreatureGroup(m_Reference, CreateArray_CreaturesFromID( m_arrLC3_Crt_FleeingPurity01) );
		CreatureGroup _GrpPurityUnits02 = CreatureGroup(m_Reference, CreateArray_CreaturesFromID( m_arrLC3_Crt_FleeingPurity02) );
		//Move to map border and despawn
		_GrpPurityUnits01.Move(m_Reference.GetLogicObjectByName("LC3_Spot_PurityFlee"), false, false, false);
		_GrpPurityUnits02.Move(m_Reference.GetLogicObjectByName("LC3_Spot_PurityFlee"), false, false, false);

		//Register Trigger for the units
		m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_DespawnPurity), _GrpPurityUnits01.GetCreatures(), true, "LC3_Trigger_PurityDespawn");
		m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_DespawnPurity), _GrpPurityUnits02.GetCreatures(), true, "LC3_Trigger_PurityDespawn");

		//Disable the wavespawner
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_PurityWaveSpawn01).Enable(false);

		m_Reference.SetFactionRelation(m_iPlayerFaction, m_iLC3_Faction_Purity, Neutral);
		m_Reference.SetFactionRelation(m_iPlayerFaction, m_iLC3_Faction_Purity_AI, Neutral);
		m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, m_iLC3_Faction_Purity, Neutral);
		m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, m_iLC3_Faction_Purity_AI, Neutral);

		// quest update for defeated purity
		m_Reference.LoseGame(m_iLC3_Faction_Purity_AI);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P4_Q1_FreeMyrah_StrikeAgainstPurity", Completed);

		//Trigger the Cutscene here
		LC3_Cutscene_CastleTaken();

		return true;
	}



		// --- OTHER EVENTS ----------------------------------------------------------------------------------------------
	bool LC3_OnLoot_TunnelKey (const uint8 _uPlayerFaction, const string&in _sItemName, const uint _uAmount)
	{
		DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_26_SO_KeyFound", false);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_GetTheKey", Completed);
		return true;
	}

	bool LC3_OnLoot_Rune(const uint8 _uPlayerFaction, const string&in _sItemName, const uint _uAmount)
	{
		if(m_Reference.GetCreatureByName(m_stgAvatar).GetCurrentHP() > 0)
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_33_SO_RuneFound", true);
		}
		m_Reference.RegisterHeroPartyEvent(AnyCanSee, TOnHeroPartyEvent(@this.LC3_OnCansee_HeropartyMyrahFinal), "Myrah_Utran", m_iPlayerFaction);
		m_Reference.GetWorld().EnableDialogueTopic("Myrah_Utran", "LC3_36_Myrah_Talk", true);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P1_Q1_FreeMyrah_GetRuneStone", Completed);
		return true;
	}

	bool LC3_OnLoot_RefugeeBelongings (const uint8 _uPlayerFaction, const string&in _sItemName, const uint _uAmount)
	{
		m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_23_Refugee_Tunnels", true);
		m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_24_SO_Greeting_02", false);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_GetRefugeeStuff", Completed);
		return true;
	}


	// HERE IS A SPECIAL SECTION FOR THE SPAWNING UTRAN UNITS GOING THROUGH DIFFERENT GATES
	// ITS EASIER TO HAVE THIS TOGETHER INSTEAD OF SPLITTING IT UP

		/*
			Increment the wavecount
			Depending on that count, choose where the spawned units are going ( each direction has a different exit )
			Register the events for reaching end of path and getting killed
			Store the spawned creatures into the correct array - for each direction one
			After 3 units spawned upgrade the spawner to it's next level
		*/
	bool LC3_OnWaveSpawned_UtranSiegeWave(Building&in _Building, Creature[]&in _Creatures)
	{
		m_iLC3_UtranSiegeWaves++;
		printNote(" Utran wave spawned " + m_iLC3_UtranSiegeWaves);
		CreatureGroup _grp = CreatureGroup(m_Reference, _Creatures);
		string _stgPath = "";
		if( m_iLC3_UtranSiegeWaves % 3  == 0)
		{
			if( m_Reference.GetSectorByName(m_stgLC3_Sector_Playerbase).GetOwner() == m_iLC3_Faction_PlayerAllied_AI || m_Reference.GetSectorByName(m_stgLC3_Sector_Playerbase).GetOwner() == m_iPlayerFaction )
			{
				_stgPath = "LC3_Path_UtranSiege_03";
				m_Reference.RegisterCreatureEventByIndividuals(FollowPathFinished, TOnCreatureEvent(@this.LC3_OnPathFinished_UtranSiegeAtGate_03), _Creatures, true, _stgPath);
			}
			else
			{
				_stgPath = "LC3_Path_UtranSiege_02";
				m_Reference.RegisterCreatureEventByIndividuals(FollowPathFinished, TOnCreatureEvent(@this.LC3_OnPathFinished_UtranSiegeAtGate_02), _Creatures, true, _stgPath);
			}
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.LC3_OnKilled_SpawnedUtranSiege_03), _Creatures, true, "");
			m_arrLC3_Crt_SpawnedUtran_Units_03 = CreateArray_IDFromCreatures( _Creatures );
			
			if(m_iLC3_UtranSiegeWaves == 3)
			{
				m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).Upgrade(m_Reference, "S_LC3_UtranSiegeSpawn_II", true);
			}
			else if(m_iLC3_UtranSiegeWaves == 6)
			{
				m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).Upgrade(m_Reference, "S_LC3_UtranSiegeSpawn_III", true);
			}
		}
		else if( m_iLC3_UtranSiegeWaves % 2 == 0 )
		{
			_stgPath = "LC3_Path_UtranSiege_02";
			m_Reference.RegisterCreatureEventByIndividuals(FollowPathFinished, TOnCreatureEvent(@this.LC3_OnPathFinished_UtranSiegeAtGate_02), _Creatures, true, _stgPath);
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.LC3_OnKilled_SpawnedUtranSiege_02), _Creatures, true, "");
			m_arrLC3_Crt_SpawnedUtran_Units_02 =  CreateArray_IDFromCreatures( _Creatures );
		}
		else
		{
			_stgPath = "LC3_Path_UtranSiege_01";
			m_Reference.RegisterCreatureEventByIndividuals(FollowPathFinished, TOnCreatureEvent(@this.LC3_OnPathFinished_UtranSiegeAtGate_01), _Creatures, true, _stgPath);
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.LC3_OnKilled_SpawnedUtranSiege_01), _Creatures, true, "");
			m_arrLC3_Crt_SpawnedUtran_Units_01 = CreateArray_IDFromCreatures( _Creatures );
		}
		_grp.FollowPathSmooth(_stgPath, true, true, kMaxFactions, WaitForAnyHeroes, false, false);

		return false;
	}

	array<uint> CreateArray_IDFromCreatures( array<Creature> _Creatures )
	{
		array<uint> _arr = {};
		for( uint i = 0; i < _Creatures.length(); i++ )
			_arr.insertLast( _Creatures[i].GetId() );

		return _arr;
	}

	array<Creature> CreateArray_CreaturesFromID( array<uint> _IDs )
	{
		array<Creature> _arr = {};
		for( uint i = 0; i < _IDs.length(); i++ )
			_arr.insertLast( m_Reference.GetCreatureById(_IDs[i]) );

		return _arr;
	}

	// +++++++++++++  U N I T S   0 1  +++++++++++++
	/*
		When reaching the gate
		- open it (currently disable) and unblock the navmeshblocker
		- Wait a second and then move on to the castle
		-Register the event to close the gate (when leaving the area around the gate)

	*/
	bool LC3_OnPathFinished_UtranSiegeAtGate_01(Creature& in _Creature)
	{
		printNote("Force at the Gate 1");
		m_Reference.GetLogicObjectByName("LC3_UtranBorder_Barricade_01").Enable(false);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_01", false);
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_UtranForceThroughGate_Castle_01), 1);

		array<Creature> _Siege = CreateArray_CreaturesFromID( m_arrLC3_Crt_SpawnedUtran_Units_01 );
		m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.LC3_OnTriggerLeft_CloseGate_01), _Siege , true, "LC3_Trigger_CloseGate_01");
		return true;
	}

	/*
		When the units from the array are killed - they need to be reomved from the array, otherwise we have some zombies here
	*/
	bool LC3_OnKilled_SpawnedUtranSiege_01(Creature& in _Creature)
	{
		if( m_arrLC3_Crt_SpawnedUtran_Units_01.length() == 0)
		{
			return true;
		}
		for( uint i = 0; i < m_arrLC3_Crt_SpawnedUtran_Units_01.length(); i++ )
		{
			if( m_Reference.GetCreatureById( m_arrLC3_Crt_SpawnedUtran_Units_01[i] ) == _Creature )
			{
				m_arrLC3_Crt_SpawnedUtran_Units_01.removeAt(i);
				break;
			}
		}
		if( m_arrLC3_Crt_SpawnedUtran_Units_01.length() == 0)
		{
			printNote("All Utran Sieges 01 dead");
			return true;
		}
		return false;
	}




	/*
		- Count how many units left the trigger - if it's over the unit count - close the gate (maybe also time it?)
		- Block navmesh - enable gate
		- Reset units outside count
	*/
	bool LC3_OnTriggerLeft_CloseGate_01(Creature& in _Creature)
	{
		m_iLC3_UtranSiegeOutsideGate_01++;
		if( m_iLC3_UtranSiegeOutsideGate_01 >= m_arrLC3_Crt_SpawnedUtran_Units_01.length())
		{
			printNote("leaving gate 1");
			m_arrLC3_Crt_SpawnedUtran_Units_01.resize(0);
			m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_02", true);
			m_Reference.GetLogicObjectByName("LC3_UtranBorder_Barricade_01").Enable(true);
			m_iLC3_UtranSiegeOutsideGate_01 = 0;
			return true;
		}
		return false;
	}
	/*
		Move to the castle and attack everything hostile on the way
	*/
	bool LC3_OnTimer_UtranForceThroughGate_Castle_01()
	{
		CreatureGroup _grp = CreatureGroup(m_Reference, CreateArray_CreaturesFromID( m_arrLC3_Crt_SpawnedUtran_Units_01) );
		printNote("Attack the Castle");
	//	_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_Castle"), false, false);
		_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_CastleBase"), false, false);
		return true;
	}

	// +++++++++++++  U N I T S   0 2  +++++++++++++
	/*
		When reaching the gate
		- open it (currently disable) and unblock the navmeshblocker
		- Wait a second and then move on to the castle
		-Register the event to close the gate (when leaving the area around the gate)
	*/
	bool LC3_OnPathFinished_UtranSiegeAtGate_02(Creature& in _Creature)
	{
		printNote("Force at the Gate 2");
		m_Reference.GetLogicObjectByName("LC3_UtranBorder_Barricade_02").Enable(false);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_02", false);
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_UtranForceThroughGate_Castle_02), 1);

		array<Creature> _Siege = CreateArray_CreaturesFromID(m_arrLC3_Crt_SpawnedUtran_Units_02);
		m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.LC3_OnTriggerLeft_CloseGate_02), _Siege, true, "LC3_Trigger_CloseGate_02");
		return true;
	}

	/*
		When the units from the array are killed - they need to be reomved from the array, otherwise we have some zombies here
	*/
	bool LC3_OnKilled_SpawnedUtranSiege_02(Creature& in _Creature)
	{
		if( m_arrLC3_Crt_SpawnedUtran_Units_02.length() == 0)
		{
			return true;
		}
		for( uint i = 0; i < m_arrLC3_Crt_SpawnedUtran_Units_02.length(); i++ )
		{
			if( m_Reference.GetCreatureById( m_arrLC3_Crt_SpawnedUtran_Units_02[i] ) == _Creature )
			{
				m_arrLC3_Crt_SpawnedUtran_Units_02.removeAt(i);
				break;
			}
		}
		if( m_arrLC3_Crt_SpawnedUtran_Units_02.length() == 0)
		{
			printNote("All Utran Sieges 02 dead");
			return true;
		}
		return false;
	}
	/*
		- Count how many units left the trigger - if it's over the unit count - close the gate (maybe also time it?)
		- Block navmesh - enable gate
		- Reset units outside count
	*/
	bool LC3_OnTriggerLeft_CloseGate_02(Creature& in _Creature)
	{
		m_iLC3_UtranSiegeOutsideGate_02++;
		if( m_iLC3_UtranSiegeOutsideGate_02 >= m_arrLC3_Crt_SpawnedUtran_Units_02.length())
		{
			m_arrLC3_Crt_SpawnedUtran_Units_02.resize(0);
			printNote("leaving gate 2");
			m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_02", true);
			m_Reference.GetLogicObjectByName("LC3_UtranBorder_Barricade_02").Enable(true);
			m_iLC3_UtranSiegeOutsideGate_02 = 0;
			return true;
		}
		return false;
	}
	/*
		Move to the castle and attack everything hostile on the way
	*/
	bool LC3_OnTimer_UtranForceThroughGate_Castle_02()
	{
		CreatureGroup _grp = CreatureGroup(m_Reference, CreateArray_CreaturesFromID( m_arrLC3_Crt_SpawnedUtran_Units_02) );
		printNote("Attack the Castle");
		_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_CastleBase"), false, false);
		//_grp.AttackPosition(m_Reference.GetSectorByName( m_stgLC3_Sector_PurityCastle ).GetMainBuilding(), false, false);
		return true;
	}


	// +++++++++++++  U N I T S   0 3  +++++++++++++
	/*
		When reaching the gate
		- open it (currently disable) and unblock the navmeshblocker
		- Wait a second and then move on to the player base
		-Register the event to close the gate (when leaving the area around the gate)
	*/
	bool LC3_OnPathFinished_UtranSiegeAtGate_03(Creature& in _Creature)
	{
		printNote("Force at the Gate 3");
		m_Reference.GetLogicObjectByName("LC3_UtranBorder_Barricade_03").Enable(false);
		m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_03", false);
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_UtranForceThroughGate_PlayerBase), 1);

		array<Creature> _Siege = CreateArray_CreaturesFromID( m_arrLC3_Crt_SpawnedUtran_Units_03 );
		m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.LC3_OnTriggerLeft_CloseGate_03), _Siege , true, "LC3_Trigger_CloseGate_03");
		return true;
	}
	/*
		When the units from the array are killed - they need to be reomved from the array, otherwise we have some zombies here
	*/
	bool LC3_OnKilled_SpawnedUtranSiege_03(Creature& in _Creature)
	{
		if( m_arrLC3_Crt_SpawnedUtran_Units_03.length() == 0)
		{
			return true;
		}
		for( uint i = 0; i < m_arrLC3_Crt_SpawnedUtran_Units_03.length(); i++ )
		{
			if( m_Reference.GetCreatureById( m_arrLC3_Crt_SpawnedUtran_Units_03[i] ) == _Creature )
			{
				m_arrLC3_Crt_SpawnedUtran_Units_03.removeAt(i);
				break;
			}
		}
		if( m_arrLC3_Crt_SpawnedUtran_Units_03.length() == 0)
		{
			printNote("All Utran Sieges 03 dead");
			return true;
		}
		return false;
	}
	/*
		- Count how many units left the trigger - if it's over the unit count - close the gate (maybe also time it?)
		- Block navmesh - enable gate
		- Reset units outside count
	*/
	bool LC3_OnTriggerLeft_CloseGate_03(Creature& in _Creature)
	{
		m_iLC3_UtranSiegeOutsideGate_03++;
		if( m_iLC3_UtranSiegeOutsideGate_03 >= m_arrLC3_Crt_SpawnedUtran_Units_03.length())
		{
			m_arrLC3_Crt_SpawnedUtran_Units_03.resize(0);
			printNote("leaving gate 3");
			m_Reference.BlockNavMesh("LC3_PhysBlocker_Wall_03", true);
			m_Reference.GetLogicObjectByName("LC3_UtranBorder_Barricade_03").Enable(true);
			m_iLC3_UtranSiegeOutsideGate_03 = 0;
			return true;
		}
		return false;
	}
	/*
		Move to the playerbase and attack everything hostile on the way
	*/
	bool LC3_OnTimer_UtranForceThroughGate_PlayerBase()
	{
		CreatureGroup _grp = CreatureGroup(m_Reference, CreateArray_CreaturesFromID( m_arrLC3_Crt_SpawnedUtran_Units_03) );
		
		if( m_Reference.GetSectorByName(m_stgLC3_Sector_Playerbase).GetOwner() == m_iLC3_Faction_PlayerAllied_AI || m_Reference.GetSectorByName(m_stgLC3_Sector_Playerbase).GetOwner() == m_iPlayerFaction )
		{
			printNote("Attack the playerbase");
			_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_Playerbase"), false, false);
			for( uint i = 0; i < _grp.GetCreatures().length(); i++ )
				m_arrLC3_Crt_AttackingPlayerBase.insertLast(_grp.GetCreatures()[i].GetId());
			
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.LC3_OnKilled_RemoveFromPlayerBaseArray), _grp.GetCreatures(), true, "");
		}
		else
			_grp.AttackPosition(m_Reference.GetLogicObjectByName("LC3_Spot_CastleBase"), false, false);
		return true;
	}

	bool LC3_OnKilled_RemoveFromPlayerBaseArray( Creature& in _Creature )
	{
		for( uint i = 0; i < m_arrLC3_Crt_AttackingPlayerBase.length(); i++ )
			if( m_Reference.GetCreatureById( m_arrLC3_Crt_AttackingPlayerBase[i] ) == _Creature )
			{
				m_arrLC3_Crt_AttackingPlayerBase.removeAt(i);
				return false;
			}
			return false;
	}


	// -------------------------------------------------------------------------------------------------------------------
	// --- C U T S C E N E  F U N C T I O N S ----------------------------------------------------------------------------
	void LC3_Cutscene_MapIntro()
	{
		printNote("Playing the Cutscene: LC3_01_Map_Intro");
		// Angar joins after the cutscene
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.LC3_OnCutsceneFinished_MapIntro), kMaxFactions);
		m_Reference.PlayCutScene("LC3_01_MapIntro");
		 
		  //CHEATING HARD
		//  m_Reference.SetTimer(TOnTimerEvent(@this.LC3_Cheat_PurityDefeated), 120);
	}

	bool LC3_OnCutsceneFinished_MapIntro(const uint8 _uPlayerFaction)
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q1_FreeMyrah", "P4_Q1_FreeMyrah_ToLoyalistCamp", Completed);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "cutscene", 0);
		return true;	
	}

	void LC3_Cutscene_MapIntro_AngarJoins()
	{
		  HeroPartyJoin(m_stgLC3_Crt_Angar);
	}

	void LC3_Cutscene_CastleTaken()
	{
		printNote("Playing the Cutscene: LC3_Castle_Taken");
		m_Reference.PlayCutScene("LC3_13_FortressCaptured");
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.LC3_OnCutsceneFinished_CastleTaken), m_iPlayerFaction);
	}

	bool LC3_OnCutsceneFinished_CastleTaken(const uint8 _uPlayerFaction)
	{
		LC3_TimeSkip01();
		return true;	
	}

	void LC3_Cutscene_HarbingerAttacks()
	{
		printNote("Playing the Cutscene: LC3_16_HarbingerAttacks");

		//Enable the siege camps
		m_Reference.EnableGroup("LC3_Grp_SiegeCamp_01", true);
		m_Reference.EnableGroup("LC3_Grp_SiegeCamp_02", true);

		for( uint i = 0; i < m_arrStgLC3_SiegeCampLights.length(); i++)
		{
			m_Reference.EnableLight(m_arrStgLC3_SiegeCampLights[i], true);
		}

		m_Reference.PlayCutScene("LC3_16_HarbingerAttacks");
		//LC3_Cutscene_HarbingerAttacks_EnableHarbinger();
		//LC3_Cutscene_HarbingerAttacks_EnableMyrah();
		//LC3_Cutscene_HarbingerAttacks_EnablePurityUnitsAtGate();
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.LC3_OnCutsceneFinished_HarbingerAttacks), m_iPlayerFaction);
		LC3_TimeSkip02();
	}

	bool LC3_OnCutsceneFinished_HarbingerAttacks(const uint8 _uPlayerFaction)
	{
		DialogTalkTo(m_stgLC3_Crt_Angar, m_stgAvatar, m_stgLC3_Crt_Angar, "LC3_17_MeetSpy");
		return true;
	}
	
	//"The Harbringer and Utran forces finally arrive from the Utran border behind the large border wall."
	void LC3_Cutscene_HarbingerAttacks_EnableHarbinger()
	{
		//m_Reference.ActivateSpawn("LC3_SP_Harbinger", true);
		for( uint i = 0; i < m_arrLC3_Stg_PurityPatrolsSpawns.length(); i++)
		{
			m_Reference.ActivateSpawn(m_arrLC3_Stg_PurityPatrolsSpawns[i], true);
		}
	}

	//"It then shows how Myrah moves in with some troops together with some purity rune guardians."
	void LC3_Cutscene_HarbingerAttacks_EnableMyrah()
	{
		m_Reference.ActivateSpawn("LC3_SP_Myrah", true);
		m_Reference.GetCreatureByName("Myrah_Utran").SetAttackable(false);
		m_Reference.GetCreatureByName("Myrah_Utran").AllowAttacks(false);
		m_Reference.ActivateSpawn("LC3_SP_RuneGuards", true);
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.LC3_OnKilled_RuneGuards), m_Reference.GetCreaturesFromSpawn("LC3_SP_RuneGuards"), false, "");
		SpawnAttackable("LC3_SP_RuneGuards", false);
		SpawnAllowAttacks("LC3_SP_RuneGuards", false);
	}

	//"[...] the camera skips to one of the border wall gates where some more purity troops come out [...] "
	void LC3_Cutscene_HarbingerAttacks_EnablePurityUnitsAtGate()
	{
		m_Reference.ActivateSpawn("LC3_SP_PurityCommander01", true);
		m_Reference.ActivateSpawn("LC3_SP_PurityCommander02", true);
		m_Reference.ActivateSpawn("LC3_SP_PurityCommander03", true);
		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.LC3_OnKilled_PurityCommander), "LC3_PurityCommander_01", "");
		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.LC3_OnKilled_PurityCommander), "LC3_PurityCommander_02", "");
		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.LC3_OnKilled_PurityCommander), "LC3_PurityCommander_03", "");
	}

	// -------------------------------------------------------------------------------------------------------------------
	// --- A R T I C Y  F U N C T I O N S --------------------------------------------------------------------------------
	void LC3_Articy_Choose_Undergast()
	{
		m_Reference.ActivateSpawn("LC3_SP_Undergast", true);
		HeroPartyJoin(m_stgHero_Undergast);
	}
	void LC3_Articy_Choose_Rohen()
	{
		m_Reference.ActivateSpawn("LC3_SP_Rohen", true);
		HeroPartyJoin(m_stgHero_Rohen);
	}
	void LC3_Articy_Choose_Isgrimm()
	{
		m_Reference.ActivateSpawn("LC3_SP_Isgrimm", true);
		HeroPartyJoin(m_stgHero_Isgrimm);
	}
	void LC3_Articy_Choose_Gor()
	{
		m_Reference.ActivateSpawn("LC3_SP_Gor", true);
		HeroPartyJoin(m_stgHero_Gor);
	}
	void LC3_Articy_Choose_Uram()
	{
		m_Reference.ActivateSpawn("LC3_SP_Uram", true);
		HeroPartyJoin(m_stgHero_Uram);
	}
	void LC3_Articy_Choose_Yria()
	{
		m_Reference.ActivateSpawn("LC3_SP_Yria", true);
		HeroPartyJoin(m_stgHero_Yria);
	}
	void LC3_Articy_Choose_Ianna()
	{
		m_Reference.ActivateSpawn("LC3_SP_Ianna", true);
		HeroPartyJoin(m_stgHero_Ianna);
	}

	void LC3_Articy_ScoutArriving()
	{
		printNote("The scout is arriving with an important message");
		m_Reference.GetCreatureByName("LC3_Scout").GoTo(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Castle"), 10, 20, false, false);
	}

	void LC3_Articy_FortifyFortressStarted()
	{
		printNote("Move your ass and fortify our home");
		m_iLC3_TimerFunc_FortifyCountdown =  m_Reference.CreateCountdownTimer(0, m_iLC3_Timer_FortifyTime, TOnTimerEvent(@this.LC3_OnTimer_FortifyCastleEnd), m_iPlayerFaction, "LC3_Timer_PurityAttack");

	}

	void LC3_Articy_TalkedAboutSpy()
	{
		m_Reference.ActivateAI(m_iLC3_Faction_PlayerAllied_AI);
		m_Reference.ActivateAI(m_iLC3_Faction_Utran_AI);
		// Activate wave spawner (allied)
		for( uint i = 0; i < m_arrStgLC3_Bldg_PuritySiegeSpawns.length(); i++ )
		{
			m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).Enable(true);
			m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).SetFaction(m_iLC3_Faction_Purity);
			m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.LC3_OnWaveSpawned_PuritySiegeWave), m_arrStgLC3_Bldg_PuritySiegeSpawns[i]);

			if( i != 0 )
			{
				m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]).SetActive(false);
			}
		}
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).Enable(true);
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).SetInteractive(false);
		m_Reference.GetBuildingByName(m_stgLC3_Bldg_UtranSiegeSpawn01).SetFaction(3); // Utran Faction
		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.LC3_OnWaveSpawned_UtranSiegeWave), m_stgLC3_Bldg_UtranSiegeSpawn01);

		m_Reference.GetCreatureByName("Myrah_Utran").Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Myrah"));
		m_Reference.GetCreatureByName("LC3_Rune_Priest").Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Myrah"));
		m_Reference.GetCreatureByName("LC3_Rune_Priest_02").Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Myrah"));
		//enable the gate guards
		for( uint i = 0; i < m_arrLC3_Stg_GateGuardSpawns.length(); i++ )
		{
			m_Reference.ActivateSpawn(m_arrLC3_Stg_GateGuardSpawns[i], true);
		}
	}

	void LC3_Articy_TalkedWithSpy()
	{
		if(m_bLC3_FoundTunnel)
		{
			m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_TunnelHint), 2);
		}
		m_Reference.GetCreatureByName("LC3_Spy_Herveus").FollowPath(m_Reference, "LC3_Path_SpyLeaving", true, false, false);
		m_Reference.RegisterCreatureEventByIndividual(FollowPathFinished, TOnCreatureEvent(@this.OnDespawnCreature), "LC3_Spy_Herveus", "LC3_Path_SpyLeaving");
	}

	void LC3_Articy_GetKeyLocationFromRefugee()
	{
		m_Reference.GetLogicObjectByName("LC3_Loot_TunnelKey").Enable(true);
	}

	void LC3_Articy_SendHeroThroughTunnel()
	{
		//Check who is curerntly going through the tunnel
		if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_YriaInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Yria).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Yria).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_RohenInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Rohen).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Rohen).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_GorInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Gor).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Gor).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_UramInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Uram).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Uram).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_UndergastInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Undergast).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Undergast).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_IannaInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Ianna).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Ianna).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_IsgrimmInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Isgrimm).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.GetCreatureByName(m_stgHero_Isgrimm).Enable(false);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_AvatarInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgAvatar).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			m_Reference.FocusCamera(m_iPlayerFaction, m_Reference.GetLogicObjectByName("LC3_Switch_TunnelExit"));
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_28_SO_CompanionThrough", false);
		}
		if( !m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_AvatarInTunnel" ) )
		{
			m_Reference.CreateCountdownTimer(0, 30, TOnTimerEvent(@this.LC3_OnTimer_HeroThroughTunnel), m_iPlayerFaction);
			m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_HeroInTunnel), 10);
		}
		m_Reference.GetLogicObjectByName("LC3_Switch_TunnelEntry01").SetInteractive(false);
	}

	bool LC3_OnTimer_SO_HeroInTunnel()
	{
		DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_27B_SO_SentThroughTunnel", false);
		return true;
	}

	bool LC3_OnTimer_HeroThroughTunnel()
	{
		printNote("Reached the end of the Tunnel A");
		if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_YriaInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Yria).Enable(true);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_RohenInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Rohen).Enable(true);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_GorInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Gor).Enable(true);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_UramInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Uram).Enable(true);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_UndergastInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Undergast).Enable(true);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_IannaInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Ianna).Enable(true);
		}
		else if( m_Reference.GetWorld().GetGlobalBool("MapVariables.LC3_IsgrimmInTunnel") )
		{
			m_Reference.GetCreatureByName(m_stgHero_Isgrimm).Enable(true);
		}
		if(!m_bLC3_UsedTunnel)
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "LC3_28_SO_CompanionThrough", false);
			m_bLC3_UsedTunnel = true;
		}

		return true;
	}

	void LC3_Articy_SO_TunnelExit(){

		printNote("Reached the end of the Tunnel B");
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_YriaInTunnel", false);
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_RohenInTunnel", false);
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_GorInTunnel", false);
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_UramInTunnel", false);
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_UndergastInTunnel", false);
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_IannaInTunnel", false);
		m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_IsgrimmInTunnel", false);
		m_Reference.GetLogicObjectByName("LC3_Switch_TunnelEntry01").SetInteractive(true);
	}

	void LC3_Articy_MyrahLeaving()
	{
		printNote("Myrah should leave");
		m_Reference.GetCreatureByName("Myrah_Utran").EnablePOIVisitingBehavior(false);
		if(m_bLC3_RuneGuardsAggro01)
		{
			printNote("Myrah going to Spot 1");
			m_Reference.GetCreatureByName("Myrah_Utran").GoTo(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Myrah_Flee_01"), 3, 6, false, false);
		}
		else if( m_bLC3_RuneGuardsAggro02 )
		{
			printNote("Myrah going to Spot 2");
			m_Reference.GetCreatureByName("Myrah_Utran").GoTo(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Myrah_Flee_02"), 3, 6, false, false);
		}

		SpawnAttackable("LC3_SP_RuneGuards", true);
		SpawnAllowAttacks("LC3_SP_RuneGuards", true);
	}

	void LC3_Articy_RefugeeScolding()
	{
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_SO_Scolding), 6);
	}

	void LC3_Articy_CheckInventoryForRefugee()
	{
		printNote("LC3_Articy_CheckInventoryForRefugee");

		/*if(m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("LC3_RefugeeBelongings", 1)){
			printNote("I have his stuff");
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_24_SO_Greeting_02", false);
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_23_Refugee_Tunnels", true);
		}
		else{
			printNote("I dont have his stuff");
			m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.LC3_OnLoot_RefugeeBelongings), "LC3_RefugeeBelongings", m_iPlayerFaction);
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_23_Refugee_Tunnels", false);
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_24_SO_Greeting_02", true);
		}
		*/
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_OnTimer_CheckInventoryRefugeeItems), 1);
	}

	bool LC3_OnTimer_CheckInventoryRefugeeItems()
	{
		if(m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("LC3_RefugeeBelongings", 1))
		{
			printNote("I have his stuff");
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_24_SO_Greeting_02", false);
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_23_Refugee_Tunnels", true);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_MAP001_TheTunnel", "P4_MAP001_TheTunnel_GetRefugeeStuff", Completed);
		}
		else
		{
			printNote("I dont have his stuff");
			m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.LC3_OnLoot_RefugeeBelongings), "LC3_RefugeeBelongings", m_iPlayerFaction);
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_23_Refugee_Tunnels", false);
			m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_24_SO_Greeting_02", true);
		}
		return true;
	}

	void LC3_Articy_FoundRefugee()
	{
		m_bLC3_FoundRefugee = true;
	}

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

	//Check which initial units the player gets (depending on his game progress)
	void LC3_CheckInitialPlayerUnits()
	{
		//if( human faction mission 1 done )
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P3_Q5c_GainHumans") == Completed )
			m_Reference.ActivateSpawn("LC3_SP_Player_Hu1", true);
		//if( human faction mission 2 done )
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P4_MAP016_StrengthenHumans") == Completed )
			m_Reference.ActivateSpawn("LC3_SP_Player_Hu2", true);
		//if( elf faction mission 1 done )
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P3_Q5a_GainElves") == Completed )
			m_Reference.ActivateSpawn("LC3_SP_Player_Elf1", true);
		//if( elf faction mission 2 done )
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P4_MAP020_HR") == Completed )			
			m_Reference.ActivateSpawn("LC3_SP_Player_Elf2", true);
		//if( orc faction mission 1 done )
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P3_Q5b_GainOrcs") == Completed )
			m_Reference.ActivateSpawn("LC3_SP_Player_Orc1", true);
		//if( orc faction mission 2 done )
		if( m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P4_Q11_BargaGor2") == Completed )
			m_Reference.ActivateSpawn("LC3_SP_Player_Orc2", true);
	}

	void RemovePuritySiegeSpawner( Building& in _Building )
	{
		// Remove the building from our array
		for( uint i = 0; i < m_arrStgLC3_Bldg_PuritySiegeSpawns.length(); i++)
		{
			if( m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[i]) == _Building )
			{
				m_arrStgLC3_Bldg_PuritySiegeSpawns.removeAt(i);
				break;
			}
		}
		if( m_arrStgLC3_Bldg_PuritySiegeSpawns.length() == 0)
		{
			return;
		}

		if( m_iLC3_PuritySiegeWaves >= m_arrStgLC3_Bldg_PuritySiegeSpawns.length() )
		{
			m_iLC3_PuritySiegeWaves = 0; // reset the building array
		}
		m_Reference.GetBuildingByName(m_arrStgLC3_Bldg_PuritySiegeSpawns[m_iLC3_PuritySiegeWaves]).SetActive(true); // activate the next spawning building
		m_iLC3_PuritySiegeWaves++; // need to increment, otherwise the cycle stops for a moment - right?

		//have to check again here :/ can i find a smoother solution here?
		if( m_iLC3_PuritySiegeWaves >= m_arrStgLC3_Bldg_PuritySiegeSpawns.length() )
		{
			m_iLC3_PuritySiegeWaves = 0; // reset the building array
		}
	}
	//m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).FollowPath( m_Reference, m_stgLC2_StartedOnRoute, true, true, false );

	void LC2CaravanStop()
	{
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).Stop( m_Reference );
		//DialogShoutout( m_stgCrt_ClaraFarlorn, m_stgCrt_ClaraFarlorn, "FH2_SO_CaravanAmbush_"+m_iFH2_Ambushes, false );
	}

	void LC2CaravanContinue()
	{
		m_Reference.GetCreatureByName( m_stgLC2_crtClaraFarlorn ).FollowPath( m_Reference, m_stgLC2_StartedOnRoute, true, true, false );
		//DialogShoutout( m_stgLC2_crtClaraFarlorn, m_stgCrt_ClaraFarlorn, "FH2_SO_CaravanContinue_"+m_iFH2_Ambushes, false );

		LC2_Villagers_MoveBehindClara();
	}

	bool LC2_Villagers_MoveBehindClara()
	{	
		array <Creature> _tempVillagers;
		// get all villager spawns
		for(uint i = 0; i < m_arrStg_FHVillagerSpawns.length()-1; i++)
		{
			EnablePOIVisitingBehaviorSpawn( m_arrStg_FHVillagerSpawns[i], false );
			_tempVillagers = m_Reference.GetCreaturesFromSpawn(m_arrStg_FHVillagerSpawns[i]);
			// get all creatures of these spawns
			for(uint j = 0; j < _tempVillagers.length(); j++)
			{
				// send them to clara
				_tempVillagers[j].AllowAttacks(false);
				_tempVillagers[j].FollowCreature(m_Reference, m_Reference.GetCreatureByName(m_stgLC2_crtClaraFarlorn), (100) + (30*i), (30*i), false, false);
			}
		}
		array <Creature> _tempMilitia;
		// also send militia
		for(uint i = 0; i < m_arrStg_FHMilitiaSpawns.length(); i++)
		{
			EnablePOIVisitingBehaviorSpawn( m_arrStg_FHMilitiaSpawns[i], false );
			_tempMilitia = m_Reference.GetCreaturesFromSpawn(m_arrStg_FHMilitiaSpawns[i]);
			// get all creatures of these spawns
			for(uint j = 0; j < _tempMilitia.length(); j++)
			{
				// send them to clara
				_tempMilitia[j].AllowAttacks(true);
				_tempMilitia[j].FollowCreature(m_Reference, m_Reference.GetCreatureByName(m_stgLC2_crtClaraFarlorn), (100) + (30*i), (30*i), false, false);
			}
		}
		m_Reference.SetTimer( TOnTimerEvent(@this.LC2_StartCarriageMovement), 5 );	
		return true;
	}

	bool LC2_StartCarriageMovement()
	{
		printNote("sending carriages");
		// get all creatures of these spawns
		array <Creature> _tempCarriages;

		_tempCarriages = m_Reference.GetCreaturesFromSpawn(m_arrStg_FHVillagerSpawns[m_arrStg_FHVillagerSpawns.length()-1]);
		for(uint j = 0; j < _tempCarriages.length(); j++)
		{
			_tempCarriages[j].EnablePOIVisitingBehavior(false);
			//m_Reference.GetCreatureByName(m_arrFH2_Carriages[j]).FollowPath( m_Reference, m_stgPath_ToEverlight, true, true, false );
			_tempCarriages[j].FollowCreature(m_Reference, m_Reference.GetCreatureByName(m_stgLC2_crtClaraFarlorn), (300) + (30*j), 100+(30*j), false, false);
			//m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.OnFH2_VillagerDied), m_arrFH2_Carriages[j], "");
			//m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.OnFH2_DespawnVillagers), m_arrFH2_Carriages[j], m_stgTrg_DespawnWest);
		}

		return true;
	}

	bool LC3_TimeSkip01()
	{
		printNote("The castle has been taken, the player gets the Sector");
		// Destroy all the purity sector centers
		//for( uint i = 0; i < m_Reference.GetSectorsByOwner(m_iLC3_Faction_Purity_AI).length(); i++ ){
		//	printNote("Deleted Sector center");
		//	m_Reference.GetSectorsByOwner(m_iLC3_Faction_Purity_AI)[0].GetMainBuilding().Destroy();
		//}
		// Disable all the fleeing units (array 1)
		for( uint i = 0; i < m_arrLC3_Crt_FleeingPurity01.length(); i++ ){
			m_Reference.GetCreatureById(m_arrLC3_Crt_FleeingPurity01[i]).Enable(false);
		}
		// Disable all the fleeing units (array 2)
		for( uint i = 0; i < m_arrLC3_Crt_FleeingPurity02.length(); i++ ){
			m_Reference.GetCreatureById(m_arrLC3_Crt_FleeingPurity02[i]).Enable(false);
		}
		// Player gets ownership of the castle
		m_Reference.GetSectorByName(m_stgLC3_Sector_PurityCastle).SetOwner(m_iPlayerFaction);
		// Castle is an expansion
		m_Reference.GetSectorByName(m_stgLC3_Sector_PurityCastle).CreateExpansion(m_iPlayerFaction, true, false);

		//all buildings from the castle go over to the player
		for( uint i = 0; i < m_Reference.GetSectorByName(m_stgLC3_Sector_PurityCastle).GetBuildings().length(); i++ ){
			m_Reference.GetSectorByName(m_stgLC3_Sector_PurityCastle).GetBuildings()[i].SetFaction(m_iPlayerFaction);
		}
		// All other buildings, build by purity ai becomes neutral
	//	m_Reference.TransferFactionAssets(m_iLC3_Faction_Purity_AI, kFactionNeutral);
		// Spawn the scout who joins your talk with angar
		m_Reference.ActivateSpawn("LC3_SP_Scout_01", true);
		// Move the heroparty to the castle ( not needed, because of the cutscene )
	//	HeroPartyTeleport("LC3_Spot_Castle");
		// Move the angar to the castle ( not needed, because of the cutscene )
	//	m_Reference.GetCreatureByName(m_stgLC3_Crt_Angar).Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Castle"));
		// Center camera on the castle ( not needed, because of the cutscene )
		m_Reference.FocusCamera(m_iPlayerFaction, m_Reference.GetCreatureByName(m_stgAvatar));
		// Angar leaves the heroparty
		HeroPartyLeave( m_stgLC3_Crt_Angar, kFactionNeutral );
		// Start the Dialog with Angar
		DialogTalkTo(m_stgLC3_Crt_Angar, m_stgAvatar, m_stgLC3_Crt_Angar, "LC3_14_ChooseCompanion");

		// Set player + player allies hostile towards the purity again
		m_Reference.SetFactionRelation(m_iPlayerFaction, m_iLC3_Faction_Purity, Hostile);
		m_Reference.SetFactionRelation(m_iPlayerFaction, m_iLC3_Faction_Purity_AI, Hostile);
		m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, m_iLC3_Faction_Purity, Hostile);
		m_Reference.SetFactionRelation(m_iLC3_Faction_PlayerAllied_AI, m_iLC3_Faction_Purity_AI, Hostile);

		// Player needs to get Sector 11 right? If not this can be deleted (TODO: ASK SOMEONE)
		if( m_Reference.GetSectorByName("Sector_11").GetOwner() != m_iPlayerFaction ){
			m_Reference.GetSectorByName("Sector_11").CreateExpansion(m_iPlayerFaction, true, true);
			m_Reference.GetSectorByName("Sector_11").SetOwner(m_iPlayerFaction);
		}

		return true;
	}

	void LC3_TimeSkip02()
	{
		// position myrah utran + rune guardians (after the cutscene, they are visible there)

		// Give everything related to the player faction to the Ally A.I (Defense only)
		array<Building> _Godstones = {};
		for( uint i = 0; i < m_Reference.FindBuildingsByDescription(m_iPlayerFaction, "S_Godstone").length(); i++ )
			_Godstones.insertLast(m_Reference.FindBuildingsByDescription(m_iPlayerFaction, "S_Godstone")[i]);

		TransferRTS( m_iPlayerFaction, m_iLC3_Faction_PlayerAllied_AI );
		EnableWorldMap( false );
		
		m_Reference.SetTimer(TOnTimerEvent(@this.LC3_TimeSkip02_GodstoneActivate), 5);

		// repositioning of the hiding refugee + enabling refugee belongings
		m_Reference.GetCreatureByName("LC3_Refugee").Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Refugee_02"));
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.LC3_OnInteract_Refugee), "LC3_Refugee", m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.LC3_OnTriggerEnter_SO_RefugeeGone), m_stgAvatar, "LC3_Trigger_SO_RefugeeGone");
		m_Reference.GetWorld().EnableDialogueTopic("LC3_Refugee", "LC3_08_SO_Greeting", false);
		//Disable the refugees belongings for the first map part
		m_Reference.GetLogicObjectByName("LC3_Loot_RefugeeBelongings").Enable(true);

		//Activate spy contact
		m_Reference.ActivateSpawn("LC3_AngarSpyContact01", true);
		SpawnAttackable("LC3_AngarSpyContact01", false);

		//Disable the optional dialog
		m_Reference.GetWorld().EnableDialogueTopic(m_stgLC3_Crt_Angar, "LC3_15_AngarInFortress_Advise", false);

		// move heroparty to angar -> initiate dialog (LC3_17_MeetSpy)
	//	HeroPartyTeleport("LC3_Spot_Castle");
	//	m_Reference.GetCreatureByName("Angar_Arandir").Teleport(m_Reference, m_Reference.GetLogicObjectByName("LC3_Spot_Castle"));
		//DialogTalkTo(m_stgLC3_Crt_Angar, m_stgAvatar, m_stgLC3_Crt_Angar, "LC3_17_MeetSpy");

		//Register lose condition when castle is lost
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.LC3_OnSectorOwnerChanged_PlayerCastle), m_stgLC3_Sector_PurityCastle);

		m_bLC3_RTSOver = true;
	}

	bool LC3_TimeSkip02_GodstoneActivate()
	{
		array<Building> _Godstones = {};
		for( uint i = 0; i < m_Reference.FindBuildingsByDescription(1, "S_Godstone").length(); i++ )
			_Godstones.insertLast(m_Reference.FindBuildingsByDescription(1, "S_Godstone")[i]);

		for( uint i = 0; i < _Godstones.length(); i++ )
			_Godstones[i].SetFaction(m_iPlayerFaction);

		//m_Reference.GetBuildingByName("Godstone_Clone_1").SetFaction(m_iPlayerFaction);
		//m_Reference.GetBuildingByName("Godstone_F").SetFaction(m_iPlayerFaction);
		return true;
	}


	void CheckHeroPartyMembers()
	{
		for( uint i = 0; i < m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers().length(); i++)
		{

			if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Gor)
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Gor_Heroparty", true);
			
			else if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Isgrimm )
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Isgrimm_Heroparty", true);
			
			else if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Ianna )
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Ianna_Heroparty", true);
	
			else if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Rohen )
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Rohen_Heroparty", true);

			else if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Undergast )
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Undergast_Heroparty", true);
	
			else if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Uram)
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Uram_Heroparty", true);
			
			else if( m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers()[i].GetDescriptionName() == m_stgHero_Yria )
				m_Reference.GetWorld().SetGlobalBool("MapVariables.LC3_Yria_Heroparty", true);

		}
	}

	//Timer
	bool LC3_Cheat_PurityDefeated()
	{
		m_Reference.GetSectorByName(m_stgLC3_Sector_PurityCastle).GetMainBuilding().Destroy();
		return true;
	}

}
