/////////////////////////////////////////////////////////////////////
// WELL.S		-	Jaard's Well
/////////////////////////////////////////////////////////////////////

SETUP

	IF !gt_PLACED_JDWELL_CHARS
		Add gt_PLACED_JDWELL_CHARS
		Add gt_CUE_CULTIST_ATTACK

		PlaceC MERULAH pMERULAH
		PlaceC CULTIST_1 pC1
		PlaceC CULTIST_2 pC2
		PlaceC CULTIST_3 pC3
		PlaceC CULTIST_4 pC4
		PlaceC CULTIST_5 pC5
		PlaceC CULTIST_6 pC6
		PlaceC CULTIST_7 pC7
		PlaceC CULTIST_8 pC8
		PlaceC CULTIST_9 pC9
		PlaceC CULTIST_10 pC10
		Capture CULTIST_1 cF_MEL_SCATTER1_PICK
		Capture CULTIST_2 cF_MEL_SCATTER1_PICK
		Capture CULTIST_3 cF_MEL_SCATTER1_PICK
		Capture CULTIST_4 cF_MEL_SCATTER1_PICK
		Capture CULTIST_5 cF_MEL_SCATTER1_PICK
		Capture CULTIST_6 cF_MEL_SCATTER1_PICK
		Capture CULTIST_7 cF_MEL_SCATTER1_PICK
		Capture CULTIST_8 cF_MEL_SCATTER1_PICK
		EngagePoint CULTIST_9 pC2 1000
		AddControl CULTIST_9 Capture cM_CAST_SPELL14_SKY
		AddControl CULTIST_9 EngagePoint pC4 1000
		AddControl CULTIST_9 Capture cM_CAST_SPELL14_SKY
		AddControl CULTIST_9 EngagePoint pC6 1000
		AddControl CULTIST_9 Capture cM_CAST_SPELL14_SKY
		AddControl CULTIST_9 EngagePoint pC8 1000
		AddControl CULTIST_9 Capture cM_CAST_SPELL14_SKY
		SequenceLoops CULTIST_9
		MoveCDir CULTIST_10 pC10B
		AddControl CULTIST_10 Capture cF_BECKON 
		AddControl CULTIST_10 MoveCDir pC10B
		AddControl CULTIST_10 Capture cF_BECKON 
		SequenceLoops CULTIST_10
		SetGoodBad CULTIST_10 good
		Add gt_CULT_GUARD_ACTIVE

		PlaceC CEREBELLA pCEREBELLA
		PlaceC CER_GUARD1 pDS1
		PlaceC CER_GUARD2 pDS2
		Lock CER_GUARD1
		Lock CER_GUARD2
	ENDIF

	IF mj_DEFEAT_INCUBAH
		RemoveC CEREBELLA
		KillC CER_GUARD1
		KillC CER_GUARD2
	ENDIF

END

VIG TempSetup FALSE

	DisableTeleport WL_HEXSTONE

	SetWeather 0 0 0 0 0 0 0 0
	AddBigFire 31620 22657

	CachePortrait CEREBELA.BIN
	CachePortrait CHIMERA.BIN
	CachePortrait DELGAR.BIN
	CachePortrait DWARRIOR.BIN

END

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

VIG ActivateCultGuard gt_CULT_GUARD_ACTIVE && (MSG-iCULTIST_10 || (FIVESEC && DAMAGED-CULTIST_10))

	Remove gt_CULT_GUARD_ACTIVE

	QuickSay Gg0001

	EngagePoint CULTIST_10 pC3 750

END

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

VIG TalkToMerulah MSG-iMERULAH

	Widescreen TRUE
	UnDrawSwordRemember
	EngageAndFace P MERULAH

	IF ce_MERULAH
		Say ni0002 NIX.BIN
	ELSE
		Add ce_MERULAH
		ChangeProfileToIdentified Tcitizen_Madman
		Say ni0001 NIX.BIN
	ENDIF

	ResetChoice
	WHILE !MenuExit
		ClearChoices

		IF co_JDWELL
			AddChoice 1 txni01
		ENDIF

		IF co_PINAEOS
			AddChoice 2 txya04
		ENDIF

		//The Desert
		AddChoice 3 txya02

		IF co_CULT
			AddChoice 4 txya03
		ENDIF

		//Empress
		AddChoice 5 txya01

		//Leave
		AddChoice 0 tx0003

		GetChoice MERULAH

		SWITCH Choice
			CASE 1
				//Jaard's Well

				Say ni0003 NIX.BIN
				Say ni0006 NIX.BIN

			CASE 2
				//Pinaeos

				Say ni003a NIX.BIN
				Say ni0004 NIX.BIN

			CASE 3
				//Desert

				Say ni0005 NIX.BIN

			CASE 4
				//Cultists

				Say ni0006 NIX.BIN

			CASE 5
				//Empress

				Say ni0007 NIX.BIN

			CASE 0
				//Leave

				Say ni0006 NIX.BIN
		ENDSWITCH
		
	ENDWHILE

	Widescreen FALSE
END

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

VIG MeetCultists ONESEC && INAREA-P-NEAR_WELL && gt_CUE_CULTIST_ATTACK

	Remove gt_CUE_CULTIST_ATTACK

	Say bj0001

	SetGoodBad CULTIST_1 bad
	SetGoodBad CULTIST_2 bad
	SetGoodBad CULTIST_3 bad
	SetGoodBad CULTIST_4 bad
	SetGoodBad CULTIST_5 bad
	SetGoodBad CULTIST_6 bad
	SetGoodBad CULTIST_7 bad
	SetGoodBad CULTIST_8 bad
	SetGoodBad CULTIST_10 bad
	GiveSightOfPlayerTo CULTIST_1
	GiveSightOfPlayerTo CULTIST_2
	GiveSightOfPlayerTo CULTIST_3
	GiveSightOfPlayerTo CULTIST_4
	GiveSightOfPlayerTo CULTIST_5
	GiveSightOfPlayerTo CULTIST_6
	GiveSightOfPlayerTo CULTIST_7
	GiveSightOfPlayerTo CULTIST_8
	GiveSightOfPlayerTo CULTIST_10
	AttackDemo2 CULTIST_1
	AttackDemo2 CULTIST_2
	AttackDemo2 CULTIST_3
	AttackDemo2 CULTIST_4
	AttackDemo2 CULTIST_5
	AttackDemo2 CULTIST_6
	AttackDemo2 CULTIST_7
	AttackDemo2 CULTIST_8
	AttackDemo2 CULTIST_10

END

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

VIG FluteTune_1 (MSG-FLUTE1 || MSG-iFLUTE1) && INAREA-P-NEAR_WELL && !gt_PLAYED_FLUTE_TUNE_1 && !gt_CUE_CULTIST_ATTACK

	Widescreen TRUE
	
	Add gt_PLAYED_FLUTE_TUNE_1

	Wait 5000

	IF !ISDEAD-CULTIST_9
		Say Bj0002
	ENDIF

	FX_RainBeetles

	Widescreen FALSE
	AwardEP xp_FLUTE_1
END

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

VIG FluteTune_2 (MSG-FLUTE2 || MSG-iFLUTE2) && INAREA-P-NEAR_WELL && !gt_PLAYED_FLUTE_TUNE_2 && !gt_CUE_CULTIST_ATTACK

	Widescreen TRUE

	Add gt_PLAYED_FLUTE_TUNE_2
	Add gt_PLAYED_FLUTE_TUNE_3

	Wait 5000

	IF !ISDEAD-CULTIST_9
		Say Bj0004
	ENDIF

	RunS SummonChimera

	//SetHP CHIMERA hp_CHIMERA
	SetHP CHIMERA 1250

	Widescreen FALSE
	AwardEP xp_FLUTE_2
END

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

VIG FluteTune_3 (MSG-FLUTE3 || MSG-iFLUTE3) && INAREA-P-NEAR_WELL && !gt_PLAYED_FLUTE_TUNE_3 && !gt_CUE_CULTIST_ATTACK

	Widescreen TRUE

	Add gt_PLAYED_FLUTE_TUNE_2
	Add gt_PLAYED_FLUTE_TUNE_3

	Wait 5000

	IF !ISDEAD-CULTIST_9
		Say Bj0003
	ENDIF

	RunS SummonChimera

	Widescreen FALSE
	AwardEP xp_FLUTE_3
END

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

VIG FluteTune_4 (MSG-FLUTE4 || MSG-iFLUTE4) && INAREA-P-NEAR_WELL && !gt_PLAYED_FLUTE_TUNE_4 && !gt_CUE_CULTIST_ATTACK

	Widescreen TRUE

	Add gt_PLAYED_FLUTE_TUNE_4

	Wait 5000

	SetGoodBad CULTIST_1 good
	SetGoodBad CULTIST_2 good
	SetGoodBad CULTIST_3 good
	SetGoodBad CULTIST_4 good
	SetGoodBad CULTIST_5 good
	SetGoodBad CULTIST_6 good
	SetGoodBad CULTIST_7 good
	SetGoodBad CULTIST_8 good
	SetGoodBad CULTIST_10 good
	SetGoodBad CULTIST_9 bad
	Wander CULTIST_1
	Wander CULTIST_2
	Wander CULTIST_3
	Wander CULTIST_4
	Wander CULTIST_5
	Wander CULTIST_6
	Wander CULTIST_7
	Wander CULTIST_8
	Wander CULTIST_10
	SwitchOnSightOfPlayer CULTIST_1 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_2 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_3 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_4 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_5 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_6 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_7 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_8 RunAwayFrom P
	SwitchOnSightOfPlayer CULTIST_10 RunAwayFrom P

	IF !ISDEAD-CULTIST_9
		Say Bj0005
		GiveSightOfPlayerTo CULTIST_9
		AttackDemo2 CULTIST_9
		Add gt_CULT_MASTER_ATTACKING
	ENDIF
	
	Widescreen FALSE
	AwardEP xp_FLUTE_4
END

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

VIG TalkToCultist MSG-iCULTIST_1 || MSG-iCULTIST_2 || MSG-iCULTIST_3 || MSG-iCULTIST_4 || MSG-iCULTIST_5 || MSG-iCULTIST_6 || MSG-iCULTIST_7 || MSG-iCULTIST_8

	QuickSay Gg0001

END

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

VIG CultMasterDead ONESEC && gt_CULT_MASTER_ATTACKING && ISDEAD-CULTIST_9

	Remove gt_CULT_MASTER_ATTACKING
	QuickSay Bj0006

END

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

VIG SummonChimera FALSE

	PlayMusic RPG32.WAV

	FX_YellowFire	25544 6016
	FX_GreenFire	25504 5896
	Wait 101
	FX_YellowFire	25504 6136
	FX_GreenFire	25404 5826
	Wait 101
	FX_YellowFire	25404 6206
	FX_GreenFire	25284 5826
	Wait 101
	FX_YellowFire	25284 6206
	FX_GreenFire	25184 5896
	Wait 101
	FX_YellowFire	25184 6136
	FX_GreenFire	25144 6016
	Wait 101
	FX_YellowFire	25144 6016
	FX_GreenFire	25184 6136
	Wait 101
	FX_YellowFire	25184 5896
	FX_GreenFire	25284 6206
	Wait 101
	FX_YellowFire	25284 5826
	FX_GreenFire	25404 6206
	Wait 101
	FX_YellowFire	25404 5826
	FX_GreenFire	25504 6136
	Wait 101
	FX_YellowFire	25504 5896
	FX_GreenFire	25544 6016

	PlaceC CHIMERA pCHIMERA

	FX_YellowFire	25544 6016
	FX_GreenFire	25504 5896
	Wait 101
	FX_YellowFire	25504 6136
	FX_GreenFire	25404 5826
	Wait 101
	FX_YellowFire	25404 6206
	FX_GreenFire	25284 5826
	Wait 101
	FX_YellowFire	25284 6206
	FX_GreenFire	25184 5896
	Wait 101
	FX_YellowFire	25184 6136
	FX_GreenFire	25144 6016
	Wait 101
	FX_YellowFire	25144 6016
	FX_GreenFire	25184 6136
	Wait 101
	FX_YellowFire	25184 5896
	FX_GreenFire	25284 6206
	Wait 101
	FX_YellowFire	25284 5826
	FX_GreenFire	25404 6206
	Wait 101
	FX_YellowFire	25404 5826
	FX_GreenFire	25504 6136
	Wait 101
	FX_YellowFire	25504 5896
	FX_GreenFire	25544 6016

	Say Ch0001

	GiveSightOfPlayerTo CHIMERA
	AttackDemo2 CHIMERA

	Add gt_P_V_CHIMERA
	Add f_CHIMERA_AT_WELL

END

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

VIG ChimeraDead ONESEC && gt_P_V_CHIMERA && ISDEAD-CHIMERA

	IF gg_FX_CHIMERA_DEATH<4

		IF !gg_FX_CHIMERA_DEATH
			Set gg_FX_CHIMERA_DEATH 0
		ENDIF
	
	ELSE

		Remove gt_P_V_CHIMERA
		Add mj_DEFEAT_CHIMERA

		IF ISEQUIPED-P-mess2
			Widescreen TRUE
			Capture P cM_SUMMON_SWORD1
			Wait 1000
			FX_UpgradeSword
			UUComplete P
			//UnDrawSword P not needed
			MessagesOff
			DeleteObjectsInBackpackWithID P mess2
			AwardOb P mess3 "new-sword"
			MakeHeld P mess3
			MessagesOn
			Widescreen FALSE
		ENDIF

	ENDIF

END

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

VIG AttackCerebellaGuards ONESEC && !gt_CER_GUARD_OOPS && (DAMAGED-CER_GUARD1 || DAMAGED-CER_GUARD2)

	SetGoodBad CER_GUARD1 bad
	SetGoodBad CER_GUARD2 bad
	Unlock CER_GUARD1
	Unlock CER_GUARD2
	AttackDemo CER_GUARD1
	AttackDemo CER_GUARD2
	Add gt_CER_GUARD_OOPS

END

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

VIG TalkToCerebellaGuards (MSG-iCER_GUARD1 || MSG-iCER_GUARD2 || (ONESEC && DISTFROM-P-CER_GUARD1-3 && !gt_MADE_FRIENDS_WITH_CER_GUARDS)) && !gt_CER_GUARD_OOPS

	Widescreen TRUE

	UnDrawSwordRemember
	EngageAndFace P CER_GUARD1

	IF ce_CER_GUARDS
		Say ds3002 DWARRIOR.BIN
	ELSE
		Add ce_CER_GUARDS
		Say ds3001 DWARRIOR.BIN
	ENDIF

	ResetChoice
	WHILE !MenuExit
		ClearChoices

		//Crown of Rule
		AddChoice 1 txpi03

		IF co_PINAEOS && !gt_MADE_FRIENDS_WITH_CER_GUARDS
			//Pinaeos
			AddChoice 2 txds01
		ENDIF

		IF ce_YARANA
			AddChoice 3 txds04
		ENDIF

		IF gt_ASKED_HAMMER_ABOUT_DRAGON_SOLDIERS && gt_MENTION_YARANA_TO_CER_GUARDS && !gt_MADE_FRIENDS_WITH_CER_GUARDS
			//Hammer
			AddChoice 4 txpw01
		ENDIF

		IF !gt_CUE_CULTIST_ATTACK || ce_YARANA
			//Cultists
			AddChoice 5 txds03
		ENDIF

		AddChoice 0 tx0003

		GetChoice CER_GUARD1 DWARRIOR.BIN

		SWITCH Choice
			CASE 1
				//Crown of Rule
				Say ds3005 DWARRIOR.BIN

			CASE 2
				//Pinaeos

				//"You know Admiral Pinaeos?"
				Say ds3006 DWARRIOR.BIN

				ClearChoices

				//"I know him vaguely."
				AddChoice 1 txds06

				//"I do not know him."
				AddChoice 2 txds07

				GetChoice CER_GUARD1 DWARRIOR.BIN

				SWITCH Choice
					CASE 1
						//"Lord Pinaeos is not a man with whom one becomes merely 'acquainted'."
						Say ds3009 DWARRIOR.BIN

						ClearChoices

						//"I am here on his business."
						AddChoice 1 txds08

						//"He is no friend of mine."
						AddChoice 2 txds09

						GetChoice CER_GUARD1 DWARRIOR.BIN

						SWITCH Choice
							CASE 1
								//"Then you are an enemy of Thardolin and the true Empress. Prepare yourself!"
								Say ds3004 DWARRIOR.BIN

								RunS AttackCerebellaGuards

								DrawSwordRemember
								SetChoiceToExit

							CASE 2
								//"Well, he is no friend of ours either..."
								Say ds3003 DWARRIOR.BIN
						ENDSWITCH
				ENDSWITCH

			CASE 3
				//Yarana
				Say ds3008 DWARRIOR.BIN
				Add gt_MENTION_YARANA_TO_CER_GUARDS

			CASE 4
				//Hammer
				Say ds3007 DWARRIOR.BIN

				IF !gt_MADE_FRIENDS_WITH_CER_GUARDS
					Add gt_MADE_FRIENDS_WITH_CER_GUARDS
					AwardEP xp_CER_GUARDS
					Unlock CER_GUARD1
					Unlock CER_GUARD2
					MoveCDir CER_GUARD1 pDS1A
					MoveCDir CER_GUARD2 pDS2A
					SetChoiceToExit
				ENDIF

			CASE 5
				//Cultists
				Say ds3010 DWARRIOR.BIN
		ENDSWITCH
	ENDWHILE

	IF !gt_CER_GUARD_OOPS && !gt_MADE_FRIENDS_WITH_CER_GUARDS
		MoveC P pP_BACKOFF
		UUComplete P
	ENDIF

	Widescreen FALSE
END

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

VIG TalkToCerebella MSG-iCEREBELLA

	Widescreen TRUE
	UnDrawSwordRemember
	EngageAndFace P CEREBELLA

	IF ce_CEREBELLA
		Say ce0002
	ELSE
		Add ce_CEREBELLA
		ChangeProfileToIdentified Tcitizen_Cerebella
		Say ce0001
	ENDIF

	ResetChoice
	WHILE !MenuExit
		ClearChoices

		AddChoice 1 tx0118
		AddChoice 2 txya01
		AddChoice 3 txya05
		AddChoice 4 txya04
		AddChoice 5 txya03
		AddChoice 6 txce01
		AddChoice 0 tx0003

		GetChoice CEREBELLA

		SWITCH Choice
			CASE 1
				Say ce0003

			CASE 2
				Say ce0004
				QLAdd ql031 qlt031 qlb031

			CASE 3
				Say ce0005

			CASE 4
				Say ce0006

			CASE 5
				Say ce0007

			CASE 6
				Say ce0008
				Say ce0009
		ENDSWITCH
	ENDWHILE

	Say ce0010

	Widescreen FALSE

END
/////////////////////////////////////////////////////////////////////

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

VIG DoDeathEffectChimera ONESEC && gg_FX_CHIMERA_DEATH && gg_FX_CHIMERA_DEATH<4
	AddTo gg_FX_CHIMERA_DEATH 1

	IF gg_FX_CHIMERA_DEATH=4
		FX_RevSpiritToPerson CHIMERA P 2
		AwardEP xp_DEFEAT_CHIMERA
	ENDIF
END

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