/////////////////////////////////////////////////////////////////////
// MARKET.S
/////////////////////////////////////////////////////////////////////

SETUP

	IF !gt_CLEAR_MINES && mj_FREED_FARMERS
		Add gt_CLEAR_MINES
	ENDIF

	IF !mj_SLEPT_AT_ANDRUS
		IF INAREA-P-narch_in && !gd_DONE_PUB && !gd_PLACED_BARTH
			PlaceC BARTH pMM_BART_START1
			Add gd_PLACED_BARTH

			MoveC BARTH PCHANT_OUTSIDE
		ENDIF
		IF INAREA-P-earch_in && !gd_DONE_PUB && !gd_PLACED_BARTH
			PlaceC BARTH pMM_BART_START2
			Add gd_PLACED_BARTH

			MoveC BARTH pMM_BARTH1
		ENDIF
	ENDIF
    IF gd_DONE_PUB && gd_PLACED_BARTH
        RemoveC BARTH
        Remove  gd_PLACED_BARTH
    ENDIF

	// patrolling guard
	IF !f_ANDRUS_DEAD
		IF !gt_PLACED_MG_PATB
			Add gt_PLACED_MG_PATB
			PlaceC MG_PATB pMG_PAT1
			RunS MadGuardPatrolBOrders
		ENDIF
	ELSE
		IF gt_PLACED_MG_PATB
			Remove gt_PLACED_MG_PATB
			KillC  MG_PATB
		ENDIF
	ENDIF
	IF mj_FREED_FARMERS
		IF !gt_PLACED_MAD_FARMER_3
			Add gt_PLACED_MAD_FARMER_3
			PlaceC MAD_FARMER_4 pMADF_4
			Wander MAD_FARMER_4
		ENDIF
	ENDIF
	IF mj_DEFEAT_GARGOS_2
		IF !gt_PLACED_THARD_MAD_MERCHANTS
			Add gt_PLACED_THARD_MAD_MERCHANTS
			PlaceC THARD_MAD_MER_4 pMG_PAT4
			PlaceC THARD_MAD_MER_5 pMADF_3
			PlaceC THARD_MAD_MER_6 pMADF_4
			WanderNotFar THARD_MAD_MER_4
			WanderNotFar THARD_MAD_MER_5
			WanderNotFar THARD_MAD_MER_6
		ENDIF
        IF !gd_PLACED_MM_DRAGONS
            PlaceC              MM_DRAGON_1 pMM_DRAGON_1A
            RunS                MM_Setup_Dragon_1

            PlaceC              MM_DRAGON_2 pMM_DRAGON_2
            RunS                MM_Setup_Dragon_2

            Add gd_PLACED_MM_DRAGONS

        ENDIF
	ENDIF
	IF mj_RECOVER_CROWN
		//bug fix for B2.3 (or whatever)
		KillC MAD_FARMER_4
		KillC  MM_DRAGON_1
		KillC  MM_DRAGON_2
	ENDIF

	IF !gt_RECENT_MUSIC_IN_MADRIGAL
		Add gt_RECENT_MUSIC_IN_MADRIGAL
		PlayMusic RPG18.WAV
	ENDIF

END

VIG TempSetup FALSE

	RunS AndrusWeather
	Set gd_WIND_TYPE	1
    RunS CueWeather

	CachePortrait BARTH.BIN
	CachePortrait ADDEPUTY.BIN
	CachePortrait PC1.BIN

END

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

VIG TradeWithMerchant_4 MSG-iTHARD_MAD_MER_4

	widescreen TRUE
	QuickSay me1004 MERCHNT1.BIN
	EngageAndFace P THARD_MAD_MER_4
	UUSay
	MessagesOff
	ShopPanel MM_A_SHOP 125 50 THARD_MAD_MER_4 BUYSELL
	MessagesOn
	Say me1001 MERCHNT1.BIN
	widescreen FALSE

END

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

VIG TradeWithMerchant_5 MSG-iTHARD_MAD_MER_5

	widescreen TRUE
	QuickSay me2002 MERCHNT2.BIN
	EngageAndFace P THARD_MAD_MER_5
	UUSay
	MessagesOff
	ShopPanel MM_G_SHOP 125 50 THARD_MAD_MER_5 BUYSELL
	MessagesOn
	Say me2015 MERCHNT2.BIN
	widescreen FALSE

END

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

VIG TradeWithMerchant_6 MSG-iTHARD_MAD_MER_6

	widescreen TRUE
	QuickSay me3001 MERCHNT3.BIN
	EngageAndFace P THARD_MAD_MER_6
	UUSay
	MessagesOff
	ShopPanel MM_S_SHOP 125 50 THARD_MAD_MER_6 BUYSELL
	MessagesOn
	Say me3012 MERCHNT3.BIN
	widescreen FALSE

END

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

VIG MM_Setup_Dragon_1   FALSE
    WanderNotFar        MM_DRAGON_1 9 13
	AddFilter			MM_DRAGON_1 CompletesOnDamaged
	AddControl			MM_DRAGON_1 MeleeAttackBLands
END

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

VIG MM_Setup_Dragon_2   FALSE
    WanderNotFar        MM_DRAGON_2 9 13
	AddFilter			MM_DRAGON_2 CompletesOnDamaged
	AddControl			MM_DRAGON_2 MeleeAttackBLands
END

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

VIG TalkToMMDragon1 MSG-iMM_DRAGON_1
	Widescreen TRUE
    StopC           MM_DRAGON_1
    EngageAndFace   MM_DRAGON_1 P
    RunS            TalkToDragonWarrior
    RunS            MM_Setup_Dragon_1
	Widescreen FALSE
END

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

VIG TalkToMMDragon2 MSG-iMM_DRAGON_2
	Widescreen TRUE
    StopC           MM_DRAGON_2
    EngageAndFace   MM_DRAGON_2 P
    RunS            TalkToDragonWarrior
    RunS            MM_Setup_Dragon_2
	Widescreen FALSE
END

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

VIG TalkToMadFarmer_4 MSG-iMAD_FARMER_4

	Widescreen TRUE
	StopC MAD_FARMER_3
	EngageAndFace P MAD_FARMER_3

	IF mj_DEFEAT_GARGOS_2
		Say fam304 farmerm3.bin
	ELSE
		//"Good day to you. You're well, I hope?"
		IF LANG-English || LANG-German
			Say fa8001 FARMERM3.BIN
		ELSE
			Say fa1003 farmerm3.bin
		ENDIF
	ENDIF

	Wander MAD_FARMER_3
	Widescreen FALSE

END

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

VIG MG_PATB_Attacked ONESEC && !gt_MG_PATB_FIGHT && DAMAGED-MG_PATB

	Add gt_MG_PATB_FIGHT
	RunS MadGuardPatrolBOrders

END

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

VIG MadGuardPatrolBOrders FALSE

	MoveC MG_PATB pMG_PAT1
	AddControl MG_PATB MoveC pMG_PAT2
	AddControl MG_PATB MoveC pMG_PAT3
	AddControl MG_PATB MoveC pMG_PAT4
	AddControl	MG_PATB	Capture	cM_GUARD_STAND1
	AddControl	MG_PATB	Capture	cM_GUARD_STAND2
	AddControl	MG_PATB	Capture	cM_GUARD_STAND3
	SequenceRandomlySelects MG_PATB

	IF gt_MG_PATB_FIGHT
		SwitchOnSightOfPlayer MG_PATB AttackDemo2
	ELSE
		SwitchOnSightOfPlayer MG_PATB LookAtTurnFollow P
	ENDIF

END

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

VIG TalkToMadGuardPatrolB MSG-iMG_PATB && !gt_MG_PATB_FIGHT

	LookAtTurn MG_PATB P
	UUComplete MG_PATB
	IF mj_SLEPT_AT_ANDRUS
		//"Everything's in order here...any questions...Elric..."
		Say mg0008 ADDEPUTY.BIN
	ELSE
		//"You'd best get indoors...brigands...inside the town..."
		Say mg0001 ADDEPUTY.BIN
	ENDIF
	RunS MadGuardPatrolBOrders
END

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

VIG	BarthInPub HALFSEC && !gd_DONE_PUB && INAREA-BARTH-pub_in && !DISTFROM-P-BARTH-5
	Add gd_DONE_PUB
	//PhotoOn
	MoveC_1tel BARTH MM_FRONT i_ENTER_INN
END

VIG BarthGoingToPub2 gd_PLACED_BARTH=1 && INAREA-BARTH-barth_1
    AddTo     gd_PLACED_BARTH   1
	MoveC BARTH PCHANT_OUTSIDE
END

VIG BarthGoingToPub gd_PLACED_BARTH=0 && INAREA-BARTH-barth_2
    AddTo     gd_PLACED_BARTH   1
    MoveC   BARTH   pMM_BART_START1
END

VIG	EnterPub !gd_DONE_PUB && INAREA-P-pub_in && gd_PLACED_BARTH

    //StopC   P
	Widescreen TRUE
	LookAtTurnFollow P BARTH

	MoveC       BARTH pMM_BARTH_STOPP
	AddControl	BARTH LookAtTurn P
	UUComplete  BARTH

    Capture     BARTH   cM_TALK_THREATEN1
	Say         ba9000 BARTH.BIN
	UUComplete  BARTH

	MoveC       P       pCHANT_OUTSIDE
	MoveC       BARTH   pMM_BARTH_ENTERINN
    UUComplete  BARTH

	Face        P       BARTH
    Capture     P       CM_TALK_QUESTION1
	Say         hx9000

	Say         ba9001 BARTH.BIN
	MoveC_1tel  BARTH   MM_FRONT    i_ENTER_INN
	Wait        2000

	Say         hx9001
	//PhotoOff
	Widescreen FALSE

	Add gd_DONE_PUB

END

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

VIG RemoveBartFromLimbo gd_DONE_PUB && !gg_REMOVE_BART_FROM_LIMBO && !ONMAP-BARTH
	Add gg_REMOVE_BART_FROM_LIMBO
	RemoveC BARTH
END

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

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

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

VIG FlyBy FALSE

	Widescreen TRUE

	// *** EXAMPLE CAMERA FLY-BY CODE ***

	// use Wait at start and end to help when editing the final recording
	// use UUCameraComplete to wait for a pan to finish
	// use SetCamMoveConstant to set camera movement per frame
	//     - remember the movie is played at 25fps no matter how slow it records

	SetCamMoveConstant 20
	FreeCam
	PhotoOn

	camcut flyby01

	campan flyby02
	UUCameraComplete

	SetCamMoveConstant 30
	
	camcut flyby03

	campan flyby04
	UUCameraComplete

	campan flyby05
	UUCameraComplete

	PhotoOff

	// *** END OF FLY-BY ***

	Widescreen FALSE

END

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

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

