#textdomain wesnoth-tsg
[scenario]
    id=03_A_Desperate_Errand

    name= _ "A Desperate Errand"
    next_scenario=04_Vale_of_Tears

    {SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC traveling_minstrels.ogg}
    {EXTRA_SCENARIO_MUSIC legends_of_the_north.ogg}

    map_data="{campaigns/The_South_Guard/maps/03_A_Desperate_Errand.map}"

    {campaigns/The_South_Guard/utils/sg_deaths.cfg}

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

    victory_when_enemies_defeated=no
    {TURNS 23 19 15}

    {TSG_BIGMAP {JOURNEY_03_NEW} }

    # The South Guard

    [side]
        side=1
        type=Horseman Commander
        id=Deoran
        name= _ "Deoran"
        profile=portraits/deoran.png
        unrenamable=yes

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

        {GOLD 100 85 70}

        canrecruit=yes
        recruit=Bowman, Spearman
    [/side]

    {STARTING_VILLAGES 1 4}

    # The Bandit Armies

    [side]
        side=2
        type=Rogue
        id=Urza Fastik
        name= _ "Urza Fastik"

        team_name=bandits
        user_team_name=_"Bandits"
        controller=ai

        {GOLD 80 100 120}

        canrecruit=yes
        [ai]
            {QUANTITY aggression 0.55 0.75 0.85}
            {ATTACK_DEPTH 3 4 5}
            village_value=0.1
            villages_per_scout=10
            [goal]
                name=target
                [criteria]
                    id=Deoran
                [/criteria]
                value=10
            [/goal]
            [goal]
                name=protect_location
                [criteria]
                    x,y=22,16
                [/criteria]
                protect_radius=10
                value=5.0
            [/goal]
            [avoid]
                x,y=1-24,1-11
            [/avoid]
            [aspect]
                id=recruitment_instructions

                [facet]
                    [value]
                        [recruit]
                            type=Vampire Bat
                            number=1
                            importance=3
                            blocker=no
                        [/recruit]
                        [recruit]
                            type=Skeleton,Skeleton Archer
                            number=1
                            importance=2
                            blocker=no
                        [/recruit]
                        [recruit]
                            type=Ruffian,Thug,Footpad
                            importance=1
                        [/recruit]

                        [limit]
                            type=Vampire Bat
#ifdef EASY
                            max=2
#else
                            max=3
#endif
                        [/limit]
                        [limit]
                            type=Skeleton,Skeleton Archer
#ifdef EASY
                            max=2
#else
                            max=3
#endif
                        [/limit]
                    [/value]
                [/facet]
            [/aspect]
        [/ai]

#ifdef EASY
        recruit=Ruffian,Thug,Footpad,Vampire Bat,Skeleton
#endif
#ifdef NORMAL
        recruit=Ruffian,Thug,Footpad,Poacher,Vampire Bat,Skeleton
#endif
#ifdef HARD
        recruit=Thug,Footpad,Poacher,Thief,Vampire Bat,Skeleton,Skeleton Archer
#endif
        {FLAG_VARIANT6 ragged}
    [/side]

    {STARTING_VILLAGES_AREA 2 18 25 10}
    {STARTING_VILLAGES_AREA 2 20 17 8}

    # The Aethenwood Elves

    [side]
        side=3
        no_leader=yes

        team_name=Elves
        user_team_name=_"Elves"
        controller=null
        hidden=yes

        # She is already in the game if she is on the recall list, which allows
        # the victory event to work, if it is triggered using debug mode commands.
        [unit]
            type=Elvish Shyde
            id=Ethiliel
            name= _ "Ethiliel"
            unrenamable=yes
            profile=portraits/ethiliel.png
            {IS_HERO}
            x,y=recall,recall
            random_traits=no
            [modifications]
                # Loyal trait is given later
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
    [/side]

    [event]
        name=prestart

        [micro_ai]
            side=2
            ai_type=assassin
            action=add

            [filter]
                type_adv_tree=Vampire Bat
            [/filter]
            [filter_second]
                id=Deoran
            [/filter_second]
        [/micro_ai]
    [/event]

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

        [message]
            speaker=narrator
            {NARRATOR: _"Deoran and his men came to the eastern border of the Aethenwood, where the towering trees of the elven forest loomed close overhead."}
            image=wesnoth-icon.png
        [/message]

        [message]
            speaker=Deoran
            message= _ "Look to the west! There lies the forest of the elves. Let us hasten across the river and the hills."
        [/message]

        [message]
            speaker=Minister Hylas
            message= _ "I must advise caution, Sir Deoran. No man has set foot in the elvish woods for many a year. They have never been friendly toward humankind, and we do not know how they will receive us now, especially after Sir Loris spurned them."
        [/message]

        [message]
            speaker=Deoran
            message= _ "We cannot fear and shun everything we do not understand! Sir Loris may have distrusted the elves, but he is gone now, and I daresay as a result of his own folly! We do not possess the strength to fight these undead, nor the means to discover their source; we can only look to these elves for help, wary of men though they may be."
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Nevertheless, we musn’t charge in blindly. Even if the elves are unlikely to attack us, we do not know what else lies in these forests."
        [/message]

        [message]
            speaker=Deoran
            message= _ "Very well. We will proceed in formation, then."
        [/message]

        [message]
            speaker=Urza Fastik
            message= _ "I have lost two brothers to this mite of a boy! This Deoran, young as he seems, may be more capable than I had thought. No matter. I will use my new powers against him and then surely he will fall!"
        [/message]

        {HIGHLIGHT_IMAGE 11 7 items/gohere.png ()}

#ifdef EASY
        [message]
            speaker=narrator
            {TUTOR: _"You must move Deoran to the center of the elvish citadel. Be sure to recruit a force strong enough to drive off the bandits before moving Deoran from his encampment!"}
            image=wesnoth-icon.png
        [/message]
#endif

        [scroll_to_unit]
            id=Deoran
        [/scroll_to_unit]

        [objectives]
            side=1
            [objective]
                description= _ "Move Deoran to the Elvish city in the western woods"
                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]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Deoran
            message= _ "There is so much ground to cover. If only our riders would arrive!"
        [/message]
    [/event]

    [event]
        name=turn 3

        [unit]
            side=1
            id=Jarek
            name= _ "Jarek"
            {QUANTITY type Dragoon Dragoon Cavalryman}
            x,y=42,19
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=Jarek
            message= _ "Commander, I received your request for reinforcements, and I have brought my riders with me!"
        [/message]

        [message]
            speaker=narrator
            image="units/human-loyalists/cavalryman/cavalryman.png~RC(magenta>red)"
#ifdef EASY
            {TUTOR: _"You may now recruit Cavalrymen. They are fast and deadly on grassland, but weak in forests and unable to traverse mountains. They can keep up with Deoran, so use them to guard him!"}
#else
            {TUTOR: _"You may now recruit Cavalrymen."}
#endif
        [/message]

        [allow_recruit]
            side=1
            type=Cavalryman
        [/allow_recruit]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Urza Fastik
        [/filter]

        [message]
            speaker=unit
            message= _ "Even our undead allies cannot stand against this commander! The dark one lied to us!"
        [/message]

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

        [role]
            role=second
            type="Peasant,Spearman,Bowman,Cavalryman,Swordsman,Pikeman,Javelineer,Longbowman,Dragoon,Royal Guard,Halberdier,Master Bowman,Cavalier"
            search_recall_list=no
        [/role]

        [message]
            role=second
            message= _ "Ha! Take that, you criminal scum!"
        [/message]

        [message]
            speaker=Deoran
            message= _ "Their leader is defeated! I hope that’s the last bandit we ever have to fight."
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "Even if the bandits are beaten, there is still the matter of the undead."
        [/message]

        [message]
            speaker=Deoran
            message= _ "Indeed, we should press on toward the elves and see if they know anything about these dark foes."
        [/message]
    [/event]

    # Deoran arrives at the elvish citadel
    [event]
        name=moveto
        [filter]
            id=Deoran
            x,y=11,7
        [/filter]

        [remove_item]
            x,y=11,7
        [/remove_item]

        {NAMED_LOYAL_UNIT 3 (Elvish Ranger) 9 4 (Linderion) (_"Linderion")}
        {NAMED_LOYAL_UNIT 3 (Elvish Marksman) 13 4 (Mithalwe) (_"Mithalwe")}
        {NAMED_LOYAL_UNIT 3 (Elvish Marshal) 7 7 (Ithelden) (_"Ithelden")}
        {NAMED_LOYAL_UNIT 3 (Elvish Avenger) 15 7 (Eltenmir) (_"Eltenmir")}
        {NAMED_LOYAL_UNIT 3 (Elvish Hero) 9 10 (Vardanos) (_"Vardanos")}
        {NAMED_LOYAL_UNIT 3 (Elvish Outrider) 13 10 (Talchar) (_"Talchar")}
        [modify_unit]
            [filter]
                side=3
                ability=ambush
            [/filter]
            [status]
                uncovered=yes
            [/status]
        [/modify_unit]

        [recall]
            id=Ethiliel
            x,y=11,6
            show=no
        [/recall]

        [message]
            speaker=Linderion
            message= _ "Halt! Who enters our sacred grove without leave?"
        [/message]

        [message]
            speaker=Deoran
            message= _ "De—"  # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Linderion
            message= _ "Choose your words wisely, human. Know that the penalty for trespassing on our lands is death. What is your name?"
        [/message]

        [message]
            speaker=Deoran
            message= _ "Deora—"   # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Ethiliel
            # wmllint: local spelling Elrath
            message= _ "Stay your hand, Linderion. This man bears the banner of Wesnoth and appears to come to us in peace. What brings you to the hallowed grove of Elrath?"
        [/message]

        [message]
            speaker=Deoran
            message= _ "My lady, we have come to the elves to seek guidance. Bandits and criminals have summoned the dead to help them plunder our farms and villages. They come from the great forest across the river to our south, where no man has yet traveled. We have defeated many a bandit already, but I fear that we cannot continue to battle them for much longer with the undead under their control."
        [/message]

        [message]
            speaker=Ithelden
            message= _ "We sent you a messenger regarding the undead, did we not? You were forewarned of the blight marching upon your land, and yet you did not prepare adequately."
        [/message]

        [message]
            speaker=Deoran
            message= _ "I do not aim to make excuses, but I have been here for scarcely a week! I do not know why the previous commander did not act on your advice, but I assure you that I will not make the same mistakes he did!"
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "For your own sake, I hope that you do not. As for the matter at hand, the elves know of the great southern forest, and have walked its paths many times."
        [/message]

        [message]
            speaker=Deoran
            message= _ "And what do you know of the undead?"
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "My answer will depend on your motives, human. What would you do, knowing the secrets of the unholy ones?"
        [/message]

        [message]
            speaker=Deoran
            message= _ "I would lead my men south of the river to find and destroy the source of these beings of darkness."
        [/message]

        [message]
            speaker=Vardanos
            message= _ "A fanciful delusion! A human untrained in the mystic arts stands no chance against the undead!"
        [/message]

        [message]
            speaker=Deoran
            message= _ "I have proven myself capable of defending my land and leading my men to victory—"
        [/message]

        [message]
            speaker=Eltenmir
            message= _ "Only in battles against <i>other humans!</i> To fight such a fell evil is another matter altogether."
        [/message]

        [message]
            speaker=Deoran
            message= _ "But surely I cannot do nothing either!"
        [/message]

        [message]
            speaker=Minister Hylas
            message= _ "<i>I warned him that the elves would not easily agree to help us.</i>"
        [/message]

        [message]
            speaker=Sir Gerrick
            message= _ "<i>Indeed, but he is right as well. We must do something, or our people will surely be slaughtered.</i>"
        [/message]

        [message]
            speaker=Ithelden
            message= _ "Enough, all of you. Ethiliel is the only one of us who has encountered the undead — she will be the best judge of what aid we would grant the humans against these abominations."
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "These men are indeed brave to face such foes, but I fear that they will fall to the darkness if they fight it alone. There is one elf who still remembers the secrets of the undead that we learned when Haldric I came to our land. His name is Mebrin, and he lives secluded in the hills south of here."
        [/message]

        [message]
            speaker=Ithelden
            message= _ "Are you sure about this? The road south is no longer as safe as it once was, and Mebrin is not as powerful as he once was. You would not presume to put one of our great sages in danger, Ethiliel."
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "<i>I</i> will accompany the human and his men to Mebrin, and he can decide whether or not he wants to help us. I will not ask you to place yourselves in danger for these humans, but you will not presume to tell me — nor Mebrin — what to do. Is that fair?"
        [/message]

        [message]
            speaker=Ithelden
            message= _ "Yes, very well."
        [/message]

        [message]
            speaker=Deoran
            image=portraits/deoran-glad.png
            message= _ "I welcome your aid, my lady."
        [/message]

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

    [event]
        name=victory

        [store_unit]
            [filter]
                id=Ethiliel
            [/filter]
            variable=EthilielV
            kill=no # Current Ethiliel may remain on the field for visual reasons.
        [/store_unit]
        # Stores a copy of Ethiel onto the recall list. The recall list cannot be
        # viewed in linger mode. Give here as well the loyal trait.
        {VARIABLE EthilielV.side 1}
        {VARIABLE EthilielV.x recall}
        {VARIABLE EthilielV.y recall}
        {CLEAR_VARIABLE EthilielV.modifications}

        [set_variables]
            name=EthilielV.modifications
            mode=insert
            [value]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/value]
        [/set_variables]

        {CLEAR_VARIABLE EthilielV.upkeep}

        [unstore_unit]
            variable=EthilielV
        [/unstore_unit]
        {CLEAR_VARIABLE EthilielV}
    [/event]

    [event]
        name=time over

        [unit]
            type=Death Knight
            side=2
            x,y=40,19
            canrecruit=yes
            animate=yes
            facing=nw
        [/unit]
        {GENERIC_UNIT 2 (Revenant) 40 20}
        {GENERIC_UNIT 2 (Skeleton) 41 20}
        {GENERIC_UNIT 2 (Skeleton Archer) 41 19}
        {GENERIC_UNIT 2 (Skeleton Archer) 42 19}
        [message]
            speaker=Deoran
            message= _ "Skeletons approach from the east! This can only mean that they have begun to attack Kerlath. We will have to return and fight them without the aid of the elves..."
        [/message]
    [/event]
[/scenario]
