[scenario]
#textdomain wesnoth-sof
name= _ "Gathering Materials"
id=4_Gathering_Materials
scenario_generation=cave
next_scenario=4t_The_Jeweler

[generator]
	[settings]
	id=4_Gathering_Materials
	name= _ "Gathering Materials"
	map_data="{@campaigns/Sceptre_of_Fire/maps/4_Gathering_Materials.map}"
	{TURNS 40 37 34}
	victory_when_enemies_defeated=no
	next_scenario=4t_The_Jeweler

		{DEFAULT_MUSIC_PLAYLIST}

		[story]
			[part]
			story= _ "Those who went to the eastern mines were brave indeed. They were infested with trolls and other vile creatures, who thrived in the dark and gloom of the caves."
			[/part]
			[part]
			story= _ "And braver still were Rugnur and his companions, who had to spend two years in those tunnels. For mining is a lengthy business. But they could for the most part avoid the enemy. They only once had to venture into the very heart of the trolls' territory."
			[/part]
			[part]
			background=maps/wesnoth.png
			show_title=yes
			{DOT 271 109}
			{DOT 281 110}
			{DOT 292 111}
			{DOT 302 113}
			{CROSS 312 116}
			[/part]
		[/story]

		{UNDERGROUND}

		{SOF_DEATHS}

		[event]
		name=prestart
			{VARIABLE coalin 0}
			{VARIABLE goldin 0}
			[objectives]
			side=1
				[objective]
				description= _ "Gather the necessary gold and coal to create the sceptre"
				condition=win
				[/objective]
				[objective]
				description= _ "1 load of gold and 2 loads of coal are needed"
				condition=win
				[/objective]
				[objective]
				description= _ "Death of Rugnur"
				condition=lose
				[/objective]
				[objective]
				description= _ "Death of Thursagan"
				condition=lose
				[/objective]
				[objective]
				description= _ "Time runs out"
				condition=lose
				[/objective]
			[/objectives]
		[/event]


		[event]
		name=start
			[recall]
			description=Baglur
			[/recall]
			[recall]
			description=Thursagan
			[/recall]
			[recall]
			description=Kinan
			[/recall]
			[recall]
			description=Rynan
			[/recall]
			[message]
			description=Rugnur
			message= _ "Well, these are the eastern mines. Trolls and ogres live here, be prepared to fight them; also be prepared to spend quite some time here - mining can take a while."
			[/message]
			[message]
			description=Thursagan
			message= _ "For me to make the artifact Haldric wants, I need a special type of gold. I do not know where it was found, but Baglur said these mines were the source of it."
			[/message]
			[message]
			description=Baglur
			message= _ "Also, the only coal that will melt this gold is also here."
			[/message]
			[message]
			description=Rugnur
			message= _ "So we're down here to, what, mine this gold and coal? That should be easy enough."
			[/message]
			[message]
			description=Thursagan
			message= _ "Yes, although we will have to hire the miners - they don't work for free. But beware, there are trolls and such down here..."
			[/message]
		[/event]

		[event]
		name=turn 20
			[gold]
			side=3
			amount=100
			[/gold]
			[allow_recruit]
			side=3
			recruit=Troll,Ogre
			[/allow_recruit]
		[/event]
	[/settings]

map_width=40
map_height=40
flipx_chance=0
village_density=40

	#the chamber with the player. Near the south-west corner
	[chamber]
	id=player
	x=0-10
	y=30-40
	size=8
	jagged=40
		[items]
			[side]
			type=Dwarvish Fighter
			description=Rugnur
			side=1
			canrecruit=1
			recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Gryphon Rider,Dwarvish Miner
			controller=human
			shroud=yes
			[/side]

			[item]
			image=items/chest.png
			[/item]

			[event]
			same_location_as_previous=yes
			name=moveto
			first_time_only=no
				[filter]
					type=Dwarvish Miner
					role=has_coal
				[/filter]
				[message]
				speaker=unit
				message= _ "My load of coal is delivered!"
				[/message]

				{MODIFY_UNIT x,y=$x1,$y1 role ""}

				[set_variable]
				name=coalin
				add=1
				[/set_variable]

				[if]
					[variable]
						name=coalin
						equals=2
					[/variable]
					[then]
						[message]
						speaker=unit
						message= _ "That's the last load of coal we need."
						[/message]
						[if]
							[variable]
							name=goldin
							equals=1
							[/variable]
							[then]
								[message]
								description=Thursagan
								message= _ "This is all we need from these mines. Now we should go back further west, where there are no trolls and ogres, and mine there."
								[/message]
								[clear_variable]
								name=coalin
								[/clear_variable]
								[clear_variable]
								name=goldin
								[/clear_variable]
								[endlevel]
								result=victory
								bonus=no
								[/endlevel]
							[/then]
						[/if]
					[/then]
				[/if]
			[/event]

			[event]
			same_location_as_previous=yes
			name=moveto
			first_time_only=no
				[filter]
					type=Dwarvish Miner
					role=has_gold
				[/filter]
				[message]
				speaker=unit
				message= _ "Here's the gold."
				[/message]

				{MODIFY_UNIT x,y=$x1,$y1 role ""}

				[set_variable]
				name=goldin
				add=1
				[/set_variable]

				[if]
					[variable]
						name=goldin
						equals=1
					[/variable]
					[then]
						[if]
							[variable]
							name=coalin
							equals=2
							[/variable]
							[then]
								[message]
								description=Thursagan
								message= _ "This is all we need from these mines. Now we should go back further west, where there are no trolls and ogres, and mine there."
								[/message]
								[clear_variable]
								name=coalin
								[/clear_variable]
								[clear_variable]
								name=goldin
								[/clear_variable]
								[endlevel]
								result=victory
								bonus=no
								[/endlevel]
							[/then]
						[/if]
					[/then]
				[/if]
			[/event]

			[event]
			name=victory
				[unstore_unit]
				variable=alanin
				[/unstore_unit]
				[clear_variable]
				name=alanin
				[/clear_variable]
				[unstore_unit]
				variable=krawg
				[/unstore_unit]
				[clear_variable]
				name=krawg
				[/clear_variable]
				[kill]
				type=Dwarvish Miner
				[/kill]
			[/event]
		[/items]
	[/chamber]

	#the chamber with the coal. Somewhere in the southeast.
	[chamber]
	id=coal1
	x=28-35
	y=28-35
	size=6
		[passage]
		chance=70
		width=1
		windiness=5
		destination=gold
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=5
		destination=coal2
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=10
		destination=gold
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=10
		destination=coal2
		[/passage]
		[items]
			[side]
			type=Troll
			facing=reverse
			side=2
			canrecruit=1
			controller=ai
				[ai]
				leader_value=10
				recruitment_pattern=fighter
				[/ai]
			recruit=Troll Whelp,Goblin Spearman
			team_name=trolls
			{GOLD 50 70 90}
			{INCOME 4 5 6}
			[/side]

			[item]
			image=items/coal.png
			[/item]

			[event]
			same_location_as_previous=yes
			name=moveto
				[filter]
				side=1
				[/filter]
				[message]
				speaker=unit
				message= _ "Here is some of the coal that we need! Bring the miners to take it!"
				[/message]
			[/event]

			[event]
			same_location_as_previous=yes
			name=moveto
			first_time_only=no
				[filter]
				side=1
				type=Dwarvish Miner
				[/filter]
				[message]
				speaker=unit
				message= _ "I have all the coal I can carry..."
				[/message]
				{MODIFY_UNIT x,y=$x1,$y1 role has_coal}
			[/event]
		[/items]
	[/chamber]

	#the northern chamber with only bad guys. Somewhere in the north-east.
	[chamber]
	id=gold
	x=28-35
	y=5-12
	size=8
	jagged=50
		[passage]
		chance=70
		width=1
		windiness=5
		destination=coal1
		[/passage]
		[passage]
		chance=70
		width=1
		windiness=5
		destination=coal2
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=10
		destination=coal1
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=10
		destination=coal2
		[/passage]
		[items]
			[side]
			type=Troll
			side=3
			canrecruit=1
			controller=ai
				[ai]
				leader_value=20
				recruitment_pattern=fighter
				[/ai]
			recruit=Troll Whelp,Goblin Spearman,Young Ogre
			team_name=trolls
			{GOLD 50 70 90}
			{INCOME 12 14 16}
			[/side]
		[/items]
	[/chamber]

	#chamber with the second coal mine. Somewhere in the north-west.
	[chamber]
	id=coal2
	x=5-12
	y=5-12
	size=6
		[passage]
		chance=70
		width=1
		windiness=5
		destination=gold
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=5
		destination=coal1
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=10
		destination=gold
		[/passage]
		[passage]
		chance=50
		width=1
		windiness=10
		destination=coal1
		[/passage]
		[items]
			[side]
			type=Troll
			side=4
			canrecruit=1
			controller=ai
				[ai]
				leader_value=10
				recruitment_pattern=fighter
				[/ai]
			recruit=Goblin Spearman,Young Ogre
			{GOLD 50 70 90}
			{INCOME 4 5 6}
			[/side]

			[item]
			image=items/coal.png
			[/item]

			[event]
			same_location_as_previous=yes
			name=moveto
				[filter]
				side=1
				[/filter]
				[message]
				speaker=unit
				message= _ "Here is some of the coal that we need! Bring the miners to take it!"
				[/message]
			[/event]

			[event]
			same_location_as_previous=yes
			name=moveto
			first_time_only=no
				[filter]
				side=1
				type=Dwarvish Miner
				[/filter]
				[message]
				speaker=unit
				message= _ "I have all the coal I can carry..."
				[/message]
				{MODIFY_UNIT x,y=$x1,$y1 role has_coal}
			[/event]
		[/items]
	[/chamber]

	#chamber with gold in it that connects to all the others
	[chamber]
	id=connector
	x=15-20
	y=15-20
	size=4
		#passages to both the troll's chamber and the player's chamber
		[passage]
		destination=player
		width=2
		windiness=10
		jagged=5
		[/passage]
		[passage]
		destination=coal1
		width=2
		windiness=10
		jagged=5
		[/passage]
		[passage]
		destination=coal2
		width=2
		windiness=10
		jagged=5
		[/passage]
		[passage]
		destination=gold
		width=2
		windiness=10
		jagged=5
		[/passage]
		[items]
			[item]
			image=items/gold.png
			[/item]

			[event]
			same_location_as_previous=yes
			name=moveto
				[filter]
				side=1
				[/filter]
				[message]
				speaker=unit
				message= _ "Here is the mine of precious gold! Send the miners this way."
				[/message]
			[/event]

			[event]
			same_location_as_previous=yes
			name=moveto
			first_time_only=no
				[filter]
				side=1
				type=Dwarvish Miner
				[/filter]
				[message]
				speaker=unit
				message= _ "I have all the gold I can carry..."
				[/message]
				{MODIFY_UNIT x,y=$x1,$y1 role has_gold}
			[/event]
		[/items]
	[/chamber]
[/generator]
[/scenario]
