#textdomain wesnoth-tutorial
{./utils.cfg}
# Comment this out for a faster (no-commentry) tutorial for testing.
{./2_Speaking.cfg}

#define BADGUY TYPE NAME LOC
[unit]
	description={NAME}
	generate_description=yes
	type={TYPE}
	x,y={LOC}
	moves=0
	side=2
	animate=yes
[/unit]
[redraw][/redraw]
#enddef

#define DEFEND_ISLAND
[if]
	{NUMEQ island_defended 0}
	{NUMEQ dumbo_dead 1}
[then]
	{VARIABLE island_defended 1}
	{LABEL (_"Patch of forest") 10,14}
	{TALK_ABOUT_LOC 10,14 (_"Now put an unwounded unit, preferably a fighter, in that patch of forest on the south-east of the island: a nice, defensible spot.")}
	{STUDENT (_"Can one unit survive against all those enemies?")}
	{TEACHER (_"With a little help, yes. If you move your Shaman next to the defending unit, it will heal it by 4 hitpoints per turn. Just be careful not to expose the Shaman to attack: it is fairly weak itself.")}
	{PRINT (_"Move a unit (fighter if possible) to the patch of forest")}
	[event]
		name=moveto
		[filter]
			x,y=10,14
		[/filter]
		{UNLABEL 10,14}
		{PRINT (_"Advance other units onto the island or to capture villages, then End Turn")}
		[allow_undo][/allow_undo]
	[/event]
[/then]
[/if]
#enddef

#define REFUND TYPE
[if]
	[variable]
		name={TYPE}
		equals=Elvish Fighter
	[/variable]
[then]
	[gold]
		amount=14
	[/gold]
[/then]
[else]
	[if]
		[variable]
			name={TYPE}
			equals=Elvish Archer
		[/variable]
	[then]
		[gold]
			amount=17
		[/gold]
	[/then]
	[else]
		[if]
			[variable]
				name={TYPE}
				equal=Elvish Shaman
			[/variable]
		[then]
			[gold]
				amount=15
			[/gold]
		[/then]
		[/if]
	[/else]
	[/if]
[/else]
[/if]
#enddef

#define IMPORTANT_UNIT UNIT
[if]
	# FIXME: Archer needs 44/35(intelligent), Fighter needs 38/30 (?)
	[or]
		[variable]
			name={UNIT}.type
			equals=Elvish Archer
		[/variable]
		[variable]
			name={UNIT}.experience
			greater_than=30
		[/variable]
	[/or]
	[or]
		[variable]
			name={UNIT}.type
			equals=Elvish Fighter
		[/variable]
		[variable]
			name={UNIT}.experience
			greater_than=29
		[/variable]
	[/or]
[then]
	{VARIABLE commented 0}
	{FOREACH galdrad_comments i}
		[if]
			[variable]
				name=galdrad_comments[$i].description
				equals=${UNIT}.description
			[/variable]
		[then]
			{VARIABLE commented 1}
		[/then]
		[/if]
	{NEXT i}
	{CLEAR_VARIABLE i}

	[if]
		{NUMEQ commented 0}
	[then]
		[store_unit]
			[filter]
				description=${UNIT}.description
			[/filter]
			variable=galdrad_comments
			mode=append
		[/store_unit]
		{TEACHER (_"That unit is about one kill (8 experience points) away from gaining a level! Do not let it die!")}
	[/then]
	[/if]
	{CLEAR_VARIABLE commented}
[/then]
[/if]
#enddef

#define DEFENDER_INJURED UNIT
[if]
	{NUMEQ {UNIT}.side 1}
	[variable]
		name={UNIT}.hitpoints
		less_than=19
	[/variable]
	[variable]
		name={UNIT}.hitpoints
		greater_than=0
	[/variable]
[then]
	{VARIABLE complained 0}

	# FIXME: If same unit gets attacked twice in same turn, this
	# does not seem to find it the second time. Some internal bug?

	{FOREACH unit_complained i}
		[if]
			[variable]
				name=unit_complained[$i].description
				equals=${UNIT}.description
			[/variable]
		[then]
			{VARIABLE complained 1}
		[/then]
		[/if]
	{NEXT i}

	[if]
		{NUMEQ complained 0}
	[then]
		[store_unit]
			[filter]
				description=${UNIT}.description
			[/filter]
			variable=unit_complained
			mode=append
		[/store_unit]
		[if]
			{NUMEQ complain_msg 2}
		[then]
			[message]
				speaker=second_unit
				message=_"I hope I get to retreat after this!"
			[/message]
			{VARIABLE_OP complain_msg add 1}
		[/then]
		[/if]

		[if]
			{NUMEQ complain_msg 1}
		[then]
			[message]
				speaker=second_unit
				message=_"One lucky attack by an Orcish Grunt and I'm done for!"
			[/message]
			{VARIABLE_OP complain_msg add 1}
		[/then]
		[/if]

		[if]
			{NUMEQ complain_msg 0}
		[then]
			[message]
				speaker=second_unit
				message=_"Ouch! I could use some healing in a village."
			[/message]
			{VARIABLE_OP complain_msg add 1}
		[/then]
		[/if]
	[/then]
	[/if]
	{CLEAR_VARIABLE i}
	{CLEAR_VARIABLE complained}
	{IMPORTANT_UNIT {UNIT}}
[/then]
[/if]
#enddef

#define CHECK_INCOME
[if]
	{NUMEQ income_exceeded 0}
[then]
	[store_side]
	[/store_side]
	[if]
		[variable]
			name=side.gold
			greater_than=13
		[/variable]
	[then]
		{VARIABLE income_exceeded 1}
		{STUDENT (_"I have $side.gold gold: enough to recruit!")}
		{TALK_ABOUT_LOC 9,15 (_"Yes, keep recruiting more units: I think you might need them!")}
	[/then]
	[/if]
	{CLEAR_VARIABLE side}
[/then]
[/if]
#enddef


[tutorial]
	id=2_Tutorial
	name=_ "Wesnoth Tutorial Part II"
	map_data="{campaigns/tutorial/maps/2_Tutorial.map}"
	turns=26

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

	[side]
		type=Fighter
		description=student
		user_description=_"Konrad"
		canrecruit=1
		side=1
		gold=123
		controller=human
		recruit=Elvish Fighter,Elvish Archer,Elvish Shaman
	[/side]

	[side]
		type=Orcish Warrior
		description=Thrag
		user_description= _ "Thrag"
		side=2
		canrecruit=1
		recruit=Orcish Grunt,Wolf Rider,Orcish Archer
		gold=0
		[ai]
			turns=1-6
			# When we unleash you, you *will* attack.
			aggression=1.0
			passive_leader=no
		[/ai]
	[/side]

	[side]
		no_leader=yes
		type=Elvish Captain
		description=Galdrad
		user_description= _ "Galdrad"
		side=3
		team_name=1
		controller=null
	[/side]

	[event]
		name=prestart
		[objectives]
			side=1
			[objective]
				description= _ "Defeat the Orc Leader"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Konrad"
				condition=lose
			[/objective]
			[objective]
				description= _ "Turns run out"
				condition=lose
			[/objective]
		[/objectives]

		[if]
			[variable]
				name=gender
				equals=female
			[/variable]
		[then]
			[store_unit]
				[filter]
					description=student
				[/filter]
				kill=yes
				variable=student_save
			[/store_unit]
			{VARIABLE student_x $student_save.x}
			{VARIABLE student_y $student_save.y}
			[unit]
				type=Fighteress
				side=1
				x,y=$student_x,$student_y
				description=student
				user_description= _"Li'sar"
				canrecruit=1
			[/unit]
			[objectives]
				side=1
				[objective]
					description= _ "Defeat the Orc Leader"
					condition=win
				[/objective]
				[objective]
					description= _ "Death of Li'sar"
					condition=lose
				[/objective]
				[objective]
					description= _ "Turns run out"
					condition=lose
				[/objective]
			[/objectives]
			[/then]
		[/if]

		[unit]
			description=Galdrad
			type=Elvish Captain
			x,y=11,3
			side=3
		[/unit]

		[unit]
			description=Dumbo
			generate_description=yes
			type=Orcish Grunt
			x,y=8,13
			side=2
			# Make sure the two archers can't take him out!
			[modifications]
				{TRAIT_RESILIENT}
			[/modifications]
		[/unit]
	[/event]

	[event]
		name=start

		{VARIABLE dumbo_dead 0}
		{VARIABLE villages_around_keep 0}
		{VARIABLE village_warn 0}
		{VARIABLE recruit_num 1}
		{VARIABLE income_exceeded 0}
		{STUDENT (_"Ho Galdrad! Has Delfador conjured something else to beat me with? A flock of scarecrows, perhaps?")}
		{GENDER ({TEACHER (_ "This is no game, Konrad! " +
			  _ "Orcs have encamped across the river. This is elven country: we Elves are fast and hard to hit in forests. They are fools to enter here. You must defeat their leader, so they never bother us again. I will advise you.")}) ({TEACHER (_ "This is no game, Li'sar! " +
			  _ "Orcs have encamped across the river. This is elven country: we Elves are fast and hard to hit in forests. They are fools to enter here. You must defeat their leader, so they never bother us again. I will advise you.")})}
		{STUDENT (_"What should I do?")}

		# Now we're into it... start music.
		{DEFAULT_MUSIC_PLAYLIST}

		{TALK_ABOUT Dumbo (_"First, we will have to deal with the Orcish Grunt stationed in the middle of the river. He should be little trouble.")}
		{TALK_ABOUT Thrag (_"By then, their leader will have recruited units to send against us, and the real fight will begin.")}
		{LABEL (_"SHALLOW") 19,16}
		{LABEL (_"SHALLOW") 18,16}
		{LABEL (_"SHALLOW") 18,14}
		{LABEL (_"SHALLOW") 19,15}
		{LABEL (_"SHALLOW") 20,14}
		{LABEL (_"DEEP") 17,16}
		{LABEL (_"DEEP") 18,15}
		{LABEL (_"DEEP") 20,15}
		{LABEL (_"DEEP") 19,17}

		{TALK_ABOUT_LOC 19,14 (_"See this dark blue water: it is too deep for either side to cross. They could slowly wade through that narrow band of shallow lighter-blue water in the east, but we would stand on the shore and force them to fight us from the water, where they are exposed and we are protected by the forest.")}
		{UNLABEL 19,16}
		{UNLABEL 18,16}
		{UNLABEL 18,14}
		{UNLABEL 19,15}
		{UNLABEL 20,14}
		{UNLABEL 17,16}
		{UNLABEL 18,15}
		{UNLABEL 20,15}
		{UNLABEL 19,17}
		{LABEL (_"Village") 11,14}
		{TALK_ABOUT_LOC 9,14 (_"The more likely attack, then, is across the bridge. That middle island is the key: it has a village, for healing injured units, and forest in which we fight so well.")}
		{UNLABEL 11,14}
		{TEACHER (_"To start, we will need some units:
Two Elvish Fighters
Two Elvish Archers
One Elvish Shaman")}

		# See if there are two fighters worth recalling
		[store_unit]
			variable=recall
			[filter]
				type=Elvish Fighter
			[/filter]
		[/store_unit]

		# FIXME: Level 2 units should come first.
		{VARIABLE recall_xp1 0}
		{VARIABLE recall_xp2 0}
		{FOREACH recall i}
			{VARIABLE_OP temp_xp format $recall[$i].experience}
			[if]
				[variable]
					name=temp_xp
					greater_than=$recall_xp1
				[/variable]
			[then]
				# Move anything from slot 1 to slot 2
				[if]
					[variable]
						name=recall_xp1
						greater_than=0
					[/variable]
				[then]
					{VARIABLE_OP recall_i2 format $recall_i1}
					{VARIABLE_OP recall_xp2 format $recall_xp1}
				[/then]
				[/if]

				{VARIABLE_OP recall_i1 format $i}
				{VARIABLE_OP recall_xp1 format $temp_xp}
			[/then]
			[else]
				[if]
					[variable]
						name=temp_xp
						greater_than=$recall_xp2
					[/variable]
				[then]
					{VARIABLE_OP recall_i2 format $i}
					{VARIABLE_OP recall_xp2 format $temp_xp}
				[/then]
				[/if]
			[/else]
			[/if]
		{NEXT i}
		{CLEAR_VARIABLE i}

		[if]
			[variable]
				name=recall_xp1
				greater_than=0
			[/variable]
		[then]
			{VARIABLE_OP recall_name1 format $recall[$recall_i1].user_description}
			[if]
				[variable]
					name=recall_xp2
					greater_than=0
				[/variable]
			[then]
				{VARIABLE_OP recall_name2 format $recall[$recall_i2].user_description}
				# We have two worth recalling.
				{TEACHER (_"During your tutorial, $recall_name1 gained $recall_xp1 experience points, and $recall_name2 gained $recall_xp2. You should recall them now so they can gain more experience, rather than recruiting new ones.")}
			[/then]
			[else]
				# We have one worth recalling.
				{TEACHER (_ "During your tutorial, $recall_name1 gained $recall_xp1 experience points. You should recall that unit now, and recruit a second one (which is cheaper than recalling, anyway).")}
			[/else]
			[/if]
			{LABEL (_"RECALL $recall_name1") 10,4}
			{PRINT (_"Right click on the tile south of you and recall $recall_name1")}
		[/then]
		[else]
			[if]
				[variable]
					name=recall.length
					greater_than=0
				[/variable]
			[then]
				{TEACHER (_"If any Elvish Fighters from your last battle had experience, we would recall them: as they don't, it's cheaper to recruit new ones. So recruit an Elvish Fighter.")}
			[/then]
			[else]
				{TEACHER (_"If you had any experienced units alive from your last battle we would recall them, instead we must recruit a new Elvish Fighter.")}
			[/else]
			[/if]
			{LABEL (_"Elvish Fighter") 10,4}
			{PRINT (_"Right click on the tile south of you and recruit an Elvish Fighter")}
		[/else]
		[/if]
	[/event]

	# Check they recall/recruit correctly in their first turn.
	[event]
		name=recruit
		first_time_only=no
		[filter]
			side=1
		[/filter]

		# What did they recruit?
		[store_unit]
			variable=recruit
			[filter]
				x,y=$x1,$y1
			[/filter]
		[/store_unit]

		[if]
			{NUMEQ recruit_num 5}
		[then]
			[if]
				[variable]
					name=recruit.type
					not_equals=Elvish Shaman
				[/variable]
			[then]
				{REFUND recruit.type}
				[kill]
					x,y=$x1,$y1
				[/kill]
				{TEACHER (_"No! I said recruit an Elvish SHAMAN! Now try again...")}
			[/then]
			[else]
				{VARIABLE_OP recruit_num add 1}
				{UNLABEL 10,2}
				{CLEAR_PRINT}
				{TEACHER (_"The Shaman is a fairly weak unit, but has the ability to heal units around it. It also has a special attack which slows enemies, halving the damage they do!")}
				{STUDENT (_"So, should I end my turn now?")}
				# FIXME: If any level 2 units, costs will be higher.
				{TEACHER (_"It's true, none of your recruited units can move, but you still can. Your five units cost you 5 gold, leaving you 3 gold pieces poorer per turn. You need more income.")}
				{GENDER ({PRINT (_"Move Konrad to capture a village")})
					({PRINT (_"Move Li'sar to capture a village")})}
			[/else]
			[/if]
		[/then]
		[/if]

		[if]
			{NUMEQ recruit_num 4}
		[then]
			[if]
				[variable]
					name=recruit.type
					not_equals=Elvish Archer
				[/variable]
			[then]
				{REFUND recruit.type}
				[kill]
					x,y=$x1,$y1
				[/kill]
				{TEACHER (_"No! I said recruit an Elvish ARCHER! Now try again...")}
			[/then]
			[else]
				{VARIABLE_OP recruit_num add 1}
				[kill]
					x,y=$x1,$y1
				[/kill]
				[unit]
					description=Eowynial
					user_description=_"Eowynial"
					type=Elvish Archer
					x,y=$x1,$y1
					side=1
					gender=female
					upkeep=full
					moves=0
					[modifications]
						{TRAIT_QUICK}
						{TRAIT_RESILIENT}
					[/modifications]
				[/unit]
				{EXPLAIN_QUICK_RESILIENT (_"Eowynial")}

				{UNLABEL 9,4}
				{UNLABEL 9,3}
				{LABEL (_"Shaman") 10,2}
				{PRINT (_"Recruit an Elvish Shaman to your north")}
			[/else]
			[/if]
		[/then]
		[/if]

		[if]
			{NUMEQ recruit_num 3}
		[then]
			[if]
				[variable]
					name=recruit.type
					not_equals=Elvish Archer
				[/variable]
			[then]
				{REFUND recruit.type}
				[kill]
					x,y=$x1,$y1
				[/kill]
				{TEACHER (_"No! I said recruit an Elvish ARCHER! Now try again...")}
			[/then]
			[else]
				{VARIABLE_OP recruit_num add 1}
				[kill]
					x,y=$x1,$y1
				[/kill]
				[unit]
					description=Elriend
					user_description=_"Elriend"
					type=Elvish Archer
					x,y=$x1,$y1
					side=1
					upkeep=full
					moves=0
						[modifications]
						{TRAIT_STRONG}
						{TRAIT_INTELLIGENT}
					[/modifications]
				[/unit]
				{EXPLAIN_STRONG_INTELLIGENT (_"Elriend")}
			[/else]
			[/if]
		[/then]
		[/if]

		[if]
			{NUMEQ recruit_num 2}
		[then]
			[if]
				[variable]
					name=recall_xp2
					greater_than=0
				[/variable]
			[then]
				# You were supposed to recall $recall_name2.
				[if]
					[variable]
						name=recruit.user_description
						not_equals=$recall_name2
					[/variable]
				[then]
					# FIXME: Did they recruit, or recall?
					{REFUND recruit.type}
					[kill]
						x,y=$x1,$y1
					[/kill]
					{TEACHER (_"No! I said RECALL $recall_name2|! Now try again...")}
				[/then]
				[else]
					{VARIABLE_OP recruit_num add 1}
					{UNLABEL 11,4}
					{LABEL (_"Archer #1") 9,4}
					{LABEL (_"Archer #2") 9,3}
					{PRINT (_"Recruit two Elvish Archers in tiles to your west")}
				[/else]
				[/if]
			[/then]
			[else]
				# You were supposed to recruit a Fighter.
				[if]
					[variable]
						name=recruit.type
						not_equals=Elvish Fighter
					[/variable]
				[then]
					{REFUND recruit.type}
					[kill]
						x,y=$x1,$y1
					[/kill]
					{TEACHER (_"No! I said recruit an Elvish FIGHTER! Now try again...")}
				[/then]
				[else]
					{VARIABLE_OP recruit_num add 1}

					[kill]
						x,y=$x1,$y1
					[/kill]
					[unit]
						description=Golir
						user_description=_"Golir"
						type=Elvish Fighter
						x,y=$x1,$y1
						side=1
						upkeep=full
						moves=0
						[modifications]
							{TRAIT_QUICK}
							{TRAIT_RESILIENT}
						[/modifications]
					[/unit]
					{EXPLAIN_QUICK_RESILIENT (_"Golir")}

					{UNLABEL 11,4}
					{LABEL (_"Archer #1") 9,4}
					{LABEL (_"Archer #2") 9,3}
					{PRINT (_"Recruit two Elvish Archers in tiles to your west")}
				[/else]
				[/if]
			[/else]
			[/if]
		[/then]
		[/if]

		[if]
			{NUMEQ recruit_num 1}
		[then]
			[if]
				[variable]
					name=recall_xp1
					greater_than=0
				[/variable]
			[then]
				# You were supposed to recall $recall_name1.
				[if]
					[variable]
						name=recruit.user_description
						not_equals=$recall_name1
					[/variable]
				[then]
					[if]
						[variable]
							name=recruit.user_description
							equals=$recall_name2
						[/variable]
					[then]
						[gold]
							amount=20
						[/gold]
						[store_unit]
							variable=unrecall
							[filter]
								x,y=$x1,$y1
							[/filter]
							kill=yes
						[/store_unit]
						{VARIABLE unrecall.x 0}
						{VARIABLE unrecall.y 0}
						[unstore_unit]
							variable=unrecall
						[/unstore_unit]
						{CLEAR_VARIABLE unrecall}
						{TEACHER (_"No! I said recall $recall_name1, not $recall_name2|! Now try again...")}
					[/then]
					[else]
						{REFUND recruit.type}
						{TEACHER (_"No! I said RECALL $recall_name1 from the last battle, not recruit a new $recruit.type|! Now try again...")}
						[kill]
							x,y=$x1,$y1
						[/kill]
					[/else]
					[/if]
				[/then]
				[else]
					{VARIABLE_OP recruit_num add 1}
					{UNLABEL 10,4}

					[if]
						[variable]
							name=recall_xp2
							greater_than=0
						[/variable]
					[then]
						{PRINT (_"Right click on the tile south-east of you and recall $recall_name2")}
						{LABEL (_"RECALL $recall_name2") 11,4}
					[/then]
					[else]
						{LABEL (_"Elvish Fighter") 11,4}
						{PRINT (_"Right click on the tile south-east of you and recruit an Elvish Fighter")}
					[/else]
					[/if]
				[/else]
				[/if]
			[/then]
			[else]
				# You were supposed to recruit a new fighter.
				# FIXME: How do we tell if they recalled instead?
				[if]
					[variable]
						name=recruit.type
						not_equals=Elvish Fighter
					[/variable]
				[then]
					{REFUND recruit.type}
					{TEACHER (_"$recruit.type|? I said RECRUIT a new ELVISH FIGHTER. Now try again...")}
					[kill]
						x,y=$x1,$y1
					[/kill]
				[/then]
				[else]
					{UNLABEL 10,4}
					{VARIABLE_OP recruit_num add 1}

					[kill]
						x,y=$x1,$y1
					[/kill]
					[unit]
						description=Elindel
						user_description=_"Elindel"
						type=Elvish Fighter
						x,y=$x1,$y1
						side=1
						upkeep=full
						moves=0
						[modifications]
							{TRAIT_STRONG}
							{TRAIT_INTELLIGENT}
						[/modifications]
					[/unit]
					{EXPLAIN_STRONG_INTELLIGENT (_"Elindel")}
					{LABEL (_"Elvish Fighter") 11,4}
					{PRINT (_"Right click on the tile south-east of you and recruit an Elvish Fighter")}
				[/else]
				[/if]
			[/else]
			[/if]
		[/then]
		[/if]
		{CLEAR_VARIABLE recruit}
	[/event]

	[event]
		name=capture
		[filter]
			x=7,9,13
			y=4,2,3
			description=student
		[/filter]
		first_time_only=no

		[allow_undo][/allow_undo]
		# FIXME: If they somehow capture a village near keep, count could be wrong.
		{VARIABLE_OP villages_around_keep add 1}
		[if]
			{NUMEQ villages_around_keep 1}
		[then]
			# FIXME: Level 2 units change costs.
			{GENDER ({TEACHER (_"You've learned well, Konrad! " +
				  _ "The village supports one unit, and pays one gold per turn: you're only losing 1 gold per turn now.")})
				({TEACHER (_"You've learned well, Li'sar! " +
				  _ "The village supports one unit, and pays one gold per turn: you're only losing 1 gold per turn now.")})}
			{PRINT (_"End your turn")}
		[/then]
		[/if]
		[if]
			{NUMEQ villages_around_keep 3}
		[then]
			{TEACHER (_"You've captured all the villages around the keep, but stay near so you can recruit more units.")}
		[/then]
		[/if]
	[/event]

	[event]
		name=capture
		[filter]
			x=7,9,13
			y=4,2,3
			side=1
			[not]
				description=student
			[/not]
		[/filter]
		{GENDER ({TEACHER (_"You should leave the villages near your keep for Konrad to capture, as he needs to stay nearby to recruit more units anyway.")})
			({TEACHER (_"You should leave the villages near your keep for Li'sar to capture, as she needs to stay nearby to recruit more units anyway.")})}
		{UNDO_REMINDER}
	[/event]

	[event]
		name=turn 2
		{TALK_ABOUT Dumbo (_"Orcs have no ranged attack, so use your archers against it.")}

		{PRINT (_"Attack the Orc with an Archer (move mouse over units to see description on right)")}

		[event]
			name=moveto
			[filter]
				x=8,10
				y=8,8
			[/filter]
			{TEACHER (_"Excellent. Elves are well protected in the forest: there's only a 30% chance of hitting an Elven Archer when it's in forest.")}
		[/event]
		[event]
			name=moveto
			[filter]
				x,y=9,8
				side=1
			[/filter]
			[allow_undo][/allow_undo]
			{TEACHER (_"It's very dangerous to stand in water when there are enemies about! Your unit would have an 80% chance of being hit when the Orc counter-attacks! Cancel!")}
			{UNDO_REMINDER}
		[/event]

		[event]
			name=attack_end
			{PRINT (_"Attack the Orc with the other Archer")}

			# FIXME: Can't nest events of same type: they both fire 8(
			# So set up this event on next attack.
			[event]
				name=attack

				[event]
					name=attack_end

					{CLEAR_PRINT}
					{UNLABEL 14,3}
					{LABEL (_"Fighter to Here") 19,5}
					{TALK_ABOUT_LOC 19,5 (_"Your other units cannot reach that Orc this turn. Send a Fighter to that village to the far east: that will take two turns.")}
					{NARRATOR (_"You can make a unit keep moving for multiple turns: select the unit, then click on the target. You will see (2) if it will take two turns to reach it.")}
					{PRINT (_"Tell a Fighter to move to the far east village")}

					[event]
						name=moveto
						[filter]
							x=15-16
							y=1-6
						[/filter]

						{UNLABEL 19,5}
						{LABEL (_"Keep") 10,3}
						{TEACHER (_"Send the other Fighter and the Shaman south so they can attack next turn, then return to the keep to recruit more units!")}
						{GENDER ({PRINT (_"Move Fighter and Shaman south, then return Konrad to the Keep")})
							({PRINT (_"Move Fighter and Shaman south, then return Li'sar to the Keep")})}
					[/event]

					[event]
						name=moveto
						[filter]
							side=1
							x,y=10,3
						[/filter]
						{UNLABEL 10,3}
						{PRINT (_"Recruit another Archer and a Fighter")}
						{VARIABLE num_recruited 0}
					[/event]

					[event]
						name=recruit
						first_time_only=no
						[filter]
							side=1
						[/filter]
						{UNLABEL 10,4}
						{VARIABLE_OP num_recruited add 1}
						[if]
							{NUMEQ num_recruited 2}
						[then]
							{STUDENT (_"I have no more money to recruit!")}
							{TEACHER (_"This is often a problem, which is why owning villages is important.")}
							{GENDER ({PRINT (_"Move Konrad to another (unowned) village")})
								({PRINT (_"Move Li'sar to another (unowned) village")})}
						[/then]
						[/if]
					[/event]
					[event]
						name=moveto
						[filter]
							x=7,9,13
							y=4,2,3
							description=student
						[/filter]
						{PRINT (_"End your turn")}
					[/event]
				[/event]
			[/event]
		[/event]
	[/event]

	[event]
		name=turn 3

		{UNLABEL 10,4}
		{UNLABEL 11,4}

		# Explain: Zone of Control
		{TALK_ABOUT Dumbo (_"The Orc is blocking the bridge! We must occupy that island before the wolf riders reach it.")}
		{STUDENT (_"Can't our units just move around him?")}

		# All around Dumbo (9,14)
		{LABEL (_"ZoC") 10,14}
		{LABEL (_"ZoC") 8,14}
		{LABEL (_"ZoC") 9,13}
		{LABEL (_"ZoC") 9,15}
		{LABEL (_"ZoC") 10,13}
		{LABEL (_"ZoC") 8,13}
		# FIXME: Figure out best unit choice.
		{TALK_ABOUT Dumbo (_"No: once you move close to an enemy unit, you are in it's 'Zone of Control', and cannot move further that turn.
To move your troops onto that island without wading slowly through the water, you'll have to kill him.")}
		{PRINT (_"Attack the Orc with an Archer")}
		{UNLABEL 10,14}
		{UNLABEL 8,14}
		{UNLABEL 9,15}
		{UNLABEL 9,13}
		{UNLABEL 10,13}
		{UNLABEL 8,13}

		[event]
			name=attack_end

			{CLEAR_PRINT}
			# This happens before kill event, so we must do this the hard way.
			[store_unit]
				variable=dumbo
				[filter]
					description=Dumbo
				[/filter]
			[/store_unit]
			[if]
				{NUMEQ dumbo.hitpoints 0}
			[then]
				{PRINT (_"Advance other units and capture villages, then End Turn")}
			[/then]
			[else]
				# FIXME: use name of unit doing attack.
				{STUDENT (_"No other units can reach that Orc: I hope my archer survives its counter-attack! I'd better grab more villages, and move everyone closer for next turn.")}
				{TEACHER (_"Yes. If your Shaman stands just behind that unit on the bridge, it will heal it at the beginning of next turn, too.")}
				{PRINT (_"Move Shaman onto bridge to stand behind unit")}
				[event]
					name=moveto
					[filter]
						type=Elvish Shaman
					[/filter]
					{PRINT (_"Advance other units and capture villages, then End Turn")}
				[/event]
			[/else]
			[/if]
			{CLEAR_VARIABLE dumbo}
		[/event]
	[/event]

	[event]
		name=die
		[filter]
			description=Dumbo
		[/filter]
		{VARIABLE dumbo_dead 1}
		# Only tell them to defend island if not turn 3.
		[if]
			[variable]
				name=turn_number
				greater_than=3
			[/variable]
		[then]
			{DEFEND_ISLAND}
		[/then]
		[/if]

		[event]
			name=moveto
			[filter]
				x=9,9,9
				y=15,16,17
				side=1
			[/filter]

			[allow_undo][/allow_undo]
			[if]
				[variable]
					name=turn_number
					less_than=8
				[/variable]
			[then]
				{TALK_NO_MOVE (_"Be careful: if you stand on the bridge you are exposed to attack from multiple directions!")}
				{UNDO_REMINDER}
			[/then]
			[/if]
		[/event]

		[event]
			name=moveto
			[filter]
				x=8,10,18,19,20,11
				y=14,15,14,15,14,15
				side=1
			[/filter]
			{TEACHER (_"It's very dangerous to stand in water when there are enemies about! Your unit would have an 80% chance of being hit! Cancel, and wait for them to attack you!")}
			{UNDO_REMINDER}
			[allow_undo][/allow_undo]
		[/event]
	[/event]

	[event]
		name=turn 4

		{CLEAR_PRINT}
		{TALK_ABOUT_LOC 19,5 (_"Don't forget about your fighter in the east: you can move him south to that last village near the channel.")}
		[allow_undo][/allow_undo]

		[if]
			{NUMEQ dumbo_dead 0}
		[then]
			# FIXME: Which unit? Is it really wounded?
			{TALK_ABOUT Dumbo (_"We need to take that village on the island, otherwise they will take it next turn! Move your wounded unit to take it so it can heal, then kill that Orc!")}
		[/then]
		[else]
			{DEFEND_ISLAND}
		[/else]
		[/if]
	[/event]

	[event]
		name=turn 5

		{DEFEND_ISLAND}
		{TALK_ABOUT_LOC 11,14 (_"Careful! It is now nighttime. Orcs are chaotic: their attacks are 25% stronger at night, 25% weaker in the day. You are lawful: stronger by day. Elves are neutral: we are unaffected by night and day.")}
		{NARRATOR (_"After this dialog, hold the mouse over the image below the map on the right, to see a description of the time of day.")}
	[/event]

	[event]
		name=turn 6

		{CHECK_INCOME}
		{TALK_ABOUT_LOC 9,15 (_"Remember to retreat your wounded units to villages. Healers can only heal 4 hitpoints at a time, villages can heal 8 (the maximum for any unit).")}
	[/event]

	[event]
		name=turn 7

		{CHECK_INCOME}
		{LABEL (_"Defend here") 19,14}
		{TALK_ABOUT_LOC 19,16 (_"Beware those Orcs crossing the river! If they get into the forest they'll be hard to dislodge!")}
	[/event]

	[event]
		name=turn 9
		{UNLABEL 19,14}
		{NARRATOR (_"You can make sure you've used all your units for this turn: press 'n' for the next unit, SPACE to indicate it's finished.
When 'n' no longer selects a new unit, you can end your turn.")}
	[/event]

	[event]
		name=turn 10
		{NARRATOR (_"You only need to defeat the leader to win: see Main Menu->Objectives.")}
	[/event]

	[event]
		name=turn 12
		{NARRATOR (_"Remember to recruit more troops as you need them: Archers are particularly effective against Grunts, Wolf Riders and their leader.")}
	[/event]

	# Remind them to keep back
	[event]
		name=moveto
		[filter]
			description=student
			x=1-20
			y=6-20
		[/filter]

		[if]
			[variable]
				name=turn_number
				less_than=8
			[/variable]
		[then]
			{TEACHER (_"Stay near the keep: you need to be on a keep to recruit more units, and I doubt the Orc leader will let you use his!")}
		[/then]
		[/if]
		[allow_undo][/allow_undo]
	[/event]

	[event]
		name=moveto
		[filter]
			description=Thrag
			x=5,14,19
			y=19,19,23
		[/filter]

		{TALK_ABOUT Thrag (_"Their leader has moved into that village! He's not as stupid as I thought: it heals him each turn and provides good defense.")}
	[/event]

	[event]
		name=moveto
		[filter]
			side=2
			x=11,6,11
			y=14,10,10
		[/filter]

		{TALK_ABOUT_LOC ($x1,$y1) (_"That unit has captured our village! You'd better get him out: it heals him each turn and provides good defense.")}
	[/event]

	# Warn about using shaman to attack.
	[event]
		name=attack
		[filter]
			type=Elvish Shaman
		[/filter]

		[message]
			speaker=unit
			message=_ "Using me to attack is risky! I can slow the opponent with my ranged attack, but I hope you have a plan if I miss!"
		[/message]
	[/event]

	[event]
		name=attack_end
		first_time_only=no

		[store_unit]
			variable=attacker
			[filter]
				x,y=$x1,$y1
			[/filter]
		[/store_unit]
		[store_unit]
			variable=defender
			[filter]
				x,y=$x2,$y2
			[/filter]
		[/store_unit]

		{DEFENDER_INJURED defender}
		{IMPORTANT_UNIT attacker}

		[if]
			[variable]
				name=attacker.description
				equals=Thrag
			[/variable]
			[variable]
				name=attacker.hitpoints
				less_than=21
			[/variable]
			{NUMEQ talk_about_killing_thrag 0}
		[then]
			{VARIABLE talk_about_killing_thrag 1}
			{TALK_ABOUT Thrag (_"You are close to killing their leader! The unit which finishes him will gain 16 experience points, because he is level 2. Choose your unit carefully!")}
		[/then]
		[/if]

		[if]
			[variable]
				name=defender.description
				equals=Thrag
			[/variable]
			[variable]
				name=defender.hitpoints
				less_than=21
			[/variable]
			{NUMEQ talk_about_killing_thrag 0}
		[then]
			{VARIABLE talk_about_killing_thrag 1}
			{TALK_ABOUT Thrag (_"You are close to killing their leader! The unit which finishes him will gain 16 experience points, because he is level 2. Choose your unit carefully!")}
		[/then]
		[/if]
		{CLEAR_VARIABLE attacker}
		{CLEAR_VARIABLE defender}
	[/event]

	[event]
		name=die
		first_time_only=no
		[filter]
			side=1
		[/filter]

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

		[if]
			[or]
				[variable]
					name=deadguy.type
					equals=Elvish Fighter
				[/variable]
			[/or]
			[or]
				[variable]
					name=deadguy.type
					equals=Elvish Archer
				[/variable]
			[/or]
		[then]
			[if]
				[variable]
					name=deadguy.experience
					greater_than=20
				[/variable]
			[then]
				{TEACHER (_"We will miss $deadguy.user_description|, and he had $deadguy.experience experience points, meaning he would have advanced to level 2 soon.")}
			[/then]
			[else]
				[if]
					[variable]
						name=deadguy.experience
						less_than=8
					[/variable]
				[then]
					{TEACHER (_"We will miss $deadguy.user_description|, but better than one of our experienced troops dying!")}
				[/then]
				[/if]
			[/else]
			[/if]
		[/then]
		[else]
			[if]
				[variable]
					name=deadguy.type
					equals=Elvish Shaman
				[/variable]
			[then]
				{TEACHER (_"Losing a healer hurts all the troops! Keep them out of the enemy's reach!")}
				{NARRATOR (_"You can see where an enemy could reach by moving the mouse over them. You can see all the possible enemy moves at once with 'Show Enemy Moves' from the 'Actions' menu.")}
			[/then]
			[else]
				# Must be level 2 unit.
				{TEACHER (_"Level 2 units are powerful, but not invulnerable! Goodbye, $deadguy.user_description|.")}
			[/else]
			[/if]
		[/else]
		[/if]
		{CLEAR_VARIABLE deadguy}
	[/event]

	[event]
		name=moveto
		[filter]
			side=1
			x=1-13
			y=18-21
		[/filter]
		{TALK_ABOUT Thrag (_"Beware the leader: he can do 36 hitpoints damage at night! Attack with many units at once, during the day.")}
	[/event]

	[event]
		name=post_advance
		[filter]
			side=1
			type=Elvish Marksman
		[/filter]
		# FIXME: Abilities.
		[message]
			speaker=unit
			message=_"Advancing a level has fully healed me!
I always have a 60% chance of hitting with my bow, and 9 hitpoints damage on each of the four attacks. Use me to dislodge hard-to-hit units."
		[/message]
	[/event]
	[event]
		name=post_advance
		[filter]
			side=1
			type=Elvish Ranger
		[/filter]
		[message]
			speaker=unit
			message=_"Advancing a level has fully healed me!
I am good with both bow and sword, but I have a special ability: ambush. I can hide in forests, and enemies can only see me if they are right next to me."
		[/message]
	[/event]
	[event]
		name=post_advance
		[filter]
			side=1
			type=Elvish Captain
		[/filter]
		[message]
			speaker=unit
			message=_"Advancing a level has fully healed me!
I am good with both bow and sword, but I have a special ability: leadership. Level 1 units around me do 25% more damage, so position me carefully."
		[/message]
	[/event]
	[event]
		name=post_advance
		[filter]
			side=1
			type=Elvish Hero
		[/filter]
		# FIXME: Abilities
		[message]
			speaker=unit
			message=_"Advancing a level has fully healed me!
I am particularly good with the sword: four attacks doing 8 damage each."
		[/message]
	[/event]

	# WE control the AI! Bwahahaha!
	[event]
		name=ai turn
		first_time_only=no
		{CLEAR_PRINT}
		[if]
			{NUMEQ turn_number 1}
		[then]
			# Advance sacrificial orc.
			{MOVE Dumbo 8 13 9 9}
			[scroll_to_unit]
				description=Thrag
			[/scroll_to_unit]
			{BADGUY (Wolf Rider) Scout1 17,24}
			{BADGUY (Wolf Rider) Scout2 18,23}
			{BADGUY (Wolf Rider) Scout3 19,24}
			{BADGUY (Wolf Rider) Scout4 17,25}
			{BADGUY (Wolf Rider) Scout5 18,25}
			# Leader moves to take village
			{MOVE Thrag 18 24 19 23}
			[capture_village]
				side=2
				x,y=19,23
			[/capture_village]
		[/then]
		[/if]
		[if]
			{NUMEQ turn_number 2}
		[then]
			# Orc runs away.
			{MOVE Dumbo 9 9 9 14}
			# Riders advance
			[scroll_to_unit]
				description=Thrag
			[/scroll_to_unit]
			{MOVE Scout1 17 24 13 20}
			{MOVE Scout2 18 23 12 19}
			{MOVE Scout3 19 24 14 20}
			{MOVE Scout4 17 25 10 24}
			{MOVE Scout5 18 25 14 19}
			[capture_village]
				side=2
				x,y=14,19
			[/capture_village]
			# Leader move to keep, recruits & advances
			{MOVE Thrag 19 23 18 24}
			{BADGUY (Orcish Grunt) Grunt1 18,23}
			{BADGUY (Orcish Grunt) Grunt2 17,24}
			{BADGUY (Orcish Archer) Archer1 19,24}
			{MOVE Thrag 18 24 16 20}
		[/then]
		[/if]
		[if]
			{NUMEQ turn_number 3}
		[then]
			{MOVE Scout1 13 20 8 18}
			{MOVE Scout2 12 19 7 18}
			{MOVE Scout3 14 20 9 18}
			{MOVE Scout4 10 24 9 26}
			[capture_village]
				side=2
				x,y=9,26
			[/capture_village]
			{MOVE Scout5 14 19 9 17}
			{MOVE Thrag 16 20 11 19}
			{MOVE Grunt1 18 23 15 20}
			{MOVE Archer1 19 24 16 20}
			{MOVE Grunt2 17 24 16 21}
		[/then]
		[/if]

		[if]
			{NUMEQ turn_number 4}
		[then]
			# Leave Scout1 and Scout2 to attack
			{MOVE Scout3 9 18 11 16}
			{MOVE Scout5 9 17 10 16}
			{MOVE Scout4 9 26 6 20}
			{MOVE Thrag 11 19 9 19}
			{MOVE Grunt1 15 20 11 19}
			{MOVE Archer1 16 20 18 17}
			{MOVE Grunt2 16 21 18 18}
		[/then]
		[/if]

		# From now on, we only control these two, down channel
		[if]
			{NUMEQ turn_number 5}
		[then]
			{MOVE Archer1 18 17 18 16}
			{MOVE Grunt2 18 18 18 17}
			# Leaders stays here, to shorten the scenario 8)
			{MOVE Thrag 9 19 9 19}
		[/then]
		[/if]

		[if]
			{NUMEQ turn_number 6}
		[then]
			{MOVE Archer1 18 16 19 16}
			{MOVE Grunt2 18 17 18 16}
			{MOVE Thrag 9 19 9 19}
		[/then]
		[/if]

		[if]
			{NUMEQ turn_number 7}
		[then]
			# Force grunt to advance if poss.
			[if]
				[not]
					[have_unit]
						x,y=19,16
					[/have_unit]
				[/not]
			[then]
				{MOVE Grunt2 18 16 19 16}
			[/then]
			[else]
				{MOVE Grunt2 18 16 18 16}
			[/else]
			[/if]
			{MOVE Thrag 9 19 9 19}
		[/then]
		[/if]

		[if]
			{NUMEQ turn_number 8}
		[then]
			# Force grunt to advance if poss.
			[if]
				[not]
					[have_unit]
						x,y=19,16
					[/have_unit]
				[/not]
			[then]
				{MOVE Grunt2 18 16 19 16}
			[/then]
			[else]
				{MOVE Grunt2 18 16 18 16}
			[/else]
			[/if]

			# We can now leader move IF they are on bridge
			[if]
				[not]
					[have_unit]
						side=1
						x=7-11
						y=16-21
					[/have_unit]
				[/not]
			[then]
				{MOVE Thrag 9 19 9 19}
			[/then]
			[/if]
		[/then]
		[/if]
	[/event]

	[event]
		name=time over
		{TEACHER (_"You took too long, we'll never be rid of these Orcs!")}
		[endlevel]
			result=defeat
		[/endlevel]
	[/event]

	[event]
		name=die
		[filter]
			description=student
		[/filter]
		[endlevel]
			result=defeat
		[/endlevel]
	[/event]

	[event]
	name=victory
	{TEACHER (_"You have been victorious over the Orcs.  Next, you may want to try one of the campaigns with a Beginner level, such as The South Guard, Two Brothers or Heir to The Throne. The South Guard was specifically designed as a beginner's campaign. Konrad, Li'sar and Delfador are characters from Heir To The Throne.")}
	[/event]
[/tutorial]
