# Level 6.1: Hunting Trolls

# coordinate shift
# x: -16 y: -69

[scenario]
#textdomain wesnoth-utbs

id="6_1_HuntingTrolls"
name= _ "In the Tunnels of the Trolls"
label= _ "In the Tunnels of the Trolls"

map_data="{campaigns/Under_the_Burning_Suns/maps/6_1TrollMission5.map}"

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

next_scenario=7_1_DwarfInterlude

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

#max turns in scenario varies depending on difficulty
#ifdef EASY
turns="62"
#endif
#ifdef MEDIUM
turns="58"
#endif
#ifdef HARD
turns="56"
#endif

victory_when_enemies_defeated=no

{UNDERGROUND}

#Elf player

[side]
	side=1
	description=Kaleh
	type=Desert Fighter
	canrecruit=1
	{INCOME 5 3 1}
	controller=human
	recruit=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
	shroud=yes
	fog=no
	team_name=dwarf_ally
[/side]

#Side=2 dwarf 1 (dwarf allies)
[side]
	side=2
	colour=7
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=dwarf_ally
[/side]

#Side=3 troll 1 (advance guard trolls at outpost)
[side]
	side=3
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=monster

	#ifdef EASY
	recruit=Troll Whelp, Troll
	#endif

	#ifdef MEDIUM
	recruit=Troll Whelp, Troll, Troll Rocklobber
	#endif

	#ifdef HARD
	recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman
	#endif

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

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

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

		# 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.6
	[/ai]
[/side]

#Side=4 empty side
[side]
	side=4
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
[/side]

#Side=5 empty side
[side]
	side=5
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
[/side]

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

#Side=7 troll 2 (elite trolls in main lair)
[side]
	side=7
	colour=6
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=monster

	#ifdef EASY
	recruit=Troll Whelp, Troll, Troll Rocklobber
	#endif

	#ifdef MEDIUM
	recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman
	#endif

	#ifdef HARD
	recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman
	#endif

	[ai]
		recruitment_pattern=fighter,archer,fighter,mixed fighter

		# 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.6
	[/ai]
[/side]

#Side=8 fire guardians (white)
[side]
	side=8
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=monster

	#ifdef EASY
	recruit=Vampire Bat2, Blood Bat2
	#endif

	#ifdef MEDIUM
	recruit=Vampire Bat2, Blood Bat2, Dread Bat
	#endif

	#ifdef HARD
	recruit=Vampire Bat2, Blood Bat2, Dread Bat
	#endif

	[ai]
		aggression=0.9
		caution=0.1

		village_value=0

		# 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}

		#fire guardians can't leave lava cavern
		[avoid]
		x,y=39-46,77-81
		[/avoid]

		[avoid]
		x,y=30-34,92-100
		[/avoid]
	[/ai]
[/side]

[story]
	[part]
	story= _ "Chapter 6: The dwarf Grendel led us through a maze of twisting passages speaking scarcely a word. Finally, after what seemed like hours of marching, he stopped. He motioned us to be very quiet and we crept forward; all I could hear was the soft patter of feet and my heavy breathing. Even that little noise seemed to echo off the cramped walls of our rough-hewn passage. I was suddenly aware of the sheer mass of rock and earth above us and for a moment I despaired of ever seeing the sun again. Then I grabbed my sword with fresh determination and vowed to see this mission through."
	[/part]

[/story]


# Prestart functions:
# set starting scenario objectives
# increase cost of recruiting units
# place item images on map
# recall main heroes
# initialize starting variables
# remove keep
# create elf units
# create AI=guardian starting units

[event]
name=prestart

# test units

#{UNIT_ (Dwarvish Fighter) (Test) ( _ "Test") 1 23 7}

#set starting scenario objectives

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


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

		[variable]
		name=scen3
		numerical_equals=2
		[/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]

		[else]

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

			[then]

			#go from 2 to 3

			[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]

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

			[/then]
		[/if]

		[if]
			[variable]
			name=scen3
			numerical_equals=3
			[/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]
		[/if]

		[/else]
	[/if]

	#secret troll tomb furnishings
	{PLACE_IMAGE items/coffin2.png 3 28}
	{PLACE_IMAGE items/bones.png 6 24}

	#troll burial grounds furnishings

	{PLACE_IMAGE items/burial.png 36 28}
	{PLACE_IMAGE items/burial.png 33 25}
	{PLACE_IMAGE items/burial.png 40 23}

	{PLACE_IMAGE items/bonestack.png 37 23}
	{PLACE_IMAGE items/bonestack.png 39 27}

	{PLACE_IMAGE scenery/monolith1.png 34 25}
	{PLACE_IMAGE scenery/monolith4.png 34 27}

	#other furnishings

	{PLACE_IMAGE items/bones.png 14 12}

	#recall heroes
	[recall]
	description=Nym
	[/recall]
	[recall]
	description=Zhul
	[/recall]
	[recall]
	description=Elyssa
	[/recall]

	#initialize starting variables

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

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

	# damage done by sanding in lava used to be
	# 30 hp at Challenging and Hard difficulty

	[set_variable]
	name=lava_damage
	value=-25
	[/set_variable]

	# heat damage by just standing in the lava cavern

	#ifdef EASY
	[set_variable]
	name=heat_damage
	value=-2
	[/set_variable]
	#endif

	#ifdef MEDIUM
	[set_variable]
	name=heat_damage
	value=-3
	[/set_variable]
	#endif

	#ifdef HARD
	[set_variable]
	name=heat_damage
	value=-4
	[/set_variable]
	#endif

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

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

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

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

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

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

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

	# create AI=guardian units. They can't move unless an enemy
	# moves nearby. I create them at the beginning because when the
	# player sees them, events will fire.

	[unit]
	type=Dwarvish Pathfinder
	description=Grendel
	user_description= _ "Grendel"
	x=7
	y=6
	side=2
	ai_special=guardian
	[modifications]
		{TRAIT_STRONG}
		{TRAIT_RESILIENT}
	[/modifications]
	[/unit]

	# Event 2.1
	#Troll interrogators guardian

	[unit]
	type=Troll
	description=Troll Interrogator
	user_description= _ "Troll Interrogator"
	x=34
	y=5
	side=3
	ai_special=guardian
	[modifications]
		{TRAIT_STRONG}
		{TRAIT_INTELLIGENT}
	[/modifications]
	[/unit]

	[unit]
	type=Troll Whelp
	description=Troll Assistant
	user_description= _ "Troll Assistant"
	x=32
	y=5
	side=3
	ai_special=guardian
	[modifications]
		{TRAIT_RESILIENT}
		{TRAIT_LOYAL}
	[/modifications]
	[/unit]

	[unit]
	type=Troll Whelp
	description=Ulg
	user_description= _ "Ulg"
	x=33
	y=7
	side=3
	ai_special=guardian
	[modifications]
		{TRAIT_STRONG}
		{TRAIT_LOYAL}
	[/modifications]
	[/unit]

	#ifdef HARD
	[unit]
	type=Troll Whelp
	description=Troll Assistant
	user_description= _ "Troll Assistant"
	x=31
	y=4
	side=3
	ai_special=guardian
	[modifications]
		{TRAIT_STRONG}
		{TRAIT_RESILIENT}
	[/modifications]
	[/unit]
	#endif

	# Event 3: Troll High Shamans guarding lava maze

	[unit]
		type=Troll Shaman
		description=Troll High Shaman
		user_description= _ "Troll High Shaman"
		x=16
		y=22
		side=7
		ai_special=guardian
		[modifications]
			{TRAIT_INTELLIGENT}
			{TRAIT_LOYAL}
		[/modifications]
	[/unit]

	[unit]
		type=Troll Shaman
		description=Troll High Shaman
		user_description= _ "Troll High Shaman"
		x=18
		y=23
		side=7
		ai_special=guardian
		[modifications]
			{TRAIT_RESILIENT}
			{TRAIT_LOYAL}
		[/modifications]
	[/unit]

	# reveal a bit of the escape passage to the player
	[remove_shroud]
	x,y=5-8,4-6
	side=1
	[/remove_shroud]

[/event]

# starting events

[event]
name=start

# starting dialogue

[message]
description=Grendel
message= _ "This passage leads very close to the trolls' main lair; you can hear them tromping back and forth just past the eastern wall. All that separates us from the trolls is a thin wall of stone. I've had me boys mine the end of the tunnel with explosives; when you move a unit adjacent to the final wall, I'll blow the charges and open the way. The troll leader should only be lightly defended; he's sent most of his best warriors to the front. You'll know the head troll when you see him, he's big, green and extra ugly."
[/message]

[message]
description=Nym
message= _ "I thought that's what all the trolls looked like. I suppose we'll just try to find the one that shouts the loudest."
[/message]

[message]
description=Zhul
message= _ "So you dug these tunnels all by yourselves?"
[/message]

[message]
description=Grendel
message= _ "Long ago, before the damned trolls invaded, we spent our days digging tunnels all through these mountains. Oh the ore and precious stones we mined! The mines were filled with the joyful sound of dwarven hammer and dwarven song and our jeweled halls glowed as brightly as the sun. Human and elf princes would pay us royally for the craftsmanship of our forges. But now the tunnels are silent and we spend our days hunting those accursed trolls. But there's no point dwelling on the past. There's more work to be done! Still, we have our honor and I promise you, do this for us and you will be rewarded handsomely."
[/message]

[message]
description=Kaleh
message= _ "It shall be done."
[/message]

[/event]

# Event 1: Blow up wall, encounter advance troll guards

# when player moves next wall trigger variable
[event]
name=moveto

[filter]
x,y=15,7
side=1
[/filter]

[message]
description=Grendel
message= _ "Once you are done moving your people into position, I will blow the charges."
[/message]

[set_variable]
name=destroy_wall
value=1
[/set_variable]
[/event]

# at start of player's next turn, blow charges and destroy wall

[event]
name=new turn
first_time_only=no

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

	[then]

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

	# Modify troll's income

	[modify_side]
		side=3

		#ifdef EASY
		income=10
		gold=75
		#endif
		#ifdef MEDIUM
		income=12
		gold=100
		#endif
		#ifdef HARD
		income=14
		gold=125
		#endif
	[/modify_side]

	# Place troll guards

	# EASY:  1 Troll Leader, 2 troll whelps, 1 rocklobber
	# MEDIUM: 1 Troll Leader, 3 troll whelps, 1 rocklobber
	# HARD: 1 Troll Leader, 3 troll whelps, 1 rocklobber, 1 troll

	# 1 Troll Leader
	[unit]
	description=Troll Brute
	user_description= _ "Troll Brute"
	type=Troll
	x=23
	y=9
	side=3
	canrecruit=1
	upkeep=free
	[modifications]
		{TRAIT_STRONG}
		{TRAIT_RESILIENT}
	[/modifications]
	[/unit]

	# 1 Troll Rocklobber
	{UNIT_ (Troll Rocklobber) (Troll Guard) ( _ "Troll Guard") 3 23 8}

	# 0-1 extra Trolls
	{UNIT_ (Troll) (Troll Guard) ( _ "Troll Guard") 3 21 9}

	# 2-3 troll whelps occupy base and villages
	# 2 troll whelps in villages
	{UNIT_ (Troll Whelp) (Troll Guard) ( _ "Troll Guard") 3 21 5}
	{UNIT_ (Troll Whelp) (Troll Guard) ( _ "Troll Guard") 3 23 6}

	#ifdef EASY
	#else
	{UNIT_ (Troll Whelp) (Troll Guard) ( _ "Troll Guard") 3 21 19}
	#endif

	# Have Grendel blow the explosives to destroy the wall

	[message]
		description=Grendel
		message= _ "Fire in the hole!"
	[/message]

	# Have screen flash red

	[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]

	# Have wall shake, then be replaced by dirt, then add rubble

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

	[terrain]
	x,y=16,7
	letter=Re
	[/terrain]

	{PLACE_IMAGE scenery/rubble.png 16 7}

	# Reveal dwarven cavern
	[remove_shroud]
	x=16-25
	y=3-10
	side=1
	[/remove_shroud]

	# Have Grendel say goodbye

	[message]
		description=Grendel
		message= _ "My work here is done. I must report back to my King. I have many more things to do before the day is done, but I will once you finish your mission. Fight well!"
	[/message]

	# Have him leave
	[kill]
	description=Grendel
	animate=no
	fire_event=no
	[/kill]

	[move_unit_fake]
	type=Dwarvish Pathfinder
	x=7,6,5,4,3,2,1
	y=6,5,5,4,5,4,4
	[/move_unit_fake]

	[terrain]
	x,y=1,4
	letter=Xu
	[/terrain]

	{PLACE_IMAGE scenery/rubble.png 2 4}

	# Have troll guards talk

	[message]
	description=Troll Guard
	message= _ "Intruders! Kill them!"
	[/message]

	[/then]
[/if]

[/event]

# Event 2: If player tries to go back up escape passage
# This event is disabled becuase player can go back up escape passage
# before he triggers Event 1 and ally leaves. Thus you could trap
# a unit behind the cave-in. Since this event is just for flavor,
# I'm disabling it.

#[event]
#name=moveto

#[filter]
#	x=2-5,4-5
#	side=1
#[/filter]

#[message]
#speaker=unit
#message= _ "Grendel must have collapsed the tunnel. Perhaps he didn't want to #give the trolls an easy access route if they defeated us. So much an an escape #route, I guess we'll just have to be sure not to fail."
#[/message]

#[/event]

# Event 2.1: Troll Interrogators

# When player appears 3 trolls are interrogating a wounded dwarf
# When they see the player they kill the dwarf. The other says
# "The prisoners must not be allowed to escape. Kill the other prisoner
# while we hold them off!"

# Troll and Troll whelp try to hold off player

# I create trolls well in advance of player entering cave
# this makes sure that player can't move into trolls hexes
# I am forced to make trolls into guardians to keep them
# from moving prematurely


# Moveto version (sighted version is disabled)

[event]
name=moveto

[filter]
	x=27-35
	y=3-8
	side=1
[/filter]

[remove_shroud]
	x=28-35
	y=3-9
	side=1
[/remove_shroud]

[unit]
	type=Dwarvish Fighter
	description=Wounded Dwarf
	user_description= _ "Wounded Dwarf"
	x=33
	y=6
	side=2
	hitpoints=5
[/unit]

[message]
	description=Troll Interrogator
	message= _ "Tell us where your leader is hiding!"
[/message]

[message]
	description=Wounded Dwarf
	message= _ "Never!"
[/message]

[message]
	description=Troll Assistant
	message= _ "Master, look!"
[/message]

[message]
	description=Troll Interrogator
	message= _ "Hah! You think you can save your friends. You are wrong. Ulg, go kill the other prisoner. We will deal with these fools."
[/message]

[message]
	description=Ulg
	message= _ "Yes master, I'll make him suffer."
[/message]

[teleport]
	[filter]
		description=Ulg
	[/filter]
	x,y=40,4
[/teleport]

[move_unit_fake]
	type=Troll Whelp
	x=15,14,13,12,11,10
	y=48,48,48,47,47,46
[/move_unit_fake]

[hide_unit]
	description=Troll Interrogator
[/hide_unit]

[redraw]
[/redraw]

{PLACE_IMAGE units/trolls/grunt-attack-1.png 34 5}

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

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

[unhide_unit]
[/unhide_unit]

[message]
	description=Wounded Dwarf
	message= _ "Aaahhhh!"
[/message]

[kill]
	description=Wounded Dwarf
	animate=yes
[/kill]

[message]
	speaker=unit
	message= _ "If we move fast we might be able to save the other prisoner before he gets killed too."
[/message]

[/event]


# Event 2.2: Wounded Dwarf

# Troll whelp tries to kill wounded Dwarvish Stalwart

# (sighted version is disabled)

[event]
name=moveto

[filter]
	x=35-41
	y=4-7
	side=1
[/filter]

[remove_shroud]
	x=34-42
	y=4-8
	side=1
[/remove_shroud]

[unit]
	type=Dwarvish Stalwart
	description=Rogrimir
	user_description= _ "Rogrimir"
	profile=portraits/rogrimir.png
	x=41
	y=4
	side=2
	hitpoints=20
	[modifications]
		{TRAIT_RESILIENT}
		{TRAIT_QUICK}
	[/modifications]
[/unit]

[message]
	description=Ulg
	message= _ "I'm gonna make you squeal, dwarf!"
[/message]

[/event]

# when Ulg dies, Rogrimir thanks player

[event]
name=die

[filter]
description=Ulg
[/filter]

[kill]
description=Ulg
animate=no
[/kill]

[message]
description=Rogrimir
message= _ "I owe you my life. I can't believe I was captured when those all around me died fighting gloriously. I'm so ashamed. I could not protect them....but I will guard you with my life, even if I have to follow you to the ends of the earth. Now lead me to the trolls and let me avenge my friends' deaths!"
[/message]

[store_unit]
[filter]
	description=Rogrimir
[/filter]

variable=dwarfstats
[/store_unit]

[set_variable]
name=dwarfstats.side
value=1
[/set_variable]

[set_variable]
name=dwarfstats.moves
value=5
[/set_variable]

[unstore_unit]
variable=dwarfstats
[/unstore_unit]

{CLEAR_VARIABLE dwarfstats}

[/event]



# Event 3: Troll Lava Maze

# lava is ironically an alias of snow. Elves take 3 moves to cross it,
# except for mounted elves which take 4 (horses hate lava). Thus
# ensuring that no elf can move more than 2 hexes on lava
# with the exception of the desert shyde/star which can move 3 hexes

# At the start of each turn, all units except the Desert Shyde/Star standing
# on a lava hex take 25 damage. This damage can kill units.

[event]
name=new turn
first_time_only=no

	[redraw]
	[/redraw]

	[store_locations]
	x=1-33
	y=11-27
	terrain=Yl
		[filter]
		side=1,3,7
		[not]
			type=Zhul Shyde,Zhul Star,Desert Shyde,Desert Star
		[/not]
		[/filter]
	variable=locs
	[/store_locations]

	{FOREACH locs i}

	[set_variable]
		name=temp_x
		to_variable=locs[$i].x
	[/set_variable]

	[set_variable]
		name=temp_y
		to_variable=locs[$i].y
	[/set_variable]

	[store_unit]
		[filter]
		x,y=$temp_x,$temp_y
		[/filter]
	variable=unitstats
	[/store_unit]

	# this code makes sure Kaleh stays unslowed
	[if]
		[variable]
		name=unslow_kaleh
		numerical_equals=1
		[/variable]

		[variable]
		name=unitstats.description
		equals=Kaleh
		[/variable]

		[then]

		[set_variable]
		name=unitstats.status.slowed
		value="off"
		[/set_variable]

		[/then]
	[/if]

	[set_variable]
		name=unitstats.hitpoints
		add=$lava_damage
	[/set_variable]

	[set_variable]
    name=damage_msg
    format=$lava_damage
    [/set_variable]

    [set_variable]
    name=damage_msg
    multiply=-1
    [/set_variable]

	# if unitstats.hitpoints is < 1, unstore unit and kill it,
	# else just unstore it

	[if]
		[variable]
		name=unitstats.hitpoints
		less_than=1
		[/variable]

		[then]

		[unstore_unit]
		variable=unitstats
		text=$damage_msg
		{COLOR_HARM}
		[/unstore_unit]

		[kill]
		x,y=$temp_x,$temp_y
		fire_event=yes
		animate=yes
		[/kill]

		[/then]

		[else]

		[unstore_unit]
		variable=unitstats
		text=$damage_msg
		{COLOR_HARM}
		[/unstore_unit]

		[/else]

	[/if]

	{CLEAR_VARIABLE unitstats}

	{NEXT i}

	{CLEAR_VARIABLE locs}
	{CLEAR_VARIABLE damage_msg}

[/event]


# At the start of each turn, all units in main cavern standing on a cave
# floor hex, or lava hex, or a dirt hex or a road hex take 3,4,5 damage
# from the heat. This damage is non-lethal.

[event]
name=new turn
first_time_only=no

	[redraw]
	[/redraw]

	[store_locations]
	x=15-32,23-29,12-16
	y=12-24,25-26,15-22
	terrain=Uu, Re, Rr, Uh, Uu^Uf
		[filter]
		side=1
		[/filter]
	variable=locs
	[/store_locations]

	{FOREACH locs i}

	[set_variable]
		name=temp_x
		to_variable=locs[$i].x
	[/set_variable]

	[set_variable]
		name=temp_y
		to_variable=locs[$i].y
	[/set_variable]

	[store_unit]
		[filter]
		x,y=$temp_x,$temp_y
		[/filter]
	variable=unitstats
	[/store_unit]

	# this code makes sure Kaleh stays unslowed
	[if]
		[variable]
		name=unslow_kaleh
		numerical_equals=1
		[/variable]

		[variable]
		name=unitstats.description
		equals=Kaleh
		[/variable]

		[then]

		[set_variable]
		name=unitstats.status.slowed
		value="off"
		[/set_variable]

		[/then]
	[/if]

	[set_variable]
	name=unitstats.hitpoints
	add=$heat_damage
	[/set_variable]

	[set_variable]
    name=damage_msg
    format=$heat_damage
    [/set_variable]

    [set_variable]
    name=damage_msg
    multiply=-1
    [/set_variable]


	#if unitstats.hitpoints is < 1, then set hitpoints to 1
	[if]
		[variable]
		name=unitstats.hitpoints
		less_than=1
		[/variable]

		[then]

		[set_variable]
		name=unitstats.hitpoints
		value=1
		[/set_variable]

		[/then]
	[/if]

	[unstore_unit]
		text=$damage_msg
		{COLOR_HARM}
		variable=unitstats
	[/unstore_unit]

	{CLEAR_VARIABLE unitstats}

	{NEXT i}

	{CLEAR_VARIABLE locs}
	{CLEAR_VARIABLE damage_msg}

[/event]


#Initial moveto event to enter lava cavern

[event]
name=moveto

[filter]
x,y=22-30,10-20
side=1
[/filter]

[remove_shroud]
x=11-33
y=11-24
side=1
[/remove_shroud]

[remove_shroud]
x=20-29
y=23-27
side=1
[/remove_shroud]

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

[place_shroud]
x=13-14
y=11-13
side=1
[/place_shroud]

[place_shroud]
x=11-12
y=26-27
side=1
[/place_shroud]

[set_variable]
name=temp_damage
value=$heat_damage
[/set_variable]

[set_variable]
name=temp_damage
multiply=-1
[/set_variable]

[object]
	id=ImmobilizeShamans
	silent=yes

	[effect]
	apply_to=movement
	set=0
	[/effect]

	[filter]
	description=Troll High Shaman
	[/filter]

[/object]

[redraw]
[/redraw]

[message]
speaker=unit
message= _ "Woah. This place is hot."
[/message]

[message]
speaker=unit
message= _ "This cavern is so hot it's stifling; I can already feel my armor heating up. If we tarry here too long we'll roast alive. I don't even want to think about what would happen if I tried to walk across the lava. On the other hand, the lava does light up the cavern nicely. I'm just thankful the trolls constructed a bridge across the lava."
[/message]

[message]
description=Troll High Shaman
message= _ "They have broken through the outer guardpost. Destroy the bridge, they must not pass!"
[/message]

# Have screen flash red

[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]

# Have screen shake, then destroy most of bridge

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

[terrain]
x=16,17,18,18,19,19,20,20,21,22,22,23,23,23,24,24,24
y=20,22,20,19,20,19,19,17,17,17,16,17,16,15,16,15,14
letter=Yl
[/terrain]

[kill]
description=Thrud
animate=yes
fire_event=no
[/kill]

[message]
speaker=unit
message= _ "Uh, I take that back. Still, the trolls don't seem to be advancing. I guess they think the lava can hold us back. Well, we'll show them. It will take more than a little heat to stop us!"
[/message]

[message]
speaker=narrator
message= _ "Any unit that ends its turn on a lava hex, except the Desert Shyde and Star who can fly over the lava, will take 25 damage at the beginning of the next turn. This lava damage can kill units. Desert Shydes and Stars will just take $temp_damage damage per turn when flying over lava, though they too can die if they spend too much time over lava. Also because of the heat in the cavern, all units on cave floor hexes will take $temp_damage damage at the start of each turn. This heat damage can reduce a unit to 1 hit point, but it can't kill it. "
[/message]

{CLEAR_VARIABLE temp_damage}

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

[set_variable]
name=flame_counter
value=5
[/set_variable]

[/event]


# pool of water lets player heal halfway

[event]
name=moveto

[filter]
x,y=22,26
side=1
[/filter]

[set_variable]
name=temp_damage
value=$heat_damage
[/set_variable]

[set_variable]
name=temp_damage
multiply=-1
[/set_variable]

[message]
speaker=unit
message= _ "There is a small pool of water here. It must come from some spring deep underground. The water is cool and refreshing. Let me bathe in it a while and recover from the heat of that blasted cavern."
[/message]

[message]
speaker=narrator
message= _ "At the start of each turn, any unit currently in this pool will heal 10 hitpoints and will not be affected by the heat in the cavern. Of course, if the unit leaves this pool, it will suffer the standard $temp_damage damage each turn from the heat."
[/message]

{CLEAR_VARIABLE temp_damage}

[/event]

# unit heals 10 hp a turn

[event]
name=new turn
first_time_only=no

[object]
	[filter]
		x,y=22,26
	[/filter]

	silent=yes
	duration="level"

	[effect]
	apply_to="hitpoints"
	increase=10
	[/effect]
[/object]

[/event]

# This function fires each turn and checks to see if it should summon
# a "Fire Pheonix" fire guardian, based on the value of the summon_flame
# variable and on the value of the flame_counter

# when the fire guardian unit dies, the flame_counter is reset to 0

# each turn flame_counter is incremented until it reached 4 (on hard
# difficulty) or 5, then a new fire guardian is summoned and
# summon_flame is turned back to 0.

# summon_flame=0: fire guardian has been created, is alive, don't create another
# summon_flame=1: fire guardian has been killed, create another
# summon_flame=2: create fire guardian for first time, elves are amazed
# summon_flame=3: player has reached troll shamans, stop summoning fire guardians

[event]
name=new turn
first_time_only=no

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

[if]

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

	#ifdef HARD
	[variable]
	name=flame_counter
	greater_than=3
	[/variable]
	#else
	[variable]
	name=flame_counter
	greater_than=4
	[/variable]
	#endif

	[then]

	[message]
	description=Troll High Shaman
	message= _ "Arise! Arise and engulf the intruders in your holy fire!"
	[/message]

	[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]

	#ifdef EASY
	{UNIT_ (Lava Monster) (Guardian Phoenix) ( _ "Guardian Phoenix") 8 26 21}
	#endif

	#ifdef MEDIUM
	{UNIT_ (Lava Monster2) (Guardian Phoenix) ( _ "Guardian Phoenix") 8 26 21}
	#endif

	#ifdef HARD
	{UNIT_ (Lava Monster3) (Guardian Phoenix) ( _ "Guardian Phoenix") 8 26 21}
	#endif

	[scroll_to_unit]
	x,y=26,21
	[/scroll_to_unit]

	[delay]
	time=250
	[/delay]

	[message]
	side=1
	x,y=16-29,11-23
	message= _ "What the heck is that? It sure doesn't look good. The last thing we need in here is even more fire."
	[/message]

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

	[/then]

	[else]

	[if]

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

		#ifdef HARD
		[variable]
		name=flame_counter
		greater_than=3
		[/variable]
		#else
		[variable]
		name=flame_counter
		greater_than=4
		[/variable]
		#endif

		[then]

		[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]

		#ifdef EASY
		{UNIT_ (Lava Monster) (Guardian Phoenix) ( _ "Guardian Phoenix") 8 26 21}
		#endif

		#ifdef MEDIUM
		{UNIT_ (Lava Monster2) (Guardian Phoenix) ( _ "Guardian Phoenix") 8 26 21}
		#endif

		#ifdef HARD
		{UNIT_ (Lava Monster3) (Guardian Phoenix) ( _ "Guardian Phoenix") 8 26 21}
		#endif

		[scroll_to_unit]
		x,y=42,90
		[/scroll_to_unit]

		[delay]
		time=250
		[/delay]

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

		[message]
		side=1
		x,y=16-29,11-23
		message= _ "That thing just won't stay dead!"
		[/message]

		[/then]
	[/if]

	[/else]
[/if]

[/event]

# when fire guardian dies, switch summon_flame back to 1
# and reset flame_counter back to 0

[event]
name=die
first_time_only=no

[filter]
	description=Guardian Phoenix
[/filter]

[if]
	[variable]
	name=summon_flame
	less_than=3
	[/variable]

	[then]

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

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

	[/then]
[/if]

[/event]


# Troll shamans raise more Fire Guardians out of the lava

# Lava monster 1: y=18
# Lava monster 2: y=25
# Lava monster 3: x=20-21 y=18-19

[event]
name=moveto

[filter]
x=11-32
y=18-25
side=1
[/filter]

[if]
	[variable]
	name=summon_flame
	numerical_not_equals=3
	[/variable]

	[then]

	[message]
	description=Troll High Shaman
	message= _ "Arise, hallowed guardians, and destroy them!"
	[/message]

	[scroll_to]
	x,y=26,17
	[/scroll_to]

	#ifdef EASY
	{UNIT_ (Lava Monster) (Fire Guardian) ( _ "Fire Guardian") 8 26 17}
	{UNIT_ (Lava Monster) (Fire Guardian) ( _ "Fire Guardian") 8 26 18}
	#endif

	#ifdef MEDIUM
	{UNIT_ (Lava Monster2) (Fire Guardian) ( _ "Fire Guardian") 8 26 17}
	{UNIT_ (Lava Monster2) (Fire Guardian) ( _ "Fire Guardian") 8 26 18}
	#endif

	#ifdef HARD
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 25 18}
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 26 17}
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 26 18}
	#endif

	[message]
	speaker=unit
	message= _ "Look, more fire guardians!"
	[/message]

	[/then]
[/if]

[/event]

[event]
name=moveto

[filter]
x=23-29
y=25-26
side=1
[/filter]

[if]
	[variable]
	name=summon_flame
	numerical_not_equals=3
	[/variable]

	[then]

	[message]
	description=Troll High Shaman
	message= _ "Arise and attack them now, while they are vulnerable!"
	[/message]

	[scroll_to]
	x,y=42,91
	[/scroll_to]

	#ifdef EASY
	{UNIT_ (Lava Monster) (Fire Guardian) ( _ "Fire Guardian") 8 26 22}
	{UNIT_ (Lava Monster) (Fire Guardian) ( _ "Fire Guardian") 8 27 22}
	#endif

	#ifdef MEDIUM
	{UNIT_ (Lava Monster2) (Fire Guardian) ( _ "Fire Guardian") 8 26 22}
	{UNIT_ (Lava Monster2) (Fire Guardian) ( _ "Fire Guardian") 8 27 22}
	#endif

	#ifdef HARD
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 26 21}
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 26 22}
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 27 22}
	#endif

	[message]
	speaker=unit
	message= _ "Oh great, even more fire guardians. When I get through this inferno I'm going to kill those trolls."
	[/message]

	[/then]
[/if]

[/event]

[event]
name=moveto

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

[if]
	[variable]
	name=summon_flame
	numerical_not_equals=3
	[/variable]

	[then]

	[message]
	description=Troll High Shaman
	message= _ "They must not be allowed to cross to the other side! Kill them!"
	[/message]

	[scroll_to]
	x,y=22,16
	[/scroll_to]

	#ifdef EASY
	{UNIT_ (Lava Monster) (Fire Guardian) ( _ "Fire Guardian") 8 22 16}
	{UNIT_ (Lava Monster) (Fire Guardian) ( _ "Fire Guardian") 8 23 17}
	#endif

	#ifdef MEDIUM
	{UNIT_ (Lava Monster2) (Fire Guardian) ( _ "Fire Guardian") 8 22 16}
	{UNIT_ (Lava Monster2) (Fire Guardian) ( _ "Fire Guardian") 8 23 17}
	#endif

	#ifdef HARD
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 23 17}
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 22 16}
	{UNIT_ (Lava Monster3) (Fire Guardian) ( _ "Fire Guardian") 8 22 17}
	#endif

	[message]
	speaker=unit
	message= _ "How surprising, more fire guardians. I'm going to be really glad to get out of this cavern."
	[/message]

	[/then]
[/if]

[/event]

#at end of lava cavern, trolls come alive
[event]
name=moveto

[filter]
x=17-18,13-21
y=18-19,20-28
side=1
[/filter]

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

[message]
x,y=18,23
message= _  "Despite the fire guardians, the elves have almost crossed the lava!"
[/message]

[message]
x,y=16,22
message= _  "They obviously weren't enough. You go alert the others and summon reinforcements. I will hold them off for as long as I can."
[/message]

[message]
x,y=18,23
message= _  "May Griknagh protect you. I'll be back soon!"
[/message]

#replace with a new troll shaman that can move
[kill]
x,y=16,22
animate=no
[/kill]

[unit]
	type=Troll Shaman
	description=Troll High Shaman
	user_description= _ "Troll High Shaman"
	x=16
	y=22
	side=7
	[modifications]
		{TRAIT_INTELLIGENT}
		{TRAIT_LOYAL}
	[/modifications]
[/unit]

[kill]
x,y=18,23
animate=no
[/kill]

[move_unit_fake]
type=Troll Shaman
x=18,17,16,16,17,18,19,20,21
y=23,24,24,25,26,27,28,28,29
[/move_unit_fake]


# Create reinforcements for shaman to return with
# Create 2 troll whelps and on Challening and Hard add a troll shaman

{UNIT_T (Troll Whelp) (Troll Reinforcements) ( _ "Troll Reinforcements") 7 27 28}
{UNIT_T (Troll Whelp) (Troll Reinforcements) ( _ "Troll Reinforcements") 7 28 28}

#on challenging/hard add a troll shaman
#ifdef EASY
#else

[unit]
	type=Troll Shaman
	description=Troll High Shaman
	user_description= _ "Troll High Shaman"
	x=26
	y=28
	side=7
	[modifications]
		{TRAIT_RESILIENT}
		{TRAIT_LOYAL}
	[/modifications]
[/unit]

#endif
[/event]

# Before you have gotten close to troll lair, keep them from gaining any gold

[event]
name=new turn
first_time_only=no

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

	[then]

	[modify_side]
		side=7
		income=0
		gold=0
	[/modify_side]

	[/then]
[/if]

[/event]

# Event 23: Trigger Troll Lord's side

[event]
name=moveto

[filter]
x=27-44
y=27-30
side=1
[/filter]

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

#create troll leader
[unit]
	type=Great Troll
	description=Troll Chieftain
	user_description= _ "Troll Chieftain"
	canrecruit=1
	upkeep=full
	x=46
	y=22
	side=7
	[modifications]
		{TRAIT_STRONG}
		{TRAIT_RESILIENT}
	[/modifications]
[/unit]

[modify_side]
	side=7

	#ifdef EASY
	income=2
	gold=120
	#endif
	#ifdef MEDIUM
	income=4
	gold=140
	#endif
	#ifdef HARD
	income=6
	gold=160
	#endif
[/modify_side]

#capture troll chieftan's villages

[capture_village]
x,y=39-49,20-29
side=7
[/capture_village]

[/event]

#reveal cavern when player enters

[event]
name=moveto

[filter]
x=33-39
y=24-28
side=1
[/filter]

#create troll defenders

{UNIT_T (Troll Whelp) (Troll Guard) ( _ "Troll Guard") 7 36 25}
{UNIT_T (Troll Whelp) (Troll Guard) ( _ "Troll Guard") 7 37 29}
{UNIT_T (Troll Rocklobber) (Troll Guard) ( _ "Troll Guard") 7 39 27}

#ifdef EASY
{UNIT_T (Troll Whelp) (Troll Guard) ( _ "Troll Guard") 7 42 25}
#else
{UNIT_T (Troll) (Troll Guard) ( _ "Troll Guard") 7 42 25}
#endif

[remove_shroud]
x=33-50
y=19-29
side=1
[/remove_shroud]

[unit]
type=Troll Shaman
description=High Advisor
user_description= _ "High Advisor"
upkeep=free
x=45
y=24
side=7
ai_special=guardian
[modifications]
	{TRAIT_LOYAL}
	{TRAIT_RESILIENT}
[/modifications]
[/unit]

[message]
description=High Advisor
message= _ "Invade our most holy cavern at your peril. Long have we protected our sacred burial grounds from your foul kind, and we shall scatter your bones next to those of our ancestors."
[/message]

[message]
description=Troll Chieftain
message= _ "Destroy the invaders! Make them pay for their slaughter!"
[/message]

[/event]

# Event 24: Troll Undead Uprising

#define TROLL_UNDEAD_UPRISING

[message]
description=High Advisor
message= _ "Arise, our brothers of ages past! Arise and destroy the intruders!"
[/message]

{UNIT_ (Walking Corpse) (troll_wc_1) ("") 7 39 22}
{INVOKE_TROLL_VARIATION description=troll_wc_1}

{UNIT_ (Walking Corpse) (troll_wc_2) ("") 7 40 28}
{INVOKE_TROLL_VARIATION description=troll_wc_2}

{UNIT_ (Walking Corpse) (troll_wc_3) ("") 7 36 23}
{INVOKE_TROLL_VARIATION description=troll_wc_3}

{UNIT_ (Walking Corpse) (troll_wc_4) ("") 7 37 29}
{INVOKE_TROLL_VARIATION description=troll_wc_4}

#ifdef MEDIUM

{UNIT_ (Walking Corpse) (troll_wc_5) ("") 7 33 25}
{INVOKE_TROLL_VARIATION description=troll_wc_5}

{UNIT_ (Walking Corpse) (troll_wc_6) ("") 7 34 28}
{INVOKE_TROLL_VARIATION description=troll_wc_6}

#endif

#ifdef HARD
{UNIT_ (Walking Corpse) (troll_wc_5) ("") 7 42 21}
{INVOKE_TROLL_VARIATION description=troll_wc_5}

{UNIT_ (Walking Corpse) (troll_wc_6) ("") 7 43 26}
{INVOKE_TROLL_VARIATION description=troll_wc_6}

#endif

#enddef

# count number of elves that have entered the trolls cave. Once 3 elves
# are in the cave, then active the troll undead uprising

[event]
name=new turn
first_time_only=no

[store_locations]
	x=35-50
	y=23-29
	[filter]
	side=1
	[/filter]
	variable=troll_list
[/store_locations]

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

{CLEAR_VARIABLE troll_list}

[if]
	[variable]
	name=temp
	greater_than_equal_to=3
	[/variable]

	[then]

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

		[then]

		{TROLL_UNDEAD_UPRISING}

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

		[/then]
	[/if]

	[/then]
[/if]

[/event]

[event]
name=die

[filter]
	description=Troll Chieftain
[/filter]

[message]
description=Troll Chieftain
message= _ "Argh! Curse you! May you never live to see daylight again!"
[/message]

[message]
speaker=second_unit
message= _ "And so, at last, it ends."
[/message]

[message]
side=7
message= _ "Da big troll is dead. Run for your lives!"
[/message]

[kill]
side=7
animate=no
[/kill]

[terrain]
x=41,41,42,43,44,45,45
y=15,16,16,17,17,18,19
letter=Uu
[/terrain]

[move_unit_fake]
type=Dwarvish Scout
x=41,41,42,43,44,45,45
y=15,16,16,17,17,18,19
[/move_unit_fake]

{UNIT_ (Dwarvish Pathfinder) (Grendel) ( _ "Grendel") 2 45 19}

[remove_shroud]
	x=43-46
	y=17-20
	side=1
[/remove_shroud]

[delay]
time=200
[/delay]

[message]
description=Grendel
message= _ "News travels fast. The chaos you have sown has caused the foul trolls to start retreating. And now the architect of our suffering is dead. This war is far from over, but with your help we won this battle. You have our gratitude. Our King has instructed us to bring you to him; he wants to talk with you and reward you. He waits in our most hallowed hall, a place that no elf has seen for generations upon generations. It is a great honor, but you have done great deeds this day. Elves killing a troll chieftain! We will tell this story for years."
[/message]

[message]
description=Nym
message= _ "With their knowledge of all these secret tunnels, you'd think they could have led us straight here instead of making us go through those 'light defenses'. It would have saved us a lot of unnecessary fighting in actually getting to the troll chieftain."
[/message]

[message]
description=Zhul
message= _ "Perhaps they wanted to further test our prowess in battle. And besides, every troll we kill is one they don't have to. Still, I think we caused a bigger distraction then they were expecting."
[/message]

[message]
description=Kaleh
message= _ "Shhhh, you two. Yes, of course, we would be honored to come and meet your King. But first, we left many of our people back up near the entrance to the great cave where you first met us and I fear that even now those caves aren't safe. Can you help us escort my people to safety?"
[/message]

[message]
description=Grendel
message= _ "Hmmmm, yes, after what you have done, I think I could arrange something. We have a few larger halls that should hold your people, a bit cramped, but safe. Since you first arrived, we've had a few lads watch over them; you hid your folk in a good defensive location, but you can never be too sure. I'll get them to help escort your people to safety. We certainly wouldn't want any surprises."
[/message]

[message]
description=Kaleh
message= _ "You are full of surprises. But I feel better knowing a few of your kind were watching out for the rest of my people. All right everyone, no celebrating yet, we still have work left to do!"
[/message]

[endlevel]
result=victory

bonus=yes
[/endlevel]

[/event]

# TROLL EASTER EGG EVENTS

# Event 25: Dwarf Ghost

[event]
name=moveto
first_time_only=no

[filter]
x=7-11
y=17-21
side=1
[/filter]

[if]

	[variable]
	name=buried_dwarf
	numerical_equals=0
	[/variable]

	[then]

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

		[then]

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

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

		[message]
		speaker=unit
		message= _ "It's cooler here, there seems to be a draft to the west."
		[/message]

		{UNIT_ (Haunt) (Dwarf Ghost) ( _ "Dwarf Ghost") 2 8 20}

		[delay]
		time=300
		[/delay]

		[message]
		description=Dwarf Ghost
		message= _ "Hail, friend. Ages ago, I too fought the trolls and came to this place. But by ill luck I was burned to death by the lava and died nearby unblessed and unhonored. Find my body and grant me the peace I so dearly wish for. Do this and I will let you pass."
		[/message]

		[/then]

	[/if]

	[/then]

[/if]

[/event]

# Event 26: Dwarf Corpse

[event]
name=moveto
first_time_only=no

[filter]
x=14
y=12-13
side=1
[/filter]

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

	[then]

	[message]
	speaker=unit
	message= _ "Look, a crumbling skeleton. I think this might be the body of the dwarven ghost. It shouldn't take long to dig a shallow grave."
	[/message]

	[redraw]
	[/redraw]

	[delay]
	time=1000
	[/delay]

	[message]
	speaker=unit
	message= _ "May Eloh, or whatever god you worship, grant you peace and safe passage to the afterlife. We will avenge your death."
	[/message]

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

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

	# kills dwarf ghost blocking passage
	[kill]
	description=Dwarf Ghost
	animate=no
	[/kill]

	# create new unit so that ghost can deliver final dialogue before leaving
	{UNIT_ (Haunt) (Dwarf Ghost) ( _ "Dwarf Ghost") 2 14 13}

	[message]
	description=Dwarf Ghost
	message= _ "Thank you. You have done for me what all my dwarven kin never could. I will no longer block your way. May Moradin bless you and watch over you. I leave now for the halls of my ancestors..."
	[/message]

	[kill]
	description=Dwarf Ghost
	animate=yes
	[/kill]

	[/then]
[/if]

[/event]

# Event 27: Troll Crypt Guardian

[event]
name=moveto

[filter]
x=7-9
y=20-25
side=1
[/filter]

{UNIT_ Soulless cryptguard ( _ "Crypt Guardian") 7 7 25}
{INVOKE_TROLL_VARIATION description=cryptguard}

[message]
speaker=unit
message= _ "This looks like a troll crypt. Whoever it was must have been very important, because they have their own undead guardian."
[/message]

[/event]

# Event 28: Troll Coffin

[event]
name=moveto

[filter]
x=5-6
y=26
side=1
[/filter]

[message]
speaker=unit
message= _ "There is a chasm here cutting off the end of the crypt. It must be rather recent, it cuts off the path leading to a rather ornate stone coffin."
[/message]

[/event]

# Ransack Troll Coffin

[event]
name=moveto
first_time_only=no

[filter]
x=3
y=28
side=1
[/filter]

[if]

	[variable]
	name=took_wand
	numerical_equals=0
	[/variable]

	[then]

	[message]
	speaker=unit

	message= _ "For a troll this is quite an ornate tomb. The coffin itself is quite impressive. Inside, the skeleton has crumbled to dust and there are a few colored stones and trinkets, but what really sticks out is this emerald wand. I don't have much experience with magical items, but the asp with emerald eyes and large fangs carved around its shaft leave little doubt as to its power. We don't normally tolerate using poison, but extreme circumstances call for extreme measures and I have a feeling we may find this useful before our journey is over."
	[option]
		message= _ "It might be useful, I'll take it."
		[command]
			[set_variable]
			name=took_wand
			value=1
			[/set_variable]
		[/command]
		[command]
			[message]
			speaker=unit
			message= _ "The wand fits comfortably in my hand. It doesn't seem to have much of a range, but in close combat it could be quite useful."
			[/message]
		[/command]

		[command]

			[object]

			[filter]
			x=3
			y=28
			side=1
			[/filter]

			id=Troll Wand
			name= _ "Emerald Wand of Poison"
			description= _ "This wand make this unit's melee attacks deal poison damage."

			[effect]
			apply_to=attack
			range=melee
				[set_specials]
					{WEAPON_SPECIAL_POISON}
				[/set_specials]
			[/effect]

			[/object]
		[/command]
	[/option]

	[option]
	message= _ "On second thought, it's better to leave the dead in peace."

	[/option]

	[/message]

	[/then]
[/if]

[/event]

#at victory, clear variables:

[event]
name=victory

{CLEAR_VARIABLE destroy_wall}

{CLEAR_VARIABLE i}
{CLEAR_VARIABLE temp}
{CLEAR_VARIABLE tempx}
{CLEAR_VARIABLE tempy}

{CLEAR_VARIABLE lava_damage}
{CLEAR_VARIABLE heat_damage}
{CLEAR_VARIABLE summon_flame}
{CLEAR_VARIABLE flame_counter}
{CLEAR_VARIABLE troll_undead_arose}
{CLEAR_VARIABLE met_ghost}
{CLEAR_VARIABLE buried_dwarf}
{CLEAR_VARIABLE took_wand}
{CLEAR_VARIABLE entered_troll_lair}

[/event]

[event]
name=time over

[message]
description=Kaleh
message= _ "Oh no, we took too long and enemy reinforcements have arrived. We'll surely be overwhelmed now!"
[/message]

[/event]

#if dwarf prisoner Rogrimir dies in battle, record him

[event]
name=die

[filter]
description=Rogrimir
[/filter]

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

[/event]

{@campaigns/Under_the_Burning_Suns/utils/deaths.cfg}

{@campaigns/Under_the_Burning_Suns/utils/global-events.cfg}
[/scenario]
