[scenario]
	id=10_Gryphon_Mountain
	#textdomain wesnoth-httt
	name= _ "Gryphon Mountain"
	map_data="{campaigns/Heir_To_The_Throne/maps/10_Gryphon_Mountain.map}"
	{SCENARIO_MUSIC "knolls.ogg"}
	{TURNS 27 24 21}

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

	next_scenario=11_The_Ford_of_Abez

	[event]
	name=prestart
		[objectives]
		side=1
			[objective]
				description= _ "Defeat the mother gryphon and the enemy commander"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Konrad"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Delfador"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Kalenz"
				condition=lose
			[/objective]
		[/objectives]
	[/event]

	{BIGMAP_GRYPHON_MOUNTAIN}

	{PLACE_IMAGE scenery/nest-empty.png 10 14}

	{PLACE_IMAGE scenery/nest-empty.png 16 16}

	{PLACE_IMAGE scenery/nest-empty.png 12 18}

	{PLACE_IMAGE scenery/nest-full.png 13 16}


	[side]
	type=Commander
	description=Konrad
	user_description= _ "Konrad"
	unrenamable=yes
	side=1
	canrecruit=1
	controller=human
#ifdef HARD
	gold=100
#else
	gold=300
#endif
	[/side]

	[side]
	type=General
	description=Robert
	user_description= _ "Robert"
	side=2
	canrecruit=1
	recruit=Cavalryman,Swordsman,Mage,Ogre,Duelist,Longbowman
		[ai]
		{ATTACK_DEPTH 1 3 5}
		recruitment_pattern=scout,fighter,fighter,fighter,archer,mixed fighter
		[/ai]
	{GOLD 160 270 350}
	[/side]

	[side]
	type=Gryphon
	description=Mother Gryphon
	user_description= _ "Mother Gryphon"
	side=3
	canrecruit=1
	recruit=Gryphon
	gold=0
		[ai]
		{ATTACK_DEPTH 1 3 5}
		passive_leader=yes
		[/ai]
	[/side]

	[event]
	name=prestart
		[recall]
		description=Delfador
		[/recall]
		[recall]
		description=Kalenz
		[/recall]

		{UNIT (Sleeping Gryphon) (Graak) ( _ "Graak") 3 12 18}
		{UNIT (Sleeping Gryphon) (Grook) ( _ "Grook") 3 16 16}
		{UNIT (Sleeping Gryphon) (Gruak) ( _ "Gruak") 3 10 14}

		{VARIABLE gryphon_disposition 1}
	[/event]

	[event]
	name=start
		[message]
		description=Konrad
		message= _ "What is this place? That is one big mountain!"
		[/message]
		[message]
		description=Delfador
		message= _ "That is the fabled Gryphon Mountain."
		[/message]
		[message]
		description=Konrad
		message= _ "Gryphon Mountain! Maybe we could steal some eggs from the gryphons and train the young to be flying mounts. Would that work, Delfador?"
		[/message]
		[message]
		description=Delfador
		message= _ "We can try to do that, but we must be careful. To disturb the gryphons could prove dangerous... and yet such mounts could help us greatly later. Whatever we do, we must pass by this place."
		[/message]
		[message]
		description=Konrad
		message= _ "Well, let's start climbing the mountain!"
		[/message]
	[/event]

	#if the player kills the mother gryphon
	#and gets her eggs
	[event]
	name=die
		[filter]
		description=Mother Gryphon
		[/filter]
		[filter_second]
		side=1
		[/filter_second]
		[message]
		speaker=second_unit
		message= _ "Here are the mother Gryphon's eggs!"
		[/message]
		[message]
		description=Konrad
		message= _ "Excellent! We should be able to breed Gryphons for our own uses now!"
		[/message]
		[set_variable]
		name=get_gryphons
		value=1
		[/set_variable]
	[/event]

	[event]
	name=turn 2
		[message]
		description=Delfador
		message= _ "It appears that we are not the only ones interested in this mountain. Once again the Queen opposes us!"
		[/message]
		[message]
		description=Konrad
		message= _ "Quickly, men! Onward!"
		[/message]
	[/event]

	#if the enemy gets to the gryphon eggs first
	[event]
	name=die
		[filter]
		description=Mother Gryphon
		[/filter]
		[filter_second]
		side=2
		[/filter_second]
		[message]
		speaker=second_unit
		message= _ "Ha ha! We have killed this foul beast of the air, and can deny the rebels its eggs!"
		[/message]
		{VARIABLE_OP gryphon_disposition add -1}
	[/event]
	[event]
	name=attack
		[filter]
		side=2
		[/filter]
		[filter_second]
		side=3
		[/filter_second]
		{VARIABLE_OP gryphon_disposition add 2}
	[/event]
	[event]
	name=attack
	first_time_only=no
		[filter]
		side=1
		[/filter]
		[filter_second]
		side=3
		[/filter_second]
		{VARIABLE_OP gryphon_disposition add -1}
	[/event]
	[event]
	name=die
		[filter]
		side=3
		[/filter]
		[filter_second]
		side=1
		[/filter_second]
		{VARIABLE_OP gryphon_disposition add -10}
	[/event]


	[event]
	name=victory
		[message]
		description=Konrad
		message= _ "We have defeated them! Now what do we do?"
		[/message]
		[message]
		description=Delfador
		message= _ "We must continue north. It is too late to return to the safety of Elensefar or Anduin before winter falls. We must therefore cross the great river and continue toward the land of the dwarves. Hurry, let us go!"
		[/message]
		[if]
			[variable]
			name=get_gryphons
			numerical_equals=1
			[/variable]
			[then]
				[message]
				description=Konrad
				message= _ "With these gryphon eggs we should be able to breed gryphons that will serve us. When they are large enough to carry mounts, we can hire gryphon riders!"
				[/message]
			[/then]
			[else]
				[if]
				[and]
					[variable]
					name=gryphon_disposition
					greater_than_equal_to=2
					[/variable]
					[have_unit]
					side=3
					[/have_unit]
				[/and]
				[then]
					[message]
					description=Konrad
					message= _ "It is a shame we could not get those gryphon eggs. I am glad we did not slaughter any gryphons. They are magnificent animals (looks back at the mountain). Still..."
					[/message]
					[message]
					description=Konrad
					message= _ "Woah!!"
					[/message]
					#
					# Wake up all the sleeping gryphons
					#
					[store_unit]
					variable=gryphon_store
						[filter]
						side=3
						[/filter]
					[/store_unit]
					{FOREACH gryphon_store i}
					{VARIABLE gryphon_store[$i].type Gryphon}
					[unstore_unit]
					variable=gryphon_store[$i]
					[/unstore_unit]
					{NEXT i}
					{CLEAR_VARIABLE gryphon_store}
					#
					# Figure out where Konrad is standing
					#
					[store_unit]
					variable=konrad_store
						[filter]
						description=Konrad
						[/filter]
					[/store_unit]
					[if]
						[variable]
						name=konrad_store.x
						greater_than=13
						[/variable]
						[then]
							{VARIABLE destination_x 24}
						[/then]
						[else]
							{VARIABLE destination_x 1}
						[/else]
					[/if]
					[if]
						[variable]
						name=konrad_store.y
						greater_than=16
						[/variable]
						[then]
							{VARIABLE destination_y 39}
						[/then]
						[else]
							{VARIABLE destination_y 1}
						[/else]
					[/if]
					#
					# Put some more gryphons up there and view the mountain
					#
					{UNIT (Gryphon) (Graik) ( _ "Graik") 3 13 14}
					{UNIT (Gryphon) (Griak) ( _ "Griak") 3 13 18}
					[scroll_to]
					x,y=13,16
					[/scroll_to]
					[message]
					speaker=narrator
					image="wesnoth-icon.png"
					message= _ "Indeed, the majestic beasts were now circling the mountain's peak. Several glared in Konrad's direction, their eagle eyes fixed on him at an incredible distance."
					[/message]
					[sound]
					name=gryphon-shriek-1.ogg
					[/sound]
					[store_unit]
					variable=gryphon_store
						[filter]
						side=3
						[/filter]
					[/store_unit]
					{FOREACH gryphon_store i}
						{VARIABLE_OP temp_x format $gryphon_store[$i].x}
						{VARIABLE_OP temp_y format $gryphon_store[$i].y}
						{VARIABLE_OP range_x format ("$temp_x|, $destination_x")}
						{VARIABLE_OP range_y format ("$temp_y|, $destination_y")}
						[kill]
						x=$temp_x
						y=$temp_y
						[/kill]
						[move_unit_fake]
						type=Gryphon
						x=$range_x
						y=$range_y
						[/move_unit_fake]
					{NEXT i}
					{CLEAR_VARIABLE konrad_store}
					{CLEAR_VARIABLE gryphon_store}
					{CLEAR_VARIABLE temp_x}
					{CLEAR_VARIABLE temp_y}
					{CLEAR_VARIABLE range_x}
					{CLEAR_VARIABLE range_y}
					{CLEAR_VARIABLE destination_x}
					{CLEAR_VARIABLE destination_y}
					[message]
					description=Delfador
					message= _ "Amazing! I have never before heard of such behavior in gryphons."
					[/message]
					[message]
					description=Konrad
					message= _ "What does it mean?"
					[/message]
					[message]
					description=Delfador
					message= _ "I do not know. Come now, the show is over."
					[/message]
				[/then]
				[else]
					[message]
					description=Konrad
					message= _ "It is a shame we could not get those gryphon eggs - they would surely have given us an advantage sometime. Still, we must continue."
					[/message]
				[/else]
				[/if]
			[/else]
		[/if]
		[message]
		description=Delfador
		message= _ "Let us continue onward!"
		[/message]
	[/event]

	#
	# If the sleeping gryphon is attacked, it wakes up
	#

	[event]
	name=attack
	[filter_second]
		description=Graak
	[/filter_second]
	[kill]
		description=Graak
	[/kill]
	{UNIT (Gryphon) (Rampant Graak) ( _ "Rampant Graak") 3 12 18}
	[/event]

	[event]
	name=attack
	[filter_second]
		description=Grook
	[/filter_second]
	[kill]
		description=Grook
	[/kill]
	{UNIT (Gryphon) (Rampant Grook) ( _ "Rampant Grook") 3 16 16}
	[/event]

	[event]
	name=attack
	[filter_second]
		description=Gruak
	[/filter_second]
	[kill]
	description=Gruak
	[/kill]
	{UNIT (Gryphon) (Rampant Gruak) ( _ "Rampant Gruak") 3 10 14}
	[/event]

	#
	# If the sleeping gryphon attacks you, it wakes up
	#

	[event]
	name=attack
	[filter]
		description=Graak
	[/filter]
	[kill]
		description=Graak
	[/kill]
	{UNIT (Gryphon) (Rampant Graak) ( _ "Rampant Graak") 3 12 18}
	[/event]

	[event]
	name=attack
	[filter]
		description=Grook
	[/filter]
	[kill]
		description=Grook
	[/kill]
	{UNIT (Gryphon) (Rampant Grook) ( _ "Rampant Grook") 3 16 16}
	[/event]

	[event]
	name=attack
	[filter]
		description=Gruak
	[/filter]
	[kill]
	description=Gruak
	[/kill]
	{UNIT (Gryphon) (Rampant Gruak) ( _ "Rampant Gruak") 3 10 14}
	[/event]

	#
	# Neutralize the movement goal for sleeping gryphons every turn
	#
	[event]
	name=side turn
	first_time_only=no
		[store_unit]
		variable=sleepy_gryphon_store
			[filter]
			type=Sleeping Gryphon
			[/filter]
		[/store_unit]
		{FOREACH sleepy_gryphon_store i}
		{VARIABLE_OP x_temp format $sleepy_gryphon_store[$i].x}
		{VARIABLE_OP y_temp format $sleepy_gryphon_store[$i].y}
		{VARIABLE sleepy_gryphon_store[$i].goto_x x_temp}
		{VARIABLE sleepy_gryphon_store[$i].goto_y y_temp}
		[unstore_unit]
		variable=sleepy_gryphon_store[$i]
		[/unstore_unit]
		{NEXT i}
		{CLEAR_VARIABLE sleepy_gryphon_store}
		{CLEAR_VARIABLE x_temp}
		{CLEAR_VARIABLE y_temp}
	[/event]

	{campaigns/Heir_To_The_Throne/utils/deaths.cfg}

[/scenario]
