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

name=_ "A Haunting in Winter"
map_data="{campaigns/Descent_Into_Darkness/maps/A_haunting_in_winter.map}"
{TURNS 36 34 32}

victory_when_enemies_defeated=yes

{STORY_A_HAUNTING_IN_WINTER}

{UNDERGROUND}

[time_area]
	x=12-24,12-21,12-20,14-18,16-18
	y=19-20,18,17,16,15
	{DAWN}
	{MORNING}
	{AFTERNOON}
	{DUSK}
	{FIRST_WATCH}
	{SECOND_WATCH}
[/time_area]

[side]
	side=1
	controller=human
	type=Apprentice Mage
	description=Malin Keshar
	user_description=_ "Malin Keshar"
	unrenamable=yes
	canrecruit=1
	recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul
	fog=yes
	shroud=yes
	gold=150
[/side]

[side]
	side=2
	controller=ai
	team_name=outlaws
	type=Dwarvish Steelclad
	description=Dap Horner
	user_description=_ "Dap Horner"
	canrecruit=1
	recruit=Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer
	{GOLD 0 20 40}
	fog=yes
	shroud=no
	[ai]
		agression=0.6
		grouping=offensive
		recruitment_pattern=mixed fighter,fighter 
	[/ai]
[/side]

[side]
	side=3
	controller=ai
	team_name=outlaws
	type=Bandit
	description=Gorak Cole
	user_description=_ "Gorak Cole"
	canrecruit=1
	recruit=Footpad,Poacher,Thug,Thief
	{GOLD 60 80 100} 
	fog=yes
	shroud=no
	[ai]
		aggression=0.7
	[/ai]
[/side]

[side]
	side=4
	controller=ai
	team_name=free undead
	no_leader=yes
	fog=no
	shroud=no
	# kamikaze.py heads straight for the leader of side 1 and attacks
	[ai]
		ai_algorithm=python_ai
		python_script="../campaigns/Descent_Into_Darkness/ais/kamikaze.py"
	[/ai]
[/side]

[event]
	name=prestart
	[music]
		name=underground.ogg
	[/music]	
	
	[objectives]
		side=1
		[objective]
			condition=win
			description=_ "Clear the cave of enemies"
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Malin Keshar"
		[/objective]
		[objective]
			condition=lose
			description=_ "Death of Darken Volk"
		[/objective]
	[/objectives]
	
	# Set outlaw villages
	{SET_VILLAGE 2 28 1}
	{SET_VILLAGE 2 23 7}
	{SET_VILLAGE 2 29 8}
	{SET_VILLAGE 2 28 10}
	
	{SET_VILLAGE 3 12 15}
	{SET_VILLAGE 3 9 18}
	{SET_VILLAGE 3 9 20}
   {SET_VILLAGE 3 10 10}
	
	# Set dwarf watchman
	{UNIT (Dwarvish Guardsman) Watchman (_ "Watchman") 2 14 12}
	
	# Ghost variable
	{VARIABLE ghost_was_freed no}
	
	# Set ghost leader rebellion turn
	[set_variable]
		name=free_ghost_turn
		random=5,6,7,8,9,10,11,12,14,15,16
	[/set_variable]
[/event]

[event]
	name=start
	[recall]
		description=Darken Volk
	[/recall]

	{DIALOGUE_AHIW_START}
[/event]

# In-scenario events
[event]
	name=sighted
	[filter]
		side=2
	[/filter]
	[filter_second]
		side=1
	[/filter_second]
	[scroll_to]
		x,y=$x1,$y1
	[/scroll_to]
	[delay]
		time=250
	[/delay]
	{DIALOGUE_AHIW_DWARVES1}
	[scroll_to]
		x,y=$x1,$y1
	[/scroll_to]
	{DIALOGUE_AHIW_DWARVES2}
[/event]

[event]
	name=new turn
	first_time_only=no
	[if]
		# Reach or pass ghost turn, and ghost wasn't already freed
		[have_unit]
			type=Ghost
		[/have_unit]
		[variable]
			name=free_ghost_turn
			less_than_equal_to=$turn_number
		[/variable]
		[variable]
			name=ghost_was_freed
			equals=no
		[/variable]
		[then]
			# Set free the ghost event
			[event]
				name=side turn
				first_time_only=yes
				{MODIFY_ONE_UNIT type=Ghost side 4}
				{MODIFY_ONE_UNIT side=4 description (Tortured Soul)}
				{MODIFY_ONE_UNIT side=4 user_description (_ "Tortured Soul")}
				{MODIFY_ONE_UNIT side=4 canrecruit 1}
				{VARIABLE ghost_was_freed yes}
				{DIALOGUE_AHIW_GHOST}
			[/event]
		[/then]
	[/if]
[/event]

# When the free ghost leader is around, one random unit per turn is freed
[event]
	name=new turn
	first_time_only=no
	[if]
		[have_unit]
			side=4
			canrecruit=1
		[/have_unit]
		[then]
{MODIFY_ONE_UNIT (race=undead
side=1) side 4}
		[/then]
	[/if]
[/event]

[event]
	name=die
	[filter]
		side=4
		canrecruit=1
	[/filter]
	# Regain control of "rebel" ghosts
	{MODIFY_UNIT (side=4
canrecruit=0) side 1}
	{DIALOGUE_AHIW_GHOSTDIE}
[/event]

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

# Victory Condition
[event]
	name=enemies defeated
	[endlevel]
		bonus=yes
		result=victory
	[/endlevel]
[/event]

[event]
	name=victory
	{CLEAR_VARIABLE free_ghost_turn}
	{CLEAR_VARIABLE ghost_was_freed}
[/event]

[/scenario]
