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

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

    map_data="{campaigns/The_South_Guard/maps/8b_The_Tides_of_War.map}"

    {campaigns/The_South_Guard/utils/sg_deaths.cfg}

    {DEFAULT_SCHEDULE}
    
    {VICTORY_AND_DEFEAT_MUSIC}

    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=yes
        recruit=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=yes
        [ai]
            recruitment_pattern=scout,fighter,fighter,archer,scout,fighter,archer,mixed fighter
            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}

        {VARIABLE stored_Deoran.x 22}
        {VARIABLE stored_Deoran.y 16}

        [unstore_unit]
            variable=stored_Deoran
            find_vacant=no
        [/unstore_unit]

        {CLEAR_VARIABLE stored_Deoran}

        [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]

        [if]
            [variable]
                name=sg_heroic_defense
                equals=true
            [/variable]
            [then]
                {STARTING_VILLAGES 1 20}
            [/then]
        [/if]

        [if]
            [variable]
                name=sg_long_defense
                equals=true
            [/variable]
            [then]
                {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}

                {MODIFY_TERRAIN Ce 25 22}
                {MODIFY_TERRAIN Ce 28 20}

                {STARTING_VILLAGES 1 9}
            [/then]
        [/if]

        [if]
            [variable]
                name=sg_medium_defense
                equals=true
            [/variable]
            [then]
                {SG_GUARD (Heavy Infantryman) (Provincial Guard) (_"Provincial Guard") 1 25 21}
                {SG_GUARD (Spearman) (Provincial Guard) (_"Provincial Guard") 1 28 21}

                {MODIFY_TERRAIN Ce 25 21}

                {STARTING_VILLAGES 1 5}
            [/then]
        [/if]

        [if]
            [variable]
                name=sg_short_defense
                equals=true
            [/variable]
            [then]
                {STARTING_VILLAGES 1 3}
            [/then]
        [/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]

        [if]
            [variable]
                name=sg_long_defense
                equals=true
            [/variable]
            [then]
                [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]

                # If defence is long but NOT heroic, only part of the council arrives in time.
                [if]
                    [variable]
                        name=sg_heroic_defense
                        equals=false
                    [/variable]
                    [then]
                        [message]
                            speaker=Minister Hylas
                            message= _ "I have summoned the great Council of Westin!"
                        [/message]
                        {SG_GUARD (Silver Mage) (Minister Mefel) (_"Minister Mefel") 1 19 18}
                        [message]
                            speaker=Minister Mefel
                            message= _ "Hylas, I have made all possible haste, but my Council bretheren are not as swift as I. I fear that they will not arrive in time!"
                        [/message]
                        [message]
                            speaker=Deoran
                            message= _ "Minister Mefel, we are cheered by your presence. I trust that you and Minister Hylas will help us send these dark forces back to the abyss that spawned them!"
                        [/message]
                    [/then]
                [/if]
            [/then]
        [/if]

        [if]
            [variable]
                name=sg_heroic_defense
                equals=true
            [/variable]
            [then]
                [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]
            [/then]
        [/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]
