#textdomain wesnoth-utbs

# Scenario 1: The Morning After

[scenario]
    # Set the map, ToD cycle, music and story
    id="1_The_Morning_After"
    name= _ "The Morning After"

    # Map data, note lack of any symbols in front of the path below, this
    # means only /data/ folder will be searched, userdata will be omitted
    map_data="{campaigns/Under_the_Burning_Suns/maps/01_The_Morning_After.map}"
    next_scenario=2_Across_the_Harsh_Sands
    {TURNS 34 32 30}

    # 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

    # This campaign uses a custom timeschedule assuming day - short night -
    # day - long night which is supposed to simulate a world with two suns
    # in the sky. Custom times of day are defined in /utils/time.cfg

    {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"}

    # The story
    {STORY_THE_MORNING_AFTER}

    # Set sides - elves, monsters and necromancer
    [side]
        side=1
        id=Kaleh
        name= _ "Kaleh"
        type=Kaleh
        variation=Youth
        [modifications]
#ifndef HARD
            {TRAIT_RESILIENT}
#ifdef EASY
            {TRAIT_INTELLIGENT}
#endif
#endif
        [/modifications]
        canrecruit=yes
        unrenamable=yes

        # Kaleh's start villages will support his initial recruits.
        {GOLD 0 0 0}
        {INCOME 4 2 0}
        controller=human
        shroud=yes
        fog=no
    [/side]

    # Monster side : mudcrawlers and cuttlefish

    [side]
        no_leader=yes
        side=2
        controller=ai
        shroud=no
        fog=no
        team_name=monsters
        user_team_name=_"Monsters"
        [ai]
            aggression=1.0
            caution=0.0
            # weak ai
            {ATTACK_DEPTH 1 2 3}
        [/ai]
    [/side]

    # Undead side, doesn't start with a leader
    [side]
        no_leader=yes
        side=3
        controller=ai
        shroud=no
        fog=no
        team_name=evil
        user_team_name=_"Evil"
        #Values reset later on, needed for proper execution of Necromancer event
        {GOLD 100 100 100}
        {INCOME -2 -2 -2}
        {FLAG_VARIANT undead}
#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
        [ai]
            recruitment_ignore_bad_movement=yes
            recruitment_ignore_bad_combat=yes
#ifdef HARD
            recruitment_pattern=scout,fighter,fighter,fighter,archer
#else
            recruitment_pattern=scout,fighter,archer,fighter
#endif
            aggression=0.80
            caution=0.10
            {ATTACK_DEPTH 2 3 4}
        [/ai]
    [/side]

    # Set required variables and initial dialogue
    # Variables set:
    # $seen_mudcrawler{'yes','no'}, $rescued_elves{0-5}, $elf_pool[], $seen_naru{'yes','no'}

    # prestart events:
    # set starting scenario objectives
    # set starting variables
    [event]
        name=prestart
        # set starting scenario objectives
        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Rescue Surviving Elves"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kaleh, Nym, Garak or Zhul"
                condition=lose
            [/objective]

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

        # Start with Nym
        [unit]
            type=Nym Hunter
            id=Nym
            name= _ "Nym"
            side=1
            x=27
            y=22
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
#ifndef HARD
                {TRAIT_RESILIENT}
#ifdef EASY
                {TRAIT_QUICK}
#endif
#endif
            [/modifications]
            {IS_HERO}
        [/unit]
        # 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.

        # At start seen a mudcrawler is false
        {VARIABLE seen_mudcrawler "no"}

        # Whether Naru (scout hiding in a village) has been rescued yet
        {VARIABLE seen_naru "no"}

        # Can't end scenario until all elves have been rescued (5 events)
        {VARIABLE rescued_elves 0}

        # setting up the village occupants
        # 2 fighters, 2 archers, 2 hunters, 2 scouts
        [set_variables]
            name=elf_pool
            [value]
                type="Desert Fighter"
                name=_"Lrea"
                gender=female
            [/value]
            [value]
                type="Desert Fighter"
                name=_"Piyru"
                gender=male
            [/value]
            [value]
                type="Desert Archer"
                name=_"Frea"
                gender=female
            [/value]
            [value]
                type="Desert Archer"
                name=_"Danu"
                gender=male
            [/value]
            [value]
                type="Desert Hunter"
                name=_"Hamuil"
                gender=male
            [/value]
            [value]
                type="Desert Hunter"
                name=_"Anioh"
                gender=male
            [/value]
            [value]
                type="Desert Scout"
                name=_"Vemuil"
                gender=male
            [/value]
            [value]
                type="Desert Scout"
                name=_"Taliu"
                gender=male
            [/value]
        [/set_variables]
    [/event]

    # Dialogue 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
            # wmllint: local spelling C'mon
            message= _ "C'mon 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]

    # Dialogue 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]

    # 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 Nisa

    [event]
        name=moveto
        [filter]
            x=17-26
            y=23-28
            side=1
        [/filter]

        {VARIABLE_OP rescued_elves add 1}
        {NAMED_GENERIC_UNIT 1 "Desert Fighter" 24 25 "Vecnu" ( _ "Vecnu")}
        {NAMED_GENERIC_UNIT 1 "Desert Archer" 24 27 "Eranor" ( _ "Eranor")}
        {NAMED_GENERIC_UNIT 1 "Desert Archer" 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
                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?"
                [/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
    [event]
        name=moveto
        [filter]
            x=17-28
            y=29-36
            side=1
        [/filter]

        {VARIABLE_OP rescued_elves add 1}
        {NAMED_GENERIC_UNIT 1 "Desert Hunter" 24 34 "Eloshi" ( _ "Eloshi")}
        {NAMED_GENERIC_UNIT 1 "Desert Archer" 19 33 "Illuvia" ( _ "Illuvia")}
        [+unit]
            gender=female
        [/unit]
        {NAMED_GENERIC_UNIT 1 "Desert Hunter" 21 35 "Raynor" ( _ "Raynor")}

        {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
    [event]
        name=moveto
        [filter]
            x=32-39
            y=32-36
            side=1
        [/filter]

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

        {ADD rescued_elves 1}

        # wmllint: recognize Rocky Horror
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 34 33}
        [+unit]
            role="Rocky Horror"
        [/unit]
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 34 34}
        [+unit]
            role="Rocky Horror"
        [/unit]
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 34 35}
        [+unit]
            role="Rocky Horror"
        [/unit]
#ifdef HARD
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 35 33}
        [+unit]
            role="Rocky Horror"
        [/unit]
#else
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 35 33}
        [+unit]
            role="Rocky Horror"
        [/unit]
#endif
#ifdef EASY
        {NOTRAIT_UNIT 2 "Small Mudcrawler" 36 32}
        [+unit]
            role="Rocky Horror"
        [/unit]
#else
        {NOTRAIT_UNIT 2 "Giant Mudcrawler" 36 32}
        [+unit]
            role="Rocky Horror"
        [/unit]
#endif

        [unit]
            type=Desert Captain
            id=Garak
            name= _ "Garak"
            profile=portraits/garak.png
            x=35
            y=34
            side=1
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
                [object]
                    [effect]
                        apply_to=attack
                        range=ranged
                        increase_damage=1
                    [/effect]
                [/object]
            [/modifications]
            {IS_HERO}
        [/unit]

        {NAMED_GENERIC_UNIT 1 "Desert Fighter" 36 33 "Jorazan" ( _ "Jorazan")}
        {NAMED_GENERIC_UNIT 1 "Desert 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
                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?"
                [/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]

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

            [if]
                [not]
                    [have_unit]
                        role="Rocky Horror"
                    [/have_unit]
                [/not]
                [then]
                    [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]
                [/then]
            [/if]
        [/event]
    [/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 dialogue
    [event]
        name=moveto
        [filter]
            x=30-32
            y=29-35
            side=1
        [/filter]

        # That's supposed to 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]

            {ADD rescued_elves 1}
            [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]
                type=Desert Druid
                id=Zhul
                name= _ "Zhul"
                profile=portraits/zhul.png
                x=31
                y=27
                side=1
                unrenamable=yes
                [modifications]
                    {TRAIT_LOYAL}
                    {TRAIT_QUICK}
                    {TRAIT_INTELLIGENT}
                [/modifications]
                {IS_HERO}
            [/unit]
            {NAMED_GENERIC_UNIT 1 "Desert Shaman" 30 27 "Ryoko" ( _ "Ryoko")}
            {NAMED_GENERIC_UNIT 1 "Desert Shaman" 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]

            #Lake monster event

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

                [unit]
                    type=Cuttle Fish
                    id="Deep One"
                    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 basicaly 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=-4
                            [/effect]
                            [effect]
                                apply_to=hitpoints
                                increase_total=-27
                            [/effect]
#ifndef HARD
                            [effect]
                                apply_to=defense
                                replace=yes
                                [defense]
                                    shallow_water=50
                                [/defense]
                            [/effect]
#endif
                        [/trait]
                    [/modifications]
                    x=32
                    y=30
                    side=2
                [/unit]
                [message]
                    speaker=narrator
                    message= _ "The water of the lake suddenly goes dark and unsettled, only to erupt in a swarm of tentacles in the moment that the first elf put a foot outside the island."
                    image=wesnoth-icon.png
                [/message]
                [message]
                    speaker=Nym
                    message= _ "What in Uria's name is that?"
                [/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 dialogue, 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 horses?"
        [/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

    [event]
        name=stable found
        first_time_only=no
        # Moved to stables and found a scout. If we have none, spawn Naru
        # wmllint: recognize Naru
        [if]
            [variable]
                name=seen_naru
                equals="yes"
            [/variable]
            [then]
                # If we have Naru, spawn Nisa
                [message]
                    speaker=unit
                    message= _ "Hey, Nisa, the rocks have stopped falling. You can come out now!"
                [/message]
                {NAMED_GENERIC_UNIT 1 "Desert Scout" $x1 $y1 "Nisa" (_"Nisa")}
                {ADD rescued_elves 1}
                [+unit]
                    gender=female
                [/unit]
                [message]
                    speaker=Nisa
                    message= _ "Oh, thank Eloh, I thought they would never stop."
                [/message]
            [/then]
            [else]
                {NAMED_GENERIC_UNIT 1 "Desert Scout" $x1 $y1 "Naru" (_"Naru")}
                [set_variable]
                    name=seen_naru
                    value="yes"
                [/set_variable]
                [message]
                    speaker=Naru
                    message= _ "Is it safe to come out? I was so scared."
                [/message]
                [message]
                    speaker=Kaleh
                    message= _ "Where are all the other horses?"
                [/message]
                [message]
                    speaker=Naru
                    message= _ "A hunting party left just yesterday, so unless the rocks fell all over the land, many of the horses 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 horses."
                [/message]
                [message]
                    speaker=Nym
                    message= _ "We can only hope that hunting party returns soon."
                [/message]
            [/else]
        [/if]
    [/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_first_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]

        # if this village had been visited by the player already, do nothing and
        # allow undoing
        [if]
            [variable]
                name=village_at_$x1|_$y1|.visited_by_player
                not_equals=yes
            [/variable]

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

                [if]
                    [variable]
                        name=village_at_$x1|_$y1|.captured_first_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 village_at_$x1|_$y1|.captured_first_by elves}

                        {VARIABLE_OP fate random 1..100}
                        # And check if it's lower than a threshold of
                        # finding an unit that's dependent on diffficulty
                        # level: 60% on easy, 50% on normal, 40% on
                        # hard. We use preprocesor to choose apropriate
                        # chance
                        [if]
                            [variable]
                                name=fate
#ifdef EASY
                                less_than_equal_to=60
#endif
#ifdef NORMAL
                                less_than_equal_to=50
#endif
#ifdef HARD
                                less_than_equal_to=40
#endif
                            [/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 random "1..$elf_pool.length"}
                                {VARIABLE_OP random_elf_pool_index add -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
                                    [modifications]
                                        {TRAIT_LOYAL}
                                    [/modifications]
                                    {IS_LOYAL}
#endif
                                [/unit]

                                # When done remove unit from the pool
                                {CLEAR_VARIABLE elf_pool[$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]
                    [/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]
            [/then]

            [else]
                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=capture
        first_time_only=no

        [filter]
            side=3

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

        [if]
            [variable]
                name=village_at_$x1|_$y1|.captured_first_by
                not_equals=elves
            [/variable]

            [then]
                {VARIABLE village_at_$x1|_$y1|.captured_first_by undead}
            [/then]
        [/if]
    [/event]

    [event]
        name=victory

        # This unstores all unspawned units from the pool into the recall list.
        # Reason for this is pretty simple, it's much easier to finish Scenario
        # 3 (for example) having two free hunters than two free scouts.
        #
        # I don't understand this. Why should a unit with no traits and no experience be a value for the player?
        # Recruiting one that has traits is cheaper than recalling. -- Fabi

        {FOREACH elf_pool i}
            [unit]
                side=1
                type=$elf_pool[$i].type
                name=$elf_pool[$i].name
                gender=$elf_pool[$i].gender
                x=recall
                y=recall
                random_traits=yes
#ifdef EASY
                [modifications]
                    {TRAIT_LOYAL}
                [/modifications]
                {IS_LOYAL}
#endif
            [/unit]
        {NEXT i}

        # This clears all those village-specific containers that were holding
        # information about who had visited the village
        {FOREACH outer_villages i}
            {CLEAR_VARIABLE village_at_$outer_villages[$i].x|_$outer_villages[$i].y|}
        {NEXT i}

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

    # Necromancer - spawning the bad guy both on time and prematurely
    # and victory event.
    # Variables cleared :
    # $seen_mudcrawler, $rescued_elves

    # We're going to use this piece of WML in two different places without
    # a change, that's why it's placed within a macro
#define DARKSORCERER_INTRO
    # 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=46
        y=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?"
    [/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 elvish hunters 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]
    [objectives]
        summary= _ "New Objectives:"
        show=yes
        [objective]
            description= _ "Rescue Surviving Elves"
            condition=win
        [/objective]
        [objective]
            description= _ "Defeat Xanthos"
            condition=win
        [/objective]
        [objective]
            description= _ "Death of Kaleh, Nym, Garak or Zhul"
            condition=lose
        [/objective]

        note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
    [/objectives]
#enddef

    # Normal necromancer placement, happens around turn 10 depending on
    # difficulty level
    [event]
#ifdef EASY
        name=turn 11
#endif
#ifdef NORMAL
        name=turn 10
#endif
#ifdef HARD
        name=turn 9
#endif

        # If Xanthos does not exist and undead gold is unmodified it means he
        # never showed up. We need this check in case player triggered him
        # earlier and managed to kill already, otherwise he might get spawned
        # once more
        [if]
            [not]
                [have_unit]
                    id=Xanthos
                [/have_unit]
            [/not]
            [then]
                [modify_side]
                    side=3
                    gold=100
                [/modify_side]
                {DARKSORCERER_INTRO}
            [/then]
        [/if]
    [/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
                    first_time_only=no
                    [filter]
                        x=1-60
                        y=1-60
                        side=1
                    [/filter]
                    [if]
                        [variable]
                            name=rescued_elves
                            equals=5
                        [/variable]
                        [then]
                            [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]
                        [/then]
                    [/if]
                [/event]
            [/then]
            [else]
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/else]
        [/if]
    [/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]

        [if]
            [not]
                [have_unit]
                    side=3
                [/have_unit]
            [/not]
            [then]
                {DARKSORCERER_INTRO}
            [/then]
        [/if]
        [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]

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

    # Elvish hunting party should arrive if the necromancer died before turn 16.
    [event]
        name=victory
        [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 "Desert Hunter" 29 2 "Pythos" ( _ "Pythos")}
        {NAMED_GENERIC_UNIT 1 "Desert Fighter" 28 2 "Shea" ( _ "Shea")}
        {NAMED_GENERIC_UNIT 1 "Desert Fighter" 29 1 "Narn" ( _ "Narn")}
        {NAMED_GENERIC_UNIT 1 "Desert Scout" 27 2 "Jokli" ( _ "Jokli")}
        {NAMED_GENERIC_UNIT 1 "Desert Archer" 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]

    # On victory dialogue
    [event]
        name=victory
        [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."
        [/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."
        [/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!"
        [/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: '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'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."
        [/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]

        # Clear variables
        {CLEAR_VARIABLE seen_mudcrawler}
        {CLEAR_VARIABLE rescued_elves}
        {CLEAR_VARIABLE seen_naru}
    [/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]

    # Kaleh abilities - special custom AMLAS for Kaleh
    {campaigns/Under_the_Burning_Suns/utils/kaleh-abilities.cfg}

    # Common death events for heroes
    {campaigns/Under_the_Burning_Suns/utils/deaths.cfg}
[/scenario]
