[scenario]
	id=8b_The_Tides_of_War
	#textdomain wesnoth-tsg

	name= _ "The Tides of War"
	next_scenario=9b_Bandit_Epilogue
	[music]
		name=main_menu_new.ogg
		ms_before=500
	[/music]
	[music]
		name=gameplay03.ogg
		ms_before=500
		append=yes
	[/music]


	{SG_MAP 8b_The_Tides_of_War}
	{@campaigns/The_South_Guard/utils/sg_deaths.cfg}

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

	victory_when_enemies_defeated=yes
	turns=60


# The South Guard

[side]
	side=1
	type=Horseman Commander
	description=Deoran
	user_description= _ "Deoran"
	unrenamable=yes

	team_name=South_Guard
	controller=human
	{CUSTOM_SG_FLAG}


	{GOLD 125 100 80}
	{INCOME 4 2 0}

	fog=no
	shroud=no

	canrecruit=1
	recruit=Peasant,Bowman,Spearman,Cavalryman,Footpad,Thug
[/side]

# The Undead Hordes

[side]
	side=2
	type=Ancient Lich
	description=Mal Feras
	user_description= _ "Mal Feras"

	team_name=The_Undead_Hordes
	controller=ai

	{GOLD 150 250 350}
	{INCOME 30 40 50}

	canrecruit=1
	[ai]
		recruitment_pattern=scout,fighter,fighter,archer,scout,fighter,archer
		aggression=1.0
		caution=0.0
		[target]
			description=Deoran
			value=6.0
		[/target]
	[/ai]
	recruit=Ghost,Wraith,Shadow,Skeleton,Revenant,Draug,Skeleton Archer,Bone Shooter,Vampire Bat,Blood Bat,Chocobone,Dark Adept,Dark Sorcerer

[/side]

#prestart
	[event]
		name=prestart

		#Set the amount of gold that the player has to what it was before Pebbles.
		[gold]
			side=1
			amount=$pebbles_starting_gold
		[/gold]
		{CLEAR_VARIABLE pebbles_starting_gold}

		# Make Deoran the leader again.
		# Thanks to "shade" for help with this!

		[store_unit]
			variable=sir_gerrick_store
			[filter]
				description=Sir Gerrick
			[/filter]
			kill=yes
		[/store_unit]

		{VARIABLE deoran_store.canrecruit 1}
		{VARIABLE deoran_store.x 22}
		{VARIABLE deoran_store.y 16}

		[unstore_unit]
			variable=deoran_store
		[/unstore_unit]

		{CLEAR_VARIABLE deoran_store}

		[if]
			[variable]
				name=sg_length_of_defense
				greater_than_equal_to=8
			[/variable]
			[then]
				{VARIABLE sg_short_defense true}
			[/then]
		[/if]
		[if]
			[variable]
				name=sg_length_of_defense
				greater_than_equal_to=12
			[/variable]
			[then]
				{VARIABLE sg_medium_defense true}
			[/then]
		[/if]
		[if]
			[variable]
				name=sg_length_of_defense
				greater_than_equal_to=18
			[/variable]
			[then]
				{VARIABLE sg_long_defense true}
			[/then]
		[/if]
		[if]
			[variable]
				name=sg_length_of_defense
				greater_than=32
			[/variable]
			[then]
				{VARIABLE sg_heroic_defense true}
			[/then]
		[/if]

		{SG_IF sg_heroic_defense}

			{STARTING_VILLAGES 1 20}

		{SG_END_IF}

		{SG_IF sg_long_defense}
			{SG_GUARD (Bowman) (Provincial Guard) (_"Provincial Guard") 1 25 22}
			{SG_GUARD (Lieutenant) (Lt. Nilaf) (_"Lt. Nilaf") 1 26 21}
			{SG_GUARD (Heavy Infantryman) (Provincial Guard) (_"Provincial Guard") 1 28 20}

			{SG_CHANGE_TERRAIN 25 22 n}
			{SG_CHANGE_TERRAIN 28 20 n}

			{STARTING_VILLAGES 1 9}

		{SG_END_IF}

		{SG_IF sg_medium_defense}
			{SG_GUARD (Heavy Infantryman) (Provincial Guard) (_"Provincial Guard") 1 25 21}
			{SG_GUARD (Spearman) (Provincial Guard) (_"Provincial Guard") 1 28 21}

			{SG_CHANGE_TERRAIN 25 21 n}

			{STARTING_VILLAGES 1 5}

		{SG_END_IF}

		{SG_IF sg_short_defense}
			{STARTING_VILLAGES 1 3}
		{SG_END_IF}

	[/event]

#start
	[event]
		name=start
		[recall]
			description=Minister Hylas
		[/recall]
		[recall]
			description=Jarek
		[/recall]

		[message]
			speaker=Deoran
			message= _ "Look!  The undead army has broken through Sir Gerrick's lines! Alas, he is lost!"
		[/message]

		[message]
			speaker=Moreth
			message= _ "Since i was a boy, Gerrick was my leader, and there was no one braver. Today we shall defend our homes, and avenge him!"
		[/message]

		{SG_IF sg_long_defense}
			[message]
				speaker=Jarek
				message= _ "But in the narrow window his valiant stand gave us, we have roused the whole provincial guard!"
			[/message]
			[message]
				speaker=Lt. Nilaf
				message= _ "Indeed Lord, we are ready to defend our homes!"
			[/message]
		{SG_END_IF}

		{SG_IF sg_heroic_defense}
			[message]
				speaker=Minister Hylas
				message= _ "And I have summoned the great council of Westin!  They will battle with all their might!"
			[/message]
			{SG_GUARD (Silver Mage) (Minister Mefel) (_"Minister Mefel") 1 19 18}
			{SG_GUARD (Red Mage) (Minister Romand) (_"Minister Romand") 1 20 18}
			{SG_GUARD (White Mage) (Minister Alanafel) (_"Minister Alanafel") 1 22 18}
			[message]
				speaker=Minister Mefel
				message= _ "Hylas, we have heard your summons, and we shall send these dark foes back to the abyss that spawned them!"
			[/message]
			[message]
				speaker=Deoran
				message= _ "Your aid will be most welcome."
			[/message]
		{SG_END_IF}

		[message]
			speaker=Deoran
			message= _ "We have rallied all the forces that we will be able to!  Let us not make Sir Gerrick's sacrifice a vain one.  For Wesnoth!"
		[/message]

		[objectives]
			side=1
			[objective]
				description= _ "Crush the undead"
				condition=win
			[/objective]
			[objective]
				description= _ "Death of Deoran"
				condition=lose
			[/objective]
			[objective]
				description= _ "Death of Minister Hylas"
				condition=lose
			[/objective]
			[objective]
				description= _ "Time runs out"
				condition=lose
			[/objective]
		[/objectives]
	[/event]











[/scenario]
