[scenario]
	id=07_Crossroads
	#textdomain wesnoth-httt
	name= _ "Crossroads"
	map_data="{campaigns/Heir_To_The_Throne/maps/07_Crossroads.map}"
	{SCENARIO_MUSIC "battle.ogg"}
	{TURNS 39 36 33}

	next_scenario=08_The_Princess_of_Wesnoth

	[event]
	name=prestart
		[objectives]
		side=1
			[objective]
				description= _ "Defeat Kojun Herolm"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Konrad"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Delfador"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Kalenz"
				condition=lose
			[/objective]
		[/objectives]
	[/event]

	[story]
		[part]
		story= _ "Konrad, Delfador, and Kalenz swiftly rode east through the wilderlands of Wesnoth."
		background="maps/wesnoth-httt.jpg"
		show_title=no
		[/part]
		[part]
		story= _ "The queen's agents were still scouring the coastal regions, for news of Elensefar's rescue had not yet reached her."
		background="maps/wesnoth-httt.jpg"
		show_title=no
		[/part]
		[part]
		story= _ "Small as it was, Konrad's army avoided the notice of hostile eyes in the sparsely populated western countryside for a time. However, their luck did not hold."
		background="maps/wesnoth-httt.jpg"
		show_title=no
		[/part]
	[/story]

	{BIGMAP_CROSSROADS}

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

	[side]
	type=Commander
	description=Konrad
	user_description= _ "Konrad"
	unrenamable=yes
	side=1
	canrecruit=1
	controller=human
	{GOLD 300 200 200}
#ifdef EASY
	{INCOME 10 0 0}
	{STARTING_VILLAGES 1 10}
#endif
		[ai]
			passive_leader="yes"
			grouping="offensive"
			aggression="0.0"
			caution="-0.75"
			[protect_location]
				x=20
				y=28
				radius="12"
				value="20.0"
			[/protect_location]
			[protect_location]
				x=16
				y=17
				radius="12"
				value="10.0"
			[/protect_location]
			[protect_location]
				x=25
				y=10
				radius="10"
				value="10.0"
			[/protect_location]
			[target]
				description=Delfador
				value=3.0
			[/target]
			[protect_unit]
				description=Delfador
				radius=6
				value=20.0
			[/protect_unit]
			[protect_unit]
				description=Konrad
				radius=10
				value=20.0
			[/protect_unit]
			[target]
				description=Kalenz
				value=3.0
			[/target]
			[protect_unit]
				description=Kalenz
				radius=4
				value=20.0
			[/protect_unit]

			[avoid]
				x="9-23"
				y="1-9"
			[/avoid]
			[avoid]
				x="14-19"
				y="10-14"
			[/avoid]
			[avoid]
				x="20-40"
				y="16-24"
			[/avoid]
			{ATTACK_DEPTH 5 5 5}
		[/ai]
	[/side]

#define CROSSROADS_AI_PARAMS
		[ai]
		caution=1.0
		aggression=0.3
		passive_leader=yes
		{ATTACK_DEPTH 1 3 5}
		[/ai]
		[ai]
		time_of_day=dusk
		turns=8-100
		caution=0.25
		aggression=0.6
		[/ai]
		[ai]
		time_of_day=first_watch,second_watch
		caution=0.0
		aggression=1.0
		grouping=no
		[/ai]
#enddef

	[side]
	type=Orcish Warlord
	description=Kojun Herolm
	user_description= _ "Kojun Herolm"
	experience=0
	side=2
	controller=ai
	canrecruit=1
	recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll Whelp
	{GOLD 100 160 220}
	team_name=orcs
	{CROSSROADS_AI_PARAMS}
	[/side]

	[side]
	type=Orcish Warrior
	description=Mokho Kimer
	user_description= _ "Mokho Kimer"
	experience=0
	side=3
	controller=ai
	canrecruit=1
	recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll Whelp
	{GOLD 60 120 180}
	team_name=orcs
	{CROSSROADS_AI_PARAMS}
	[/side]

	#signs at the crossroads for decoration
	{PLACE_IMAGE scenery/signpost.png 16 16}

#define TRAP1 NUM
	{RANDOM $random_string}
	{VARIABLE_OP trapx{NUM} to_variable possible_ambush_locations[$random].x}
	{VARIABLE_OP trapy{NUM} to_variable possible_ambush_locations[$random].y}
	[event]
	name=moveto
		[filter]
		side=1
		x=$trapx{NUM}
		y=$trapy{NUM}
		[/filter]
		[unit]
		generate_description=yes
		side=2
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Orcish Archer
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
		[unit]
		generate_description=yes
		side=2
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Orcish Grunt
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
#ifdef HARD
		[unit]
		generate_description=yes
		side=2
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Orcish Archer
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
#endif
		[print]
		text=_"Ambushed!"
		red,green,blue=255,0,0
		size=32
		[/print]
	[/event]

	[event]
	name=victory
		{CLEAR_VARIABLE (trapx{NUM})}
		{CLEAR_VARIABLE (trapy{NUM})}
	[/event]
#enddef

#define TRAP2 NUM
	{RANDOM $random_string}
	{VARIABLE_OP trapx{NUM} to_variable possible_ambush_locations[$random].x}
	{VARIABLE_OP trapy{NUM} to_variable possible_ambush_locations[$random].y}
	[event]
	name=moveto
		[filter]
		side=1
		x=$trapx{NUM}
		y=$trapy{NUM}
		[/filter]
		[unit]
		generate_description=yes
		side=3
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Wolf Rider
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
		[unit]
		generate_description=yes
		side=3
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Troll Whelp
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
#ifdef NORMAL
		[unit]
		generate_description=yes
		side=3
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Orcish Archer
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
#endif
#ifdef HARD
		[unit]
		generate_description=yes
		side=3
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Orcish Archer
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]

		[unit]
		generate_description=yes
		side=3
		x=$trapx{NUM}
		y=$trapy{NUM}
		type=Troll Whelp
		[modifications]
			{TRAIT_LOYAL}
		[/modifications]
		[/unit]
#endif
		[print]
		text=_"Ambushed!"
		red,green,blue=255,0,0
		size=32
		[/print]
	[/event]
	[event]
	name=victory
		{CLEAR_VARIABLE (trapx{NUM})}
		{CLEAR_VARIABLE (trapy{NUM})}
	[/event]
#enddef

	[event]
	name=start
		[recall]
		description=Delfador
		[/recall]
		[recall]
		description=Kalenz
		[/recall]
		[message]
		description=Delfador
		message= _ "Here we come to the great cross-roads. We should go northeast."
		[/message]
		[message]
		description=Kalenz
		message= _ "Beware! These hills are not safe! The roads are important to Asheviere's strategy, and she has hired orcs to guard them. We shall have to fight to travel through."
		[/message]
		[message]
		description=Konrad
		message= _ "Then fight we shall. Fortunately, now that we have liberated Elensefar, they are providing what gold they can spare to help us swell our ranks with new recruits. Let it begin!"
		[/message]
	[/event]

	[event]
	name=start
		[store_locations]
		x=13-35,1-35
		y=3-16,17-30
		terrain=Hh, Gg^Vh, Mm
		variable=possible_ambush_locations
		[/store_locations]
		{VARIABLE_OP last_possibility to_variable possible_ambush_locations.length}
		{VARIABLE_OP last_possibility add -1}
		{VARIABLE_OP random_string format 0..$last_possibility}

		#25 ambushes total
		{TRAP1 0}
		{TRAP2 1}
		{TRAP1 2}
		{TRAP2 3}
		[if]
		[variable]
		name=warlord_count
		numerical_equals=3
		[/variable]
			[then]
			[/then]
			[else]
			{TRAP1 4}
			{TRAP2 5}
			{TRAP1 6}
			{TRAP2 7}
			{TRAP1 8}
			{TRAP2 9}
			{TRAP1 10}
			{TRAP2 11}
			{TRAP1 12}
			{TRAP2 13}
			[if]
			[variable]
			name=warlord_count
			numerical_equals=2
			[/variable]
				[then]
				[/then]
				[else]
				{TRAP1 14}
				{TRAP2 15}
				{TRAP1 16}
				{TRAP2 17}
				{TRAP1 18}
				{TRAP2 19}
				{TRAP1 20}
				{TRAP2 21}
				{TRAP1 22}
				{TRAP2 23}
				{TRAP1 24}
				[/else]
			[/if]
			[/else]
		[/if]
		{CLEAR_VARIABLE warlord_count}
		{CLEAR_VARIABLE possible_ambush_locations}
	[/event]

	[event]
	name=moveto
		[filter]
		side=1
		x,y=12,11
		[/filter]
		[move_unit_fake]
		type=Elvish Archer
		x=12,12,11
		y=14,13,13
		[/move_unit_fake]

		{UNIT (Elvish Archer) (Niodien) ( _ "Niodien") 1 11 13}

		[message]
		description=Niodien
		message= _ "Stay on the path! The hills here are not safe!"
		[/message]
	[/event]

	[event]
	name=moveto
		[filter]
		side=1
		x,y=3,15
		[/filter]
		[move_unit_fake]
		type=Elvish Fighter
		x=4,5,5
		y=16,16,15
		[/move_unit_fake]

		{UNIT (Elvish Fighter) (Loflar) ( _ "Loflar") 1 5 15}

		[message]
		description=Loflar
		message= _ "Beware the hills! There are many orcs in hiding, preparing to ambush you!"
		[/message]
	[/event]

	[event]
		name=moveto
		[allow_undo]
		[/allow_undo]
		[filter]
			side=1
			x=16
			y=16
		[/filter]
		[redraw]
		[/redraw]
		[message]
			speaker=narrator
			image="scenery/signpost.png"
			message= _ "NE - Dan'Tonk
SE - Fort Tahn"
		[/message]
		[message]
			description=Konrad
			message= _ "Dan'Tonk, we are so close to Weldyn."
		[/message]
		[message]
			description=Delfador
			message= _ "We dare not confront Asheviere yet. We must retrieve the Scepter of Fire and gather more allies in the north."
		[/message]
	[/event]

	[event]
	name=die
		[filter]
		description=Kojun Herolm
		[/filter]
		[endlevel]
		result=victory
		bonus=yes
		[/endlevel]
	[/event]

	[event]
	name=victory
		[message]
		description=Konrad
		message= _ "Victory is ours, men. Let us proceed northeast!"
		[/message]
		{CLEAR_VARIABLE last_possibility}
		{CLEAR_VARIABLE random_string}
	[/event]

{campaigns/Heir_To_The_Throne/utils/deaths.cfg}

[/scenario]
