[scenario]
	id=5_Choice_In_The_Fog
	#textdomain wesnoth-tsg

	name= _ "Choice in the Fog"
	next_scenario=6a_Tidings_Good_And_Ill
	[music]
		name=underground.ogg
		ms_before=500
	[/music]
	# music changes when bandits are encountered


	map_data="{campaigns/The_South_Guard/maps/5_Choice_In_The_Fog.map}"

	{campaigns/The_South_Guard/utils/sg_deaths.cfg}

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

	{SG_CHOICE_IN_THE_FOG}

	victory_when_enemies_defeated=yes
	{TURNS 50 40 35}


[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}
	{INCOME 6 4 2}

	#ifdef EASY
		fog=yes
		shroud=no
	#endif
	#ifdef MEDIUM
		fog=yes
		shroud=yes
	#endif
	#ifdef HARD
		fog=yes
		shroud=yes
	#endif

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

# The Bandit Armies

[side]
	side=2
	type=Outlaw
	description=Urza Afalas
	user_description= _ "Urza Afalas"
	profile=portraits/urza-afalas-masked.png

	{GOLD 50 70 90}
	{INCOME 2 3 5}

	team_name=bandits
	controller=ai

	canrecruit=1
	[ai]
		recruitment_pattern= fighter, scout, scout
		{QUANTITY aggression 0.3 0.4 0.5}
		{ATTACK_DEPTH 3 4 5}
	[/ai]
	#ifdef EASY
		recruit=Thug
	#endif

	#ifdef NORMAL
		recruit=Footpad, Thug
	#endif

	#ifdef HARD
		recruit=Footpad,Thug, Outlaw, Bandit
	#endif

[/side]

# The Undead Hordes

[side]
	side=3
	type=Soulless
	description=Gruth
	user_description= _ "Gruth"

	team_name=undead
	controller=ai

	{GOLD 30 50 80}
	{INCOME 5 10 15}

	canrecruit=1
	[ai]
		recruitment_pattern=fighter
		{NO_SCOUTS}
		{ATTACK_DEPTH 1 2 3}
	[/ai]

	#ifdef EASY
		recruit=Walking Corpse
	#endif
	#ifdef NORMAL
		recruit=Walking Corpse, Soulless
	#endif
	#ifdef HARD
		recruit=Walking Corpse, Soulless, Ghoul
	#endif

[/side]

# The Undead Hordes

[side]
	side=4
	type=Lich
	description=Mal M'brin
	user_description= _ "Mal M'brin"
	profile=portraits/blue-lich.png

	team_name=undead
	controller=ai

	{GOLD 60 90 120}
	{INCOME 3 5 6}

	canrecruit=1
	[ai]
		recruitment_pattern=fighter,archer
		{QUANTITY aggression 0.2 0.4 0.6}
		{NO_SCOUTS}
		{ATTACK_DEPTH 3 4 5}
	[/ai]
	#ifdef EASY
		recruit=Skeleton, Skeleton Archer, Ghoul
	#endif
	#ifdef NORMAL
		recruit=Skeleton, Revenant, Deathblade, Skeleton Archer, Ghoul
	#endif
	#ifdef HARD
		recruit=Skeleton, Revenant, Deathblade, Skeleton Archer, Bone Shooter, Ghoul
	#endif

[/side]

# Scenario Prestart

[event]
	name=prestart
	[store_unit]
		[filter]
			description=Urza Afalas
		[/filter]
		variable=urza_store
	[/store_unit]

# Prevent the Bandit leader from moving so his sighted event will fire correctly
	{VARIABLE urza_store.movement_costs.castle 20}
	{VARIABLE urza_store.movement_costs.grassland 20}
	{VARIABLE urza_store.movement_costs.forest 30}
	{VARIABLE urza_store.movement_costs.shallow_water 80}
	[unstore_unit]
		variable=urza_store
	[/unstore_unit]
	{CLEAR_VARIABLE urza_store}
[/event]

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

	[message]
		description=Deoran
		image=portraits/deoran-mad.png
		message= _ "The heat in this forest is oppressive, and this fog cannot be natural. I wonder what evil lurks nearby?"
	[/message]

	[message]
		description=Minister Hylas
		message= _ "I fear the fog emanates from some powerful lord of the undead. We may be overmatched..."
	[/message]

	[message]
		description=Sir Gerrick
		message= _ "This is quite a change from fighting bandits in the farmland near Westin!"
	[/message]

	[message]
		description=Ethiliel
		message= _ "I have brought many of my people along to aid us. My soldiers and shamans will now fight at your command."
	[/message]
	#ifdef EASY
		[message]
			speaker=narrator
			image="elves-wood/fighter-melee-2.png~TC(1,magenta)"
			message= _ "Elvish Fighters are at home in the thick forests. They have both a sword and a bow and are deadly with both. They are quick and can hold their own against just about anything."
		[/message]
		[message]
			speaker=narrator
			image="elves-wood/shaman-heal7.png~TC(1,magenta)"
			message= _ "Elvish Shamans are no match for most enemies in single combat. They do, however, heal units next to them every turn. Use them to bolster your weakening lines and heal wounded soldiers."
		[/message]
	#endif
	[message]
		description=Deoran
		message= _ "Why did we stop and make camp here?"
	[/message]

	[message]
		description=Ethiliel
		message= _ "The great river is before us. No elf, still living, has crossed it. If the undead come from across the river, then we must search for them carefully, for I know not the way."
	[/message]

	[message]
		description=Sir Gerrick
		message= _ "I fear no forests. Let us find this river and whatever enemies lie beyond."
	[/message]

	[message]
		description=Deoran
		message= _ "Very well. We will seek the river and probe its secrets."
	[/message]

	[objectives]
		side=1
			[objective]
				description= _ "Investigate the areas to the south of the Great River"
				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]

# The adventurers defeat the zombie leader

[event]
	name=die
	[filter]
		description=Gruth
	[/filter]

	[message]
		description=second_unit
		message= _ "The master of the undead is defeated!"
	[/message]

	[message]
		description=Dorean
		message= _ "No. I fear there is still much evil present. That must have been merely a servant of a darker master."
	[/message]

[/event]

# The adventurers locate the bandits: a choice must be made

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

	[redraw]
	[/redraw]
	
	[music]
		immediate=yes
		name=knolls.ogg
		ms_before=500
	[/music]
	[music]
		name=wanderer.ogg
		ms_before=500
		append=yes
	[/music]
	[message]
		description=Urza Afalas
		message= _ "Thank heaven! You're alive!"
	[/message]

	[message]
		description=Ethiliel
		message= _ "Save your thanks! We are here to root out all the evil from these woods, and that means you!"
	[/message]

	[message]
		description=Sir Gerrick
		message= _ "Draw your swords and say your prayers! You cannot stand against us! You will pay for your crimes!"
	[/message]

	[message]
		description=Urza Afalas
		message= _ "But have you not seen the undead in these forests? I know you have seen them under the control of the many bandit leaders before..."
	[/message]

	[message]
		description=Deoran
		message= _ "What of them?"
	[/message]

	[message]
		description=Urza Afalas
		message= _ "A year ago we ventured into the land of the elves in secret, and we captured a great sage. We forced him to teach us the secrets of this forest and of the undead."
	[/message]

	[message]
		description=Ethiliel
		message= _ "You imprisoned Mebrin!? For that you must surely pay. Speak swiftly so that we may end this parlay and dispatch you quickly! We will have vengeance!"
	[/message]

	[message]
		description=Urza Afalas
		message= _ "Hear me out! He taught us to summon the dead to fight for us. We were weak and foolish and soon summoned undead that we could not control. Mebrin too fell sway to the influence of the undead, and now he leads them. For a time he served us, but now he has gone mad and is attacking us as well!"
	[/message]

	[message]
		description=Ethiliel
		image=portraits/ethiliel-mad.png
		message= _ "Lies! Mebrin would never fight for the undead, much less lead them!"
	[/message]

	[message]
		description=Deoran
		message= _ "But what do you want us to do about it? You are criminals!"
	[/message]

	[message]
		description=Urza Afalas
		message= _ "Join us in the fight! Together we can drive off these cruel undead and restore peace to the land."
	[/message]

	[message]
		description=Sir Gerrick
		message= _ "My lord, they could be valuable allies, and the undead are a greater threat to our lands. Justice can wait until we are all safely in Westin."
	[/message]

	[message]
		description=Ethiliel
		image=portraits/ethiliel-mad.png
		message= _ "But think of the destruction they wrought on your borders! You cannot ally yourselves with these evil men! Vengeance!"
	[/message]

	[message]
		description=Deoran
		message= _ "Hmm...I have to consider this..."
		[option]
			id=accept_bandits
			message= _ "Very well. All men must unite against the undead."
			[command]
				[kill]
					side=2
					description=Urza Afalas
					animate=no
					fire_event=no
				[/kill]

				[scroll_to]
					x,y=40,20
				[/scroll_to]

				[sound]
					name=fanfare-short.wav
				[/sound]

				[move_unit_fake]
					type=Outlaw
					x=40,30
					y=20,28
				[/move_unit_fake]

				[unit]
					description=Urza Afalas
					user_description= _ "Urza Afalas"
					type=Outlaw
					side=1
					{IS_HERO}
					x=30
					y=28
					[modifications]
						{TRAIT_RESILIENT}
						{TRAIT_INTELLIGENT}
					[/modifications]
				[/unit]

				[redraw]
				[/redraw]

				[message]
					description=Urza Afalas
					message= _ "We will now fight alongside you, come my thugs and footpads, rally to me!"
				[/message]

				[message]
					description=Ethiliel
					image=portraits/ethiliel-mad.png
					message= _ "You are no better than these criminals! We shall see if you can find your own way out of the forest! Come my people let us return to our lands. We were foolish to ever have any dealings with these humans. Do not set foot in our land ever again Deoran, you have brought us nothing but grief."
				[/message]

				[kill]
					side=1
					race=elf
					animate=no
					fire_event=no
				[/kill]

				[message]
					description=Sir Gerrick
					message= _ "The elves have abandoned us in this accursed forest! We are surely lost!"
				[/message]

				[message]
					description=Urza Afalas
					message= _ "Do not fear, I can lead you out when the time is right."
				[/message]

				[set_variable]
					name=side_with_bandits
					value=yes
				[/set_variable]

				[allow_recruit]
					side=1
					type=Thug,Footpad
				[/allow_recruit]

				[disallow_recruit]
					side=1
					type=Elvish Shaman,Elvish Fighter
				[/disallow_recruit]

# switch the outlaws to your direct control
				[while]
					[have_unit]
						side=2
					[/have_unit]

					[do]
						[store_unit]
							[filter]
								side=2
							[/filter]
							variable=unitstats
						[/store_unit]

						[set_variable]
							name=unitstats.side
							value=1
						[/set_variable]

						[unstore_unit]
							variable=unitstats
						[/unstore_unit]
					[/do]
				[/while]

				{CLEAR_VARIABLE unitstats}

				[remove_shroud]
					side=1
					x,y=1-60,1-50
				[/remove_shroud]

				[objectives]
					side=1
					[objective]
						description= _ "Find the source of the undead and destroy it."
						condition=win
					[/objective]
					[objective]
						description= _ "Death of Deoran"
						condition=lose
					[/objective]
					[objective]
						description= _ "Death of Sir Gerrick"
						condition=lose
					[/objective]
					[objective]
						description= _ "Death of Urza Afalas"
						condition=lose
					[/objective]
					[objective]
						description= _ "Time runs out"
						condition=lose
					[/objective]
				[/objectives]
			[/command]
		[/option]

		[option]
			id=reject_bandits
			message= _ "Your crimes are too great. You will fall with the rest of the foul undead!"
			[command]
				[message]
					description=Urza Afalas
					message= _ "Then this parlay is over! You may have sounded the doom of all of us!"
				[/message]

				[message]
					description=Ethiliel
					image=portraits/ethiliel-mad.png
					message= _ "You will pay for taking Mebrin from us! If he is harmed..."
				[/message]

				[set_variable]
					name=side_with_bandits
					value=no
				[/set_variable]

				[objectives]
					side=1
					[objective]
						description= _ "Find the source of the undead and destroy it."
						condition=win
					[/objective]
					[objective]
						description= _ "Defeat the last of the bandit leaders."
						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]
			[/command]
		[/option]
	[/message]
[/event]

# Urza Afalas is killed

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

	[if]
		[variable]
			name=side_with_bandits
			equals=yes
		[/variable]
		[then]
			[message]
				speaker=unit
				image=portraits/urza-afalas.png
				message= _ "Now I pay for my crimes. But how many others will also suffer for them?"
			[/message]
			[endlevel]
				result=defeat
			[/endlevel]
		[/then]
		[else]
			[message]
				description=Urza Afalas
				message= _ "Fools! That lich will be the death of us all! You have sealed our doom!"
			[/message]
		[/else]
	[/if]
[/event]


# A Sea Serpent in the Deep

[event]
	name=moveto
	[filter]
		side=1
		x,y=16,39
	[/filter]

	[unit]
		side=3
		type=Sea Serpent
		description=Beast of the Lake
		user_description= _ "Beast of the Lake"
		x,y=15,39
	[/unit]

	[message]
		description=Beast of the Lake
		message= _ "Graar!"
	[/message]
[/event]

# Someone attacks Mal M'brin and he vanishes!

[event]
	name=attack
	[filter_second]
		description=Mal M'brin
	[/filter_second]

	[kill]
		description=Mal M'brin
		animate=yes
		fire_event=no
	[/kill]

	sound=lightning.ogg

	[if]
		[variable]
			name=side_with_bandits
			equals=yes
		[/variable]
		[then]
			[message]
				description=Sir Gerrick
				message= _ "Well! That was easier than I thought it'd be. Looks like the undead aren't so tough after all!"
			[/message]
			[message]
				description=Deoran
				image=portraits/deoran-glad.png
				message= _ "Indeed. The dark king has fallen. Now that the elves have abandoned us, our lives depend on Urza Afalas. Will you lead us from this accursed forest?"
			[/message]
			[message]
				description=Urza Afalas
				message= _ "What choice do I have? My life is in as much danger as yours. I will lead you and your men back to the lands of Wesnoth if you will grant me pardon."
			[/message]
			[message]
				description=Deoran
				message= _ "I cannot promise clemency, as that decision must be made by the council at Westin, but I will plead your case."
			[/message]
			[message]
				description=Urza Afalas
				message= _ "More than that I cannot ask."
			[/message]
			[endlevel]
				result=victory
				next_scenario=6b_The_Long_March
				bonus=yes
			[/endlevel]
		[/then]
		[else]
			[message]
				speaker=unit
				message= _ "I struck him and he disappeared! Can I really have killed the Lich?"
			[/message]
			[message]
				description=Sir Gerrick
				message= _ "We have beaten them both, criminals and undead!"
			[/message]
			[message]
				description=Deoran
				image=portraits=deoran-glad.png
				message= _ "We should make haste to return to Wesnoth before the harvest. Fall has already been upon us for some time."
			[/message]
			[message]
				description=Ethiliel
				message= _ "Do not be so hasty; great mages are no mere tricksters to be defeated so easily. I fear that there are tunnels and catacombs buried beneath his fortress and that we have merely defeated a spectre. If we wish to cleanse the land of his evil, we must enter the darkness and root him out from within."
			[/message]
			[message]
				description=Deoran
				image=portraits=deoran-sad.png
				message= _ "My men are not dwarves! How are we to fight in catacombs and tunnels?"
			[/message]
			[message]
				description=Sir Gerrick
				message= _ "Someone must take news back to Wesnoth of this new evil that lurks near our borders. Who knows how many more of these undead are hiding in the forest."
			[/message]
			[message]
				description=Deoran
				message= _ "Go, Sir Gerrick, and take with you an escort of elves, if Ethiliel will permit it."
			[/message]
			[message]
				description=Ethiliel
				message= _ "Indeed I do. My kinsfolk will protect you and your message!"
			[/message]
			[message]
				description=Sir Gerrick
				message= _ "Fare well Deoran! I will be there to greet you when you return to Kerlath."
			[/message]
			[store_unit]
				variable=Sir_Gerrick_Store
				[filter]
					description=Sir Gerrick
				[/filter]
				kill=yes
			[/store_unit]
			[store_unit]
				variable=elvish_fighters
				[filter]
					type=Elvish Fighter, Elvish Captain, Elvish Hero, Elvish Champion, Elvish Marshall
				[/filter]
				kill=yes
			[/store_unit]
			[store_unit]
				variable=elvish_healers
				[filter]
					type=Elvish Shaman
				[/filter]
				kill=yes
			[/store_unit]
			[endlevel]
				result=victory
				next_scenario=6a_Tidings_Good_And_Ill
				bonus=yes
			[/endlevel]
		[/else]
	[/if]
[/event]

[/scenario]
