[scenario]
	id=23_Test_of_the_Clans
	#textdomain wesnoth-httt
	name= _ "Test of the Clan"
	map_data="{campaigns/Heir_To_The_Throne/maps/23_Test_of_the_Clans.map}"
	{SCENARIO_MUSIC "northerners.ogg"}
	{TURNS 53 50 47}

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

	next_scenario=24_Battle_for_Wesnoth

	[event]
	name=prestart
		[objectives]
		side=1
			[objective]
				description= _ "Defeat 25 Units"
				condition=win
			[/objective]
			[objective]
				description= _ "Defeat Enemy Leaders (Bonus)"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Konrad"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Delfador"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Li'sar"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Kalenz"
				condition=lose
			[/objective]
			[objective]
				description= _ "Turns run out"
				condition=lose
			[/objective]
		[/objectives]
	[/event]

	{BIGMAP_TEST_OF_THE_CLANS}

	[side]
		team_name=elves
		type=Commander
		description=Konrad
		user_description= _ "Konrad"
		unrenamable=yes
		side=1
		canrecruit=1
		controller=human
	[/side]

	[side]
		team_name=clan
		type=Grand Knight
		description=Sir Alric
		user_description= _ "Sir Alric"
		side=2
		canrecruit=1
		recruit=Horseman,Knight,Bowman,Lancer
		[ai]
			recruitment_pattern=fighter,fighter,archer
			{ATTACK_DEPTH 5 5 6}
		[/ai]
		[ai]
			time_of_day=morning,afternoon
			grouping=offensive
			aggression=0.6
		[/ai]
		[ai]
			time_of_day=first_watch,second_watch
			aggression=0.4
			grouping=defensive
		[/ai]
		{GOLD 120 150 180}
		{INCOME 2 4 8}
	[/side]

	[side]
		team_name=clan
		type=Grand Knight
		description=Sir Ruga
		user_description= _ "Sir Ruga"
		side=3
		canrecruit=1
		recruit=Horseman,Knight,Bowman,Lancer
		[ai]
			recruitment_pattern=fighter,fighter,archer
			{ATTACK_DEPTH 5 5 6}
		[/ai]
		[ai]
			time_of_day=morning,afternoon
			grouping=offensive
			aggression=0.6
		[/ai]
		[ai]
			time_of_day=first_watch,second_watch
			aggression=0.4
			grouping=defensive
		[/ai]
		{GOLD 120 150 180}
		{INCOME 2 4 8}
	[/side]

	[side]
		team_name=clan
		type=Grand Knight
		description=Sir Daryn
		user_description= _ "Sir Daryn"
		side=4
		canrecruit=1
		recruit=Horseman,Knight,Bowman,Lancer
		[ai]
			recruitment_pattern=fighter,fighter,archer
			{ATTACK_DEPTH 5 5 6}
		[/ai]
		[ai]
			time_of_day=morning,afternoon
			grouping=offensive
			aggression=0.6
		[/ai]
		[ai]
			time_of_day=first_watch,second_watch
			aggression=0.4
			grouping=defensive
		[/ai]
		{GOLD 120 150 180}
		{INCOME 2 4 8}
	[/side]

	[side]
		team_name=clan
		type=Grand Knight
		description=Lord Bayar
		user_description= _ "Lord Bayar"
		side=5
		canrecruit=1
		recruit=Knight,Longbowman
		[ai]
			recruitment_pattern=fighter,fighter,archer
			{ATTACK_DEPTH 5 5 6}
		[/ai]
		[ai]
			time_of_day=morning,afternoon
			grouping=offensive
			aggression=0.6
		[/ai]
		[ai]
			time_of_day=first_watch,second_watch
			aggression=0.4
			grouping=defensive
		[/ai]
		{GOLD 140 170 200}
		{INCOME 4 8 12}
	[/side]

	[event]
	name=prestart
		{VARIABLE units_slain 0}
		{VARIABLE temp_clan_member_text (_"Clan Member Defeated")}
		[recall]
			description=Delfador
		[/recall]
		[recall]
			description=Kalenz
		[/recall]
		[recall]
			description=Li'sar
		[/recall]
	[/event]

	[event]
	name=start
		[message]
			description=Konrad
			message= _ "Greetings, men of the plains."
		[/message]
		[message]
			description=Sir Daryn
			message= _ "What do these intruders want? We did not invite them here, that is certain."
		[/message]
		[message]
			description=Delfador
			message= _ "We come in peace! We wish for you to aid us in our struggle against Asheviere, the evil Queen Mother."
		[/message]
		[message]
			description=Sir Alric
			message= _ "We will not join you. You who are led by these youths and this old man."
		[/message]
		[message]
			description=Delfador
			message= _ "You are for us or against us. If you do not join us to overthrow the evil Queen, we will strip you of your power, once the throne is rightfully reclaimed."
		[/message]
		[message]
			description=Lord Bayar
			message= _ "Hah! You think you can seize the throne? Defeat us in battle and we will join you, or leave now and never return!"
		[/message]
		[message]
			description=Kalenz
			message= _ "Very well. We will fight you."
		[/message]
		[message]
			description=Lord Bayar
			message= _ "Fools! We will run you down like dogs!"
		[/message]
		[message]
			description=Sir Alric
			message= _ "There is no turning back for you now. This is a fight to the death!"
		[/message]
		[music]
		name="battle.ogg"
		immediate=yes
		[/music]
	[/event]

	[event]
	name=turn 3
		[message]
			description=Konrad
			message= _ "Delfador, this is sheer madness. We cannot afford to play games when we should be marching against the Queen."
		[/message]
		[message]
			description=Konrad
			message= _ "Lord Bayar, halt this folly! I challenge you to a personal combat."
		[/message]
		[message]
			description=Lord Bayar
			message= _ "Ho! You have amused me, young heir. Ho, ho, challenge indeed."
		[/message]
		[message]
			description=Konrad
			message= _ "Young heir? Then you assent to my claim?"
		[/message]
		[message]
			description=Lord Bayar
			message= _ "Impudence. Bah! Do you see orcs on our plains? Did we not grant you a test of your strength?"
		[/message]
		[message]
			description=Konrad
			message= _ "I fail to see the purpose of this exercise. It only weakens us."
		[/message]
		[message]
			description=Lord Bayar
			message= _ "No, whelp. You may be weakened, but the horse clans are eternal. I will promise you this, however. If you can defeat me personally, I myself will join your siege of Weldyn."
		[/message]
		[message]
			description=Sir Ruga
			message= _ "Aye."
		[/message]
		[message]
			description=Sir Daryn
			message= _ "Aye."
		[/message]
		[message]
			description=Sir Alric
			message= _ "Aye."
		[/message]
	[/event]

	#
	# Lord Bayar dies - you get a bonus
	#
	[event]
	name=die
		[filter]
			description=Lord Bayar
		[/filter]

		{VARIABLE clan_bayar 1}

		[message]
			description=Lord Bayar
			message= _ "I cannot believe this! You have defeated me! You are now my liege, and I leave the battlefield in shame. But the Clan shall fight on!"
		[/message]
		[message]
			description=Delfador
			message= _ "Their leader has fallen but still they fight!"
		[/message]
	[/event]
	#
	# Sir Daryn dies - you get a bonus
	#
	[event]
	name=die
		[filter]
			description=Sir Daryn
		[/filter]

		{VARIABLE clan_daryn 1}

		[message]
			description=Sir Daryn
			message= _ "You can defeat me, but the Clan will never fall. Our numbers are endless!"
		[/message]
	[/event]
	#
	# Sir Ruga dies - you get a bonus
	#
	[event]
	name=die
		[filter]
			description=Sir Ruga
		[/filter]

		{VARIABLE clan_ruga 1}

		[message]
			description=Sir Ruga
			message= _ "Even as I pledge my lance to your service, my Clan fights on!"
		[/message]
	[/event]
	#
	# Sir Alric dies - you get a bonus
	#
	[event]
	name=die
		[filter]
			description=Sir Alric
		[/filter]

		{VARIABLE clan_alric 1}

		[message]
			description=Sir Alric
			message= _ "A humiliating defeat, yet you are no match for the might of the Clan!"
		[/message]
	[/event]

#define BONUS_VICTORY
	[if]
		[have_unit]
			description=Lord Bayar
			side=5
		[/have_unit]
		[then]
			[role]
				type=Grand Knight
				side=5
				role=clanboss
			[/role]
		[/then]
		[else]
			[role]
				type=Grand Knight
				side=5,4,3,2
				role=clanboss
			[/role]
		[/else]
	[/if]
	[message]
		role=clanboss
		message= _ "Stop! I cannot believe this! You have defeated us! Indeed, you are worthy, worthy even to claim the throne. The clans will help you. We will fight with you against the Queen."
	[/message]
	[message]
		description=Konrad
		message= _ "So you admit defeat! You will serve me in fighting the evil queen?"
	[/message]
	[message]
		role=clanboss
		message= _ "We will serve you, my lord. You will make a worthy king."
	[/message]


	[message]
		speaker=narrator
		image="wesnoth-icon.png"
		message= _ "The mighty riders of the eastern plains, the Knights of the Clans, are now yours to command!"
	[/message]
	[allow_recruit]
	type=Knight
	[/allow_recruit]


	[message]
		description=Li'sar
		message= _ "I think you are mistaken! You will help me be queen."
	[/message]
	[message]
		role=clanboss
		message= _ "Who then is your leader? Who do we serve?"
	[/message]
	[message]
		description=Delfador
		message= _ "You will serve us. You will protect our flanks while we make way straight for the queen. With you on either flank, we can surely overcome her."
	[/message]
	[message]
		description=Kalenz
		message= _ "Delfador, don't you think it is time we settled this?"
	[/message]
	[message]
		description=Delfador
		message= _ "Yes, it is time. It is time for the truth to be told. I had hoped to take this secret to my grave, but it isn't to be. You elves live too long, and though I have tried hard to understand, your wisdom is foreign to me."
	[/message]
	[message]
		description=Konrad
		message= _ "Secret? What secret Delfador? What are you talking about?"
	[/message]
	[message]
		description=Delfador
		message= _ "We should not speak of it now. Instead come with me, Konrad and Li'sar, to the top of mount Elnar. To look at Weldyn. To make plans for the battle, and to talk."
	[/message]
	[endlevel]
		result=victory
		bonus=yes
		{CLEAR_VARIABLE units_slain}
		{CLEAR_VARIABLE temp_clan_member_text}
	[/endlevel]
#enddef

	[event]
	name=die
	first_time_only=no
		[filter]
			side=2,3,4,5
		[/filter]

		{VARIABLE_OP units_slain add 1}
		{VARIABLE_OP temp_string format ($units_slain + " " + $temp_clan_member_text)}

		#
		# After the first execution of this event, this changes the text to plural
		#
		{VARIABLE temp_clan_member_text (_ "Clan Members Defeated")}

		[print]
			text=$temp_string
			size=18
			red,green,blue=255,255,255
		[/print]

		{CLEAR_VARIABLE temp_string}

		[if]
			[variable]
				name=units_slain
				numerical_equals=25
			[/variable]

			[then]
				[message]
					description=Delfador
					message= _ "We are routing their forces! Let's see if the Clan has had enough. Their help in guarding our flanks will be invaluable."
				[/message]
				{BONUS_VICTORY}
			[/then]
		[/if]
	[/event]

	[event]
	name=enemies defeated
		#
		# Re-create Lord Bayar so he can talk. He's not dead; he's just out of commission.
		#
		{UNIT (Grand Knight) (Lord Bayar) (_ "Lord Bayar") 5 8 54}
		{BONUS_VICTORY}
	[/event]

	{campaigns/Heir_To_The_Throne/utils/deaths.cfg}

[/scenario]
