[scenario]
	id=04_The_Bay_of_Pearls
	#textdomain wesnoth-httt
	name= _ "The Bay of Pearls"
	map_data="{campaigns/Heir_To_The_Throne/maps/Bay_of_Pearls}"
	{SCENARIO_MUSIC "gameplay03.ogg"}
	{TURNS 27 24 21}

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

	next_scenario=05a_Muff_Malals_Peninsula

	[event]
	name=prestart
		[objectives]
		side=1
			[objective]
				description= _ "Defeat one enemy leader, and resist the other until time expires"
				condition=win
			[/objective]
			[objective]
				description= _ "Defeat all enemy leaders (Bonus)"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Konrad"
				condition=lose
			[/objective]
			[objective]
				description= _ "Turns run out"
				condition=lose
			[/objective]
		[/objectives]
	[/event]

	{BIGMAP_BAY_OF_PEARLS}

	[side]
	type=Commander
	description=Konrad
	user_description= _ "Konrad"
	unrenamable=yes
	side=1
	canrecruit=1
	recruit=Elvish Scout,Elvish Fighter,Elvish Archer,Horseman,Mage,Elvish Shaman
	gold=140
	controller=human
	[/side]

	[side]
	type=Orcish Warrior
	description=Dwaba-Kukai
	user_description= _ "Dwaba-Kukai"
	side=2
	canrecruit=1
	recruit=Vampire Bat,Naga Fighter
		[ai]
		recruitment_pattern=scout,fighter
		{ATTACK_DEPTH 1 3 5}
		[/ai]
	team_name=orcs
	{GOLD 60 90 150}
	[/side]

	[side]
	type=Orcish Warrior
	description=Managa'Gwin
	user_description= _ "Managa'Gwin"
	recruit=Wolf Rider,Orcish Warrior,Troll Whelp,Orcish Archer
	side=3
	canrecruit=1
	{GOLD 120 180 240}
		[ai]
		{ATTACK_DEPTH 1 3 5}
		[/ai]
	team_name=orcs
	[/side]

	{STARTING_VILLAGES 3 20}
	{STARTING_VILLAGES 2 10}

	[event]
	name=prestart

#
# Grant an extra village
#
#ifdef EASY
		[terrain]
		x=1
		y=37
		letter=n
		[/terrain]
#endif

#
# Remove the river ford hexes on hard
#
#ifdef HARD
		[terrain]
		x=3-5
		y=40
		letter=c
		[/terrain]
#endif

		[recall]
		description=Delfador
		[/recall]

		#the ship they came on.
		{PLACE_IMAGE units/transport/galleon.png 2 34}

		[unit]
		type=Orcish Archer
		description=Bugg
		user_description= _ "Bugg"
		side=2
		x=16
		y=18
		ai_special=guardian
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
		[unit]
		type=Naga Fighter
		description=Xnamas
		user_description= _ "Xnamas"
		x=2
		y=10
		ai_special=guardian
		side=2
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
		[unit]
		type=Naga Fighter
		description=Inalai
		user_description= _ "Inalai"
		x=4
		y=10
		ai_special=guardian
		side=2
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]

		{OBJ_TRIDENT_STORM 5 4 bop_stormtrident}

		#when certain villages are entered, Mermen are rescued
		{PLACE_IMAGE /units/merfolk/fighter.png 4 38}
		{PLACE_IMAGE items/cage.png 4 38}

		{PLACE_IMAGE /units/merfolk/fighter.png 7 35}
		{PLACE_IMAGE items/cage.png 7 35}

		{PLACE_IMAGE /units/merfolk/fighter.png 11 33}
		{PLACE_IMAGE items/cage.png 11 33}

		{PLACE_IMAGE /units/merfolk/fighter.png 19 23}
		{PLACE_IMAGE items/cage.png 19 23}

		{PLACE_IMAGE /units/merfolk/fighter.png 3 10}
		{PLACE_IMAGE items/cage.png 3 10}
	[/event]

	[event]
	name=start
		[message]
		description=Konrad
		message= _ "So this is the Bay of Pearls. It looks like they have those mermen working hard!"
		[/message]
		[message]
		description=Delfador
		message= _ "Indeed it does. It also looks like they have many, many troops. I should go around the bay and distract some of them. You and the rest rescue the mermen!"
		[/message]
		[message]
		description=Konrad
		message= _ "Very well. Be careful!"
		[/message]

		#Delfador leaves the party
		[store_unit]
			variable=delfador_store
			kill=yes
			[filter]
			description=Delfador
			[/filter]
		[/store_unit]
	[/event]

	#comic relief with Bugg becoming a 'sea orc'
	[event]
	name=turn 3
		# ensure Bugg hasn't been killed
		[if]
			[have_unit]
			side=2
			description=Bugg
			[/have_unit]
		[then]
		[message]
		description=Bugg
		message= _ "But boss, why are we only using bats and nagas?"
		[/message]

		[message]
		description=Dwaba-Kukai
		image=portraits/James_Woo/orc-warlord2.png
		message= _ "Because we need to control the seas and the merman folk, and nagas and bats are best for doing that!"
		[/message]

		[message]
		description=Bugg
		message= _ "But orcs are the most powerful race in all of..."
		[/message]

		[message]
		description=Dwaba-Kukai
		image=portraits/James_Woo/orc-warlord2.png
		message= _ "Shut up, worm! I'm the boss!"
		[/message]
		[/then]
		[/if]
	[/event]

	[event]
	name=turn 4
		[if]
			[have_unit]
			side=2
			description=Bugg
			[/have_unit]
		[then]
		#override kills being processed after
		#units being created if they're in the same event
		[command]
			[kill]
			description=Bugg
			[/kill]

			{UNIT (Sea Orc) (Bugg) ( _ "Bugg") 2 16 18}

			[message]
			description=Bugg
			message= _ "Ha ha ha! Now orcs will rule over land and sea!"
			[/message]

			[message]
			description=Dwaba-Kukai
			image=portraits/James_Woo/orc-warlord2.png
			message= _ "(Sigh) Will someone kill this idiot for me, please?"
			[/message]
		[/command]
		[/then]
		[/if]
	[/event]

	[event]
	name=die
		[filter]
		description=Bugg
		[/filter]
		[message]
		speaker=unit
		message= _ "But... but... how can this be happening to me?"
		[/message]
		[message]
		speaker=second_unit
		message= _ "Who was that idiot?"
		[/message]
	[/event]

	[event]
	name=moveto

		[removeitem]
		[/removeitem]

		[filter]
		side=1
		x=19
		y=23
		[/filter]

		[unit]
		side=1
		x=19
		y=23
		description=Gwaba
		type=Merman Fighter
		user_description= _ "Gwaba"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_STRONG}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=19
		y=23
		description=Nepba
		type=Merman Fighter
		user_description= _ "Nepba"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=19
		y=23
		description=Triram
		type=Merman Fighter
		user_description= _ "Triram"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_RESILIENT}
		[/modifications]
		[/unit]

#ifdef EASY
		[unit]
		side=1
		x=19
		y=23
		description=Mriram
		type=Merman Fighter
		user_description= _ "Mriram"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_STRONG}
		[/modifications]
		[/unit]
#endif
		[message]
		description=Gwaba
		message= _ "Free at last! Now death to the orcs!"
		[/message]
	[/event]

	[event]
	name=moveto
		[removeitem]
		[/removeitem]

		[filter]
		side=1
		x=11
		y=33
		[/filter]

		[unit]
		side=1
		x=11
		y=33
		description=Mabooa
		type=Merman Fighter
		user_description= _ "Mabooa"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_RESILIENT}
		[/modifications]
		[/unit]

#ifdef EASY
		[unit]
		side=1
		x=11
		y=33
		description=Earooa
		type=Merman Fighter
		user_description= _ "Earooa"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_STRONG}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=11
		y=33
		description=Nethuns
		type=Merman Fighter
		user_description= _ "Nethuns"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]
#else
		[unit]
		side=1
		x=11
		y=33
		description=Gwoama
		type=Merman Fighter
		user_description= _ "Gwoama"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_RESILIENT}
		[/modifications]
		[/unit]
#endif
		[message]
		description=Mabooa
		message= _ "Now that we are free, together we can defeat our oppressors!"
		[/message]
	[/event]

	[event]
	name=moveto
		[removeitem]
		[/removeitem]

		[filter]
		side=1
		x=7
		y=35
		[/filter]

		[unit]
		side=1
		x=7
		y=35
		description=Kaba
		type=Merman Fighter
		user_description= _ "Kaba"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_QUICK}
		[/modifications]
		[/unit]

#ifdef EASY
		[unit]
		side=1
		x=7
		y=35
		description=Kwaboo
		type=Merman Fighter
		user_description= _ "Kwaboo"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]
#endif

		[message]
		description=Kaba
		message= _ "Freedom! Now where are those orcs? Let me at 'em!"
		[/message]
	[/event]

	[event]
	name=moveto
		[removeitem]
		[/removeitem]

		[filter]
		x=4
		y=38
		side=1
		[/filter]

		[unit]
		side=1
		x=4
		y=38
		description=Gwimli
		type=Merman Fighter
		user_description= _ "Gwimli"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_STRONG}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=4
		y=38
		description=Jarla
		type=Merman Fighter
		user_description= _ "Jarla"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]

#ifdef EASY
		[unit]
		side=1
		x=4
		y=38
		description=Gwarloa
		type=Merman Fighter
		user_description= _ "Gwarloa"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_RESILIENT}
		[/modifications]
		[/unit]
#endif
		[message]
		description=Gwimli
		message= _ "Thank you for rescuing us! Now we can help you fight the evil orcs! The main cage where they keep most of the mermen is in the northwest!"
		[/message]
	[/event]

	[event]
	name=moveto
		[removeitem]
		[/removeitem]

		[filter]
		side=1
		x=3
		y=10
		[/filter]

		[unit]
		side=1
		x=3
		y=10
		description=Heldaga
		type=Merman Fighter
		user_description= _ "Heldaga"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_QUICK}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=3
		y=10
		description=Apalala
		type=Merman Hunter
		user_description= _ "Apalala"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_STRONG}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=3
		y=10
		description=Oceania
		type=Mermaid Initiate
		user_description= _ "Oceania"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]
#ifdef EASY
		[unit]
		side=1
		x=3
		y=10
		description=Elcmar
		type=Merman Fighter
		user_description= _ "Elcmar"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_STRONG}
		[/modifications]
		[/unit]
		[unit]
		side=1
		x=11
		y=33
		description=Aigaion
		type=Merman Fighter
		user_description= _ "Aigaion"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_QUICK}
		[/modifications]
		[/unit]
#else
		[unit]
		side=1
		x=3
		y=10
		description=Tini
		type=Merman Fighter
		user_description= _ "Tini"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_RESILIENT}
		[/modifications]
		[/unit]
#endif

		[message]
		description=Heldaga
		message= _ "Death to the orcs! Come, my mer brethren, let us fight the orcs and drive them from our shores!"
		[/message]
	[/event]

#if victorious, the player can henceforth recruit merfolk
	[event]
	name=victory
		[allow_recruit]
		type=Merman Fighter,Merman Hunter,Mermaid Initiate
		[/allow_recruit]
	[/event]

#define BAY_OF_PEARLS_VICTORY
		[message]
		description=Konrad
		message= _ "At last, we have freed the mermen. Go back to the ocean and live in peace."
		[/message]
		[role]
		type=Merman Fighter,Merman Warrior,Merman Triton,Merman Hoplite
		role=ThankfulMerman
		[/role]
		[message]
		role=ThankfulMerman
		message= _ "My lord! You may need the help of some of us who have skill in the sea in future. We would like to come with you and offer you help."
		[/message]
		[message]
		speaker=narrator
		image="wesnoth-icon.png"
		message= _ "You may now recruit the noble merfolk!"
		[/message]
		[message]
		description=Konrad
		message= _ "Now where is Delfador? I hope he's safe!"
		[/message]
		[unit]
		x=14
		y=40
		description=Delfador
		type=Elder Mage
		user_description= _ "Delfador"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]
		[message]
		description=Delfador
		message= _ "I am perfectly safe, friend!"
		[/message]
		[message]
		description=Konrad
		message= _ "There you are! I am so glad you are all right! Now we may have a little rest."
		[/message]
		[message]
		description=Delfador
		message= _ "I am afraid there is no time for rest, Konrad. Asheviere has now laid siege to Elensefar, breaking the century-old treaty between Wesnoth and the Elense city-state. If the city falls, there is no telling how many other lands she may swallow up!"
		[/message]

		[message]
		description=Konrad
		message= _ "Oh no! What shall we do?"
		[/message]

		[message]
		description=Delfador
		message= _ "You must lead our men to the city, and help defend it. Or recapture it if it falls before you arrive."
		[/message]

		[message]
		description=Konrad
		message= _ "I must do that? But what about you, Delfador? You're coming with me, right?"
		[/message]

		[message]
		description=Delfador
		message= _ "I am afraid not, Konrad. I have come across some important documents, and must make haste with them to the Elven Council. It seems that the time to stop Asheviere is shorter than I had thought."
		[/message]

		[message]
		description=Konrad
		message= _ "But Delfador! I can't do it on my own!"
		[/message]

		[role]
		type=Elvish Champion,Elvish Marshal,Elvish Captain,Elvish Hero,Knight,Elvish Rider,Elvish Outrider,Paladin,Mage,White Mage,Red Mage,Elvish Fighter,Elvish Archer,Elvish Shaman,Horseman
		role=Supporter
		[/role]
		[message]
		role=Supporter
		message= _ "On your own? My lord! We, your loyal soldiers, will support you!"
		[/message]
		[message]
		description=Delfador
		message= _ "You will prevail. I have faith in you. Head north. Elensefar is but three days' travel if you make haste."
		[/message]
		[message]
		description=Konrad
		message= _ "Very well. But how do I get there?"
		[/message]
		[message]
		description=Delfador
		message= _ "It is north-west of here, a few leagues inland. There are two ways to go, by ship or on foot. Each has its own dangers. You must choose between them."
			[option]
			message= _ "Ships? Ugh! I have been sea sick for the last time. We shall walk!"
				[command]
					[message]
					description=Delfador
					message= _ "Safe journey to you, Konrad. Until we meet again!"
					[/message]
					[kill]
					description=Delfador
					[/kill]
					[endlevel]
					result=victory
					next_scenario=05a_Muff_Malals_Peninsula
					bonus=yes
					[/endlevel]
				[/command]

			[/option]
			[option]
			message= _ "Going by ship we may at least get a little rest for ourselves. By sea it is!"
				[command]
					[message]
					description=Delfador
					message= _ "Safe voyage to you then, Konrad. May the weather be fair."
					[/message]
					[kill]
					description=Delfador
					[/kill]
					[endlevel]
					result=victory
					next_scenario=05b_Isle_of_the_Damned
					bonus=yes
					[/endlevel]
				[/command]
			[/option]
		[/message]
#enddef

	#track which enemy leaders are dead
	[event]
	name=die
		[filter]
		description=Dwaba-Kukai
		[/filter]
		[if]
			[variable]
			name=land_orc_dead
			equals=yes
			[/variable]
			[then]
			{BAY_OF_PEARLS_VICTORY}
			[/then]
			[else]
				[set_variable]
				name=sea_orc_dead
				value=yes
				[/set_variable]
			[/else]
		[/if]
	[/event]

	[event]
	name=die
		[filter]
		description=Managa'Gwin
		[/filter]
		[if]
			[variable]
			name=sea_orc_dead
			equals=yes
			[/variable]
			[then]
			{BAY_OF_PEARLS_VICTORY}
			[/then]
			[else]
				[set_variable]
				name=land_orc_dead
				value=yes
				[/set_variable]
			[/else]
		[/if]
	[/event]

	[event]
	name=time over

		[unit]
		x=14
		y=40
		description=Delfador
		type=Elder Mage
		user_description= _ "Delfador"
		unrenamable=yes
		[modifications]
			{TRAIT_LOYAL}
			{TRAIT_INTELLIGENT}
		[/modifications]
		[/unit]

#if neither of the enemies is dead, automatically lose
		[if]
			[variable]
			name=sea_orc_dead
			not_equals=yes
			[/variable]
			[variable]
			name=land_orc_dead
			not_equals=yes
			[/variable]

			[then]
				[message]
				description=Delfador
				message= _ "Have you not been able to defeat our foes in all these days? They have summoned reinforcements. Surely now our doom is upon us!"
				[/message]
				[endlevel]
				result=defeat
				[/endlevel]
			[/then]

	#if we have killed at least one orcish leader, we
			#go on to the next scenario
			[else]
				[message]
				description=Delfador
				message= _ "Konrad! We cannot spend any more time here. Though it would be good to defeat the orcs and free more of their prisoners, more urgent business calls us!"
				[/message]
				[message]
				description=Konrad
				message= _ "Delfador, thank goodness you have survived! This has been a tough battle, but why can we not finish it? Why must we leave?"
				[/message]
				[message]
				description=Delfador
				message= _ "I bear ill tidings. Asheviere has now laid siege to Elensefar, breaking the century-old treaty between Wesnoth and the Elense city-state. If the city falls, there is no telling how many other lands she may swallow up!"
				[/message]
				[message]
				description=Konrad
				message= _ "I must do this? But you are coming with me, aren't you, Delfador?"
				[/message]
				[message]
				description=Delfador
				message= _ "I am afraid not, Konrad. I have found some important documents that need seeing to. I must ride at once to make council with the elves. I will meet you in Elensefar, after you have secured it."
				[/message]
				[message]
				description=Konrad
				message= _ "I fear I will struggle to do this on my own... but what must be must be. How do I get to Elensefar?"
				[/message]

		#if we killed the orc at sea, we travel by ship
		#if we killed the orc on land, we travel by land
				[if]
					[variable]
					name=sea_orc_dead
					equals=yes
					[/variable]
					[then]
						[message]
						description=Delfador
						message= _ "Since you have broken the orcs' hegemony over the seas, going by ship would be safest. Sail along the coast, and you can land mere miles from Elensefar. Make haste!"
						[/message]
						[kill]
						description=Delfador
						[/kill]
						[endlevel]
						result=victory
						next_scenario=05b_Isle_of_the_Damned
						[/endlevel]
					[/then]
					[else]
						[message]
						description=Delfador
						message= _ "With the orcs controlling the seas, going by ship would not be safe. Travel by land, Elensefar is only six days' march up the coast. Make haste!"
						[/message]
						[kill]
						description=Delfador
						[/kill]
						[endlevel]
						result=victory
						next_scenario=05a_Muff_Malals_Peninsula
						[/endlevel]
					[/else]
				[/if]
			[/else]
		[/if]
	[/event]

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

