# Level 12: The Final Confrontation

[scenario]
#textdomain wesnoth-utbs

id="12_FinalConfrontation"
name= _ "The Final Confrontation"
label= _ "The Final Confrontation"

next_scenario=13_Epilogue

map_data="{campaigns/Under_the_Burning_Suns/maps/12Final4.map}"

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

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

#there is no turn limit for this scenario
turns="-1"

{UNDERGROUND}

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

[/side]

# Side 2:ÊEloh
[side]
	side=2
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=eloh

	[ai]
		aggression=0.95
		caution=0.1

		# change AI so that enemies target Kaleh's friends
		# more than Kaleh himself. I want to threaten
		# other units more, since Kaleh's death leads to
		# immediate defeat

		[target]
		description=Kaleh
		value=1
		[/target]

		[target]
		description=Nym
		value=3
		[/target]

		[target]
		description=Zhul
		value=3
		[/target]

		[target]
		description=$ally_name
		value=3
		[/target]
	[/ai]
[/side]

# Side 3: Brainwashed Elves
[side]
	side=3
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=eloh

	[ai]
		aggression=0.95
		caution=0.1

		[target]
		description=Kaleh
		value=1
		[/target]

		[target]
		description=Nym
		value=3
		[/target]

		[target]
		description=Zhul
		value=3
		[/target]

		[target]
		description=$ally_name
		value=3
		[/target]
	[/ai]
[/side]

# Side 4: Pulsing Spires
[side]
	side=4
	no_leader=yes
	gold=0
	income=0
	controller=ai
	shroud=no
	fog=no
	team_name=eloh

	[ai]
		aggression=-1.0
		caution=1.0

		[target]
		description=Kaleh
		value=1
		[/target]

		[target]
		description=Nym
		value=3
		[/target]

		[target]
		description=Zhul
		value=3
		[/target]

		[target]
		description=$ally_name
		value=3
		[/target]
	[/ai]
[/side]

# OLD: Chapter 11: True power is not measured in strength or knowledge, but in the sacrifices that others will make on your behalf.

# NEW: True strength is not measured in might or knowledge, but in what you will sacrifice for those you love.

[story]
	[part]
	story= _ "Chapter 12: True strength is not measured in might or knowledge, but in how much you will sacrifice for those you love."
	[/part]

[/story]

# Prestart functions:
# insert items onto map
# place item images on map
# recall main heroes
# store/remove kaleh
# initialize starting variables
# set starting scenario objectives

[event]
name=prestart

	# scenario testing units

	# add items to map

	{PLACE_IMAGE items/kaleh-dead.png 10 13}

	# recall heroes

	[recall]
	description=Zhul
	[/recall]
	[recall]
	description=Nym
	[/recall]
	# recall dwarf/troll
	[recall]
	description=$ally_name
	[/recall]

	# store/remove kaleh

	[store_unit]
	[filter]
		description=Kaleh
	[/filter]
	kill=yes
	variable=stored_kaleh
	[/store_unit]

	[redraw]
	[/redraw]

	#teleport heroes

	[teleport]
	[filter]
		description=Nym
	[/filter]
	x,y=10,16
	[/teleport]

	[teleport]
	[filter]
		description=Zhul
	[/filter]
	x,y=11,17
	[/teleport]

	[teleport]
	[filter]
		description=$ally_name
	[/filter]
	x,y=9,17
	[/teleport]

	#initialize starting variables

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

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

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

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

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

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

	#if ally never survived to final battle then save this info
	[if]
		[have_unit]
			description=$ally_name
		[/have_unit]

		[then]

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

		[/then]

	[/if]

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

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

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

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

	# at each increase 1 extra alien minion is produced each turn

	[set_variable]
	name=first_increase
	#ifdef EASY
	value=2
	#endif
	#ifdef MEDIUM
	value=2
	#endif
	#ifdef HARD
	value=1
	#endif
	[/set_variable]

	[set_variable]
	name=second_increase
	#ifdef EASY
	value=4
	#endif
	#ifdef MEDIUM
	value=3
	#endif
	#ifdef HARD
	value=3
	#endif
	[/set_variable]

	[set_variable]
	name=third_increase
	#ifdef EASY
	value=6
	#endif
	#ifdef MEDIUM
	value=5
	#endif
	#ifdef HARD
	value=5
	#endif
	[/set_variable]

	# set starting scenario objectives

	[objectives]
		summary= _ "Starting Objectives:"
		[objective]
			description= _ "Defeat the false Eloh"
			condition=win
		[/objective]
		[objective]
			description= _ "Death of Kaleh"
			condition=lose
		[/objective]
	[/objectives]

[/event]

# Event 1: Starting dialogue

[event]
name=start

[scroll_to]
x,y=10,13
[/scroll_to]

[redraw]
[/redraw]

[delay]
	time=750
[/delay]

[message]
	description=Nym
	image=portraits/nym.png
	message= _ "Kaleh! No!"
[/message]

[redraw]
[/redraw]

[delay]
	time=500
[/delay]

# Nym runs to Kaleh's side

[store_unit]
	[filter]
		description=Nym
	[/filter]
	variable=stored_unit
[/store_unit]

[hide_unit]
x,y=10,16
[/hide_unit]

[move_unit_fake]
type=$stored_unit.type
x=10,10,10
y=16,15,14
[/move_unit_fake]

{CLEAR_VARIABLE stored_unit}

[teleport]
	[filter]
		description=Nym
	[/filter]
	x,y=10,14
[/teleport]

[unhide_unit]
[/unhide_unit]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

# Zhul runs to Kaleh's side

[store_unit]
	[filter]
		description=Zhul
	[/filter]
	variable=stored_unit
[/store_unit]

[hide_unit]
x,y=11,17
[/hide_unit]

[move_unit_fake]
type=$stored_unit.type
x=11,10,10,11,11
y=17,16,15,15,14
[/move_unit_fake]

{CLEAR_VARIABLE stored_unit}

[teleport]
	[filter]
		description=Zhul
	[/filter]
	x,y=11,14
[/teleport]

[unhide_unit]
[/unhide_unit]

[message]
	description=Zhul
	image=portraits/zhul.png
	message= _ "He's still breathing. Eloh, what grace I have, give unto him."
[/message]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

[message]
	description=Nym
	image=portraits/nym.png
	message= _ "He's stirring."
[/message]

# Ally runs to Kaleh's side

[hide_unit]
x,y=9,17
[/hide_unit]

[store_unit]
	[filter]
		description=$ally_name
	[/filter]
	variable=stored_unit
[/store_unit]

[move_unit_fake]
	type=$stored_unit.type
	x=9,8,8,8,9
	y=17,16,15,14,14
[/move_unit_fake]

{CLEAR_VARIABLE stored_unit}

[teleport]
	[filter]
		description=$ally_name
	[/filter]
	x,y=9,14
[/teleport]

[unhide_unit]
[/unhide_unit]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

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

	[then]

	[message]
	description=$ally_name
	image=portraits/rogrimir.png
	message= _ "Aye, there's still life in the boy. But where is the foul creature that did this to him?"
	[/message]

	[/then]

	[else]

	[message]
	description=$ally_name
	image=portraits/grog.png
	message= _ "The little one is not dead yet. But where is evil lady that did this to him?"
	[/message]

	[/else]
[/if]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

[unit]
	type=Divine Incarnation
	description=Eloh
	user_description= _ "Eloh"
	x,y=10,11
	upkeep=free
	side=2
	[modifications]
		{TRAIT_INTELLIGENT}
		{TRAIT_QUICK}
	[/modifications]
[/unit]

[delay]
	time=500
[/delay]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "So, the elf's puny friends think they can save him. But you are too late. He is already mine!"
[/message]

[removeitem]
	x,y=10,13
[/removeitem]

[unstore_unit]
	variable=stored_kaleh
	find_vacant=yes
[/unstore_unit]

[teleport]
	[filter]
		description=Kaleh
	[/filter]
	x,y=10,13
[/teleport]

[object]
	[filter]
		description=Kaleh
	[/filter]

	id=WoundedDamage
	silent=yes

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


[if]
	[have_unit]
	description=$ally_name
	[/have_unit]

	[then]

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

		[then]

		[message]
			description=Kaleh
			image=portraits/kaleh.png
			message= _ "Nym, Zhul, $ally_name , you shouldn't have."
		[/message]

		[/then]

		[else]

		[message]
			description=Kaleh
			image=portraits/kaleh.png
			message= _ "Nym, Zhul, $ally_name , you shouldn't have."
		[/message]

		[/else]
	[/if]

	[/then]

	[else]
		[message]
			description=Kaleh
			image=portraits/kaleh.png
			message= _ "Nym, Zhul, you shouldn't have."
		[/message]
	[/else]
[/if]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Your struggles were mildly entertaining, but futile in the end. For I am powerful beyond your imagining, and this is the seat of my power!"
[/message]

[message]
	description=Zhul
	image=portraits/zhul.png
	message= _ "You are not Eloh. You are but a pitiful mockery of her power and glory!"
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Is that what you think? I shall prove you wrong. Look out upon your people and despair!"
[/message]

[move_unit_fake]
type=Desert Fighter
x=9,10,10,10,9,8
y=20,19,18,17,17,16
[/move_unit_fake]

[unit]
	type=Desert Fighter
	description=Anarion
	user_description= _ "Anarion"
	upkeep=full
	x=8
	y=16
	side=3
	[modifications]
		{TRAIT_QUICK}
		{TRAIT_STRONG}
	[/modifications]
[/unit]

[redraw]
[/redraw]

[delay]
time=100
[/delay]

[move_unit_fake]
type=Desert Archer
x=11,10,10,10,11,12
y=20,19,18,17,17,16
[/move_unit_fake]

[unit]
	type=Desert Archer
	description=Zylea
	user_description= _ "Zylea"
	upkeep=full
	x=12
	y=16
	side=3
	[modifications]
		{TRAIT_DEXTROUS}
		{TRAIT_RESILIENT}
	[/modifications]
[/unit]

[message]
	description=Anarion
	message= _ "All hail Eloh!"
[/message]

[message]
	description=Zylea
	message= _ "Death to the heretics!"
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "They worship their true god."
[/message]

[message]
	description=Eloh
	image=portraits/eloh.png
	message= _ "Come and bow down before your true master, boy."
[/message]

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "Your wish is my command."
[/message]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

# Kaleh moves over to Eloh

[hide_unit]
x,y=10,13
[/hide_unit]

[store_unit]
	[filter]
		description=Kaleh
	[/filter]
	variable=stored_unit
[/store_unit]

[move_unit_fake]
type=$stored_unit.type
x=10,10
y=13,12
[/move_unit_fake]

[delay]
	time=200
[/delay]

	{PLACE_IMAGE units/elves-desert/kaleh-defend.png 10 12}

	[redraw]
	[/redraw]

	[delay]
		time=200
	[/delay]

	[removeitem]
		x,y=10,12
	[/removeitem]

	{PLACE_IMAGE units/elves-desert/kaleh-leading.png 10 12}

	[redraw]
	[/redraw]

	[delay]
		time=200
	[/delay]

	[removeitem]
		x,y=10,12
	[/removeitem]

	{PLACE_IMAGE units/elves-desert/kaleh-melee-1.png 10 12}

	[redraw]
	[/redraw]

{CLEAR_VARIABLE stored_unit}

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

[removeitem]
	x,y=10,12
[/removeitem]

[teleport]
	[filter]
		description=Kaleh
	[/filter]
	x,y=10,12
[/teleport]

[unhide_unit]
[/unhide_unit]

[redraw]
[/redraw]

# damage Eloh slightly

[object]
	[filter]
		description=Eloh
	[/filter]

	id=StabbingDamage
	silent=yes

	[effect]
		apply_to=hitpoints
		increase=-6
	[/effect]
[/object]

[redraw]
[/redraw]

[delay]
	time=500
[/delay]

[message]
	description=Eloh
	image=portraits/eloh_rage.png
	message= _ "Argh, you stabbed me!"
[/message]

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "I have crossed deserts, mountains, and oceans and watched my people bleed every step of the way. I did not come all this way to give up now. I am tired of being called boy; I am Kalehssar, the leader of my people and I will fight you until my dying breath!"
[/message]

[message]
	description=Eloh
	image=portraits/eloh_rage.png
	message= _ "I command you to stop this foolishness!"
[/message]

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "Never!"
[/message]

[message]
	description=Nym
	image=portraits/nym.png
	message= _ "The shell brooches Melusand gave us, they're glowing!"
[/message]

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "You will never dominate us, not while hope survives!"
[/message]

[message]
	description=Eloh
	image=portraits/eloh_rage.png
	message= _ "So be it. You choose death? Then you shall receive it from those you hold most dear. Kill the unbelievers, let none survive!"
[/message]

[message]
	description=Anarion
	message= _ "Yes mistress."
[/message]

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "Ignore our brethren, we must destroy her!"
[/message]

[/event]


# MACRO 1: Create an alien minion

#define CREATE_MINION

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

[while]

[variable]
	name=counter
	less_than=1
[/variable]

[do]
	{RANDOM 6..14}

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

	{RANDOM 7..14}

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

	{RANDOM 0..39}

	[store_locations]
	x=$temp_x
	y=$temp_y
	terrain=Rr, Uu
	variable=locs
	[/store_locations]

	[if]

	[variable]
	name=locs.length
	numerical_equals=1
	[/variable]

	[then]

		{FREE_UNIT (Crawling Horror) () ("") 2 $temp_x $temp_y}

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

	[/then]

	[/if]

[/do]

[/while]

#enddef

# MACRO 2: Perform special attack by Central Body

#define SPECIAL_ATTACK

[store_locations]
[filter]
	side=1
[/filter]
variable=elf_list
[/store_locations]

[set_variable]
	name=array_length
	value=$elf_list.length
[/set_variable]

#subtract 1 because arrays go from 0 to length-1
[set_variable]
	name=array_length
	add=-1
[/set_variable]

[set_variable]
	name=random_string
	format=0..$array_length
[/set_variable]

[set_variable]
	name=victim
	random=$random_string
[/set_variable]

[set_variable]
	name=temp_x
	to_variable=elf_list[$victim].x
[/set_variable]

[set_variable]
	name=temp_y
	to_variable=elf_list[$victim].y
[/set_variable]

#used to be 140,255,247

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

[redraw]
[/redraw]

[delay]
	time=250
[/delay]

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

[redraw]
[/redraw]

[delay]
	time=100
[/delay]

# Add 2 effects slow unit and damage it
# 1: slow unit

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

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

	[unstore_unit]
		variable=unitstats
	[/unstore_unit]

	{CLEAR_VARIABLE unitstats}

# 2: do damage to unit (8/9/10 based on difficulty?-stops healing)

[object]
	[filter]
		x,y=$temp_x,$temp_y
	[/filter]

	silent=yes

	[effect]
		apply_to=hitpoints
		#ifdef EASY
		increase=-10
		#endif
		#ifdef MEDIUM
		increase=-11
		#endif
		#ifdef HARD
		increase=-12
		#endif
	[/effect]

[/object]

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

	[then]

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

	[message]
		x,y=$temp_x,$temp_y
		message= _ "What the heck? That central creature just hit me with some sort of slime. It hurts and I, I'm stuck!"
	[/message]

	[/then]

	[else]

	[message]
		x,y=$temp_x,$temp_y
		message= _ "Ow, I'm stuck!"
	[/message]

	[/else]
[/if]
#enddef


# Event 1: The Death of Eloh and the revealing of the true monster

[event]
name=die

[filter]
description=Eloh
[/filter]

[message]
speaker=Eloh
image=portraits/eloh_rage.png
message= _ "You think you killed me? You have no idea what you are facing."
[/message]

[message]
speaker=Nym
image=portraits/nym.png
message= _ "Who is she really? Could it be Yanqui, back to avenge his imprisonment?"
[/message]

[message]
speaker=Eloh
image=portraits/eloh_rage.png
message= _ "Nonsense. Unlike that fool, I do not care about petty things like revenge. Nor do I depend on mortals to enact my will. No, I shall destroy you myself!"
[/message]

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

[while]
	[have_unit]
		side=3
	[/have_unit]

	[do]

	[store_unit]
	[filter]
		side=3
	[/filter]
	variable=unitstats
	[/store_unit]

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

	[unstore_unit]
		variable=unitstats
	[/unstore_unit]

	[/do]
[/while]

{CLEAR_VARIABLE unitstats}

[message]
type=Desert Fighter, Desert Archer
message= _ "Huh? What happened?"
[/message]

[message]
	description=Zhul
	image=portraits/zhul.png
	message= _ "Her spell has been broken. But I don't think we have won yet. Come aid us!"
[/message]

[message]
type=Desert Fighter, Desert Archer
message= _ "Yes priestess."
[/message]

[scroll]
	x=25
[/scroll]
[scroll]
	x=-25
[/scroll]
[scroll]
	x=25
[/scroll]
[scroll]
	x=-25
[/scroll]
[scroll]
	x=25
[/scroll]
[scroll]
	x=-25
[/scroll]

[redraw]
[/redraw]

[delay]
	time=400
[/delay]

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

[redraw]
[/redraw]

[delay]
	time=250
[/delay]

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

[redraw]
[/redraw]

# main body appears

[terrain]
letter=Ryd
x,y=10,10
[/terrain]

# create main body unit here

[unit]
	type=Central Body
	description=Yechnagoth
	user_description= _ "Yechnagoth"
	side=2
	x,y=10,10
[/unit]

# add roots around central body

#{PLACE_IMAGE scenery/castle-ruins.png 9 11}
#{PLACE_IMAGE scenery/castle-ruins.png 10 11}
#{PLACE_IMAGE scenery/castle-ruins.png 11 11}
#{PLACE_IMAGE scenery/castle-ruins.png 9 10}
#{PLACE_IMAGE scenery/castle-ruins.png 10 9}
#{PLACE_IMAGE scenery/castle-ruins.png 11 10}

# Pulsing Spires appear

#define SPIRES_0

[terrain]
letter=Uu
x=6,12,12
y=10,7,13
[/terrain]

# create Pulsing Spires at:
# (6,10) (12,7) (12,13)

[unit]
	type=Pulsing Spire
	side=4
	x,y=6,10
[/unit]

{PLACE_IMAGE units/alien/spire-top.png 6 9}

[unit]
	type=Pulsing Spire
	side=4
	x,y=12,7
[/unit]

{PLACE_IMAGE units/alien/spire-top.png 12 6}

[unit]
	type=Pulsing Spire
	side=4
	x,y=12,13
[/unit]

{PLACE_IMAGE units/alien/spire-top.png 12 12}

#enddef

#define SPIRES_1

[terrain]
letter=Uu
x=8,8,14
y=7,13,10
[/terrain]

# create Pulsing Spires at:
# (8,7) (8,13) (14,10)

[unit]
	type=Pulsing Spire
	side=4
	x,y=8,7
[/unit]

{PLACE_IMAGE units/alien/spire-top.png 8 6}

[unit]
	type=Pulsing Spire
	side=4
	x,y=8,13
[/unit]

{PLACE_IMAGE units/alien/spire-top.png 8 12}

[unit]
	type=Pulsing Spire
	side=4
	x,y=14,10
[/unit]

{PLACE_IMAGE units/alien/spire-top.png 14 9}

#enddef

{RANDOM 0..1}

[set_variable]
name=temp
value=$random
[/set_variable]

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

	[then]

	{SPIRES_1}

	[/then]

	[else]

	{SPIRES_0}

	[/else]
[/if]

[redraw]
[/redraw]

[message]
	description=Nym
	image=portraits/nym.png
	message= _ "What is that thing!?!"
[/message]

[message]
	description=Zhul
	image=portraits/zhul.png
	message= _ "Eloh protect us!"
[/message]

[colour_adjust]
	red,green,blue=33,181,140
[/colour_adjust]

[redraw]
[/redraw]

[delay]
	time=250
[/delay]

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

[redraw]
[/redraw]

# alien bugs appear

# create 3 bugs using a macro

{CREATE_MINION}
{CREATE_MINION}
{CREATE_MINION}

[redraw]
[/redraw]

[delay]
time=500
[/delay]

[message]
	description=Zhul
	image=portraits/zhul.png
	message= _ "Curse Uria, more abominations!"
[/message]

[message]
	description=Nym
	image=portraits/nym.png
	message= _ "Is it even possible to kill this thing? It's huge!"
[/message]

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "It must have some sort of weak point. Look at those pulsing spires, I thought they were stone, but they seem to be alive. Maybe if we destroy them it will weaken the creature. No matter what horrors appear, we must keep attacking it. We can't stop now!"
[/message]

[objectives]
	summary= _ "New Objectives:"
	[objective]
		description= _ "Defeat Yechnagoth"
		condition=win
	[/objective]
	[objective]
		description= _ "Death of Kaleh"
		condition=lose
	[/objective]
[/objectives]

[/event]

# Event 2: New minions are created each turn

[event]
name=new turn
first_time_only=no

[if]
	[have_unit]
	description=Yechnagoth
	[/have_unit]

	[then]

	{CREATE_MINION}

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

	#[message]
	#speaker=narrator
	#message= _ "minion turn counter: $minion_turn_counter"
	#[/message]

	[/then]
[/if]



[if]
	[variable]
	name=minion_turn_counter
	greater_than=$first_increase
	[/variable]

	[then]

	{CREATE_MINION}

	[/then]
[/if]

[if]
	[variable]
	name=minion_turn_counter
	greater_than=$second_increase
	[/variable]

	[then]

	{CREATE_MINION}

	[/then]
[/if]

[if]
	[variable]
	name=minion_turn_counter
	greater_than=$third_increase
	[/variable]

	[then]

	{CREATE_MINION}

	[/then]
[/if]

[/event]


# Event 3: Central Body heals fully each turn

[event]
name=new turn
first_time_only=no

[if]
	[have_unit]
	type=Central Body
	[/have_unit]

	[then]



	[store_unit]
	[filter]
		type=Central Body
	[/filter]
	variable=stored_alien
	[/store_unit]

	[set_variable]
	name=temp
	value=$stored_alien.hitpoints
	[/set_variable]

	[object]
		[filter]
			type=Central Body
		[/filter]

		silent=yes
		duration="level"

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

	[if]
		[variable]
		name=temp
		less_than=100
		[/variable]

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

		[then]

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

		[message]
		description=Kaleh
		image=portraits/kaleh.png
		message= _ "That central body is healing faster than we can damage it. It's almost as if our attacks are doing no damage at all. We got to try another tactic, and fast!"
		[/message]

		[/then]

	[/if]

	{CLEAR_VARIABLE stored_alien}

	[/then]
[/if]

[/event]

# Event 4: Special attack my Central Body each turn

[event]
name=new turn
first_time_only=no

[if]
	[have_unit]
	description=Yechnagoth
	[/have_unit]

	[then]

	{SPECIAL_ATTACK}

	[/then]
[/if]

[/event]

# Event 5: When player destroys all 3 Pulsing Spires, Central Body is weakened

[event]
name=die
first_time_only=no

[filter]
type=Pulsing Spire
[/filter]

# erase image of top of spire on hex one above where spire actually is

[set_variable]
name=x_var
value=$x1
[/set_variable]

[set_variable]
name=y_var
value=$y1
[/set_variable]

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

[removeitem]
x,y=$x_var,$y_var
[/removeitem]

{CLEAR_VARIABLE x_var}
{CLEAR_VARIABLE y_var}

# when all 3 spires are destroyed, weaken main body

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

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

	[then]

	[kill]
	type=Pulsing Spire
	fire_event=no
	animate=no
	[/kill]

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

	[message]
	description=narrator
	message= _ "Aaaauuurrrggghhhh!!!"
	[/message]

	[kill]
	type=Central Body
	animate=no
	fire_event=no
	[/kill]

	[unit]
	type=Central Body2
	description=Yechnagoth
	user_description= _ "Yechnagoth"
	side=2
	x,y=10,10
	[/unit]

	[redraw]
	[/redraw]

	[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "I think we're finally doing some damage. We must attack the central body, while it remains vulnerable!"
	[/message]

	[/then]

[/if]

[/event]

# Event 6: Death of weakened Central Body

[event]
name=die

[filter]
type=Central Body2
[/filter]

[kill]
type=Central Body2
animate=no
fire_event=no
[/kill]

[unit]
	type=Central Body3
	description=Yechnagoth
	user_description= _ "Yechnagoth"
	side=2
	x,y=10,10
[/unit]

[redraw]
[/redraw]

[endlevel]
	result=continue
[/endlevel]

[/event]


#victory event

[event]
name=victory

# shake cavern

[scroll]
	x=40
[/scroll]
[scroll]
	x=-40
[/scroll]
[scroll]
	x=40
[/scroll]
[scroll]
	x=-40
[/scroll]
[scroll]
	x=40
[/scroll]
[scroll]
	x=-40
[/scroll]

# flash dark blue, light blue, very light blue,

# dark blue

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

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

#light blue

[colour_adjust]
	red,green,blue=33,181,140
[/colour_adjust]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

# very light blue

[colour_adjust]
	red,green,blue=140,255,247
[/colour_adjust]

[redraw]
[/redraw]

[delay]
	time=300
[/delay]

# back to normal

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

[redraw]
[/redraw]

# kill central body

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

[redraw]
[/redraw]

[delay]
	time=750
[/delay]

# have a minion scream

[message]
type=Crawling Horror
message= _ "Aiiieeee!!!"
[/message]

[redraw]
[/redraw]

# kill minions

[kill]
side=2
animate=yes
fire_event=no
[/kill]

[redraw]
[/redraw]

# wait
[delay]
	time=2500
[/delay]

#ending conversation

[message]
	description=Kaleh
	image=portraits/kaleh.png
	message= _ "At last. It is finished."
[/message]


[if]
	[have_unit]
	description=Nym
	[/have_unit]

	[then]

	[message]
		description=Nym
		image=portraits/nym.png
		message= _ "Is Yechnagoth really dead?"
	[/message]

	[message]
		description=Kaleh
		image=portraits/kaleh.png
		message= _ "Yes, she's dead Nym."
	[/message]

	[message]
		description=Nym
		image=portraits/nym.png
		message= _ "I almost can't believe it."
	[/message]

	[/then]
[/if]

[message]
	description=Zhul
	image=portraits/zhul.png
	message= _ "Behold, the pretender has been defeated. Eloh's might has prevailed."
[/message]

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

	[then]

	[message]
	description=$ally_name
	image=portraits/rogrimir.png
	message= _ "Ugh. I'm covered in blood and guts, and this nasty blue stuff. I don't know what in the nine hells we were fighting, but she doesn't smell any better dead than she did alive."
	[/message]

	[/then]

	[else]

	[message]
	description=$ally_name
	image=portraits/grog.png
	message= _ "Ugh. $ally_name is covered in blood and guts and nasty blue goo. Whatever creature was, she doesn't smell any better dead than she did alive."
	[/message]

	[/else]
[/if]

[if]
	[or]
	[have_unit]
	description=Nym
	[/have_unit]
	[/or]

	[or]
	[have_unit]
	description=Zhul
	[/have_unit]
	[/or]

	[or]
	[have_unit]
	description=$ally_name
	[/have_unit]
	[/or]

	[then]

	[message]
		description=Kaleh
		image=portraits/kaleh.png
		message= _ "Let's get out of here."
	[/message]

	[/then]
[/if]

{CLEAR_VARIABLE stored_kaleh}
{CLEAR_VARIABLE spires_destroyed}
{CLEAR_VARIABLE minion_turn_counter}
{CLEAR_VARIABLE attacked_yechnagoth}
{CLEAR_VARIABLE hit_by_special_attack}

{CLEAR_VARIABLE random}
{CLEAR_VARIABLE counter}
{CLEAR_VARIABLE temp}
{CLEAR_VARIABLE temp_x}
{CLEAR_VARIABLE temp_y}

[/event]

# testing event to skip to end of battle

#[event]
#name=turn 2

#[kill]
#type=Pulsing Spire
#animate=yes
#fire_event=yes
#[/kill]

#[/event]

# deaths3.cfg differs from deaths.cfg becuase in this version only Kaleh's
# death causes defeat
{@campaigns/Under_the_Burning_Suns/utils/deaths3.cfg}

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