[scenario]
#textdomain wesnoth-sof
name= _ "Closing the Gates"
id=2_Closing_the_Gates
turns=15
map_data="{@campaigns/Sceptre_of_Fire/maps/2_Closing_the_Gates.map}"
next_scenario=2t_In_the_Dwarven_City
victory_when_enemies_defeated=no

	{DEFAULT_MUSIC_PLAYLIST}

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

	[side]
	type=Dwarvish Fighter
	description=Rugnur
	side=1
	canrecruit=1
	shroud=yes
	controller=human
	recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman
	team_name=good
	[/side]

	[side]
	type=Elvish Captain
	description=Glindur
	user_description= _ "Glindur"
	side=2
	canrecruit=1
	{RECRUIT (Elvish Fighter,Elvish Scout,Elvish Archer,Elvish Shaman) (Elvish Fighter,Elvish Hero,Elvish Scout,Elvish Archer,Elvish Shaman) (Elvish Fighter,Elvish Hero,Elvish Scout,Elvish Archer,Elvish Ranger,Elvish Shaman)}
	{GOLD 200 250 300}
	{INCOME 5 7 9}
		[ai]
		grouping=offensive
		[/ai]
	[/side]

	[side]
	no_leader=yes
	side=3
	[/side]

	[story]
		[part]
		story= _ "Next in our story, Rugnur retreated into the caves of Knalga.  But the elves pressed on, and would enter the caves shortly."
		[/part]
		[part]
		background=maps/wesnoth.png
		show_title=yes
		{DOT 238 136}
		{CROSS 241 131}
		[/part]
	[/story]

	{SOF_DEATHS}

	[event]
	name=prestart
		[objectives]
		side=1
			[objective]
			description= _ "Place someone on each of the six magic glyphs in order to close the dwarvish gates"
			condition=win
			[/objective]
			[objective]
			description= _ "Kill all elves who are in the caves after the gates are closed"
			condition=win
			[/objective]
			[objective]
			description= _ "Death of Rugnur"
			condition=lose
			[/objective]
			[objective]
			description= _ "Death of Baglur"
			condition=lose
			[/objective]
			[objective]
			description= _ "Time runs out"
			condition=lose
			[/objective]
		[/objectives]

		[kill]
		side=1
		type=Caravan
		[/kill]
		[remove_shroud]
		x= 1-3,   4, 5-6, 7-14,15-16,   17,   18,   19,   20,21-22,   23,   24,12-32
		y=5-28,7-28,9-28,13-28,18-28,19-28,20-28,21-28,22-28,23-28,25-28,26-28, 9-13
		[/remove_shroud]
		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=6,3
		side=3)}
		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=6,3
		side=3)}
		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=6,3
		side=3)}

		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=30,25
		side=3)}
		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=30,25
		side=3)}
		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=30,25
		side=3)}
#ifdef HARD
		{RANDOM_TRAIT_UNIT (
		type=Troll
		x,y=30,25
		side=3)}
#endif
#ifdef NORMAL
		{RANDOM_TRAIT_UNIT (
		type=Troll Whelp
		x,y=30,25
		side=3)}
#endif

		[item]
			x,y=12,12
			image=scenery/rubble.png
		[/item]
		[item]
			x,y=13,13
			image=scenery/rubble.png
		[/item]
		[item]
			x,y=14,13
			image=scenery/rubble.png
		[/item]
	[/event]

	[event]
	name=start
		{MOVE_UNIT description=Rugnur 22 12}
		[recall]
		description=Alanin
		[/recall]
		[redraw]
			side=1
		[/redraw]
		[message]
		description=Rugnur
		message= _ "These elves are right behind me! We have to go warn the council of this attack!..."
		[/message]
		[message]
		description=Alanin
		message= _ "Here - I'll go warn the council. You stay here and fight."
		[/message]
		[message]
		description=Rugnur
		message= _ "Yes, that sounds good. I'll stay here and try to defend the gates..."
		[/message]
		{MOVE_UNIT description=Alanin 32 12}
		[store_unit]
			[filter]
			description=Alanin
			[/filter]
		variable=changealanin
		kill=yes
		[/store_unit]
		[message]
		description=Glindur
		message= _ "I see you have sent a messenger to the city. Good idea, but will it really help? We have more troops and more provisions, and we are going to enter those caves and kill you!"
		[/message]
		[message]
		description=Rugnur
		message= _ " *gulp*"
		[/message]
		[message]
		description=Glindur
		message= _ "Ha! I thought as much. Well then, surrender!"
		[/message]
		[message]
		description=Rugnur
		message= _ "Um... on what terms?"
		[/message]
		[message]
		description=Glindur
		message= _ "Unconditional."
		[/message]
		{RANDOM_TRAIT_UNIT (
		type=Dwarvish Guardsman
		generate_description=yes
		x,y=10,13
		side=1)}
		{RANDOM_TRAIT_UNIT (
		type=Dwarvish Guardsman
		generate_description=yes
		x,y=14,15
		side=1)}
		{RANDOM_TRAIT_UNIT (
		type=Dwarvish Guardsman
		generate_description=yes
		x,y=12,12
		side=1)}
		{RANDOM_TRAIT_UNIT (
		type=Dwarvish Guardsman
		generate_description=yes
		x,y=14,13
		side=1)}
#ifdef EASY
		{RANDOM_TRAIT_UNIT (
		type=Dwarvish Guardsman
		generate_description=yes
		x,y=12,14
		side=1)}
#endif
		[unit]
		x,y=22,11
		type=Dwarvish Stalwart
		side=1
		description=Baglur
		user_description= _ "Baglur"
		{IS_HERO}
		profile=portraits/baglur.png
			[modifications]
				{TRAIT_LOYAL}
				{TRAIT_RESILIENT}
			[/modifications]
		[/unit]
		[message]
		description=Baglur
		message= _ "Wait! Rugnur, didn't they tell you ANYTHING when you took command here?!?"
		[/message]
		[message]
		description=Rugnur
		message= _ "Not really. This was supposedly a time of peace. Who are you?"
		[/message]
		[message]
		description=Baglur
		message= _ "Argh! I'm a retired warrior... it looks like I'll have to come out and help you, or we'll be overrun by the damn elves... argh again. Well, listen here. This entrance to the city can be closed. There's a gate. If we can close it, the elves will not be able to enter. And you elves; begone from here!"
		[/message]
		[message]
		description=Glindur
		message= _ "Cease your meddling, old dwarf! Rugnur is in charge here, and it is he who will bargain with us."
		[/message]
		[message]
		description=Rugnur
		message= _ "Baglur, how do you close the gates?"
		[/message]
		[message]
		description=Baglur
		message= _ "Agh, well that's the difficulty. Its a magic gate. Indestructible. But that means it can only be closed by magic. You need to position a warrior on each of the six glyphs. When all are occupied, the gates will close. Then the elves will be shut out of the caves forever, at least through this entrance."
		[/message]
		[message]
		description=Rugnur
		message= _ "Don't we have troops positioned near these glyphs, to unlock them?"
		[/message]
		[message]
		description=Baglur
		message= _ "Argh, well, no. Lately trolls have been more in charge of those caves where the glyphs are than we dwarves have."
		[/message]
		[message]
		description=Rugnur
		message= _ "Well, where are they located?"
		[/message]
		[message]
		description=Baglur
		message= _ "Two are down a side passage in the northwest, another two are in a similar location in the southeast, and two are right next to the front gate."
		[/message]
		[message]
		description=Glindur
		message= _ "Have you made up your mind yet about surrendering?! If you will not give up, prepare for battle!"
		[/message]
		[message]
		description=Rugnur
		message= _ "You may be more powerful than us, but I doubt even you can blast through Dwarf-made stonecraft. We refuse - now let's close these gates!"
		[/message]
		[item]
		x,y=9,11
		image=scenery/rune1.png
		[/item]
		[item]
		x,y=14,3
		image=scenery/rune2.png
		[/item]
		[item]
		x,y=30,19
		image=scenery/rune3.png
		[/item]
		[item]
		x,y=17,15
		image=scenery/rune4.png
		[/item]
		[item]
		x,y=3,5
		image=scenery/rune1.png
		[/item]
		[item]
		x,y=23,24
		image=scenery/rune2.png
		[/item]
	[/event]

	[event]
	name=moveto
		[filter]
		x,y=3,5
		side=1
		[/filter]
		[message]
		speaker=unit
		message= _ "But what about this entrance? The elves can come through it just as easily as the main gate, and it cannot be closed!"
		[/message]
		[message]
		description=Baglur
		message= _ "I think it can be sealed up somehow... Yes, look, activating that glyph seems to have closed up the gap."
		[/message]
		[terrain]
		x,y=2,6
		letter=Xu
		[/terrain]
	[/event]

	[event]
	name=moveto
		[filter]
		x,y=23,24
		side=1
		[/filter]
		[message]
		speaker=unit
		message= _ "But what about this entrance? The elves can come through it just as easily as the main gate, and it cannot be closed!"
		[/message]
		[message]
		description=Baglur
		message= _ "I think it can be sealed up somehow... Yes, look, activating that glyph seems to have closed up the gap."
		[/message]
		[terrain]
		x,y=21,24
		letter=Xu
		[/terrain]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		x=9,14,30,17,3,23
		y=11,3,19,15,5,24
		side=1
		[/filter]
		[if]
			[have_unit]
			x,y=9,11
			side=1
			[/have_unit]
			[have_unit]
			x,y=14,3
			side=1
			[/have_unit]
			[have_unit]
			x,y=30,19
			side=1
			[/have_unit]
			[have_unit]
			x,y=17,15
			side=1
			[/have_unit]
			[have_unit]
			x,y=3,5
			side=1
			[/have_unit]
			[have_unit]
			x,y=23,24
			side=1
			[/have_unit]
			[then]
				[message]
				description=Rugnur
				message= _ "We have everyone positioned on the glyphs! What do we do now?"
				[/message]
				[message]
				description=Baglur
				message= _ "Just watch. The gates will close very soon. Then the elves outside - and, unfortunately, our dwarves who are still out there - will become irrelevant."
				[/message]
				[scroll_to]
				x,y=13,13
				[/scroll_to]

				[delay]
				time=200
				[/delay]
				[sound]
					name=gunshot.wav
				[/sound]
				[removeitem]
					x,y=12,12
				[/removeitem]
				[terrain]
				x=12
				y=12
				letter=Xu
				[/terrain]
				[redraw]
				[/redraw]

				[delay]
				time=200
				[/delay]
				[sound]
					name=gunshot.wav
				[/sound]
				[removeitem]
					x,y=13,13
				[/removeitem]
				[terrain]
				x=13
				y=13
				letter=Xu
				[/terrain]
				[redraw]
				[/redraw]

				[delay]
				time=200
				[/delay]
				[sound]
					name=gunshot.wav
				[/sound]
				[removeitem]
					x,y=14,13
				[/removeitem]
				[terrain]
				x=14
				y=13
				letter=Xu
				[/terrain]
				[redraw]
				[/redraw]

				[message]
				description=Glindur
				message= _ "Agh! Well, you have defeated me for now, but eventually you will have to exit these caves, to give Haldric back his jewel. And when you do, we will be ready for you."
				[/message]
				[message]
				description=Baglur
				message= _ "If that is what you choose to do, fine, but be prepared to wait for many years."
				[/message]

				[kill]
				x=   1,   2,   3,   4,    5,    6,  7-8,    9,10-12,13-14,15-16,   17,   18,   19,   20,21-22
				y=7-28,7-28,8-28,9-28,10-28,12-28,13-28,14-28,13-28,14-28,18-28,19-28,20-28,21-28,22-28,26-28
				side=1
				fire_event=yes
				animate=yes
				[/kill]

				[kill]
				x=   1,   2,   3,   4,    5,    6,  7-8,    9,10-12,13-14,15-16,   17,   18,   19,   20,21-22
				y=7-28,7-28,8-28,9-28,10-28,12-28,13-28,14-28,13-28,14-28,18-28,19-28,20-28,21-28,22-28,26-28
				side=2,3
				fire_event=no
				[/kill]

				[place_shroud]
				x=   1,   2,   3,   4,    5,    6,  7-8,    9,10-12,13-14,15-16,   17,   18,   19,   20,21-22
				y=7-28,7-28,8-28,9-28,10-28,12-28,13-28,14-28,13-28,14-28,18-28,19-28,20-28,21-28,22-28,26-28
				[/place_shroud]
				[if]
					[have_unit]
					side=2
					[/have_unit]
					[then]
						[message]
						description=Rugnur
						message= _ "There are still some elves left in here. We have to eliminate them, too, unless they surrender."
						[/message]
						[role]
						role=elf
						side=2
						[/role]
						[message]
						role=elf
						message= _ "You would have us be cowards! We do not surrender."
						[/message]
						[objectives]
						side=1
							[objective]
	 						description= _ "Kill all elves who are in the caves"
							condition=win
							[/objective]
							[objective]
							description= _ "Death of Rugnur"
							condition=lose
							[/objective]
							[objective]
							description= _ "Death of Baglur"
							condition=lose
							[/objective]
							[objective]
							description= _ "Time runs out"
							condition=lose
							[/objective]
						[/objectives]
						[event]
						name=die
						first_time_only=no
							[filter]
							side=2
							[/filter]
							[if]
								[have_unit]
								side=2
								[/have_unit]
								[then]
								[/then]
								[else]
									[message]
									description=Rugnur
									message= _ "That's all of the elves. Now I should go down to the city and report. I'm late already..."
									[/message]
									[endlevel]
									result=victory
									bonus=yes
									[/endlevel]
								[/else]
							[/if]
						[/event]
					[/then]
					[else]
						[message]
						description=Rugnur
						message= _ "Well, now I should go down to the city and report. I'm late already..."
						[/message]
						[endlevel]
						result=victory
						bonus=yes
						[/endlevel]
					[/else]
				[/if]
			[/then]
			[else]
				[message]
				speaker=unit
				message= _ "My glyph is on."
				[/message]

				[allow_undo][/allow_undo]
			[/else]
		[/if]
	[/event]

	[event]
	name=die
		[filter]
		description=Baglur
		[/filter]
		[endlevel]
		result=defeat
		[/endlevel]
	[/event]
[/scenario]
