/////////////////////////////////////////////////////////////////////
// THARD.S		- Thardolin
/////////////////////////////////////////////////////////////////////

SETUP

	IF gt_PLACED_THARDOLIN_CHARS
		RemoveC DELGAR
	ELSE
		Add gt_PLACED_THARDOLIN_CHARS

		PlaceC YARANA pYARANA
		RunS YaranaActions
		PlaceC PINAEOS pPINAEOS

		PlaceC THARD_GUARD_1 pGUARD_1
		PlaceC THARD_GUARD_2 pGUARD_2
		PlaceC THARD_GUARD_3 pGUARD_3
		PlaceC THARD_GUARD_4 pGUARD_4

		PlaceC THARD_MAD_MER_1 pMER_1
		PlaceC THARD_MAD_MER_2 pMER_2
		PlaceC THARD_MAD_MER_3 pMER_3
		WanderNotFar THARD_MAD_MER_1
		WanderNotFar THARD_MAD_MER_2
		WanderNotFar THARD_MAD_MER_3
		PlaceC THARD_BOD_1 pC_1
		PlaceC THARD_BOD_2 pC_2
		PlaceC THARD_BOD_3 pC_3
		PlaceC THARD_BOD_4 pC_4
		PlaceC THARD_BOD_5 pC_5
		PlaceC THARD_BOD_6 pC_6
		PlaceC THARD_BOD_7 pC_7
		PlaceC THARD_BOD_8 pC_8
		WanderNotFar THARD_BOD_1
		WanderNotFar THARD_BOD_2
		RunS ThardBod3Actions
		WanderNotFar THARD_BOD_4
		WanderNotFar THARD_BOD_5
		WanderNotFar THARD_BOD_6
		WanderNotFar THARD_BOD_7
		WanderNotFar THARD_BOD_8

		IDoorLocked dTPAL_MID
	ENDIF


	//random placement of Delgar Dim
	SWITCH RAND-2
		CASE 0
			PlaceC DELGAR pDELGAR1
		CASE 1
			PlaceC DELGAR pDELGAR2
	ENDSWITCH
	Wander DELGAR

	//update Pinaeos
	IF gt_PIN_BUSINESS=1 && ce_CEREBELLA
		Set gt_PIN_BUSINESS 2
	ENDIF
	IF gt_PINAEOS_COMPLETE
		Remove gt_PINAEOS_COMPLETE
		KillC PINAEOS
	ENDIF

	IF !gt_RECENT_MUSIC_IN_THARDOLIN
		Add gt_RECENT_MUSIC_IN_THARDOLIN
		PlayMusic RPG12.WAV
	ENDIF

END

VIG TempSetup FALSE

	DisableTeleport TD_EF
    SetWeather  0 0 0 0 0 0 0 0
	SetLiquid water 1550 20 20
	SetLiquid water2 1550 20 20
	SetLiquid water3 1550 20 20
	SetLiquid water4 1550 20 20
	SetWaterType 0

END

/////////////////////////////////////////////////////////////////////

VIG ThardGuardsPeaceful mj_RECOVER_CROWN && !gt_THARD_GUARDS_PEACEFUL

	Add gt_THARD_GUARDS_PEACEFUL
	SetGoodBad			THARD_GUARD_1
	SetGoodBad			THARD_GUARD_2
	StopC			THARD_GUARD_1
	StopC			THARD_GUARD_2

END

/////////////////////////////////////////////////////////////////////

VIG ThardBod3Actions FALSE

	MoveCDir THARD_BOD_3 pC_3
	AddControl THARD_BOD_3 DelayControl 10 20
	AddControl THARD_BOD_3 Capture cF_STAND_AT_EASE
	SequenceLoops THARD_BOD_3

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_1 MSG-iTHARD_BOD_1

	Widescreen TRUE
	EngageAndFace P THARD_BOD_1
	UUComplete P
	Wait 1000
	Capture THARD_BOD_1 cM_SHRUG2
	UUComplete THARD_BOD_1
	WanderNotFar THARD_BOD_1
	Wait 1000
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_2 MSG-iTHARD_BOD_2

	Widescreen TRUE
	EngageAndFace P THARD_BOD_2
	UUComplete P
	Wait 1000
	Capture THARD_BOD_2 cM_SHRUG2
	UUComplete THARD_BOD_2
	WanderNotFar THARD_BOD_2
	Wait 1000
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_3 MSG-iTHARD_BOD_3

	Widescreen TRUE
	Engage P THARD_BOD_3 750
	UUComplete P
	LookAtTurnFollow THARD_BOD_3 P
	Wait 2500
	RunS ThardBod3Actions
	Wait 1000
	Capture P cM_SHRUG1
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_4 MSG-iTHARD_BOD_4

	Widescreen TRUE
	EngageAndFace P THARD_BOD_4
	UUComplete P
	Wait 1000
	WanderNotFar THARD_BOD_4
	Wait 1000
	Capture P cM_SHRUG1
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_5 MSG-iTHARD_BOD_5

	Widescreen TRUE
	EngageAndFace P THARD_BOD_5
	UUComplete P
	Wait 1000
	Capture THARD_BOD_5 cM_SHRUG2
	UUComplete THARD_BOD_5
	WanderNotFar THARD_BOD_5
	Wait 1000
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_6 MSG-iTHARD_BOD_6

	Widescreen TRUE
	EngageAndFace P THARD_BOD_6
	UUComplete P
	Wait 1000
	Capture THARD_BOD_6 cM_SHRUG2
	UUComplete THARD_BOD_6
	WanderNotFar THARD_BOD_6
	Wait 1000
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_7 MSG-iTHARD_BOD_7

	Widescreen TRUE
	EngageAndFace P THARD_BOD_7
	UUComplete P
	Wait 1000
	WanderNotFar THARD_BOD_7
	Wait 1000
	Capture P cM_SHRUG1
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToThardBod_8 MSG-iTHARD_BOD_8

	Widescreen TRUE
	EngageAndFace P THARD_BOD_8
	UUComplete P
	Wait 1000
	WanderNotFar THARD_BOD_8
	Wait 1000
	Capture P cM_SHRUG1
	Widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TalkToDelgarDim MSG-iDELGAR

	Widescreen TRUE
	UnDrawSwordRemember
	EngageAndFace P DELGAR

	IF ce_DELGAR
		Say dd0002
	ELSE
		Add ce_DELGAR
		ChangeProfileToIdentified Tcitizen_DelgarDim
		Say dd0001
	ENDIF

	ResetChoice
	WHILE !MenuExit
		ClearChoices

		//Trade
		AddChoice 1 tx0008

		IF !mj_DEFEAT_AL
			//Al'Kadath
			AddChoice 2 tx0118
		ENDIF

		//Thardolin
		//AddChoice 3 tx0120

		//Empress
		AddChoice 4 txya01

		//Cult
		AddChoice 5 txpi06

		//Leave
		AddChoice 0 tx0003

		GetChoice DELGAR

		SWITCH Choice
			CASE 1
				//Trade

				Say dd0003
				MessagesOff
				SHOPPANEL DELG_SHOP 200 50 DELGAR BUYSELL
				MessagesOn
				Say dd0004

			CASE 2
				//Al'Kadath

				Say dd0009

			CASE 3
				//Thardolin

				Say dd0010

			CASE 4
				//Empress

				Say dd0011

			CASE 5
				//Cult

				Say dd0012

			CASE 0
				//Leave

				SWITCH RAND-4
					CASE 0
						Say dd0005
					CASE 1
						Say dd0006
					CASE 2
						Say dd0007
					CASE 3
						Say dd0008
				ENDSWITCH
		ENDSWITCH
	ENDWHILE

	Widescreen FALSE
	WanderNotFar DELGAR 2 10
	SwitchOnSightOfPlayer DELGAR LookAtTurnFollow P

END

/////////////////////////////////////////////////////////////////////

VIG TalkToYarana MSG-iYARANA

	Widescreen TRUE
	UnDrawSwordRemember
	EngageAndFace P YARANA

	IF !ce_YARANA
		Add ce_YARANA
		ChangeProfileToIdentified Tcitizen_Yarana
		//"Hail traveller,I am Yarana. You are not dressed for travel in these parts...my father left some desert clothes..."
		Say ya0001

		//player gets changed into desert clothes
		RunS PalFadeBLACK
		SetPCModel				PCstage3B
		ChangeProfilePortrait P	PC3B.BIN
		RunS PalFadeRPG
		AwardEP xp_FIND_YARANA
	ELSE
		//"It is good to see you still alive..."
		Say ya0009
	ENDIF

	ResetChoice
	WHILE !MenuExit
		ClearChoices

		IF co_EMPRESS
			AddChoice 1 txya01
		ENDIF

		//The desert
		AddChoice 2 txya02

		IF co_CULT
			AddChoice 3 txya03
		ENDIF

		IF co_PINAEOS
			AddChoice 4 txya04
		ENDIF

		//Crown of Rule
		AddChoice 5 txya05

		IF ce_MERULAH
			AddChoice 6 txya06
		ENDIF

		//Leave
		AddChoice 0 tx0003

		GetChoice YARANA

		SWITCH Choice
			CASE 1
				//Empress

				//"I was once a maid to the empress...a change has come over her...cold and cruel..."
				Say ya0002

			CASE 2
				//Desert

				//"...once lush farmlands...people..walk there as if spellbound...They have established a cult...they hold...Jaard's Well..."
				Say ya0003

				Add co_CULT
				Add co_JDWELL

			CASE 3
				//Cult

				//"I know little of them, my sister ran away...to join them...my father tried to bring her back, but...was lost..."
				Say ya0004

			CASE 4
				//Pinaeos

				//"...fool...seeks the crown...he has a weakness for antiquities..."
				Say ya0005

			CASE 5
				//Crown of Rule

				//"...the Empress cannot bear to wear it now..."
				Say ya0006

				Add co_EMPRESS

			CASE 6
				//Merulah

				//"That was my father's name..."
				Say ya0010
				IF !gt_XP_MERULAH
					Add gt_XP_MERULAH
					AwardEP xp_MERULAH
				ENDIF
		ENDSWITCH
	ENDWHILE

	//"Farewell, traveller."
	Say ya0007

	Widescreen FALSE

	RunS YaranaActions
END

/////////////////////////////////////////////////////////////////////

VIG TalkToPinaeos MSG-iPINAEOS && !(gt_PIN_BUSINESS=4)
	IF gt_PIN_BUSINESS=5
		//"In you go...I'm sure you know what to do."
		QuickSay pi011a
	ELSE
StartRecord
camcut pos02
		Widescreen TRUE
		UnDrawSwordRemember
		EngageAndFace P Pinaeos

		IF !ce_PINAEOS
			Add ce_PINAEOS
			Add co_PINAEOS
			ChangeProfileToIdentified Tcitizen_Pinaeos
			Set gt_PIN_BUSINESS 0

			//"I heard there was someone new in town. I am Admiral Pinaeos..."
			Say pi0001
		ELSE
			//"Welcome back. Did you find anything of interest while you were gone?"
			Say pi0002
		ENDIF

		ResetChoice
		WHILE !MenuExit
			ClearChoices

			IF co_ALKADATH
				AddChoice 1 tx0118
			ENDIF

			//Dragon Soldiers
			AddChoice 2 txpi02

			//Crown of Rule
			AddChoice 3 txpi03

			IF co_EMPRESS_MAGIC
				AddChoice 4 txpi04
			ENDIF

			IF ce_MERULAH
				AddChoice 5 txpi05
			ENDIF

			IF co_CULT
				AddChoice 6 txpi06
			ENDIF

			IF gt_PIN_BUSINESS=2
				//Ghost of Empress
				AddChoice 7 txpi07
			ELSE
				//Business
				AddChoice 9 txpi09
			ENDIF

			//Archaeology
			AddChoice 8 txpi08

			//Trade
			//AddChoice 10 tx0008

			//Leave
			AddChoice 0 tx0003

			GetChoice PINAEOS

			SWITCH Choice
				CASE 1
					//Al'Kadath

					//"...imbecile...His kind was a rarity before the Empress' magical research..."
					Say pi0006

					Add co_EMPRESS_MAGIC

				CASE 2
					//Dragon Soldiers

					//"...remains of the...Imperial Marines. The Empress uses her new-found magic..."
					Say pi0007

					Add co_EMPRESS_MAGIC

				CASE 3
					//Crown of Rule

					//"...in the palace, kept...by the Empress."
					Say pi0008

				CASE 4
					//Empress Magic

					//"...researching...magic...performing...rites..."
					Say pi0013

				CASE 5
					//Desert Madman

					//"...I could find a dozen desert madmen...by walking out onto the streets...don't bother me!"
					Say pi0014

					SetChoiceToExit

				CASE 6
					//Cultists

					//"...think they can summon a god...from the desert...to lay waste to...the city..."
					Say pi0015

				CASE 7
					//Ghost of Empress

					//"...you have proved your loyalty..."
					Say pi0016
					AwardEP xp_PINAEOS_WORK
					QLRemove ql302

					Capture PINAEOS cM_TOSS_GENTLE
					Capture P cM_OBJ_ACCEPT_1H1
					UUComplete P
					Gold+ P 500

					//"...that was merely the beginning...Perhaps you would help me again...?"
					Say pi0017

					Set gt_PIN_BUSINESS 3

				CASE 8
					//Archaeology

					//"...ancient ruins...items found are often magical...I will happily purchase such items..."
					Say pi0012

				CASE 9
					//Business

					IF gt_PIN_BUSINESS>1
						//"I need the Crown of Rule...I need you to create...a diversion."
						Say pi0010
						IF gt_PIN_BUSINESS=3

							//"...place it...near the...gate...meet me beside the gangplank...we will enter the palace."
							QuickSay pi0011
							Capture PINAEOS cM_TOSS_GENTLE
							Capture P cM_OBJ_ACCEPT_1H1
							UUComplete P

							AwardOb P bomb "unusual-artefact"
							Set gt_PIN_BUSINESS 4
							QLAdd ql303 qlt303 qlb303
							UUSay

							SetChoiceToExit
						ENDIF
					ELSE
						//"...archaeological site south of the city...guarded by the Empress' soldiers...find out what it is..."
						Say pi0009
						IF !gt_PIN_BUSINESS=1
							QLAdd ql302 qlt302 qlb302
							Set gt_PIN_BUSINESS 1
						ENDIF
					ENDIF

				//CASE 10
					//Trade

					//"You have something of value...?"
					//Say pi0004

					// <trade with Pinaeos>

					//"Perhaps we can discuss antiquities in the future..."
					//Say pi0005

				CASE 0
					//Leave

					//"...good day."
					Say pi0003

			ENDSWITCH
		ENDWHILE

		IF gt_PIN_BUSINESS=4
			MoveC_1tel PINAEOS TD_BOAT1_IN pPINAEOS_WAIT
		ENDIF
StopRecord
camcut p 
setcammovenormal
		Widescreen FALSE
		DrawSwordRemember
	ENDIF

END

/////////////////////////////////////////////////////////////////////

VIG PlantBombOnWagon FIVESEC && gt_PIN_BUSINESS=4 && OBJINAREA-bomb-NEAR_WAGON

	Add gt_PLACED_BOMB_IN_WAGON

END

/////////////////////////////////////////////////////////////////////

VIG DistractGuards gt_PLACED_BOMB_IN_WAGON && CC-PINAEOS && (INAREA-P-NEAR_MEETING || MSG-iPINAEOS) && (POS-P-BOMB || OBJINAREA-bomb-NEAR_WAGON)

	// *** BOMB THE PALACE ***

	<< *** needs camera work *** >>

	Widescreen TRUE

	SetWalkType P run
	EngageAndFace P PINAEOS
	UUComplete P
	QLRemove ql303
	Wait 1500


	IF POS-P-BOMB

//		PlaySFXPerson IG_175.WAV P
		PlaySFX IG_175.WAV

		FireDamageNA P 1000
		NormalDamageNA P 1000

		wait 2000

	ELSE

		freecam
		camcut bm01

		wait 1500

		FX_BombExplodes pP_BY_WAGON
		DeleteObjectsInWorldWithID bomb

		//explosion SFX
//		PlaySFXPosid IG_175.WAV pP_BY_WAGON
		PlaySFX IG_175.WAV

		SetHP THARD_GUARD_3 10
		SetHP THARD_GUARD_4 15
		FireDamageNA THARD_GUARD_3 120
		FireDamageNA THARD_GUARD_4 115

		SetGoodBad	THARD_GUARD_1 bad
		SetWalkType	THARD_GUARD_1 run
		EngagePoint	THARD_GUARD_1 pP_BY_WAGON 500
		AddControl	THARD_GUARD_1 Filter Timeout 10 Filter FailCompletes LookAtTurnFollow P
		AddControl	THARD_GUARD_1 AttackDemo2
		SetGoodBad	THARD_GUARD_2 bad
		SetWalkType	THARD_GUARD_2 run
		EngagePoint	THARD_GUARD_2 pP_BY_WAGON 500
		AddControl	THARD_GUARD_2 Filter Timeout 10 Filter FailCompletes LookAtTurnFollow P
		AddControl	THARD_GUARD_2 AttackDemo2

		setdoorspeed dtpal_thard 1000
		IDoorClosed dtpal_thard
		RDoorOpen dtpal_thard

		wait 3000

		normalcam
		camcut P
		LookAtTurn P pDELGAR1
		Wait 2500

		//"In you go...I'm sure you know what to do."
		Say pi011a
		SetWalkType P walk
		MoveC P pDELGAR1

		Set gt_PIN_BUSINESS 5
		Add gt_PINAEOS_COMPLETE
		Remove gt_PLACED_BOMB_IN_WAGON
		MoveC_1tel PINAEOS TD_BOAT1_OUT pPINAEOS
		AwardEP xp_BOMB_PALACE
		SetWalkType	THARD_GUARD_1 walk
		SetWalkType	THARD_GUARD_2 walk

	ENDIF

	Widescreen FALSE
END

/////////////////////////////////////////////////////////////////////

VIG TradeWithMerchant_1 MSG-iTHARD_MAD_MER_1

	widescreen TRUE
	EngageAndFace P THARD_MAD_MER_1
	Say me1004 MERCHNT1.BIN
	MessagesOff
	ShopPanel TM_F_SHOP 125 50 THARD_MAD_MER_1 BUYSELL
	MessagesOn
	Say me1001 MERCHNT1.BIN
	widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TradeWithMerchant_2 MSG-iTHARD_MAD_MER_2

	widescreen TRUE
	EngageAndFace P THARD_MAD_MER_2
	Say me2002 MERCHNT2.BIN
	MessagesOff
	ShopPanel TM_W_SHOP 125 50 THARD_MAD_MER_2 BUYSELL
	MessagesOn
	Say me2015 MERCHNT2.BIN
	widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG TradeWithMerchant_3 MSG-iTHARD_MAD_MER_3

	widescreen TRUE
	EngageAndFace P THARD_MAD_MER_3
	Say me3001 MERCHNT3.BIN
	MessagesOff
	ShopPanel TM_A_SHOP 125 50 THARD_MAD_MER_3 BUYSELL
	MessagesOn
	Say me3012 MERCHNT3.BIN
	widescreen FALSE

END

/////////////////////////////////////////////////////////////////////

VIG YaranaActions FALSE

	MoveC		YARANA	pYCounter
	AddControl	YARANA	DelayControl 3 5
	AddControl	YARANA	Filter Timeout 4 Filter FailCompletes LookAtTurnFollow P
	AddControl	YARANA	TDCapture cM_STEPPING_ON_SPOT		pYCounter	10 3
	AddControl	YARANA	TDCapture cF_KNEEL_FUMBLE			pYBoxes		10 3
	AddControl	YARANA	TDCapture cF_HAVE_A_STRETCH_FORWARD	pYWindow	10 3
	AddControl	YARANA	TDCapture cF_HAVE_A_STRETCH_UP		pYCounter	10 3
	SequenceRandomlySelects YARANA

END

/////////////////////////////////////////////////////////////////////
