[scenario]
	id=05b_Isle_of_the_Damned
	#textdomain wesnoth-httt
	next_scenario=06_The_Siege_of_Elensefar
	name= _ "Isle of the Damned"
	map_data="{campaigns/Heir_To_The_Throne/maps/Isle_of_the_Damned}"
	{SCENARIO_MUSIC "wesnoth-1.ogg"}
	{TURNS 27 24 21}

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

	[event]
	name=prestart
		[objectives]
		side=1
			[objective]
				description= _ "Resist until the end of the turns"
				condition=win
			[/objective]
			[objective]
				description= _ "Defeat all enemy leaders (Bonus)"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Konrad"
				condition=lose
			[/objective]
		[/objectives]
	[/event]

	{BIGMAP_ISLE_OF_THE_DAMNED_1}

	[story]
		[part]
		story= _ "But the voyage did not go as smoothly as had been hoped. A storm blew up and bore down on the ship. Though all hands were on deck working desperately, a sudden gust of wind flung Konrad overboard as he attempted to secure the sails..."
		background=story/story9.png
		show_title=no
		[/part]
		[part]
		story= _ "The mermen finally saved Konrad from the sea, but were unable to get him back to the ship. With great effort though, they reached a nearby island..."
		background="maps/wesnoth-httt.jpg"
		show_title=no
		[/part]
	[/story]

	{BIGMAP_ISLE_OF_THE_DAMNED_2}

	[side]
	description=Konrad
	user_description= _ "Konrad"
	type=Commander
	unrenamable=yes
	side=1
	canrecruit=1
	recruit=Thug,Poacher,Footpad
	controller=human
	{GOLD 120 100 100}
	#ifdef HARD
	fog=yes
	#endif
	[/side]

	[side]
	description=Haf-Mal
	user_description= _ "Haf-Mal"
	type=Lich
	side=2
	canrecruit=1
	team_name=undead
	recruit=Skeleton,Vampire Bat,Ghost,Dark Adept,Chocobone
		[ai]
		recruitment_pattern=scout,fighter,fighter,archer
		{ATTACK_DEPTH 1 3 5}
		[/ai]
	{GOLD 95 140 140}
	[/side]

	[side]
	description=Jarmal-Gorg
	user_description= _ "Jarmal-Gorg"
	type=Lich
	side=3
	canrecruit=1
	team_name=undead
	recruit=Skeleton,Skeleton Archer,Walking Corpse,Vampire Bat,Ghost,Dark Adept
		[ai]
		recruitment_pattern=scout,fighter,archer,fighter,archer,fighter
		{ATTACK_DEPTH 1 3 5}
		[/ai]
	{GOLD 95 140 140}
	[/side]

	[event]
	name=prestart

	{PLACE_IMAGE misc/temple.png 11 13}
	{PLACE_IMAGE misc/temple.png 10 17}
	{PLACE_IMAGE misc/temple.png 9 15}

	#reset gold held to 100
	[store_gold]
	side=1
	variable=isle_damned_starting_gold
	[/store_gold]
	{VARIABLE_OP isle_damned_starting_gold multiply -1}
	[gold]
	side=1
	amount=$isle_damned_starting_gold
	[/gold]
	[gold]
	side=1
	amount=100
	[/gold]
	{VARIABLE_OP isle_damned_starting_gold multiply -1}

	[disallow_recruit]
	side=1
	type=Elvish Fighter
	[/disallow_recruit]
	[disallow_recruit]
	side=1
	type=Elvish Archer
	[/disallow_recruit]
	[disallow_recruit]
	side=1
	type=Elvish Scout
	[/disallow_recruit]
	[disallow_recruit]
	side=1
	type=Elvish Shaman
	[/disallow_recruit]
	[disallow_recruit]
	side=1
	type=Horseman
	[/disallow_recruit]
	[disallow_recruit]
	side=1
	type=Mage
	[/disallow_recruit]

	# Kill the recall list except for merfolk
	[store_unit]
	variable=iotd_recall_store
	kill=yes
		[filter]
		side=1
#ifdef HARD
#else
			[not]
			race=merman
			[/not]
#endif
			[not]
			description=Konrad
			[/not]
		[/filter]
	[/store_unit]

	[/event]

	[event]
	name=start

		{UNIT (Merman Fighter) (Kalba) ( _ "Kalba") 1 27 12}
		{UNIT (Merman Fighter) (Gnaba) ( _ "Gnaba") 1 31 14}
		[message]
		description=Konrad
		message= _ "Whew, I survived. But now where am I? Is this island inhabited?"
		[/message]
		[message]
		description=Kalba
		message= _ "We have heard only the worst things about this place, my lord. It is said that the fiends of the undead have come in great numbers and turned the island into an ugly wasteland."
		[/message]
		[message]
		description=Konrad
		message= _ "Let's hope these rumors are not true! I have none of my men with me! How could I defend myself?"
		[/message]
		[message]
		description=Kalba
		message= _ "There are still some bands of humans hiding on the island, my lord. If you recruit some of them to help, we might have some hope of holding off the undead hordes!"
		[/message]

		[move_unit_fake]
		type=Outlaw
		x=20,20,21
		y=10,11,12
		[/move_unit_fake]

		{UNIT (Outlaw) (Delurin) ( _ "Delurin") 1 21 12}

		[redraw]
		[/redraw]

		[message]
		description=Delurin
		message= _ "Maybe we can make a deal! Help us defeat those evil creatures!"
		[/message]

	[/event]

	[event]
	name=turn 2
		[message]
		description=Konrad
		message= _ "There are some ancient temples to the southwest; I wonder what might be inside them!"
		[/message]
	[/event]

#define EMPTY_TEMPLE_TRAP X Y
	[event]
	name=moveto
		[filter]
		side=1
		x={X}
		y={Y}
		[/filter]
		[message]
		speaker=unit
		message= _ "The temple seems to be empty."
		[/message]
	[/event]
#enddef

#define MOREMIRMU_TRAP X Y
	[event]
	name=moveto
		[filter]
		side=1
		x={X}
		y={Y}
		[/filter]
		[message]
		speaker=unit
		message= _ "Looks like there is somebody hidden in the temple."
		[/message]
		[unit]
		description=Moremirmu
		user_description= _ "Moremirmu"
		side=1
		type=White Mage
		x={X}
		y={Y}

			#Moremirmu has a special sword which makes him
			#especially deadly against undead.
			[modifications]
				[object]
					[effect]
					apply_to=attack
					range=melee
					set_name= _ "holy sword"
					set_type=holy
					multiply_damage=2
					increase_attacks=2
					[/effect]
				[/object]
				{TRAIT_LOYAL}
			[/modifications]
		[/unit]
		#set the variable to say the Moremirmu is alive
		[set_variable]
		name=moremirmu
		value=1
		[/set_variable]
		[message]
		description=Moremirmu
		message= _ "I was hiding in this holy place, planning how to defeat the evil undead. Now with your help, I can destroy them."
		[/message]
		[message]
		description=Konrad
		message= _ "Join us, wise one. We welcome your aid!"
		[/message]
		[message]
		description=Moremirmu
		message= _ "If we eradicate the undead blight on these islands, I will surely go with you. Otherwise, I plan to finish my task here before moving on."
		[/message]
	[/event]
#enddef

#define XAKAE_TRAP X Y
	[event]
	name=moveto
		[filter]
		side=1
		x={X}
		y={Y}
		[/filter]
		[message]
		speaker=unit
		message= _ "Looks like there is somebody hidden in the temple."
		[/message]

		[unit]
			type=Revenant
			description=Xakae
			user_description= _ "Xakae"
			side=2
			x={X}
			y={Y}
			[modifications]
				{TRAIT_UNDEAD}
				{TRAIT_LOYAL}
			[/modifications]
		[/unit]

		{UNDEAD_UNIT (Walking Corpse) 2 ({X}) ({Y})}
		{UNDEAD_UNIT (Walking Corpse) 2 ({X}) ({Y})}
#ifdef HARD
		{UNDEAD_UNIT (Walking Corpse) 2 ({X}) ({Y})}
#endif

		[message]
		description=Xakae
		message= _ "Surprise! Searching for magi, and all I get is these foul humans!"
		[/message]
	[/event]
#enddef

	[event]
	name=start

#
# Determine the contents of the temples:
# - on easy, Moremirmu shows up in 1 close temple and the others are empty
# - on normal, Moremirmu shows up in 1 close temple and the far one has the revenant
# - on hard, Moremirmu and the revenant show up in the 2 close temples (far one is empty)
#
		{RANDOM 1..2}
		[if]
			[variable]
			name=random
			numerical_equals=1
			[/variable]
#ifdef EASY
			[then]
				{MOREMIRMU_TRAP 11 13}
				{EMPTY_TEMPLE_TRAP 10 17}
				{EMPTY_TEMPLE_TRAP 9 15}
			[/then]
			[else]
				{MOREMIRMU_TRAP 10 17}
				{EMPTY_TEMPLE_TRAP 11 13}
				{EMPTY_TEMPLE_TRAP 9 15}
			[/else]
#endif
#ifdef NORMAL
			[then]
				{MOREMIRMU_TRAP 11 13}
				{EMPTY_TEMPLE_TRAP 10 17}
				{XAKAE_TRAP 9 15}
			[/then]
			[else]
				{MOREMIRMU_TRAP 10 17}
				{EMPTY_TEMPLE_TRAP 11 13}
				{XAKAE_TRAP 9 15}
			[/else]
#endif
#ifdef HARD
			[then]
				{MOREMIRMU_TRAP 11 13}
				{XAKAE_TRAP 10 17}
				{EMPTY_TEMPLE_TRAP 9 15}
			[/then]
			[else]
				{MOREMIRMU_TRAP 10 17}
				{XAKAE_TRAP 11 13}
				{EMPTY_TEMPLE_TRAP 9 15}
			[/else]
#endif
		[/if]
	[/event]

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

		[message]
		speaker=unit
		message= _ "Fight on against the undead without me, friends!"
		[/message]
		[set_variable]
		name=moremirmu
		value=0
		[/set_variable]
	[/event]

#define ISLE_GALLEON_ARRIVE

		[move_unit_fake]
			type=Galleon
			x=33,32,31,30,29,28,27
			y=7,7,8,7,7,7,8
		[/move_unit_fake]

		{PLACE_IMAGE units/transport/galleon.png 27 8}

		[allow_recruit]
		side=1
		type=Elvish Fighter
		[/allow_recruit]
		[allow_recruit]
		side=1
		type=Elvish Archer
		[/allow_recruit]
		[allow_recruit]
		side=1
		type=Elvish Scout
		[/allow_recruit]
		[allow_recruit]
		side=1
		type=Elvish Shaman
		[/allow_recruit]
		[allow_recruit]
		side=1
		type=Horseman
		[/allow_recruit]
		[allow_recruit]
		side=1
		type=Mage
		[/allow_recruit]
		[disallow_recruit]
		side=1
		type=Thug
		[/disallow_recruit]
		[disallow_recruit]
		side=1
		type=Poacher
		[/disallow_recruit]
		[disallow_recruit]
		side=1
		type=Footpad
		[/disallow_recruit]
#enddef

#define ISLE_RESTORE_GOLD
	[gold]
	side=1
	amount=$isle_damned_starting_gold
	[/gold]
	#Add WML to clear the Variable
	{CLEAR_VARIABLE isle_damned_starting_gold}
#enddef

#define RESTORE_RECALL_LIST
	{FOREACH iotd_recall_store i}
		[unstore_unit]
		variable=iotd_recall_store[$i]
		[/unstore_unit]
	{NEXT i}
	{CLEAR_VARIABLE iotd_recall_store}
#enddef

	[event]
	name=enemies defeated
		[message]
		description=Konrad
		message= _ "We have wrested control of the island from the evil undead! Now all we have to do is wait for the ship to arrive, so we can make our way to Elensefar!"
		[/message]

		{ISLE_GALLEON_ARRIVE}
		{ISLE_RESTORE_GOLD}
		{RESTORE_RECALL_LIST}

		[if]
			[variable]
			name=moremirmu
			equals=1
			[/variable]
			[then]
				[message]
				description=Moremirmu
				message= _ "Together we have vanquished the foul undead! Come, I will join you on your noble quest."
				[/message]
				[set_variable]
				name=moremirmu
				value=2
				[/set_variable]
			[/then]
		[/if]

	[/event]

	[event]
	name=time over
		{ISLE_GALLEON_ARRIVE}
		{ISLE_RESTORE_GOLD}
		{RESTORE_RECALL_LIST}
		[message]
		speaker=narrator
		image=units/elves-wood/fighter.png
		message= _ "Thank goodness we have found you, sir! Come aboard quickly, we shall take you away from this horrible island!"
		[/message]
		[message]
		description=Konrad
		message= _ "It's a shame complete victory could not be ours, but thank goodness I am rescued! On to Elensefar!"
		[/message]
		[if]
			[variable]
			name=moremirmu
			equals=1
			[/variable]
			[then]
				[message]
				description=Moremirmu
				message= _ "Thank you for your assistance here brothers. I will stay to continue resisting the foul undead. May fate be with you in your noble quest, and may we meet again some day!"
				[/message]
				[kill]
				description=Moremirmu
				[/kill]
			[/then]
		[/if]
		[endlevel]
		result=victory
		[/endlevel]
	[/event]

	{campaigns/Heir_To_The_Throne/utils/deaths.cfg}
[/scenario]
