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

	name= _ "Into The Depths"
	next_scenario=8a_Vengeance
	[music]
		name=underground.ogg
		ms_before=500
	[/music]
	[music]
		name=knolls.ogg
		ms_before=500
		append=yes
	 [/music]

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

	{campaigns/The_South_Guard/utils/sg_deaths.cfg}

	{UNDERGROUND}

	victory_when_enemies_defeated=no
	{TURNS 50 40 36}


# 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}


	fog=yes
	shroud=yes

	{GOLD 125 100 80}
	{INCOME 10 8 6}

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

# The Undead Hordes

[side]
	side=2
	#ifdef EASY
		type=Lich
	#endif
	#ifdef MEDIUM
		type=Lich
	#endif
	#ifdef HARD
		type=Ancient Lich
	#endif
	description=Mal M'Brin
	user_description= _ "Mal M'Brin"
	profile=portraits/blue-lich.png

	team_name=undead_hordes
	controller=ai

	{GOLD 50 70 100}
	{INCOME 1 2 4}

	canrecruit=1
	[ai]		recruitment_pattern=fighter, mixed fighter
		aggression=0.2
	[/ai]

	#ifdef EASY
		recruit=Skeleton, Vampire Bat
	#endif

	#ifdef NORMAL
		recruit=Skeleton, Ghost, Vampire Bat
	#endif

	#ifdef HARD
		recruit=Deathblade, Ghost, Wraith, Shadow
	#endif
[/side]

# Friendly Trolls

[side]
	side=3
	type=Troll Hero
	description=Grée
	user_description= _ "Grée"

	team_name=trolls
	controller=ai

	{GOLD 30 40 60}
	{INCOME 1 2 4}

	canrecruit=1
	[ai]
		recruitment_pattern=fighter
		aggression=0.2
	[/ai]

	#ifdef EASY
		recruit=Troll, Troll Rocklobber
	#endif

	#ifdef NORMAL
		recruit=Troll Whelp
	#endif

	#ifdef HARD
		recruit=Troll Whelp
	#endif
[/side]

# Scenario Setup

[event]
	name=prestart
	[recall]
		description=Ethiliel
	[/recall]
	[recall]
		description=Minister Hylas
	[/recall]
[/event]

# Scenario Beginning

[event]
	name=start

	[message]
		speaker=Deoran
		message= _ "My mount will not help me in these rocky paths - I will leave him here at the entrance and proceed on foot."
	[/message]
	[message]
		speaker=Ethiliel
		message= _ "That is wise. Speed is less valuable in caves than toughness."
	[/message]

	#ifdef EASY
		[message]
			speaker=narrator
			message= _ "Cavalrymen and Dragoons will be less useful in the caves than soldiers who fight on foot."
		[/message]
		[message]
			speaker=narrator
			message= _ "Also, soldiers with the -quick- trait will be useful in the dark."
		[/message]
	#endif

	# Transform Deoran into a Foot Commander - thanks to Shadow for the graphics!

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

	[delay]
		time=100
	[/delay]

	[set_variable]
		name=deoran_store.hitpoints
		value=60
	[/set_variable]

	[if]
		[variable]
			name=deoran_store.type
			equals=Horseman Commander
		[/variable]
		[then]
			[set_variable]
				name=deoran_store.type
				value=Dismounted Commander
			[/set_variable]
			[set_variable]
				name=mounted_deoran_unit_type
				value=Horseman Commander
			[/set_variable]
		[/then]
		[else]
			[set_variable]
				name=deoran_store.type
				value=Dismounted Commander
			[/set_variable]
			[set_variable]
				name=mounted_deoran_unit_type
				value=Lancer Commander
			[/set_variable]
		[/else]
	[/if]

	[unstore_unit]
		variable=deoran_store
		find_vacant=yes
	[/unstore_unit]

	{CLEAR_VARIABLE deoran_store}

	[message]
		speaker=Ethiliel
		message= _ "Proceed slowly, who knows what evils inhabited these parts before Mebrin was turned! We cannot be too careful."
	[/message]

	[objectives]
		side=1
			[objective]
				description= _ "Find the source of the undead under the citadel."
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Deoran"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Ethiliel"
				condition=lose
			[/objective]
			[objective]
				description= _ "Time runs out"
				condition=lose
			[/objective]
	[/objectives]

[/event]

# The road is blocked...

[event]
	name=moveto
	[filter]
		side=1
		x=8,9
		y=6
	[/filter]

	[message]
		speaker=unit
		message= _ "It seems that the old dwarven road has fallen into disrepair! The stream cuts the path."
	[/message]
	[message]
		speaker=Minister Hylas
		message= _ "Perhaps we can cross on the ice?"
	[/message]
	[message]
		speaker=Deoran
		message= _ "It looks thin - tread carefully."
	[/message]
[/event]

[event]
	name=moveto
	[filter]
		side=1
		x=10-18
		y=7-11
	[/filter]

	[scroll]
		x,y=5,5
	[/scroll]
	[scroll]
		x,y=-5,-5
	[/scroll]
	[scroll]
		x,y=5,5
	[/scroll]
	[scroll]
		x,y=-5,-5
	[/scroll]
	{SG_CHANGE_TERRAIN 10 6 Wo}

	[message]
		speaker=unit
		message= _ "The ice is collapsing! I'll be trapped!"
	[/message]
	[message]
		speaker=Deoran
		message= _ "We have nothing suitable to make a bridge - you will have to explore that side of the stream and see where the road leads."
	[/message]

	[message]
		speaker=Ethiliel
		message= _ "The ice to the south seems thicker. We should head that way!"
	[/message]
[/event]

[event]
	name=moveto
	[filter]
		side=1
		x=15-18
		y=9-11
	[/filter]

	[message]
		speaker=unit
		message= _ "Look! Rocks have fallen and collapsed the old dwarven road. I'm stuck!"
	[/message]
	[message]
		speaker=Deoran
		message= _ "We'll find a way to rescue you, don't worry."
	[/message]
[/event]

[event]
	name=sighted
	[filter]
		side=3
	[/filter]

	[message]
		speaker=Grée
		message= _ "Ha! Humans and Elves! What are you doing in our caves, and why shouldn't we grind your bones and gnaw on your flesh?"
	[/message]

	[message]
		speaker=Deoran
		message= _ "We mean no trespass. We are hunting the undead."
	[/message]

	[message]
		speaker=Grée
		message= _ "Undead! Ha! We kill undead all the time. Why should we help you?"
	[/message]

	[message]
		speaker=Deoran
		message= _ "What should we offer them for their help?"
		[option]
			id=offer_money
			#ifdef EASY
				message= _ "We will give you 50 gold pieces once the undead are defeated."
			#endif
			#ifdef MEDIUM
				message= _ "We will give you 75 gold pieces once the undead are defeated."
			#endif
			#ifdef HARD
				message= _ "We will give you 100 gold pieces once the undead are defeated."
			#endif

			[command]
				[remove_shroud]
					side=1
					x,y=1-35,1-30
				[/remove_shroud]
				[modify_side]
					side=3
					team_name=South_Guard
				[/modify_side]
				{PLACE_IMAGE (items/gohere.png) 29 24}
				[message]
					speaker=Grée
					message= _ "Gold is good. We can trade gold for weapons and fire. We will not kill you now."
				[/message]
				[message]
					speaker=Deoran
					message= _ "Can you offer us any aid against the undead? We are not well suited to fighting in the caves."
				[/message]
				[message]
					speaker=Grée
					message= _ "Gah! We already planned to kill the undead ourselves... First we kill dwarves though! Now we have dwarvish thunder fire."
				[/message]
				[message]
					speaker=Grée
					message= _ "Go here and light it and it will blast a backdoor into the lich's lair!"
				[/message]
				[scroll_to]
					x,y=29,24
				[/scroll_to]

				{VARIABLE bomb_placed true}
				{VARIABLE troll_allies true}

			[/command]
		[/option]

		[option]
			id=offer_freedom
			message= _ "We will offer you freedom and a place in our lands."
			[command]
				[message]
					speaker=Grée
					message= _ "Ha! Who wants peace and freedom! We want blood!"
				[/message]
				[message]
					speaker=Minister Hylas
					message= _ "Then you will not treat with us and aid us in our quest to destroy the undead menace?"
				[/message]
				[message]
					speaker=Grée
					message= _ "Bah! Grind their bones!"
				[/message]
			[/command]
		[/option]
	[/message]
[/event]

[event]
	name=moveto
	[filter]
		side=1
		x,y=29,24
	[/filter]


	{SG_IF bomb_placed}

	[message]
		speaker=unit
		message= _ "I'm lighting it!"
	[/message]
	[sound]
		name=fire.wav
	[/sound]
	[sound]
		name=fire.wav
	[/sound]

	[scroll]
		x,y=10,10
	[/scroll]
	[scroll]
		x,y=-10,-10
	[/scroll]
	[scroll]
		x,y=10,10
	[/scroll]
	[scroll]
		x,y=-10,-10
	[/scroll]
	{SG_CHANGE_TERRAIN 28 23 Re}

	[message]
		speaker=unit
		message= _ "I've broken through!"
	[/message]

	[removeitem]
		x,y=29,24
	[/removeitem]

	{SG_END_IF}

[/event]

# Confrontation with Mal Brin
[event]
	name=moveto
	[filter]
		side=1
		x,y=28,23
	[/filter]

	[message]
		speaker=Mal M'Brin
		message= _ "Petty mortals, bow down and cower in fear before me, and I may make your passing swift. For I was once one such as you, full of doubt and weakness, but now I have passed over and become more than you could possibly imagine."
	[/message]
	[message]
		speaker=Deoran
		image=portraits/deoran-mad.png
		message= _ "For all your vaunted powers you are a mockery to all that you once believed in. I will destroy you and your works if it's the last thing I do!"
	[/message]
	[message]
		speaker=Mal M'Brin
		message= _ "Foolish boy! you do not understand. Come closer and I will show you my power. I will end your brief, miserable life. Thereafter, it may amuse me to cause your bones to serve me."
	[/message]
[/event]

[event]
	name=die
	[filter]
		description=Mal M'Brin
	[/filter]
	[set_variable]
		name=undead_dead
		value=true
	[/set_variable]
	[message]
		speaker=Mal M'Brin
		message= _ "Nooo! This cannot be. The elves I once led have destroyed me. After all I have sacrificed, I still die...."
	[/message]
        [if]
                [variable]
                        name=troll_dead
			equals=true
                [/variable]
                [then]
                        [endlevel]
                                result=victory
                                bonus=no
                        [/endlevel]
                [/then]
        [/if]
	[if]
		[variable]
			name=troll_allies
			equals=true
		[/variable]
		[then]

			[message]
				speaker=Grée
				message= _ "Gah! The undead are dead again! Now you'd better pay up!"
			[/message]

			[store_side]
				side=1
			[/store_side]

			[if]
				[variable]
					name=side.gold
					#ifdef EASY
						greater_than_equal_to=50
					#endif
					#ifdef MEDIUM
						greater_than_equal_to=75
					#endif
					#ifdef HARD
						greater_than_equal_to=100
					#endif
				[/variable]
				[then]
					[gold]
						side=1
						#ifdef EASY
							amount=-50
						#endif
						#ifdef MEDIUM
							amount=-75
						#endif
						#ifdef HARD
							amount=-100
						#endif
					[/gold]

					[message]
						speaker=Deoran
						message= _ "Here is your reward. Now we will leave your caves in peace."
					[/message]
					[message]
						speaker=Grée
						message= _ "I suppose we will not kill you, but do not try your luck again!"
					[/message]
					[endlevel]
						result=victory
						bonus=no
					[/endlevel]

				[/then]
				[else]
					[message]
						speaker=Grée
						message= _ "You don't have the gold to pay us! Now we will grind your bones into dust!"
					[/message]
					[modify_side]
						side=3
						team_name=trolls
					[/modify_side]
				[/else]
			[/if]
		[/then]
	[/if]
	{CLEAR_VARIABLE bomb_placed}
	{CLEAR_VARIABLE troll_allies}

[/event]

[event]
        name=die
        [filter]
                description=Grée
        [/filter]
	[set_variable]
		name=troll_dead
		value=true
	[/set_variable]
	[if]
		[variable]
			name=undead_dead
			value=true
		[/variable]
		[then]
			[endlevel]
				result=victory
				bonus=no
			[/endlevel]
		[/then]
	[/if]
	{CLEAR_VARIABLE bomb_placed}
	{CLEAR_VARIABLE troll_allies}
[/event]

[/scenario]
