/////////////////////////////////////////////////////////////////////
// TPALACE.S		-	Thardolin Palace
/////////////////////////////////////////////////////////////////////

SETUP

	IF !gt_PLACED_TPALACE_CHARS
		Add gt_PLACED_TPALACE_CHARS

		PlaceC CEREBELLA pCEREBELLA
		PlaceC THARD_GUARD_5 pGUARD_5
		PlaceC THARD_GUARD_6 pGUARD_6
		PlaceC THARD_GUARD_11 pGUARD_11
		PlaceC THARD_GUARD_12 pGUARD_12

		EngagePoint THARD_GUARD_11 pGUARD_11 500
		AddControl THARD_GUARD_11 EngagePoint pGUARD_12 500
		AddControl THARD_GUARD_11 EngagePoint pGUARD_13 500
		AddControl THARD_GUARD_11 EngagePoint pGUARD_14 500
		SequenceRandomlySelects THARD_GUARD_11
		SwitchOnSightOfPlayer THARD_GUARD_11 AttackDemo2

		EngagePoint THARD_GUARD_12 pGUARD_11 500
		AddControl THARD_GUARD_12 EngagePoint pGUARD_12 500
		AddControl THARD_GUARD_12 EngagePoint pGUARD_13 500
		AddControl THARD_GUARD_12 EngagePoint pGUARD_14 500
		SequenceRandomlySelects THARD_GUARD_12
		SwitchOnSightOfPlayer THARD_GUARD_12 AttackDemo2

		Add gt_CUE_TPAL_GUARD_JUMP
	ENDIF

END

VIG TempSetup FALSE

    SetWeather  0 0 0 0 0 0 0 0

	FX_WaterFountain 15106 27936 2250
	AddBigFire 11264 12800
	AddBigFire 20200 15360

	CachePortrait CEREBELA.BIN
	CachePortrait CHIMERA.BIN

END

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

VIG GuardsPeaceful mj_RECOVER_CROWN && !gt_GUARDS_PEACEFUL

	Add gt_GUARDS_PEACEFUL
	SetGoodBad			THARD_GUARD_5
	SetGoodBad			THARD_GUARD_6
	SetGoodBad			THARD_GUARD_11
	SetGoodBad			THARD_GUARD_12
	StopC			THARD_GUARD_5
	StopC			THARD_GUARD_6
	StopC			THARD_GUARD_11
	StopC			THARD_GUARD_12

END

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

VIG GuardsJumpOnPlayer FIVESEC && gt_CUE_TPAL_GUARD_JUMP

	Remove gt_CUE_TPAL_GUARD_JUMP

	GiveSightOfPlayerTo	THARD_GUARD_5
	AttackDemo2			THARD_GUARD_5
	GiveSightOfPlayerTo	THARD_GUARD_6
	AttackDemo2			THARD_GUARD_6

END

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

VIG EngageIncubah HALFSEC && !gt_MET_INCUBAH && (DISTFROM-P-CEREBELLA-12 || MSG-iCEREBELLA || DAMAGED-CEREBELLA)

	SetGoodBad THARD_GUARD_11 good
	SetGoodBad THARD_GUARD_12 good
	LookAtTurnFollow THARD_GUARD_11 P
	LookAtTurnFollow THARD_GUARD_12 P

	Add gt_MET_INCUBAH

	Widescreen TRUE

	Engage P CEREBELLA 1000
	UUComplete P

	FX_BlueFireGlow pCEREBELLA
	FX_RedFireGlow pCEREBELLA
	Wait 2500

	Capture CEREBELLA cF_ARMS_WIDE_FALL
	FX_WhiteFireGlow pCEREBELLA
	Wait 2500
	PlaceC INCUBAH pCEREBELLA
	Wait 1000

	IF !f_CHIMERA_AT_WELL
		PlaceC CHIMERA pCEREBELLA
		FX_GreenFire CHIMERA
		Wait 1500
		Say Ch0001
		GiveSightOfPlayerTo CHIMERA
		AttackDemo2 CHIMERA
		Add gt_CHIMERA_AT_PALACE
	ENDIF

	AttackDemo2 INCUBAH
	ChangeProfileToIdentified Tcitizen_Cerebella
	Widescreen FALSE

END

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

VIG IncubahDead ONESEC && !mj_DEFEAT_INCUBAH && gt_MET_INCUBAH && ISDEAD-INCUBAH

	IF (f_CHIMERA_AT_WELL || ISDEAD-CHIMERA)

		QLRemove ql031
		Add mj_DEFEAT_INCUBAH

		Widescreen TRUE

		IF !gg_FX_INCUBAH_DEATH
			Set gg_FX_INCUBAH_DEATH 0
			WHILE gg_FX_INCUBAH_DEATH<4
				TryToRunS DoDeathEffectIncubah
				Wait 1
			ENDWHILE
		ENDIF

		UnDrawSwordRemember
		Freecam
		camcut pos02
		setcammoveconstant 8
		campan pos03

		Engage P CEREBELLA 250
		UUComplete P

		Say ce0011

		RunS PalFadeBLACK

		KillC THARD_GUARD_11
		KillC THARD_GUARD_12
		KillC INCUBAH
		KillC CHIMERA

		MoveCDir P pP
		MoveCDir CEREBELLA pCEREBELLA
		
		UUComplete P
		UUComplete CEREBELLA

		PlaceC THARD_GUARD_7 pGUARD_7
		PlaceC THARD_GUARD_8 pGUARD_8
		PlaceC THARD_GUARD_9 pGUARD_9
		PlaceC THARD_GUARD_10 pGUARD_10
		SetGoodBad THARD_GUARD_7 good
		SetGoodBad THARD_GUARD_8 good
		SetGoodBad THARD_GUARD_9 good
		SetGoodBad THARD_GUARD_10 good

		SetPCModel				PCstage4
		ChangeProfilePortrait P	PC4.BIN

		camcut pos05
		EngageAndFace P CEREBELLA
		RunS PalFadeRPG
		Say ce0012

		Capture CEREBELLA cF_OBJ_ACCEPT_1H1
		Capture P cM_OBJ_ACCEPT_1H1
		UUComplete P
		AwardOb P crown_rule "crown-of-rule"
		Add mj_RECOVER_CROWN
		AwardEP xp_RECOVER_CROWN
		QLRemove ql030
		QLRemove ql304

		Capture P cM_GREETING_BOW_WAIST
		UUComplete P

		Widescreen FALSE
		SetCamMoveNormal
	//	DrawSwordRemember

		SetCharSet	FAITH	FS4

		NormalCam
		camcut P
		SetCamMoveNormal

	ELSE

		IF !gg_FX_INCUBAH_DEATH
			Set gg_FX_INCUBAH_DEATH 0
		ENDIF

	ENDIF


END

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

VIG TalkToCerebella mj_DEFEAT_INCUBAH && MSG-iCEREBELLA

	Widescreen TRUE
	EngageAndFace P CEREBELLA
	UUComplete P
	Say ce0013
	Widescreen FALSE

END

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

VIG DoDeathEffectIncubah ONESEC && gg_FX_INCUBAH_DEATH && gg_FX_INCUBAH_DEATH<4
	AddTo gg_FX_INCUBAH_DEATH 1

	IF gg_FX_INCUBAH_DEATH=4
		FX_RevSpiritToPerson INCUBAH P 1
		AwardEP xp_DEFEAT_INCUBAH
	ENDIF
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
	ENDIF
END

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

VIG CueDeathEffectChimera ONESEC && gt_CHIMERA_AT_PALACE && ISDEAD-CHIMERA && !gg_FX_CHIMERA_DEATH
	AwardEP xp_DEFEAT_CHIMERA
	Set gg_FX_CHIMERA_DEATH 0
END

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