# Level 8: Out of the Frying Pan...

[scenario]
#textdomain wesnoth-utbs

id="8_OutoftheFryingPan"
name= _ "Out of the Frying Pan"
label= _ "Out of the Frying Pan"

next_scenario=9_BloodisThickerThanWater

{DESERTMAP 8Frying8}

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

#don't display snapshot of map in saved games
snapshot="no"

#max turns in scenario varies depending on difficulty
#ifdef EASY
turns="72"
#endif
#ifdef MEDIUM
turns="68"
#endif
#ifdef HARD
turns="64"
#endif

victory_when_enemies_defeated=no

{DAWN1}
{MORNING1}
{MIDDAY1}
{AFTERNOON1}
{DUSK1}
{SHORTDARK}
{DAWN2}
{MORNING2}
{MIDDAY2}
{AFTERNOON2}
{DUSK2}
{LONGDARK1}
{LONGDARK2}
{LONGDARK3}
{LONGDARK4}

#Side 1: elves
[side]
	side=1
	description=Kaleh
	type=Desert Fighter
	canrecruit=1
	{INCOME 4 2 0}
	controller=human
	shroud=yes
	fog=no
	team_name=elf_ally

[/side]

#Side 2: Human forces (blue)
[side]
	side=2
	no_leader=yes
	canrecruit=1
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=human_ally

	#ifdef EASY
	recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Bowman, Longbowman
	#endif

	#ifdef MEDIUM
	recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Dragoon, Bowman, Longbowman
	#endif

	#ifdef HARD
	recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Dragoon, Bowman, Longbowman
	#endif

	[ai]
		#ifdef EASY
		recruitment_pattern=scout,fighter,archer,mixed fighter
		#endif

		#ifdef MEDIUM
		recruitment_pattern=scout,fighter,archer,mixed fighter
		#endif

		#ifdef HARD
		recruitment_pattern=scout,fighter,archer,mixed fighter
		#endif

		aggression=0.6
		caution=0.1

		# AI will attack a weak unit with a max of 3,4,5 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 3 4 5}

		passive_leader=yes

		[target]
		side=1
		value=10
		[/target]

		[target]
		side=5
		value=1
		[/target]

	[/ai]
[/side]


#Side=3 undead cultists (green)
[side]
	side=3
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=cultists_ally

	[ai]
		# AI will attack a weak unit with a max of 3,4,5 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 3 4 5}

		aggression=0.8
		caution=0.1
	[/ai]

[/side]

#Side=4 confused ants (yellow)
[side]
	side=4
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no

	[ai]
		# AI will attack a weak unit with a max of 3,4,5 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 2 3 4}

		aggression=-0.99
		caution=0.99

		#keep ants from running too far down the tunnel
		[avoid]
		x=31-36
		y=45-49
		[/avoid]
	[/ai]
[/side]

#Side=5 Vengeful Undead
[side]
	side=5
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=human_ally

	#ifdef EASY
	recruit=EGhost, EWraith, EShadow
	#endif

	#ifdef MEDIUM
	recruit=EGhost, EWraith, EShadow
	#endif

	#ifdef HARD
	recruit=EGhost, EWraith, EShadow
	#endif

	[ai]
		# AI will attack a weak unit with a max of 3,4,5 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 3 4 5}

		aggression=0.75
		caution=0.1

		# this code unnecessary if allied with humans

		#[target]
		#side=1
		#value=15
		#[/target]

		#[target]
		#side=2
		#value=1
		#[/target]

		recruitment_pattern=fighter,scout,fighter

		# keep undead away from player's base
		# option 1 is to avoid x=1-19 (let them enter cave but not
		# sneak around behind base)
		# option 2 is to avoid x=1-25 (lets them get near cave
		# but not enter it)

		[avoid]
		x,y=1-25,1-60
		[/avoid]

	[/ai]

[/side]


#Side=6 dwarf/troll pursuers
[side]
	side=6
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no

	[ai]
		# AI will attack a weak unit with a max of 2,3,4 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 2 3 4}

		aggression=0.8
		caution=0.1
	[/ai]
[/side]

#Side=7 Assassin/Cloaked Figure's side
[side]
	side=7
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=yes
	fog=no
	team_name=monster

	[ai]
		aggression=0.90
		caution=0.10

		[avoid]
		x=10-20
		y=10-18
		[/avoid]

		[target]
		description=Kaleh
		value=20
		[/target]
	[/ai]



[/side]

#Side=8 Human messengers
[side]
	side=8
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=human_ally

	[ai]
		# AI will attack a weak unit with a max of 3,4,5 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 3 4 5}

		aggression=0.75
		caution=0.25

		[leader_goal]
		x=29-60
		y=1
		[/leader_goal]

		protect_leader=10.0
		protect_leader_radius=20

		[target]
		side=1
		value=50
		[/target]

		[target]
		side=5
		value=1
		[/target]
	[/ai]
[/side]

#Side=9 temple demons

[side]
	side=9
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=cultists_ally

	[ai]
		# AI will attack a weak unit with a max of 3,4,5 units
		# depending on the difficulty (default=5)
		{ATTACK_DEPTH 3 4 5}

		aggression=0.7
		caution=0.1
	[/ai]
[/side]


[story]
	[part]
	story= _ "Chapter 8: I set out with a lightened heart and quickened step; we were going back up and I was sure that soon this underground gauntlet would be over. With the help of our new allies, I felt much more confident than I had before. Oh to feel the wind in my hair and the sun on my face. But for now we had many more miles to wend and in the monotony of the marching I let my mind wander to bigger matters."
	[/part]

	[part]
	story= _ "What kind of home had Eloh prepared for us on the other side of the mountains? Was there anywhere in the world that hadn't been plagued with war and destruction? I grew up in a land of 'kill or be killed'. Outlaws, ogres and other monsters preyed on the weak and helpless. Orcs and goblins raided any settlements they could find, and my people struggled to protect what little they had. And through it all crazed necromancers and undead spirits haunted the sands, feeding on the few survivors."
	[/part]

	[part]
	story= _ "At first I thought that if we could just leave the desert, we could find a peaceful place away from all the bloodshed and death. But even underground the last remnants of the trolls and dwarves continue to fight a bloody struggle to the death. Is this what our world has become? And why did Eloh tell me to 'kill the unbelievers'? If we had attacked both the dwarves and the trolls we would not have made it even this far. Everywhere I look I see remains of once great empires. If we help destroy the last of these peoples who will be left?"
	[/part]

	[part]
	story= _ "And yet, here in the dark, Eloh says she is powerless. Here she cannot help us, we must fend for ourselves. Though she is our god, I cannot just lie back and depend on her to always save us. These are my people too, and I have a responsibility to them as their leader. I must make my own decisions as I see best. And as Zhul told me when I was but a child, Eloh forgives all our sins. If I err in my judgment she will surely understand. Eloh may be our guide, but I am our leader and I will do what I must to protect my people during our journey."
	[/part]

	[part]
	story= _ "And so, bolstered with a new resolve, I continued the march up out of the darkness and towards a new land."
	[/part]
[/story]

# Prestart functions:
# insert items onto map
# kill Elyssa to keep her from being recruited
# increase cost of recruiting units
# place item images on map
# recall main heroes
# initialize starting variables
# remove shroud surrounding starting position
# add more dirt at easier difficulties
# set starting scenario objectives

[event]
name=prestart

#escaped from caves events tests
#{UNIT_ (Desert Archer) (Test) ( _ "Test") 1 24 23}
#{UNIT_ (Desert Fighter) (Test) ( _ "Test") 1 20 20}

#training hall test
#{UNIT_ (Great Mage) (Test) ( _ "Test") 1 12 44}

#wizard lair tests
#{UNIT_ (Great Mage) (Test) ( _ "Test") 1 16 27}
#{UNIT_ (Great Mage) (Test) ( _ "Test") 1 16 27}
#{UNIT_ (Desert Star) (Test) ( _ "Test") 1 16 27}

#cloaked figure tests
#{UNIT_ (Great Mage) (Test) ( _ "Test") 1 10 21}
#{UNIT_ (Great Mage) (Test) ( _ "Test") 1 10 21}

# add items to map

	# main gate guardian runes
	{PUT_IMG items/rune2-burning.png 23 48}
	{PUT_IMG items/rune2-burning.png 20 45}

	# wizard chamber guardian rune
	{PUT_IMG items/rune4-burning.png 18 34}

	# wizard's monster trapping runes
	{PUT_IMG items/rune3-burning.png 17 32}
	{PUT_IMG items/rune3-burning.png 19 32}

	# wizard's magic circle
	{PUT_IMG items/magiccircle-nw.png 17 29}
	{PUT_IMG items/magiccircle-n.png 18 28}
	{PUT_IMG items/magiccircle-ne.png 19 29}
	{PUT_IMG items/magiccircle-sw.png 17 30}
	{PUT_IMG items/magiccircle-s.png 18 30}
	{PUT_IMG items/magiccircle-se.png 19 30}

	# golem trapped in magic circle
	{PUT_IMG flesh-golem.png 18 29}

	# wizard's dragon statues
	{PUT_IMG items/dragonstatue.png 16 28}
	{PUT_IMG items/dragonstatue.png 20 28}

	# center chamber healing runes
	{PUT_IMG items/rune-lightblue-small.png 17 44}
	{PUT_IMG items/rune-lightblue-small.png 19 43}

	# kitchen trash + rocks
	{PUT_IMG misc/trash.png 12 46}
	{PUT_IMG misc/trash.png 10 49}
	{PUT_IMG misc/trash.png 9 47}
	{PUT_IMG misc/rocks.png 10 48}

	# barracks trash + rocks
	{PUT_IMG misc/trash.png 15 40}
	{PUT_IMG misc/trash.png 14 36}
	{PUT_IMG misc/trash.png 13 39}
	{PUT_IMG misc/rocks.png 15 38}
	{PUT_IMG misc/rocks.png 18 39}
	{PUT_IMG items/bones.png 15 36}
	{PUT_IMG items/bones.png 16 39}

	# training hall skeletons (remains of students + trainer)
	{PUT_IMG items/bones.png 9 40}
	{PUT_IMG items/bones.png 9 43}
	{PUT_IMG items/bones.png 11 41}
	{PUT_IMG items/bones.png 12 42}

	# crypt coffins + rocks
	{PUT_IMG items/coffin2.png 10 26}
	{PUT_IMG items/coffin2.png 10 28}
	{PUT_IMG items/coffin2.png 12 25}
	{PUT_IMG items/coffin2.png 12 27}
	{PUT_IMG misc/rocks.png 12 28}

	# cloaked figure chamber
	{PUT_IMG misc/rocks.png 8 21}

	# temple altar
	{PUT_IMG items/altar.png 6 33}
	{PUT_IMG items/bones.png 7 36}

	# rocks in human outpost/elves base cave
	{PUT_IMG misc/rocks.png 16 17}

	# chest of gold in human outpost at cave mouth
	{PUT_IMG items/chest-plain-open.png 17 21}

	# kill Elyssa to keep her from being recruited

	[kill]
		description=Elyssa
		animate=no
		fire_event=no
	[/kill]

	#increase the cost of all units by 1
	[if]

		[variable]
		name=scen3
		numerical_equals=2
		[/variable]

		[then]

		#go from 4 to 5

		[disallow_recruit]
			type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
			side=1
		[/disallow_recruit]

		[allow_recruit]
			type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
			side=1
		[/allow_recruit]

		[/then]

		[else]

		[if]
			[variable]
			name=scen3
			numerical_equals=1
			[/variable]

			[then]

			#go from 3 to 4

			[disallow_recruit]
				type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
				side=1
			[/disallow_recruit]

			[allow_recruit]
				type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
				side=1
			[/allow_recruit]

			[/then]
		[/if]

		[if]
			[variable]
			name=scen3
			numerical_equals=3
			[/variable]

			[then]

			#go from 5 to 6

			[disallow_recruit]
				type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
				side=1
			[/disallow_recruit]

			[allow_recruit]
				type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
				side=1
			[/allow_recruit]

			[/then]
		[/if]

		[/else]
	[/if]

	# recall heroes
	# this is a placeholder unit, used to make sure heroes recall
	# in encampment hexes
	{UNIT_ (Desert Hero) (Test) ( _ "Test") 1 51 41}

	[recall]
	description=Zhul
	[/recall]
	[recall]
	description=Nym
	[/recall]

	# recall dwarf/troll
	# name is Grog/Nog or Rogrimir/Jarl

	[recall]
	description=Rogrimir
	[/recall]
	[recall]
	description=Jarl
	[/recall]
	[recall]
	description=Grog
	[/recall]
	[recall]
	description=Nog
	[/recall]

	# kill placeholder unit
	[kill]
	x,y=51,41
	animate=no
	[/kill]

	[if]
		[have_unit]
		description=Grog
		[/have_unit]

		[then]

		[set_variable]
		name=ally_name
		value=Grog
		[/set_variable]

		[set_variable]
		name=ally_race
		value=Troll
		[/set_variable]

		[/then]
	[/if]

	[if]
		[have_unit]
		description=Nog
		[/have_unit]

		[then]

		[set_variable]
		name=ally_name
		value=Nog
		[/set_variable]

		[set_variable]
		name=ally_race
		value=Troll
		[/set_variable]

		[/then]
	[/if]

	[if]
		[have_unit]
		description=Rogrimir
		[/have_unit]

		[then]

		[set_variable]
		name=ally_name
		value=Rogrimir
		[/set_variable]

		[set_variable]
		name=ally_race
		value=Dwarf
		[/set_variable]

		[/then]
	[/if]

	[if]
		[have_unit]
		description=Jarl
		[/have_unit]

		[then]

		[set_variable]
		name=ally_name
		value=Jarl
		[/set_variable]

		[set_variable]
		name=ally_race
		value=Dwarf
		[/set_variable]

		[/then]
	[/if]

	# put hero icon on troll/dwarf ally

	{UNIT_OVERLAY description=$ally_name misc/hero-icon.png}

	# initialize starting variables

	[set_variable]
	name=ally_must_live
	value=1
	[/set_variable]

	[set_variable]
	name=type_of_sealife
	value=0
	[/set_variable]

	[set_variable]
	name=humans_killed
	value=0
	[/set_variable]
	
	# used to display alternate death message if the last of the 3 humans dies
	# from drowning instead of being killed by another unit
	[set_variable]
	name=human_drowned
	value=0
	[/set_variable]

	[set_variable]
	name=entered_gate
	value=0
	[/set_variable]

	#ifdef EASY
	[set_variable]
	name=healing_rune1
	value=1
	[/set_variable]

	[set_variable]
	name=healing_rune2
	value=2
	[/set_variable]
	#endif

	#ifdef MEDIUM
	[set_variable]
	name=healing_rune1
	value=1
	[/set_variable]

	[set_variable]
	name=healing_rune2
	value=1
	[/set_variable]
	#endif

	#ifdef HARD
	[set_variable]
	name=healing_rune1
	value=1
	[/set_variable]

	[set_variable]
	name=healing_rune2
	value=1
	[/set_variable]
	#endif

	[set_variable]
	name=entered_training_hall
	value=0
	[/set_variable]

	[set_variable]
	name=broke_circle
	value=0
	[/set_variable]

	[set_variable]
	name=entered_temple
	value=0
	[/set_variable]

	[set_variable]
	name=pulled_lever
	value=0
	[/set_variable]

	[set_variable]
	name=ally_conversation
	value=0
	[/set_variable]

	[set_variable]
	name=pissed_off_durstrag
	value=0
	[/set_variable]

	# clock variable, starts at 1
	[set_variable]
	name=time_of_day
	value=1
	[/set_variable]

	# flag to store if we should start the messenger timer or not
	[set_variable]
	name=start_messenger_timer
	value=0
	[/set_variable]

	# timer to store when to send off a human messenger
	[set_variable]
	name=messenger_timer
	value=0
	[/set_variable]

	# flag to make sure that undead emissary only comes out once
	[set_variable]
	name=undead_emissary
	value=0
	[/set_variable]

	[set_variable]
	name=stop_flooding
	value=0
	[/set_variable]

	[set_variable]
	name=human_conversation
	value=0
	[/set_variable]

	[set_variable]
	name=saw_valley_river
	value=0
	[/set_variable]

	#remove shroud surrounding starting position
	[remove_shroud]
	x=48-64
	y=41-49
	side=1
	[/remove_shroud]

	[remove_shroud]
	x=48-57
	y=38-42
	side=1
	[/remove_shroud]

	# add more dirt to secret passage at easier difficulties

	#ifdef HARD
	#else
	[terrain]
	x,y=20,51
	letter=r
	[/terrain]
	#endif

	#ifdef EASY
	[terrain]
	x,y=17,51
	letter=r
	[/terrain]
	#endif


# set starting scenario objectives

[if]
	[variable]
	name=ally_race
	equals=Dwarf
	[/variable]

	[then]

	[objectives]
	summary= _ "Starting Objectives:"
	[objective]
		description= _ "Escape the Caves"
		condition=win
	[/objective]
	[objective]
		description= _ "Death of Kaleh, Nym, Zhul, or Dwarf Ally"
		condition=lose
	[/objective]
	[/objectives]

	[/then]

	[else]

	[objectives]
	summary= _ "Starting Objectives:"
	[objective]
		description= _ "Escape the Caves"
		condition=win
	[/objective]
	[objective]
		description= _ "Death of Kaleh, Nym, Zhul, or Troll Ally"
		condition=lose
	[/objective]
	[/objectives]

	[/else]
[/if]

[/event]

# I NEED THE CLOCK FUNCTION TO GO FIRST BECAUSE LATER EVENTS CHECK TO SEE
# WHAT TIME IT IS

# Clock Function

# Step 0: increment messenger timer
# Step 1: if we are going into night or day, flip daytime boolean
# Step 2: advance clock

#first day
#dawn		1
#morning	2
#mid-day	3
#afternoon	4
#dusk		5
#shortdark	6

#second day
#dawn		-1
#morning	-2
#mid-day	-3
#afternoon	-4
#dusk		-5
#longdark 1	-6
#longdark 2	-7
#longdark 3	-8
#longdark 4	-9

[event]
name=new turn
first_time_only=no

# timer to store when to send off a human messenger
[if]
	[variable]
	name=start_messenger_timer
	numerical_equals=1
	[/variable]

	[then]

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

	[/then]
[/if]

[if]
	[variable]
		name=time_of_day
		numerical_equals=-9
	[/variable]

[then]
	[set_variable]
		name=time_of_day
		value=1
	[/set_variable]

[/then]

[else]

	[if]

		[variable]
			name=time_of_day
			numerical_equals=6
		[/variable]

	[then]
		[set_variable]
			name=time_of_day
			value=-1
		[/set_variable]

	[/then]

	[else]
		[if]
			[variable]
				name=time_of_day
				greater_than=0
			[/variable]

		[then]
			[set_variable]
				name=time_of_day
				add=1
			[/set_variable]

		[/then]

		[else]
			[set_variable]
				name=time_of_day
				add=-1
			[/set_variable]

		[/else]
		[/if]

	[/else]
	[/if]

[/else]
[/if]

[/event]



# Event 1: Starting dialogue & dwarves/troll appear

[event]
name=start

[message]
	description=$ally_name
	message= _ "We've come far and we're almost to the surface. But first we should stop and rest here for a while."
[/message]

[message]
	description=Kaleh
	message= _ "That's a big river; the water is really moving fast."
[/message]

[if]
	[variable]
	name=ally_race
	equals=Dwarf
	[/variable]

	[then]

	[message]
		description=$ally_name
		message= _ "Yes, this time of year the snow melts from the mountains, and rivers like this often go deep underground. Sometimes the rivers break through and flood caverns, a deadly accident that has occasionally befallen my kind."
	[/message]

	[/then]

	[else]

	[message]
		description=$ally_name
		message= _ "Deep and dark are the waters that flow in our caves. Sometimes raging waters flood tunnels without warning. A stream can sustain a village, a sudden flood can destroy it."
	[/message]

	[/else]
[/if]

[message]
	description=Nym
	message= _ "Well, the faster we get out of here, the happier I'll be."
[/message]

[scroll]
	x=20
[/scroll]
[scroll]
	x=-20
[/scroll]
[scroll]
	x=20
[/scroll]
[scroll]
	x=-20
[/scroll]

[message]
	description=Zhul
	message= _ "Wait, did you feel that?"
[/message]

[message]
	description=Nym
	message= _ "What?"
[/message]

[message]
	description=Zhul
	message= _ "It felt like a distant rumbling. And what's that roaring sound?"
[/message]

# create trolls/dwarves

#in easier difficulties, I wound troll/dwarf units


[if]
	[variable]
	name=ally_race
	equals=Dwarf
	[/variable]

	[then]

	[move_unit_fake]
	type=Troll Whelp
	x=52,52,53,53,53,53,52,51
	y=50,49,49,48,47,46,45,45
	[/move_unit_fake]

	[unit]
	type=Troll Whelp
	description=Troll Avenger
	user_description= _ "Troll Avenger"
	side=6
	x=51
	y=45
	#ifdef EASY
	hitpoints=28
	#endif
	#ifdef MEDIUM
	hitpoints=32
	#endif
	[/unit]

	[move_unit_fake]
	type=Troll Whelp
	x=52,52,53,53,53,53,52,52
	y=50,49,49,48,47,46,45,44
	[/move_unit_fake]

	[unit]
	type=Troll Whelp
	description=Troll Avenger
	user_description= _ "Troll Avenger"
	side=6
	x=52
	y=44
	#ifdef EASY
	hitpoints=28
	#endif
	#ifdef MEDIUM
	hitpoints=32
	#endif
	[/unit]

	[move_unit_fake]
	type=Troll Shaman
	x=52,52,53,53,53,53,52
	y=50,49,49,48,47,46,45
	[/move_unit_fake]

	[unit]
	type=Troll Shaman
	description=Troll Avenger
	user_description= _ "Troll Avenger"
	side=6
	x=52
	y=45
	#ifdef EASY
	hitpoints=34
	#endif
	#ifdef MEDIUM
	hitpoints=38
	#endif
	[/unit]

	[/then]

	[else]

	[move_unit_fake]
	type=Dwarvish Fighter
	x=52,52,53,53,53,53,52,51
	y=50,49,49,48,47,46,45,45
	[/move_unit_fake]

	[unit]
	type=Dwarvish Fighter
	description=Dwarf Avenger
	user_description= _ "Dwarf Avenger"
	side=6
	x=51
	y=45
	#ifdef EASY
	hitpoints=26
	#endif
	#ifdef MEDIUM
	hitpoints=30
	#endif
	[/unit]

	[move_unit_fake]
	type=Dwarvish Thunderer
	x=52,52,53,53,53,53,52,52
	y=50,49,49,48,47,46,45,44
	[/move_unit_fake]

	[unit]
	type=Dwarvish Thunderer
	description=Dwarvish Avenger
	user_description= _ "Dwarf Avenger"
	side=6
	x=52
	y=44
	#ifdef EASY
	hitpoints=26
	#endif
	#ifdef MEDIUM
	hitpoints=30
	#endif
	[/unit]

	[move_unit_fake]
	type=Dwarvish Pathfinder
	x=52,52,53,53,53,53,52
	y=50,49,49,48,47,46,45
	[/move_unit_fake]

	[unit]
	type=Dwarvish Pathfinder
	description=Dwarvish Avenger
	user_description= _ "Dwarf Avenger"
	side=6
	x=52
	y=45
	#ifdef EASY
	hitpoints=25
	#endif
	#ifdef MEDIUM
	hitpoints=32
	#endif
	[/unit]

	[/else]
[/if]



[if]
	[variable]
	name=ally_race
	equals=Dwarf
	[/variable]

	[then]

	[message]
		description=Troll Avenger
		message= _ "Foul elves, you not escaped us yet. The Great Leader shall be avenged! We have dammed the river and soon all shall drown in its dark waters. Come join us in death!"
	[/message]

	[/then]

	[else]

	[message]
		description=Dwarf Avenger
		message= _ "Foul elves, you have not escaped yet. Our chieftain shall be avenged! We have dammed the river and soon all shall drown in its dark waters. Come join us in death!"
	[/message]

	[/else]
[/if]

[message]
	description=Kaleh
	message= _ "That sound must be the rushing water. We have to get our people out of here, and fast!"
[/message]

[message]
	description=$ally_name
	message= _ "Quick, the southern passage!"
[/message]

[message]
	description=Zhul
	message= _ "We haven't a moment to lose!"
[/message]

[/event]

# Event 2: confused ants

#EASY: 3 fleeing ants, 1 normal ant
#MEDIUM: 3 fleeing ants, 2 normal ants
#HARD: 3 fleeing ants, 3 normal ants

[event]
name=moveto

[filter]
x=36-42
y=45-53
side=1
[/filter]

[terrain]
x=44
y=52
letter=c
[/terrain]

#create confused ants

[unit]
type=Giant Ant
x=42
y=49
side=4
goto_x=39
goto_y=49
[/unit]

[unit]
type=Giant Ant
x=40
y=52
side=4
goto_x=38
goto_y=50
[/unit]

[unit]
type=Giant Ant
x=43
y=51
side=4
goto_x=38
goto_y=49
[/unit]

[unit]
type=Giant Ant
x=39
y=50
side=4
[/unit]

#ifdef MEDIUM

[unit]
type=Giant Ant
x=38
y=52
side=4
[/unit]

#endif

#ifdef HARD

[unit]
type=Giant Ant
x=41
y=52
side=4
[/unit]

#endif

[remove_shroud]
side=1
x=37-44
y=46-53
[/remove_shroud]

[remove_shroud]
side=1
x=36-41
y=50-54
[/remove_shroud]

# check to see if Nym is the unit that triggered this event
# to keep her from talking to herself during the dialogue

[store_locations]
x,y=$x1,$y1
[filter]
	description=Nym
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=0
	[/variable]

	[then]
	# unit that triggered event is not Nym

	[message]
	speaker=unit
	message= _ "Hey look, more ants!"
	[/message]

	[message]
	description=Nym
	message= _ "Are you sure there aren't any spiders?"
	[/message]

	[message]
	speaker=unit
	message= _ "No, but the water is rising to the southeast as well. The river must have led to more tunnels than we first thought."
	[/message]

	[message]
	description=Zhul
	message= _ "The ants must be fleeing from the flood too."
	[/message]

	[message]
	speaker=unit
	message= _ "They seem confused, leaderless. I guess it's every ant for itself. Uh, oh. Some of them seem to have noticed us."
	[/message]

	[message]
	description=Kaleh
	message= _ "Well, we have to get out of here too. Looks like we don't have any choice but to fight our way through the chaos."
	[/message]

	[/then]

	[else]

	# Nym triggered event, change dialogue

	[message]
	speaker=unit
	message= _ "Hey look, more ants!"
	[/message]

	[message]
	speaker=unit
	message= _ "I don't see any spiders, but the water is rising to the southeast as well. The river must have lead to more tunnels than we first thought."
	[/message]

	[message]
	description=Zhul
	message= _ "The ants must be fleeing from the flood too."
	[/message]

	[message]
	speaker=unit
	message= _ "They seem confused, leaderless. I guess it's every ant for itself. Uh, oh. Some of them seem to have noticed us."
	[/message]

	[message]
	description=Kaleh
	message= _ "Well, we have to get out of here too. Looks like we don't have any choice but to fight our way through the chaos."
	[/message]

	[/else]

[/if]

{CLEAR_VARIABLE unittest}

[/event]


# Event 3: human explorers / cave delvers / spelunkers

[event]
name=moveto

[filter]
x=30-34
y=43-48
side=1
[/filter]

[terrain]
x=36,37
y=43,43
letter=c
[/terrain]

[remove_shroud]
side=1
x=29-35
y=41-49
[/remove_shroud]

[remove_shroud]
side=1
x=28-30
y=44-46
[/remove_shroud]

#ifdef EASY

[move_unit_fake]
type=Javelineer
x=36,35,34,33
y=42,43,43,44
[/move_unit_fake]

{FREE_UNIT (Javelineer) (Bernard) ( _ "Bernard") 2 33 44}

[redraw]
[/redraw]

[move_unit_fake]
type=Swordsman
x=36,35,34,34
y=42,43,43,44
[/move_unit_fake]

{FREE_UNIT (Swordsman) (Daryl) ( _ "Daryl") 2 34 44}

[redraw]
[/redraw]

[move_unit_fake]
type=Bowman
x=36,35,34
y=42,43,43
[/move_unit_fake]

{FREE_UNIT (Bowman) (Oswald) ( _ "Oswald") 2 34 43}

[redraw]
[/redraw]

#endif

#ifdef MEDIUM

[move_unit_fake]
type=Javelineer
x=36,35,34,33
y=42,43,43,44
[/move_unit_fake]

{FREE_UNIT (Javelineer) (Bernard) ( _ "Bernard") 2 33 44}

[redraw]
[/redraw]

[move_unit_fake]
type=Swordsman
x=36,35,34,34
y=42,43,43,44
[/move_unit_fake]

{FREE_UNIT (Swordsman) (Daryl) ( _ "Daryl") 2 34 44}

[redraw]
[/redraw]

[move_unit_fake]
type=Longbowman
x=36,35,34
y=42,43,43
[/move_unit_fake]

{FREE_UNIT (Longbowman) (Oswald) ( _ "Oswald") 2 34 43}

[redraw]
[/redraw]

#endif

#ifdef HARD

[move_unit_fake]
type=Javelineer
x=36,35,34,33
y=42,43,43,44
[/move_unit_fake]

{FREE_UNIT (Javelineer) (Bernard) ( _ "Bernard") 2 33 44}

[redraw]
[/redraw]

[move_unit_fake]
type=Swordsman
x=36,35,34,34
y=42,43,43,44
[/move_unit_fake]

{FREE_UNIT (Swordsman) (Daryl) ( _ "Daryl") 2 34 44}

[redraw]
[/redraw]

[move_unit_fake]
type=Master Bowman
x=36,35,34
y=42,43,43
[/move_unit_fake]

{FREE_UNIT (Master Bowman) (Oswald) ( _ "Oswald") 2 34 43}

[redraw]
[/redraw]

#endif

[message]
description=Daryl
message= _ "Huff, huff. First the boss tells us to patrol these caves, and then these durn caves start flooding. What next?"
[/message]

[message]
description=Bernard
message= _ "Shut up and keep running, or we'll be fishbait for sure!"
[/message]

[store_locations]
x,y=$x1,$y1
[filter]
	description=$ally_name
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=type_of_sealife
	value=1
	[/set_variable]

	[message]
	description=Oswald
	message= _ "Hey look! Those must be Elves!"
	[/message]

	[message]
	description=Daryl
	message= _ "Huh? Elves?"
	[/message]

	[message]
	description=Bernard
	message= _ "Yeah, just like my old grandmam used to tell us: pointy ears, pale hair, those shifty eyes, hearts as hard as a hermit crab's shell. It must be an invasion, they must have started the flood!"
	[/message]

	[/then]

	[else]

	[message]
	description=Oswald
	message= _ "Hey look! It's a $ally_race"
	[/message]

	[message]
	description=Daryl
	message= _ "Huh? A $ally_race?"
	[/message]

	[if]
		[variable]
		name=ally_race
		equals=Troll
		[/variable]

		[then]

		[set_variable]
		name=type_of_sealife
		value=2
		[/set_variable]

		[message]
		description=Bernard
		message= _ "Yeah, just like my old grandmam used to tell us: dark green skin, beady red eyes, hulking brutes with brains as small as a barnacle. They lurk deep in the earth and hate everything that lives above ground. This must be an invasion, the trolls must have started the flood!"
		[/message]

		[/then]

		[else]

		[set_variable]
		name=type_of_sealife
		value=3
		[/set_variable]

		[message]
		description=Bernard
		message= _ "Yeah, just like my old grandmam used to tell us: short and stocky, long beards, filthy bastards who are as sneaky as a cuttlefish.  They lurk underground and only come up to steal whatever valuables they can get their hands on. This must part of their plot, the dwarves must have started the flood!"
		[/message]

		[/else]
	[/if]

	[/else]

[/if]

{CLEAR_VARIABLE unittest}

[message]
description=Oswald
message= _ "Then let's kill them!"
[/message]

[message]
description=Daryl
message= _ "Yeah!"
[/message]

[message]
speaker=unit
message= _ "They're definitely of the 'attack first, ask questions later' variety."
[/message]

[/event]

# when all humans are dead, play victory conversation

[event]
name=die
first_time_only=no

[filter]
side=2
[/filter]

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

[if]

	[variable]
	name=humans_killed
	numerical_equals=3
	[/variable]

	[then]

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

	#kill human before displaying messages
	[kill]
	side=2
	animate=no
	[/kill]
	
	# Vary dialogue depending on what kind of sea life the humans originally
	# mentioned. Also if last human died from drowning instead of being killed
	# have Kaleh as the question, instead of the victorious unit.

	[if]
		[variable]
		name=type_of_sealife
		numerical_equals=1
		[/variable]

		[then]
		# case 1: humans saw an elf first and mentioned hermit crabs
		
		[if]
			[variable]
			name=human_drowned
			numerical_equals=1
			[/variable]
			
			[then]
			
			[message]
			speaker=Kaleh
			message= _ "Fish bait? Hermit Crabs? Who are these humans and what were they talking about?"
			[/message]

			[/then]
			
			[else]
			
			[message]
			speaker=second_unit
			message= _ "Fish bait? Hermit Crabs? Who are these humans and what were they talking about?"
			[/message]

			[/else]
		[/if]

		[/then]

		[else]

		[if]

			[variable]
			name=type_of_sealife
			numerical_equals=2
			[/variable]

			[then]
			# case 2: humans saw troll ally first and mentioned barnacles
			
			[if]
				[variable]
				name=human_drowned
				numerical_equals=1
				[/variable]
			
				[then]
				
				[message]
				speaker=Kaleh
				message= _ "Fish bait? Barnacles? Who are these humans and what were they talking about?"
				[/message]
				
				[/then]
				
				[else]
			
				[message]
				speaker=second_unit
				message= _ "Fish bait? Barnacles? Who are these humans and what were they talking about?"
				[/message]
			
				[/else]
			[/if]

			[/then]

			[else]
			# case 3: humans saw dwarf ally first and mentioned cuttlefish
			
			[if]
				[variable]
				name=human_drowned
				numerical_equals=1
				[/variable]
			
				[then]
				
				[message]
				speaker=Kaleh
				message= _ "Fish bait? Cuttlefish? Who are these humans and what were they talking about?"
				[/message]
				
				[/then]
				
				[else]
				
				[message]
				speaker=second_unit
				message= _ "Fish bait? Cuttlefish? Who are these humans and what were they talking about?"
				[/message]
				
				[/else]
			[/if]
			
			[/else]
		[/if]

		[/else]
	[/if]

	[message]
	description=Zhul
	message= _ "No time for questions now, the water shows no signs of stopping. We've got to get out of here while we still can!"
	[/message]

	[message]
	description=$ally_name
	message= _ "Curses, the water is rising too fast. That tunnel those humans were fleeing down was the fastest way out of here, but it's already flooding."
	[/message]

	[message]
	description=Kaleh
	message= _ "There must be another way out. There must!"
	[/message]

	[message]
	description=$ally_name
	message= _ "There might be, but I don't--"
	[/message]

	[message]
	description=Nym
	message= _ "Then show us the way already! We're running out of time. "
	[/message]

	[message]
	description=$ally_name
	message= _ "Fine. Just keep going west, but be careful."
	[/message]

	[/then]
[/if]

[/event]

# Event 4: Discovers Cultists Fort

[event]
name=moveto

[filter]
x=20-27
y=45-50
side=1
[/filter]

[remove_shroud]
x=20-27
y=45-50
side=1
[/remove_shroud]

[store_locations]
x,y=$x1,$y1
[filter]
	description=$ally_name
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "Woah, what is this place? It sure seems well protected."
	[/message]

	[message]
	description=$ally_name
	message= _ "This is an ancient fortress. Who lived here I do not know, but it has been long since abandoned."
	[/message]

	[/then]

	[else]

	[message]
description=$ally_name
message= _ "Behold, we come now to an ancient fortress. Who lived here I do not know, but it has been long since abandoned."
	[/message]

	[/else]
[/if]

{CLEAR_VARIABLE unittest}

[message]
description=Nym
message= _ "You've been this way before?"
[/message]

[message]
description=$ally_name
message= _ "Yes, but I didn't explore very far. This foul place is still protected by wards and guards. It reeks of dark magic."
[/message]

[message]
description=Kaleh
message= _ "I wish there was another path, but it seems we have no choice."
[/message]

[message]
description=$ally_name
message= _ "Wait. The chamber in front of us is probably trapped and well guarded. There is another way. When I explored here before, I found a secret passage that bypassed the main gate. Search along the southern wall of this cave and you should find it. The only problem is that the passage is long and windy, and it will cost us precious minutes. With the water rising that may be time we don't have to spend. I leave the final decision up to you, Kaleh."
[/message]

[/event]


# Event 4a: discover entrance to secret tunnel

[event]
name=moveto

[filter]
x=24
y=49
side=1
[/filter]

[store_locations]
	x,y=$x1,$y1
	[filter]
	description=$ally_name
	[/filter]
	variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "I think I see a door-shaped crack in this wall."
	[/message]

	[message]
	description=$ally_name
	message= _ "Good, that should be the entrance to the secret tunnel. Now just push hard inwards."
	[/message]

	[message]
	speaker=unit
	message= _ "Got it!"
	[/message]

	[/then]

	[else]

	[message]
	speaker=unit
	message= _ "Hmmm, the entrance to the secret tunnel should be right around here somewhere."
	[/message]

	[message]
	speaker=unit
	message= _ "Got it!"
	[/message]

	[/else]
[/if]

{CLEAR_VARIABLE unittest}

[terrain]
x,y=24,50
letter=u
[/terrain]

[/event]


# Event 4b: discover exit from secret tunnel

[event]
name=moveto

[filter]
x=13
y=50
side=1
[/filter]

[store_locations]
	x,y=$x1,$y1
	[filter]
	description=$ally_name
	[/filter]
	variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "The passage just halts at a dead end."
	[/message]

	[message]
	description=$ally_name
	message= _ "You didn't expect the other end to be left wide open did you? There should be another secret door hidden right in front of you."
	[/message]

	[message]
	speaker=unit
	message= _ "Oh, right. Hold on, I think I've found it."
	[/message]

	[/then]

	[else]

	[message]
	speaker=unit
	message= _ "Okay, this is the end of the tunnel. Which means the other secret door should be right here."
	[/message]

	[message]
	speaker=unit
	message= _ "Hold on, I think I've found it."
	[/message]

	[/else]
[/if]

{CLEAR_VARIABLE unittest}

[terrain]
x,y=13,49
letter=u
[/terrain]

[terrain]
x=8,8
y=48,49
letter=c
[/terrain]

[/event]

# Event 5: Enter warded cave

# remove runes at 20,45 and 23,48
# do 25% 30% 35% damage to unit
# awaken guardian undead:

# EASY: 1 ghouls, 1 soulless, 2 skeletons
# MEDIUM: 1 ghouls, 1 necrophage, 2 skeletons
# HARD: 2 necrophages, 2 skeletons

[event]
name=moveto

[filter]
x=19-24,21
y=45-47,48
side=1
[/filter]

[if]
	[variable]
	name=entered_gate
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=entered_gate
	value=1
	[/set_variable]

	[colour_adjust]
	red,green,blue=255,0,0
	[/colour_adjust]

	[redraw]
	[/redraw]

	[delay]
	time=100
	[/delay]

	[colour_adjust]
	red,green,blue=0,0,0
	[/colour_adjust]

	[redraw]
	[/redraw]

	[removeitem]
	x,y=20,45
	[/removeitem]

	[removeitem]
	x,y=23,48
	[/removeitem]

	[object]
		[filter]
			x=$x1
			y=$y1
		[/filter]

		id=RuneDamage
		silent=yes

		[effect]
			apply_to=hitpoints
			#ifdef EASY
			increase=-25%
			#endif
		[/effect]

		[effect]
			apply_to=hitpoints
			#ifdef MEDIUM
			increase=-30%
			#endif
		[/effect]


		[effect]
			apply_to=hitpoints
			#ifdef HARD
			increase=-35%
			#endif
		[/effect]

	[/object]

	# EASY: 1 ghoul, 1 soulless, 2 skeletons
	# MEDIUM: 1 ghoul, 1 necrophage, 2 skeletons
	# HARD: 2 necrophages, 2 skeletons

	#ifdef EASY
	{FREE_UNIT (Soulless) (Gate Guard) ( _ "Gate Guard") 3 21 48}
	{FREE_UNIT (Ghoul) (Gate Guard) ( _ "Gate Guard") 3 24 46}
	#endif

	#ifdef MEDIUM
	{FREE_UNIT (Ghoul) (Gate Guard) ( _ "Gate Guard") 3 21 48}
	{FREE_UNIT (Necrophage) (Gate Guard) ( _ "Gate Guard") 3 24 46}
	#endif

	#ifdef HARD
	{FREE_UNIT (Necrophage) (Gate Guard) ( _ "Gate Guard") 3 21 48}
	{FREE_UNIT (Necrophage) (Gate Guard) ( _ "Gate Guard") 3 24 46}
	#endif

	{FREE_UNIT (Skeleton) (Gate Guard) ( _ "Gate Guard") 3 22 45}
	{FREE_UNIT (Skeleton) (Gate Guard) ( _ "Gate Guard") 3 20 46}


	[/then]
[/if]

[/event]


# Event 6: Enter central cave

[event]
name=moveto

[filter]
x=16-21
y=41-45
side=1
[/filter]

[remove_shroud]
x=15-22
y=41-44
side=1
[/remove_shroud]

[remove_shroud]
x=15-20
y=41-45
side=1
[/remove_shroud]

[store_locations]
x,y=$x1,$y1
[filter]
	description=$ally_name
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=0
	[/variable]

	[then]


	[message]
	speaker=unit
	message= _ "This cave seems pretty empty, except for those two glowing runes in the center. This fort must have once been heavily occupied because countless feet have left well worn paths leading in several directions. $ally_name which way should we go?"
	[/message]

	[message]
	speaker=$ally_name
	message= _ "I don't know. When I last came this way I got scared by all the runes and things moving in the shadows, and I explored no further."
	[/message]

	[/then]

	[else]

	[message]
	speaker=unit
	message= _ "The many tracks left by countless feet clearly show that this fort must have once been heavily occupied, but now this area is empty, except for those two glowing runes in the center. When I last came this way I got scared by the runes and other things moving in the shadows and explored no further. I'm afraid I cannot advise you which way to go from here."
	[/message]

	[/else]
[/if]

{CLEAR_VARIABLE unittest}

[message]
description=Nym
message= _ "Well, we can't spend all day thinking about it. Pick a direction, Kaleh."
[/message]

[message]
description=Zhul
message= _ "Wait, those runes are giving off a cool blue light and for some reason they don't seem as threatening as the burning red ones we saw before. Perhaps some of the magic left behind here could help us, if someone was brave enough to step into them."
[/message]

[/event]


# Event 6a: Step on healing runes (17,44) (19,43)

# EASY: rune1 heals 1 time, rune2 heals 2 times
# MEDIUM: rune1 heals 1 times, rune2 heals 1 time
# HARD: rune1 heals 1 time, rune2 heals 1 time

# when a unit steps on the runes, it is healed

[event]
name=moveto
first_time_only=no

[filter]
x=17
y=44
side=1
[/filter]

[if]
	[variable]
	name=healing_rune1
	greater_than=0
	[/variable]

	[then]

	[colour_adjust]
	red,green,blue=31,122,255
	[/colour_adjust]

	[redraw]
	[/redraw]

	[delay]
	time=100
	[/delay]

	[colour_adjust]
	red,green,blue=0,0,0
	[/colour_adjust]

	[redraw]
	[/redraw]

	[object]
		[filter]
			x,y=17,44
		[/filter]

		silent=yes
		duration="level"

		[effect]
		apply_to="hitpoints"
		heal_full="yes"
		[/effect]
	[/object]

	[message]
	speaker=unit
	message= _ "I feel refreshed and rejuvenated!"
	[/message]

	[set_variable]
	name=healing_rune1
	add=-1
	[/set_variable]

	[if]
		[variable]
		name=healing_rune1
		numerical_equals=0
		[/variable]

		[then]

		[removeitem]
		x,y=17,44
		[/removeitem]

		[message]
		speaker=unit
		message= _ "The rune is gone. I guess the magic only had limited uses."
		[/message]

		[set_variable]
		name=healing_rune1
		add=-1
		[/set_variable]

		[/then]

	[/if]

	[/then]

[/if]

[/event]

[event]
name=moveto
first_time_only=no

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

[if]
	[variable]
	name=healing_rune2
	greater_than=0
	[/variable]

	[then]

	[colour_adjust]
	red,green,blue=31,122,255
	[/colour_adjust]

	[redraw]
	[/redraw]

	[delay]
	time=100
	[/delay]

	[colour_adjust]
	red,green,blue=0,0,0
	[/colour_adjust]

	[redraw]
	[/redraw]

	[object]
		[filter]
			x,y=19,43
		[/filter]

		silent=yes
		description=_"The user feels much better."
		duration="level"

		[effect]
		apply_to="hitpoints"
		heal_full="yes"
		[/effect]
	[/object]

	[message]
	speaker=unit
	message= _ "I feel refreshed and rejuvenated!"
	[/message]

	[set_variable]
	name=healing_rune2
	add=-1
	[/set_variable]

	[if]
		[variable]
		name=healing_rune2
		numerical_equals=0
		[/variable]

		[then]

		[removeitem]
		x,y=19,43
		[/removeitem]

		[message]
		speaker=unit
		message= _ "The rune is gone. I guess the magic only had limited uses"
		[/message]

		[set_variable]
		name=healing_rune2
		add=-1
		[/set_variable]

		[/then]

	[/if]

	[/then]

[/if]

[/event]


# Event 7: Enter dining cavern

# water pours in from the west
# 2/3/4 water snakes come out of the water and attack

[event]
name=moveto

[filter]
x=7-14
y=46-49
side=1
[/filter]

[terrain]
x=8,8
y=48,49
letter=c
[/terrain]

[remove_shroud]
x=5-15
y=46-49
side=1
[/remove_shroud]

[remove_shroud]
x=5-11
y=46-51
side=1
[/remove_shroud]

[message]
speaker=unit
message= _ "There isn't much left of the furnishings of this room. I think it was some sort of storeroom, but it looks like scavengers have taken anything useful."
[/message]

[message]
speaker=unit
message= _ "Curse Uria! The water is rising over here as well. Already the western end of this chamber is flooded. And I think I see shapes rising out of the water. Whatever they are, it can't be good."
[/message]

# I replaced the water snake units with soulless units
# I deleted the water snake units becuase they lacked proper animation

{FREE_UNIT (Soulless) (Bloated Corpse) ( _ "Bloated Corpse") 3 7 48}
{FREE_UNIT (Soulless) (Bloated Corpse) ( _ "Bloated Corpse") 3 8 49}

[/event]

# Event 8: Training Hall

# one turn after you enter the hall, ghostly warriors arise and attack
# should be harder because it's the fast path

[event]
name=moveto

[filter]
x=8-13
y=40-44
side=1
[/filter]

[remove_shroud]
x=7-12
y=39-45
side=1
[/remove_shroud]

[remove_shroud]
x=7-14
y=40-45
side=1
[/remove_shroud]

#activate flooding of dining cavern

[terrain]
x=8,8
y=48,49
letter=c
[/terrain]

[message]
speaker=unit
message= _ "This looks like a training hall. There are still a few old swords and spears lying in the corners. But otherwise it seems quite abandoned."
[/message]

[set_variable]
name=entered_training_hall
value=1
[/set_variable]

[/event]

#at next turn create haunt trainer and ghost novices

[event]
name=new turn
first_time_only=no

[if]

	[variable]
	name=entered_training_hall
	numerical_equals=1
	[/variable]

	[then]

	[set_variable]
	name=entered_training_hall
	value=2
	[/set_variable]

	#create wraith and ghosts

	{FREE_UNIT (Haunt) (Blessed Kali) ( _ "Blessed Kali") 3 9 40}

	{FREE_UNIT (Ghost) (Novice Pior) ( _ "Novice Pior") 3 9 43}
	{FREE_UNIT (Ghost) (Novice Iona) ( _ "Novice Iona") 3 11 41}
	{FREE_UNIT (Ghost) (Novice Dani) ( _ "Novice Dani") 3 12 42}


	[message]
	description=Blessed Kali
	message= _ "All right you runts, let's try this again. Pior, remember to swing your sword with your whole body, not just your arms."
	[/message]

	[message]
	description=Novice Pior
	message= _ "Yes Sir."
	[/message]

	[message]
	description=Blessed Kali
	message= _ "Jarl, keep your feet moving. If you stand still you're a dead man."
	[/message]

	[message]
	description=Novice Dani
	message= _ "Right, Sir."
	[/message]

	[message]
	description=Blessed Kali
	message= _ "Iona, try to vary your attacks more, you're becoming too predictable."
	[/message]

	[message]
	description=Novice Iona
	message= _ "I'll try, Sir."
	[/message]

	[message]
	description=Blessed Kali
	message= _ "And remember, everyone, we're going to keep practicing until I'm satisfied. So, ready...attack!"
	[/message]

	[message]
	x,y=8-14,40-45
	side=1
	message= _ "Wait a minute, I don't see any targets or practice dummies. Who are they supposed to be attacking?"
	[/message]

	[message]
	description=Kaleh
	message= _ "I believe that would be us. But perhaps we can give them a few lessons in proper fighting style."
	[/message]

	[/then]
[/if]

[/event]

# while trainer is alive, replace any defeated ghosts

[event]
name=new turn
first_time_only=no

[if]
	[have_unit]
	description=Blessed Kali
	[/have_unit]

	[then]

	[set_variable]
	name=iona_dead
	value=1
	[/set_variable]

	[set_variable]
	name=jarl_dead
	value=1
	[/set_variable]

	[set_variable]
	name=pior_dead
	value=1
	[/set_variable]

	[if]
		[have_unit]
		description=Novice Iona
		[/have_unit]

		[then]

		[set_variable]
		name=iona_dead
		value=0
		[/set_variable]

		[/then]
	[/if]

	[if]
		[have_unit]
		description=Novice Dani
		[/have_unit]

		[then]

		[set_variable]
		name=jarl_dead
		value=0
		[/set_variable]

		[/then]
	[/if]

	[if]
		[have_unit]
		description=Novice Pior
		[/have_unit]

		[then]

		[set_variable]
		name=pior_dead
		value=0
		[/set_variable]

		[/then]
	[/if]


	[if]
		[variable]
		name=iona_dead
		numerical_equals=1
		[/variable]

		[or]
		[variable]
		name=jarl_dead
		numerical_equals=1
		[/variable]
		[/or]

		[or]
		[variable]
		name=pior_dead
		numerical_equals=1
		[/variable]
		[/or]

		[then]

		[message]
		description=Blessed Kali
		message= _ "Come on! I ain't going anywhere for the rest of the day, and unless you can fight better than that, neither are you.  Now get your sorry behinds up off the ground and do it all over again. You numbskulls aren't getting the easy treatment on my watch, no sir!"
		[/message]

		[/then]
	[/if]

	[if]
		[variable]
		name=jarl_dead
		numerical_equals=1
		[/variable]

		[then]

		{FREE_UNIT (Ghost) (Novice Dani) ( _ "Novice Dani") 3 12 42}

		[/then]
	[/if]

	[if]
		[variable]
		name=iona_dead
		numerical_equals=1
		[/variable]

		[then]

		{FREE_UNIT (Ghost) (Novice Iona) ( _ "Novice Iona") 3 11 41}

		[/then]
	[/if]

	[if]
		[variable]
		name=pior_dead
		numerical_equals=1
		[/variable]

		[then]

		{FREE_UNIT (Ghost) (Novice Pior) ( _ "Novice Pior") 3 9 43}

		[/then]
	[/if]

	[/then]

[/if]

[/event]


#when blessed kali dies, the rest of his ghost students leave too

[event]
name=die

[filter]
description=Blessed Kali
[/filter]

[kill]
description=Blessed Kali
animate=no
fire_event=no
[/kill]

	[set_variable]
	name=iona_dead
	value=1
	[/set_variable]

	[set_variable]
	name=jarl_dead
	value=1
	[/set_variable]

	[set_variable]
	name=pior_dead
	value=1
	[/set_variable]

	[if]
		[have_unit]
		description=Novice Iona
		[/have_unit]

		[then]

		[set_variable]
		name=iona_dead
		value=0
		[/set_variable]

		[/then]
	[/if]


	[if]
		[have_unit]
		description=Novice Dani
		[/have_unit]

		[then]

		[set_variable]
		name=jarl_dead
		value=0
		[/set_variable]

		[/then]
	[/if]


	[if]
		[have_unit]
		description=Novice Pior
		[/have_unit]

		[then]

		[set_variable]
		name=pior_dead
		value=0
		[/set_variable]

		[/then]
	[/if]



	[if]
		[variable]
		name=jarl_dead
		numerical_equals=1
		[/variable]

		[then]

		{FREE_UNIT (Ghost) (Novice Dani) ( _ "Novice Dani") 3 13 43}

		[/then]
	[/if]


	[if]
		[variable]
		name=iona_dead
		numerical_equals=1
		[/variable]

		[then]

		{FREE_UNIT (Ghost) (Novice Iona) ( _ "Novice Iona") 3 11 41}

		[/then]
	[/if]

	[if]
		[variable]
		name=pior_dead
		numerical_equals=1
		[/variable]

		[then]

		{FREE_UNIT (Ghost) (Novice Pior) ( _ "Novice Pior") 3 9 43}

		[/then]
	[/if]

[message]
description=Novice Pior
message= _ "Finally, we get to take a break. I am so sick of fighting practice."
[/message]

[message]
description=Novice Dani
message= _ "Kali's just a hardass because he's bitter that he never became a high priest."
[/message]

[message]
description=Novice Iona
message= _ "Hey, c'mon, maybe we can grab some food from the kitchen before we have to go to prayers."
[/message]

[message]
description=Novice Pior
message= _ "Good idea! I hope they let us go outside tomorrow; I so miss the sun."
[/message]

[kill]
description=Novice Iona
animate=no
fire_event=no
[/kill]

[kill]
description=Novice Dani
animate=no
fire_event=no
[/kill]

[kill]
description=Novice Pior
animate=no
fire_event=no
[/kill]

[message]
description=Nym
message= _ "Still lambasting those novices after all these years, that guy definitely had too much of a work ethic."
[/message]

[message]
description=Zhul
message= _ "Sniff, who were those children? Why did they die, in the dark, so many years ago? May Eloh shine her eternal light upon their souls."
[/message]

[message]
description=Kaleh
message= _ "The past is the past, and there's nothing we can do about it. Right now we have our own people to worry about."
[/message]

[/event]


# Event 9: Enter sleeping area

# several skeletons arise and attack
# EASY: 2 skeletons, 1 skeleton archer
# MEDIUM: 2 skeletons, 2 skeleton archers
# HARD: 1 deathblade, 1 skeleton, 1 bone shooter, 1 skeleton archer

[event]
name=moveto

[filter]
x=13-19
y=36-40
side=1
[/filter]

[remove_shroud]
x=11-20
y=35-39
side=1
[/remove_shroud]

[remove_shroud]
x=14-17
y=38-41
side=1
[/remove_shroud]

#activate flooding of dining cavern

[terrain]
x=8,8
y=48,49
letter=c
[/terrain]

[message]
speaker=unit
message= _ "This must have been the barracks. Remains of cots and beds litter the floor. Whatever happened here, it must have been sudden. Several skeletons still lie in their beds, sleeping for eternity."
[/message]

{FREE_UNIT (Skeleton) (Restless Dead) ( _ "Restless Dead") 3 15 40}
{FREE_UNIT (Skeleton Archer) (Restless Dead) ( _ "Restless Dead") 3 14 36}

#ifdef HARD
{FREE_UNIT (Deathblade) (Restless Dead) ( _ "Restless Dead") 3 13 39}
#else
{FREE_UNIT (Skeleton) (Restless Dead) ( _ "Restless Dead") 3 13 39}
#endif

#ifdef HARD
{FREE_UNIT (Bone Shooter) (Restless Dead) ( _ "Restless Dead") 3 17 37}
#endif

#ifdef MEDIUM
{FREE_UNIT (Skeleton Archer) (Restless Dead) ( _ "Restless Dead") 3 17 37}
#endif

[message]
description=Restless Dead
message= _ "Revenge!"
[/message]

[message]
speaker=Nym
message= _ "Well, so much for sleeping for eternity."
[/message]

[/event]

# event for secret door to wizard's lair

[event]
name=moveto

[filter]
x=17
y=36
side=1
[/filter]

[message]
speaker=unit
message= _ "Hey, what's this? There seems to be an outline of a door in this wall. Maybe if I give it a push..."
[/message]

[terrain]
x,y=18,35
letter=u
[/terrain]

[message]
speaker=unit
message= _ "What do you know? A secret door!"
[/message]

[message]
description=Kaleh
message= _ "Well, what's behind the door?"
[/message]

[message]
speaker=unit
message= _ "Uh oh. The path is blocked by another of those red glowing runes. I'm not sure crossing it would be a good idea."
[/message]

[/event]

# Event 10: Enter Wizard's Lair

# strange monsters are trapped on the runes

# Kromph offers to help you (10-3 impact beserk chaotic)

[event]
name=moveto

[filter]
x=16-20
y=27-34
side=1
[/filter]

[remove_shroud]
x=15-21
y=27-34
side=1
[/remove_shroud]

# upon entering chamber, remove entry rune and damage and poison invading
# unit

[colour_adjust]
	red,green,blue=255,0,0
[/colour_adjust]

[redraw]
[/redraw]

[delay]
	time=100
[/delay]

[colour_adjust]
	red,green,blue=0,0,0
[/colour_adjust]

[redraw]
[/redraw]

[removeitem]
x,y=18,34
[/removeitem]

[object]
	[filter]
		x=$x1
		y=$y1
	[/filter]

	id=WizardDamage
	silent=yes

	#ifdef EASY
	[effect]
		apply_to=hitpoints
		increase=-20%
	[/effect]
	#endif

	#ifdef MEDIUM
	[effect]
		apply_to=hitpoints
		increase=-25%
	[/effect]
	#endif

	#ifdef HARD
	[effect]
		apply_to=hitpoints
		increase=-30%
	[/effect]
	#endif

[/object]


[store_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
variable=unitstats
[/store_unit]

[set_variable]
	name=unitstats.status.poisoned
	value="on"
[/set_variable]

[unstore_unit]
	variable=unitstats
[/unstore_unit]

{CLEAR_VARIABLE unitstats}

{FREE_UNIT (Crab Man) (Failed Experiment) ( _ "Failed Experiment") 3 17 32}
{FREE_UNIT (Young Ogre) (Failed Experiment) ( _ "Failed Experiment") 3 19 32}

[message]
speaker=unit
message= _ "This chamber seems to have been some sort of laboratory. The floor is littered with broken bottles and other strange equipment. What is more striking are the glowing runes and the creatures that just appeared on them. Some sort of clawed creature and a tortured young ogre. And behind them is some huge beast floating in the middle of a magic circle. The beast seems asleep, but the front two are very much awake. And boy do they seem angry. "
[/message]

[message]
x,y=17,32
message= _ "Grawww!"
[/message]

[message]
x,y=19,32
message= _ "Make pain end!"
[/message]

[/event]

#disrupt magical circle

[event]
name=moveto
first_time_only=no

[filter]
x=17-19
y=28-30
side=1
[/filter]

[if]
	[variable]
	name=broke_circle
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit

	message= _ "In the center of this circle is a huge creature, with surging muscles and bloodshot eyes. I would think it was just a very big man, except for the fine stitches that cover its entire body. In fact it seems to be composed of many body parts all sewn together. It seems to be floating asleep in the center of the glowing magical circle. I could scratch out part of the circle and break it, but I have no idea what the consequences would be. I'm not sure I want something with that kind of strength attacking me."
	[option]

		message= _ "Break the circle"
		[command]
			[set_variable]
			name=broke_circle
			value=1
			[/set_variable]

			[removeitem]
			x,y=$x1,$y1
			[/removeitem]
		[/command]

		[command]
			# Kill old unit which couldn't move and
			# Just replace with new version of unit
			# since new golem is on player's side, it is
			# no longer allied with undead

			[removeitem]
			x,y=18,29
			[/removeitem]

			{FREE_UNIT (Flesh Golem) (Kromph) ( _ "Kromph") 1 18 29}
		[/command]

		[command]
			[message]
			description=Kromph
			message= _ "Master, what is your command?"
			[/message]

			[message]
			speaker=unit
			message= _ "What?!?"
			[/message]

			[message]
			description=Kromph
			message= _ "Kromph need command. Command me!"
			[/message]

			[message]
			description=Nym
			message= _ "Follow us. Attack our enemies."
			[/message]

			[message]
			description=Kromph
			message= _ "Yes, mistress. Kromph follow you. Kill enemies."
			[/message]

			[message]
			description=Zhul
			message= _ "Quick thinking, Nym. It seems to be some sort of magical creation. Lucky that it thought we were its master."
			[/message]

			[message]
			description=Kaleh
			message= _ "Looks like you have your own rather large pet, Nym. "
			[/message]

			[message]
			description=Nym
			message= _ "It wouldn't have been my first choice. But it could prove useful. I wonder what it likes to eat?"
			[/message]
		[/command]

	[/option]

	[option]
	message= _ "Leave that thing alone."

	[/option]

	[/message]

	[/then]
[/if]

[/event]


# Event 11: Enter Unholy Sanctuary

[event]
name=moveto

[filter]
x=5-10
y=32-37
side=1
[/filter]

[remove_shroud]
x=3-11
y=31-37
side=1
[/remove_shroud]

[message]
speaker=unit
message= _ "All the paths lead to this chamber. Is this just a dead end? It seems to be some sort of temple, but it has obviously been abandoned for a long time. All that is left is that stone altar. What god they were worshipping I have no idea, but the dried blood and cracked bones on the altar do not bode well."
[/message]

[message]
description=$ally_name
message= _ "I don't like the smell of this place."
[/message]

[message]
description=Zhul
message= _ "I feel some sort of presence...ugh...it makes my skin crawl."
[/message]

[message]
description=Nym
message= _ "I though you said $ally_name, that you'd been here before? Where are we supposed to go from here?"
[/message]

[message]
description=$ally_name
message= _ "I never explored this deep into the complex. But every lair has to have a back door somewhere."
[/message]

[message]
description=Kaleh
message= _ "Well I refuse to give up. There must be some way out. Search everywhere, people."
[/message]

[set_variable]
name=entered_temple
value=1
[/set_variable]

[/event]

[event]
name=new turn
first_time_only=no

[if]
	[variable]
	name=entered_temple
	numerical_equals=1
	[/variable]

	[then]

	[set_variable]
	name=entered_temple
	value=2
	[/set_variable]

	[colour_adjust]
	red,green,blue=255,0,0
	[/colour_adjust]

	[redraw]
	[/redraw]

	[delay]
	time=100
	[/delay]

	[colour_adjust]
	red,green,blue=0,0,0
	[/colour_adjust]

	[redraw]
	[/redraw]

	{FREE_UNIT (Ixthala Demon) (Ancient Guardian) ( _ "Ancient Guardian") 9 5 35}
	{FREE_UNIT (Ixthala Demon) (Ancient Guardian) ( _ "Ancient Guardian") 9 8 33}

	[message]
	x,y=5,35
	message= _ "Zantoff tharqan yur glit zarf!"
	[/message]

	[message]
	x,y=8,33
	message= _ "Uqtor dunil olgluck vara nir!"
	[/message]

	[message]
	description=Zhul
	message= _ "It seems that the temple had some power left in it after all."
	[/message]

	[message]
	description=Nym
	message= _ "I have no idea what they just said, but their meaning is quite clear."
	[/message]

	[message]
	description=Kaleh
	message= _ "Actions speak louder than words, and I intend to send them back to whatever stygian pits they came from!"
	[/message]

	[/then]
[/if]

[/event]

# Altar contains hidden lever which open secret exit

[event]
name=moveto
first_time_only=no

[filter]
x=5-7
y=32-34
side=1
[/filter]

[if]
	[variable]
	name=pulled_lever
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit

	message= _ "What's this? Hidden underneath the edge of the altar is an iron lever. It looks slightly rusted, but with some effort I could pull it. I have no idea what it will do, but we're running out of options."
	[option]
		message= _ "Pull the lever."
		[command]
			[set_variable]
			name=pulled_lever
			value=1
			[/set_variable]

			[scroll]
			x=20
			[/scroll]
			[scroll]
			x=-20
			[/scroll]
			[scroll]
			x=20
			[/scroll]
			[scroll]
			x=-20
			[/scroll]

			[terrain]
			x=9,9
			y=31,32
			letter=u
			[/terrain]

			[terrain]
			x=1
			y=33
			letter=s
			[/terrain]

			[terrain]
			x=2,2,3
			y=33,34,35
			letter=c
			[/terrain]

			[remove_shroud]
			x=2-5
			y=33-36
			side=1
			[/remove_shroud]

			[redraw]
			[/redraw]

			[message]
			speaker=unit
			message= _ "What?!? Two secret passages? What do you think this once was, a trap? Or possibly a back door?"
			[/message]

			[message]
			speaker=Zhul
			message= _ "I can't even begin to fathom what these cultists were up to. But more importantly, which way do we go?"
			[/message]

			[message]
			speaker=unit
			message= _ "Look, the western passage is already flooding! It must connect back somehow to the other tunnels. "
			[/message]

			[message]
			speaker=Nym
			message= _ "There's no time to ponder the history of this place. We've got to get out of here!"
			[/message]

			[message]
			speaker=Kaleh
			message= _ "Right, the eastern passage it is. I have no idea where it goes, but with the water rising, soon anywhere will be better than here."
			[/message]
		[/command]

	[/option]

	[option]
	message= _ "Leave it alone."
	[/option]

	[/message]

	[/then]
[/if]

[/event]

# Event 12: Enter Secret Crypt

[event]
name=moveto

[filter]
x=8-14
y=24-30
side=1
[/filter]

[remove_shroud]
x=8-14
y=24-31
side=1
[/remove_shroud]

[message]
speaker=unit
message= _ "This looks like some kind of burial chamber."
[/message]

[message]
description=Zhul
message= _ "Crypts like these are often heavily guarded, we would do well not to disturb the sarcophagi."
[/message]

#create crypt guardian unit

{FREE_UNIT (Spider Lich) (Crypt Guardian) ( _ "Crypt Guardian") 3 12 25}

[message]
description=Crypt Guardian
message= _ "I have long waited for fools such as yourselves to dare to disturb our rest, elf. Pay the price of all such defilers!"
[/message]

[message]
description=Nym
message= _ "Got any other timely advice, Zhul?"
[/message]

[message]
description=$ally_name
message= _ "We're in luck, a fissure has opened up a crack in the northern wall. We may be able to escape that way."
[/message]

[/event]

# Event 13: Encounter Cloaked Figure for a third time
# Figure appears at 10,19

[event]
name=moveto

[filter]
x=8-12
y=19-23
side=1
[/filter]

[remove_shroud]
x=7-13
y=19-24
side=1
[/remove_shroud]

[unit]
	type=Dark Assassin3
	description=Cloaked Figure
	user_description= _ "Cloaked Figure"
	side=7
	x=10
	y=19
	[modifications]
		{TRAIT_INTELLIGENT}
		{TRAIT_RESILIENT}
	[/modifications]
[/unit]

[message]
description=Cloaked Figure
image=portraits/cloaked.png
message= _ "You run, but you shall not escape death!"
[/message]

[message]
description=Kaleh
message= _ "In Eloh's name, not you again. Must I fight you a third time?"
[/message]

[message]
description=Cloaked Figure
image=portraits/cloaked.png
message= _ "You abandoned them, Kaleh, to eternal suffering and torment. And now you shall pay the price! You too shall watch the black waters consume those you love. Embrace the darkness, Kaleh, it is coming for you too."
[/message]

[message]
description=Kaleh
message= _ "Even you shall not stop me. You shall taste the might of the Quenoth elves!"
[/message]

[message]
description=Cloaked Figure
image=portraits/cloaked.png
message= _ "Ha! Foolish boy, you know nothing."
[/message]

[/event]


# Event 14: Defeat of Cloaked Figure (kaleh carries him himself)

[event]
name=die

[filter]
	description=Cloaked Figure
[/filter]

[message]
description=Kaleh
message= _ "Quick, grab him! Don't let him escape again."
[/message]

[message]
description=Cloaked Figure
image=portraits/cloaked.png
message= _ "No, no, no more escaping. Please kill me, just make the pain end."
[/message]

[message]
description=Kaleh
message= _ "No, you have hounded me with your riddles for too long. I want some answers. Who are you? What's behind that black mask?"
[/message]

[message]
description=Cloaked Figure
image=portraits/uncloaked.png
message= _ "Behold, Kaleh, your own worst enemy. Do you now see the irony?"
[/message]

[message]
description=Nym
message= _ "Oh Eloh save us, it's....it's an elf."
[/message]

[message]
description=Kaleh
message= _ "Keratur, son of Tanuil. What is Eloh's name are you doing here? How could you do this? We thought you were dead."
[/message]

[message]
description=Zhul
message= _ "Kaleh, we don't have time for questions. The water is still rising and we must get our people to safety."
[/message]

[message]
description=Kaleh
message= _ "No matter what you have done, you are one of us, Keratur, and I will not leave you here to die in the darkness. I will carry you myself if I have to."
[/message]

[message]
description=Cloaked Figure
image=portraits/uncloaked.png
message= _ "So be it. I care not."
[/message]

[/event]

[event]
name=moveto

[filter]
x=12-20
y=1-18
side=1
[/filter]

[message]
speaker=unit
message= _ "Look, the tunnel slopes sharply downwards to the left. And it's big enough that it should divert most of the rising water."
[/message]

[message]
speaker=unit
message= _ "And I think I see a faint light off to the right."
[/message]

[message]
description=Zhul
message= _ "Could it be? Could we actually be almost out of this seemingly neverending darkness?"
[/message]

[/event]


# I want the conversation between Kaleh and the dwarf/troll ally
#  to occur the turn after the player finds the exit and Keratur dies

# So I am putting this event out of order, so that when the
# player enters the final cave, it checks if ally_conversation=1 before
# ally_conversation is set to 1. So that way, this event doesn't
# happen until the turn afterwards.

[event]
name=new turn
first_time_only=no

[if]
	[variable]
	name=ally_conversation
	numerical_equals=1
	[/variable]

	[then]

	[set_variable]
	name=ally_conversation
	value=2
	[/set_variable]

	[set_variable]
	name=ally_must_live
	value=0
	[/set_variable]

	[if]
		[variable]
		name=ally_race
		equals=Dwarf
		[/variable]

		[then]

		[message]
		description=Kaleh
		message= _ " $ally_name, I want to thank you so much for guiding us out of the caves. We never would have found our way without your help. But with the tunnels flooded, how are you going to find your way back to your people?"
		[/message]

		[message]
		description=$ally_name
		message= _ "Ach, it is I who should be congratulating you, laddie. I showed you the way, but it was you and your people who defeated the many perils and obstacles to your escape. In all my years such bravery and courage I have rarely seen."
		[/message]

		[message]
		description=$ally_name
		message= _ "But truly I cannot return the way I came and even if there are other tunnels which lead back down to my homeland, I do not know where to search for them. I know as little about the land above ground as you do."
		[/message]

		[message]
		description=$ally_name
		message= _ "But my king told me to protect you from all dangers, and I plan to keep that oath. I do not like the above ground, it is too open and exposed; I feel that I could be attacked from any direction. But an oath is an oath and so I will follow you and your people wherever you may go and protect you as best I can. The tunnels cannot stay flooded forever; later perhaps if am able to return this way, I may be able to find my way back to my homeland. But for now I am yours to command."
		[/message]

		[message]
		description=Kaleh
		message= _ " Your loyalty is a credit to your people. I am glad indeed to have you fighting by my side."
		[/message]

		[/then]

		[else]

		[message]
		description=Kaleh
		message= _ " $ally_name, thank you so much for leading us out of the caves. We never would have found our way without your help. But with the tunnels flooded, how are you going to find your way back to your people?"
		[/message]

		[message]
		description=$ally_name
		message= _ " $ally_name proud of little elves too. He would not have made it this far without all your help. $ally_name is surprised by your bravery and strength."
		[/message]

		[message]
		description=$ally_name
		message= _ "Truth is that $ally_name not know much of sunlight lands. Sun and stars are scary, everything is open, exposed, no safe places to hide. But $ally_name cannot go back through all that water. And $ally_name doesn't know where to find other tunnels back to his home. He is as lost as elves are."
		[/message]

		[message]
		description=$ally_name
		message= _ "But $ally_name not afraid. Great leader told $ally_name to guide and protect elves, and $ally_name will keep his oath. $ally_name will follow elves wherever they may go and protect them from danger as best he can. Maybe later, $ally_name will find another way back down to the caves of his people. But for now, $ally_name will continue to serve and protect you."
		[/message]

		[message]
		description=Kaleh
		message= _ " Your loyalty is a credit to your people. I am glad indeed to have you fighting by my side."
		[/message]

		[/else]
	[/if]

	[/then]
[/if]
[/event]


# when a unit moves into human outpost cavern, they see the human base
# and the dead guards. If unit is not Kaleh, Kaleh comes up to see
# Then Cloaked Figure asks Kaleh to put him down and a conversation
# ensues.


# This rather long macro ensures that if Kaleh is asked to come up next to
# the unit that fires the event he doesn't appear in a cave wall. Instead
# the macro finds an empty hex next to the unit. Since this event fires
# the first time any unit moves into target area, I am sure there will
# be an empty spot adjacent to the unit.

#define KALEH_TELEPORT X_LOC Y_LOC

# search adjacent hexs for one that is not cave wall or chasm or water
# when you find a hex that is valid, check to see if a unit is already
# there, if the hex is empty teleport Kaleh there

# x+0 y+1

[set_variable]
name=kaleh_x
value={X_LOC}
[/set_variable]

[set_variable]
name=kaleh_y
value={Y_LOC}
[/set_variable]

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]

[/if]


# x+1 y+0
[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

# x+0 y-1

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

	[set_variable]
	name=temp_y
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

# x-1 y+0

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

	[set_variable]
	name=temp_x
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

# x+1 y+1

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

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

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

# x+1 y-1

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

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

	[set_variable]
	name=temp_y
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

# x-1 y+1

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

	[set_variable]
	name=temp_x
	add=-1
	[/set_variable]

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

# x-1 y-1

[if]
	[variable]
	name=found_empty_hex
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=temp_x
	value=$kaleh_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$kaleh_y
	[/set_variable]

	[set_variable]
	name=temp_x
	add=-1
	[/set_variable]

	[set_variable]
	name=temp_y
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDoK[]
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[if]
			[have_unit]
			x,y=$temp_x,$temp_y
			side=1
			[/have_unit]

			[then]
			# do nothing
			[/then]

			[else]

			[teleport]
			[filter]
				description=Kaleh
			[/filter]
			x,y=$temp_x,$temp_y
			[/teleport]

			[/else]
		[/if]

		[/then]
	[/if]

	[/then]
[/if]

#enddef


[event]
name=moveto

[filter]
x=17-24
y=15-23
side=1
[/filter]

# reveal interior of entrance cave
[remove_shroud]
x=16-21
y=15-22
side=1
[/remove_shroud]

[remove_shroud]
x=21-24
y=17-21
side=1
[/remove_shroud]

# this command is to keep Daryl, Oswald, and Bernard's death counter
# from firing once side 2 humans start dying

[set_variable]
name=humans_killed
add=10
[/set_variable]

[message]
speaker=unit
message= _ "Look, daylight! I think we finally made it out of the caves!"
[/message]

[message]
speaker=unit
message= _ "What's this? Someone has built an outpost at the end of the cave. Where are its occupants?"
[/message]

[store_locations]
	x,y=$x1,$y1
	[filter]
	description="Kaleh"
	[/filter]
	variable=kalehtest
[/store_locations]

[if]
	[variable]
	name=kalehtest.length
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "Kaleh, I think you should come up and see this."
	[/message]

	{KALEH_TELEPORT $x1 $y1}

	[/then]
[/if]

{CLEAR_VARIABLE kalehtest}

[message]
speaker=Kaleh
message= _ "Oh, Eloh. They're all dead. Butchered. Quick, we have to clean this up, we don't want the rest of our people to have to see such horror."
[/message]

[message]
description=Kaleh
message= _ "Now, Keratur, I will have my answers. Did you have a hand in this?"
[/message]

#create keratur in a blank space near kaleh

[unit]
	type=Dark Assassin3
	description=Keratur
	user_description= _ "Keratur"
	profile=portraits/uncloaked.png
	x=$x1
	y=$y1
	side=1
	hitpoints=5
[/unit]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "They heard me and...and they got in the way. But they aren't even elves, what do they matter?"
[/message]

[message]
description=Nym
message= _ "You idiot--"
[/message]

[message]
description=Kaleh
message= _ "Quiet, Nym. But I still don't understand how you got here. We were sure you were dead. We searched and searched, but never found your body."
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "Heh, heh, no you didn't find me. I awoke trapped under the rubble, and when I finally escaped the village was deserted. Just the stink of death and destruction. And then I saw them, hordes of undead pouring down from across the dunes. A cabal of necromancers . . . they found me and made me watch, they made me watch it all! "
[/message]

[message]
description=Kaleh
message= _ "Watch what?"
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "They brought some humans, bound up tight. So beautiful...she had flaming red hair...they cut her...I can still hear her screaming. But that was only the beginning. They chanted words of power, and spilled the hot blood onto the sand and then I heard their screams of agony and pain..."
[/message]

[message]
description=Kaleh
message= _ "From the humans?"
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "Paugh. No, I heard the screams of the dead, torn from their rest, their souls rose into the air howling in agony."
[/message]

[message]
description=Zhul
message= _ "But, but we burned the bodies so they couldn't be raised."
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "Fool. That did not stop their dark power. Nothing could stop them. I felt the rush of flying spirits, and the unbearable cold, so cold. For a moment I felt their torment. But no, they wouldn't kill me. They let me go as a witness and laughed as I scrambled over the dunes."
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "I was able to follow your trail, and I slipped among your people. No one noticed me, no I was too sneaky. And you wondered how I managed to follow you through the tunnels? Hah, you escorted me."
[/message]

[message]
description=Kaleh
message= _ "But why, why did you want to kill us?"
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "You abandoned them! The pain, the agony, I still see their ghostly faces and hear their wails. And the necromancers kept chanting one name over and over: Yechnagoth, Yechnagoth, it reverberated in my ears. And every time I sleep I hear that name, and laughter, hideous laughter. She kept telling me it was your fault. And I believed her. Kaleh, forgive me, I just wanted to make the pain stop."
[/message]

[message]
description=Kaleh
message= _ "I...I forgive you."
[/message]

[message]
description=Keratur
image=portraits/uncloaked.png
message= _ "I do not fear death any more."
[/message]

#kill keratur

[kill]
description=Keratur
animate=no
fire_event=no
[/kill]

[message]
description=Kaleh
message= _ "He's dead. Rest in peace. Oh, what have I done? All our dead kin, desecrated and tormented for eternity."
[/message]

[message]
description=Zhul
message= _ "As you said yourself, the past is the past, there is nothing you can do now."
[/message]

[message]
description=Nym
message= _ "Don't blame yourself. You didn't know. If we had stayed behind we too would have been killed by the undead; we could not have defended our village against so many. We had no choice."
[/message]

[message]
description=Kaleh
message= _ "That is small consolation. My deeds have turned to ashes in my mouth. Eloh forgive me. I did not know."
[/message]

[delay]
time=1000
[/delay]

# Nym asks to be allowed to scout outside

[message]
description=Nym
message= _ "With your permission, Kaleh, I think I should go scout around a bit outside. We have no idea what lies out there. And I can sneak around unseen many places you can't."
[/message]

[message]
description=Kaleh
message= _ "Okay Nym, just be careful."
[/message]

[message]
description=Nym
message= _ "I'm always careful. I'll be back soon."
[/message]

[store_unit]
	[filter]
	description=Nym
	[/filter]
	kill=yes
	variable=Nymstats
[/store_unit]

[delay]
time=500
[/delay]

# price of recruits goes up based on number of turns it took to escape
# the caves

[message]
description=Kaleh
message= _ "Well, at least we can use this outpost to rally our surviving troops. How many of our people made it out of the caves, Zhul?"
[/message]

[message]
description=Zhul
message= _ "We're still trying to get a head count, but between the underground horrors and the water, we lost quite a few. Recruiting new warriors is going to be even more difficult. Still we should thank Eloh, and you, Kaleh, that so many of us did survive."
[/message]

# increase the price of recruiting new units by 2 gold

	[if]

		[variable]
		name=scen3
		numerical_equals=2
		[/variable]

		[then]

		#go from 5 to 7

		[disallow_recruit]
			type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
			side=1
		[/disallow_recruit]

		[disallow_recruit]
			type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
			side=1
		[/disallow_recruit]

		[allow_recruit]
			type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
			side=1
		[/allow_recruit]

		[/then]

		[else]

		[if]
			[variable]
			name=scen3
			numerical_equals=1
			[/variable]

			[then]

			#go from 4 to 6

			[disallow_recruit]
				type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
				side=1
			[/disallow_recruit]

			[allow_recruit]
				type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
				side=1
			[/allow_recruit]

			[/then]
		[/if]

		[if]
			[variable]
			name=scen3
			numerical_equals=3
			[/variable]

			[then]

			#go from 6 to 8

			[disallow_recruit]
				type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
				side=1
			[/disallow_recruit]

			[disallow_recruit]
				type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
				side=1
			[/disallow_recruit]

			[allow_recruit]
				type=Desert Fighter8, Desert Archer8, Desert Hunter8, Desert Shaman8, Desert Scout8
				side=1
			[/allow_recruit]

			[/then]

		[/if]

		[/else]
	[/if]

[message]
description=Kaleh
message= _ "Well, Nym's right, we don't know what's out there. So we should set up a perimeter guard around the cave mouth and start discovering what this side of the mountains looks like."
[/message]

[objectives]
summary= _ "New Objectives:"
show=yes
	[objective]
		description= _ "Explore Outside"
		condition=win
	[/objective]
	[objective]
		description= _ "Death of Kaleh, Nym, or Zhul"
		condition=lose
	[/objective]
[/objectives]

[set_variable]
name=ally_conversation
value=1
[/set_variable]

# change the music playing
[music]
name=elf-land.ogg
immediate=yes
[/music]

# remove hero icon from troll/dwarf ally

{REMOVE_UNIT_OVERLAY description=$ally_name misc/hero-icon.png}

[/event]

# Event 14.5 Player discovers human's chest of gold at cave mouth

[event]
name=moveto

[filter]
x,y=17,21
side=1
[/filter]

{PUT_IMG items/chest-plain-open.png 17 21}

[sound]
name=gold.ogg
[/sound]

[message]
speaker=unit
message= _ "Looks like the guards at this outpost had been saving away a bit of loot. I don't suppose they're going to mind anymore if we made use of it."
[/message]

#ifdef EASY
[gold]
	amount=50
	side=1
[/gold]
#endif

#ifdef MEDIUM
[gold]
	amount=50
	side=1
[/gold]
#endif

#ifdef HARD
[gold]
	amount=25
	side=1
[/gold]
#endif

[/event]


# Event 15: Elves step out into the daylight, Eloh appears

# asks for Kaleh, he goes outside, conversation ensues
# human leader rides up, talks, leaves

[event]
name=moveto

#event should only fire when unit steps several hexes out into the dunes

[filter]
x=25-50
y=19-31
side=1
[/filter]

[store_locations]
x,y=$x1,$y1
[filter]
	race=elf
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=1
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "Praise Eloh, it is so good to be outside again.  To see the sky stretching out above me, to feel the wind in my face..."
	[/message]

	[/then]
[/if]

{CLEAR_VARIABLE unittest}

[store_locations]
x,y=$x1,$y1
[filter]
	description=$ally_name
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=1
	[/variable]

	[then]

	[if]
		[variable]
		name=ally_race
		equals=Dwarf
		[/variable]

		[then]
		# dwarf ally version

		[message]
	speaker=unit
	message= _ "I think we finally made it outside. I'd forgotten how big the sky is and how windy it can be."
		[/message]

		[/then]

		[else]
		# troll ally version

		[message]
	speaker=unit
	message= _ "We made it. Outside look strange to $ally_name, $ally_name not used to big open spaces."
		[/message]

		[/else]
	[/if]

	[/then]
[/if]

{CLEAR_VARIABLE unittest}

[store_locations]
x,y=$x1,$y1
[filter]
	description=Kromph
[/filter]
variable=unittest
[/store_locations]

[if]
	[variable]
	name=unittest.length
	numerical_equals=1
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "Kromph is outside, but everything looks strange. What does mistress want Kromph to do?"
	[/message]

	[message]
	description=Nym
	message= _ "Just stay where you are, I'll come up there myself"
	[/message]

	# teleport nym next to kromph to see for herself

	[teleport]
	[filter]
		description=Nym
	[/filter]
	x,y=$temp_x,$temp_y
	[/teleport]

	[redraw]
	[/redraw]

	[message]
	description=Nym
	message= _ "Praise Eloh, it is so good to be outside again.  To see the sky stretching out above me, to feel the wind in my face..."
	[/message]

	[/then]
[/if]

{CLEAR_VARIABLE unittest}

#from an elf still in the cave
[message]
x,y=12-23,15-20
side=1
race=elf
message= _ "Can you see very far? Do you have any idea where we are?"
[/message]

[message]
speaker=unit
message= _ "We've come out on the side of a mountain, overlooking a large valley. The land seems to be much the same as the foothills south of the mountains. The valley is filled with sand dunes, though the center is flat.  There seems to be some sort of settlement in the center of the valley. And far to the north I can see something sparkling on the horizon, but I don't know what it is."
[/message]

#reveal most of the valley to player

#central corridor
[remove_shroud]
x=26-49
y=0-30
side=1
[/remove_shroud]

#NW cave wall right above unit
[remove_shroud]
x=25-31
y=19-20
side=1
[/remove_shroud]

#SW edge of valley, southern cave wall near player

[remove_shroud]
x=21-31
y=27
side=1
[/remove_shroud]

[remove_shroud]
x=23-31
y=28
side=1
[/remove_shroud]

[remove_shroud]
x=25-31
y=29
side=1
[/remove_shroud]

#South and SE edge of valley
[remove_shroud]
x=48-56
y=17-26
side=1
[/remove_shroud]

[remove_shroud]
x=48-54
y=27
side=1
[/remove_shroud]

[remove_shroud]
x=48-53
y=28
side=1
[/remove_shroud]

[remove_shroud]
x=48-51
y=29-30
side=1
[/remove_shroud]

[remove_shroud]
x=27-49
y=31
side=1
[/remove_shroud]

[remove_shroud]
x=29-31
y=32
side=1
[/remove_shroud]

[remove_shroud]
x=35-47
y=32
side=1
[/remove_shroud]

#eloh appears

{FREE_UNIT (Divine Avatar) (Eloh) ( _ "Eloh") 2 30 22}

[store_locations]
	x,y=$x1,$y1
	[filter]
	description="Kaleh"
	[/filter]
	variable=kalehtest
[/store_locations]

[store_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	variable=speaker
[/store_unit]

[if]
	[variable]
	name=kalehtest.length
	numerical_equals=0
	[/variable]

	[then]

	#if Kaleh isn't the unit moving outside then Eloh calls for him

	[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Kaleh, Kaleh, come to me."
	[/message]

	[message]
	description=Kaleh
	message= _ "What is the voice? It sounds so familiar."
	[/message]

	[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Come out so that I might see you. Your god calls to you."
	[/message]

	[message]
	description=Kaleh
	message= _ "Am I dreaming? Is this real? I'm coming, I'm coming."
	[/message]

	[teleport]
	[filter]
		description=Kaleh
	[/filter]
	x,y=25,23
	[/teleport]

	[/then]

	[else]

	[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Hail Kaleh, it is I, Eloh."
	[/message]

	[/else]
[/if]

[message]
	description=Kaleh
	message= _ "But I am not asleep? And yet I can see you? How is this possible?"
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Do you doubt my powers? You have come out of the darkness, and I appear unto you to congratulate you."
[/message]

# if kaleh didn't go outside first, the unit who did asks kaleh who is
# is talking to. Otherwise Zhul asks him.

[if]
	[variable]
	name=kalehtest.length
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit
	message= _ "Kaleh, who are you talking to?"
	[/message]

	[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "For now, I appear only to you, for you, Kaleh, are special, you are the Chosen One."
	[/message]

	[message]
	description=Kaleh
	message= _ " $speaker.description, be quiet, I'll explain it all later."
	[/message]

	[/then]

	[else]

	[message]
	description=Zhul
	message= _ "Kaleh, who are you talking to?"
	[/message]

	[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "For now, I appear only to you, for you, Kaleh, are special, you are the Chosen One."
	[/message]

	[message]
	description=Kaleh
	message= _ "Be quiet Zhul, I'll explain it all later."
	[/message]

	[/else]
[/if]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Yes, I have chosen you as the one to lead my people out of danger and death and into a life of eternal salvation. Crossing under the mountains was a very important step, and your destruction of the unbelievers proves your-"
[/message]

#troll/dwarf ally teleports to just outside of cave

[teleport]
[filter]
	description=$ally_name
[/filter]
x,y=21,23
[/teleport]

[message]
	description=$ally_name
	message= _ "Kaleh, a quick question-"
[/message]

[message]
	description=Kaleh
	message= _ "Not now $ally_name, I'm busy."
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "What's this? You did not kill the unbelievers?!"
[/message]

[if]
	[variable]
	name=ally_race
	equals=Dwarf
	[/variable]

	[then]

	[message]
		description=Kaleh
		message= _ "I am sorry I could not have fulfilled your command, but we found ourselves in the middle of a war. We were vastly outnumbered and we needed help. In fact the Dwarves have been very helpful.  They helped protect us from the trolls and without their guidance we would not have made it out of the caves alive."
	[/message]

	[/then]

	[else]

	[message]
		description=Kaleh
		message= _ "I am sorry I could not have fulfilled your command, but we found ourselves in the middle of a war. We were vastly outnumbered and we needed help. In fact the Trolls have been very helpful.  They helped protect us from the dwarves and without them we would not have made it out of the caves alive."
	[/message]

	[/else]
[/if]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "You were weak and foolish, but I forgive you. You must remember, Kaleh, that without my guidance, your people would have died out years ago. I am your god, and you must follow my every command."
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Now, in the valley live a group of humans who have also seen the light. They may seem strange, but they are my obedient followers. You must trust them, they will show you the way north. Follow them and they will lead you to me. "
[/message]

[message]
	description=Kaleh
	message= _ "What do you mean 'lead you to me'? You are a god, don't you exist everywhere? I thought you were going to show us our new home."
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Of course I am. Oh, how little you understand. Do not worry yourself with all those tiny questions. Come to me and all will be made clear."
[/message]

{CLEAR_VARIABLE kalehtest}
{CLEAR_VARIABLE speaker}

[delay]
time=100
[/delay]

{FREE_UNIT (Human Commander) (Sergeant Durstrag) ( _ "Sergeant Durstrag") 2 30 25}
{FREE_UNIT (Dragoon) (Human Guard) ( _ "Human Guard") 2 31 25}
{FREE_UNIT (Dragoon) (Human Guard) ( _ "Human Guard") 2 31 26}
{FREE_UNIT (Swordsman) (Human Guard) ( _ "Human Guard") 2 30 24}
{FREE_UNIT (Longbowman) (Human Guard) ( _ "Human Guard") 2 30 26}

[message]
	description=Sergeant Durstrag
	message= _ "I saw the distress signal from the outpost on the bluff. Who in the Dark Lady's name are you and what have you done with my men?"
[/message]

[message]
	description=Kaleh
	message= _ "My name is Kaleh, and these are my people. We come from the south and unfortunately we found your men dead--"
[/message]

[message]
	description=Sergeant Durstrag
	message= _ "Dead?! You 'found' them you say? You'll pardon me if I don't take you at your word. We haven't seen elves for generations, but we remember your ancient betrayal. What are elves doing sneaking up through the caves out onto our back doorstep? "
[/message]

[message]
	description=$ally_name
	message= _ "Well, actually they were fleeing from--"
[/message]

[if]
	[variable]
	name=ally_race
	equals=Troll
	[/variable]

	[then]

	[message]
		description=Sergeant Durstrag
		message= _ "A troll! This just gets better and better. We haven't seen one of your kind up here for many years, but I have a long memory. I still remember the troll raids when I was a youth."
	[/message]

	[/then]

	[else]

	[message]
		description=Sergeant Durstrag
		message= _ "A dwarf! This just gets better and better. We haven't seen one of your kind up here for many years, but we have a long memories. I remember how your 'traders' used to come up and cheat us out of our valuables. You'll find we're not so easy to fool this time."
	[/message]

	[/else]
[/if]

[message]
	description=Kaleh
	message= _ "Look, if you'll just let me explain--"
[/message]

[if]
	[variable]
	name=ally_race
	equals=Troll
	[/variable]

	[then]

	[message]
		description=Sergeant Durstrag
		message= _ "Oh there is no need to explain, it's pretty obvious what you're up to. Here we have a whole legion of elves, consorting with trolls, sneaking up behind our defenses. This looks an awful lot like an invasion to me."
	[/message]

	[/then]

	[else]

	[message]
		description=Sergeant Durstrag
		message= _ "Oh they're no need to explain, it's pretty obvious what you're up to. Here we have a whole legion of elves, consorting with dwarves, sneaking up behind our defenses. This looks an awful lot like an invasion to me. "
	[/message]

	[/else]
[/if]

[message]
	description=Kaleh
	message= _ "No, no. You don't understand! We were told you could help us."
[/message]

[message]
	description=Human Guard
	message= _ "Sir, remember the edict passed down by councilman Noblis? About any foreigners spotted on the borders?"
[/message]

[message]
	description=Sergeant Durstrag
	message= _ "I have no idea what you're babbling about, elf, but you're just lucky you caught me on a good day. You get to explain everything to the Iron Council. Now you and your people just lay down your weapons and we will take you into custody to be judged. They'll deal with you as they see fit."
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Everything will be fine. Do as he says."
[/message]

[message]
	description=Kaleh
	message= _ "I am my own master. I will not be ordered around, not even by you, Eloh."
[/message]

[message]
	description=Sergeant Durstrag
	message= _ "What's that, boy? Are you talking back to me? This isn't a negotiation. You are on my land, and under my jurisdiction. Lay down your weapons and submit peacefully or I'll make you sorry you didn't."
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Kaleh, I am Eloh, bearer of the staff of Ishtar and slayer of the demon-god Yanqui. Do as I say! Submit to him or I will abandon your people to suffering and death. Your bones will litter the sand dunes, and vultures shall pick at your flesh. I am not a forgiving god, Kaleh."
[/message]

[message]
	description=Kaleh
	message= _ "Then kill me if you must, but I will not give myself over to those who threaten me and my people. I have not come through peril and darkness just to surrender to a man such as you."
[/message]

[message]
	description=Sergeant Durstrag
	message= _ "Your dare defy me?!? All who refuse to submit to the authority of the Iron Council shall be killed. By the Dark Lady, I shall not put up with this bickering any longer. To battle men! Drive those heathens back into the caves!"
[/message]

# Move Durstag and his guards back to human base

[kill]
description=Sergeant Durstrag
animate=no
fire_event=no
[/kill]

[kill]
description=Human Guard
animate=no
fire_event=no
[/kill]

[unit]
	type=Human Commander
	description=Sergeant Durstrag
	user_description= _ "Sergeant Durstrag"
	canrecruit=1
	upkeep=free
	x=44
	y=27
	side=2
	[modifications]
	{TRAIT_INTELLIGENT}
	{TRAIT_RESILIENT}
	[/modifications]
[/unit]

{UNIT_ (Dragoon) (Human Guard) ( _ "Human Guard") 2 43 28}
{UNIT_ (Dragoon) (Human Guard) ( _ "Human Guard") 2 44 26}
{UNIT_ (Swordsman) (Human Guard) ( _ "Human Guard") 2 43 27}
{UNIT_ (Longbowman) (Human Guard) ( _ "Human Guard") 2 44 27}

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "You disappoint me, Kaleh. You are weak, and not worthy of my guidance. Do what you will, but this is not over. You may be the appointed leader of your people but I am your god, and I will not let you usurp my authority."
[/message]

[kill]
description=Eloh
animate=no
fire_event=no
[/kill]

[message]
	description=Kaleh
	message= _ "You are not the god I grew up with. You may be all powerful, but I will not be your puppet. I am still their leader and as long as I draw breath I will do what I think is best for my people."
[/message]

[message]
	description=Zhul
	message= _ "Kaleh, would you mind telling me what in Uria's name is going on."
[/message]

[message]
	description=Kaleh
	message= _ "There's no time. Right now we have to prepare ourselves for another battle. I'd better head back to the outpost and rally our troops. I fear a whole lot of hurt is going to be coming up through those hills very soon."
[/message]

[message]
	description=Zhul
	message= _ "Well, now we're really in for it. I hope you know what you're doing, Kaleh."
[/message]

[teleport]
[filter]
	description=Kaleh
[/filter]
x,y=18,19
[/teleport]

[if]
	[variable]
	name=ally_race
	equals=Troll
	[/variable]

	[then]

	[message]
	description=$ally_name
	message= _ " $ally_name no like humans either. They mean. But they sound great when they go squish."
	[/message]

	[/then]

	[else]

	[message]
	description=$ally_name
	message= _ "I never liked humans much anyway. I'll be glad to be fighting something besides undead."
[/message]

	[/else]
[/if]

[modify_side]
	side=2

	#ifdef EASY
	income=9
	gold=150
	#endif
	#ifdef MEDIUM
	income=11
	gold=150
	#endif
	#ifdef HARD
	income=13
	gold=175
	#endif
[/modify_side]

#capture some of the nearby villages
[capture_village]
	x,y=34-37,25-26
	side=2
[/capture_village]

[capture_village]
	x,y=41-43,19-23
	side=2
[/capture_village]

[objectives]
summary= _ "New Objectives:"
show=yes
	[objective]
		description= _ "Defeat Sergeant Durstrag"
		condition=win
	[/objective]
	[objective]
		description= _ "Death of Kaleh, Nym, or Zhul"
		condition=lose
	[/objective]
[/objectives]

[set_variable]
	name=pissed_off_durstrag
	value=1
[/set_variable]

# change the music playing
[music]
name=wesnoth-2.ogg
immediate=yes
[/music]

[/event]

# Event 16: Nym returns

# Next turn after big Eloh/Durstrag conversation, Nym returns and
# tells Kaleh that Durstrag plans to send for reinforcements

# Since last turn Kaleh got teleported to (18,19) he can't have moved
# very far. If Kaleh is on player's keep hex (which is probable) then
# teleport Nym right next to him. If he's in northern part of entrance cave
# put her in center of cave. Else assume he's at edge of southern cave and
# put her near him. I could just teleport Nym directly onto Kaleh's
# location, but this often makes her appear in a cave wall.

[event]
name=new turn
first_time_only=no

[if]
	[variable]
	name=pissed_off_durstrag
	numerical_equals=1
	[/variable]

	[then]

	[set_variable]
	name=pissed_off_durstrag
	value=2
	[/set_variable]

	[unstore_unit]
	variable=Nymstats
	[/unstore_unit]

	{CLEAR_VARIABLE Nymstats}

	# if Kaleh is on keep hex (18,19) teleport Nym next to him

	[if]
		[have_unit]
		description=Kaleh
		x,y=18,19
		[/have_unit]

		[then]

		[teleport]
		[filter]
			description=Nym
		[/filter]
		x,y=19,19
		[/teleport]

		[/then]

		[else]

		# if Kaleh is elsewhere in northern part of entrance caves,
		# then put Nym on 21,20 (roughly center of entrance cave)

		[if]
			[have_unit]
			description=Kaleh
			x,y=13-24,16-20
			[/have_unit]

			[then]

			[teleport]
			[filter]
				description=Nym
			[/filter]
			x,y=21,20
			[/teleport]

			[/then]

			[else]

			# else Kaleh must be at edge of entrance cave,
			# so put Nym at 21,21

			[teleport]
			[filter]
				description=Nym
			[/filter]
			x,y=21,21
			[/teleport]

			[/else]
		[/if]

		[/else]

	[/if]

	[message]
	description=Nym
	message= _ "I'm back, Kaleh."
	[/message]

	[message]
	description=Kaleh
	message= _ "Ah! You scared me, Nym. I didn't hear you coming."
	[/message]

	[message]
	description=Nym
	message= _ "Of course you didn't. That's why it's called sneaking."
	[/message]

	[message]
	description=Nym
	message= _ "Anyway you've really gotten us into a mess. The good news is that the outpost isn't guarded as heavily as you might think. The garrison seems only half-manned. They obviously didn't expect any serious attack to come from this direction."
	[/message]

	[message]
	description=Kaleh
	message= _ "And what's the bad news?"
	[/message]

	[message]
	description=Nym
	message= _ "The bad news is that I overheard the commander ordering a special group of his men to get ready to ride north and summon reinforcements. It seems that the humans have a bigger village to the north. This outpost is lightly guarded enough that we might be able to defeat them, but in our weakened state if they bring the full strength of their army against us I fear we may be crushed."
	[/message]

	[message]
	description=Kaleh
	message= _ "Then we'll just have to make sure that no messenger escapes this valley to summon reinforcements."
	[/message]

	[objectives]
	summary= _ "New Objectives:"
	show=yes
	[objective]
		description= _ "Defeat Sergeant Durstrag"
		condition=win
	[/objective]
	[objective]
		description= _ "If a human messenger escapes the valley"
		condition=lose
	[/objective]
	[objective]
		description= _ "Death of Kaleh, Nym, or Zhul"
		condition=lose
	[/objective]
	note= _ "The messenger is the leader of the special white colored units"
	[/objectives]

	# flag to store if we should start the messenger timer or not
	[set_variable]
	name=start_messenger_timer
	value=1
	[/set_variable]

	#set messenger timer at 2, so first messenger goes in 6,5,4 turns

	[set_variable]
	name=messenger_timer
	value=2
	[/set_variable]

	[/then]
[/if]
[/event]

# Event 17: Undead Emissary

# If it is dusk or night

[event]
name=new turn
first_time_only=no

[if]
	[variable]
		name=time_of_day
		equals=5
	[/variable]

	[or]
	[variable]
		name=time_of_day
		equals=6
	[/variable]
	[/or]

	[or]
	[variable]
		name=time_of_day
		equals=-5
	[/variable]
	[/or]

	[or]
	[variable]
		name=time_of_day
		equals=-6
	[/variable]
	[/or]

	[or]
	[variable]
		name=time_of_day
		equals=-7
	[/variable]
	[/or]

	[or]
	[variable]
		name=time_of_day
		equals=-8
	[/variable]
	[/or]

	[or]
	[variable]
		name=time_of_day
		equals=-9
	[/variable]
	[/or]

	[then]

	[if]
		[variable]
		name=start_messenger_timer
		numerical_equals=1
		[/variable]

		[variable]
		name=undead_emissary
		numerical_equals=0
		[/variable]

		[then]

		[set_variable]
		name=undead_emissary
		value=1
		[/set_variable]

		[move_unit_fake]
		type=ENightgaunt
		x=34,35,36,36,35
		y=32,32,31,30,30
		[/move_unit_fake]

		{FREE_UNIT (ENightgaunt) (Undead Emissary) ( _ "Undead Emissary") 5 35 30}

		[message]
		description=Undead Emissary
		message= _ "Cursed Elves, you tracked your filth through our halls and you defiled our sanctuary. You have besmirched our honor, and we will have our revenge. We are the order of the crimson talon, and even death shall not stop us. You shall rue the day that you ever trespassed into our lair!"
		[/message]

		[kill]
		description=Undead Emissary
		animate=no
		[/kill]

		[move_unit_fake]
		type=ENightgaunt
		x=35,35,35,35
		y=30,31,32,33
		[/move_unit_fake]

		[message]
		description=Nym
		message= _ "Can't the dead ever just stay dead? And aren't they trapped by the flooded tunnels and caves?"
		[/message]

		[message]
		description=Zhul
		message= _ "Undead don't have to breathe and I don't think a little water is going to stop them. Besides, you saw how the ghost just flew through the rock; if they can move through walls then what do they care about flooded tunnels?"
		[/message]

		[message]
		description=Nym
		message= _ "Great. So now we're fighting in a haunted valley."
		[/message]

		[modify_side]
		side=5

		#ifdef EASY
		income=9
		gold=100
		#endif
		#ifdef MEDIUM
		income=11
		gold=125
		#endif
		#ifdef HARD
		income=13
		gold=150
		#endif
		[/modify_side]

		[unit]
		type=Spectre
		description=Undead Leader
		user_description= _ "Undead Leader"
		canrecruit=1
		side=5
		upkeep=free
		x=28
		y=37
		[/unit]

		[/then]

	[/if]

	[/then]
[/if]

[/event]

#Event 17.5 A conversation about the humans

[event]
name=new turn
first_time_only=no

[if]
	[variable]
	name=messenger_timer
	numerical_equals=1
	[/variable]

	[variable]
	name=human_conversation
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=human_conversation
	value=1
	[/set_variable]

	[message]
	description=Kaleh
	message= _ "I don't understand. What are these humans doing here? I've never seen so many in one place before."
	[/message]

	[message]
	description=Zhul
	message= _ "Humans aren't just the bandits and outlaws you're familiar with from the deserts, Kaleh. Remember that long ago the great human empire of Wesnoth spread all across the known lands. Some of our people say that it was the humans who brought the great fall upon us. But to blame others is folly. Eloh says that it was not the darkness without, but the darkness within us that was the cause of our corruption and downfall."
	[/message]

	[message]
	description=Zhul
	message= _ "But now is not a time for preaching. Humans once spread to many lands, and despite all the ravages of time, I have no doubt that at least a few of them have survived. They are a hardy people and quickly adapt to new conditions. I only wish that the same could be said of our brethren."
	[/message]

	[message]
	description=Nym
	message= _ "There might be other elves somewhere. We can't be sure."
	[/message]

	[message]
	description=Kaleh
	message= _ "No we can't. But for now we must deal with the problem at hand. Thank you for the information, Zhul; these humans are good fighters but they are no match for our speed and skill. I grew up fighting in dunes such as these, and I will not be bested by a bunch of ruffians."
	[/message]

	[/then]
[/if]

[/event]

# Event 18: Sending for Reinforcements

# EASY: 1 dragoon, 2 cavalryman, 2 spearmen
# MEDIUM: 1 dragoon, 2 cavaliers, 1 javelineer, 1 longbowman
# HARD: 3 dragoons, 1 swordsman, 1 longbowman

# EASY: once every 8 turns
# MEDIUM: once every 7 turns
# HARD: once every 6 turns

[event]
name=new turn
first_time_only=no

[if]
	#ifdef EASY
	[variable]
	name=messenger_timer
	numerical_equals=8
	[/variable]
	#endif
	#ifdef MEDIUM
	[variable]
	name=messenger_timer
	numerical_equals=7
	[/variable]
	#endif
	#ifdef HARD
	[variable]
	name=messenger_timer
	numerical_equals=6
	[/variable]
	#endif

	[then]

	[set_variable]
	name=messenger_timer
	value=0
	[/set_variable]

	[message]
	description=Sergeant Durstrag
	message= _ "Send forth the messenger and his escort. Go north and bring help as soon as possible!"
	[/message]

	{RANDOM 44..51}

	[set_variable]
	name=loc_x
	value=$random
	[/set_variable]

	{RANDOM 21..25}

	[set_variable]
	name=loc_y
	value=$random
	[/set_variable]

	[unit]
	type=Dragoon
	description=Human Messenger
	user_description= _ "Human Messenger"
	canrecruit=1
	upkeep=free
	x=$loc_x
	y=$loc_y
	goto_y=1
	side=8
	[/unit]

	[unit]
	#ifdef EASY
	type=Cavalryman
	#endif
	#ifdef MEDIUM
	type=Cavalier
	#endif
	#ifdef HARD
	type=Dragoon
	#endif
	description=Human Escort
	user_description= _ "Human Escort"
	upkeep=free
	x=$loc_x
	y=$loc_y
	goto_y=1
	side=8
	[/unit]

	[unit]
	#ifdef EASY
	type=Cavalryman
	#endif
	#ifdef MEDIUM
	type=Cavalier
	#endif
	#ifdef HARD
	type=Dragoon
	#endif
	description=Human Escort
	user_description= _ "Human Escort"
	upkeep=free
	x=$loc_x
	y=$loc_y
	goto_y=1
	side=8
	[/unit]

	[unit]
	#ifdef EASY
	type=Spearman
	#endif
	#ifdef MEDIUM
	type=Javelineer
	#endif
	#ifdef HARD
	type=Swordsman
	#endif
	description=Human Escort
	user_description= _ "Human Escort"
	upkeep=free
	x=$loc_x
	y=$loc_y
	goto_y=1
	side=8
	[/unit]

	[unit]
	#ifdef EASY
	type=Spearman
	#endif
	#ifdef MEDIUM
	type=Longbowman
	#endif
	#ifdef HARD
	type=Master Bowman
	#endif
	description=Human Escort
	user_description= _ "Human Escort"
	upkeep=free
	x=$loc_x
	y=$loc_y
	goto_y=1
	side=8
	[/unit]

	[message]
	description=Kaleh
	message= _ "If that messenger escapes the valley, we'll be in trouble. We have to stop him!"
	[/message]

	[/then]
[/if]
[/event]

# Event 18.5: Messenger Dies

[event]
name=die
first_time_only=no

[filter]
	description=Human Messenger
[/filter]

[message]
description=Human Messenger
message= _ "No! I must get help!"
[/message]

[message]
description=Kaleh
message= _ "Good. We're safe for now. We just have to defeat Durstrag before he sends another messenger for reinforcements."
[/message]

[/event]

# Event 19: Messenger Escapes!

[event]
name=moveto

[filter]
side=8
description = _ "Human Messenger"
y=1
[/filter]

[kill]
description= _ "Human Messenger"
animate=no
fire_event=no
[/kill]

[message]
description=Kaleh
message= _ "The messenger has escaped! He will surely return with reinforcements. We are doomed!"
[/message]

[endlevel]
	result=defeat
[/endlevel]
[/event]


# Event 20: Defeat of Sergeant Durstrag

[event]
name=die

[filter]
description=Sergeant Durstrag
[/filter]

[message]
description=Kaleh
message= _ "Don't worry. We're not the monsters you seem to think we are. I will not kill you in cold blood."
[/message]

[message]
description=Sergeant Durstrag
message= _ "Paugh, boy, you know nothing! There are fates worse than death."
[/message]

[kill]
description=Sergeant Durstrag
animate=yes
fire_event=no
[/kill]

[message]
description=Nym
message= _ "He killed himself rather then surrender to us!"
[/message]

[message]
side=2
message= _ "They killed Sergeant Durstrag! Run for your lives!"
[/message]

[kill]
side=2
animate=no
fire_event=no
[/kill]

[kill]
side=5
animate=no
fire_event=no
[/kill]

[message]
description=Zhul
message= _ "The rest of the humans are fleeing."
[/message]

[message]
description=Kaleh
message= _ "Let them go. We have won this battle and I am weary of all this bloodshed."
[/message]

[message]
description=Zhul
message= _ "What was it that the human Durstrag was so afraid of?"
[/message]

[message]
description=Kaleh
message= _ "I don't know, but I fear we may find out."
[/message]

[message]
description=Zhul
message= _ "You're being very cryptic, Kaleh. Now that the battle is over would you care to explain to us who you were talking to back when we first met the humans?"
[/message]

[message]
description=Kaleh
message= _ "No, not yet."
[/message]

[message]
description=Nym
message= _ "What's wrong, Kaleh? Don't you trust us?"
[/message]

[message]
description=Kaleh
message= _ "Yes, yes of course I do. But it's just a theory. I don't want to say more until I have proof. Give me until tomorrow night, then I'll tell you everything."
[/message]

[message]
description=Zhul
message= _ "Very well. I've trusted your decisions and your leadership so far; I'll wait a little longer."
[/message]

[message]
description=Nym
message= _ "So what do we do now? The land seems to be about the same on the northern side of the mountains as it was on the south. And we can't hang around here forever. The humans will be back with reinforcements eventually, and the valley is still haunted with undead."
[/message]

[message]
description=Kaleh
message= _ "Yes, I think the sooner we leave this valley the better. But we don't know anything about the surrounding terrain. Without anyone to guide us, we have no idea what perils may be nearby. I don't like sending our people across foreign lands when I don't know what's in front of us. We've lost too many people already. I don't want to lead us into a trap."
[/message]

[message]
description=Nym
message= _ "When I was scouting around I think I saw a small oasis near the entrance to this valley. If we move out there we should be out of range of the undead. I think it would be safe, at least for the short term."
[/message]

[message]
description=Zhul
message= _ "Indeed. Undead ghosts such as these are often bound to the places they died: the farther away they travel, the weaker they are. So if we move out of the immediate vicinity we should be pretty safe."
[/message]

[message]
description=Kaleh
message= _ "Good, we'll move our people out and camp by the oasis. Now, Nym, you know who our best scouts are; I want you to lead a few elves to do some reconnaissance.  We'll send out small groups of scouts to the north, northeast and northwest. Don't go too far, try not to be seen, and please don't do anything dangerous. But I want to know what's out there."
[/message]

[message]
description=Zhul
message= _ "But hasn't Eloh told you where to go and what dangers you face?"
[/message]

[message]
description=Kaleh
message= _ "She was ... rather vague. I know we're supposed to generally go north, but I want more information before I commit us to a direction."
[/message]

[message]
description=Nym
message= _ "Don't you worry about us, Kaleh. We'll be careful. I'll organize five bands to scout out the nearby lands. We should be back in about half a day."
[/message]

[message]
description=Kaleh
message= _ "Good, until then we'll settle around that oasis and set up as good a defense as we can. Until I know what's out there, I'm not taking any chances."
[/message]

[endlevel]
	result=victory
	bonus=yes
[/endlevel]

[/event]


# Flooding algorithm

# At the end of each turn:

# Turn shallow water hexes to deep water and
# Turn all cave tiles within one hex of water to shallow water

# Step by Step Process:
# 1. change all shallow water hexes to ice
# 2. change hexes adjacent to ice to shallow water (except for cave wall)
# 3. change ice to deep water
# 4. kill any unit in deep water, destroy any items in deep water

[event]
name=new turn
first_time_only=no

[if]
	[variable]
	name=stop_flooding
	numerical_equals=0
	[/variable]
	
	# don't flood before first turn
	[not]
	[variable]
	name=turn_number
	numerical_equals=1
	[/variable]
	[/not]

	[then]

# 1. change all shallow water hexes to ice

[store_locations]
	x=1-99
	y=1-99
	radius=1000
	terrain=c
	variable=shallowwater_loc
[/store_locations]

{FOREACH shallowwater_loc i}

[set_variable]
	name=water_x
	to_variable=shallowwater_loc[$i].x
[/set_variable]

[set_variable]
	name=water_y
	to_variable=shallowwater_loc[$i].y
[/set_variable]

[terrain]
	letter=i
	x,y=$water_x,$water_y
[/terrain]

{NEXT i}

{CLEAR_VARIABLE shallowwater_loc}

# 2. change caves adjacent to ice to shallow water

[store_locations]
	x=1-99
	y=1-99
	radius=1000
	terrain=i
	variable=deepwater_loc
[/store_locations]

{FOREACH deepwater_loc i}

[set_variable]
	name=water_x
	to_variable=deepwater_loc[$i].x
[/set_variable]

[set_variable]
	name=water_y
	to_variable=deepwater_loc[$i].y
[/set_variable]

# find adjacent hex with cave floor or dirt

# test these hexes

# x+0 y+1

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x+1 y+0

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x+0 y-1

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

	[set_variable]
	name=temp_y
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x-1 y+0

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

	[set_variable]
	name=temp_x
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x+1 y+1

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

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

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x+1 y-1

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

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

	[set_variable]
	name=temp_y
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x-1 y+1

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

	[set_variable]
	name=temp_x
	add=-1
	[/set_variable]

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

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

# x-1 y-1

	[set_variable]
	name=temp_x
	value=$water_x
	[/set_variable]

	[set_variable]
	name=temp_y
	value=$water_y
	[/set_variable]

	[set_variable]
	name=temp_x
	add=-1
	[/set_variable]

	[set_variable]
	name=temp_y
	add=-1
	[/set_variable]

	[store_locations]
		x=$temp_x
		y=$temp_y
		terrain=urDnKCRX[]%
		variable=hex_loc
	[/store_locations]

	[set_variable]
	name=temp
	value=$hex_loc.length
	[/set_variable]

	{CLEAR_VARIABLE hex_loc}

	[if]
		[variable]
		name=temp
		numerical_equals=1
		[/variable]

		[then]

		[terrain]
		letter=c
		x,y=$temp_x,$temp_y
		[/terrain]

		[/then]
	[/if]

{NEXT i}

{CLEAR_VARIABLE deepwater_loc}

# 3. change ice to deep water

[store_locations]
	x=1-99
	y=1-99
	radius=1000
	terrain=i
	variable=shallowwater_loc
[/store_locations]

{FOREACH shallowwater_loc i}

[set_variable]
	name=water_x
	to_variable=shallowwater_loc[$i].x
[/set_variable]

[set_variable]
	name=water_y
	to_variable=shallowwater_loc[$i].y
[/set_variable]

[terrain]
	letter=s
	x,y=$water_x,$water_y
[/terrain]

{NEXT i}

{CLEAR_VARIABLE shallowwater_loc}

# 4. kill any unit in deep water, destroy any items in deep water

[store_locations]
	x=1-99
	y=1-99
	radius=1000
	terrain=s
	variable=deepwater_loc
[/store_locations]

{FOREACH deepwater_loc i}

[set_variable]
	name=water_x
	to_variable=deepwater_loc[$i].x
[/set_variable]

[set_variable]
	name=water_y
	to_variable=deepwater_loc[$i].y
[/set_variable]

#destroy any items in deep water
[removeitem]
	x,y=$water_x,$water_y
[/removeitem]

# If unit side is not 3 then kill unit. (side 3is undead who can't drown) 
# Also if unit side is 1 then display death message: "I'm drowning!" 

[store_locations]
	x,y=$water_x,$water_y
	[filter]
		side=1,2,4,5,6,7,8,9
	[/filter]
	variable=victim_side
[/store_locations]

[if]
	[variable]
		name=victim_side.length
		numerical_equals=1
	[/variable]

	[then]
	
	[store_locations]
		x,y=$water_x,$water_y
		[filter]
			side=1
		[/filter]
		variable=victim_side
	[/store_locations]
	
	[if]
		[variable]
			name=victim_side.length
			numerical_equals=1
		[/variable]
		
		[then]

		[message]
			x,y=$water_x,$water_y
			message= _ "Help, I'm drowning!"
		[/message]
		
		[/then]
	[/if]
	
	# if it is a human that drowned, set the flag
	# flag is used for death event of 3 human spelunkers, to display
	# alternate death message if the last of them dies from drowning
	[store_locations]
		x,y=$water_x,$water_y
		[filter]
			side=2
		[/filter]
		variable=victim_side
	[/store_locations]
	
	[if]
		[variable]
			name=victim_side.length
			numerical_equals=1
		[/variable]
		
		[then]

		[set_variable]
			name=human_drowned
			value=1
		[/set_variable]
		
		[/then]
	[/if]
	
	[kill]
		x,y=$water_x,$water_y
		animate=no
		fire_event=yes
	[/kill]

	#clear the flag
	[set_variable]
	name=human_drowned
	value=0
	[/set_variable]
	

	[/then]

[/if]

{NEXT i}

{CLEAR_VARIABLE deepwater_loc}

	[/then]
[/if]

[/event]

# when water reaches escape passage, stop flooding and make it pour out
# into the valley

[event]
name=new turn
first_time_only=no

[store_locations]
x=12
y=18
terrain=cs
variable=hex_loc
[/store_locations]

[set_variable]
	name=temp
	value=$hex_loc.length
[/set_variable]

{CLEAR_VARIABLE hex_loc}

[if]
	[variable]
	name=temp
	numerical_equals=1
	[/variable]

	[then]

	[set_variable]
	name=stop_flooding
	value=1
	[/set_variable]

	# flood rest of side passage with deep water
	[terrain]
	x=12,12,12,12,13,14,15,16,17,18,19,20,21,22,23,23,24,25,25,26
	y=18,17,16,15,15,15,15,14,14,14,14,13,14,13,14,15,15,16,17,17
	letter=s
	[/terrain]

	# create shallow water stream in valley
	[terrain]
	x=27,28,29,30,31,32,33,34,35,35,36,37,38,39,40,41,41,42,42,42,43,43
	y=18,18,18,17,18,17,17,16,16,15,14,14,14,14,14,14,15,13,14,15,13,14
	letter=c
	[/terrain]

	[if]
		[have_unit]
		x=26-50
		y=1-33
		side=1
		[/have_unit]

		[variable]
		name=saw_valley_river
		numerical_equals=0
		[/variable]

		[then]

		[set_variable]
		name=saw_valley_river
		value=1
		[/set_variable]

		[message]
		x=26-50
		y=1-33
		side=1
		message= _ "Look, the water is pouring out the side tunnel into the valley! That's a lot of water: it's even creating a small river. I sure wouldn't want to be downstream of that deluge right now."
		[/message]

		[/then]

		[else]

		[if]
			[have_unit]
			x=21-37
			y=18-33
			side=1
			[/have_unit]

			[variable]
			name=saw_valley_river
			numerical_equals=0
			[/variable]

			[then]

			[set_variable]
			name=saw_valley_river
			value=1
			[/set_variable]

			[message]
			x=21-37
			y=18-33
			side=1
			message= _ "Look, the water is pouring out the side tunnel into the valley! That's a lot of water: it's even creating a small river. I sure wouldn't want to be downstream of that deluge right now."
			[/message]

			[/then]
		[/if]

		[/else]
	[/if]

	[/then]
[/if]

[/event]

# if player didn't see water when it flooded out into the valley
# as soon as he does move a unit out into the valley, comment on it

[event]
name=moveto

[filter]
	x=26-50
	y=1-33
	side=1
[/filter]

[allow_undo]
[/allow_undo]

[if]
	[variable]
	name=stop_flooding
	numerical_equals=1
	[/variable]

	[variable]
	name=saw_valley_river
	numerical_equals=0
	[/variable]

	[then]

	[set_variable]
	name=saw_valley_river
	value=1
	[/set_variable]

	[message]
	speaker=unit
	message= _ "Look, up there in the valley. The water has poured out of the side tunnel and created a small river and lake. I'm glad we weren't downstream of that deluge when the water came rushing out of the tunnel."
	[/message]

	[/then]

[/if]

[/event]


#time over event

[event]
name=time over

[message]
description=Kaleh
message= _ "I can see human reinforcements arriving on the horizon. We'll surely be overwhelmed now! If only we had moved faster."
[/message]

[/event]


#victory event

[event]
name=victory

# reveal map in-between starting valley and location elves move to
[remove_shroud]
x=45-60
y=1-6
side=1
[/remove_shroud]

[teleport]
[filter]
	description=Kaleh
[/filter]
x,y=61,6
[/teleport]

[teleport]
[filter]
	description=Zhul
[/filter]
x,y=63,5
[/teleport]

[teleport]
[filter]
	description=$ally_name
[/filter]
x,y=60,6
[/teleport]

[store_unit]
	[filter]
	description=Nym
	[/filter]
	kill=yes
	variable=Nymstats
[/store_unit]

{FREE_UNIT (Desert Fighter) (Dummy Unit1) ( _ "Dummy Unit1") 1 66 2}
{FREE_UNIT (Desert Fighter) (Dummy Unit2) ( _ "Dummy Unit2") 1 57 3}
{FREE_UNIT (Desert Archer) (Dummy Unit3) ( _ "Dummy Unit3") 1 65 3}
{FREE_UNIT (Desert Archer) (Dummy Unit4) ( _ "Dummy Unit4") 1 59 2}
{FREE_UNIT (Desert Hunter) (Dummy Unit5) ( _ "Dummy Unit5") 1 58 5}
{FREE_UNIT (Desert Shaman) (Dummy Unit6) ( _ "Dummy Unit6") 1 62 2}

[scroll_to_unit]
description=Kaleh
[/scroll_to_unit]

[delay]
time=500
[/delay]

[message]
speaker=narrator
message= _ "Several hours pass..."
[/message]

[move_unit_fake]
type=$Nymstats.type
x=51,52,53,54,55,56,57,57,58,59,60,60
y=1,1,1,1,1,1,1,2,2,2,2,3
[/move_unit_fake]

[set_variable]
name=Nymstats.hitpoints
value=12
[/set_variable]

[unstore_unit]
variable=Nymstats
[/unstore_unit]

{CLEAR_VARIABLE Nymstats}

[teleport]
[filter]
	description=Nym
[/filter]
x,y=60,3
[/teleport]

[message]
speaker=Zhul
message= _ "In Eloh's name, Nym, you look terrible. Are you okay?"
[/message]

[message]
description=Nym
message= _ "Yes. Just...let me...catch...my breath."
[/message]

[delay]
time=100
[/delay]

[move_unit_fake]
type=Merman Netcaster
x=51,52,53,54,55,56,57,58,59,59,60
y=1,1,1,1,2,1,2,2,3,4,4
[/move_unit_fake]

[unit]
type=Merman Netcaster
description=Esanoo
user_description= _ "Esanoo"
profile=portraits/esanoo.png
hitpoints=10
upkeep=loyal
x=60
y=4
side=1
[modifications]
	{TRAIT_LOYAL}
	{TRAIT_RESILIENT}
[/modifications]
[/unit]

[delay]
time=200
[/delay]

[message]
description=Esanoo
message= _ "Water. Sweet water. By the gods, I thought my scales would fall off."
[/message]

[message]
description=Kaleh
message= _ "What in Uria's name is that?"
[/message]

[message]
description=Nym
message= _ "Relax, he's a friend. Just let me explain."
[/message]

[message]
description=Kaleh
message= _ "You're really beat up, Nym. Are you sure you're okay?"
[/message]

[message]
description=Nym
message= _ "I'm fine. But I found someone who really wanted to speak with you."
[/message]

[message]
description=$ally_name
message= _ "He looks like a half-man half-fish."
[/message]

[message]
description=Esanoo
message= _ "Indeed. I come from the ocean, and long have I been looking for you."
[/message]

[message]
description=Kaleh
message= _ "The Ocean? What are you talking about?"
[/message]

[message]
description=Nym
message= _ "Don't try to explain, Esanoo. We'll have to show them instead."
[/message]

[message]
description=Esanoo
message= _ "It's not important. What's important is that I am an emissary from one who much desires to speak with you, Kaleh. Despite the danger, my master sent me and my brethren to scour the dry land searching for you."
[/message]

[message]
description=Zhul
message= _ "There are more of you? Where are the others?"
[/message]

[message]
description=Esanoo
message= _ "They have been captured by the foul humans. I just barely managed to hide and escape, with the help of your friend."
[/message]

[message]
description=Zhul
message= _ "And why should we trust anything you say?"
[/message]

[message]
description=Esanoo
message= _ "My master thought you might be suspicious. She said that what we must talk with you about concerns the fate of your people. Apparently it concerns 'Yechnagoth' and 'Yanqui'. She said that you would understand, Kaleh."
[/message]

[message]
description=Kaleh
message= _ "Hmmmm...yes, yes I think I do. I don't know why, but I trust you."
[/message]

[message]
description=Esanoo
message= _ "Thank you. Now I have a boon to ask of you. Our instructions were to find you and to bring you and your people to meet with my master. The problem is that I don't know where she is hiding."
[/message]

[message]
description=Zhul
message= _ "You don't know where to find your master?"
[/message]

[message]
description=Esanoo
message= _ "It's complicated, and I don't know how much I am allowed to tell you. My people are fighting a desperate war against...against a powerful foe. Many times our enemy has tried to assassinate my master. My master worried that her presence was a danger to the rest of my kind. So right after she sent us on our mission she went into hiding. I am the youngest member of our group, and so I wasn't told the location. You must understand, there are spies everywhere. Only the leaders of our group knew, but the rest of them were all captured by those foul humans. They are being held in the settlement to the north. If we are to have any chance of finding my master, we must first rescue them. I would do it myself, but..."
[/message]

[message]
description=Nym
message= _ "It would be suicide for you to try to rescue them alone. Of course we will help you."
[/message]

[message]
description=Esanoo
message= _ "Thank you. I am not very good at fighting on the dry ground."
[/message]

[message]
description=Kaleh
message= _ "All the other scouting parties have returned, except for one. Tanstafaal and his scouts haven't reported back yet. I'm starting to get worried."
[/message]

[message]
description=Nym
message= _ "They were sent due north. From Esanoo's description it sounds like they were headed right for the human settlement. I hope nothing bad has happened to them."
[/message]

[message]
description=Kaleh
message= _ "Things are coming to a head. I'm worried about Tanstafaal and your merfolk friends. Time is of the essence, so let's move out as soon as possible."
[/message]

[kill]
description=Dummy Unit1
animate=no
[/kill]
[kill]
description=Dummy Unit2
animate=no
[/kill]
[kill]
description=Dummy Unit3
animate=no
[/kill]
[kill]
description=Dummy Unit4
animate=no
[/kill]
[kill]
description=Dummy Unit5
animate=no
[/kill]
[kill]
description=Dummy Unit6
animate=no
[/kill]

{CLEAR_VARIABLE type_of_sealife}
{CLEAR_VARIABLE humans_killed}
{CLEAR_VARIABLE human_drowned}
{CLEAR_VARIABLE entered_training_hall}
{CLEAR_VARIABLE broke_circle}

# the three undead trainees
{CLEAR_VARIABLE	iona_dead}
{CLEAR_VARIABLE	pior_dead}
{CLEAR_VARIABLE	jarl_dead}

{CLEAR_VARIABLE entered_temple}
{CLEAR_VARIABLE pulled_lever}
{CLEAR_VARIABLE ally_conversation}
{CLEAR_VARIABLE pissed_off_durtarg}
{CLEAR_VARIABLE start_messenger_timer}
{CLEAR_VARIABLE messenger_timer}
{CLEAR_VARIABLE loc_x}
{CLEAR_VARIABLE loc_y}
{CLEAR_VARIABLE undead_emissary}
{CLEAR_VARIABLE stop_flooding}
{CLEAR_VARIABLE human_conversation}
{CLEAR_VARIABLE saw_valley_river}

[/event]


# set time for all underground areas to be always night/underground

	#bottom half of map (from, y=34 downwards)
	[time_area]
		x=1-80
		y=34-60
		{UNDERGROUND}
	[/time_area]

	#Cave walls on eastern side of valley
	[time_area]
		x=46-80
		y=33
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=47-80
		y=32
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=48-80
		y=31
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=50-80
		y=30
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=51-80
		y=29
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=52-80
		y=28
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=54-80
		y=26-27
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=56-80
		y=21-25
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=57-80
		y=19-20
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=56-80
		y=18
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=55-80
		y=17
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=51
		y=17
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=49-80
		y=14-16
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=48-80
		y=12-13
		{UNDERGROUND}
	[/time_area]

	# eastern cave walls splits into two parts as we go father north
	# from y=11 downwards

	# western point:

	[time_area]
		x=48-58
		y=11
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=60
		y=11
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=48-56
		y=10
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=49-54
		y=9
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=50-54
		y=8
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=51-54
		y=7
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=52-53
		y=6
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=52
		y=5
		{UNDERGROUND}
	[/time_area]

	# eastern slope:

	[time_area]
		x=62-80
		y=11
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=64-80
		y=10
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=66-80
		y=9
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=68-80
		y=8
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=70-80
		y=6-7
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=72-80
		y=5
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=74-80
		y=4
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=76-80
		y=2-3
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=78-80
		y=1
		{UNDERGROUND}
	[/time_area]

	# North Western half of underground area (from y=33 upwards)

	[time_area]
		x=1-42
		y=33
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=40,38
		y=32,32
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-36
		y=32
		{UNDERGROUND}
	[/time_area]

	#little point in cave wall at SW cave wall in valley
	[time_area]
		x=32-34
		y=31
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-28
		y=31
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-27
		y=30
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-26
		y=29
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-24
		y=28
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-22
		y=27
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-20
		y=26
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-19
		y=23-25
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-20
		y=22
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-21
		y=22
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-23
		y=21
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-25
		y=19-20
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-26
		y=18
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-27
		y=16-17
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-26
		y=14-15
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-25
		y=11-13
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=1-27
		y=9-10
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=2-26
		y=8
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=4-24
		y=7
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=10-16
		y=6
		{UNDERGROUND}
	[/time_area]

	[time_area]
		x=12,14
		y=5,5
		{UNDERGROUND}
	[/time_area]

# deaths2.cfg differs from deaths.cfg becuase the former contains the
# death event for the troll/dwarf ally

{@campaigns/Under_the_Burning_Suns/utils/deaths2.cfg}

[/scenario]
