#textdomain wesnoth-utbs

[scenario]
    id=01_The_Morning_After
    name= _ "The Morning After"
    {UTBS_MAP 01_The_Morning_After.map}
    next_scenario=02_Across_the_Harsh_Sands
    {TURNS 34 32 29}

    # Since the scenario can't end until all the elves are rescued we
    # can't allow it to end with the death of the necromancer
    victory_when_enemies_defeated=no

    {TWO_SUNS_DEFAULT_SCHEDULE}

    {INTRO_AND_SCENARIO_MUSIC "elf-land.ogg" "revelation.ogg"}
    {EXTRA_SCENARIO_MUSIC "nunc_dimittis.ogg"}
    {EXTRA_SCENARIO_MUSIC "elvish-theme.ogg"}

    {STORY_THE_MORNING_AFTER}

    [terrain_graphics]
        map="
.,  *,  .
, *,  *,  
*,  1,  *
, *,  *,  
.,  *,  ."
        [tile]
            pos=1
        [/tile]
        x,y=29,27
        [image]
            name=great-tree-smashed.png
            layer=0
            base=108,108
            center=144,108
        [/image]
    [/terrain_graphics]

    # Set sides - elves, monsters and necromancer
    # wmllint: validate-off
    [side]
        side=1
        controller=human
        # Kaleh's start villages will support his initial recruits.
        gold=0
        {INCOME 4 2 0}
        user_team_name= _ "team_name^Quenoth Elves"
        {FLAG_VARIANT long}

        # wmllint: recognize Kaleh
        {KALEH}

        shroud=yes

        # Start with Nym
        [unit]
            # wmllint: who NYM is Nym
            {NYM}
            x,y=27,22
        [/unit]
    [/side]
    # wmllint: validate-on

    # Monster side : mudcrawlers and cuttlefish

    [side]
        side=2
        controller=ai
        team_name=monsters
        user_team_name= _ "Monsters"
        no_leader=yes

        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 1.0}
            {AI_SIMPLE_ALWAYS_ASPECT caution 0.0}
        [/ai]
    [/side]

    # Undead side, doesn't start with a leader
    [side]
        side=3
        controller=ai
        # Gold and income set when Necromancer appears
#ifndef HARD
        recruit=Skeleton, Skeleton Archer, Vampire Bat, Ghoul, Dark Adept
#endif
#ifdef HARD
        recruit=Revenant, Bone Shooter, Blood Bat, Necrophage, Dark Adept, Deathblade
#endif
        team_name=evil
        user_team_name= _ "Evil"
        {FLAG_VARIANT undead}
        no_leader=yes

        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.80}
            {AI_SIMPLE_ALWAYS_ASPECT caution 0.10}
#ifdef HARD
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern scout,fighter,fighter,fighter,archer}
#else
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern scout,fighter,archer,fighter}
#endif
        [/ai]
    [/side]

    [event]
        name=prestart

#ifdef HARD
        # Remove one village on HARD
        [terrain]
            x,y=53,3
            terrain=Dd
        [/terrain]
#endif

        # Can't end scenario until all elves have been rescued (5 events)
        [objectives]
            [objective]
                description= _ "Rescue surviving elves"
                condition=win
            [/objective]
            [objective]
                description= _ "Defeat Xanthos"
                condition=win
                [show_if]
                    [have_unit]
                        id=Xanthos
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Kaleh"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Nym"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Garak"
                condition=lose
                [show_if]
                    # We could just use [have_unit], but if Garak or Zhul dies and the player
                    # checks the objectives, the respective objective won't be displayed,
                    # and disappearing objectives for no good reason would look buggy.
                    [variable]
                        name=found_garak
                        boolean_equals=yes
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Zhul"
                condition=lose
                [show_if]
                    [variable]
                        name=found_zhul
                        boolean_equals=yes
                    [/variable]
                [/show_if]
            [/objective]

            {TURNS_RUN_OUT}

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

        # (as of 1.14.0+) There are no female fighter, etc. versions, maybe this will change some day.
        # Commented out rather than removed the gender stuff so it is a reminder

        # Setting up the village occupants
        # 2 fighters, 2 archers, 2 hunters (if not HARD), 2 scouts
        [set_variables]
            name=elf_pool
            [value]
                type="Quenoth Fighter"
                name= _ "Lreu"
                gender=male
                # name= _ "Lrea"
                # gender=female
            [/value]
            [value]
                type="Quenoth Fighter"
                name= _ "Piyru"
                gender=male
            [/value]
            [value]
                type="Quenoth Fighter"
                name= _ "Feru"
                gender=male
                # name= _ "Frea"
                # gender=female
            [/value]
            [value]
                type="Quenoth Scout"
                name= _ "Danu"
                gender=male
            [/value]
            [value]
                type="Quenoth Scout"
                name= _ "Hamuil"
                gender=male
            [/value]
            [value]
                type="Quenoth Scout"
                name= _ "Anioh"
                gender=male
            [/value]
            [value]
                type="Tauroch Rider"
                name= _ "Vemuil"
                gender=male
            [/value]
            [value]
                type="Tauroch Rider"
                name= _ "Taliu"
                gender=male
            [/value]
        [/set_variables]
    [/event]

    # Dialog at start of scenario
    [event]
        name=start

        [message]
            speaker=Nym
            message= _ "Hey Kaleh, are you in there?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Nym, is that you?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Yes, come on out already. The storm has passed. With the morning light Naia has ended the terrible night."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Has the sky really stopped falling?"
        [/message]

        [message]
            speaker=Nym
            message= _ "I already told you, the sky is clear and empty. Now come quickly, silly, others may need our help."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "What’s happened? Oh Eloh, the craters are everywhere, everything is gone, ruined. I can hardly recognize our village. I didn’t think it could be this bad."
        [/message]

        [message]
            speaker=Nym
            message= _ "Come on, Kaleh, we have to go see if anyone is hurt or needs help. I think I hear people calling from the south. Now is not a time for fear, we must be strong. After all you are the nephew of Tanuil, our leader, and you must answer to the call of duty. Perhaps in the light of day things won’t be as bad as you think. Let’s explore the village and see who else has survived the night."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Wait, our keep is just to the east. Our leader Tanuil must surely be recruiting others to help deal with the devastation. Perhaps we should go to the keep, before we explore the rest of the village."
        [/message]
    [/event]

    # Dialog when Nym and Kaleh see the ruined keep
    [event]
        name=moveto
        [filter]
            x=33-40
            y=19-26
            side=1
        [/filter]

        [allow_undo][/allow_undo]

        [message]
            speaker=Kaleh
            message= _ "Tanuil’s keep, our beautiful fortress, it is destroyed. How will we summon our people to battle?"
        [/message]

        [message]
            speaker=Nym
            message= _ "We must rally those survivors we can find amidst the rubble. It doesn’t look like anyone survived, but at least we can thank Eloh it was a quick death. But come on, we can’t dwell on the dead, we must help the living."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "But if Tanuil is dead, who will lead us?"
        [/message]

        [message]
            speaker=Nym
            message= _ "That’s a question for another time. Let’s keep exploring the wreckage."
        [/message]
    [/event]

    # There are 3 mudcrawler encounter spots, in the NW and SW corner
    # and in the barracks.  Depending on which way you circle around
    # the village, you will encounter the NW or barracks first.

    # Survivors - two mudcrawler events, Garak event, Zhul event, scout events
    # Handle all events within the oasis boundary.
    # This includes finding all the elves that we have to rescue, dealing with
    # mudcrawlers and lake monster.
    # ! -- Depends on
    # $rescued_elves, $seen_mudcrawler

    # North-West mudcrawler/villager encounter
    # Elvish fighter and 2 archers fighting
    # Easy:   1 giant mudcrawler,  3 small mudcrawlers
    # Medium: 2 giant mudcrawlers, 2 small mudcrawlers
    # Hard:   3 giant mudcrawlers, 1 small mudcrawler

    # wmllint: local spelling Yasi

    # First mudcrawler encounter event trigger
    [event]
        name=moveto
        [filter]
            x=17-26
            y=23-28
            side=1
        [/filter]

        # Activate the event
        [fire_event]
            name=first_mudcrawler_encounter
        [/fire_event]
    [/event]

    [event]
        name=first_mudcrawler_encounter

        [set_variable]
            name=rescued_elves
            add=1
        [/set_variable]

        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 24 25 "Vecnu" ( _ "Vecnu")}
        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 24 27 "Eranor" ( _ "Eranor")}
        {NAMED_GENERIC_UNIT 1 "Tauroch Rider" 21 25 "Seil" ( _ "Seil")}
        # {NAMED_GENERIC_UNIT 1 "Tauroch Rider" 21 25 "Seela" ( _ "Seela")}
        # [+unit]
        #     gender=female
        # [/unit]

        # Again core macro, monsters shouldn’t have traits
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 20 24}

#ifdef HARD
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 20 25}
#else
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 20 25}
#endif
#ifdef EASY
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 23 27}
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 25 28}
#else
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 23 27}
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 24 28}
#endif

        [if]
            [variable]
                name=seen_mudcrawler
                boolean_equals=no
            [/variable]
            [then]
                # Haven't seen a mudcrawler yet, set the flag and perform
                # what-the-hell-is-that routine.
                {VARIABLE seen_mudcrawler yes}

                [message]
                    speaker=Vecnu
                    message= _ "Kaleh, Nym, help us!"
                [/message]

                [message]
                    speaker=Nym
                    message= _ "What in Uria’s name is that?"
                    image=portraits/nym_moody.png
                [/message]

                [message]
                    speaker=Vecnu
                    message= _ "They came with the stones that fell from the sky. I know not what they are, but more seem to be emerging from the craters. If we don’t stop them there will be nothing left of our village or our people."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "To battle, my friends! There are still those left who can fight."
                [/message]
            [/then]
            [else]
                # Seen a mudcrawler, do let's-kick-their-ass routine
                [message]
                    speaker=Kaleh
                    message= _ "There are more of our people fighting the mud monsters!"
                [/message]

                [message]
                    speaker=Nym
                    message= _ "Then let’s join the battle!"
                [/message]
            [/else]
        [/if]
    [/event]

    # South-West mudcrawler/villager encounter
    # Elvish archer and 2 hunters fighting
    # Easy:   1 giant mudcrawler,  3 small mudcrawlers
    # Medium: 2 giant mudcrawlers, 2 small mudcrawlers
    # Hard:   3 giant mudcrawlers, 1 small mudcrawler

    # Second mudcrawler encounter event trigger
    [event]
        name=moveto
        [filter]
            x=17-28
            y=29-36
            side=1
        [/filter]

        [fire_event]
            name=second_mudcrawler_encounter
        [/fire_event]
    [/event]

    [event]
        name=second_mudcrawler_encounter

        [set_variable]
            name=rescued_elves
            add=1
        [/set_variable]

        {NAMED_GENERIC_UNIT 1 "Tauroch Rider" 24 34 "Eloshi" ( _ "Eloshi")}
        {NAMED_GENERIC_UNIT 1 "Quenoth Scout" 19 33 "Illuvin" ( _ "Illuvin")}
        # {NAMED_GENERIC_UNIT 1 "Quenoth Scout" 19 33 "Illuvia" ( _ "Illuvia")}
        # [+unit]
        #     gender=female
        # [/unit]
#ifdef HARD
        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 21 35 "Raynor" ( _ "Raynor")}
#else
        {NAMED_GENERIC_UNIT 1 "Tauroch Rider" 21 35 "Raynor" ( _ "Raynor")}
#endif

        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 25 34}
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 21 36}
#ifdef HARD
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 24 35}
#else
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 24 35}
#endif
#ifdef EASY
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 20 34}
#else
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 20 34}
#endif

        [message]
            speaker=Kaleh
            message=_ "More of these muddy crawlies, let’s get rid of them with haste."
        [/message]
    [/event]

    # Training ground encounter
    # Easy:   2 giant mudcrawler,  3 small mudcrawlers
    # Medium: 3 giant mudcrawlers, 2 small mudcrawlers
    # Hard:   4 giant mudcrawlers, 1 small mudcrawlers

    # Third mudcrawler encounter event trigger
    [event]
        name=moveto
        [filter]
            x=32-39
            y=32-36
            side=1
        [/filter]

        [fire_event]
            name=third_mudcrawler_encounter
            [primary_unit]
                id=$unit.id
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=third_mudcrawler_encounter

        # We want this village captured to allow player move through it
        # without losing the turn
        [capture_village]
            side=1
            x,y=36,34
        [/capture_village]

        [set_variable]
            name=rescued_elves
            add=1
        [/set_variable]

        # wmllint: recognize Rocky Horror
        {UNIT 2 "Giant Mudcrawler" 34 33 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
        {UNIT 2 "Giant Mudcrawler" 34 34 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
        {UNIT 2 "Small Mudcrawler" 34 35 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
#ifdef HARD
        {UNIT 2 "Giant Mudcrawler" 35 33 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
#else
        {UNIT 2 "Small Mudcrawler" 35 33 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
#endif
#ifdef EASY
        {UNIT 2 "Small Mudcrawler" 36 32 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
#else
        {UNIT 2 "Giant Mudcrawler" 36 32 (
            role="Rocky Horror"
            generate_name,random_traits,random_gender=yes,no,yes
        )}
#endif

        [unit]
            # wmllint: who GARAK is Garak
            {GARAK}
            side=1
            x,y=35,34
            {ABILITY_TEACHING_EVENT}
        [/unit]

        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 36 33 "Jorazan" ( _ "Jorazan")}
        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 35 34 "Zyar" ( _ "Zyar")}
        # {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 35 34 "Zyara" ( _ "Zyara")}
        # [+unit]
        #     gender=female
        # [/unit]

        [message]
            speaker=unit
            message= _ "This is our training ground. And look, there is Garak, the captain of the guard. He and his fighters have survived the night!"
        [/message]

        [if]
            [variable]
                name=seen_mudcrawler
                boolean_equals=no
            [/variable]
            [then]
                # Again, haven't seen a mudcrawler yet, set the flag and perform what-the-hell-is-that routine.
                {VARIABLE seen_mudcrawler yes}

                [message]
                    speaker=Garak
                    message= _ "Kaleh, Nym, help us!"
                [/message]

                [message]
                    speaker=Nym
                    message= _ "What in Uria’s name is that?"
                    image=portraits/nym_moody.png
                [/message]

                [message]
                    speaker=Garak
                    message= _ "They came with the stones that fell from the sky. I know not what they are, but more seem to be emerging from the craters. If we don’t stop them there will be nothing left of our village or our people."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "To battle, my friends! There are still those left who can fight."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Kaleh
                    message= _ "But they are fighting many mud creatures. Quick, we must help them!"
                [/message]
            [/else]
        [/if]

        {VARIABLE found_garak yes}

        [show_objectives][/show_objectives]
    [/event]

    # Garak's speech when they kill the last of training grounds
    # mudcrawlers. For this we use die event that on each
    # occurrence checks if there are any more training ground
    # mudcrawlers alive.
    [event]
        name=die
        [filter]
            role="Rocky Horror"
        [/filter]
        [filter_condition]
            [have_unit]
                role="Rocky Horror"
                count=0
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=second_unit
            message= _ "Ha! They’re destroyed at last."
        [/message]

        [message]
            speaker=Garak
            message= _ "Thanks for the help. I am glad to see that so many have survived the night. But there’s no time to talk, we must save the rest of our people and crush any other of these earthen abominations back into the earth."
        [/message]
    [/event]

    # The following three events are nested, because they are supposed to
    # occur in that particular sequence with none of them bypassed.
    # Thanks to this only one of them is loaded in memory at any given
    # time before resolution.

    # Approaching bridge dialog
    [event]
        name=moveto
        [filter]
            x=30-32
            y=29-35
            side=1
        [/filter]

        # Allow to undo the move before the event is triggered
        [allow_undo][/allow_undo]

        [message]
            speaker=Kaleh
            message= _ "This bridge leads to the holy island at the center of our lake."
        [/message]

        [message]
            speaker=Nym
            message= _ "Hmmmm. Some of the druids that worship on the island may still be alive. We should go check."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Be careful. The bridge is broken, so we’ll have to wade through the shallow water."
        [/message]

        # Finding druids
        [event]
            name=moveto
            [filter]
                x=30-32
                y=27-29
                side=1
            [/filter]

            [set_variable]
                name=rescued_elves
                add=1
            [/set_variable]

            [message]
                speaker=Kaleh
                message= _ "The great tree! It has been buried under the rocks. Our most holy sanctuary, defiled. Oh, Eloh, what shall we do?"
            [/message]

            [message]
                speaker=Nym
                message= _ "Is anyone still alive?"
            [/message]

            [unit]
                # wmllint: who ZHUL is Zhul
                {ZHUL}
                side=1
                x,y=31,27
            [/unit]
#ifndef HARD
            {NAMED_GENERIC_UNIT 1 "Quenoth Mystic" 30 27 "Ryoko" ( _ "Ryoko")}
#endif
            {NAMED_GENERIC_UNIT 1 "Quenoth Mystic" 32 27 "Yuni" ( _ "Yuni")}

            [message]
                speaker=Zhul
                message= _ "Finally! We were worried that no one else had survived."
            [/message]

            [message]
                speaker=Nym
                message= _ "Mother priestess, are you all right?"
            [/message]

            [message]
                speaker=Zhul
                message= _ "There’s no time to stand on ceremony. I’m fine. I’m afraid only a few of us survived, but we will lend you what skills we have. Show me to those who need healing."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "But the great tree, it has been destroyed!"
            [/message]

            [message]
                speaker=Zhul
                message= _ "All things of this world come to an end, but the power of Eloh endures. A new one shall grow in its place. Come now, let us see to the needs of our people."
            [/message]

            {VARIABLE found_zhul yes}

            [show_objectives][/show_objectives]

            # Lake monster event
            [event]
                name=moveto
                [filter]
                    x=30-32
                    y=30-34
                    side=1
                [/filter]

                [unit]
                    x,y=32,30
                    side=2
                    type=Cuttle Fish
                    name= _ "Deep One"
                    description= _ "The Deep Ones are gigantic aquatic monsters that lurk in the dark places of the world. Rarely do they come to the surface, and when they do the best way to survive an encounter with these monsters is to remain ashore. They can grab their opponents with strong tentacles, or spit a poisonous black ink from a distance."
                    # Deep one is basically a weakened Cuttlefish, it
                    # would be pretty much unbeatable if left without change
                    [modifications]
                        [trait]
                            id=Deep_one
                            [effect]
                                apply_to=attack
                                range=melee
                                increase_attacks={ON_DIFFICULTY -4 -3 -2}
                            [/effect]
                            [effect]
                                apply_to=hitpoints
                                increase_total={ON_DIFFICULTY -30 -27 -20}
                            [/effect]
#ifndef HARD
                            [effect]
                                apply_to=defense
                                replace=yes
                                [defense]
                                    shallow_water=50
                                [/defense]
                            [/effect]
#endif
                        [/trait]
                    [/modifications]
                [/unit]

                [message]
                    speaker=narrator
                    message= _ "The water of the lake suddenly goes dark and unsettled, only to erupt in a swarm of tentacles the moment the first elf set foot off the island."
                    image=wesnoth-icon.png
                [/message]

                [message]
                    speaker=Nym
                    message= _ "What in Uria’s name is that?"
                    image=portraits/nym_moody.png
                [/message]

                [message]
                    speaker=Zhul
                    message= _ "I felt a great darkness in this lake, but I knew not what it was. The falling rocks must have woken it from its sleep."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "Protect the priestesses, we shall send this monstrosity back to the depths it came from!"
                [/message]
            [/event]
        [/event]
    [/event]

    # Grasslands dialog, when Kaleh and Nym approach the eastern fields,
    # this will show only the first time player enters the stables area
    [event]
        name=moveto
        [filter]
            x=39-44
            y=26-33
            side=1
        [/filter]

        [message]
            speaker=Kaleh
            message= _ "These fields seem strangely vacant. Where are the dustboks?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Maybe they’re hiding in the stables. Let’s go check."
        [/message]
    [/event]

    # These two events actually do the same thing on two different
    # villages.

#define STABLE X Y
    [event]
        name=moveto
        [filter]
            [filter_location]
                x={X}
                y={Y}
                radius=1
            [/filter_location]
            side=1
        [/filter]

        [fire_event]
            name=stable found
            [primary_unit]
                x=$x1
                y=$y1
            [/primary_unit]
        [/fire_event]
    [/event]
#enddef

    {STABLE 43 29}
    {STABLE 43 32}

#undef STABLE

    # Moved to stables and found a scout. We have none, spawn Naru
    [event]
        name=stable found

        {NAMED_GENERIC_UNIT 1 "Quenoth Scout" $x1 $y1 "Naru" (_"Naru")}

        [message]
            speaker=Naru
            message= _ "Is it safe to come out? I was so scared."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Where are all the other dustboks?"
        [/message]

        [message]
            speaker=Naru
            message= _ "A hunting party left just yesterday, so unless the rocks fell all over the land, many of the dustboks have probably survived. The few that remained here were scared by the falling rocks and fled into the night. It took all my skill to calm Yasi and keep him from running."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "We’ll need your help in checking to see if the outer settlements survived. Who knows what kinds of damage they suffered in the night? And perhaps some of the people out in the desert have been able to round up some of the loose dusties."
        [/message]

        [message]
            speaker=Nym
            message= _ "We can only hope that hunting party returns soon."
        [/message]

        # We have Naru, spawn Nisa
        # This event replaces containing event to ensure units are found in order
        [event]
            name=stable found

            [message]
                speaker=unit
                message= _ "Hey, Nisen, the rocks have stopped falling. You can come out now!"
                # message= _ "Hey, Nisa, the rocks have stopped falling. You can come out now!"
            [/message]

            {NAMED_UNIT 1 "Quenoth Scout" $x1 $y1 "Nisen" (_"Nisen") (gender=male)}
            # {NAMED_UNIT 1 "Quenoth Scout" $x1 $y1 "Nisa" (_"Nisa") (gender=female)}

            [set_variable]
                name=rescued_elves
                add=1
            [/set_variable]

            [message]
                speaker=Nisen
                # speaker=Nisa
                message= _ "Oh, thank Eloh, I thought they would never stop."
            [/message]
        [/event]
    [/event]

    # The following start and two capture events handle the discovery of
    # random elves in the outer villages. If the player captures a village
    # before an undead unit does, he has a chance of finding a random elf
    # (picked from the $elf_pool array set up in prestart) to join him. However,
    # if an undead unit had captured the village first, there's nothing left.
    #
    # The information about who captured a village first and whether the player
    # has visited the village already is stored in a container unique to each
    # village location, set when someone steps on the village for the first
    # time. For example if the undead capture the village at 30,8 first, the
    # following container would be set:
    #
    # [village_at_30_8]
    #      captured_by=undead
    # [/village_at_30_8]

    [event]
        name=start

        # There is a number of houses inside the oasis and even more tents
        # by the necromancer's fort, we need to make sure that these are
        # ignored. To do this we store coordinates ([store_locations]) of
        # all desert villages (Dd^Vt) that are not ([not]) within
        # rectangle defined by points 40,1 60,12 (x=40-60, y=1-12) or
        # ([or]) rectangle defined by 22,24 43,34 .  First rectangle
        # includes all villages near necromancer, the second covers whole
        # oasis. These coordinates are stored to array called
        # outer_villages (variable=outer_villages).
        [store_locations]
            variable=outer_villages
            terrain=Dd^Vdt,Dd^Vda
            [not]
                x=40-60
                y=1-12
                [or]
                    x=22-43
                    y=24-34
                [/or]
            [/not]
        [/store_locations]
    [/event]

    [event]
        name=capture
        first_time_only=no
        [filter]
            side=1
            [filter_location]
                find_in=outer_villages
            [/filter_location]
        [/filter]
        [filter_condition]
            [variable]
                name=village_at_$x1|_$y1|.visited_by_player
                not_equals=yes
            [/variable]
        [/filter_condition]

        {VARIABLE village_at_$x1|_$y1|.visited_by_player yes}

        [if]
            [variable]
                name=village_at_$x1|_$y1|.captured_by
                not_equals=undead
            [/variable]

            # if this village wasn't captured by undead first, the
            # player has a chance of finding a random elf
            [then]
                {VARIABLE_OP fate rand "1..100"}

                # And check if it's lower than a threshold of
                # finding an unit that's dependent on difficulty
                # level: 60% on easy, 50% on normal, 40% on
                # hard. We use preprocesor to choose appropriate
                # chance
                [if]
                    [variable]
                        name=fate
                        less_than_equal_to={ON_DIFFICULTY 60 50 40}
                    [/variable]
                    [then]
                        # So the RNG smiled upon the player, time to pick a
                        # random elf from pool we defined in prestart

                        {VARIABLE_OP random_elf_pool_index rand "1..$elf_pool.length"}
                        {VARIABLE_OP random_elf_pool_index sub 1}

                        [unit]
                            side=1
                            type=$elf_pool[$random_elf_pool_index].type
                            x,y=$x1,$y1
                            name=$elf_pool[$random_elf_pool_index].name
                            gender=$elf_pool[$random_elf_pool_index].gender
                            random_traits=yes
#ifdef EASY
                            {IS_LOYAL}
                            [modifications]
                                {TRAIT_LOYAL}
                            [/modifications]
#endif
                        [/unit]

                        # When done remove unit from the pool
                        {CLEAR_VARIABLE elf_pool[$random_elf_pool_index]}
                        {CLEAR_VARIABLE random_elf_pool_index}

                        # And write joyful message
                        [message]
                            speaker=unit
                            message= _ "Oh good, some elves have survived in this outer settlement. They’ve agreed to help us search for other survivors."
                        [/message]
                    [/then]
                    # And when RNG plays hardball we need to
                    # inform the player he's out of luck
                    [else]
                        [message]
                            speaker=unit
                            message= _ "The encampment is empty. I wonder what happened to the inhabitants?"
                        [/message]
                    [/else]
                [/if]
                {CLEAR_VARIABLE fate}
            [/then]

            # If this village was captured by undead first, the player
            # can't find any elves there anymore
            [else]
                [message]
                    speaker=unit
                    message= _ "This encampment has been abandoned. There are signs of a struggle and a few bloodstains but nothing else. I fear for those elves who lived out here."
                [/message]
            [/else]
        [/if]
    [/event]

    [event]
        name=capture
        first_time_only=no

        [filter]
            side=3

            [filter_location]
                find_in=outer_villages
            [/filter_location]
        [/filter]

        {VARIABLE village_at_$x1|_$y1|.captured_by undead}
    [/event]

    # Necromancer - spawning the bad guy both on time and prematurely
    # and victory event.

    # Normal necromancer placement, happens around turn 10 depending on
    # difficulty level
    [event]
        name="turn {ON_DIFFICULTY 11 10 9}"

        # If Xanthos does not exist, create him
        # No need for test as event will do nothing if it already ran
        [fire_event]
            name=xanthos_appearance
        [/fire_event]
    [/event]

    # Xanthos appearance event
    [event]
        name=xanthos_appearance

        # Place the bad guy, give him proper gold and income
        [unit]
#ifdef HARD
            type=Necromancer
#else
            type=Dark Sorcerer
#endif
            id=Xanthos
            name= _ "Xanthos"
            canrecruit=yes
            x,y=46,3
            side=3
        [/unit]

        [modify_side]
            side=3
            {GOLD 150 175 200}
            {INCOME 12 15 20}
        [/modify_side]

        [remove_shroud]
            side=1
            x=44-48
            y=1-5
        [/remove_shroud]

        [message]
            speaker=Xanthos
            message= _ "This place reeks of death, I could smell it from miles away. Oh, how I love it, it is the smell of power, the inevitable triumph of death over life. Puny elves, I shall use the corpses of your families to create an army of undead! All shall bow down before Xanthos the Necromancer!"
        [/message]

        [message]
            speaker=Nym
            message= _ "His timing couldn’t be worse. I know that undead cultists often prey on small targets, but they haven’t had the guts to attack us for years. Why has Eloh heaped so much misfortune upon us?"
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Zhul
            message= _ "Have some more faith, girl, the goddess does not send us more than we can handle. With Eloh’s grace we shall yet triumph over this pretender."
        [/message]

        [message]
            speaker=Garak
            message= _ "Bah, I’ve fought these dark cultists before. They can be killed just like anyone else, and our riders can easily defeat their skeleton armies."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I have heard of your kind, foul necromancer. You travel the sands, daring to bring back and enslave those who have passed on. But we will prove to you that death is not all-powerful. You shall not desecrate the bodies of my kith and kin! You shall learn to fear the wrath of Eloh and the Quenoth elves!"
        [/message]

        [place_shroud]
            side=1
            x=44-48
            y=1-5
        [/place_shroud]

        [show_objectives]
        [/show_objectives]
    [/event]

    # This event prevents player from running to the dark sorcerer's base
    # before he shows up on turn 11. If the player approaches his base
    # before turn 11 he appears and attacks. Either way the unit moving
    # into the area also comments on the plight of those elves who lived
    # out in the open sands.
    [event]
        name=moveto
        [filter]
            x=37-60
            y=1-12
            side=1
        [/filter]

        [fire_event]
            name=xanthos_appearance
        [/fire_event]

        [message]
            speaker=unit
            message= _ "Some of our people felt crowded in the village, and wanted to live out on the open sands. They thought they could flee to the safety of our walls if danger came. I shudder to imagine what may have become of them."
        [/message]
    [/event]

    # When the dark sorcerer dies, check to make sure elves have been rescued
    # before ending the scenario. If no set an event that checks if that
    # changed on each move. It's ugly but there is no better way of doing
    # that at the moment

    [event]
        name=die
        [filter]
            id=Xanthos
        [/filter]

        [sound]
            name=wail-long.wav
        [/sound]

        [kill]
            side=3
            animate=yes
            [not]
                id=Xanthos
            [/not]
        [/kill]

        [message]
            speaker=Kaleh
            message= _ "The necromancer is finally vanquished."
        [/message]

        [message]
            speaker=Zhul
            message= _ "And at last the dead shall have their rest."
        [/message]

        [if]
            [variable]
                name=rescued_elves
                not_equals=5
            [/variable]
            [then]
                [message]
                    speaker=Kaleh
                    message= _ "The necromancer is dead, but I don’t think we’ve explored the entire village. There may still be elves that need rescuing. We should go back and check."
                [/message]

                [event]
                    name=moveto
                    [filter]
                        side=1
                    [/filter]
                    [filter_condition]
                        [variable]
                            name=rescued_elves
                            equals=5
                        [/variable]
                    [/filter_condition]

                    [message]
                        speaker=Kaleh
                        message= _ "We’ve explored the village, and I think we’ve rescued the last of the survivors."
                    [/message]

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

    # Elvish hunting party shows up on turn 16
    [event]
        name=turn 16
        [fire_event]
            name=hunting party
        [/fire_event]
    [/event]

    [event]
        name=hunting party

        [remove_shroud]
            side=1
            x=24-32
            y=1-6
        [/remove_shroud]

        {NAMED_GENERIC_UNIT 1 "Quenoth Scout" 29 2 "Pythos" ( _ "Pythos")}
#ifndef HARD
        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 28 2 "Shea" ( _ "Shea")}
#endif
        {NAMED_GENERIC_UNIT 1 "Quenoth Fighter" 29 1 "Narn" ( _ "Narn")}
#ifndef HARD
        {NAMED_GENERIC_UNIT 1 "Quenoth Scout" 27 2 "Jokli" ( _ "Jokli")}
#endif
        {NAMED_GENERIC_UNIT 1 "Quenoth Scout" 28 1 "Lyer" ( _ "Lyer")}
        # {NAMED_GENERIC_UNIT 1 "Quenoth Scout" 28 1 "Lyia" ( _ "Lyia")}
        # [+unit]
        #     gender=female
        # [/unit]

        [message]
            speaker=Pythos
            message= _ "Hail, is anyone still alive?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Yes, and we could certainly use your help. A necromancer has been attacking us, he intends to use our fallen comrades as fodder for his evil magics. Where have you been?"
        [/message]

        [message]
            speaker=Pythos
            message= _ "We were out far in the sands, searching for prey and roaming orcs. As soon as we saw the rock storm we raced back as fast as we could. I only wish we could have come sooner."
        [/message]

        [message]
            speaker=Nym
            message= _ "No use crying over spilt water. But we’re sure glad you’re here now."
        [/message]
    [/event]

    [event]
        name=victory

        # Elvish hunting party arrives if the necromancer died before turn 16.
        [fire_event]
            name=hunting party
        [/fire_event]

        [message]
            speaker=Nym
            message= _ "It seems that we finally have some peace. But what do we do now?"
        [/message]

        [message]
            speaker=Garak
            message= _ "Where is Tanuil and his family?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "The keep has been crushed by the rocks. We could find no survivors."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Too many have died this night."
        [/message]

        [message]
            speaker=Nym
            message= _ "Our village is in ruins. The walls that were built by our ancestors over generations have been demolished in a space of hours. Most of our dwellings are destroyed. And the great tree itself is no more. One thing is obvious, we cannot stay here."
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Garak
            message= _ "You are a fool to despair. This has always been our home. The water here is good, we know this land. We can rebuild; Eloh willing, we can thrive again."
        [/message]

        [message]
            speaker=Nym
            message= _ "Think for a moment. Who else has seen the rock storm? What other foes are coming to pick over the remains of our people? There is no mercy in the desert, and we have many enemies who would seek to gain in our time of weakness."
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Garak
            message= _ "Impudent girl, you should not speak so to your elders, or to your betters."
        [/message]

        [message]
            speaker=Nym
            message= _ "I have a right to speak my mind!"
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Zhul
            message= _ "Peace, please calm yourselves. In chaos there is nothing but death and destruction. Even in this time of trial we must show our fortitude, and follow our laws. Without laws we are like beasts in the desert, fighting over scraps of meat. Among the survivors Kaleh is by heritage the closest relative to Tanuil and thus our leader. What say you Kaleh?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Last night, before the rock storm, I heard a voice in my sleep. It sounded like sweet music, and somehow I knew it was Eloh. I still remember her exact words: <i>“You must be strong, young elf, for you enter a time of peril. The home you know will be destroyed, and you must lead your people to a new land. To the north you will find salvation and peace. Cross the desert and head to the mountains. Fear not, for I will guide you and protect you.”</i> I’m not sure why I’m the one she chose to appeal to, but if this is her will, I will see it done. Our home is gone and the desert is a harsh place. If Eloh has prepared a new home for us, then I will lead us there."
        [/message]

        [message]
            speaker=Garak
            message= _ "I fear what dangers lurk in the harsh sands and beyond to the north, but because you are our leader, I will follow where you go."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Then let us collect what supplies we can from the wreckage and head north with great haste. Our home is protection no longer, we must find a new haven for our people."
        [/message]

        [message]
            speaker=Nym
            message= _ "What about the bodies of the dead? We can’t leave them to be torn by crows or desecrated by other dark mages."
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I agree, we should not forget our dead. We should build a huge pyre and burn them with proper ceremony, so that the smoke may carry them on to the next realm."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Kaleh, I don’t want to tarry longer than necessary, but I agree that we must see to the dead before we leave. Garak, you and your men start collecting our dead. Nym, help me find oil and wood so that we may build a pyre."
        [/message]

        [message]
            speaker=narrator
            message= _ "And so it was done. The dead were laid reverently on top of what little wood we could find. But the fire was big enough to burn the bodies to ashes and speed their souls to the hereafter. I remember at the time that the death of so many of our people was not the best omen for the start of such a large journey. They were the first of our people to die in this great endeavor, but they were to be far from the last."
            image=wesnoth-icon.png
        [/message]

        # Unstore all unspawned units from the pool into the recall list.
        # Provides extra loyal units on easy, and eventually discounted units on all difficulties.
        # Reduces luck issues based on which units were found.

        [foreach]
            array=elf_pool
            [do]
                [unit]
                    side=1
                    type=$this_item.type
                    name=$this_item.name
                    gender=$this_item.gender
                    x=recall
                    y=recall
                    random_traits=yes
#ifdef EASY
                    [modifications]
                        {TRAIT_LOYAL}
                    [/modifications]
                    {IS_LOYAL}
#endif
                [/unit]
            [/do]
        [/foreach]

        # Clear variables
        {CLEAR_VARIABLE seen_mudcrawler}
        {CLEAR_VARIABLE rescued_elves}
        {CLEAR_VARIABLE found_garak}
        {CLEAR_VARIABLE found_zhul}

        # This clears all those village-specific containers that were holding
        # information about who had visited the village
        [foreach]
            array=outer_villages
            [do]
                {CLEAR_VARIABLE village_at_$this_item.x|_$this_item.y|}
            [/do]
        [/foreach]

        {CLEAR_VARIABLE elf_pool}
        {CLEAR_VARIABLE outer_villages}
    [/event]

    [event]
        name=time over

        [message]
            speaker=Kaleh
            message= _ "What’s that to the north? It looks like even more undead! The rock storm must have attracted other necromancers. There’s no way we can defeat them all. We’ve run out of time. There’s no escape. Eloh save us!"
        [/message]
    [/event]

    # Common death events for heroes
#define UTBS_GARAK_MUST_LIVE
#enddef
    {UTBS_INCLUDE utils/deaths.cfg}
#undef UTBS_GARAK_MUST_LIVE
[/scenario]
