// ------------------------------------------------------------------------------------------------------------------------------------
// version: 0.1

// Documentation can be found at:
// 		http://cp-srv-01/wiki
//		file://///CP-SRV-01/Projects/SF3/LevelDesign/ScriptDokumentation/html/index.html

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

// ------------------------------------------------------------------------------------------------------------------------------------
// classes:
/*


*/
class Level: LevelBase
{
	// count this version-number up. This is for later version tracking, when the QA plays the map.
	string m_stgVersion = "0.123 - 05.12.2017 - 06:02";
	//string m_stgVersion = "0.11";

	// -------------------------------------------------------------------------------------------------------------------
	// --- Member Variables ----------------------------------------------------------------------------------------------
	int m_iEY0_PartyLevel 	= 6;
	int m_iEY1_PartyLevel 	= 20;
	int m_iTE2_PartyLevel 	= 20;

	// rift quest from Desert Oasis (dragon)
	bool m_bHasRiftQuest =								false;

	bool m_bTE_Artifact_ZombieInside_01 =				false;
	bool m_bTE_Artifact_ZombieInside_02 =				false;
	bool m_bTE_Artifact_ZombieInside_03 =				false;

// -------------------------------------------------------------------------------------------------------------------
// ------------------------------------------V E R S I O N  0 1-------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------

	//**SPAWNS**

		//* Enemies *
	array<string> m_arrStgTE1_UndeadSpawns =  		{"TE1_Spawn_Undead02", "TE1_Spawn_Undead03", "TE1_Spawn_Undead04"};
	array<uint> m_arrUIntTE1_KilledFortressUnits = 	{};


	//**BUILDINGS & GODSTONES**
	array<string> m_arrActivatedGodstones;

	//**BOOLS**
	bool m_bTE1_FightingWithSentenza = 				false;
	bool m_bTE1_TalkedABoutHire	=					false;
	bool m_bTE1_KillingSentenza = 					false;

	//**GENERAL**
	uint m_iTE1_Faction_Harbinger =					1;
	uint m_iTE1_Faction_NortanderArmy =		 		2;
	uint m_iTE1_Faction_Mercenary =		 			3;
	uint m_iTE1_Faction_Sentenza =		 			4;
	uint m_iTE1_Faction_Undead =					5;
	uint m_iTE1_MercenaryPrice = 					5000;
	uint m_iTE1_CachedAvatarHP = 					0;
	uint m_iTE1_KilledFortressTroops = 				0;

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

	//	**SWITCHES**
	array<string> m_arrStg_PrisonCells = 				{"TE2_Switch_Cell01", "TE2_Switch_Cell02", "TE2_Switch_Cell03", "TE2_Switch_Cell04"};
	array<string> m_arrStg_PrisonCellsWithPrisoners = 	{"TE2_Switch_Cell01", "TE2_Switch_Cell03", "TE2_Switch_Cell04"};

	//	**SPAWNS**
		//	*Enemies*

	array <string> m_arrStg_Spawn_GuardPosts = 			{"TE2_SP_GuardsPost01","TE2_SP_GuardsPost02","TE2_SP_GuardsPost03","TE2_SP_GuardsPost04","TE2_SP_GuardsPost05"};

	//	**CREATURES**
	array<uint> m_arrUintTE2_UnarmedPrisonerIDs = 		{};

	//	**BOOLS**


	bool m_bTE2_EscapeesAtMage = 						false;
	array<bool> m_arrBTE2_PrisonersFreed = 				{false,false,false};
	bool m_bTE2_FightingWithAmaria = 					false;

	bool m_bTE2_PrisonerSeesAvatar = 					false;
	bool m_bTE2_EscapeeSeesAvatar = 					false;
	bool m_bTE2_DeserterSeesAvatar = 					false;
	bool m_bTE2_DeserterSaved = 						false;
	bool m_bTE2_DeserterDied = 							false;

	bool m_bTE2_AmariaSO_1 = 							false;
	bool m_bTE2_AmariaSO_2 = 							false;
	bool m_bTE2_AmariaSO_3 = 							false;

	bool m_bTE2_DefeatEnemyAI = 						false;

	bool m_bTE2_AvatarAtDeadBrother =					false;
	bool m_bTE2_EscapeeAtDeadBrother =					false;

	bool _closedFirst = 								false;
	bool _closedSecond = 								false;
	bool _closedThird = 								false;

	//	**INTEGER**
		//	*Timer*
	uint m_iFaction_HouseLeonidar = 					2;
	uint m_iFaction_HouseLeonidarAI = 					3;
	uint m_iFaction_EscapeeHostile = 					5;
	uint m_iFaction_Deserter = 							6;
	uint m_iFaction_Amaria = 							7;
	uint m_iFaction_NeutralVariant1 = 					1;

	//	**OTHER**

	array<string> m_arrStg_Sectors = 					{"Sector_01", "Sector_02", "Sector_03", "Sector_04", "Sector_05", "Sector_06", "Sector_07", "Sector_08", "Sector_09", "Sector_10", "Sector_11",
														 "Sector_12", "Sector_13", "Sector_14", "Sector_15"};

	array<string> m_arrStg_Sectors_Neutral = 			{"Sector_Neutral_01", "Sector_Neutral_02", "Sector_Neutral_03", "Sector_Neutral_05", "Sector_18_PrisonerCamp01"};


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

	array<uint> m_arrUIntTE3_KilledUndeadIDs = 			{};
	array<Creature>@ m_arrCrtTE3_Undead_01 = 			{};
	array<Creature>@ m_arrCrtTE3_Undead_02 = 			{};
	array<Creature>@ m_arrCrtTE3_Undead_03 = 			{};
	array<Creature>@ m_arrCrtTE3_Undead_04 = 			{};
	// initial sequence
	bool m_bCanGetThroughGuardBlock01 = 				false;

	// factions
	uint m_iFaction_HouseWulfgar = 						2;
	uint m_iFaction_HouseHallit = 						3;
	uint m_iFaction_PurityVariant2 = 					4;

	// undead castle quest
	uint m_iTE3_KilledUndead = 							0;
	uint m_iNumUndeadGroupsLeft =						6;

	// wulfgar variables
	bool m_bTalkedToSheyn =								false;
	bool m_bWulfgarHostile =							false;

	// wyvern quest
	bool m_bHasWeylandUndeadQuest = 					false;
	bool m_bHasNotMetUlric = 							true;
	bool m_bAcceptedUlricWyvernQuest = 					false;

	// sheyn, hallit
	bool m_bSecretMeetingWithSheyn =					false;
	bool m_bPoisenedWeyland =							false;


	// conclave
	bool m_bWeylandAtMeeting =							false;
	bool m_bSheynAtMeeting = 							false;
	bool m_bMyrahMarried =								false;
	bool m_bClearedCastle =								false;


	// village encounter
	bool m_bStartedVillageEncounter = 					false;


	// generic
	bool m_bEY3FirstGodstoneEnabled =					false;
	bool m_bRecapSO =									false;

	bool m_bTE3_BarrierSO =								false;
	bool m_bTE3_Wulfgar_Pass = 							false;




// --------------------------------------------------------------------------------------------------------------------
// --- 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
	{
		print("[SCRIPT] --- V E R S I O N : LevelBase: "+m_LevelBaseVersion+", Map Script: " + m_stgVersion+" (Level was just created)");
		print("[SCRIPT] --- M A P : Map: "+ m_Reference.GetMapId() +", setting: " + m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) +".");

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

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

		// setting specific calls
		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 0 ) // First setting
		{
			// Set Hero Party
			if (m_bDebuggingMode)
				SetHeroParty(m_iEY0_PartyLevel);

			InitEvents_0(); // (setting 0)
			InitCommon_0(); // (setting 0)
		}
		else if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 1 ) // Second setting
		{
			// Set Hero Party
			if (m_bDebuggingMode)
				SetHeroParty(m_iEY1_PartyLevel);

			InitEvents_1(); // (setting 1)
			InitCommon_1(); // (setting 1)
		}
		else if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 2 ) // Third setting
		{
			// Set Hero Party
			if (m_bDebuggingMode)
				SetHeroParty(m_iTE2_PartyLevel);

			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
	{
		print("[SCRIPT] --- V E R S I O N : LevelBase: "+m_LevelBaseVersion+", Map Script: " + m_stgVersion+" (Level was loaded)");
		LevelBase::OnLoaded(_uVersion);


		InitRifts();

		if ( m_Reference.GetWorld().GetCurrentMapSetting( m_Reference.GetMapId() ) == 2 )
		{
			// *The first group of Undead to kill*
			if( m_arrCrtTE3_Undead_01.length() == 0 )
			{
				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead06").length(); i++ )
					m_arrCrtTE3_Undead_01.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead06")[i]);

				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead05").length(); i++ )
					m_arrCrtTE3_Undead_01.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead05")[i]);

				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_UndeadMisc").length(); i++ )
					m_arrCrtTE3_Undead_01.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_UndeadMisc")[i]);
			}
			// *The second group of Undead to kill
			if( m_arrCrtTE3_Undead_02.length() == 0 )
			{
				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead04").length(); i++ )
					m_arrCrtTE3_Undead_02.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead04")[i]);
			}
			// *The third group of Undead to kill
			if( m_arrCrtTE3_Undead_03.length() == 0 )
			{
				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead03").length(); i++ )
					m_arrCrtTE3_Undead_03.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead03")[i]);

				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead01").length(); i++ )
					m_arrCrtTE3_Undead_03.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead01")[i]);
			}
			// *The fourth group of Undead to kill
			if( m_arrCrtTE3_Undead_04.length() == 0 )
			{
				for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead02").length(); i++ )
					m_arrCrtTE3_Undead_04.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead02")[i]);
			}
		}
	}

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

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

	void InitEvents ()
	{
		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.TE_Artifact_OnSpawnedCreatures_SummonedZombies), "TE2_TE3_Artifact_Soulreaver_Spawner_1");
		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.TE_Artifact_OnSpawnedCreatures_SummonedZombies), "TE2_TE3_Artifact_Soulreaver_Spawner_2");
		m_Reference.RegisterBuildingCreatureEventByIndividual(CreaturesSpawned, TOnBuildingCreatureEvent(@this.TE_Artifact_OnSpawnedCreatures_SummonedZombies), "TE2_TE3_Artifact_Soulreaver_Spawner_3");
	}

	

// for the first map setting
	void InitEvents_0 ()
	{
		print("[SCRIPT] INITIALIZE MAP VERSION 1");
		//**HEROPARTY**

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.OnTrigger_SOCastleEntrance), "TE1_Trigger_CastleEntrance", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_Blocked01), "TE1_Trigger_SO_Blocked_01", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_Blocked02), "TE1_Trigger_SO_Blocked_02", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_BlockedBridge01), "TE1_Trigger_SO_Blocked_Bridge01", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_BlockedBridge01), "TE1_Trigger_SO_Blocked_Bridge02", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_Wasteland), "TE1_Trigger_SO_Wasteland", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_FishingHut), "TE1_Trigger_SO_FishingHut", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_NearGodstone), "TE1_Trigger_SO_NearGodstone", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_WalkToSentenza), "TE1_Trigger_SO_WalkToSentenza", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE1_OnTrigger_SO_SeesSentenza), "TE1_Trigger_SO_SeesSentenza", m_iPlayerFaction);


		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE1_OnSwitch_InspectionClosedGate), "TE1_Switch_ClosedGate", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE1_OnSwitch_InspectionFrontGate), "TE1_Switch_FrontGate", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.OnGodstoneCastleActivated), "Entity_Godstone_Castle", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE1_OnInteract_MercenaryLeader), "TE1_MercenaryLeader", m_iPlayerFaction);

		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE1_OnEnterSector_StartFightUndeadNortander_02), "Sector_09", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE1_OnEnterSector_StartFightUndeadNortander_03), "Sector_12", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE1_OnEnterSector_StartFightUndeadNortander_04), "Sector_11", m_iPlayerFaction);


		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE1_OnTrigger_Play_SentenzaCombatMusic01), m_stgAvatar, "TE1_Trigger_SentenzaTheme");
		m_Reference.RegisterCreatureEventByIndividual(LeftArea, TOnCreatureEvent(@this.TE1_OnTrigger_Cancel_SentenzaCombatMusic01), m_stgAvatar, "TE1_Trigger_SentenzaTheme");


		RegisterEventHeroPartyMember(); // Register Companion died event

		//**CREATURES**
		m_Reference.RegisterCreatureEventByIndividual(Damaged, TOnCreatureEvent(@this.TE1_OnDamage_Sentenza), "Sentenza_Noria", "");
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE1_OnKilled_CastleTroops), m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Castle_01"), true, "");
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE1_OnKilled_CastleTroops), m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Castle_02"), true, "");
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE1_OnKilled_CastleTroops), m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Castle_03"), true, "");

		//**BUILDINGS**
		m_Reference.RegisterBuildingEventByIndividual(GodstonePortalChanged, TOnBuildingEvent(@this.OnGodstoneCastlePortalOpen), "Entity_Godstone_Castle");

	}



// for the second map setting
	void InitEvents_1 ()
	{
	//**HEROPARTY EVENTS**
		//Trigger
		m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_BaseFound), "Sector_03", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Prisoner1), "TE2_Trigger_SOPrisoner_1", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Prisoner2), "TE2_Trigger_SOPrisoner_2", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Prisoner3), "TE2_Trigger_SOPrisoner_3", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_DeserterDiscussion), "TE2_Trigger_DeserterDiscussion", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_WeaponRack), "TE2_Trigger_SO_WeaponRack", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Barrier), "TE2_Trigger_CastleEntrance", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_AmariaFight), "TE2_Trigger_AmariaFight", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_AtMage), "TE2_Trigger_TeleportAreaAtMage", m_iPlayerFaction);

		m_Reference.RegisterSectorEvent (OwnerChanged, TOnSectorEvent(@this.TE2_OnSectorOwnerChange_PlayerCapital), "Sector_03");
		m_Reference.RegisterBuildingEventByIndividual(Destroyed, TOnBuildingEvent(@this.TE2_OnDestroyed_LeonidarMainSector), m_Reference.GetSectorByName("Sector_12").GetMainBuilding());

		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_SO_DeadBrother), m_stgAvatar, "TE2_Trigger_SO_DeadBrother");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_SO_DeadBrother), "TE2_Escapee_02", "TE2_Trigger_SO_DeadBrother");

		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnLeaveTrigger_SO_DeadBrother), m_stgAvatar, "TE2_Trigger_SO_DeadBrother");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnLeaveTrigger_SO_DeadBrother), "TE2_Escapee_02", "TE2_Trigger_SO_DeadBrother");

		m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_EscapeesAtMage), m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02"), true,  "TE2_Trigger_TeleportAreaAtMage");
		m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.TE2_OnTrigger_EscapeesLeaveMage), m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02"), false,  "TE2_Trigger_TeleportAreaAtMage");

		m_Reference.RegisterCreatureEventByIndividual(Damaged, TOnCreatureEvent(@this.TE2_OnDamage_Amaria), "Amaria_Leonidar", "");

		//Sector
		m_Reference.RegisterHeroPartyEvent(AllInsideSector, TOnHeroPartyEvent(@this.TE2_OnEnteredSector_HeropartyAtCastle), m_arrStg_Sectors_Neutral[2],m_iPlayerFaction);

		//Interact
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE2_OnInteract_WeaponRack), "TE2_Switch_WeaponRack", m_iPlayerFaction );

		m_Reference.RegisterHeroPartyEvent (Interact, TOnHeroPartyEvent(@this.TE2_OnInteract_FreePrisoner_01), m_arrStg_PrisonCellsWithPrisoners[0], m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent (Interact, TOnHeroPartyEvent(@this.TE2_OnInteract_FreePrisoner_02),	m_arrStg_PrisonCellsWithPrisoners[1], m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent (Interact, TOnHeroPartyEvent(@this.TE2_OnInteract_FreePrisoner_03), m_arrStg_PrisonCellsWithPrisoners[2], m_iPlayerFaction);

		m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.TE2_OnLoot_CellKey), "TE2_PrisonerCellKey_01", m_iPlayerFaction);

	}

// for the third map setting
	void InitEvents_2 ()
	{
		//TEMPInitEventsForThirdVersion();
		array <Entity> _GateSwitch = m_Reference.GetEntitiesInGroup( "EY3_Grp_Switch_Gates" );
		for ( uint i = 0; i < _GateSwitch.length(); i++ )
			m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE3_OnInteract_SO_Barrier), m_Reference.FindEntityName( _GateSwitch[i] ), m_iPlayerFaction);

		// first banter before reaching myrah
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_12_BN_Banter), "EY3_Trg_12_BN_Banter", m_iPlayerFaction);

		// small SO before reaching myrah's camp
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SO_MyrahCamp), "EY3_Trg_SO_MyrahCamp", m_iPlayerFaction);

		// guard after the myrah camp
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_GuardBlock01), "EY3_Trg_GuardBlock01", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_GuardBlock02), "EY3_Trg_GuardBlock02", m_iPlayerFaction);

		// recap after leaving camp
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_TE3_04A_SO_Recap), "EY3_Trg_TE3_04A_SO_Recap", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_TE3_04A_SO_Recap), "EY3_Trg_TE3_04A_SO_Recap02", m_iPlayerFaction);

		// hallit_soldier_01 help trigger
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_Hallit_Soldier_01), "EY3_Trg_Hallit_Soldier_01", m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Spawn_UndeadMisc), m_Reference.GetCreaturesFromSpawn("EY3_Spawn_UndeadMisc"), true, "");

		// small SO after clearing the castle  TE3_13_SO_Eerie
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SO_Eerie), "EY3_Trg_SO_Eerie", m_iPlayerFaction);

		// keeping track of the undead mobs in castle
		m_iNumUndeadGroupsLeft = 0;
		m_iNumUndeadGroupsLeft += m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead06").length();
		m_iNumUndeadGroupsLeft += m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead05").length();
		m_iNumUndeadGroupsLeft += m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead04").length();
		m_iNumUndeadGroupsLeft += m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead03").length();
		m_iNumUndeadGroupsLeft += m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead02").length();
		m_iNumUndeadGroupsLeft += m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead01").length();

		// first wulfgar talk finished; spawn ulric
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SouthernUlricSpawn), "EY3_Trg_SouthernUlricSpawn", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_NorthernUlricSpawn), "EY3_Trg_NorthernUlricSpawn", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_WesternUlricSpawn), "EY3_Trg_WesternUlricSpawn", m_iPlayerFaction);

		// wyvern quest
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Spawn_Wyvern), m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Wyvern"), true, "");
		m_Reference.RegisterInventoryEvent(Added, TOnInventoryEvent(@this.TE3_OnLoot_WyvernTeeth), "TE3_WyvernTeeth", m_iPlayerFaction);

		// wulfgar guard encounter
		m_Reference.RegisterHeroPartyEvent(AllInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_EY3_Trg_Wulfgar_Guard01), "EY3_Trg_Wulfgar_Guard_01", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AllInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_EY3_Trg_Wulfgar_Guard02), "EY3_Trg_Wulfgar_Guard_02", m_iPlayerFaction);
		m_Reference.RegisterHeroPartyEvent(AllInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_EY3_Trg_Wulfgar_Guard03), "EY3_Trg_Wulfgar_Guard_03", m_iPlayerFaction);

		// sheyn SO
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SO_ThatsShyen), "EY3_Trg_SO_ThatsSheyn", m_iPlayerFaction);

		// sheyn secret meeting
	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SheynSecretMeeting), "EY3_Trg_SheynSecretMeeting_01", m_iPlayerFaction);
	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SheynSecretMeeting), "EY3_Trg_SheynSecretMeeting_02", m_iPlayerFaction);
	//	m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_SheynSecretMeeting), "EY3_Trg_SheynSecretMeeting_03", m_iPlayerFaction);

		// hallit guard encounter
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_Weyland_Hallit), "EY3_Trg_Weyland_Hallit", m_iPlayerFaction);

		// hallit poison
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.EY3_OnInteract_Switch_PoisonWeyland), "EY3_Switch_PoisonWeyland", m_iPlayerFaction);

		// village encounter
		m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.EY3_OnAnyInside_Trg_VillageEncounter), "EY3_Trg_VillageEncounter", m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Spawn_VillageAbomination), m_Reference.GetCreaturesFromSpawn("EY3_Spawn_VillageAbomination"), true, "");

		// conclave trigger
		m_Reference.RegisterHeroPartyEvent(AllInsideSector, TOnHeroPartyEvent(@this.EY3_OnAllInside_Sector_StartConclave), "Sector_Neutral_03", m_iPlayerFaction);


	}
//
	void InitCommon ()
	{

		// INSPECTIONS
		m_Reference.GetLogicObjectByName("TE_Inspect_FishersTent").SetInspectionText(18000);
		m_Reference.GetLogicObjectByName("TE_Inspect_Barrels").SetInspectionText(18001);
		m_Reference.GetLogicObjectByName("TE_Inspect_BloodburnVictims").SetInspectionText(18002);
		m_Reference.GetLogicObjectByName("Te_Inspect_DeadWolfGuardSoldier").SetInspectionText(18003);
		m_Reference.GetLogicObjectByName("TE_Inspect_JailPit").SetInspectionText(18004);
		m_Reference.GetLogicObjectByName("TE_Inspect_StoneSwordAltar").SetInspectionText(18005); // Artifact
		m_Reference.GetLogicObjectByName("TE_Inspect_TreeWithMessage").SetInspectionText(18006);
		m_Reference.GetLogicObjectByName("TE1_Inspect_TorturedPrisoner").SetInspectionText(18007);
		m_Reference.GetLogicObjectByName("TE1_Switch_ClosedGate").SetInspectionText(18008);


		// ARTIFACTS
		m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_1").SetSelectable(false);
		m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_2").SetSelectable(false);
		m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_3").SetSelectable(false);

		m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_LootChest").Enable(false);
		m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ChestAppearanceFX").Enable(false);
		m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_1").Enable(false);
		m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_2").Enable(false);
		m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_3").Enable(false);
		m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn1_SpawnEffect").Enable(false);
		m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn2_SpawnEffect").Enable(false);
		m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn3_SpawnEffect").Enable(false);

		if( m_Reference.GetWorld().GetGlobalBool("MapVariables.Artifact_TE_Zombie1_Killed") == true )
		{
			m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_1").Enable(false);
		}

		if( m_Reference.GetWorld().GetGlobalBool("MapVariables.Artifact_TE_Zombie2_Killed") == true )
		{
			m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_2").Enable(false);
		}

		if( m_Reference.GetWorld().GetGlobalBool("MapVariables.Artifact_TE_Zombie3_Killed") == true )
		{
			m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_3").Enable(false);
		}

		if( m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") >= 3 )
		{
			m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_DeathCircleFX").Enable(false);
			m_Reference.GetLogicObjectByName("TE_Inspect_StoneSwordAltar").SetInspectionText(uint(-1));

			for( uint i = 0; i < uint (m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled")); i++ )
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_" + i).Enable(true);
		}

	}

// for the first map version
	void InitCommon_0 ()
	{
		if( m_bDebuggingMode)
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P3_Q21_TheEye", true);
		}

		PlayTrack_Silence();

		m_iTE1_MercenaryPrice = m_Reference.GetWorld().GetGlobalInt("QuestVariables.TE1_MercenaryPrice", - 1);
		m_Reference.BlockNavMesh("TE1_PhysicBlocker_ClosedGate", true);
		m_Reference.BlockNavMesh("TE1_PhysicBlocker_FrontGate", true);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_EnterTheEye", Completed);

		m_Reference.GetCreatureByName("Bertrand_Carpel").AllowAttacks(false);
		m_Reference.GetCreatureByName("Bertrand_Carpel").SetAttackable(false);
		m_Reference.GetCreatureByName("Bertrand_Carpel").SetImmovable(true);
		m_Reference.GetCreatureByName("Bertrand_Carpel").SetPreserveBody(true);

		m_Reference.GetBuildingByName("Entity_Godstone_Start").SetFaction(m_iPlayerFaction);

	//	m_Reference.GetCreatureByName("Sentenza_Noria").AllowAttacks(false);
	//	m_Reference.GetCreatureByName("Sentenza_Noria").SetAttackable(false);
		m_Reference.GetCreatureByName("Sentenza_Noria").SetImmortal(true);
		m_Reference.GetCreatureByName("Sentenza_Noria").SetImmovable(true);

		for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy").length(); i++)
			m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy")[i].SetImmovable(true);

		for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02").length(); i++)
			m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02")[i].SetImmovable(true);

	//	for(uint i = 0; i < m_arrStg_PrisonCellsWithPrisoners.length(); i++)
	//		m_Reference.GetCreatureByName(m_arrStg_PrisonCellsWithPrisoners[i]).SetInteractive(false);

		SpawnAttackable("TE1_Spawn_SentenzaArmy", false);

		int _iFortressTroopsAmount = m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Castle_01").length() + m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Castle_02").length() + m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Castle_03").length();

		m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE1_FortressTroops_Amount", _iFortressTroopsAmount);

		// Set the initial state of the fortress gate which gets blown up by Rondar Lacaine with a fireball
		m_Reference.GetLogicObjectByName( "TE1_FortressGate_Explosion" ).Enable( false );
		m_Reference.EnableGroup( "TE1_FortressGate_AfterExplosion", false );
		m_Reference.EnableGroup( "TE1_FortressGate_Smoke", false );
		m_Reference.EnableGroup( "TE1_FortressGate_Fire", false );

		//Call intro cutscene here
		TE1_CutScene_MapIntro_1( );
	}
// for the second map version
	void InitCommon_1 ()
	{
		InitRifts();
		m_Reference.BlockNavMesh("TE2_PhysicBlocker_IslandGate", true);
		
		HeroPartyTeleport("PlayerSpawn_1_Pos");
		m_Reference.FocusCamera(m_iPlayerFaction, m_Reference.GetLogicObjectByName("PlayerSpawn_1_Pos"));

		DisableAllGodstonesForFaction( m_iPlayerFaction );	

		m_Reference.GetCreatureByName("TE2_OldMageRebel").SetImmovable(true);

		for( uint i = 0; i < m_arrStg_PrisonCells.length(); i++ )
			m_Reference.GetLogicObjectByName(m_arrStg_PrisonCells[i]).Lock(m_Reference, "TE2_PrisonerCellKey_01");

		m_Reference.GetCreatureByName("TE2_Prisoner").ChangeEquipmentSet(0);
		m_Reference.GetCreatureByName("TE2_Prisoner_02").ChangeEquipmentSet(0);
		m_Reference.GetCreatureByName("TE2_Prisoner_03").ChangeEquipmentSet(0);
		m_Reference.GetCreatureByName("TE2_Prisoner").SetPreserveBody(true);
		m_Reference.GetCreatureByName("TE2_Prisoner_02").SetPreserveBody(true);
		m_Reference.GetCreatureByName("TE2_Prisoner_03").SetPreserveBody(true);

		m_Reference.GetCreatureByName("TE2_Leonidar_Commander").Enable(false);
		m_Reference.GetCreatureByName("TE2_Deserter").SetPreserveBody(true);
		m_Reference.GetCreatureByName("TE2_Escapee_01").SetPreserveBody(true);
		m_Reference.GetCreatureByName("TE2_Escapee_02").SetPreserveBody(true);

		if( m_bDebuggingMode )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_Q21_HouseLeonidar", true);
		}
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_GoToTheEye", Completed);

		if( m_Reference.GetFactionRace(m_iPlayerFaction) == Human )
			m_Reference.ActivateSpawn("TE2_SP_InitUnits01_H", true);

		else if( m_Reference.GetFactionRace(m_iPlayerFaction) == Elf )
			m_Reference.ActivateSpawn("TE2_SP_InitUnits01_E", true);

		else if( m_Reference.GetFactionRace(m_iPlayerFaction) == Orc )
			m_Reference.ActivateSpawn("TE2_SP_InitUnits01_O", true);

		m_Reference.GetLogicObjectByName("TE2_PortalEffect").Enable(false);
		m_Reference.GetLogicObjectByName("TE2_Switch_Portal").Enable(false);


		if(m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_MAP014_ElderRifts"))
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_MAP014_ElderRifts", "P3_MAP014_ElderRifts_MoveToTheEye", Completed);
		}

		// ensure rifts are spawned(or not)
		
	}

// for the third map version
	void InitCommon_2 ()
	{
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("PotionOfReskill", 4);
		//TEMPInitCommonForThirdVersion();
		InitRifts();

		HeroPartyTeleport("PlayerSpawn_2_Pos");
		DisableAllGodstonesForFaction( m_iPlayerFaction );

		m_Reference.GetBuildingByName("TE3_WulfgarSpawner").Enable(false);
		m_Reference.GetBuildingByName("TE3_HallitSpawner").Enable(false);

		// *The first group of Undead to kill*
		if( m_arrCrtTE3_Undead_01.length() == 0 )
		{
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead06").length(); i++ )
				m_arrCrtTE3_Undead_01.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead06")[i]);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead05").length(); i++ )
				m_arrCrtTE3_Undead_01.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead05")[i]);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_UndeadMisc").length(); i++ )
				m_arrCrtTE3_Undead_01.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_UndeadMisc")[i]);
		}
		// *The second group of Undead to kill
		if( m_arrCrtTE3_Undead_02.length() == 0 )
		{
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead04").length(); i++ )
				m_arrCrtTE3_Undead_02.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead04")[i]);
		}
		// *The third group of Undead to kill
		if( m_arrCrtTE3_Undead_03.length() == 0 )
		{
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead03").length(); i++ )
				m_arrCrtTE3_Undead_03.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead03")[i]);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead01").length(); i++ )
				m_arrCrtTE3_Undead_03.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead01")[i]);
		}
		// *The fourth group of Undead to kill
		if( m_arrCrtTE3_Undead_04.length() == 0 )
		{
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead02").length(); i++ )
				m_arrCrtTE3_Undead_04.insertLast(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Undead02")[i]);
		}

		// INIT EVENTS FOR ZOMBIE GROUPS HERE - INIT EVENTS DOESNT KNOW THEM
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Undead01), m_arrCrtTE3_Undead_01, true, "");
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Undead02), m_arrCrtTE3_Undead_02, true, "");
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Undead03), m_arrCrtTE3_Undead_03, true, "");
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.EY3_OnKilled_Undead04), m_arrCrtTE3_Undead_04, true, "");

		uint _iUndeadToKill = m_arrCrtTE3_Undead_01.length() + m_arrCrtTE3_Undead_02.length() + m_arrCrtTE3_Undead_03.length() + m_arrCrtTE3_Undead_04.length();
		m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE3_UndeadToKill", _iUndeadToKill);

		// Initialize utran dialogue
		m_Reference.GetWorld().EnableDialogueTopic("Myrah_Utran", "T3_02B_FirstContact", true);

		// if Angar Arandir is part of the hero party, we don't need him to spawn on the map
		if( m_Reference.GetCreatureByName("Angar_Arandir").Exists() && !m_Reference.GetHeroParty(0).IsMember(m_Reference.GetCreatureByName("Angar_Arandir")))
		{
			m_Reference.ActivateSpawn("EY3_Spawn_Angar", true);
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgAvatar, "D02077D2");
		}

		// activate wulfgar RTS camp
		//m_Reference.ActivateAI(m_iFaction_HouseWulfgar);
		//m_Reference.GetSectorByName("Sector_14").SetOwner(m_iFaction_HouseWulfgar);

		// initialize Wulfgar dialogue
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "T3_07B_FirstContact", true);
		m_Reference.GetWorld().EnableDialogueTopic("Ulric_Wulfgar", "T3_10B_FirstContact", true);

		// ensure rifts are spawned(or not)
		if(m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_MAP014_ElderRifts"))
		{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_MAP014_ElderRifts", "P3_MAP014_ElderRifts_MoveToTheEye", Completed);
		}


		m_Reference.GetCreatureByName("TE3_Myrah_Guard_01").SetImmovable(true);
		m_Reference.GetCreatureByName("TE3_Myrah_Guard_02").SetImmovable(true);
		m_Reference.GetCreatureByName("TE3_Wulfgar_Guard_01").SetImmovable(true);
		m_Reference.GetCreatureByName("TE3_Wulfgar_Guard_02").SetImmovable(true);
		m_Reference.GetCreatureByName("TE3_Wulfgar_Guard_03").SetImmovable(true);
		m_Reference.GetCreatureByName("TE3_Hallit_Guard").SetImmovable(true);
		m_Reference.GetCreatureByName("Sheyn_Wulfgar").SetImmovable(true);
		m_Reference.GetCreatureByName("Ulric_Wulfgar").SetImmovable(true);
		m_Reference.GetCreatureByName("Weyland_Hallit").SetImmovable(true);
		m_Reference.GetCreatureByName("Myrah_Utran").SetImmovable(true);

		m_Reference.BlockNavMesh("EY3_PhysicBlocker_Wulfgar_Guard_01", true);
		m_Reference.BlockNavMesh("EY3_PhysicBlocker_Wulfgar_Guard_02", true);
		m_Reference.BlockNavMesh("EY3_PhysicBlocker_Wulfgar_Guard_03", true);

		// ensure gates are closed for RPG mode
		TE3_CloseGates();

		// disable conclave setup
		m_Reference.EnableGroup("TE3_ConclaveSetup", false);

		m_Reference.GetWorld().AddItemToCreatureDrops( m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Wyvern")[0].GetDescriptionName() , "TE3_WyvernTeeth", 1, 100);

		// ensure player can not poison weyland too early
		m_Reference.GetLogicObjectByName("EY3_Switch_PoisonWeyland").SetInteractive(false);

		// disable ulric wulfgar at the beginning
		m_Reference.GetCreatureByName("Ulric_Wulfgar").Enable(false);

		// guard blockers
		m_Reference.EnableGroup("PhysicBlockerGuards", true);
		array <Entity> _entTmp = m_Reference.GetEntitiesInGroup( "PhysicBlockerGuards");
		for ( uint _iTmp = 0; _iTmp < _entTmp.length(); _iTmp++ )
		{
			m_Reference.BlockNavMesh( m_Reference.FindEntityName( _entTmp[_iTmp] ), true );
		}

		m_Reference.PlayCutScene("TE3_01_MapIntro");

		if( m_bDebuggingMode )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_Q21_TheConclave", true);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_TalkWithAngar", Completed);

		}
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_EnterTheEye", Completed);
	}


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

	bool TE_Artifact_OnSpawnedCreatures_SummonedZombies( Building& in _Building, Creature[]& in _Creatures )
	{
		_Building.Enable(false);
		if( _Building == m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_1") )
		{
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE_Artifact_OnKilled_Zombie_01), _Creatures, false, "");
			m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE_Artifact_OnTriggerEnter_Zombie_01), _Creatures, false, "EL2_EL3_Artifact_Soulreaver_DeathCircle");
			m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.TE_Artifact_OnTriggerLeave_Zombie_01), _Creatures, false, "EL2_EL3_Artifact_Soulreaver_DeathCircle");
			m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn1_SpawnEffect").Enable(true);
			m_Reference.SetTimer(TOnTimerEvent(@this.TE_Artifact_OnTimer_DisableSpawnEffect_01), 1);
		}
		else if( _Building == m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_2") )
		{
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE_Artifact_OnKilled_Zombie_02), _Creatures, false, "");
			m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE_Artifact_OnTriggerEnter_Zombie_02), _Creatures, false, "EL2_EL3_Artifact_Soulreaver_DeathCircle");
			m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.TE_Artifact_OnTriggerLeave_Zombie_02), _Creatures, false, "EL2_EL3_Artifact_Soulreaver_DeathCircle");
			m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn2_SpawnEffect").Enable(true);
			m_Reference.SetTimer(TOnTimerEvent(@this.TE_Artifact_OnTimer_DisableSpawnEffect_02), 1);
		}
		else if( _Building == m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_3") )
		{
			m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE_Artifact_OnKilled_Zombie_03), _Creatures, false, "");
			m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE_Artifact_OnTriggerEnter_Zombie_03), _Creatures, false, "EL2_EL3_Artifact_Soulreaver_DeathCircle");
			m_Reference.RegisterCreatureEventByIndividuals(LeftArea, TOnCreatureEvent(@this.TE_Artifact_OnTriggerLeave_Zombie_03), _Creatures, false, "EL2_EL3_Artifact_Soulreaver_DeathCircle");
			m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn3_SpawnEffect").Enable(true);
			m_Reference.SetTimer(TOnTimerEvent(@this.TE_Artifact_OnTimer_DisableSpawnEffect_03), 1);
		}
		return false;
	}

	bool TE_Artifact_OnTimer_DisableZombieChestEffect()
	{
		m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ChestAppearanceFX").Enable(false);
		return true;
	}

	bool TE_Artifact_OnTimer_DisableSpawnEffect_01()
	{
		m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn1_SpawnEffect").Enable(false);
		return true;
	}
	bool TE_Artifact_OnTimer_DisableSpawnEffect_02()
	{
		m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn2_SpawnEffect").Enable(false);
		return true;
	}
	bool TE_Artifact_OnTimer_DisableSpawnEffect_03()
	{
		m_Reference.GetLogicObjectByName("TE2_TE3_Artifact_Soulreaver_Spawn3_SpawnEffect").Enable(false);
		return true;
	}

	bool TE_Artifact_OnTriggerEnter_Zombie_01( Creature& in _Creature )
	{
		m_bTE_Artifact_ZombieInside_01 = true;
		return false;
	}

	bool TE_Artifact_OnTriggerEnter_Zombie_02( Creature& in _Creature )
	{
		m_bTE_Artifact_ZombieInside_02 = true;
		return false;
	}

	bool TE_Artifact_OnTriggerEnter_Zombie_03( Creature& in _Creature )
	{
		m_bTE_Artifact_ZombieInside_03 = true;
		return false;
	}

	bool TE_Artifact_OnTriggerLeave_Zombie_01( Creature& in _Creature )
	{
		m_bTE_Artifact_ZombieInside_01 = false;
		return false;
	}

	bool TE_Artifact_OnTriggerLeave_Zombie_02( Creature& in _Creature )
	{
		m_bTE_Artifact_ZombieInside_02 = false;
		return false;
	}

	bool TE_Artifact_OnTriggerLeave_Zombie_03( Creature& in _Creature )
	{
		m_bTE_Artifact_ZombieInside_03 = false;
		return false;
	}

	bool TE_Artifact_OnKilled_Zombie_01( Creature& in _Creature )
	{
		if( m_bTE_Artifact_ZombieInside_01 )
		{
			m_Reference.GetWorld().SetGlobalBool("MapVariables.Artifact_TE_Zombie1_Killed", true);
			m_Reference.GetWorld().SetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled", m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") +1);
			m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_" + m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") ).Enable(true);

			if( m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") >= 3 )
			{
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_LootChest").Enable(true);
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ChestAppearanceFX").Enable(true);
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_DeathCircleFX").Enable(false);
				m_Reference.GetLogicObjectByName("TE_Inspect_StoneSwordAltar").SetInspectionText(uint(-1));
				m_Reference.SetTimer(TOnTimerEvent(@this.TE_Artifact_OnTimer_DisableZombieChestEffect), 1);

			} 
		}
		else
		{
			m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_1").Enable(true);
		}
		return true;
	}



	bool TE_Artifact_OnKilled_Zombie_02( Creature& in _Creature )
	{
		if( m_bTE_Artifact_ZombieInside_02 )
		{
			m_Reference.GetWorld().SetGlobalBool("MapVariables.Artifact_TE_Zombie2_Killed", true);
			m_Reference.GetWorld().SetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled", m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") +1);
			m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_" + m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") ).Enable(true);
			
			if( m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") >= 3 )
			{
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_LootChest").Enable(true);
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ChestAppearanceFX").Enable(true);
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_DeathCircleFX").Enable(false);
				m_Reference.GetLogicObjectByName("TE_Inspect_StoneSwordAltar").SetInspectionText(uint(-1));
				m_Reference.SetTimer(TOnTimerEvent(@this.TE_Artifact_OnTimer_DisableZombieChestEffect), 1);
			} 

		}
		else
		{
			m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_2").Enable(true);
		}
		return true;
	}

	bool TE_Artifact_OnKilled_Zombie_03( Creature& in _Creature )
	{
		if( m_bTE_Artifact_ZombieInside_03 )
		{
			m_Reference.GetWorld().SetGlobalBool("MapVariables.Artifact_TE_Zombie3_Killed", true);
			m_Reference.GetWorld().SetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled", m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") +1);
			m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ShrineFlame_" + m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") ).Enable(true);
		
			if( m_Reference.GetWorld().GetGlobalInt("MapVariables.Artifact_TE_ZombiesKilled") >= 3 )
			{
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_LootChest").Enable(true);
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_ChestAppearanceFX").Enable(true);
				m_Reference.GetLogicObjectByName("EL2_EL3_Artifact_Soulreaver_DeathCircleFX").Enable(false);
				m_Reference.GetLogicObjectByName("TE_Inspect_StoneSwordAltar").SetInspectionText(uint(-1));
				m_Reference.SetTimer(TOnTimerEvent(@this.TE_Artifact_OnTimer_DisableZombieChestEffect), 1);
			} 

		}
		else
		{
			m_Reference.GetBuildingByName("TE2_TE3_Artifact_Soulreaver_Spawner_3").Enable(true);
		}
		return true;
	}

// -------------------------------------------------------------------------------------------------------------------
// ------------------------------------------V E R S I O N 0 1--------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------

	// --- E V E N T  F U N C T I O N S ----------------------------------------------------------------------------------
		// --- Trigger & Switch Events -----------------------------------------------------------------------------------

	 // Shoutout at the castle entrance
		bool OnTrigger_SOCastleEntrance( Creature& in _Creature )
		{
			print("[SCRIPT] NOTE: You just arrived at the castle!");
			m_Reference.GetWorld().EnableDialogueTopic(m_stgAvatar, "TE1_SO_Entrance", true);
			DialogShoutout( m_stgAvatar, m_stgAvatar, "TE1_SO_Entrance", false);
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P3_Q21_TheEye", "P3_Q21_ClearFortress", true );
			return true;
		}
	// Shoutout when near the castle godstone
		bool TE1_OnTrigger_SO_NearGodstone(Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_GetNearGodStone", false);
				return true;
			}
			return false;
		}
	// Shoutout about the swamp
		bool TE1_OnTrigger_SO_Wasteland(Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_Wasteland", false);
				return true;
			}
			return false;
		}
	// Shoutout about a fishing hut
		bool TE1_OnTrigger_SO_FishingHut(Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_FishingHut", false);
				return true;
			}
			return false;
		}
	// Shoutout about a broken brdige
		bool TE1_OnTrigger_SO_BlockedBridge01(Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_RoadBlocked_Bridge", false);
				return true;
			}
			return false;
		}
	// Shoutout about a blocked way
		bool TE1_OnTrigger_SO_Blocked01 (Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_RoadBlocked", false);
				return true;
			}
			return false;
		}
	// Shoutout about a blocked way
		bool TE1_OnTrigger_SO_Blocked02 (Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_RoadBlocked_Alt", false);
				return true;
			}
			return false;
		}
	// Shoutout when entering sentenas part of the castle
		bool TE1_OnTrigger_SO_WalkToSentenza (Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_WalkToSentenza", false);
				return true;
			}
			return false;
		}
	// Shoutout when seeing sentenza
		bool TE1_OnTrigger_SO_SeesSentenza (Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE1_SO_Sentenza", false);
				return true;
			}
			return false;
		}
	// Play sentenza them inside his area of the castle
		bool TE1_OnTrigger_Play_SentenzaCombatMusic01(Creature& in _Creature)
		{
			m_Reference.SetGlobalSoundTrack(m_iPlayerFaction, uint8(-1), TrackMusic, "music/characters/sentenza_combat");

			m_Reference.SuspendAutomaticCombatMusic(m_iPlayerFaction, uint8(-1), true);
			return false;
		}
	// Cancle sentenza them when leaving his area of the castle
		bool TE1_OnTrigger_Cancel_SentenzaCombatMusic01(Creature& in _Creature)
		{
			m_Reference.SetGlobalSoundTrack( m_iPlayerFaction, uint8(-1), TrackMusic, "music/setting/swamp" );
			m_Reference.SuspendAutomaticCombatMusic(m_iPlayerFaction, uint8(-1), false);
			return false;
		}
	// Fleeing Sentenza units despawn at map border
		bool TE1_OnTrigger_DespawnSentenzaUnits(Creature& in _Creature)
		{
			printNote("Despawning a unit");
			_Creature.Enable(false);
			return false;
		}
	// Shoutout when inspecting the closed side gate
		bool TE1_OnSwitch_InspectionClosedGate( Creature& in _Creature )
		{
			print("[SCRIPT] NOTE: You inspect the closed gate!");
			DialogShoutout( m_stgAvatar, m_stgAvatar, "TE1_SO_SideGate", true);
			return false;
		}
	// Shoutout when inspecting the closed front gate
		bool TE1_OnSwitch_InspectionFrontGate( Creature& in _Creature )
		{
			print("[SCRIPT] NOTE: You inspect the front gate!");
			DialogShoutout( m_stgAvatar, m_stgAvatar, "TE1_SO_FrontGate", true);
			return false;
		}

		bool TE1_OnInteract_MercenaryLeader( Creature& in _Creature )
		{
			if( m_Reference.GetHeroParty(m_iPlayerFaction).GetGold() >= 5000 )
			{
				m_Reference.GetWorld().BlockDialogueTopicNode("TE1_MercenaryLeader", "E15EF2C0"); //  block not enough gold
				m_Reference.GetWorld().UnblockDialogueTopicNode("TE1_MercenaryLeader", "C7A56BC0"); // unblock enough gold
				if(m_bTE1_TalkedABoutHire)
					m_Reference.GetWorld().UnblockDialogueTopicNode("TE1_MercenaryLeader", "6547EB9C"); // unblock enough gold
			}
			else
			{
				m_Reference.GetWorld().UnblockDialogueTopicNode("TE1_MercenaryLeader", "E15EF2C0"); // unblock not enough gold
				m_Reference.GetWorld().BlockDialogueTopicNode("TE1_MercenaryLeader", "C7A56BC0"); // block enough gold
				m_Reference.GetWorld().BlockDialogueTopicNode("TE1_MercenaryLeader", "6547EB9C"); // block enough gold
			}
			return false;
		}

		// --- Timer Events ----------------------------------------------------------------------------------------------
	// Mark the castle godstone during dialog (maybe obsolete)
		bool TE1_OnTimer_MarkGodstoneCastle()
		{
			MarkerLogic ( "TE1_Pos_GodstoneCastle", "POIMarker", "Show", true, 0 );
			return true;
		}
	// Check if in combat with sentenza for battle theme issues
		bool TE1_OnTimer_CheckFightingSentenza()
		{
			if(!m_bTE1_KillingSentenza)
				return true;

			if(!m_Reference.IsCampaignFactionInCombat())
				m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "Combat", 0);
			else
				m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "Combat", 1);

			return false;
		}

		// --- Path Events -----------------------------------------------------------------------------------------------

		// --- Kill Events ------------------------------------------------------------------------------------------------
	// When fighting sentenza - if avatar dies and revive timer is over - lose game
		bool TE1_OnReviveTimerEnd_AvatarLoseGame(Creature& in _Creature)
		{
			if(_Creature != m_Reference.GetCreatureByName(m_stgAvatar))
				return false;

			print("[SCRIPT] NOTE: The Avatar died ... you lost");
			m_Reference.LoseGame(m_iPlayerFaction);
			return true;
		}
	// When fighting sentenza - if heroparty member dies (not avatar) random banter by sentenza
		bool TE1_OnKill_CompanionDied(Creature& in _Creature)
		{
			if(m_bTE1_FightingWithSentenza)
			{
				print("[SCRIPT] NOTE: A companion died ... Sentenza is amused");
				SentenzaRandomBanter();
			}
			return false;
		}

		bool TE1_OnKill_Rondar( Creature& in _Creature )
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ProtectRondar", Failed);
			return true;
		}

		bool TE1_OnKill_Bertrand( Creature& in _Creature )
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ProtectBertrand", Failed);
			return true;
		}

	// When fighting sentenza - if sentenza dies - play the kill cutscene
		bool TE1_OnDamage_Sentenza(Creature& in _Creature)
		{
			if(_Creature.GetCurrentHP() < PercentOf( _Creature.GetMaxHP(), 5))
			{
				TE1_PlayCutScene_KillSentenza();
				return true;
			}
			return false;
		}

		bool TE1_OnKilled_CastleTroops(Creature& in _Creature)
		{
			if( !ArrayContainsCreatureID( m_arrUIntTE1_KilledFortressUnits, _Creature.GetId()) ){
				m_iTE1_KilledFortressTroops++;
				m_arrUIntTE1_KilledFortressUnits.insertLast(_Creature.GetId());
			}
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE1_FortressTroops_Dead", m_iTE1_KilledFortressTroops);
			if( CheckSpawnDead("TE1_Spawn_Castle_01") && CheckSpawnDead("TE1_Spawn_Castle_02") && CheckSpawnDead("TE1_Spawn_Castle_03") )
			{
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ClearFortress", Completed);
				if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q21_TheEye", "P3_Q21_LightGodstone") == Completed )
				{
					m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P3_Q21_TheEye", "P3_Q21_ConnectGodstones", true);
					if( m_Reference.GetBuildingByName("Entity_Godstone_Castle").GetConnectedGodstone() ==  m_Reference.GetBuildingByName("Entity_Godstone_Start") )
					{
						m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ConnectGodstones", Completed);
					}
				}
				return true;
			}
			return false;
		}

		// --- Sector Events ------------------------------------------------------------------------------------------------
	// When entering the sector - undead and nortander armies start fighting
		bool TE1_OnEnterSector_StartFightUndeadNortander_02(Creature& in _Creature)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[0]).length(); i++)
				m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[0])[i].SetFaction(10);

			m_Reference.RegisterHeroPartyEvent(AllOutsideSector, TOnHeroPartyEvent(@this.TE1_OnLeaveSector_EndFightUndeadNortander_02), "Sector_09", m_iPlayerFaction);
			return true;
		}
	// When entering the sector - undead and nortander armies start fighting
		bool TE1_OnEnterSector_StartFightUndeadNortander_03(Creature& in _Creature)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[1]).length(); i++)
				m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[1])[i].SetFaction(10);

			m_Reference.RegisterHeroPartyEvent(AllOutsideSector, TOnHeroPartyEvent(@this.TE1_OnLeaveSector_EndFightUndeadNortander_03), "Sector_12", m_iPlayerFaction);
			return true;
		}
	// When entering the sector - undead and nortander armies start fighting
		bool TE1_OnEnterSector_StartFightUndeadNortander_04(Creature& in _Creature)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[2]).length(); i++)
				m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[2])[i].SetFaction(10);

			m_Reference.RegisterHeroPartyEvent(AllOutsideSector, TOnHeroPartyEvent(@this.TE1_OnLeaveSector_EndFightUndeadNortander_04), "Sector_11", m_iPlayerFaction);
			return true;
		}

	// When leaving the sector - undead and nortander armies stop fighting
		bool TE1_OnLeaveSector_EndFightUndeadNortander_02(Creature& in _Creature)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[0]).length(); i++)
				m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[0])[i].SetFaction(m_iTE1_Faction_NortanderArmy);

			m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE1_OnEnterSector_StartFightUndeadNortander_02), "Sector_09", m_iPlayerFaction);
			return true;
		}
	// When leaving the sector - undead and nortander armies stop fighting
		bool TE1_OnLeaveSector_EndFightUndeadNortander_03(Creature& in _Creature)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[1]).length(); i++)
				m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[1])[i].SetFaction(m_iTE1_Faction_NortanderArmy);

			m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE1_OnEnterSector_StartFightUndeadNortander_03), "Sector_12", m_iPlayerFaction);
			return true;
		}
	// When leaving the sector - undead and nortander armies stop fighting
		bool TE1_OnLeaveSector_EndFightUndeadNortander_04(Creature& in _Creature)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[2]).length(); i++)
				m_Reference.GetCreaturesFromSpawn(m_arrStgTE1_UndeadSpawns[2])[i].SetFaction(m_iTE1_Faction_NortanderArmy);

			m_Reference.RegisterHeroPartyEvent(AnyInsideSector, TOnHeroPartyEvent(@this.TE1_OnEnterSector_StartFightUndeadNortander_04), "Sector_11", m_iPlayerFaction);
			return true;
		}


		// --- Other Events -----------------------------------------------------------------------------------------------
	// Add godstone to the activated gostone array - not used currently
		bool OnGodstoneCastleActivated(Creature& in _Creature)
		{
			print("[SCRIPT] NOTE: You activated the godstone!");
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_LightGodstone", Completed);
			if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q21_TheEye", "P3_Q21_ClearFortress") == Completed )
			{
				m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P3_Q21_TheEye", "P3_Q21_ConnectGodstones", true);
			}
			m_arrActivatedGodstones.insertLast( "Entity_Godstone_Castle" );

			return true;
		}
	// Play the cutscene 'TE1_01_RondarArrival' when opening a connection between the start godstone and the castle godstone
		bool OnGodstoneCastlePortalOpen(Building& in _Building)
		{
			print("[SCRIPT] NOTE: You opened the goddamn portal!");
			if( m_Reference.GetBuildingByName("Entity_Godstone_Castle").GetConnectedGodstone() ==  m_Reference.GetBuildingByName("Entity_Godstone_Start") )
			{
				//TE1_CutScene_HarbingerArrive();
				if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q21_TheEye", "P3_Q21_ClearFortress") == Completed )
				{
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ConnectGodstones", Completed);
					return true;
				}

				
			}
			return false;
		}

		void TE1_PlayCutscene_RondarArrival()
		{
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE1_OnCutsceneEnd_RondarArrival), m_iPlayerFaction);
			m_Reference.PlayCutScene("TE1_01_RondarArrival");
		}

	// -------------------------------------------------------------------------------------------------------------------
	// --- C U T S C E N E S ---------------------------------------------------------------------------------------------

		void TE1_CutScene_MapIntro_1()
		{
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE1_OnCutsceneEnd_IntroDialog), m_iPlayerFaction);
			m_Reference.PlayCutScene("MapIntro_1");
		}

		//Called @ after Cutscene MapIntro_1
		bool TE1_OnCutsceneEnd_IntroDialog(const uint8 _uPlayerFaction)
		{
			printNote("Talking to Bertrand");
			DialogTalkTo("Bertrand_Carpel", m_stgAvatar, "Bertrand_Carpel", "TE1_FirstContact");
			return true;
		}

		void EY01_CutScene_HarbingerArrive()
		{
			// Rondar and his trooops enabled
			m_Reference.ActivateSpawn( "TE1_Spawn_Rondar", true);
			m_Reference.ActivateSpawn( "TE1_Spawn_RondarReinforcement", true);

			// Rondar should not be attacked, not perform attacks himself and be immovable
			m_Reference.GetCreatureByName("Rondar_Lacaine").AllowAttacks(false);
			m_Reference.GetCreatureByName("Rondar_Lacaine").SetAttackable(false);
			m_Reference.GetCreatureByName("Rondar_Lacaine").SetImmovable(true);
			m_Reference.GetCreatureByName("Rondar_Lacaine").SetPreserveBody(true);

			m_Reference.GetWorld().EnableDialogueTopic("Bertrand_Carpel", "TE1_Bertrand_Misc", false);
			//set global bool - Guess this is not used anymore
			m_Reference.GetWorld().SetGlobalBool("StoryVariables.TE1_RondarArrived", true);
			printNote("The bool of doom " + m_Reference.GetWorld().GetGlobalBool("StoryVariables.TE1_RondarArrived"));
		}

		// Called @ CutsceneTE1_Harbinger_Arrive
		void EY01_HarbingerArriveCutscene_InteractWithGodstone()
		{
			// Rondar and his priests (all in the same spawn) need to be in the playerfaction (to interact with the godstone) but not be controlled by the player
			// Then they interact with the godstone to teleport inside the castle (can be done in cutscene)
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Rondar").length(); i++ )
			{
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Rondar")[i].SetFaction(m_iPlayerFaction);
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Rondar")[i].SetPlayerControllable(false);
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Rondar")[i].Interact(m_Reference, m_Reference.GetBuildingByName("Entity_Godstone_Start"),true); // call this @cutscene
			}
			// Rondar's troops need to be in the playerfaction (to interact with the godstone)
			// Then they interact with the godstone to teleport inside the castle (can be done in cutscene)
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement").length(); i++)
			{
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement")[i].SetFaction(m_iPlayerFaction);
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement")[i].Interact(m_Reference, m_Reference.GetBuildingByName("Entity_Godstone_Start"),true); // call this @cutscene
			}

			// Bertrand needs to be in the playerfaction (to interact with the godstone) but not be controlled by the player
			// Then he interacts with the godstone to teleport inside the castle (can be done in cutscene)
			m_Reference.GetCreatureByName("Bertrand_Carpel").SetFaction(m_iPlayerFaction);
			m_Reference.GetCreatureByName("Bertrand_Carpel").SetPlayerControllable(false);
			m_Reference.GetCreatureByName("Bertrand_Carpel").Interact(m_Reference, m_Reference.GetBuildingByName("Entity_Godstone_Start"),false);// call this @cutscene
		}

		//Called @ after Cutscene Harbinger arrival
		bool TE1_OnCutsceneEnd_RondarArrival(const uint8 _uPlayerFaction)
		{
			DialogTalkTo("Rondar_Lacaine", m_stgAvatar, "Rondar_Lacaine", "TE1_ArriveInFortress" );
			m_Reference.GetWorld().EnableDialogueTopic("Rondar_Lacaine", "TE1_ArriveInFortress", true);
			AutosaveTimed(1);
			return true;
		}

		void TE1_PlayCutscene_BlowUpGate()
		{
			printNote("PlayCutScene(TE1_02_BlowUpGate)");
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE1_OnCutsceneEnd_BlowUpGate), m_iPlayerFaction);
			m_Reference.PlayCutScene("TE1_02_BlowUpGate");
		}

		bool TE1_OnCutsceneEnd_BlowUpGate(const uint8 _uPlayerFaction)
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Rondar").length(); i++)
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Rondar")[i].FollowCreature (m_Reference, m_Reference.GetCreatureByName(m_stgAvatar), 30, 20, false, false);

			m_Reference.GetCreatureByName("Bertrand_Carpel").FollowCreature (m_Reference, m_Reference.GetCreatureByName(m_stgAvatar), 30, 20, false, false);
			return true;
		}

		void EY01_CutScene_BlowUpGate()
		{
			m_Reference.GetCreatureByName("Rondar_Lacaine").SetFaction(1); // rondar faction
			m_Reference.GetCreatureByName("Rondar_Lacaine").AddSpell(m_Reference, "Fireball_I");
			m_Reference.GetCreatureByName("Rondar_Lacaine").Cast(m_Reference, "Fireball_I", m_Reference.GetBuildingByName("TE1_Bldg_FrontGate"), false);

			//disable navmeshblocker and the entity
			//gate attackable
			m_Reference.GetBuildingByName("TE1_Bldg_FrontGate").SetAttackable(true);
			m_Reference.GetBuildingByName("TE1_Bldg_FrontGate").SetFaction(7); // Barricade Faction - only hostile towards harbinger

			m_Reference.BlockNavMesh("TE1_PhysicBlocker_FrontGate", false);
			//switch not interactive anymore
			m_Reference.GetLogicObjectByName("TE1_Switch_FrontGate").SetInteractive(false);
		}

		void EY01_CutScene_KillSentenza_UnitsFight()
		{
			HeroPartyImmortal(true);
			m_iTE1_CachedAvatarHP = m_Reference.GetCreatureByName(m_stgAvatar).GetCurrentHP();
			//Sentenza and avatar fighting each other
			m_Reference.GetCreatureByName(m_stgAvatar).Attack(m_Reference, m_Reference.GetCreatureByName("Sentenza_Noria"), false);
			m_Reference.GetCreatureByName("Sentenza_Noria").Attack(m_Reference, m_Reference.GetCreatureByName(m_stgAvatar), false);

			m_Reference.ActivateSpawn("TE1_SP_FakeUnitPlayer_01", true);
			m_Reference.ActivateSpawn("TE1_SP_FakeUnitPlayer_02", true);
			m_Reference.ActivateSpawn("TE1_SP_FakeUnitPlayer_03", true);
			m_Reference.ActivateSpawn("TE1_SP_FakeUnitEnemy_01", true);
			m_Reference.ActivateSpawn("TE1_SP_FakeUnitEnemy_02", true);
			m_Reference.ActivateSpawn("TE1_SP_FakeUnitEnemy_03", true);

			SetSpawnImmortal("TE1_SP_FakeUnitPlayer_01", true);
			SetSpawnImmortal("TE1_SP_FakeUnitPlayer_02", true);
			SetSpawnImmortal("TE1_SP_FakeUnitPlayer_03", true);

			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitPlayer_01")[0].Attack(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_01")[0], false);
			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_01")[0].Attack(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitPlayer_01")[0], false);

			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitPlayer_02")[0].Attack(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_02")[0], false);
			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_02")[0].Attack(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitPlayer_02")[0], false);

			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitPlayer_03")[0].Attack(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_03")[0], false);
			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_03")[0].Attack(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitPlayer_03")[0], false);

		}
		// called at cutscene 'SentenzaDie'
		void EY01_CutScene_KillSentenza_Death()
		{
			print("[SCRIPT] NOTE: LET THE CUTSCENE BEGIN");

			m_Reference.GetCreatureByName("Sentenza_Noria").SetImmortal(false);
			m_Reference.RegisterCreatureEventByIndividual(Damaged, TOnCreatureEvent(@this.TE1_OnDamage_SentenzaDeath), "Sentenza_Noria", "");

			//m_Reference.GetWorld().EnableDialogueTopic("Rondar_Lacaine", "TE1_Conclusion", true);
			//m_Reference.GetWorld().EnableDialogueTopic("Bertrand_Carpel", "TE1_SO_Final", true);
			m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "combat", 0);
		}

		bool TE1_OnDamage_SentenzaDeath(Creature& in _Creature)
		{
			m_Reference.GetCreatureByName("Rondar_Lacaine").Revive();
			m_Reference.GetCreatureByName("Bertrand_Carpel").Revive();
			_Creature.Kill();
			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_01")[0].Kill();
			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_02")[0].Kill();
			m_Reference.GetCreaturesFromSpawn("TE1_SP_FakeUnitEnemy_03")[0].Kill();

			SetSpawnImmortal("TE1_SP_FakeUnitPlayer_01", false);
			SetSpawnImmortal("TE1_SP_FakeUnitPlayer_02", false);
			SetSpawnImmortal("TE1_SP_FakeUnitPlayer_03", false);
			HeroPartyImmortal(false);
			return true;
		}

		bool TE1_OnCutsceneEnd_SentenzaKilled(const uint8 _uPlayerFaction)
		{
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy")[i].Enable(true);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02")[i].Enable(true);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement")[i].Enable(true);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Mercenaries").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Mercenaries")[i].Enable(true);


			m_Reference.SetFactionRelation(m_iPlayerFaction, m_iTE1_Faction_Sentenza, Neutral);
			m_Reference.SetFactionRelation(m_iTE1_Faction_Harbinger, m_iTE1_Faction_Sentenza, Neutral);
			SetFactionSpawn("TE1_SP_FakeUnitPlayer_01", m_iPlayerFaction);
			SetFactionSpawn("TE1_SP_FakeUnitPlayer_02", m_iPlayerFaction);
			SetFactionSpawn("TE1_SP_FakeUnitPlayer_03", m_iPlayerFaction);
			CreatureGroup _grp01 = CreatureGroup(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy"));
			CreatureGroup _grp02 = CreatureGroup(m_Reference, m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02"));
			_grp01.Move(m_Reference.GetLogicObjectByName("TE1_Spot_SentenzaUnitsFlee"), false, false, false);
			_grp02.Move(m_Reference.GetLogicObjectByName("TE1_Spot_SentenzaUnitsFlee"), false, false, false);
			m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE1_OnTrigger_DespawnSentenzaUnits), m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy"), true, "TE1_Trigger_DespawnSentenzaUnits");
			m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE1_OnTrigger_DespawnSentenzaUnits), m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02"), true, "TE1_Trigger_DespawnSentenzaUnits");

			m_Reference.GetCreatureByName("Bertrand_Carpel").Revive();
			m_Reference.GetCreatureByName("Rondar_Lacaine").Revive();
			m_Reference.GetCreatureByName("Bertrand_Carpel").GoTo(m_Reference, m_Reference.GetCreatureByName("Rondar_Lacaine"), 15, 30, false, false);
			m_Reference.GetWorld().EnableDialogueTopic("Rondar_Lacaine", "TE1_Conclusion", true);
			m_Reference.GetWorld().EnableDialogueTopic("Bertrand_Carpel", "TE1_SO_Final", true);
			m_Reference.GetCreatureByName(m_stgAvatar).Heal( m_iTE1_CachedAvatarHP - m_Reference.GetCreatureByName(m_stgAvatar).GetCurrentHP() );
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_DefeatSentenza", Completed);
			if(m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q21_TheEye", "P3_Q21_ProtectRondar") != Failed )
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ProtectRondar", Completed);
			if(m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P3_Q21_TheEye", "P3_Q21_ProtectBertrand") != Failed )
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_Q21_TheEye", "P3_Q21_ProtectBertrand", Completed);


			return true;
		}

		void TE1_PlayCutScene_KillSentenza()
		{

			// sentenza army disable (fake army alive)
			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy")[i].Enable(false);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_SentenzaArmy02")[i].Enable(false);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_RondarReinforcement")[i].Enable(false);

			for( uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Mercenaries").length(); i++ )
				m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Mercenaries")[i].Enable(false);


			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE1_OnCutsceneEnd_SentenzaKilled), m_iPlayerFaction);
			// deactivate sentenzas AI behaviour
			m_Reference.DeactivateAI( 4 );
			m_bTE1_KillingSentenza = true;
			// start the cutscene

			m_Reference.SetGlobalSoundParameter( m_iPlayerFaction, uint8(-1), "combat", 0);
			m_Reference.PlayCutScene("TE1_03_SentenzaDie");
		}

		void TE1_Cutscene_GateExplosionEnable( )
		{
			m_Reference.GetLogicObjectByName( "TE1_FortressGate_Explosion" ).Enable( true );
		}

		void TE1_Cutscene_GateExplosionDisable( )
		{
			m_Reference.GetLogicObjectByName( "TE1_FortressGate_Explosion" ).Enable( false );
		}

		void TE1_Cutscene_SwitchGateVersions( )
		{
			m_Reference.EnableGroup( "TE1_FortressGate_BeforeExplosion" , false );
			m_Reference.EnableGroup( "TE1_FortressGate_AfterExplosion", true );
			m_Reference.EnableGroup( "TE1_FortressGate_Fire", true );

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

		bool TE1_OnTimer_SwitchFireOnGate( )
		{
			m_Reference.EnableGroup( "TE1_FortressGate_Fire", false );
			m_Reference.EnableGroup( "TE1_FortressGate_Smoke", true );

			return true;
		}

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

	void TE1_Articy_MarkGodStone()
	{
		m_Reference.SetTimer( TOnTimerEvent(@this.TE1_OnTimer_MarkGodstoneCastle), 1 );
	}

	void TE1_Articy_HireMercenaries()
	{
		print("[SCRIPT] NOTE: You hired them");
		array<Creature> _Mercenaries = m_Reference.GetCreaturesFromSpawn("TE1_Spawn_Mercenaries");
		CreatureGroup _mercGrp = CreatureGroup(m_Reference, _Mercenaries);
		for(uint i = 0; i < _Mercenaries.length(); i++){
			_Mercenaries[i].SetFaction(m_iPlayerFaction);
			_Mercenaries[i].GoTo(m_Reference,m_Reference.GetCreatureByName("TE1_MercenaryLeader"), 5, 10, false);
		}
		m_Reference.GetWorld().EnableDialogueTopic("TE1_MercenaryLeader", "TE1_FirstContact", false);
		EnablePOIVisitingBehaviorSpawn("TE1_Spawn_Mercenaries", false);
		m_Reference.GetCreatureByName("TE1_MercenaryLeader").SetFaction(m_iPlayerFaction);
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveGold(m_iTE1_MercenaryPrice);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("SQ_021_HireMercenaries", "SQ_021_HireMercenaries", Completed);

	}

	void TE1_Articy_TalkedAboutHire()
	{
		m_bTE1_TalkedABoutHire = true;
	}


	void TE1_Articy_SentenzaHostile()
	{
		print("[SCRIPT] NOTE: Let's fight this monster");

		// THORSTEN Remove Spell
		m_Reference.GetCreatureByName("Rondar_Lacaine").RemoveSpell(m_Reference, "Fireball_I");

		//THORSTEN Learn Harbinger Spells
		m_Reference.GetCreatureByName("Rondar_Lacaine").AddSpell(m_Reference, "Harbinger_Sentenza_Boss_Heal");
		m_Reference.GetCreatureByName("Rondar_Lacaine").AddSpell(m_Reference, "Harbinger_Sentenza_Boss_Buff");
		m_Reference.GetCreatureByName("Rondar_Lacaine").AddSpell(m_Reference, "Harbinger_Sentenza_Boss_Revive");

		m_Reference.SetFactionRelation(m_iPlayerFaction, m_iTE1_Faction_Sentenza, Hostile);
		m_Reference.SetFactionRelation(m_iTE1_Faction_Harbinger, m_iTE1_Faction_Sentenza, Hostile);
		m_Reference.SetGlobalSoundParameter(m_iPlayerFaction, uint8(-1), "combat", 1);
		m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P3_Q21_TheEye", "P3_Q21_ProtectRondar", true);
		m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P3_Q21_TheEye", "P3_Q21_ProtectBertrand", true);
		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE1_OnKill_Rondar), "Rondar_Lacaine", "");
		m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE1_OnKill_Bertrand), "Bertrand_Carpel", "");
		m_Reference.GetCreatureByName("Rondar_Lacaine").Stop(m_Reference);
		m_Reference.GetCreatureByName("Rondar_Lacaine").AllowAttacks(true);
		m_Reference.GetCreatureByName("Rondar_Lacaine").SetAttackable(true);
		m_Reference.GetCreatureByName("Bertrand_Carpel").Stop(m_Reference);
		m_Reference.GetCreatureByName("Bertrand_Carpel").AllowAttacks(true);
		m_Reference.GetCreatureByName("Bertrand_Carpel").SetAttackable(true);

		SetSpawnImmovable("TE1_Spawn_SentenzaArmy", false);
		EnablePOIVisitingBehaviorSpawn("TE1_Spawn_SentenzaArmy", false);
		SetSpawnImmovable("TE1_Spawn_SentenzaArmy02", false);
		EnablePOIVisitingBehaviorSpawn("TE1_Spawn_SentenzaArmy02", false);
		SpawnAttackable("TE1_Spawn_SentenzaArmy", true);
		m_Reference.RegisterHeroPartyEvent(HeroRevivePeriodEnded, TOnHeroPartyEvent(@this.TE1_OnReviveTimerEnd_AvatarLoseGame), m_stgAvatar, m_iPlayerFaction);
		m_bTE1_FightingWithSentenza = true;
		m_Reference.SetTimer(TOnTimerEvent(@this.TE1_OnTimer_CheckFightingSentenza), 3);

	}

	void TE1_Articy_EnableMapTransition()
	{
		m_Reference.GetWorld().SetMapAccessible(35, true, m_Reference.GetWorld().GetCurrentMapSetting(35));
	}

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

	void SentenzaRandomBanter(){
		if(m_Reference.GetCreatureByName("Sentenza_Noria").GetCurrentHP() > 0){
			int _rand = m_Reference.GetRandom().GetInteger(0,3);
			switch(_rand){
				case 0:
					DialogShoutout("Sentenza_Noria", "Sentenza_Noria", "TE1_SO_KillAlly", false);
					break;
				case 1:
					DialogShoutout("Sentenza_Noria", "Sentenza_Noria", "TE1_SO_KillAll2", false);
					break;
				case 2:
					DialogShoutout("Sentenza_Noria", "Sentenza_Noria", "TE1_SO_KillAll3", false);
					break;
				default: break;
			}
		}
	}

	void RegisterEventHeroPartyMember(){
		array<Creature> _heroParty = m_Reference.GetHeroParty(m_iPlayerFaction).GetMembers();
		for(uint i = 0; i < _heroParty.length(); i++){
			if(_heroParty[i].GetDescriptionName() != m_stgAvatar){
				m_Reference.RegisterHeroPartyEvent(Killed, TOnHeroPartyEvent(@this.TE1_OnKill_CompanionDied), _heroParty[i].GetDescriptionName(), m_iPlayerFaction);
			}
		}
	}


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

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

		// --- TRIGGER EVENTS --------------------------------------------------------------------------------------------
	bool TE2_OnTrigger_SO_BaseFound(Creature& in _Creature)
	{
		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE2_01A_SO_BaseFound", false);
		m_Reference.GetSectorByName("Sector_03").CreateCapital(m_iPlayerFaction, true);
		// .. had to do it this ways, else the player won't get start resources by Levelbase_gameplay

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_CheckOutpost", Completed);
	//	m_Reference.ActivateSpawn("TE2_SP_FleeingPrisoner01", true);
		m_Reference.ActivateAI(m_iFaction_HouseLeonidarAI);
		return true;
	}

	void Articy_TE2_CutsceneFleeingPrisoner()
	{
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE2_OnCutsceneFinished_FleeingPrisoner), m_iPlayerFaction);
		m_Reference.PlayCutScene("TE2_Cutscene_FleeingPrisoner");
	}

	bool TE2_OnCutsceneFinished_FleeingPrisoner(const uint8 _uPlayerFaction)
	{
		DialogTalkTo( "TE2_Fleeing_Prisoner", m_stgAvatar, "TE2_Fleeing_Prisoner", "TE2_35_FirstContact" );
		return true;
	}

	void TE2_CutsceneFunc_FleeingPrisonerRunning()
	{
		m_Reference.ActivateSpawn("TE2_SP_FleeingPrisoner01", true);
		m_Reference.GetCreatureByName("TE2_Fleeing_Prisoner").FollowPath(m_Reference, "TE2_Path_FleeingPrisoner", true, false);
	}

	bool TE2_OnTrigger_SO_Barrier(Creature& in _Creature)
	{
		if(_Creature != m_Reference.GetCreatureByName(m_stgAvatar))
		{
			return false;
		}
		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE2_01_SO_Barrier", true);
		return true;
	}

	bool TE2_OnTrigger_SO_DeserterDiscussion(Creature& in _Creature)
	{
		DialogTalkTo( "TE2_Deserter", "TE2_Escapee_01", "TE2_Escapee_01", "TE2_04_SO_DeserterArgument");
		m_Reference.GetWorld().EnableDialogueTopic("TE2_Escapee_01", "TE2_05_FirstContact", true);
		m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_SQ21_02_TheDeserter", true);
		return true;
	}

	bool TE2_OnTrigger_AtMage(Creature& in _Creature)
	{
		if( !m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_Q21_HouseLeonidar", "P4_Q21_TalkToMage") )
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_HouseLeonidar", "P4_Q21_TalkToMage", true);
		return true;
	}

	bool TE2_OnKilled_PurityAttack(Creature& in _Creature)
	{
		// QUEST STUFF
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_Kill_Purity_Attack", Completed);
		m_Reference.GetWorld().EnableDialogueTopic("TE2_Fleeing_Prisoner", "TE2_36_PrisonerSaved", true);
		Autosave();
		printNote("All purity attackers are dead");
		return true;
	}

	bool TE2_OnTrigger_SO_Prisoner1(Creature& in _Creature)
	{
		if( !m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P4_SQ21_01_Prisoners") && m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P4_SQ21_01_Prisoners") != Completed )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_SQ21_01_Prisoners", true);
		}
		if(!m_arrBTE2_PrisonersFreed[0])
		{
			DialogShoutout("TE2_Prisoner", "TE2_Prisoner", "TE2_29_SO_Overhere", false);
			m_Reference.SetTimer(TOnTimerEvent(@this.TE2_OnTimer_ResetPrisonerShoutout_1), 60);
		}
		return true;
	}

	bool TE2_OnTrigger_SO_Prisoner2(Creature& in _Creature)
	{
		if( !m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P4_SQ21_01_Prisoners") && m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P4_SQ21_01_Prisoners") != Completed )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_SQ21_01_Prisoners", true);
		}
		if(!m_arrBTE2_PrisonersFreed[1])
		{
			DialogShoutout("TE2_Prisoner_02", "TE2_Prisoner_02", "TE2_31_SO_Overhere", false);
			m_Reference.SetTimer(TOnTimerEvent(@this.TE2_OnTimer_ResetPrisonerShoutout_2), 60);
		}
		return true;
	}

	bool TE2_OnTrigger_SO_Prisoner3(Creature& in _Creature)
	{
		if( !m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P4_SQ21_01_Prisoners") && m_Reference.GetJournal(m_iPlayerFaction).GetQuestState("P4_SQ21_01_Prisoners") != Completed )
		{
			m_Reference.GetJournal(m_iPlayerFaction).ActivateQuest("P4_SQ21_01_Prisoners", true);
		}
		if(!m_arrBTE2_PrisonersFreed[2])
		{
			DialogShoutout("TE2_Prisoner_03", "TE2_Prisoner_03", "TE2_33_SO_Overhere", false);
			m_Reference.SetTimer(TOnTimerEvent(@this.TE2_OnTimer_ResetPrisonerShoutout_3), 60);
		}
		return true;
	}

	bool TE2_OnTrigger_SO_DeadBrother(Creature& in _Creature)
	{
		if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
		{
			m_bTE2_AvatarAtDeadBrother = true;
		}
		else if(_Creature == m_Reference.GetCreatureByName("TE2_Escapee_02"))
		{
			m_bTE2_EscapeeAtDeadBrother = true;
		}
		if(m_bTE2_AvatarAtDeadBrother && m_bTE2_EscapeeAtDeadBrother)
		{
			printNote("HE IS DEAD :(");
			DialogShoutout("TE2_Escapee_02", "TE2_Escapee_02", "TE2_11_SO_DeadBrother", true);
			return true;
		}
		return false;
	}

		bool TE2_OnLeaveTrigger_SO_DeadBrother(Creature& in _Creature)
		{
			if(_Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				m_bTE2_AvatarAtDeadBrother = false;
			}
			else if(_Creature == m_Reference.GetCreatureByName("TE2_Escapee_02"))
			{
				m_bTE2_EscapeeAtDeadBrother = false;
			}
			return false;
		}

		bool TE2_OnTrigger_DeserterAtCastleEntrance(Creature& in _Creature)
		{
			_Creature.Teleport(m_Reference, m_Reference.GetLogicObjectByName("TE2_Spot_TeleportCastle_Deserter"));
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE2_OldMageRebel", "68CE1790");
			m_Reference.GetWorld().BlockDialogueTopicNode("TE2_OldMageRebel", "3E1A9291");
			m_Reference.GetWorld().EnableDialogueTopic("TE2_Deserter", "TE2_13_SO_Join", true);
			Autosave();
			return true;
		}

		bool TE2_OnTrigger_SO_WeaponRack(Creature& in _Creature)
		{
			if( _Creature != m_Reference.GetCreatureByName(m_stgAvatar) || m_arrUintTE2_UnarmedPrisonerIDs.length() == 0)
			{
				printNote("See the weapon rack nut no idea what to do with it");
				return false;
			}
			printNote("See the weapon rack");
			if( !m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_SQ21_01_Prisoners", "P4_SQ21_01_EquipPrisoners") && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_EquipPrisoners") != Completed )
			{
				m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_SQ21_01_Prisoners", "P4_SQ21_01_EquipPrisoners", true);
			}
			DialogShoutout(m_stgAvatar, m_stgAvatar, "TE2_44_SO_WeaponRack", false);
			return true;
		}

		bool TE2_OnTrigger_PrisonerAtWeaponRack(Creature& in _Creature)
		{
			if( m_arrUintTE2_UnarmedPrisonerIDs.length() <= 0 )
				return true;
			printNote("Prisoner gets armor");

			//int _rand = m_Reference.GetRandom().GetInteger(0, 8);
			_Creature.ChangeEquipmentSet(1);
			_Creature.SetPlayerControllable(true);
			_Creature.AllowAttacks(true);

			for(uint i = 0; i < m_arrUintTE2_UnarmedPrisonerIDs.length(); i++)
			{
				if(m_Reference.GetCreatureById(m_arrUintTE2_UnarmedPrisonerIDs[i]) == _Creature)
				{
					m_arrUintTE2_UnarmedPrisonerIDs.removeAt(i);
					break;
				}
			}

			int _iEquipped = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.TE2_EquippedPrisoners", - 1);
			_iEquipped ++;
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE2_EquippedPrisoners", _iEquipped);
			if( _iEquipped == 1)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_Inv_EquipPrisoner_01", Completed);

			else if( _iEquipped == 2)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_Inv_EquipPrisoner_02", Completed);

			else if( _iEquipped == 3)
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_Inv_EquipPrisoner_03", Completed);

			return false;
		}

		bool TE2_OnTrigger_DeserterAtKeyGuard(Creature& in _Creature)
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE2_KTE1_Guard", "AE52E80F");
			return false;
		}

		bool TE2_OnTrigger_DeserterLeavesKeyGuard(Creature& in _Creature)
		{
			m_Reference.GetWorld().BlockDialogueTopicNode("TE2_KTE1_Guard", "AE52E80F");
			return true;
		}

		bool TE2_OnTrigger_AmariaFight(Creature& in _Creature)
		{
			if( m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_Q21_HouseLeonidar", "P4_Q21_FindAmaria") && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_FindAmaria") != Completed )
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_FindAmaria", Completed);

			if( _Creature == m_Reference.GetCreatureByName(m_stgAvatar))
			{
				m_Reference.GetWorld().EnableDialogueTopic("Amaria_Leonidar", "TE2_46_FirstContact", true);
				return true;
			}
			return false;
		}


		bool TE2_OnTrigger_EscapeesAtMage(Creature& in _Creature)
		{
			m_bTE2_EscapeesAtMage = true;
			return false;
		}

		bool TE2_OnTrigger_EscapeesLeaveMage(Creature& in _Creature)
		{
			m_bTE2_EscapeesAtMage = false;
			return false;
		}


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

		bool TE2_OnInteract_WeaponRack(Creature& in _Creature)
		{
			printNote("PRISONERS IN THE HOUSE *" + m_arrUintTE2_UnarmedPrisonerIDs.length() + " *");
			if( m_arrUintTE2_UnarmedPrisonerIDs.length() > 0)
			{
				DialogShoutout(m_stgAvatar, m_stgAvatar, "TE2_45_SO_PrisonersArmed", false);
				CreatureGroup _grpPrisoners = CreatureGroup(m_Reference);
				for( uint i = 0; i < m_arrUintTE2_UnarmedPrisonerIDs.length(); i++)
				{
					_grpPrisoners.Add(m_Reference.GetCreatureById( m_arrUintTE2_UnarmedPrisonerIDs[i] ));
					m_Reference.GetCreatureById(m_arrUintTE2_UnarmedPrisonerIDs[i]).AllowAttacks(false);
				}
				_grpPrisoners.Move(m_Reference.GetLogicObjectByName("TE2_Switch_WeaponRack"), false, false, false);
				_grpPrisoners.SetControllable(false);
				m_Reference.RegisterCreatureEventByIndividuals(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_PrisonerAtWeaponRack), _grpPrisoners.GetCreatures(), true, "TE2_Trigger_CheckWeaponRack");
			}
			return false;
		}

		bool TE2_OnInteract_FreePrisoner_01(Creature& in _Creature)
		{
			if(m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("TE2_PrisonerCellKey_01", 1))
			{
				printNote("You freed Prisoner 01");
				int _iFreedPrisoner = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", - 1);
				_iFreedPrisoner++;
				m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", _iFreedPrisoner);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_Inv_FreePrisoner_01", Completed);

				DialogTalkTo("TE2_Prisoner", m_stgAvatar, m_stgAvatar, "TE2_41_SO_PrisonersFreed");
				m_arrBTE2_PrisonersFreed[0] = true;

				SetFactionSpawn("TE2_SP_Prisoners01", m_iPlayerFaction);
				m_arrUintTE2_UnarmedPrisonerIDs.insertLast( m_Reference.GetCreatureByName("TE2_Prisoner").GetId() );
				m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE2_OnKilled_UnarmedPrisoners), "TE2_Prisoner", "" );
				m_Reference.RegisterCreatureEventByIndividual(Resurrected, TOnCreatureEvent(@this.TE2_OnResurrected_UnarmedPrisoners), "TE2_Prisoner", "" );
				return true;
			}
			DialogShoutout("TE2_Prisoner", "TE2_Prisoner", "TE2_30_SO_Guard", true);
			return false;
		}


		bool TE2_OnInteract_FreePrisoner_02(Creature& in _Creature)
		{
			if(m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("TE2_PrisonerCellKey_01", 1))
			{
				printNote("You freed Prisoner 02");
				int _iFreedPrisoner = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", - 1);
				_iFreedPrisoner++;
				m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", _iFreedPrisoner);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_Inv_FreePrisoner_02", Completed);
				DialogTalkTo("TE2_Prisoner_02", m_stgAvatar, m_stgAvatar, "TE2_42_SO_PrisonersFreed_02");
				m_arrBTE2_PrisonersFreed[1] = true;

				SetFactionSpawn("TE2_SP_Prisoners02", m_iPlayerFaction);
				m_arrUintTE2_UnarmedPrisonerIDs.insertLast( m_Reference.GetCreatureByName("TE2_Prisoner_02").GetId() );
				m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE2_OnKilled_UnarmedPrisoners), "TE2_Prisoner_02", "" );
				m_Reference.RegisterCreatureEventByIndividual(Resurrected, TOnCreatureEvent(@this.TE2_OnResurrected_UnarmedPrisoners), "TE2_Prisoner_02", "" );
				return true;
			}
			DialogShoutout("TE2_Prisoner_02", "TE2_Prisoner_02", "TE2_32_SO_Guard", true);
			return false;
		}


		bool TE2_OnInteract_FreePrisoner_03(Creature& in _Creature)
		{
			if(m_Reference.GetHeroParty(m_iPlayerFaction).HasItems("TE2_PrisonerCellKey_01", 1))
			{
				printNote("You freed Prisoner 03");
				int _iFreedPrisoner = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", - 1);
				_iFreedPrisoner++;
				m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", _iFreedPrisoner);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_Inv_FreePrisoner_03", Completed);
				DialogTalkTo("TE2_Prisoner_03", m_stgAvatar, m_stgAvatar, "TE2_43_SO_PrisonersFreed_03");
				m_arrBTE2_PrisonersFreed[2] = true;

				SetFactionSpawn("TE2_SP_Prisoners03", m_iPlayerFaction);
				m_arrUintTE2_UnarmedPrisonerIDs.insertLast( m_Reference.GetCreatureByName("TE2_Prisoner_03").GetId() );
				m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE2_OnKilled_UnarmedPrisoners), "TE2_Prisoner_03", "" );
				m_Reference.RegisterCreatureEventByIndividual(Resurrected, TOnCreatureEvent(@this.TE2_OnResurrected_UnarmedPrisoners), "TE2_Prisoner_03", "" );
				return true;
			}
			DialogShoutout("TE2_Prisoner_03", "TE2_Prisoner_03", "TE2_34_SO_Guard", true);
			return false;
		}

		// --- DAMAGE KILL CREATURE EVENTS -------------------------------------------------------------------------------
		bool TE2_OnKilled_AvatarLose(Creature& in _Creature)
		{
			m_Reference.LoseGame(m_iPlayerFaction);
			return true;
		}

		bool TE2_OnDamage_Escapees(Creature& in _Creature)
		{
			if(_Creature.GetCurrentHP() <= 0 && CheckSpawnDead("TE2_SP_Rebels02"))
			{
				printNote("Killed those fuckers");
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_02_TheDeserter", "P4_SQ21_02_DefeatEscapees", Completed);
				m_Reference.GetWorld().EnableDialogueTopic( "TE2_Deserter", "TE2_12_Saved", true);
				m_bTE2_DeserterSaved = true;
			}
			return false;
		}

		bool TE2_OnKilled_UnarmedPrisoners(Creature& in _Creature)
		{
			for(uint i = 0; i < m_arrUintTE2_UnarmedPrisonerIDs.length(); i++)
			{
				if( m_Reference.GetCreatureById(m_arrUintTE2_UnarmedPrisonerIDs[i]) == _Creature)
				{
					m_arrUintTE2_UnarmedPrisonerIDs.removeAt(i);
					printNote("One of the prisoners died " + m_arrUintTE2_UnarmedPrisonerIDs.length());
					int _iPrisoners = m_arrUintTE2_UnarmedPrisonerIDs.length();
					m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", _iPrisoners);
				}
			}
			return true;
		}

		bool TE2_OnDamage_Deserter(Creature& in _Creature)
		{
			m_Reference.GetCreatureByName("TE2_Deserter").Kill();
			printNote("The Deserter died");
			m_Reference.GetWorld().EnableDialogueTopic( "TE2_Escapee_01", "TE2_07_Join", true);
			m_bTE2_DeserterDied = true;
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgAvatar, "BEBA57D0");
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "5C5F68BC");
			return true;
		}

		bool TE2_OnDamage_Avatar(Creature& in _Creature)
		{
			if(_Creature.GetCurrentHP() <= 0 )
			{
				printNote("The avatar died");
				if(m_bTE2_FightingWithAmaria)
				{
					DialogShoutout( "Amaria_Leonidar", "Amaria_Leonidar", "TE2_51_SO_AvatarDead", false );
				}

			}
			return false;
		}

		bool TE2_OnHeroReviveEnded_Avatar(Creature& in _Creature)
		{
			printNote("Avatar was not revived");
			m_Reference.LoseGame(m_iPlayerFaction);
			return true;
		}

		bool TE2_OnDamage_Amaria(Creature& in _Creature){

			if( _Creature.GetCurrentHP() <= 0)
			{
				printNote("Amaria died");
				for( uint i = 0; i < _Creature.GetSummonedCreatures(m_Reference).length(); i++ )
					_Creature.GetSummonedCreatures(m_Reference)[i].Kill();


				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_DefeatAmaria", Completed);
				if(m_Reference.GetCreatureByName("TE2_Prisoner").Exists())
					m_Reference.RegisterCreatureEventByIndividual(CanSee, TOnCreatureEvent(@this.TE2_OnCanSee_PrisonerSeesAvatar), "TE2_Prisoner", m_stgAvatar);
				
				if(m_Reference.GetCreatureByName("TE2_Escapee_01").Exists())
					m_Reference.RegisterCreatureEventByIndividual(CanSee, TOnCreatureEvent(@this.TE2_OnCanSee_EscapeeSeesAvatar), "TE2_Escapee_01", m_stgAvatar);
				
				if(m_Reference.GetCreatureByName("TE2_Deserter").Exists())
					m_Reference.RegisterCreatureEventByIndividual(CanSee, TOnCreatureEvent(@this.TE2_OnCanSee_DeserterSeesAvatar), "TE2_Prisoner_02", m_stgAvatar);
				
				if(m_bTE2_PrisonerSeesAvatar)
					m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "0786FE4D");
				
				if(m_bTE2_DeserterSeesAvatar)
					m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "DB46FE00");
				
				if(m_bTE2_EscapeeSeesAvatar)
					m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "7E87AE3C");
				
				DialogShoutout_Important("Amaria_Leonidar", m_stgAvatar, "TE2_52_SO_AmariaDead", "Amaria_Leonidar", array <string> = {} );
				m_bTE2_PrisonerSeesAvatar = false;
				m_bTE2_DeserterSeesAvatar = false;
				m_bTE2_EscapeeSeesAvatar = false;

				m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseLeonidarAI, Neutral);
			//	DisableAI();
				m_Reference.LoseGame(m_iFaction_HouseLeonidarAI);
				TransferRTS(0, kFactionNeutral);

				return true;
			}
			else if( !m_bTE2_AmariaSO_3 && _Creature.GetCurrentHP() <= PercentOf(_Creature.GetMaxHP(), 33))
			{
				DialogShoutout("Amaria_Leonidar", "Amaria_Leonidar", "TE2_50_SO_Combat_SO_03" ,false);
				m_bTE2_AmariaSO_3 = true;
			}

			else if( !m_bTE2_AmariaSO_2 && _Creature.GetCurrentHP() <= PercentOf(_Creature.GetMaxHP(), 50))
			{
				DialogShoutout("Amaria_Leonidar", "Amaria_Leonidar", "TE2_49_SO_Combat_SO_02" ,false);
				m_bTE2_AmariaSO_2 = true;
			}

			else if( !m_bTE2_AmariaSO_1 && _Creature.GetCurrentHP() <= PercentOf(_Creature.GetMaxHP(), 66))
			{
				DialogShoutout("Amaria_Leonidar", "Amaria_Leonidar", "TE2_47_SO_Combat_SO_01" ,false);
				m_bTE2_AmariaSO_1 = true;
			}
			
			return false;
		}

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


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

		bool TE2_OnFollowPathFinished_FisherInsideHouse(Creature & in _Creature)
		{
			print("[SCRIPT] NOTE: Fisher is in his House and teleports away");
			m_Reference.GetCreatureByName("TE2_Fisherman").Enable(false);
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE2_OldMageRebel", "68CE1790");
			m_Reference.GetWorld().BlockDialogueTopicNode("TE2_OldMageRebel", "3E1A9291");
			Autosave();
			return true;
		}

		// --- TIMER EVENTS ----------------------------------------------------------------------------------------------

		bool TE2_OnTimer_ResetPrisonerShoutout_1()
		{
			m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Prisoner1), "TE2_Trigger_SOPrisoner_1", m_iPlayerFaction);
			return true;

		}

		bool TE2_OnTimer_ResetPrisonerShoutout_2()
		{
			m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Prisoner2), "TE2_Trigger_SOPrisoner_2", m_iPlayerFaction);
			return true;
		}

		bool TE2_OnTimer_ResetPrisonerShoutout_3()
		{
			m_Reference.RegisterHeroPartyEvent(AnyInside, TOnHeroPartyEvent(@this.TE2_OnTrigger_SO_Prisoner3), "TE2_Trigger_SOPrisoner_3", m_iPlayerFaction);
			return true;
		}

		// --- SIGHT EVENTS ----------------------------------------------------------------------------------------------

		bool TE2_OnCanNotSee_Deserter(Creature& in _Creature)
		{
			m_Reference.GetCreatureByName("TE2_Deserter").Stop(m_Reference);
			m_Reference.GetCreatureByName("TE2_Deserter").Teleport( m_Reference, m_Reference.GetLogicObjectByName("TE2_Spot_TeleportCastle_Deserter"));
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE2_OldMageRebel", "68CE1790");
			m_Reference.GetWorld().BlockDialogueTopicNode("TE2_OldMageRebel", "3E1A9291");
			m_Reference.GetWorld().EnableDialogueTopic("TE2_Deserter", "TE2_13_SO_Join", true);
			Autosave();
			return true;
		}

		bool TE2_OnCanSee_PrisonerSeesAvatar(Creature& in _Creature)
		{
			m_bTE2_PrisonerSeesAvatar = true;
			return true;
		}

		bool TE2_OnCanSee_EscapeeSeesAvatar(Creature& in _Creature)
		{
			m_bTE2_EscapeeSeesAvatar = true;
			return true;
		}

		bool TE2_OnCanSee_DeserterSeesAvatar(Creature& in _Creature)
		{
			m_bTE2_DeserterSeesAvatar = true;
			return true;
		}



		// --- SECTOR EVENTS ---------------------------------------------------------------------------------------------
		bool TE2_OnEnteredSector_HeropartyAtCastle(Creature& in _Creature)
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "TE2_27_SO_Inside", false);
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_HouseLeonidar", "P4_Q21_FindAmaria", true);
			//m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE2_OnKilled_AvatarLose), m_stgAvatar );
			m_Reference.RegisterHeroPartyEvent( HeroRevivePeriodEnded, TOnHeroPartyEvent(@this.TE2_OnKilled_AvatarLose), "", m_iPlayerFaction);
			Autosave();
			return true;
		}

		bool TE2_OnSectorOwnerChange_PlayerCapital(Sector@ _Sector, const uint8 _uPreviousOwnerFaction, const uint8 _uNewOwnerFaction)
		{
			if( _uPreviousOwnerFaction == m_iPlayerFaction)
			{
				m_Reference.LoseGame(m_iPlayerFaction);
			}
			return true;
		}

		bool TE2_OnDestroyed_LeonidarMainSector( Building& in _Building )
		{
			m_Reference.LoseGame(3); // Leonidar AI
			return true;
		}


		// --- OTHER EVENTS ----------------------------------------------------------------------------------------------
		bool TE2_OnResurrected_UnarmedPrisoners(Creature& in _Creature)
		{
			//string _stgTmp = "";
			//if( ! _Creature.GetEquipment(PrimaryHand, _stgTmp))
			//{
			printNote("an unarmed prisoner revived");
			m_arrUintTE2_UnarmedPrisonerIDs.insertLast(_Creature.GetId());
			m_Reference.RegisterCreatureEventByIndividual(Killed, TOnCreatureEvent(@this.TE2_OnKilled_UnarmedPrisoners), _Creature.GetDescriptionName(), "");
			//}
			int _iPrisoners = m_arrUintTE2_UnarmedPrisonerIDs.length();
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE2_FreedPrisoners", _iPrisoners);
			//else
			//{
			//	printNote("an armed prisoner revived");
			//	return true;
			//}
			return false;
		}

		bool TE2_OnLoot_CellKey( const uint8 _uPlayerFaction, const string&in _sItemName, const uint _uAmount )
		{
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_01_Prisoners", "P4_SQ21_01_FindKey", Completed);
			return true;
		}


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

	void TE2_Articy_HelpFleeingPrisoner()
	{
		m_Reference.ActivateSpawn("TE2_SP_GuardsHunt01", true);
		CreatureGroup _grp = CreatureGroup(m_Reference, m_Reference.GetCreaturesFromSpawn("TE2_SP_GuardsHunt01"));
		_grp.AttackPosition(m_Reference.GetLogicObjectByName("TE2_Marker_PlayerBaseRuin"), false, false);
		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE2_OnKilled_PurityAttack), _grp.GetCreatures(), false, "");
	}

	bool TE2_OnTimer_PurityAttack()
	{
		CreatureGroup _grp = CreatureGroup(m_Reference, m_Reference.GetCreaturesFromSpawn("TE2_SP_GuardsHunt01"));
		_grp.AttackPosition(m_Reference.GetLogicObjectByName("TE2_Marker_PlayerBaseRuin"), false, false);
		return true;
	}

	void Articy_TE2_FleeingPrisonerJoins()
	{
		m_Reference.GetCreatureByName("TE2_Fleeing_Prisoner").SetFaction(m_iPlayerFaction);
	}

	void TE2_Articy_GiveStaffToFleeingPrisoner()
	{
		print("[SCRIPT] NOTE: Wow what a fancy staff :O");
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems("Battlestaff_Q0", 1);
	}

	void TE2_Articy_GetTeleportPowder()
	{
		print("[SCRIPT] NOTE: Received teleport powder");
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("TE2_TeleportPowder", 1);
		if( m_bTE2_DeserterDied || m_bTE2_DeserterSaved )
			DialogShoutoutTimed ( m_stgAvatar, m_stgAvatar, "TE2_26_SO_Deserter", false, 10 );
	}

	void TE2_Articy_SendFisherToCastle()
	{
		print("[SCRIPT] NOTE: The fisherman helps you now");
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems("TE2_TeleportPowder", 1);
		m_Reference.GetWorld().EnableDialogueTopic("TE2_Fisherman", "TE2_18_FirstContact" ,false);
		m_Reference.GetCreatureByName("TE2_Fisherman").FollowPath(m_Reference, "TE2_Path_FisherIntoHouse", true, false);
		m_Reference.RegisterCreatureEventByIndividual( FollowPathFinished, TOnCreatureEvent(@this.TE2_OnFollowPathFinished_FisherInsideHouse), "TE2_Fisherman", "TE2_Path_FisherIntoHouse");
	}

	void TE2_Articy_TeleportHeroGroupToCastle()
	{
		print("[SCRIPT] NOTE: the mage should teleport you into the castle");
		PlayerHeroControlDisable();
		m_Reference.FadeToBlackAndBack(m_iPlayerFaction, uint8(-1), 1000, 1000);
		m_Reference.SetTimer(TOnTimerEvent(@this.TE2_OnTimer_SetHeropartyPos), 1);
		m_Reference.SetTimer(TOnTimerEvent(@this.TE2_OnTimer_PrepareTeleport), 3);
	}

	bool TE2_OnTimer_SetHeropartyPos()
	{
		/*m_Reference.HeroPartyTeleport("TE2_TeleportSpot");
		if(m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02").length() != 0 && m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02")[0].GetFaction() == m_iPlayerFaction && m_bTE2_EscapeesAtMage )
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02").length(); i++)
				m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02")[i].Teleport(m_Reference, m_Reference.GetLogicObjectByName("TE2_TeleportSpot"));
		}*/
		return true;
	}

	bool TE2_OnTimer_PrepareTeleport()
	{
		//m_Reference.HeroPartyTeleport("TE2_TeleportSpot");
		m_Reference.GetCreatureByName("TE2_OldMageRebel").ForceCast(m_Reference, "Cutscene_TeleportTargetGroupFake", m_Reference.GetCreatureByName(m_stgAvatar), false);
		m_Reference.RegisterCreatureEventByIndividual(Damaged, TOnCreatureEvent(@this.TE2_OnDamage_Avatar), m_stgAvatar, "");
		//m_Reference.RegisterHeroPartyEvent(HeroRevivePeriodEnded, TOnCreatureEvent(@this.TE2_OnHeroReviveEnded_Avatar), m_stgAvatar, m_iPlayerFaction);
		
		m_Reference.SetTimer(TOnTimerEvent(@this.TE2_OnTimer_TeleportCastle), 2);

		return true;
	}

	bool TE2_OnTimer_TeleportCastle()
	{
		HeroPartyTeleport("TE2_Spot_TeleportCastle");
		if(m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02").length() != 0 && m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02")[0].GetFaction() == m_iPlayerFaction && m_bTE2_EscapeesAtMage )
		{
			for(uint i = 0; i < m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02").length(); i++)
				m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02")[i].Teleport(m_Reference, m_Reference.GetLogicObjectByName("TE2_Spot_TeleportCastle"));
		}
		m_Reference.GetLogicObjectByName("TE2_PortalEffect").Enable(true);
		m_Reference.GetLogicObjectByName("TE2_Switch_Portal").Enable(true);
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE2_OnInteract_Portal), "TE2_Switch_Portal", m_iPlayerFaction);
		PlayerHeroControlEnable();
		m_Reference.FocusCamera(m_iPlayerFaction, m_Reference.GetLogicObjectByName("TE2_Spot_TeleportCastle"));
		return true;
	}


	bool TE2_OnInteract_Portal(Creature& in _Creature)
	{
		_Creature.Teleport(m_Reference, m_Reference.GetLogicObjectByName("TE2_Spot_TeleportCastle"));
		return false;
	}

	void TE2_Articy_TurnEscapeesHostile()
	{
		DialogShoutout("TE2_Escapee_02", "TE2_Escapee_02", "TE2_10_SO_Combat", false);
		SetFactionSpawn("TE2_SP_Rebels02", m_iFaction_EscapeeHostile);
		m_Reference.RegisterCreatureEventByIndividuals(Damaged, TOnCreatureEvent(@this.TE2_OnDamage_Escapees), m_Reference.GetCreaturesFromSpawn("TE2_SP_Rebels02"), true);
	}

	void TE2_Articy_KillDeserter()
	{
		m_Reference.SetFactionRelation (m_iFaction_EscapeeHostile, m_iPlayerFaction, Neutral);
		m_Reference.GetCreatureByName("TE2_Deserter").AllowAttacks(false);
		SetFactionSpawn("TE2_SP_Rebels02", m_iFaction_EscapeeHostile);
		m_Reference.GetCreatureByName("TE2_Escapee_01").Attack(m_Reference, m_Reference.GetCreatureByName("TE2_Deserter"), false);
		DialogShoutout("TE2_Deserter", "TE2_Deserter", "TE2_06_SO_Scream", false);
		m_Reference.RegisterCreatureEventByIndividual(Damaged, TOnCreatureEvent(@this.TE2_OnDamage_Deserter), "TE2_Deserter", "");
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_HouseLeonidar", "P4_Q21_AskDeserter", Failed);
	}

	void TE2_Articy_EscapeesJoin()
	{
		print("[SCRIPT] NOTE: The escapees join you");
		SetFactionSpawn("TE2_SP_Rebels02", m_iPlayerFaction);
	}

	void TE2_Articy_SendDeserterToCastle()
	{
		print("[SCRIPT] NOTE: The deserter moves out to the castle");
		m_Reference.GetHeroParty(m_iPlayerFaction).RemoveItems("TE2_TeleportPowder", 1);
		m_Reference.GetCreatureByName("TE2_Deserter").GoTo(m_Reference, m_Reference.GetLogicObjectByName("TE2_Spot_CastleEntrance"), 3, 5, false);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_DeserterAtCastleEntrance), "TE2_Deserter", "TE2_Trigger_CastleEntrance");
		m_Reference.RegisterHeroPartyEvent(AllCannotSee, TOnHeroPartyEvent(@this.TE2_OnCanNotSee_Deserter), "TE2_Deserter", m_iPlayerFaction);
		m_Reference.GetWorld().EnableDialogueTopic("TE2_Deserter", "TE2_12_Saved", false);
		SpawnAttackable("TE2_SP_LeonidarDeserter01", false);
	}

	void TE2_Articy_FreePrisoner_01()
	{
		print("[SCRIPT] NOTE: Prisoner 01 freed");
	}

	void TE2_Articy_FreePrisoner_02()
	{
		print("[SCRIPT] NOTE: Prisoner 02 freed");
	}

	void TE2_Articy_FreePrisoner_03()
	{
		print("[SCRIPT] NOTE: Prisoner 03 freed");
	}

	void TE2_Articy_KeyGuardHelping()
	{
		print("[SCRIPT] NOTE: Key guard scared");
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("TE2_PrisonerCellKey_01", 1);
	}

	void TE2_Articy_KeyGuardHostile()
	{
		print("[SCRIPT] NOTE: Key guard angry");
		m_Reference.SetFactionRelation(9, m_iPlayerFaction, Hostile); // Set
	}

	void TE2_Articy_DeserterJoins()
	{
		print("[SCRIPT] NOTE: Deserter becomes a member of your party");
		m_Reference.GetCreatureByName("TE2_Deserter").SetFaction(m_iPlayerFaction);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_DeserterAtKeyGuard), "TE2_Deserter", "TE2_Trigger_Range_KeyGuard");
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_DeserterLeavesKeyGuard), "TE2_Deserter", "TE2_Trigger_Range_KeyGuard");
		m_Reference.GetHeroParty(m_iPlayerFaction).AddItems("TE2_PrisonerCellKey_01", 1);
		SpawnAttackable("TE2_SP_LeonidarDeserter01", true);
	}

	void TE2_Articy_AmariaHostile()
	{
		print("[SCRIPT] NOTE: Key guard angry");
		m_Reference.SetFactionRelation( m_iPlayerFaction, m_iFaction_Amaria, Hostile);
		m_bTE2_FightingWithAmaria = true;
	}

	void TE2_Articy_SpawnLeonidarCommander()
	{
		print("[SCRIPT] NOTE: The commander appears");
		//play a cutscene right here
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE2_OnCutsceneFinished_LeonidarCommander), m_iPlayerFaction);
		m_Reference.PlayCutScene("TE2_Cutscene_SpawnLeonidarCommander");
	}

	bool TE2_OnCutsceneFinished_LeonidarCommander( const uint8 _uPlayerFaction )
	{
		DialogShoutout("TE2_Leonidar_Commander", "TE2_Leonidar_Commander", "TE2_54_Commander", true);
		PlayerHeroControlDisable();
		return true;
	}

	void TE2_Articy_TraderShowStock()
	{
		print("[SCRIPT] NOTE: The Trader opens his coat...");
		m_Reference.GetCreatureByName("TE2_Bathum_Trader").EnableTrade(true);
	}

	void TE2_Articy_WinGame()
	{
		print("[SCRIPT] NOTE: The commander appears");
		PlayerHeroControlEnable();
		Autosave();
		EnableWorldMap( true );
		// DISABLE THE BARRIER
		m_Reference.EnableGroup("TE2_MagicCastleBarrier", false);
		m_Reference.BlockNavMesh("TE2_PhysicBlocker_IslandGate", false);

		for( uint i = 0; i < m_arrStg_PrisonCellsWithPrisoners.length(); i++)
		{
			m_Reference.GetLogicObjectByName( m_arrStg_PrisonCellsWithPrisoners[i]).Enable(false);
		}
		m_Reference.GetCreatureByName( "TE2_Prisoner").Enable(false);
		m_Reference.GetCreatureByName( "TE2_Prisoner_02").Enable(false);
		m_Reference.GetCreatureByName( "TE2_Prisoner_03").Enable(false);

		if( m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P4_SQ21_01_Prisoners") )
			m_Reference.GetJournal(m_iPlayerFaction).SetQuestState("P4_SQ21_01_Prisoners", Failed);

		if( m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P4_SQ21_02_TheDeserter") )
			m_Reference.GetJournal(m_iPlayerFaction).SetQuestState("P4_SQ21_02_TheDeserter", Failed);

		m_Reference.GetCreatureByName("TE2_Deserter").Enable(false);
		m_Reference.GetCreatureByName("TE2_Escapee_01").Enable(false);
		m_Reference.GetCreatureByName("TE2_Escapee_02").Enable(false);
		//m_Reference.WinGame(m_iPlayerFaction);
	}

	bool TE2_OnTrigger_CommanderAtPit(Creature& in _Creature)
	{
		DialogShoutout("TE2_Leonidar_Commander", "TE2_Leonidar_Commander", "TE2_SO_Tahar", true);
		return true;
	}

	bool TE2_OnInteract_Commander(Creature& in _Creature)
	{
		m_Reference.RegisterCreatureEventByIndividual( CanSee, TOnCreatureEvent(@this.TE2_OnCanSee_DeserterSeesAvatar), "TE2_Deserter", m_stgAvatar);
		if(m_bTE2_DeserterSeesAvatar)
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE2_Leonidar_Commander", "C6EBDA49");
			m_Reference.GetWorld().BlockDialogueTopicNode("TE2_Leonidar_Commander", "FE904F77");
		}
		if( m_Reference.GetSectorsByOwner(m_iFaction_HouseLeonidarAI).length() == 0 )
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE2_Leonidar_Commander", "590C06DA");
			m_Reference.GetWorld().BlockDialogueTopicNode("TE2_Leonidar_Commander", "126F924A");
		}
		m_bTE2_DeserterSeesAvatar = false;
		return false;
	}

	// -------------------------------------------------------------------------------------------------------------------
	// --- C U T S C E N E  F U N C T I O N S ----------------------------------------------------------------------------
	void EY02_Cutscene_CommanderArriving_EnableCommander()
	{
		m_Reference.ActivateSpawn("TE2_SP_LeonidarCommander", true);
		m_Reference.GetCreatureByName("TE2_Leonidar_Commander").Enable(true);
		m_Reference.GetCreatureByName("TE2_Leonidar_Commander").SetFaction(kFactionNeutral);
		m_Reference.LoseGame(2);
		m_Reference.GetCreatureByName("TE2_Leonidar_Commander").GoTo(m_Reference, m_Reference.GetCreatureByName(m_stgAvatar), 5, 8, false);
			//This could be done smoother via articy
	//	m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE2_OnTrigger_CommanderAtPit), "TE2_Leonidar_Commander", "TE2_Trigger_AmariaFight");
		m_bTE2_DeserterSeesAvatar = false;
			//This could be done smoother via articy
		m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE2_OnInteract_Commander), "TE2_Leonidar_Commander", m_iPlayerFaction);
		SpawnAttackable("TE2_SP_LeonidarCommander", false);
	}

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

	bool CheckSpawnDead( string _strgSpawn )
	{
		array<Creature> _ArrSpawn = m_Reference.GetCreaturesFromSpawn( _strgSpawn );
		printNote("Creature died " + _ArrSpawn.length() + " left" );
		if( _ArrSpawn.length() == 0 || (_ArrSpawn.length() == 1 && _ArrSpawn[0].GetCurrentHP() <= 0))
		{
			return true;
		}
		return false;
	}

	bool ArrayContainsCreatureID( array<uint> _CreatureIDs, uint _id )
	{
		for( uint i = 0; i < _CreatureIDs.length(); i++ )
		{
			if(_CreatureIDs[i] == _id)
				return true;
		}
		return false;
	}

	void DisableAI()
	{
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanControlUnits ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanControlHeroes ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanControlBuildings ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanControlProduction ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanAttack ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanScout ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanExpand ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanBuild ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanUpgradeBuildings ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanManageWorkers ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanProduceUnits ,false);
		m_Reference.SetAIFlag(m_iFaction_HouseLeonidarAI, CanUpgradeUnits ,false);
		CreatureGroup _GrpAIUnits = CreatureGroup(m_Reference, m_Reference.FindCreaturesByFaction(m_iFaction_HouseLeonidarAI));

		_GrpAIUnits.Move( m_Reference.GetLogicObjectByName( "TE2_Spot_AICapital"));
	}

	void RandomShoutout_AlarmedGuard( Creature _alarmedGuard)
	{
		int _rand = m_Reference.GetRandom().GetInteger(0,4);
			switch(_rand)
			{
				case 0:
					DialogShoutout("TE2_AlarmGuard", "TE2_AlarmGuard", "TE2_20_Alerted_1", false);
					break;
				case 1:
					DialogShoutout("TE2_AlarmGuard", "TE2_AlarmGuard", "TE2_21_Alerted_2", false);
					break;
				case 2:
					DialogShoutout("TE2_AlarmGuard", "TE2_AlarmGuard", "TE2_23_Alerted_3", false);
					break;
				case 3:
					DialogShoutout("TE2_AlarmGuard", "TE2_AlarmGuard", "TE2_24_Alerted_4", false);
					break;

				default: break;
			}
	}


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

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

	// ----------------------------------------------------
	// ----------------- T R I G G E R --------------------
	// ----------------------------------------------------
	// party banter at the start of the map
	bool EY3_OnAnyInside_Trg_12_BN_Banter(Creature& in _Creature)
	{
		printNote("12_BN_Banter start");
		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_12_BN_Banter", false); // no banter cause bugged
		return true;

	}

	// guard trigger, either block(make player run back), or SO for heading out
	bool EY3_OnAnyInside_Trg_GuardBlock01(Creature& in _Creature)
	{

		if(!m_bCanGetThroughGuardBlock01)
		{
			printNote("TE3_02A_SO_NoGettingThrough start, blocking player");
			DialogShoutout("TE3_Myrah_Guard_01", "TE3_Myrah_Guard_01", "TE3_02A_SO_NoGettingThrough", true);
			return false;
		}
		else
		{
			printNote("TE3_04B_SO_HeadingOut start, letting player through");
			DialogShoutout("TE3_Myrah_Guard_01", "TE3_Myrah_Guard_01", "TE3_04B_SO_HeadingOut", true);

			return true;
		}
	}

	// guard trigger, either block(make player run back), or SO for heading out
	bool EY3_OnAnyInside_Trg_GuardBlock02(Creature& in _Creature)
	{

		if(!m_bCanGetThroughGuardBlock01)
		{
			printNote("TE3_02A_SO_NoGettingThrough start, blocking player");
			DialogShoutout("TE3_Myrah_Guard_02", "TE3_Myrah_Guard_02", "TE3_02A_SO_NoGettingThrough", true);
			return false;
		}
		else
		{
			printNote("TE3_04B_SO_HeadingOut start, letting player through");
			DialogShoutout("TE3_Myrah_Guard_02", "TE3_Myrah_Guard_02", "TE3_04B_SO_HeadingOut", true);

			return true;
		}
	}

	// Recap SO after player moves out of camp
	bool EY3_OnAnyInside_Trg_TE3_04A_SO_Recap(Creature& in _Creature)
	{
		if(!m_bRecapSO){
			printNote("TE3_04A_SO_Recap");
			DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_04A_SO_Recap", true);
			m_bRecapSO = true;
		}
		return true;
	}

	// soldier at castle that cries for help
	bool EY3_OnAnyInside_Trg_Hallit_Soldier_01(Creature& in _Creature)
	{
		printNote("EY3_OnAnyInside_Trg_Hallit_Soldier_01");

		DialogShoutout("TE3_Hallit_Soldier_01", "TE3_Hallit_Soldier_01", "TE3_25_SO_Wulfgar_Soldier_Help", true);

		return true;
	}

	// when castle is cleared, a small SO is triggered on top
	bool EY3_OnAnyInside_Trg_SO_Eerie(Creature& in _Creature)
	{
		printNote("EY3_OnAnyInside_Trg_SO_Eerie start");
		if(m_iNumUndeadGroupsLeft > 0)
		{
			return false;
		}
		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_13_SO_Eerie", true);

		return true;
	}

	// cutscene?
	// player left wulfgar camp towards N, spawn ulric there
	bool EY3_OnAnyInside_Trg_NorthernUlricSpawn(Creature & in _Creature)
	{
		if(m_bTalkedToSheyn && m_bHasNotMetUlric)
		{
			printNote("Spawn Ulric Wulfgar north");
			m_Reference.PlayCutScene("TE3_10_DiscussionAboutWulfgar_North");
			m_Reference.GetCreatureByName("Ulric_Wulfgar").Enable(true);
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.EY3_OnCutsceneFinished_DiscussionAboutWulfgar), m_iPlayerFaction);

			m_bHasNotMetUlric = false;
			return true;
		}

		return false;
	}

	// cutscene?
	// player left wulfgar camp towards SW, spawn ulric there
	bool EY3_OnAnyInside_Trg_SouthernUlricSpawn(Creature& in _Creature)
	{
		if(m_bTalkedToSheyn && m_bHasNotMetUlric)
		{
			printNote("Spawn Ulric Wulfgar south");
			m_Reference.PlayCutScene("TE3_10_DiscussionAboutWulfgar_South");
			m_Reference.GetCreatureByName("Ulric_Wulfgar").Enable(true);
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.EY3_OnCutsceneFinished_DiscussionAboutWulfgar), m_iPlayerFaction);

			m_bHasNotMetUlric = false;
			return true;
		}

		return false;
	}

	// cutscene?
	// player left wulfgar camp towards SW, spawn ulric there
	bool EY3_OnAnyInside_Trg_WesternUlricSpawn(Creature& in _Creature)
	{
		if(m_bTalkedToSheyn && m_bHasNotMetUlric)
		{
			printNote("Spawn Ulric Wulfgar west");
			m_Reference.PlayCutScene("TE3_10_DiscussionAboutWulfgar_West");
			m_Reference.GetCreatureByName("Ulric_Wulfgar").Enable(true);
			m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.EY3_OnCutsceneFinished_DiscussionAboutWulfgar), m_iPlayerFaction);

			m_bHasNotMetUlric = false;
			return true;
		}

		return false;
	}

	bool EY3_OnAnyInside_Trg_Weyland_Hallit(Creature& in _Creature)
	{
		printNote("player faces guard to hallit camp");

		DialogShoutout("TE3_Hallit_Guard", "TE3_Hallit_Guard", "TE3_22_Hallit_Guard_01", true);
		m_Reference.GetWorld().EnableDialogueTopic("TE3_Hallit_Guard", "TE3_23_SO_Hallit_Guard", true);

		return true;
	}

	bool EY3_OnAnyInside_EY3_Trg_Wulfgar_Guard01(Creature& in _Creature)
	{
		printNote("player faces guard to wulfgar camp");
		if(!m_bTE3_Wulfgar_Pass)
		{
			m_bTE3_Wulfgar_Pass = true;
			DialogShoutout("TE3_Wulfgar_Guard_01", "TE3_Wulfgar_Guard_01", "TE3_05_YouMayPass", true);
		}
		return true;
	}


	bool EY3_OnAnyInside_EY3_Trg_Wulfgar_Guard02(Creature& in _Creature)
	{
		printNote("player faces guard to wulfgar camp");
		if(!m_bTE3_Wulfgar_Pass)
		{
			m_bTE3_Wulfgar_Pass = true;
			DialogShoutout("TE3_Wulfgar_Guard_02", "TE3_Wulfgar_Guard_02", "TE3_05_YouMayPass", true);
		}
		return true;
	}

	bool EY3_OnAnyInside_EY3_Trg_Wulfgar_Guard03(Creature& in _Creature)
	{
		printNote("player faces guard to wulfgar camp");
		if(!m_bTE3_Wulfgar_Pass)
		{
			m_bTE3_Wulfgar_Pass = true;
			DialogShoutout("TE3_Wulfgar_Guard_03", "TE3_Wulfgar_Guard_03", "TE3_05_YouMayPass", true);
		}
		return true;
	}


	bool EY3_OnAnyInside_Trg_SheynSecretMeeting(Creature& in _Creature)
	{

		if(m_bSecretMeetingWithSheyn)
		{
			printNote("Teleport sheyn to secret meeting position");
			// cutscene?
			m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_19_SecretMeeting", true);
			m_Reference.GetCreatureByName("Sheyn_Wulfgar").Teleport(m_Reference, m_Reference.GetLogicObjectByName("EY3_Mrk_SheynMeeting"));
			//m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "_sTaskName", Completed);
			return true;
		}

		return false;
	}

	bool EY3_OnAnyInside_Trg_SO_MyrahCamp(Creature& in _Creature)
	{
		printNote("SO before myrah camp");
		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_01C_SO_ThatsTheCamp", false);

		return true;
	}

	bool EY3_OnAnyInside_Trg_SO_ThatsShyen(Creature& in _Creature)
	{
		printNote("SO before meeting Sheyn");
		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_07A_SO_ThatsSheyn", false);

		return true;
	}

	// village encounter
	bool EY3_OnAnyInside_Trg_VillageEncounter(Creature& in _Creature)
	{
		printNote("start village encounter");

		if(!m_bStartedVillageEncounter)
		{
			m_Reference.ActivateSpawn("EY3_Spawn_VillageAbomination", true);
			m_Reference.ActivateSpawn("EY3_Trg_VillageSurvivor", true);

			DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_28_SO_ArchfireBeasts", false);

			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_03_Hospitality", "P4_SQ21_03_Hospitality_Investigate", Completed );
			
			m_bStartedVillageEncounter = true;
			return false;
		}

		if(!IsSpawnAlive("EY3_Spawn_VillageAbomination"))
		{
			DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_32_SO_AfterVillageScene", false);
			return true;
		}

		return false;
	}

	// final trigger to start the meeting once player has finished all the tasks
	bool EY3_OnAllInside_Sector_StartConclave(Creature& in _Creature)
	{
		if(m_bSheynAtMeeting && m_bWeylandAtMeeting && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed)
		{
			Conclave();
			return true;
		}
		printNote("Condition failed Sheyn: " + m_bSheynAtMeeting + " Weyland: " + m_bWeylandAtMeeting);

		return false;
	}

	void Conclave()
	{
		printNote("all done; start the conclave now. player chose to poison weyland?" + m_bPoisenedWeyland);
		m_Reference.PlayCutScene("TE3_40_Conclave");
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_40_Conclave), m_iPlayerFaction);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_StartConclave", Completed);
		if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_PoisonHallit") != Completed )
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_PoisonHallit", Failed);
	}

	// ----------------------------------------------------
	// ----------------- K I L L --------------------------
	// ----------------------------------------------------

	// "story" trigger for guard help SO
	bool EY3_OnKilled_Spawn_UndeadMisc(Creature& in _Creature)
	{
		printNote("EY3_OnKilled_Spawn_UndeadMisc");
		if(IsSpawnAlive("EY3_Spawn_UndeadMisc"))
		{
			return false;
		}
		if(m_bHasWeylandUndeadQuest)
		{
			m_Reference.GetWorld().BlockDialogueTopicNode("TE3_Hallit_Soldier01", "B968CC98");
			m_Reference.GetWorld().UnblockDialogueTopicNode("TE3_Hallit_Soldier01", "F82D1053");
		}

		DialogTalkTo("TE3_Hallit_Soldier_01", m_stgAvatar, "TE3_Hallit_Soldier_01", "TE3_26_Wulfgar_Soldier_Thanks");


		return true;
	}

	bool EY3_OnKilled_Spawn_Undead(Creature & in _Creature)
	{
		if(m_iNumUndeadGroupsLeft > 0)
		{
			printNote("Undead castle mob killed");
			m_iNumUndeadGroupsLeft--;
			return false;
		}
		else
		{
			printNote("Undead castle groups cleared");
			// enable proper dialogue for weyland marriage talk
			m_Reference.GetWorld().BlockDialogueTopicNode("Weyland_Hallit", "90FCE317");
			m_Reference.GetWorld().UnblockDialogueTopicNode("Weyland_Hallit", "E58709CF");
			m_bClearedCastle = true;
			return true;
		}
	}

	bool EY3_OnKilled_Undead01(Creature& in _Creature)
	{
		if( !ArrayContainsCreatureID( m_arrUIntTE3_KilledUndeadIDs, _Creature.GetId()) )
		{
			m_arrUIntTE3_KilledUndeadIDs.insertLast(_Creature.GetId());
			m_iTE3_KilledUndead++;
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE3_UndeadKilled", m_iTE3_KilledUndead);
			printNote("Undead in array 1" + m_arrCrtTE3_Undead_01.length() );
			for( uint i = 0; i < m_arrCrtTE3_Undead_01.length(); i++)
			{
				if( m_arrCrtTE3_Undead_01[i] == _Creature )
				{
					m_arrCrtTE3_Undead_01.removeAt(i);
					break;
				}
			}
			if( m_arrCrtTE3_Undead_01.length() == 0 )
			{
				printNote("Undead #1 cleared");
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_Inv_ClearFortress_01", Completed);
				if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed && m_bSheynAtMeeting && m_bWeylandAtMeeting && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_Talk_to_Sheyn_Secret") == Completed )
				{
					m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_StartConclave", true);
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_StartConclave", Completed);
					m_Reference.PlayCutScene("TE3_40_Conclave");
					m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_40_Conclave), m_iPlayerFaction);
				}
				return true;
			}
		}
		return false;
	}

	bool EY3_OnKilled_Undead02(Creature& in _Creature)
	{
		if( !ArrayContainsCreatureID( m_arrUIntTE3_KilledUndeadIDs, _Creature.GetId()) )
		{
			m_arrUIntTE3_KilledUndeadIDs.insertLast(_Creature.GetId());
			m_iTE3_KilledUndead++;
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE3_UndeadKilled", m_iTE3_KilledUndead);

			for( uint i = 0; i < m_arrCrtTE3_Undead_02.length(); i++)
			{
				if( m_arrCrtTE3_Undead_02[i] == _Creature )
				{
					m_arrCrtTE3_Undead_02.removeAt(i);
					break;
				}
			}
			if( m_arrCrtTE3_Undead_02.length() == 0 )
			{
				printNote("Undead #2 cleared");
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_Inv_ClearFortress_02", Completed);
				if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed && m_bSheynAtMeeting && m_bWeylandAtMeeting && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_Talk_to_Sheyn_Secret") == Completed )
				{
					m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_StartConclave", true);
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_StartConclave", Completed);
					m_Reference.PlayCutScene("TE3_40_Conclave");
					m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_40_Conclave), m_iPlayerFaction);
				}
				return true;
			}
		}
		return false;
	}

	bool EY3_OnKilled_Undead03(Creature& in _Creature)
	{
		if( !ArrayContainsCreatureID( m_arrUIntTE3_KilledUndeadIDs, _Creature.GetId()) )
		{
			m_arrUIntTE3_KilledUndeadIDs.insertLast(_Creature.GetId());
			m_iTE3_KilledUndead++;
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE3_UndeadKilled", m_iTE3_KilledUndead);

			for( uint i = 0; i < m_arrCrtTE3_Undead_03.length(); i++)
			{
				if( m_arrCrtTE3_Undead_03[i] == _Creature )
				{
					printNote("Undead before removing: " + m_arrCrtTE3_Undead_03.length() );
					m_arrCrtTE3_Undead_03.removeAt(i);
					printNote("Removing one undead - undead left: " + m_arrCrtTE3_Undead_03.length() );
					break;
				}
			}
			if( m_arrCrtTE3_Undead_03.length() == 0 )
			{
				printNote("Undead #3 cleared");
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_Inv_ClearFortress_03", Completed);
				if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed && m_bSheynAtMeeting && m_bWeylandAtMeeting && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_Talk_to_Sheyn_Secret") == Completed )
				{
					m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_StartConclave", true);
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_StartConclave", Completed);
					m_Reference.PlayCutScene("TE3_40_Conclave");
					m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_40_Conclave), m_iPlayerFaction);
				}
				return true;
			}
		}
		return false;
	}

	bool EY3_OnKilled_Undead04(Creature& in _Creature)
	{
		if( !ArrayContainsCreatureID( m_arrUIntTE3_KilledUndeadIDs, _Creature.GetId()) )
		{
			m_arrUIntTE3_KilledUndeadIDs.insertLast(_Creature.GetId());
			m_iTE3_KilledUndead++;
			m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.TE3_UndeadKilled", m_iTE3_KilledUndead);

			for( uint i = 0; i < m_arrCrtTE3_Undead_04.length(); i++)
			{
				if( m_arrCrtTE3_Undead_04[i] == _Creature )
				{
					printNote("Undead before removing: " + m_arrCrtTE3_Undead_04.length() );
					m_arrCrtTE3_Undead_04.removeAt(i);
					printNote("Removing one undead - undead left: " + m_arrCrtTE3_Undead_04.length() );
					break;
				}
			}
			if( m_arrCrtTE3_Undead_04.length() == 0 )
			{
				printNote("Undead #4 cleared");
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_Inv_ClearFortress_04", Completed);
				if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed && m_bSheynAtMeeting && m_bWeylandAtMeeting && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_Talk_to_Sheyn_Secret") == Completed )
				{
					m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_StartConclave", true);
					m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_StartConclave", Completed);
					m_Reference.PlayCutScene("TE3_40_Conclave");
					m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_40_Conclave), m_iPlayerFaction);
				}
				return true;
			}
		}
		return false;
	}

	// when quest wyvern dies
	bool EY3_OnKilled_Spawn_Wyvern(Creature& in _Creature)
	{
		printNote("player killed quest wyvern");
		_Creature.DropItem(m_Reference, "TE3_WyvernTeeth", 1);

	/*	if(!m_bAcceptedUlricWyvernQuest)
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode("Ulric_Wulfgar", "760D894B");
			m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "01AA54D2");
			m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "C8B85653");
		}
		else
		{
			m_Reference.GetWorld().EnableDialogueTopic("Ulric_Wulfgar", "TE3_14_SO_Wyvern", true);
			m_Reference.GetWorld().EnableDialogueTopic("Ulric_Wulfgar", "TE3_11_SO_KillWyvern", false);
		} */
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_KillWyvern", Completed);
		return true;
	}

	bool TE3_OnLoot_WyvernTeeth (const uint8 _uPlayerFaction, const string&in _sItemName, const uint _uAmount)
	{
		if(!m_bAcceptedUlricWyvernQuest)
		{
			m_Reference.GetWorld().UnblockDialogueTopicNode("Ulric_Wulfgar", "760D894B");
			m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "01AA54D2");
			m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "C8B85653");
		}
		else
		{
			m_Reference.GetWorld().EnableDialogueTopic("Ulric_Wulfgar", "TE3_14_SO_Wyvern", true);
			m_Reference.GetWorld().EnableDialogueTopic("Ulric_Wulfgar", "TE3_11_SO_KillWyvern", false);
		}
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_LootWyvern", Completed);
		return true;
	}


	// abominations in vilalge have spawned
	bool EY3_OnKilled_Spawn_VillageAbomination(Creature& in _Creature)
	{
		printNote("killed abomination, playing SO");

		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_03_Hospitality", "P4_SQ21_03_Hospitality_Abominations", Completed );

		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_29_AbominationsKilled", false);

		return true;
	}

	// -------------------------------------------------
	// ----------- I N T E R A C T ---------------------
	// -------------------------------------------------
	bool TE3_OnInteract_SO_Barrier(Creature& in _Creature)
	{
		if( m_bTE3_BarrierSO )
			return true;
		DialogShoutout( m_stgAvatar, m_stgAvatar, "TE3_46_SO_Barrier", false );
		m_bTE3_BarrierSO = true;
		m_Reference.EnableGroup("EY3_Grp_Switch_Gates", false);
		return true;
	}

	// player clicked on switch to poison weyland
	bool EY3_OnInteract_Switch_PoisonWeyland(Creature& in _Creature)
	{
		if(m_bSheynAtMeeting)
		{
			printNote("player decided to poison weyland");
			DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_InitPoison", true);
			m_Reference.RegisterCreatureEventByIndividual(LeftArea, TOnCreatureEvent(@this.TE3_OnTriggerLeave_PoisonArea), m_stgAvatar, "TE3_Trigger_PoisonArea");
			//TE3_PoisonWeyland();

		}
		return true;
	}

	bool TE3_OnTriggerLeave_PoisonArea(Creature& in _Creature)
	{
		m_Reference.GetCreatureByName(m_stgAvatar).CancelDialogue();
		return true;
	}


	bool EY3_OnCutsceneFinished_DiscussionAboutWulfgar(const uint8 _uPlayerFaction)
	{
		DialogTalkTo("Ulric_Wulfgar", m_stgAvatar, "Ulric_Wulfgar", "TE3_10B_FirstContact");

		return true;
	}


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

	// ---------------------------------------------------------
	// GENERAL


	void Articy_EnterWulfgarCamp()
	{
		m_Reference.BlockNavMesh("EY3_PhysicBlocker_Wulfgar_Guard_01", false);
		m_Reference.BlockNavMesh("EY3_PhysicBlocker_Wulfgar_Guard_02", false);
		m_Reference.BlockNavMesh("EY3_PhysicBlocker_Wulfgar_Guard_03", false);
	}
	// allow player to get past the gurad block
	void ArticyDisableGuardBlock01()
	{
		printNote("Enabling player to go through GuardBlock01");
		m_bCanGetThroughGuardBlock01 = true;

		m_Reference.EnableGroup("PhysicBlockerGuards", false);
		array <Entity> _entTmp = m_Reference.GetEntitiesInGroup( "PhysicBlockerGuards");
		for ( uint _iTmp = 0; _iTmp < _entTmp.length(); _iTmp++ )
		{
			m_Reference.BlockNavMesh( m_Reference.FindEntityName( _entTmp[_iTmp] ), false );
		}
	}

	void ArticyTE3_HelpHallitSolider()
	{
		if( !m_Reference.GetJournal(m_iPlayerFaction).IsTaskActive("P4_Q21_TheConclave", "P4_Q21_ClearFortress") && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") != Completed )
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_ClearFortress", true);
	}
	// ---------------------------------------------------------
	// WEYLAND STORY

	// angar keeps repeating his dialogue, so block it
	void ArticyTE3_03_General_BlockAngar()
	{
		printNote("blocking angar dialogue loop");
		m_Reference.GetWorld().BlockDialogueTopicNode("Myrah_Utran", "CFD5DC3E");
	}

	// general topic for myrah utran(marriage stuff)
	void ArticyWeylandMarriageProposal()
	{
		printNote("Player knows about weyland's marraige proposal, dialogue topic at myrah enabled");
		m_Reference.GetWorld().EnableDialogueTopic("Myrah_Utran", "TE3_03_General", true);

		if(m_bTalkedToSheyn)
		{
			m_Reference.GetWorld().BlockDialogueTopicNode(m_stgAvatar, "43DC7C9A");
			m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "B155473C");
		}

		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_27_Reflection", true);
	}

	// marriage topic for weyland(marriage stuff)
	void ArticyMyrahTalkMarriage()
	{
		printNote("Player talked to myrah about marraige, dialogue topic at weyland enabled");
		m_Reference.GetWorld().EnableDialogueTopic("Weyland_Hallit", "TE3_34_Marriage", true);

		DialogShoutout(m_stgAvatar, m_stgAvatar, "TE3_33_SO_AfterMyrah", true);
	}

	// player got task to clear castle with weyland's soldiers
	void ArticyWeylandQuest()
	{
		printNote("player got task to clear castle with weyland's soldiers");
		m_Reference.GetWorld().EnableDialogueTopic("Weyland_Hallit", "TE_37_SO_ClearOutTheCastle", true);
	}

	// Weyland joins the meeting
	void ArticyWeylandAtMeeting()
	{
		printNote("Weyland will now be at the meeting");
		m_bWeylandAtMeeting = true;
		Autosave();
		PlayerHeroControlEnable();
		if( m_bSheynAtMeeting && m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed )
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_StartConclave", true);
	}

	// player accepts to marry off myrah to weyland
	void ArticyWeylandMarriageAccepted()
	{
		printNote("Player agreed to marry off myrah");
		m_bMyrahMarried = true;

		// unblock in conclave dialogue myrah
		m_Reference.GetWorld().UnblockDialogueTopicNode("Sheyn_Wulfgar", "851C6F4C");
		m_Reference.GetWorld().BlockDialogueTopicNode("Sheyn_Wulfgar", "F895B411");

		if(!m_bPoisenedWeyland)
		{
			// unblock in aftertreason dialogue sheyn ulric spared
			m_Reference.GetWorld().UnblockDialogueTopicNode("Ulric_Wulfgar", "3E27CC33");
			m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "F0F71643");

			// unblock in aftertreason dialogue sheyn ulric killed
			m_Reference.GetWorld().UnblockDialogueTopicNode("Sheyn_Wulfgar", "8765A6E6");
			m_Reference.GetWorld().BlockDialogueTopicNode("Sheyn_Wulfgar", "AF5D87DE");
		}
	}

	// player declines to marry off myrah to weyland
	void ArticyWeylandMarriageDeclined()
	{
		printNote("Player declined to marry off myrah");
		m_bMyrahMarried = false;
	}

	// ---------------------------------------------------------
	// WULFGAR STORY

	// trigger to spawn ulric after leaving camp now
	void ArticySheynFirstContact_Finished()
	{
		printNote("Player finished first contact with Sheyn");
		m_bTalkedToSheyn = true;
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_08_SO_AreYouDeaf", true);

		m_Reference.GetWorld().BlockDialogueTopicNode(m_stgAvatar, "842118BC");
		m_Reference.GetWorld().UnblockDialogueTopicNode(m_stgAvatar, "192FF07B");

		DialogShoutoutTimed(m_stgAvatar, m_stgAvatar, "TE3_09_SO_AfterSheynTalk", false, 2);
	}

	// player got the quest to kill wyvern from ulric
	void ArticyAcceptedUlricWyvernQuest()
	{
		printNote("player got the quest to kill wyvern from ulric");
		m_Reference.GetWorld().EnableDialogueTopic("Ulric_Wulfgar", "TE3_11_SO_KillWyvern", true);
		m_bAcceptedUlricWyvernQuest = true;
	}

	// player gets asked to go to a private meeting with sheyn
	void ArticySecretSheynMeeting()
	{
		printNote("Player got asked for secret meeting with sheyn");
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_17_SO_SecretMeeting", true);
		m_bSecretMeetingWithSheyn = true;
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE3_OnTriggerEnter_SecretMeetingSheyn), m_stgAvatar, "TE3_Trg_SheynMeeting");
		DialogShoutoutTimed(m_stgAvatar, m_stgAvatar, "TE3_18_SO_SecretMeeting", true, 5);
	}

	bool TE3_OnTriggerEnter_SecretMeetingSheyn(Creature& in _Creature)
	{
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_17_SO_SecretMeeting", false);
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_19_SecretMeeting", true);
		m_Reference.RegisterCreatureEventByIndividual(EnteredSector, TOnCreatureEvent(@this.TE3_OnSectorEnter_SheynSecretMeeting), "Sheyn_Wulfgar", "Sector_12");
		m_Reference.GetCreatureByName("Sheyn_Wulfgar").Teleport(m_Reference, m_Reference.GetLogicObjectByName("TE3_Spot_SheynSecretArrival"));
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_SecretMeeting", Completed);
		return true;
	}

	bool TE3_OnSectorEnter_SheynSecretMeeting(Creature& in _Creature)
	{
		_Creature.GoTo(m_Reference, m_Reference.GetLogicObjectByName("EY3_Mrk_SheynMeeting"), 5, 10, false, false);
		return true;
	}

	// player had a secret meeting with Sheyn, sheyn will now be at the castle(once cleared) and player has the option to poison weyland
	void ArticySheynAtMeeting()
	{
		printNote("Secret meeting with sheyn done; player can now poison weyland; sheyn at meeting");
		m_bSheynAtMeeting = true;
		Autosave();
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_20_SO_YouKnowWhatToDo", true);
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_17_SO_SecretMeeting", false);
		m_Reference.GetLogicObjectByName("EY3_Switch_PoisonWeyland").SetInteractive(true);
		if( m_Reference.GetJournal(m_iPlayerFaction).GetTaskState("P4_Q21_TheConclave", "P4_Q21_ClearFortress") == Completed && m_bWeylandAtMeeting )
			m_Reference.GetJournal(m_iPlayerFaction).ActivateTask("P4_Q21_TheConclave", "P4_Q21_StartConclave", true);
	}

	// player killed the wyvern, can now talk to sheyn
	void ArticyOnUlricWulfgarDialogue_FinishWyvernQuest()
	{
		printNote("concluded wyvern quest, continuing with sheyn");
		// cutscene?
		//m_Reference.GetCreatureByName("Ulric_Wulfgar").Teleport(m_Reference, m_Reference.GetCreatureByName("Sheyn_Wulfgar"));
		m_Reference.GetCreatureByName("Ulric_Wulfgar").GoTo(m_Reference, m_Reference.GetCreatureByName("Sheyn_Wulfgar"), 5, 10, false, false);
		m_Reference.RegisterCreatureEventByIndividual(EnteredArea, TOnCreatureEvent(@this.TE3_OnTriggerEnter_UlricAtSheyn), "Ulric_Wulfgar", "EY3_Trg_SO_ThatsSheyn");
	}

	bool TE3_OnTriggerEnter_UlricAtSheyn(Creature& in _Creature)
	{
		DialogShoutout( "Ulric_Wulfgar", "Ulric_Wulfgar", "TE3_15_SO_WalkToSheyn", false );
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_16_WyvernKilled", true);
		m_Reference.GetWorld().EnableDialogueTopic("Sheyn_Wulfgar", "TE3_08_SO_AreYouDeaf", false);
		return true;
	}

	// conclave

	void ArticyConclaveAfterTreason()
	{
		printNote("ArticyConclaveAfterTreason");
		DialogShoutout("Ulric_Wulfgar", "Ulric_Wulfgar", "TE3_43_AfterTreason", true);
	}


	void ArticyConclaveConclusion()
	{
		TE3_Cutscene_Conclave_MyrahUlricNeutral();
		PlayerHeroControlDisable();
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutscenFinished_RTS), m_iPlayerFaction);
		m_Reference.PlayCutScene("TE3_RTSPreparations");
		
		//m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_ConclaveConcluded), m_iPlayerFaction);
	}

	bool TE3_OnCutscenFinished_RTS( const uint8 _uPlayerFaction )
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_Inv_HoldConclave", Completed);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Barracks", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Capital_I", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Capital_II", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Capital_III", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Expansion_0", 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_Expansion_III", 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_WoodenTower_III", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_StoneTower", true);

		m_Reference.GetWorld().UnlockBlueprint("BP_H_Farm", 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_IronMine", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_IronSmeltery", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Smith", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Academy", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_AriaCollector", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_AriaDestillery", true);

		m_Reference.GetWorld().UnlockBlueprint("BP_H_Pillager", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Recruit", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Soldier", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Helebardier", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Scout", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Marksman", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Armsman", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Mentalist", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Paladin", true);
		m_Reference.GetWorld().UnlockBlueprint("BP_H_Catapult", true);

		Autosave();
		
		return true;
	}

	void ArticySetWulfgarHostile()
	{
		printNote("player made wulfgar hostile");
		m_bWulfgarHostile = true;
	}

	//
	void ArticyOnSurvivorDialogue()
	{
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_SQ21_03_Hospitality", "P4_SQ21_03_Hospitality_TalkToSurvivor", Completed );
		m_Reference.GetWorld().EnableDialogueTopic("TE3_Survivor", "TE3_31_SO_LeaveMeAlone", true);
	}

	void ArticyPlayerHeroControlEnable()
	{
		PlayerHeroControlEnable();
	}

	void ArticyPlayerHeroControlDisable()
	{
		PlayerHeroControlDisable();
	}


	// -------------------------------------------------------------------------------------------------------------------
	// --- C U S T O M  F U N C T I O N S --------------------------------------------------------------------------------
	// if the player has accepted the rift quest from DO1, no monsters will spawn
	void TE3_CheckRifts()
	{
		// ensure spawns are activated
		if( !m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedFirstRift") && m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_MAP014_ElderRifts") )
		{
			m_Reference.EnableGroup("TE_RiftGate1", true);
			m_Reference.ActivateSpawn("EY3_Spawn_RiftMob03", true);
			m_Reference.ActivateSpawn("EY3_Spawn_RiftMob04", true);
		}
		else
		{
			m_Reference.EnableGroup("TE_RiftGate1", false);
		}

		if( !m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedSecondRift") && m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_MAP014_ElderRifts") ) 
		{
			m_Reference.EnableGroup("TE_RiftGate2", true);
			m_Reference.ActivateSpawn("EY3_Spawn_RiftMob02", true);
		}
		else
		{
			m_Reference.EnableGroup("TE_RiftGate2", false);
		}

		if( !m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedThirdRift") && m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_MAP014_ElderRifts") )
		{
			m_Reference.EnableGroup("TE_RiftGate3", true);
			m_Reference.ActivateSpawn("EY3_Spawn_RiftMob01", true);
		}
		else
		{
			m_Reference.EnableGroup("TE_RiftGate3", false);
		}

	  // ensure spawns are deactivated


	
	}



	// Open the gates (for RTS part)
	void TE3_OpenGates()
	{
		// disable navmesh blockers so player can walk through the gates
		//m_Reference.EnableGroup("EY3_GateBlocker", false);
		array <Entity> _entTmp = m_Reference.GetEntitiesInGroup( "EY3_GateBlocker" );
		for ( uint i = 0; i < _entTmp.length(); i++ )
		{
			m_Reference.BlockNavMesh( m_Reference.FindEntityName( _entTmp[i] ), false );
		}

		m_bTE3_BarrierSO = true;
		m_Reference.EnableGroup("EY3_Grp_Switch_Gates", false);

		// show open gates
		m_Reference.EnableGroup("TE3_LordWallGate_1_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_1_Closed", false);

		m_Reference.EnableGroup("TE3_LordWallGate_2_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_2_Closed", false);

		m_Reference.EnableGroup("TE3_LordWallGate_3_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_3_Closed", false);

		m_Reference.EnableGroup("TE3_LordWallGate_4_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_4_Closed", false);

		m_Reference.EnableGroup("TE3_LordWallGate_5_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_5_Closed", false);

		m_Reference.EnableGroup("TE3_LordWallGate_6_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_6_Closed", false);

		m_Reference.EnableGroup("TE3_LordWallGate_7_Open", true);
		m_Reference.EnableGroup("TE3_LordWallGate_7_Closed", false);
	}

	// Close gates (for RPG Part)
	void TE3_CloseGates()
	{
		// Enable navmesh blockers
		m_Reference.EnableGroup("EY3_GateBlocker", true);
		array <Entity> _entTmp = m_Reference.GetEntitiesInGroup( "EY3_GateBlocker");
		for ( uint _iTmp2 = 0; _iTmp2 < _entTmp.length(); _iTmp2++ )
		{
			m_Reference.BlockNavMesh( m_Reference.FindEntityName( _entTmp[_iTmp2] ), true );
		}

		// show closed gates
		m_Reference.EnableGroup("TE3_LordWallGate_1_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_1_Closed", true);

		m_Reference.EnableGroup("TE3_LordWallGate_2_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_2_Closed", true);

		m_Reference.EnableGroup("TE3_LordWallGate_3_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_3_Closed", true);

		m_Reference.EnableGroup("TE3_LordWallGate_4_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_4_Closed", true);

		m_Reference.EnableGroup("TE3_LordWallGate_5_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_5_Closed", true);

		m_Reference.EnableGroup("TE3_LordWallGate_6_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_6_Closed", true);

		m_Reference.EnableGroup("TE3_LordWallGate_7_Open", false);
		m_Reference.EnableGroup("TE3_LordWallGate_7_Closed", true);
	}

	// helper function to poison weyland from everywhere
	void TE3_PoisonWeyland()
	{
		printNote("Player chose to poison weyland");
		m_bPoisenedWeyland = true;
		m_Reference.GetLogicObjectByName("EY3_Switch_PoisonWeyland").Enable(false);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_PoisonHallit", Completed);
		// unblock in conclave dialogue
		m_Reference.GetWorld().UnblockDialogueTopicNode("Sheyn_Wulfgar", "E03A3E81");
		m_Reference.GetWorld().BlockDialogueTopicNode("Sheyn_Wulfgar", "4685F36C");

		// unblock in aftertreason dialogue
		m_Reference.GetWorld().UnblockDialogueTopicNode("Ulric_Wulfgar", "5FE5AB76");
		m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "00B7A3F7");

		// unblock in aftertreason dialogue death to ulric
		m_Reference.GetWorld().UnblockDialogueTopicNode("Ulric_Wulfgar", "B7DC61A2");
		m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "D89C7A26");

		// unblock in aftertreason dialogue spare ulric
		m_Reference.GetWorld().UnblockDialogueTopicNode("Ulric_Wulfgar", "8FED08D9");
		m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "D89C7A26");

		// make sure to block all alive dialogues
		m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "F0F71643");
		m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "3E27CC33");
		m_Reference.GetWorld().BlockDialogueTopicNode("Ulric_Wulfgar", "D89C7A26");
	}

	bool TE3_OnCutsceneEnd_TE3_40_Conclave(const uint8 _uPlayerFaction)
	{
		DialogShoutout("Sheyn_Wulfgar", "Sheyn_Wulfgar", "TE3_39_Conclave", true);
		PlayerHeroControlDisable();
		return true;
	}

	void Articy_TE3_PurityAttack()
	{
		m_Reference.PlayCutScene("TE3_41_PurityAttacks");
		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_41_PurityAttacks), m_iPlayerFaction);
	}

	void TE3_Cutscene_Conclave_FightStart()
	{
		printNote("fight in conclave starts");
		m_Reference.GetCreatureByName("Myrah_Utran").SetImmortal(true);
		m_Reference.GetCreatureByName("Ulric_Wulfgar").SetImmortal(true);
		m_Reference.GetCreatureByName("Sheyn_Wulfgar").SetImmortal(true);
		m_Reference.GetCreatureByName("Ulric_Wulfgar").SetImmovable(true);

		if(m_Reference.GetCreatureByName("Weyland_Hallit").GetCurrentHP() > 0)
		{
			m_Reference.GetCreatureByName("Weyland_Hallit").SetImmortal(true);
		}
	}

	void TE3_Cutscene_Conclave_WeylandDies()
	{
		printNote("Kill Weyland hallit in conclave cutscene");
		m_Reference.GetCreatureByName("Weyland_Hallit").KillAndPreserve(m_Reference);
	}

 	void TE3_Cutscene_Conclave_StartWeylandDeath()
 	{
 		printNote("starting weyland death cutscene");
 		m_Reference.PlayCutScene("TE3_35B_WeylandDies");
 		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_35B_WeylandDies), m_iPlayerFaction);
 	}

 	bool TE3_OnCutsceneEnd_TE3_35B_WeylandDies(const uint8 _uPlayerFaction)
 	{
 		m_Reference.PlayCutScene("TE3_41_PurityAttacks");
 		m_Reference.RegisterUIEvent(CutsceneFinished, TOnUIEvent(@this.TE3_OnCutsceneEnd_TE3_41_PurityAttacks), m_iPlayerFaction);
		PlayerHeroControlDisable();
		return true;

 	}

 	bool TE3_OnCutsceneEnd_TE3_41_PurityAttacks(const uint8 _uPlayerFaction)
 	{
 		PlayerHeroControlEnable();
 		return true;
 	}

	void TE3_Cutscene_Conclave_MyrahUlricHostile()
	{
		m_Reference.SetFactionRelation(8, 9, Hostile);
	}

	void TE3_Cutscene_Conclave_MyrahUlricNeutral()
	{
		m_Reference.SetFactionRelation(8, 9, Neutral);
	}

	void TE3_Cutscene_Conclave_Setup()
	{
		printNote("conclave begins");
		m_Reference.EnableGroup("TE3_ConclaveSetup", true);
		array <Entity> _entTmp = m_Reference.GetEntitiesInGroup( "TE3_ConclaveSetup");
		for ( uint _iTmp = 0; _iTmp < _entTmp.length(); _iTmp++ )
		{
			// debug for later
			//m_Reference.BlockNavMesh( m_Reference.FindEntityName( _entTmp[_iTmp] ), true );
		}
	}

	void TE3_Cutscene_Conclave_SpawnPurityAmbush()
	{
		printNote("Spawn purity army for ambush");
		m_Reference.ActivateSpawn("EY3_Spawn_Lightbringer", true);
	}

	void TE3_Cutscene_Conclave_MovePurityAmbush()
	{
		printNote("Purity moves towards conclave");

		array <Creature>@ _crtLightbringer = m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Lightbringer");
		for (uint _iTmp = 0; _iTmp < _crtLightbringer.length(); _iTmp++)
		{
			_crtLightbringer[_iTmp].AttackPosition(m_Reference, m_Reference.GetLogicObjectByName("EY3_Mrk_LightbringerMoveTo"), true, false);
		}

		m_Reference.RegisterCreatureEventByIndividuals(Killed, TOnCreatureEvent(@this.TE3_Cutscene_Conclave_PurityAmbushKilled), m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Lightbringer"), true, "");
	}

	bool TE3_Cutscene_Conclave_PurityAmbushKilled(Creature& in _Creature)
	{
		if(m_Reference.GetCreaturesFromSpawn("EY3_Spawn_Lightbringer").length() == 0)
		{
			TE3_Cutscene_Conclave_MyrahUlricNeutral();
			PlayerHeroControlDisable();
			m_Reference.PlayCutScene("TE3_42_PurityAmbushFendedOff");
			return true;
		}

		return false;
	}

	void TE3_Cutscene_Concalve_ActivateRTS()
	{
		m_Reference.ActivateAI(m_iFaction_HouseWulfgar);
		m_Reference.GetSectorByName("Sector_14").SetOwner(m_iFaction_HouseWulfgar);
		EnablePOIVisitingBehaviorSpawn ( "EY3_Sp_WulfgarStartArmy01", false );
		EnablePOIVisitingBehaviorSpawn ( "EY3_Sp_WulfgarStartArmy02", false );

		m_Reference.ActivateAI(m_iFaction_HouseHallit);
		m_Reference.GetSectorByName("Sector_08").SetOwner(m_iFaction_HouseHallit);
		EnablePOIVisitingBehaviorSpawn ( "EY3_Sp_HallitStartArmy01", false );

		m_Reference.ActivateAI(m_iFaction_PurityVariant2);
		m_Reference.GetSectorByName("Sector_01").SetOwner(m_iFaction_PurityVariant2);
		m_Reference.ActivateSpawn("EY3_Sp_PurityAiHeroes", true);
		m_Reference.ActivateSpawn("EY3_Sp_PurityStartArmy", true);

		m_Reference.GetSectorByName("Sector_15").SetOwner(m_iPlayerFaction);
		EnablePOIVisitingBehaviorSpawn ( "EY3_Sp_UtranStartArmy01", false );
		SetFactionSpawn( "EY3_Sp_UtranStartArmy01", m_iPlayerFaction );

		// todo: all different paths
		if(m_bPoisenedWeyland)
		{
			m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseHallit, Hostile);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_AllyHallit", Failed);
		}
		else
		{
			if(m_bMyrahMarried)
			{
				m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseHallit, Allied);
				m_Reference.GetBuildingByName("TE3_HallitSpawner").Enable(true);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_AllyHallit", Completed);
				m_Reference.GetWorld().SetGlobalBool("StoryVariables.TS_MyrahMarried", true);
				m_Reference.GetWorld().SetGlobalBool("StoryVariables.TS_HallitAllied", true);
			}
			else
			{
				m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseHallit, Neutral);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_AllyHallit", Failed);
			}
		}

		if(m_bWulfgarHostile)
		{
			m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseWulfgar, Hostile);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_AllyWulfgar", Failed);
		}
		else
		{
			if( m_bMyrahMarried || m_bPoisenedWeyland )
			{
				m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseWulfgar, Allied);
				m_Reference.GetBuildingByName("TE3_WulfgarSpawner").Enable(true);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_AllyWulfgar", Completed);
				m_Reference.GetWorld().SetGlobalBool("StoryVariables.TS_WulfgarAllied", true);
			}
			else
			{
				m_Reference.SetFactionRelation(m_iPlayerFaction, m_iFaction_HouseWulfgar, Neutral);
				m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_AllyWulfgar", Failed);
			}
		}

		PlayerHeroControlEnable();
		//m_Reference.RegisterBuildingEventByDescription(Destroyed, TOnBuildingEvent(@this.TE3_OnBuildingDestroyed_PurityDefeated), "H_Capital_II", m_iFaction_PurityVariant2);
		m_Reference.RegisterSectorEvent(OwnerChanged, TOnSectorEvent(@this.TE3_OnSectorOwnerChanged_PurityBase), "Sector_01");
	}

	bool TE3_OnSectorOwnerChanged_PurityBase(Sector@ _Sector, const uint8 _uPreviousOwnerFaction, const uint8 _uNewOwnerFaction)
	{
		if( _uPreviousOwnerFaction == m_iFaction_PurityVariant2 )
		{
			if(m_bPoisenedWeyland) // if hallit not gained
			{
				if(m_bWulfgarHostile) // if also wulfgar not gained
				{
					m_Reference.PlayCutScene("TE3_48D_PurityDefeated_NoHousesGained");
				}
				else // if no hallit but wulfgar gained
				{
					m_Reference.PlayCutScene("TE3_48C_PurityDefeated_HouseWulfgarGained");
				}
			}
			else
			{
				if(m_bMyrahMarried) // if hallit gained
				{
					if(m_bWulfgarHostile) // if only hallit gained
					{
						m_Reference.PlayCutScene("TE3_48B_PurityDefeated_HouseHallitGained");
					}
					else // if both gained
					{
						m_Reference.PlayCutScene("TE3_48A_PurityDefeated_BothHousesGained");
					}
				}
				else // if hallit neutral?
				{
					if(m_bWulfgarHostile) // if hallit gained but no wulfgar
					{
						m_Reference.PlayCutScene("TE3_48B_PurityDefeated_HouseHallitGained");
					}
					else // if wulfgar gained and hallit neutral
					{
						m_Reference.PlayCutScene("TE3_48C_PurityDefeated_HouseWulfgarGained");
					}
				}
			}
			m_Reference.LoseGame(m_iFaction_PurityVariant2);
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_DefeatPurity", Completed);
			TransferRTS(0, kFactionNeutral);
			EnableWorldMap( true );
			return true;
		}
		return false;
	}

	bool TE3_OnBuildingDestroyed_PurityDefeated(Building&in _Building)
	{
		if(m_bPoisenedWeyland) // if hallit not gained
		{
			if(m_bWulfgarHostile) // if also wulfgar not gained
			{
				m_Reference.PlayCutScene("TE3_48D_PurityDefeated_NoHousesGained");
			}
			else // if no hallit but wulfgar gained
			{
				m_Reference.PlayCutScene("TE3_48C_PurityDefeated_HouseWulfgarGained");
			}
		}
		else
		{
			if(m_bMyrahMarried) // if hallit gained
			{
				if(m_bWulfgarHostile) // if only hallit gained
				{
					m_Reference.PlayCutScene("TE3_48B_PurityDefeated_HouseHallitGained");
				}
				else // if both gained
				{
					m_Reference.PlayCutScene("TE3_48A_PurityDefeated_BothHousesGained");
				}
			}
			else // if hallit neutral?
			{
				if(m_bWulfgarHostile) // if hallit gained but no wulfgar
				{
					m_Reference.PlayCutScene("TE3_48B_PurityDefeated_HouseHallitGained");
				}
				else // if wulfgar gained and hallit neutral
				{
					m_Reference.PlayCutScene("TE3_48C_PurityDefeated_HouseWulfgarGained");
				}
			}
		}
		m_Reference.LoseGame(m_iFaction_PurityVariant2);
		m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P4_Q21_TheConclave", "P4_Q21_DefeatPurity", Completed);
		TransferRTS(0, kFactionNeutral);
		EnableWorldMap( true );
		return true;
	}
	// -------------------------------------------------------------------------------------------------------------------
	// -------------------------------------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------------------------
// ------------------------------------------V E R S I O N I N D E P E N D E N T--------------------------------------
// -------------------------------------------------------------------------------------------------------------------

	void InitRifts()
	{
		TE3_CheckRifts();
		if(m_Reference.GetJournal(m_iPlayerFaction).IsQuestActive("P3_MAP014_ElderRifts"))
		{

			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_MAP014_ElderRifts", "P3_MAP014_ElderRifts_MoveToTheEye", Completed);

			if( !m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedFirstRift", true))
				m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE_OnInteract_Rift01), "TE_Switch_RiftGate01", m_iPlayerFaction);

			if( !m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedSecondRift", true))
				m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE_OnInteract_Rift02), "TE_Switch_RiftGate02", m_iPlayerFaction);

			if( !m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedThirdRift", true))
				m_Reference.RegisterHeroPartyEvent(Interact, TOnHeroPartyEvent(@this.TE_OnInteract_Rift03), "TE_Switch_RiftGate03", m_iPlayerFaction);

		}
	}

	bool TE_OnInteract_Rift01( Creature& in _Creature)
	{
		if( m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedFirstRift", true))
			return true;
		// INSERT SHOUTOUT HERE
		// --------------------
		_closedFirst = true;
		m_Reference.EnableGroup("TE_RiftGate1", false);
		m_Reference.GetWorld().SetGlobalBool("QuestVariables.DO1_ClosedFirstRift", true);
		int _iClosed = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.DO1_NumClosedRifts", - 1);
		_iClosed++;
		m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.DO1_NumClosedRifts", _iClosed);
		if( m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedSecondRift", true) && m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedThirdRift", true) )
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_MAP014_ElderRifts", "P3_MAP014_ElderRifts_CloseTheRifts", Completed);

		m_Reference.GetLogicObjectByName("TE_Switch_RiftGate01").Enable(false);
		return true;
	}

	bool TE_OnInteract_Rift02( Creature& in _Creature)
	{
		if( m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedSecondRift", true))
			return true;
		// INSERT SHOUTOUT HERE
		// --------------------
		_closedSecond = true;
		m_Reference.EnableGroup("TE_RiftGate2", false);
		m_Reference.GetWorld().SetGlobalBool("QuestVariables.DO1_ClosedSecondRift", true);
		int _iClosed = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.DO1_NumClosedRifts", - 1);
		_iClosed++;
		m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.DO1_NumClosedRifts", _iClosed);
		if( m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedFirstRift", true) && m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedThirdRift", true) )
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_MAP014_ElderRifts", "P3_MAP014_ElderRifts_CloseTheRifts", Completed);

		m_Reference.GetLogicObjectByName("TE_Switch_RiftGate02").Enable(false);
		return true;
	}

	bool TE_OnInteract_Rift03( Creature& in _Creature)
	{
		if( m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedThirdRift", true))
			return true;
		// INSERT SHOUTOUT HERE
		// --------------------
		_closedThird = true;
		m_Reference.EnableGroup("TE_RiftGate3", false);
		m_Reference.GetWorld().SetGlobalBool("QuestVariables.DO1_ClosedThirdRift", true);
		int _iClosed = m_Reference.GetWorld().GetGlobalInt("QuestLogVariables.DO1_NumClosedRifts", - 1);
		_iClosed++;
		m_Reference.GetWorld().SetGlobalInt("QuestLogVariables.DO1_NumClosedRifts", _iClosed);
		if( m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedFirstRift", true) && m_Reference.GetWorld().GetGlobalBool("QuestVariables.DO1_ClosedSecondRift", true) )
			m_Reference.GetJournal(m_iPlayerFaction).SetTaskState("P3_MAP014_ElderRifts", "P3_MAP014_ElderRifts_CloseTheRifts", Completed);

		m_Reference.GetLogicObjectByName("TE_Switch_RiftGate03").Enable(false);
		return true;
	}

}
