[scenario]
id=Alone_at_Last
next_scenario=Descent_into_Darkness
#textdomain wesnoth-did

name=_ "Alone at Last"
map_data="{campaigns/Descent_Into_Darkness/maps/Alone_at_last.map}"
turns=-1

victory_when_enemies_defeated=no

{STORY_ALONE_AT_LAST}

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

[side]
	side=1
	controller=human
	type=Apprentice Mage
	description=Malin Keshar
	user_description=_ "Malin Keshar"
	unrenamable=yes
	canrecruit=1
	recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept DiD
	fog=no
	shroud=no
	gold=180
[/side]

[side]
	# Darken Volk
	side=2
	controller=ai
	no_leader=yes
	gold=430
	recruit=Soulless,Blood Bat,Wraith,Ghost,Shadow,Necrophage,Bone Shooter,Skeleton,Revenant,Deathblade,Dark Sorcerer_DiD
	[ai]
		village_value=0.2
		villages_per_scout=10
		[target]
			description=Malin Keshar
			value=1
		[/target]
		[target]
			side=3
			value=5
		[/target]
		protect_leader=4
	[/ai]
[/side]

[side]
	# Paladins and co.
	side=3
	team_name=wesnothians
	controller=ai
	no_leader=yes
	gold=150
	income=20
	recruit=Spearman,Heavy Infantryman,White Mage,Mage,Paladin
	[ai]
		village_value=0.1
		villages_per_scout=10
		[target]
			description=Darken Volk
			value=2
		[/target]
		#recruitment_pattern=fighter,healer
	[/ai]
[/side]

[side]
	# Dela Keshar
	side=4
	team_name=wesnothians
	controller=ai
	no_leader=yes
	gold=250
	recruit=Spearman,Archer,Swordsman,Longbowman,Thug,Poacher,Footpad
	[ai]
		[target]
			description=Malin Keshar
			value=2
		[/target]
	[/ai]
[/side]

[event]
	name=prestart
	[music]
		name=wanderer.ogg
	[/music]

	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Take the book back from Darken Volk."
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Malin Keshar"
		[/objective]
	[/objectives]

	# Ditch the starting point keep
	[terrain]
		x,y=2,26
		letter=Uu
	[/terrain]

	# Place DV
	{VARIABLE darkenVolkStore.x 2}
	{VARIABLE darkenVolkStore.y 27}
	{VARIABLE darkenVolkStore.side 1}
	[unstore_unit]
		variable=darkenVolkStore
	[/unstore_unit]
	{CLEAR_VARIABLE darkenVolkStore}

	# Scenario variables
	{VARIABLE bookX 0}
	{VARIABLE bookY 0}
[/event]


[event]
	name=start
	{MOVE_UNIT (description=Malin Keshar) 7 22}
	{DIALOGUE_AAL_START}
	{MOVE_UNIT (description=Darken Volk) 8 21}
	[if]
		[variable]
			name=hasBook
			equals=Malin
		[/variable]
		[then]
			# Malin has the book
			{DIALOGUE_AAL_START2A}
		[/then]
		[else]
			# DV already has book
			{DIALOGUE_AAL_START2B}
		[/else]
	[/if]
	{CLEAR_VARIABLE hasBook}
	{MODIFY_UNIT (description=Darken Volk) role book_carrier}
	[unit_overlay]
		x,y=8,21
		image="misc/book-icon.png"
	[/unit_overlay]
	{MOVE_UNIT (description=Darken Volk) 19 19}
	{MODIFY_UNIT (description=Darken Volk) side 2}
	{MODIFY_UNIT (description=Darken Volk) canrecruit 1}
	{DELAY 500}
	{MOVE_UNIT (description=Malin Keshar) 7 21}
	{DELAY 500}
	{MOVE_UNIT (description=Malin Keshar) 8 20}
	{DELAY 500}
	{MOVE_UNIT (description=Malin Keshar) 9 20}
	{DELAY 500}
	{CREATE_ADVISOR}
	{DIALOGUE_AAL_START3}
	{MOVE_UNIT (description=Malin Keshar) 5 17}
	{MOVE_UNIT (description=Darken Volk) 26 10}

	# Make camp
	[terrain]
		x=25-27,26
		y=10-11,9
		letter=Ce
	[/terrain]
	[terrain]
		x,y=26,10
		letter=Ke
	[/terrain]

[/event]

# In-scenario events
[event]
	name=attack
	[filter]
		side=1
	[/filter]
	[filter_second]
		side=2
	[/filter_second]
	{DIALOGUE_AAL_REALIZE}
[/event]

[event]
	name=attack
	[filter]
		side=1
	[/filter]
	[filter_second]
		description=Darken Volk
	[/filter_second]
	{DIALOGUE_AAL_TAUNT}
[/event]

[event]
	# Paladins!
	name=new turn
	first_time_only=no
	[if]
		[variable]
			name=turn_number
			numerical_equals=5
		[/variable]
		[then]
		# Fake move the paladin in, set up a camp, have some dialog, and give him another paladin and a mage of light
			[move_unit_fake]
				type=Paladin
				x=34,32
				y=27,23
				side=3
			[/move_unit_fake]
			[unit]
				type=Paladin
				side=3
				x,y=32,23
				description=Sir Cadaeus
				user_description=_ "Sir Cadaeus"
				canrecruit=1
				random_traits=yes
				animate=no
			[/unit]
			{GEN_UNIT (Paladin) 3 31 24}
			{GEN_UNIT (Paladin) 3 31 23}
			{GEN_UNIT (Mage of Light) 3 33 24}
			# Make camp
			[terrain]
				x=31-33,32
				y=23-24,22
				letter=Ce
			[/terrain]
			[terrain]
				x,y=32,23
				letter=Ke
			[/terrain]
			{DIALOGUE_AAL_PALADIN}
		[/then]
	[/if]
[/event]

[event]
	# Dela joins the party
	name=new turn
	first_time_only=no
	[if]
		[variable]
			name=turn_number
			numerical_equals=10
		[/variable]
		[then]
		# Fake move Dela in, set up camp, have some dialog.  She doesn't bring anyone with her.
			[move_unit_fake]
				type=Frontier Baroness
				x=27,21
				y=1,4
				side=4
			[/move_unit_fake]
			[unit]
				type=Frontier Baroness
				side=4
				x,y=21,4
				description=Dela Keshar
				user_description="Dela Keshar"
				canrecruit=1
				animate=no
			[/unit]
			# Make camp
			[terrain]
				x=20-22,21
				y=3-4,5
				letter=Ce
			[/terrain]
			[terrain]
				x,y=21,4
				letter=Ke
			[/terrain]
			{DIALOGUE_AAL_DELA}
		[/then]
	[/if]
[/event]

[event]
	name=die
	[filter]
		description=Darken Volk
	[/filter]
	{DIALOGUE_AAL_DVDIE}
	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Bring the book back to Malin's castle."
		[/objective]
	[/objectives]
	{DIALOGUE_AAL_NOTE}
[/event]

[event]
	name=die
	first_time_only=no
	[filter]
		role=book_carrier
	[/filter]
	{VARIABLE_OP bookX format $x1}
	{VARIABLE_OP bookY format $y1}
	{PLACE_IMAGE (items/book5.png) ($bookX) ($bookY)}
	[event]
		name=moveto
		first_time_only=yes
		[filter]
			x=$bookX
			y=$bookY
			side=1
			[not]
				type=Ghost,Wraith,Spectre,Shadow,Nightgaunt,Vampire Bat,Blood Bat
			[/not]
		[/filter]
		[removeitem]
			x=$bookX
			y=$bookY
		[/removeitem]
		[role]
			role=book_carrier
			x=$bookX
			y=$bookY
		[/role]
		[unit_overlay]
			x=$bookX
			y=$bookY
			image="misc/book-icon.png"
		[/unit_overlay]
		{DIALOGUE_AAL_GOTIT}
	[/event]
[/event]

#Inform the player if a unit cannot pick up the book
[event]
	name=moveto
	first_time_only=no
	[filter]
		x=$bookX
		y=$bookY
		side=1
		type=Ghost,Wraith,Spectre,Shadow,Nightgaunt,Vampire Bat,Blood Bat
	[/filter]
	{DIALOGUE_AAL_TOOHEAVY}
[/event]

# Defeat Conditions
{MALIN_DEATH}

# Victory Condition
[event]
	name=moveto
	[filter]
		role=book_carrier
		x=4-6,5-7
		y=16-17,18
	[/filter]
	{MOVE_UNIT (description=Malin Keshar) 1 12}
	{DIALOGUE_AAL_END}
	[endlevel]
		bonus=no
		result=continue
	[/endlevel]
[/event]

[event]
	name=victory
	{CLEAR_VARIABLE bookX}
	{CLEAR_VARIABLE bookY}
	{MODIFY_UNIT (role=book_carrier) overlays none}
[/event]

[/scenario]
