#textdomain wesnoth-tsg
[scenario]
    id=4_Vale_of_Tears

    name= _ "Vale of Tears"
    next_scenario=5_Choice_In_The_Fog

    {SCENARIO_MUSIC elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}

    map_data="{campaigns/The_South_Guard/maps/4_Vale_of_Tears.map}"

    {campaigns/The_South_Guard/utils/sg_deaths.cfg}

    {DEFAULT_SCHEDULE}

    {TURNS 40 32 28}
    victory_when_enemies_defeated=no

    # The South Guard

    [side]
        side=1
        type=Horseman Commander
        id=Deoran
        name= _ "Deoran"
        unrenamable=yes

        team_name=South_Guard
        user_team_name=_"South Guard"
        controller=human
        {CUSTOM_SG_FLAG}

        {GOLD 150 125 80}

        canrecruit=yes
        recruit=Bowman, Spearman, Cavalryman

        [village]
            x,y=3,10
        [/village]

        [village]
            x,y=4,13
        [/village]

        [village]
            x,y=8,15
        [/village]
    [/side]

    {STARTING_VILLAGES 1 5}

    # The Undead Hordes

    [side]
        side=2
#ifdef EASY
        type=Dark Adept
#endif
#ifdef NORMAL
        type=Dark Sorcerer
#endif
#ifdef HARD
        type=Necromancer
#endif
        id="Mal A'kai"
        name= _ "Mal A'kai"
        facing=sw

        {GOLD 70 90 120}

        team_name=undead
        user_team_name=_"Undead"
        controller=ai

        canrecruit=yes
        [ai]
#ifdef EASY
            recruitment_pattern=fighter
#else
            recruitment_pattern=fighter,archer
#endif
            {QUANTITY aggression 0.5 0.6 0.7}
            {ATTACK_DEPTH 3 4 5}
            [target]
                id=Ethiliel
                value=3.0
            [/target]
        [/ai]
#ifdef EASY
        recruit=Walking Corpse,Skeleton
#endif
#ifdef NORMAL
        recruit=Walking Corpse,Skeleton, Skeleton Archer,Ghoul
#endif
#ifdef HARD
        recruit=Walking Corpse,Skeleton, Revenant, Skeleton Archer,Bone Shooter,Ghoul
#endif
    [/side]

    {STARTING_VILLAGES 2 14}

    # The Bandit Army

    [side]
        side=3
        type=Outlaw
        id=Jera Ilras
        name= _ "Jera Ilras"
        facing=sw

        {GOLD 30 40 80}

        team_name=undead
        user_team_name=_"Undead"
        controller=ai

        canrecruit=yes
        [ai]
#ifdef EASY
            recruitment_pattern=scout,archer
#else
            recruitment_pattern=fighter,scout,archer
#endif
            {QUANTITY aggression 0.2 0.3 0.4}
            [target]
                id=Ethiliel
                value=2.0
            [/target]
            [avoid]
                x,y=27-35,29-35
            [/avoid]
        [/ai]
#ifdef EASY
        recruit=Footpad,Poacher
#endif
#ifdef NORMAL
        recruit=Footpad,Thug,Poacher
#endif
#ifdef HARD
        recruit=Footpad,Thug,Poacher,Thief
#endif
    [/side]

    {STARTING_VILLAGES 3 9}

    #start
    [event]
        name=start
        [recall]
            id=Sir Gerrick
        [/recall]
        [recall]
            id=Ethiliel
        [/recall]
        [recall]
            id=Minister Hylas
        [/recall]
        [recall]
            id=Jarek
        [/recall]

        [message]
            speaker=Deoran
            message= _ "We have followed you away from our homes and left them unguarded. Now, where can we find this sage who knows the southern forest well?"
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "This is the Vale of Blossoming Trees. Our great sages come here to live when they feel that it is time for them to allow others to lead our people. The sage you speak of lives in a secluded village between the two lakes."
        [/message]

        {HIGHLIGHT_IMAGE 31 32 items/gohere.png ()}

        [message]
            speaker=Sir Gerrick
            message= _ "Why, my lady, are there humans camped to the south of us? Are they friends of the elves? I had thought that no humans had set foot in this valley."
        [/message]

        [message]
            speaker=Ethiliel
            image=portraits/ethiliel-mad.png
            message= _ "What!? Those are no friends of the elves! They are brigands, and they must be destroyed!"
        [/message]

        [message]
            speaker=Deoran
            message= _ "Perhaps they are allied with the bandits who have been sacking our towns! They have grown bold to attack the elves!"
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "Destroy these intruders, and I will ask him to help you. He is ancient, and he remembers well Haldric's betrayal of the elves, so if a human sets foot in his village first, he almost certainly will have nothing to do with us!"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Sounds like a charming fellow..."
        [/message]

        [message]
            speaker=Deoran
            message= _ "Yet, as she says, he is our best hope to rid our lands of this new menace. We do that which we must. Ethiliel, you make for Mebrin's village. We will handle the intruders."
        [/message]

        [message]
            speaker="Mal A'kai"
            message= _ "Ha! You're too late. We've taken what we want from this valley."
        [/message]

        [message]
            speaker=Jera Ilras
            message= _ "Now your blood and tears will join that of the elves!"
        [/message]

        [objectives]
            side=1
            [objective]
                description= _ "Cleanse the Vale of Tears"
                condition=win
            [/objective]
            [objective]
                description= _ "Move Ethiliel to Mebrin's village"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Deoran"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Sir Gerrick"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Minister Hylas"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Ethiliel"
                condition=lose
            [/objective]
            [objective]
                description= _ "Time runs out"
                condition=lose
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/objectives]
    [/event]

    [event]
        name=attack_end

        [filter]
            side=1
        [/filter]

        [filter_attack]
            type=pierce
        [/filter_attack]

        [filter_second]
            type=Skeleton, Revenant, Deathblade, Draug, Skeleton Archer, Bone Shooter, Banebow
        [/filter_second]

        # only comment on pierce damage being useless if the player didn't
        # actually kill the skeleton with it
        [if]
            [variable]
                name=second_unit.hitpoints
                greater_than=0
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "Our weapons are useless against these skeletons! They have nothing for our shafts to pierce but air!"
                [/message]
            [/then]
        [/if]

        [message]
            speaker=Deoran
            message= _ "We must clear out these undead if you are to reach Mebrin's village! What should we do?"
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "For now, I can slow them down. Where are the elves who used to live in this valley? They should come to our aid!"
        [/message]

        [message]
            speaker=Deoran
            message= _ "You said this valley would be safe, and we find it filled with skeletal foes! Cannot some of your elf friends help us in our struggle?"
        [/message]
    [/event]

    [event]
        name=last breath

        [filter]
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "I shall not join these accursed undead! Bury me deeply my friends..."
        [/message]

        [kill]
            x,y=$x1,$y1
            animate=yes
        [/kill]

        [message]
            speaker=Ethiliel
            message= _ "You shall not die in vain! My bodyguard will avenge you!"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "You have a bodyguard?!"
        [/message]

        [message]
            speaker=Deoran
            message= _ "You have a bodyguard?!!"
        [/message]

        [store_unit]
            [filter]
                id=Ethiliel
            [/filter]
            variable=ethiliel_loc
            kill=no
        [/store_unit]

        [store_locations]
            terrain=*^F*
            [and]
                x,y=$ethiliel_loc.x,$ethiliel_loc.y
                radius=3
            [/and]
            variable=bodyguard_loc
        [/store_locations]

        {VARIABLE number 0}
        [while]
            [variable]
                name=number
                less_than=$bodyguard_loc.length
            [/variable]
            [variable]
                name=number
#ifdef EASY
                less_than=4
#endif
#ifdef NORMAL
                less_than=3
#endif
#ifdef HARD
                less_than=2
#endif
            [/variable]
            [do]
                # fallback coordinates, in case no nearby vacant forest is found
                {VARIABLE guard_x $ethiliel_loc.x}
                {VARIABLE guard_y $ethiliel_loc.y}

                [set_variable]
                    name=guard_x
                    value=$bodyguard_loc[$number].x
                [/set_variable]

                [set_variable]
                    name=guard_y
                    value=$bodyguard_loc[$number].y
                [/set_variable]

                [unit]
                    role=Elvish Bodyguard
                    name= _ "Elvish Bodyguard"
                    type=Elvish Ranger
                    side=1
                    x,y=$guard_x,$guard_y
                    random_traits=yes
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                    {IS_LOYAL}
                [/unit]

                {VARIABLE_OP number add 1}
            [/do]
        [/while]

        {CLEAR_VARIABLE bodyguard_loc,ethiliel_loc,number}

        [message]
            role=Elvish Bodyguard
            message= _ "We stand ready, my lady, to protect you! We shall lead these men of Wesnoth into the fray!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            role=Elvish Bodyguard
        [/filter]

        [message]
            speaker=unit
            message= _ "For my lady I fall..."
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id="Mal A'kai"
        [/filter]

        [message]
            speaker="Mal A'kai"
            message= _ "Finally, release! Thank you, my friends..."
        [/message]

        [kill]
            x,y=$x1,$y1
            animate=yes
        [/kill]

        {VARIABLE undead_defeated "yes"}

        [if]
            [variable]
                name=mebrin_found
                equals=yes
            [/variable]
            [variable]
                name=undead_defeated
                equals=yes
            [/variable]
            [variable]
                name=bandits_defeated
                equals=yes
            [/variable]
            [then]
                #           [kill]
                #               type=Elvish Ranger,Elvish Avenger
                #               animate=no
                #               fire_event=no
                #           [/kill]

                {CLEAR_VARIABLE mebrin_found}
                {CLEAR_VARIABLE undead_defeated}
                {CLEAR_VARIABLE bandits_defeated}

                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Jera Ilras
        [/filter]

        [message]
            speaker=Jera Ilras
            message= _ "You're too late! You'll never find our stronghold, and even if you did, what can you do against the dead?"
        [/message]

        [message]
            speaker=second_unit
            message= _ "You, at least, will trouble us no more!"
        [/message]

        [kill]
            x,y=$x1,$y1
            animate=yes
        [/kill]

        {VARIABLE bandits_defeated "yes"}

        [if]
            [variable]
                name=mebrin_found
                equals=yes
            [/variable]
            [variable]
                name=undead_defeated
                equals=yes
            [/variable]
            [variable]
                name=bandits_defeated
                equals=yes
            [/variable]
            [then]
                #           [kill]
                #               type=Elvish Ranger,Elvish Avenger
                #               animate=no
                #               fire_event=no
                #           [/kill]

                {CLEAR_VARIABLE mebrin_found}
                {CLEAR_VARIABLE undead_defeated}
                {CLEAR_VARIABLE bandits_defeated}

                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]

    # Ethieliel arrives at Mebrin's village

    [event]
        name=moveto
        [filter]
            id=Ethiliel
            x,y=31,32
        [/filter]

        [removeitem]
            x,y=31,32
        [/removeitem]

        [message]
            speaker=Ethiliel
            message= _ "Mebrin! Are you there? We have come to seek your aid!"
        [/message]

        [message]
            speaker=narrator
            message= _ "..."
            image=wesnoth-icon.png
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "Mebrin! Where are you?!"
        [/message]

        [message]
            speaker=narrator
            message= _ "..."
            image=wesnoth-icon.png
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "His home is empty... There are footprints leading away to the south... What can have happened here?"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Maybe whoever summoned these undead knows where he is?"
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "There is no blood here, yet no Mebrin. Someone must have kidnapped him. But the undead would have slain him and made him one of them. Who then can have taken him?"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Maybe the bandits who have been summoning the undead took him?"
        [/message]

        [message]
            speaker=Ethiliel
            image=portraits/ethiliel-mad.png
            message= _ "We must follow these footprints into the woods! Whoever took our greatest sage must pay! Nothing will stop the vengeance of the elves!"
        [/message]

        [message]
            speaker=Deoran
            message= _ "Well, vengeance or no, if you will lead us into the forest, we will follow you and battle the undead!"
        [/message]

        {VARIABLE mebrin_found "yes"}

        [if]
            [variable]
                name=mebrin_found
                equals=yes
            [/variable]
            [variable]
                name=undead_defeated
                equals=yes
            [/variable]
            [variable]
                name=bandits_defeated
                equals=yes
            [/variable]
            [then]
                #   [kill]
                #       type=Elvish Ranger,Elvish Avenger
                #       animate=no
                #       fire_event=no
                #   [/kill]

                {CLEAR_VARIABLE mebrin_found}
                {CLEAR_VARIABLE undead_defeated}
                {CLEAR_VARIABLE bandits_defeated}

                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]
[/scenario]
