[scenario]
	id=7b_Pebbles_In_The_Flood
	#textdomain wesnoth-tsg

	name= _ "Pebbles in the Flood"
	next_scenario=8b_The_Tides_of_War
	[music]
		name=main_menu.ogg
		ms_before=500
	[/music]

	map_data="{campaigns/The_South_Guard/maps/7b_Pebbles_In_The_Flood.map}"

	{campaigns/The_South_Guard/utils/sg_help.cfg}

	{DAWN}
	{MORNING}
	{AFTERNOON}
	{DUSK}
	{FIRST_WATCH}
	{SECOND_WATCH}

	{SG_PEBBLES_IN_THE_FLOOD}

	turns=-1
	victory_when_enemies_defeated=no
	disallow_recall=yes


# The South Guard

[side]
	side=1
	type=Horseman Commander
	description=Deoran
	user_description= _ "Deoran"
	unrenamable=yes

	team_name=South_Guard
	controller=human
	{CUSTOM_SG_FLAG}


	{GOLD 250 200 125}
	{INCOME 4 2 0}

	fog=yes
	shroud=no

	canrecruit=1
	recruit=Peasant, Bowman, Spearman, Cavalryman, Footpad, Thug
[/side]

# The Undead Hordes

[side]
	side=2
	type=Ancient Lich
	description=Mal M'Brin
	user_description= _ "Mal M'Brin"

	team_name=The_Undead_Hordes
	controller=ai

	{GOLD 150 250 350}
	{INCOME 50 75 100}

	canrecruit=1
	[ai]
		recruitment_pattern=scout, fighter, fighter, archer, scout, fighter, archer
		aggression=1.0
		caution=0.0
		[target]
			description=Sir Gerrick
			value=10.0
		[/target]
	[/ai]
	recruit=Wraith, Shadow, Skeleton, Revenant, Draug, Bone Shooter, Blood Bat, Chocobone

[/side]

[side]
	side=3
	type=Lich
	description=Mal Tera
	user_description= _ "Mal Tera"

	team_name=The_Undead_Hordes
	controller=ai

	{GOLD 200 250 300}
	{INCOME 0 0 0}

	canrecruit=1
	[ai]
		recruitment_pattern=fighter
		aggression=0.95
	[/ai]
	#ifdef EASY
		recruit=Walking Corpse
	#endif
	#ifdef MEDIUM
		recruit=Walking Corpse, Soulless
	#endif
	#ifdef HARD
		recruit=Walking Corpse, Soulless, Ghoul
	#endif

[/side]

#prestart
	[event]
		name=prestart

		[store_side]
			side=1
		[/store_side]
		{VARIABLE_OP pebbles_starting_gold to_variable side.gold}
		{CLEAR_VARIABLE side}
		{VARIABLE_OP pebbles_starting_gold multiply -1}
			[gold]
				side=1
				amount=$pebbles_starting_gold
			[/gold]
			[gold]
				side=1
				amount=200
			[/gold]
		{VARIABLE_OP pebbles_starting_gold multiply -1}

		# Sgt. Finde's Section

		{SG_GUARD Sergeant (Sgt. Finde) (_"Sgt. Finde") 1 5 11}
		{SG_GUARD Spearman (Maelvas) (_"Maelvas") 1 4 10}
		{SG_GUARD Spearman (Orome) (_"Orome") 1 5 10}
		{SG_GUARD Peasant (Mitche) (_"Mitche") 1 6 10}

		# Lt. Illan's Section

		{SG_GUARD (Lieutenant) (Lt. Illan) (_"Lt. Illan") 1 13 12}
		{SG_GUARD (Heavy Infantryman) (Rheban) (_"Rheban") 1 13 13}
		{SG_GUARD (Horseman) (Jul) (_"Jul") 1 14 12}

		# Lt. Meris' Section

		{SG_GUARD (Lieutenant) (Lt. Meris) (_"Lt. Meris") 1 35 11}
		{SG_GUARD (Peasant) (Findlas) (_"Findlas") 1 34 10}
		{SG_GUARD (Bowman) (Chumet) (_"Chumet") 1 33 10}
		{SG_GUARD (Heavy Infantryman) (Neras) (_"Neras") 1 33 11}
		{SG_GUARD (Bowman) (Eera) (_"Eera") 1 34 11}

		# Ancient Lich's Guards

		{SG_GUARD Draug (Death Guard) (_"Death Guard") 2 26 23}
		{SG_GUARD Draug (Death Guard) (_"Death Guard") 2 29 22}

	[/event]

#start
	[event]
		name=start
		[recall]
			description=Sir Gerrick
		[/recall]
		[recall]
			description=Urza Afalas
		[/recall]

		[message]
			speaker=Deoran
			message= _ "We have escaped the great forest, but look! The undead are chasing us - we must not have rooted them all out of the wood."
		[/message]
		[message]
			speaker=Sir Gerrick
			message= _ "My lord, you must hasten back to Westin to prepare a defense against them. I will command the defense of the border forts."
		[/message]
		[message]
			speaker=Urza Afalas
			message= _ "I too will make my stand here - I owe you my life and must atone for my crimes. Together we will hold off the foul undead as long as we can."
		[/message]
		[message]
			speaker=Deoran
			message= _ "I will ride to Westin and summon the council. We shall return as soon as we can in force and relieve you."
		[/message]
		[message]
			speaker=Sir Gerrick
			message= _ "Make no promises you know you cannot keep. Organize the defense of Westin, and if you survive, remember those who fell here."
		[/message]

		# Switch the leader from Deoran to Sir Gerrick
		# Thanks to "shade" for help with this!

		[store_unit]
			variable=deoran_store
			[filter]
				description=Deoran
			[/filter]
			kill=yes
		[/store_unit]

		{VARIABLE deoran_store.canrecruit 0}

		[move_unit_fake]
			type=$deoran_store.type
			x=19,19,19,19,19,18,18,18,18,17,17
			y=10,9,8,7,6,5,4,3,2,2,1
		[/move_unit_fake]

		[unstore_unit]
			variable=deoran_store
		[/unstore_unit]

		[hide_unit]
			x=19
			y=10
		[/hide_unit]

		[teleport]
			[filter]
				description=Deoran
			[/filter]
			x,y=17,1
		[/teleport]

		[unhide_unit]
		[/unhide_unit]

		[store_unit]
			variable=Sir_Gerrick_Store
			[filter]
				description=Sir Gerrick
			[/filter]
			kill=no
		[/store_unit]

		{VARIABLE Sir_Gerrick_Store.canrecruit 1}

		[unstore_unit]
			variable=Sir_Gerrick_Store
		[/unstore_unit]

		{CLEAR_VARIABLE Sir_Gerrick_Store}

		[message]
			id=sg_7_intro_6
			speaker=Deoran
			message= _ "Your name will be sounded in the roll of heroes, and you will be avenged. Thank you, my friend."
		[/message]

		[store_unit]
			variable=deoran_store
			[filter]
				description=Deoran
			[/filter]
			kill=yes
		[/store_unit]

		[message]
			speaker=Lt. Illan
			message= _ "We are yours to command, Sir Gerrick. Our men are not the great warriors that you and Deoran are, but we will hold our lines staunchly, until the bitter end."
		[/message]

		[objectives]
			side=1
				[objective]
					description= _ "Hold the line: Keep Sir Gerrick alive as long as possible"
					condition=win
				[/objective]
		[/objectives]

		[message]
			speaker=narrator
			message= _ "There is no way to win this scenario, and no way to lose. Hold off the undead hordes as long as you can. Keep Sir Gerrick alive as long as you can. Every turn that passes strengthens the defenses of Westin."
		[/message]
	[/event]

[event]
	name=die
	[filter]
		side=2
	[/filter]
	[gold]
		side=2
		#ifdef EASY
			amount=50
		#endif
		#ifdef MEDIUM
			amount=75
		#endif
		#ifdef HARD
			amount=125
		#endif
	[/gold]
[/event]

[event]
	name=die
	[filter]
		description=Urza Afalas
	[/filter]

	[message]
		speaker=Urza Afalas
		message= _ "Now I will never see my home again... Hold back the undead, Gerrick!"
	[/message]
[/event]

[event]
	name=die
	[filter]
		description=Sir Gerrick
	[/filter]

	[message]
		speaker=Sir Gerrick
		message= _ "I only hope we have bought Deoran enough time to secure Westin for the onslaught!"
	[/message]
	[message]
		speaker=Mal M'Brin
		message= _ "We will crush Westin as we have crushed you! No one shall stand between us and our home."
	[/message]

	{VARIABLE sg_length_of_defense $turn_number}

	#make all units unrecruitable for the next scenario

	[store_unit]
		[filter]
			side=1
			x=1-40
			y=1-25
		[/filter]

		kill=yes
		variable=temp
	[/store_unit]

	{CLEAR_VARIABLE temp}

	[endlevel]
		result=continue
	[/endlevel]
[/event]

[/scenario]
