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

name=_ "Descent into Darkness"
map_data="{campaigns/Descent_Into_Darkness/maps/Descent_into_darkness.map}"
turns=-1

victory_when_enemies_defeated=no

{STORY_DESCENT_INTO_DARKNESS}

{UNDERGROUND}

[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
	income=0
	{GOLD 100 80 60}
	fog=yes
	shroud=yes
[/side]

[side]
	# Troll leader
	side=2
	team_name=trolls
	controller=ai
	# place leader later
	no_leader=yes
	gold=60
	recruit=Troll Whelp,Troll,Troll Rocklobber,Troll Warrior,Troll Shaman
	[ai]
		caution=0.5
		grouping=defensive
		protect_leader=10
		recruitment_pattern=fighter,fighter,mixed fighter
		# Avoid the spiders, the wose, and the beginning area
		[avoid]
			x=2-9,2-27,5-9
			y=11-15,30-35,19-23
		[/avoid]
	[/ai]
	fog=yes
	shroud=no
[/side]

[side]
	# Eastern village trolls
	side=3
	team_name=trolls
	controller=ai
	no_leader=yes
	[ai]
		# Avoid the spiders, the wose, and the beginning area
		[avoid]
			x=2-9,2-27,5-9
			y=11-15,30-35,19-23
		[/avoid]
	[/ai]
	fog=yes
	shroud=no
[/side]

[side]
	# Western village trolls
	side=4
	team_name=trolls
	controller=ai
	no_leader=yes
	[ai]
		# Avoid the spiders, the wose, and the beginning area
		[avoid]
			x=2-9,2-27,5-9
			y=11-15,30-35,19-23
		[/avoid]
	[/ai]
	fog=yes
	shroud=no
[/side]

[side]
	# Monsters
	side=5
	controller=ai
	no_leader=yes
	[ai]
		# This is mostly for the Wose -- the others are guardians
		[target]
			side=1
			value=5
		[/target]
	[/ai]
	fog=yes
	shroud=yes
[/side]

[side]
	# mirror
	side=6
	colour=5
	controller=ai
	no_leader=yes
	ai_algorithm=idle_ai
	fog=yes
	shroud=yes
[/side]


[event]
	name=prestart
	[music]
		# none to start with
	[/music]

	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Become a Lich."
		[/objective]
	[/objectives]

	# Ditch the starting keep
	[terrain]
		x,y=3,34
		letter=Uu
	[/terrain]

	# Place the "mirror"
	[unit]
		type=Mirror
		side=6
		x,y=6,31
		description=makeshift altar
		user_description=_ "makeshift altar"
		animate=no
	[/unit]

	# Malin starts injured and poisoned
	{MODIFY_UNIT (description=Malin Keshar) hitpoints 12}
	{MODIFY_UNIT (description=Malin Keshar) status.poisoned on}

	# Place and store the new Malin
	[unit]
		# Malin's new look
		type=Lich
		side=1
		description=Mal Keshar
		user_description="Mal Keshar"
		unrenamable=yes
		canrecruit=1
		profile=brown-lich.png
		x,y=1,1
		hitpoints=5
	[/unit]
	[store_unit]
		[filter]
			description=Mal Keshar
		[/filter]
		variable=malinAsLich
		kill=yes
	[/store_unit]

	# Castle trolls - all difficulties
	{GEN_GUARD (Troll) 2 14 7}
	{GEN_GUARD (Troll) 2 8 7}
	{GEN_GUARD (Troll) 2 16 3}
	{GEN_GUARD (Troll Rocklobber) 2 12 1}
	{GEN_GUARD (Troll Shaman) 2 7 4}

	# Eastern village trolls - all difficulties
	{GEN_GUARD (Troll) 3 30 19}
	{GEN_GUARD (Troll) 3 31 12}
	{GEN_GUARD (Troll Shaman) 3 33 14}

	# Western village trolls - all difficulties
	{GEN_GUARD (Troll Shaman) 4 4 21}
	{GEN_GUARD (Troll) 4 10 26}
	{GEN_GUARD (Troll Whelp) 4 2 25}
	{GEN_GUARD (Troll) 4 10 16}

	# Monsters
	{GEN_GUARD (Giant Rat) 5 14 29}
	{GEN_GUARD (Giant Rat) 5 21 28}
	{GEN_GUARD (Giant Rat) 5 24 34}
	{GEN_GUARD (Giant Rat) 5 18 18}
	{GEN_GUARD (Giant Rat) 5 22 5}
	{GEN_GUARD (Cave Bat) 5 29 26}
	{GEN_GUARD (Cave Bat) 5 26 31}
	{GEN_GUARD (Cave Bat) 5 19 32}
	{GEN_GUARD (Cave Bat) 5 19 23}
	{GEN_GUARD (Cave Bat) 5 18 13}
	{GEN_GUARD (Cave Bat) 5 18 34}
	{GEN_GUARD (Giant Spider) 5 7 12}
	{GEN_GUARD (Giant Spider) 5 8 13}
	{GEN_GUARD (Giant Spider) 5 6 15}

	#ifdef NORMAL
		{GEN_GUARD (Troll) 2 7 7}
		{GEN_GUARD (Troll Whelp) 4 4 19}
		{GEN_GUARD (Troll Whelp) 3 31 16}
	#endif

	#ifdef HARD
		{GEN_GUARD (Troll) 2 7 7}
		{GEN_GUARD (Troll Rocklobber) 4 8 18}
		{GEN_GUARD (Troll Rocklobber) 3 27 16}
	#endif
[/event]


[event]
	name=start
	{MOVE_UNIT (description=Malin Keshar) 4 33}
	{CREATE_ADVISOR}
	{DIALOGUE_DID_START}
	{PUT_TO_RECALL_LIST (role=advisor)}
	{DIALOGUE_DID_START2}
[/event]


# In-scenario events
[event]
	# Malin becomes a lich
	name=attack_end
	first_time_only=no
	[filter]
		description=Malin Keshar
	[/filter]
	{IF_UNIT_DEAD (Malin Keshar)}
		[kill]
			description=makeshift altar
		[/kill]
		{PLACE_IMAGE (scenery/slab1.png) 6 31}

		# Malin dies
		# I really want to black out the screen, but it doesn't seem to want to let me do that with [place_shroud], so I'll settle for scrolling to a shrouded part
		[scroll_to]
			x,y=25,32
		[/scroll_to]
		{DELAY 1000}
		{DIALOGUE_DID_LICH1}

		# and is reborn as a lich
		{VARIABLE_OP malinAsLich.x format $x1}
		{VARIABLE_OP malinAsLich.y format $y1}
		[unstore_unit]
			variable=malinAsLich
			find_vacant=no
			animate=yes
		[/unstore_unit]
		{CLEAR_VARIABLE malinAsLich}
		[redraw]
			side=1
		[/redraw]

		# He's not necessariliy totally happy about this
		{DIALOGUE_DID_LICH2}
		{DELAY 500}

		# Blow open a wall
		[move_unit_fake]
			type=Iceball
			side=1
			x=6,7,8,9,10
			y=31,32,31,32,31
		[/move_unit_fake]
		{TREMOR}
		[terrain]
			x,y=10,31
			letter=Uh
		[/terrain]

		[objectives]
			side=1
			[objective]
				condition=win
				description=_ "Regain your strength"
			[/objective]
			[objective]
				condition=lose
				description=_ "Destruction of Mal Keshar"
			[/objective]
		[/objectives]

		# Previously recruited and new adepts can now also become liches
		{MODIFY_UNIT (type=Dark Adept DiD) type (Dark Adept)}
		{MODIFY_UNIT (type=Dark Sorcerer DiD) type (Dark Sorcerer)}
		[disallow_recruit]
			side=1
			type=Dark Adept DiD
		[/disallow_recruit]
		[allow_recruit]
			side=1
			type=Dark Adept
		[/allow_recruit]

		# Some somber music
		[music]
			name=main_menu.ogg
			ms_after=10000
		[/music]
		[music]
			name=revelation.ogg
			append=yes
			ms_after=10000
		[/music]

	{END_IF_DEAD}
[/event]

[event]
	name=attacker_hits
	first_time_only=yes
	[filter]
		description=Mal Keshar
	[/filter]
	[special_filter]
		weapon=touch
	[/special_filter]
	{DIALOGUE_DID_ATTACK}
[/event]

[event]
	# See your goal
	name=moveto
	[filter]
		description=Mal Keshar
		x=20-25
		y=27-29
	[/filter]
	[remove_shroud]
		# See the road to the castle and the castle itself
		side=1
		x=3-13,20-22,18-20,17-19,13-16,11-15
		y=2-8,18-28,15-17,14-16,12-13,9-11
	[/remove_shroud]
	[redraw]
		side=1
	[/redraw]
	[scroll_to]
		x,y=8,5
	[/scroll_to]
	{DELAY 2000}
	{DIALOGUE_DID_CASTLE1}
	[remove_shroud]
		x=27-32
		y=23-27
	[/remove_shroud]
	[redraw]
		side=1
	[/redraw]
	[scroll_to]
		x,y=34,24
	[/scroll_to]
	{DELAY 1500}
	{DIALOGUE_DID_CASTLE2}

	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Clear your new home of trolls"
		[/objective]
		[objective]
			condition=lose
			description=_ "Destruction of Mal Keshar"
		[/objective]
	[/objectives]

	# Turns are measured from here
	{VARIABLE_OP totalTurns to_variable turn_number}
	{VARIABLE_OP totalTurns add 50}
	[modify_turns]
		value=$totalTurns
	[/modify_turns]
	{CLEAR_VARIABLE totalTurns}
[/event]

[event]
	# Set the troll enemy and return income to normal when you reach your keep
	name=moveto
	[filter]
		description=Mal Keshar
		x,y=30,25
	[/filter]
	[unit]
		# Troll leader
		type=Troll Hero
		side=2
		description=Grnknrr
		x,y=10,6
		canrecruit=1
	[/unit]
	[modify_side]
		side=1
		income=2
	[/modify_side]
[/event]

[event]
	# Fun with a wose
	name=moveto
	[filter]
		x,y=7,22
	[/filter]
	{GEN_UNIT (Ancient Wose) 5 7 21}
	[terrain]
		x,y=7,21
		letter=Gg
	[/terrain]
	[message]
		type=Ancient Wose
		message=_ "Who has awoken me from my slumber? Undead? I shall not suffer the existence of such foul creatures."
	[/message]
[/event]

[event]
	# Have a nice trip, see you in the fall. . .
	name=moveto
	first_time_only=no
	[filter]
		x,y=24,13
		[not]
			type=Vampire Bat,Blood Bat,Ghost,Wraith,Spectre,Shadow,Nightgaunt
		[/not]
	[/filter]
	[message]
		x,y=24,13
		message=_ "AAAAAAAaaaaaaaggggggghhhhhhh!!!!...... . . .   ."
	[/message]
	{MOVE_UNIT (x,y=24,13) 25 13}
	[kill]
		x,y=25,13
		animate=no
		fire_event=yes
	[/kill]
[/event]


# Defeat Conditions
{MAL_DEATH}


# Victory Condition
[event]
	# Kill the troll leader
	name=die
	[filter]
		side=2
		canrecruit=1
	[/filter]
	[endlevel]
		result=victory
	[/endlevel]
[/event]


[event]
	name=victory
	{VARIABLE timesForever 0}
[/event]

[/scenario]
