[scenario]
id=Peaceful_Valley
next_scenario=A_Haunting_in_Winter
#textdomain wesnoth-did

name=_ "Peaceful Valley"
map_data="{campaigns/Descent_Into_Darkness/maps/Peaceful_valley.map}"
{TURNS 29 26 23}

victory_when_enemies_defeated=no

{STORY_PEACEFUL_VALLEY}

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

[side]
	side=1
	controller=human
	type=Apprentice Mage
	description=Malin Keshar
	user_description=_ "Malin Keshar"
	unrenamable=yes
	canrecruit=1
	recruit=Walking Corpse,Vampire Bat
	{GOLD 120 100 80}
	fog=yes
	shroud=yes
[/side]

[side]
	side=2
	controller=ai
	type=Goblin Knight
	description=T'shar Lggi
	user_description=_ "T'shar Lggi"
	canrecruit=1
	recruit=Goblin Rouser,Goblin Impaler,Wolf Rider
	{GOLD 70 90 110}
	fog=yes
	shroud=no
	[ai]
		village_value=2
		caution=0.5
		recruitment_pattern=scout,fighter
	[/ai]
[/side]

[event]
	name=prestart

	[music]
		name=revelation.ogg
	[/music]

	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Occupy all of the goblin villages"
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Malin Keshar"
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Darken Volk"
		[/objective]
	[/objectives]

	{VARIABLE number_villages 13}
	{VARIABLE villages_owned 0}

	# Set goblin villages
	{SET_VILLAGE 2 4 1}
	{SET_VILLAGE 2 18 2}
	{SET_VILLAGE 2 12 3}
	{SET_VILLAGE 2 4 4}
	{SET_VILLAGE 2 11 5}
	{SET_VILLAGE 2 4 7}
	{SET_VILLAGE 2 8 7}
	{SET_VILLAGE 2 12 7}
	{SET_VILLAGE 2 3 10}
	{SET_VILLAGE 2 7 10}
	{SET_VILLAGE 2 10 11}
	{SET_VILLAGE 2 15 11}
	{SET_VILLAGE 2 6 13}
[/event]

[event]
	name=start
	[unit]
		description=Darken Volk
		user_description="Darken Volk"
		profile=portraits/darken_volk.png
		type=Dark Sorcerer DiD
		unrenamable=yes
		upkeep=loyal
		side=1
		x=15
		y=16
		{IS_HERO}
	[/unit]

	{DIALOGUE_PV_START}
[/event]

# Macros

# Generate a random number of guards between 0 and 2 near X,Y
# Note that this uses BfW's default behavior to shift unit placement when you try to place on top of another unit
#define RANDOM_GUARDS TYPE DESCRIPTION UDESCRIPTION SIDE X Y
{RANDOM 0..2}
{VARIABLE i 0}
[while]
	[variable]
		name=i
		less_than=$random
	[/variable]
	[do]
		[unit]
			description={DESCRIPTION}
			user_description={UDESCRIPTION}
			type={TYPE}
			upkeep=loyal
			side={SIDE}
			x={X}
			y={Y}
			animate=yes
		[/unit]
		{VARIABLE_OP i add 1}
	[/do]
[/while]
{CLEAR_VARIABLE i}
#enddef


# In-scenario events
[event]
	name=capture
	first_time_only=yes
	[filter]
		side=1
	[/filter]
	{DIALOGUE_PV_CAPTURE}
[/event]

[event]
	name=capture
	first_time_only=no
	[filter]
		side=1
	[/filter]
	{RANDOM_GUARDS (Goblin Spearman) Villager (_ "Villager") 2 $x1 $y1}
[/event]

[event]
	name=moveto
	[filter]
		side=1
		x,y=15,11
	[/filter]
	{DIALOGUE_PV_SWAMP1}
[/event]

[event]
	name=moveto
	[filter]
		[not]
			[not]
				description=Darken Volk
			[/not]
			[not]
				description=Malin Keshar
			[/not]
		[/not]
		x=14-15,16-20,19-20
		y=9-10,6-10,11
	[/filter]
	{DIALOGUE_PV_SWAMP2}
	[scroll_to]
		x,y=17,8
	[/scroll_to]
	{UNDEAD_UNIT Ghoul 1 19 7}
	{UNDEAD_UNIT Ghoul 1 17 9}
	{UNDEAD_UNIT Ghoul 1 17 8}
	{DIALOGUE_PV_SWAMP3}
[/event]

{DIALOGUE_PV_EE}

# Defeat Conditions
{MALIN_DEATH}
{VOLK_DEATH}
{TIME_OUT_LOSE}

# Victory Condition
#[event]
#	name=capture
#	first_time_only=no
#	[filter]
#		side=2
#	[/filter]
#	{VARIABLE_OP villages_owned add -1}
#[/event]

[event]
	name=capture
	first_time_only=no
	[filter]
		side=1
	[/filter]
#	{VARIABLE_OP villages_owned add 1}
	#when capturing a village we check if we own all villages of the map
	[store_villages]
		variable=villages
		owner_side=1
	[/store_villages]
	[if]
		[variable]
#			name=villages_owned
			name=villages.length
			numerical_equals=$number_villages
		[/variable]
		[then]
			[endlevel]
				bonus=yes
				result=victory
			[/endlevel]
			{DIALOGUE_PV_END}
		[/then]
	[/if]
[/event]

[event]
	name=victory
	{CLEAR_VARIABLE number_villages}
	#{CLEAR_VARIABLE villages_owned}
	{CLEAR_VARIABLE villages}
[/event]

[/scenario]
