[scenario]
id=A_Small_Favor2
next_scenario=A_Small_Favor3
#textdomain wesnoth-did

name=_ "A Small Favor - Part 2"
map_data="{campaigns/Descent_Into_Darkness/maps/A_small_favor2.map}"
{TURNS 30 27 25}

victory_when_enemies_defeated=no

# no story -- this occurs immediately after the previous scenario

{UNDERGROUND}

[side]
	side=1
	controller=human
	team_name=intruders
	type=Apprentice Mage
	description=Malin Keshar
	user_description=_ "Malin Keshar"
	unrenamable=yes
	canrecruit=1
	recruit=
	gold=0
	shroud=yes
	fog=no
	share_maps=yes
	share_view=yes
[/side]

[side]
	# Mages
	side=2
	controller=ai
	team_name=defenders
	no_leader=yes
	[ai]
		village_value=0
		agression=0.8
	[/ai]
[/side]

[event]
	name=prestart
	[music]
		name=underground.ogg
	[/music]
	[music]
		name=frantic.ogg
		append=yes
		ms_before=2000
		ms_after=2000
	[/music]
	
	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Find the mage Lord Karres"
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Malin Keshar"
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Darken Volk"
		[/objective]
	[/objectives]
	
	# Place doors
	{PLACE_DOOR 5 13 nwse 4 12 6 13}
	{PLACE_DOOR 11 9 nwse 10 8 12 9}
	{PLACE_DOOR 12 2 nwse 11 2 13 3}
	{PLACE_DOOR 23 4 nwse 22 3 24 4}
	{PLACE_DOOR 24 2 nwse 23 2 25 3}
	{PLACE_DOOR 25 10 nwse 24 9 26 10}
	{PLACE_DOOR 21 12 nwse 20 11 22 12}
	{PLACE_DOOR 24 19 nwse 23 19 25 20}

	{PLACE_DOOR 4 15 nesw 5 15 3 16}
	{PLACE_DOOR 25 16 nesw 26 15 24 16}

	{PLACE_IMAGE scenery/signpost.png 1 1}

	# Place manor guards in hallways
	{GEN_GUARDIAN (Heavy Infantryman) (Guard) (_ "Guard") 2 6 14}
	{GEN_GUARDIAN (Pikeman) (Guard) (_ "Guard") 2 7 14}
	{GEN_GUARDIAN (Swordsman) (Guard) (_ "Guard") 2 19 10}
	{GEN_GUARDIAN (Heavy Infantryman) (Guard) (_ "Guard") 2 15 10}
	{GEN_GUARDIAN (Halbardier) (Guard) (_ "Guard") 2 2 2}
		
	# Place mages in rooms
	{GEN_UNIT Mage 2 4 17}
	{GEN_UNIT Mage 2 3 12}
	{GEN_UNIT (White Mage) 2 2 10}
	{GEN_UNIT (Red Mage) 2 7 8}
	{GEN_UNIT (Mage) 2 8 1}
	{GEN_UNIT (Mage) 2 23 6}
	{GEN_UNIT (White Mage) 2 24 6}
	{GEN_UNIT (Mage) 2 28 3}
	{GEN_UNIT (Red Mage) 2 27 10}
	{GEN_UNIT (Silver Mage) 2 23 13}
	{GEN_UNIT (Silver Mage) 2 27 15}
	{GEN_UNIT (Silver Mage) 2 29 14}
	{GEN_UNIT (Mage) 2 26 19}
	
	
	# More mages, depending on the difficulty?
	#ifdef NORMAL
	#ifdef HARD
	{GEN_UNIT Mage 2 27 19}
	{GEN_UNIT Mage 2 29 14}
	{GEN_UNIT Mage 2 9 9}
	{GEN_UNIT Mage 2 29 3}
	{GEN_UNIT Mage 2 2 16}
	#endif
	#endif
		
	# Put the mage lord randomly in one of the rooms
	{VARIABLE mageLordStart[0].x 29}
	{VARIABLE mageLordStart[0].y 13}
	{VARIABLE mageLordStart[1].x 28}
	{VARIABLE mageLordStart[1].y 2}
	{VARIABLE mageLordStart[2].x 22}
	{VARIABLE mageLordStart[2].y 6}
	{VARIABLE mageLordStart[3].x 4}
	{VARIABLE mageLordStart[3].y 7}
	{VARIABLE mageLordStart[4].x 5}
	{VARIABLE mageLordStart[4].y 19}
	{VARIABLE mageLordStart[5].x 29}
	{VARIABLE mageLordStart[5].y 9}
	{VARIABLE mageLordStart[6].x 2}
	{VARIABLE mageLordStart[6].y 9}
	{VARIABLE_OP i random (0..6)}
	{VARIABLE_OP actualStart.x format $mageLordStart[$i].x}
	{VARIABLE_OP actualStart.y format $mageLordStart[$i].y}
	{CLEAR_VARIABLE i}
	{CLEAR_VARIABLE mageLordStart}
	{GEN_GUARDIAN (Great Mage) (Lord Karres) (_ "Lord Karres") 2 $actualStart.x $actualStart.y}
	{CLEAR_VARIABLE actualStart}


	{VARIABLE_OP i random (0..2)}
	{IF i numerical_equals 0 (
		[then]
			[terrain]
				x=6
				y=3
				letter=Rr
			[/terrain]
		[/then]
	)}
	{IF i numerical_equals 1 (
		[then]
			[terrain]
				x=6
				y=5
				letter=Rr
			[/terrain]
		[/then]
	)}
	{IF i numerical_equals 2 (
		[then]
			[terrain]
				x=2
				y=5
				letter=Rr
			[/terrain]
		[/then]
	)}
	{CLEAR_VARIABLE i}

	#TODO: Create some scenery (fire, torches, ...)
	
[/event]

[event]
	name=start		
	{FOREACH ASFUnit_store i}
		{VARIABLE ASFUnit_store[$i].x 19}
		{VARIABLE ASFUnit_store[$i].y 18}
		[unstore_unit]
			variable=ASFUnit_store[$i]
			find_vacant=yes
		[/unstore_unit]
	{NEXT i}	
	{CLEAR_VARIABLE ASFUnit_store}
	# All undead at this point are Malin's
	{MODIFY_UNIT (race=undead) upkeep loyal}
	
	{VARIABLE darkenVolkStore.x 19}
	{VARIABLE darkenVolkStore.y 18}
	[unstore_unit]
		variable=darkenVolkStore
		find_vacant=yes
	[/unstore_unit]
	{CLEAR_VARIABLE darkenVolkStore}
	
	{DIALOGUE_ASF2_START}
[/event]

[event]
	name=die
	[filter]
		description=Lord Karres
	[/filter]

	{DIALOGUE_ASF2_TOBOOK}

	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Move through the passage way in the northwest leading to the great hall"
		[/objective]
	[/objectives]
	[event]
		name=moveto
		[filter]
			description=Malin Keshar
			x,y=1,1
		[/filter]
		{DIALOGUE_ASF2_FOUNDPASSAGE}
		[endlevel]
			result=victory
			bonus=yes
		[/endlevel]
	[/event]

[/event]

# Defeat Conditions
{MALIN_DEATH}
{VOLK_DEATH2}

[event]
	name=time over
	[message]
		speaker=narrator
		message=_ "As dawn breaks, the city guards force their way into the manor and capture the two necromancers."
	[/message]
	[endlevel]
		result=defeat
	[/endlevel]
[/event]

[event]
	name=victory
	[store_unit]
		[filter]
			race=undead
			x=1-50
			y=1-50
		[/filter]
		variable=ASFUnit_store
		kill=yes
	[/store_unit]
	[store_unit]
		[filter]
			description=Darken Volk
		[/filter]
		variable=darkenVolkStore
		kill=yes
	[/store_unit]
[/event]


[/scenario]
