[scenario]
	id=4_Vale_of_Tears
	#textdomain wesnoth-tsg

	name= _ "Vale of Tears"
	next_scenario=5_Choice_In_The_Fog
	[music]
		name=revelation.ogg
		ms_before=500
	[/music]
	[music]
		name=knolls.ogg
		ms_before=500
		append=yes
	[/music]
	[music]
		name=elf-land.ogg
		ms_before=500
		append=yes
	[/music]

	map_data="{campaigns/The_South_Guard/maps/4_Vale_of_Tears.map}"

	{campaigns/The_South_Guard/utils/sg_deaths.cfg}

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

	{TURNS 40 32 28}
	victory_when_enemies_defeated=no


# 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 150 125 80}

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

# The Undead Hordes

[side]
	side=2
	#ifdef EASY
		type=Dark Adept
	#endif
	#ifdef MEDIUM
		type=Dark Sorcerer
	#endif
	#ifdef HARD
		type=Necromancer
	#endif
	description=Mal A'kai
	user_description= _ "Mal A'kai"

	{GOLD 70 90 120}
	{INCOME 3 5 7}

	team_name=undead
	controller=ai

	canrecruit=1
	[ai]
		recruitment_pattern=fighter,archer
		{QUANTITY aggression 0.5 0.6 0.7}
		{ATTACK_DEPTH 3 4 5}
		[target]
			description=Ethiliel
			value=3.0
		[/target]
	[/ai]
	#ifdef EASY
		recruit=Walking Corpse,Skeleton
	#endif
	#ifdef NORMAL
		recruit=Walking Corpse,Skeleton, Skeleton Archer
	#endif
	#ifdef HARD
		recruit=Walking Corpse,Skeleton, Revenant, Skeleton Archer,Bone Shooter
	#endif
[/side]

# The Bandit Army

[side]
	side=3
	type=Outlaw
	description=Jera Ilras
	user_description= _ "Jera Ilras"

	{GOLD 30 40 80}
	{INCOME 2 3 4}

	team_name=undead
	controller=ai

	canrecruit=1
	[ai]
		recruitment_pattern=fighter,scout,archer
		{QUANTITY aggression 0.2 0.3 0.4}
		[target]
			description=Ethiliel
			value=2.0
		[/target]
	[/ai]
	#ifdef EASY
		recruit=Foodpad,Poacher
	#endif
	#ifdef NORMAL
		recruit=Footpad,Thug,Poacher
	#endif
	#ifdef HARD
		recruit=Footpad,Thug,Poacher,Thief
	#endif
[/side]


#prestart
	[event]
		name=prestart

		{STARTING_VILLAGES 1 7}

	[/event]

#start
	[event]
		name=start
		[recall]
			description=Sir Gerrick
		[/recall]
		[recall]
			description=Ethiliel
		[/recall]
		[recall]
			description=Minister Hylas
		[/recall]
		[recall]
			description=Jarek
		[/recall]

		[message]
			speaker=Deoran
			message= _ "We have followed you away from our homes and left them unguarded. Now, where can we find this sage who knows the southern forest well?"
		[/message]

		[message]
			speaker=Ethiliel
			message= _ "This is the Vale of Blossoming Trees. Our great sages come here to live when they feel that it is time for them to allow others to lead our people. The sage you speak of lives in a secluded village between the two lakes."
		[/message]

		[message]
			speaker=Sir Gerrick
			message= _ "Why, my lady, are there humans camped to the south of us? Are they friends of the elves? I had thought that no humans had set foot in this valley."
		[/message]

		[message]
			speaker=Ethiliel
			image=portraits/ethiliel-mad.png
			message= _ "What!? Those are no friends of the elves! They are brigands, and they must be destroyed!"
		[/message]

		[message]
			speaker=Deoran
			message= _ "Perhaps they are allied with the bandits who have been sacking our towns! They have grown bold to attack the elves!"
		[/message]

		[message]
			speaker=Ethiliel
			message= _ "Destroy these intruders, and I will ask him to help you. He is ancient, and he remembers well Haldric's betrayal of the elves, so if a human sets foot in his village first, he almost certainly will have nothing to do with us!"
		[/message]

		[message]
			speaker=Sir Gerrick
			message= _ "Sounds like a charming fellow..."
		[/message]

		[message]
			speaker=Deoran
			message= _ "Yet, as she says, he is our best hope to rid our lands of this new menace. We do that which we must. Ethiliel, you make for Mebrin's village. We will handle the intruders."
		[/message]

		[message]
			speaker=Jera Ilras
			message= _ "Ha! You're too late. We've taken what we want from this valley. Now your blood and tears will join that of the elves!"
		[/message]

		[objectives]
			side=1
				[objective]
					description= _ "Cleanse the Vale of Tears"
					condition=win
				[/objective]
				[objective]
					description= _ "Move Ethiliel to Mebrin's village"
					condition=win
				[/objective]
				[objective]
					description= _ "Death of Deoran"
					condition=lose
				[/objective]
				[objective]
					description= _ "Death of Sir Gerrick"
					condition=lose
				[/objective]
				[objective]
					description= _ "Death of Ethiliel"
					condition=lose
				[/objective]
				[objective]
					description= _ "Time runs out"
					condition=lose
				[/objective]
		[/objectives]

	[/event]

#Ineffective Attack

[event]
	name=attack
	[filter]
		side=1
		type=Spearman, Pikeman, Halbardier, Bowman, Longbowman, Master Bowman, Horseman Commander, Lance Commander
	[/filter]
	[filter_second]
		type=Skeleton, Revenant, Deathblade, Draug, Skeleton Archer, Bone Shooter, Soul Shooter
	[/filter_second]

	[message]
		speaker=unit
		message= _ "Our weapons are useless against these skeletons! They have nothing for our shafts to pierce but air!"
	[/message]
	[message]
		speaker=Deoran
		message= _ "We must clear out these undead if you are to reach Mebrin's village! What should we do?"
	[/message]

	[message]
		speaker=Ethiliel
		message= _ "For now, I can slow them down. Where are the elves who used to live in this valley? They should come to our aid!"
	[/message]

	[message]
		speaker=Deoran
		message= _ "You said this valley would be safe, and we find it filled with skeletal foes! Cannot some of your elf friends help us in our struggle?"
	[/message]

[/event]

[event]
	name=die
	first_time_only=yes
	[filter]
		side=1
	[/filter]

	[message]
		speaker=unit
		message= _ "I shall not join these accursed undead! Bury me deeply my friends..."
	[/message]

	[message]
		speaker=Ethiliel
		message= _ "You shall not die in vain! My bodyguard will avenge you!"
	[/message]

	[message]
		speaker=Sir Gerrick
		message= _ "You have a bodyguard?!"
	[/message]

	[message]
		speaker=Deoran
		message= _ "You have a bodyguard?!!"
	[/message]

	[store_unit]
		[filter]
			description=Ethiliel
		[/filter]
		variable=ethiliel_loc
		kill=no
	[/store_unit]

	[store_locations]
		x,y=$ethiliel_loc.x,$ethiliel_loc.y
		radius=3
		[and]
			terrain=Gs^Fp
		[/and]
		variable=bodyguard_loc
	[/store_locations]

	{VARIABLE number 0}
	[while]
		[variable]
			name=number
			less_than=$bodyguard_loc.length
		[/variable]
		[variable]
			name=number
			#ifdef EASY
				less_than=4
			#endif
			#ifdef MEDIUM
				less_than=3
			#endif
			#ifdef HARD
				less_than=2
			#endif
		[/variable]
		[do]
			{VARIABLE guard_x 0}
			{VARIABLE guard_y 0}
			[set_variable]
				name=guard_x
				to_variable=bodyguard_loc[$number].x
			[/set_variable]

			[set_variable]
				name=guard_y
				to_variable=bodyguard_loc[$number].y
			[/set_variable]

			[unit]
				description=Elvish Bodyguard
				user_description= _ "Elvish Bodyguard"
				type=Elvish Ranger
				side=1
				name=Elvish Bodyguard
				x,y=$guard_x,$guard_y
			[/unit]

			{VARIABLE_OP number add 1}
		[/do]
	[/while]

	[clear_variable]
		name=bodyguard_loc
	[/clear_variable]
	[clear_variable]
		name=ethiliel_loc
	[/clear_variable]
	[clear_variable]
		name=number
	[/clear_variable]

	[message]
		speaker=Elvish Bodyguard
		message= _ "We stand ready, my lady, to protect you! We shall lead these men of Wesnoth into the fray!"
	[/message]

[/event]

[event]
	name=die
	[filter]
		type=Elvish Ranger
	[/filter]

	[message]
		speaker=unit
		message= _ "For my lady I fall..."
	[/message]

[/event]

[event]
	name=die
	[filter]
		description=Mal A'kai
	[/filter]

	[message]
		speaker=Mal A'kai
		message= _ "Finally, release! Thank you, my friends..."
	[/message]

	{VARIABLE undead_defeated "yes"}

	[if]
		[variable]
			name=mebrin_found
			equals=yes
		[/variable]
		[variable]
			name=undead_defeated
			equals=yes
		[/variable]
		[variable]
			name=bandits_defeated
			equals=yes
		[/variable]
		[then]
#			[kill]
#				type=Elvish Ranger,Elvish Avenger
#				animate=no
#				fire_event=no
#			[/kill]

			{CLEAR_VARIABLE mebrin_found}
			{CLEAR_VARIABLE undead_defeated}
			{CLEAR_VARIABLE bandits_defeated}

			[endlevel]
				result=victory
				bonus=yes
			[/endlevel]
		[/then]
	[/if]

[/event]

[event]
	name=die
	[filter]
		description=Jera Ilras
	[/filter]

	[message]
		speaker=Jera Ilras
		message= _ "You're too late! You'll never find our stronghold, and even if you did, what can you do against the dead!"
	[/message]

	[message]
		speaker=second_unit
		message= _ "You, at least, will trouble us no more!"
	[/message]

	{VARIABLE bandits_defeated "yes"}

	[if]
		[variable]
			name=mebrin_found
			equals=yes
		[/variable]
		[variable]
			name=undead_defeated
			equals=yes
		[/variable]
		[variable]
			name=bandits_defeated
			equals=yes
		[/variable]
		[then]
#			[kill]
#				type=Elvish Ranger,Elvish Avenger
#				animate=no
#				fire_event=no
#			[/kill]

			{CLEAR_VARIABLE mebrin_found}
			{CLEAR_VARIABLE undead_defeated}
			{CLEAR_VARIABLE bandits_defeated}

			[endlevel]
				result=victory
				bonus=yes
			[/endlevel]
		[/then]
	[/if]

[/event]

[event]
	name=moveto
	[filter]
		description=Ethiliel
		x,y=31,32
	[/filter]

	[message]
		speaker=Ethiliel
		message= _ "Mebrin! Are you there? We have come to seek your aid!"
	[/message]

	[message]
		speaker=narrator
		message= _ "..."
	[/message]

	[message]
		speaker=Ethiliel
		message= _ "Mebrin! Where are you?!"
	[/message]

	[message]
		speaker=narrator
		message= _ "..."
	[/message]

	[message]
		speaker=Ethiliel
		message= _ "His home is empty... There are footprints leading away to the south... What can have happened here?"
	[/message]

	[message]
		speaker=Sir Gerrick
		message= _ "Maybe whoever summoned these undead knows where he is?"
	[/message]

	[message]
		speaker=Ethiliel
		message= _ "There is no blood here, yet no Mebrin. Someone must have kidnapped him. But the undead would have slain him and made him one of them. Who then can have taken him?"
	[/message]

	[message]
		speaker=Sir Gerrick
		message= _ "Maybe the bandits who have been summoning the undead took him?"
	[/message]

	[message]
		speaker=Ethiliel
		image=portraits/ethiliel-mad.png
		message= _ "We must follow these footprints into the woods! Whoever took our greatest sage must pay! Nothing will stop the vengeance of the elves!"
	[/message]

	[message]
		speaker=Deoran
		message= _ "Well, vengeance or no, if you will lead us into the forest, we will follow you and battle the undead!"
	[/message]

	{VARIABLE mebrin_found "yes"}

	[if]
		[variable]
			name=mebrin_found
			equals=yes
		[/variable]
		[variable]
			name=undead_defeated
			equals=yes
		[/variable]
		[variable]
			name=bandits_defeated
			equals=yes
		[/variable]
		[then]
		#	[kill]
		#		type=Elvish Ranger,Elvish Avenger
		#		animate=no
		#		fire_event=no
		#	[/kill]

			{CLEAR_VARIABLE mebrin_found}
			{CLEAR_VARIABLE undead_defeated}
			{CLEAR_VARIABLE bandits_defeated}

			[endlevel]
				result=victory
				bonus=yes
			[/endlevel]
		[/then]
	[/if]

[/event]

[/scenario]
