#textdomain wesnoth-utbs

[scenario]
    id=08_Out_of_the_Frying_Pan
    name= _ "Out of the Frying Pan"
    next_scenario=09_Blood_is_Thicker_Than_Water
    {UTBS_MAP 08_Out_of_the_Frying_Pan.map}

    {STORY_OUT_OF_THE_FRYING_PAN}

    {SCENARIO_MUSIC "underground.ogg"}
    {EXTRA_SCENARIO_MUSIC "loyalists.ogg"}
    {EXTRA_SCENARIO_MUSIC "suspense.ogg"}
    #TODO redo the playlist

    {TURNS 72 68 64}

    victory_when_enemies_defeated=no

    {TWO_SUNS_DEFAULT_SCHEDULE}

    #Side 1: elves
    [side]
        side=1
        id=Kaleh
        type=Quenoth Youth
        canrecruit=yes
        gold=200
        {INCOME 4 2 0}
        controller=human
        shroud=yes
        fog=no
        team_name=elf_ally
        user_team_name= _ "team_name^Quenoth Elves"
        {FLAG_VARIANT long}
    [/side]

    #Side 2: Human forces (blue)
    [side]
        side=2
        no_leader=yes
        gold=0
        income=0
        controller=ai
        team_name=human_ally
        user_team_name=_"Humans"
        {FLAG_VARIANT undead}
#ifdef EASY
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Bowman, Longbowman
#else
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Bowman, Longbowman, Dragoon
#endif
        [ai]
            recruitment_pattern=scout,fighter,archer

            aggression=0.6
            caution=0.1

            passive_leader=yes

            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=10
            [/goal]
        [/ai]
    [/side]

    #Side=3 undead cultists (green)
    [side]
        side=3
        no_leader=yes
        gold=0
        income=0
        controller=ai
        team_name=cultists
        user_team_name=_"Cultists"
        {FLAG_VARIANT undead}
        [ai]
            aggression=0.8
            caution=0.1
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    #Side=4 confused ants (yellow)
    [side]
        side=4
        no_leader=yes
        gold=0
        income=0
        controller=ai
        hidden=yes
        [ai]
            aggression=-0.99
            caution=0.99

            #keep ants from running too far down the tunnel
            [avoid]
                x=31-36
                y=45-49
            [/avoid]
        [/ai]
    [/side]

    #Side=5 Vengeful Undead
    [side]
        side=5
        no_leader=yes
        gold=0
        income=0
        controller=ai
        team_name=human_ally
        user_team_name=_"Human Ally"
        {FLAG_VARIANT undead}
        recruit=EGhost, EWraith, EShadow
        hidden=yes
        [ai]
            aggression=0.75
            caution=0.1

            recruitment_pattern=scout

            # keep undead away from player’s base
            # option 1 is to avoid x=1-19 (let them enter cave but not
            # sneak around behind base)
            # option 2 is to avoid x=1-25 (lets them get near cave
            # but not enter it)

            [avoid]
                x,y=1-25,1-60
            [/avoid]
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    #Side=6 dwarf/troll pursuers
    [side]
        side=6
        no_leader=yes
        gold=0
        income=0
        controller=ai
        hidden=yes

        [ai]
            aggression=0.8
            caution=0.1
        [/ai]
    [/side]

    #Side=7 Assassin/Cloaked Figure's side
    [side]
        side=7
        no_leader=yes
        gold=0
        income=0
        controller=ai
        team_name=monster
        hidden=yes

        [ai]
            aggression=0.90
            caution=0.10

            [avoid]
                x=10-20
                y=10-18
            [/avoid]
            [goal]
                name=target
                [criteria]
                    id=Kaleh
                [/criteria]
                value=20
            [/goal]
        [/ai]
    [/side]

    #Side=8 Human messengers
    [side]
        side=8
        no_leader=yes
        gold=0
        income=0
        controller=ai
        team_name=human_ally
        user_team_name=_"Humans"
        {FLAG_VARIANT undead}
    [/side]

    {LOYALIST_COLOR_SHIFT}

    # Prestart functions:
    # insert items onto map
    # kill Elyssa to keep her from being recruited
    # increase cost of recruiting units
    # place item images on map
    # recall main heroes
    # initialize starting variables
    # remove shroud surrounding starting position
    # add more dirt at easier difficulties
    # set starting scenario objectives

    [event]
        name=prestart

        # add items to map

        # main gate guardian runes
        {PLACE_IMAGE items/rune2-burning.png 23 48}
        {PLACE_IMAGE items/rune2-burning.png 20 45}

        # wizard chamber guardian rune
        {PLACE_IMAGE items/rune4-burning.png 18 34}

        # wizard's monster trapping runes
        {PLACE_IMAGE items/rune3-burning.png 17 32}
        {PLACE_IMAGE items/rune3-burning.png 19 32}

        # wizard's magic circle
        {PLACE_IMAGE items/magiccircle-nw.png 17 29}
        {PLACE_IMAGE items/magiccircle-n.png 18 28}
        {PLACE_IMAGE items/magiccircle-ne.png 19 29}
        {PLACE_IMAGE items/magiccircle-sw.png 17 30}
        {PLACE_IMAGE items/magiccircle-s.png 18 30}
        {PLACE_IMAGE items/magiccircle-se.png 19 30}

        # golem trapped in magic circle
        {PLACE_IMAGE "units/monsters/flesh-golem.png~RC(magenta>red)" 18 29}

        # Miscellaneous potions
        {PLACE_IMAGE items/potion-poison.png 18 27}
        {PLACE_IMAGE items/potion-red.png 17 28}
        {PLACE_IMAGE items/potion-grey.png 19 28}
        {PLACE_IMAGE items/potion-yellow.png 16 29}
        {PLACE_IMAGE items/potion-green.png 20 29}

        # wizard's dragon statues
        [item]
            image=items/dragonstatue.png
            x,y=16,28
        [/item]

        [item]
            image=items/dragonstatue.png~FL()
            x,y=20,28
        [/item]

        # center chamber healing runes
        {PLACE_IMAGE items/rune-lightblue-small.png 17 44}
        {PLACE_IMAGE items/rune-lightblue-small.png 19 43}

        # kitchen trash + rocks
        {PLACE_IMAGE scenery/trash.png 12 46}
        {PLACE_IMAGE scenery/trash.png 10 49}
        {PLACE_IMAGE scenery/trash.png 9 47}
        {PLACE_IMAGE scenery/rubble.png 10 48}

        # barracks trash + rocks
        {PLACE_IMAGE scenery/trash.png 15 40}
        {PLACE_IMAGE scenery/trash.png 14 36}
        {PLACE_IMAGE scenery/trash.png 13 39}
        {PLACE_IMAGE scenery/rubble.png 15 38}
        {PLACE_IMAGE scenery/rubble.png 18 39}
        {PLACE_IMAGE items/bones.png 15 36}
        {PLACE_IMAGE items/bones.png 16 39}

        # training hall skeletons (remains of students + trainer)
        {PLACE_IMAGE items/bones.png 9 40}
        {PLACE_IMAGE items/bones.png 9 43}
        {PLACE_IMAGE items/bones.png 11 41}
        {PLACE_IMAGE items/bones.png 12 42}

        # crypt coffins + rocks
        {PLACE_IMAGE items/coffin-closed.png 10 26}
        {PLACE_IMAGE items/coffin-closed.png 10 28}
        {PLACE_IMAGE items/coffin-closed.png 12 25}
        {PLACE_IMAGE items/coffin-closed.png 12 27}
        {PLACE_IMAGE scenery/rubble.png 12 28}

        # cloaked figure chamber
        {PLACE_IMAGE scenery/rubble.png 8 21}

        # temple altar
        {PLACE_IMAGE items/altar-evil.png 6 33}
        {PLACE_IMAGE items/bones.png 7 36}

        # rocks in human outpost/elves base cave
        {PLACE_IMAGE scenery/rubble.png 16 17}

        # chest of gold in human outpost at cave mouth
        {PLACE_IMAGE items/chest-plain-closed.png 17 21}

        # kill Elyssa to keep her from being recruited

        [kill]
            id=Elyssa
            animate=no
            fire_event=no
        [/kill]

        {INCREASE_RECRUIT_COSTS 1}

        # Place units in the encampment
        [recall]
            id=Nym
            x,y=52,42
        [/recall]

        [recall]
            id=Zhul
            x,y=52,41
        [/recall]

        # recall dwarf/troll ally
        [recall]
            id=$ally_name
            x,y=51,43
        [/recall]

        # wmllint: recognize Grog
        # wmllint: recognize Nog
        # wmllint: recognize Rogrimir
        # wmllint: recognize Jarl

        # put hero icon on troll/dwarf ally
        [unit_overlay]
            id=$ally_name
            image=misc/hero-icon.png
        [/unit_overlay]

        # initialize starting variables

        [set_variable]
            name=ally_must_live
            value=yes
        [/set_variable]

        [set_variable]
            name=healing_rune1
            value=1
        [/set_variable]

#ifdef EASY
        [set_variable]
            name=healing_rune2
            value=2
        [/set_variable]
#else
        [set_variable]
            name=healing_rune2
            value=1
        [/set_variable]
#endif

        # timer to store when to send off a human messenger
        [set_variable]
            name=messenger_timer
            value=0
        [/set_variable]

        #remove shroud surrounding starting position
        [remove_shroud]
            x=48-64,48-57
            y=41-49,38-42
            side=1
        [/remove_shroud]

        # add more dirt to secret passage at easier difficulties

#ifndef HARD
        [terrain]
            x,y=20,51
            terrain=Re
        [/terrain]
#endif

#ifdef EASY
        [terrain]
            x,y=17,51
            terrain=Re
        [/terrain]
#endif

        # set starting scenario objectives
        [objectives]
            [objective]
                description= _ "Escape the caves"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL ally_must_live boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Explore outside"
                condition=win
                [show_if]
                    [not]
                        [have_unit]
                            id=Sergeant Durstrag,Esanoo
                        [/have_unit]
                    [/not]
                    {VARIABLE_CONDITIONAL ally_must_live boolean_equals no}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Defeat Sergeant Durstrag"
                condition=win
                [show_if]
                    [have_unit]
                        id=Sergeant Durstrag
                    [/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 Zhul"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Grog"
                condition=lose
                [show_if]
                    {VARIABLE_CONDITIONAL ally_name equals "Grog"}
                    {VARIABLE_CONDITIONAL ally_must_live boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Nog"
                condition=lose
                [show_if]
                    {VARIABLE_CONDITIONAL ally_name equals "Nog"}
                    {VARIABLE_CONDITIONAL ally_must_live boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Rogrimir"
                condition=lose
                [show_if]
                    {VARIABLE_CONDITIONAL ally_name equals "Rogrimir"}
                    {VARIABLE_CONDITIONAL ally_must_live boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Jarl"
                condition=lose
                [show_if]
                    {VARIABLE_CONDITIONAL ally_name equals "Jarl"}
                    {VARIABLE_CONDITIONAL ally_must_live boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "A human messenger escapes the valley"
                condition=lose
                [show_if]
                    {VARIABLE_CONDITIONAL messengers_incoming boolean_equals yes}
                [/show_if]
            [/objective]

            {TURNS_RUN_OUT}

            [note]
                description= _  "The messenger is the leader of the special white colored units"
                [show_if]
                    {VARIABLE_CONDITIONAL messengers_incoming boolean_equals yes}
                [/show_if]
            [/note]

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

    # Event 1: Starting dialogue & dwarves/troll appear

    [event]
        name=start

        [message]
            speaker=$ally_name
            message= _ "We’ve come far and we’re almost to the surface. But first we should stop and rest here for a while."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "That’s a big river; the water is really moving fast."
        [/message]

        [if]
            [variable]
                name=ally_race
                equals=dwarf
            [/variable]

            [then]
                [message]
                    speaker=$ally_name
                    message= _ "Yes, this time of year the snow melts from the mountains, and rivers like this often go deep underground. Sometimes the rivers break through and flood caverns, a deadly accident that has occasionally befallen my kind."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=$ally_name
                    message= _ "Deep and dark are the waters that flow in our caves. Sometimes raging waters flood tunnels without warning. A stream can sustain a village, a sudden flood can destroy it."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Nym
            message= _ "Well, the faster we get out of here, the happier I’ll be."
        [/message]

        [sound]
            name=cave-in.ogg
        [/sound]

        {UTBS_SHAKE_SCREEN}

        [message]
            speaker=Zhul
            message= _ "Wait, did you feel that?"
        [/message]

        [message]
            speaker=Nym
            message= _ "What?"
            image=portraits/nym_moody.png
        [/message]

        [message]
            speaker=Zhul
            message= _ "It felt like a distant rumbling. And what’s that roaring sound?"
        [/message]

        # create trolls/dwarves

        #in easier difficulties, I wound troll/dwarf units

        [if]
            [variable]
                name=ally_race
                equals=dwarf
            [/variable]

            [then]
                [move_unit_fake]
                    type=Troll Whelp
                    side=6
                    x=52,52,53,53,53,53,52,51
                    y=50,49,49,48,47,46,45,45
                [/move_unit_fake]

                [unit]
                    type=Troll Whelp
                    name= _ "Troll Avenger"
                    side=6
                    x=51
                    y=45
#ifdef EASY
                    hitpoints=28
#endif
#ifdef NORMAL
                    hitpoints=32
#endif
                [/unit]

                [move_unit_fake]
                    type=Troll Whelp
                    side=6
                    x=52,52,53,53,53,53,52,52
                    y=50,49,49,48,47,46,45,44
                [/move_unit_fake]

                [unit]
                    type=Troll Whelp
                    name= _ "Troll Avenger"
                    side=6
                    x=52
                    y=44
#ifdef EASY
                    hitpoints=28
#endif
#ifdef NORMAL
                    hitpoints=32
#endif
                [/unit]

                [move_unit_fake]
                    type=Troll Shaman
                    side=6
                    x=52,52,53,53,53,53,52
                    y=50,49,49,48,47,46,45
                [/move_unit_fake]

                [unit]
                    type=Troll Shaman
                    name= _ "Troll Avenger"
                    role=avenger
                    side=6
                    x=52
                    y=45
#ifdef EASY
                    hitpoints=34
#endif
#ifdef NORMAL
                    hitpoints=38
#endif
                [/unit]

                [message]
                    role=avenger
                    message= _ "Foul elves, you not escaped us yet. The Great Leader shall be avenged! We have dammed the river and soon all shall drown in its dark waters. Come join us in death!"
                [/message]
            [/then]

            [else]
                [move_unit_fake]
                    type=Dwarvish Fighter
                    side=6
                    x=52,52,53,53,53,53,52,51
                    y=50,49,49,48,47,46,45,45
                [/move_unit_fake]

                [unit]
                    type=Dwarvish Fighter
                    name= _ "Dwarf Avenger"
                    side=6
                    x=51
                    y=45
#ifdef EASY
                    hitpoints=26
#endif
#ifdef NORMAL
                    hitpoints=30
#endif
                [/unit]

                [move_unit_fake]
                    type=Dwarvish Thunderer
                    side=6
                    x=52,52,53,53,53,53,52,52
                    y=50,49,49,48,47,46,45,44
                [/move_unit_fake]

                [unit]
                    type=Dwarvish Thunderer
                    name= _ "Dwarf Avenger"
                    side=6
                    x=52
                    y=44
#ifdef EASY
                    hitpoints=26
#endif
#ifdef NORMAL
                    hitpoints=30
#endif
                [/unit]

                [move_unit_fake]
                    type=Dwarvish Pathfinder
                    side=6
                    x=52,52,53,53,53,53,52
                    y=50,49,49,48,47,46,45
                [/move_unit_fake]

                [unit]
                    type=Dwarvish Pathfinder
                    name= _ "Dwarf Avenger"
                    role=avenger
                    side=6
                    x=52
                    y=45
#ifdef EASY
                    hitpoints=25
#endif
#ifdef NORMAL
                    hitpoints=32
#endif
                [/unit]

                [message]
                    role=avenger
                    message= _ "Foul elves, you have not escaped yet. Our chieftain shall be avenged! We have dammed the river and soon all shall drown in its dark waters. Come join us in death!"
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Kaleh
            message= _ "That sound must be the rushing water. We have to get our people out of here, and fast!"
        [/message]

        [message]
            speaker=$ally_name
            message= _ "Quick, the southern passage!"
        [/message]

        [message]
            speaker=Zhul
            message= _ "We haven’t a moment to lose!"
        [/message]
    [/event]

    # Event 2: confused ants

    #EASY: 3 fleeing ants, 1 normal ant
    #NORMAL: 3 fleeing ants, 2 normal ants
    #HARD: 3 fleeing ants, 3 normal ants

    [event]
        name=moveto

        [filter]
            x=36-42
            y=45-53
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [terrain]
            x=44
            y=52
            terrain=Wwg
        [/terrain]

        #create confused ants

        [unit]
            type=Giant Ant
            x=42
            y=49
            side=4
            goto_x=39
            goto_y=49
        [/unit]

        [unit]
            type=Giant Ant
            x=40
            y=52
            side=4
            goto_x=38
            goto_y=50
        [/unit]

        [unit]
            type=Giant Ant
            x=43
            y=51
            side=4
            goto_x=38
            goto_y=49
        [/unit]

        [unit]
            type=Giant Ant
            x=39
            y=50
            side=4
        [/unit]

#ifndef EASY
        [unit]
            type=Giant Ant
            x=38
            y=52
            side=4
        [/unit]
#endif

#ifdef HARD
        [unit]
            type=Giant Ant
            x=41
            y=52
            side=4
        [/unit]
#endif

        [remove_shroud]
            side=1
            x=37-44,36-41
            y=46-53,50-54
        [/remove_shroud]

        [if]
            # The ally has not seen the first set of ants, so has a different reaction.
            [variable]
                name=unit.id
                equals=$ally_name
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "Hey look, ants!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Hey look, more ants!"
                [/message]
            [/else]
        [/if]

        [if]
            # check to see if Nym is the unit that triggered this event
            # to keep her from talking to herself during the dialogue
            [variable]
                name=unit.id
                not_equals=Nym
            [/variable]

            [then]
                [message]
                    speaker=Nym
                    message= _ "Are you sure there aren’t any spiders?"
                [/message]

                [message]
                    speaker=unit
                    message= _ "No, but the water is rising to the southeast as well. The river must lead to more tunnels than we first thought."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message= _ "I don’t see any spiders, but the water is rising to the southeast as well. The river must lead to more tunnels than we first thought."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Zhul
            message= _ "The ants must be fleeing from the flood too."
        [/message]

        [message]
            speaker=unit
            message= _ "They seem confused, leaderless. I guess it’s every ant for itself. Uh, oh. Some of them seem to have noticed us."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Well, we have to get out of here too. Looks like we don’t have any choice but to fight our way through the chaos."
        [/message]
    [/event]

    # Event 3: human explorers / cave delvers / spelunkers

    [event]
        name=moveto

        [filter]
            x=30-34
            y=43-48
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [terrain]
            x=36,37
            y=43,43
            terrain=Wwg
        [/terrain]

        [remove_shroud]
            side=1
            x=29-35,28-30
            y=41-49,44-46
        [/remove_shroud]

        [move_unit_fake]
            type=Javelineer
            side=2
            x=36,35,34,33
            y=42,43,43,44
            image_mods={ARMOR_SHIFT_IPF}
        [/move_unit_fake]

        {NAMED_UNIT 2 (Javelineer) 33 44 (Bellerin) ( _ "Bellerin") (upkeep,role,facing=free,human_scout,sw)}

        [move_unit_fake]
            type=Swordsman
            side=2
            x=36,35,34,34
            y=42,43,43,44
            image_mods={ARMOR_SHIFT_IPF}
        [/move_unit_fake]

        {NAMED_UNIT 2 (Swordsman) 34 44 (Durth) ( _ "Durth") (upkeep,role,facing=free,human_scout,sw)}

        [move_unit_fake]
            type={ON_DIFFICULTY (Bowman) (Longbowman) (Master Bowman)}
            side=2
            x=36,35,34
            y=42,43,43
            image_mods={ARMOR_SHIFT_IPF}
        [/move_unit_fake]

        {NAMED_UNIT 2 {ON_DIFFICULTY (Bowman) (Longbowman) (Master Bowman)} 34 43 (Othgar) ( _ "Othgar") (upkeep,role,facing=free,human_scout,sw)}

        [message]
            speaker=Durth
            # wmllint: local spelling durn
            message= _ "<i>Huff, huff.</i> First the boss tells us to patrol these caves, and then these durn caves start flooding. What next?"
        [/message]

        [message]
            speaker=Bellerin
            message= _ "Shut up and keep running, or we’ll be fish-bait for sure!"
        [/message]

        [switch]
            variable=unit.race
            [case]
                value=troll
                [message]
                    speaker=Othgar
                    message= _ "Hey look! It’s a troll!"
                [/message]
                [message]
                    speaker=Durth
                    message= _ "Huh? A troll?"
                [/message]
                [message]
                    speaker=Bellerin
                    message= _ "Yeah, just like my old grandmam used to tell us: dark gray skin, beady red eyes, hulking brutes with brains as small as a barnacle. They lurk deep in the earth and hate everything that lives above ground. This must be an invasion! The trolls must have started the flood!"
                [/message]

                [set_variable]
                    name=sealife_response
                    value= _ "Fish bait? Barnacles? Who are these humans and what were they talking about?"
                [/set_variable]
            [/case]
            [case]
                value=dwarf
                [message]
                    speaker=Othgar
                    message= _ "Hey look! It’s a dwarf!"
                [/message]
                [message]
                    speaker=Durth
                    message= _ "Huh? A dwarf?"
                [/message]
                [message]
                    speaker=Bellerin
                    message= _ "Yeah, just like my old grandmam used to tell us: short and stocky, long beards, filthy bastards who are as sneaky as a cuttlefish. They lurk underground and only come up to steal whatever valuables they can get their hands on. This must part of their plot. The dwarves must have started the flood!"
                [/message]
                [set_variable]
                    name=sealife_response
                    value= _ "Fish bait? Cuttlefish? Who are these humans and what were they talking about?"
                [/set_variable]
            [/case]
            [else]
                [message]
                    speaker=Othgar
                    message= _ "Hey look! Those must be elves!"
                [/message]
                [message]
                    speaker=Durth
                    message= _ "Huh? Elves?"
                [/message]
                [message]
                    speaker=Bellerin
                    message= _ "Yeah, just like my old grandmam used to tell us: pointy ears, those shifty eyes, hearts as hard as a hermit crab’s shell. It must be an invasion! They must have started the flood!"
                [/message]

                [set_variable]
                    name=sealife_response
                    value= _ "Fish bait? Hermit Crabs? Who are these humans and what were they talking about?"
                [/set_variable]
            [/else]
        [/switch]

        [message]
            speaker=Othgar
            message= _ "Then let’s kill them!"
        [/message]

        [message]
            speaker=Durth
            message= _ "Yeah!"
        [/message]

        [message]
            speaker=unit
            message= _ "They’re definitely of the ‘attack first, ask questions later’ variety."
        [/message]
    [/event]

    # when all humans are dead, play victory conversation

    [event]
        name=die

        [filter]
            side=2
            role=human_scout
        [/filter]

        [filter_condition]
            [have_unit]
                role=human_scout
                count=0
            [/have_unit]
        [/filter_condition]

        # Vary dialogue depending on what kind of sea life the humans originally
        # mentioned. Also if last human died from drowning instead of being killed
        # have Kaleh as the question, instead of the victorious unit.

        # Set speaker before checking for dialog
        [if]
            # Checks if the unit was killed by the player or whether it drowned
            [have_unit]
                side=1
                x,y=$x2,$y2
            [/have_unit]
            [then]
                {CHECK_SPEAKER}
            [/then]
            [else]
                [set_variable]
                    name=speaking_unit.id
                    value=Kaleh
                [/set_variable]
            [/else]
        [/if]

        [message]
            speaker=$speaking_unit.id
            message=$sealife_response
        [/message]
        {CLEAR_VARIABLE speaking_unit,sealife_response}

        [message]
            speaker=Zhul
            message= _ "No time for questions now, the water shows no signs of stopping. We’ve got to get out of here while we still can!"
        [/message]

        [message]
            speaker=$ally_name
            message= _ "Curses, the water is rising too fast. That tunnel those humans were fleeing down was the fastest way out of here, but it’s already flooding."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "There must be another way out. There must!"
        [/message]

        [message]
            speaker=$ally_name
            message= _ "There might be, but I don’t—"
        [/message]

        [message]
            speaker=Nym
            message= _ "Then show us the way already! We’re running out of time."
        [/message]

        [message]
            speaker=$ally_name
            message= _ "Fine. Just keep going west, but be careful."
        [/message]
    [/event]

    # Event 4: Discovers Cultists Fort

    [event]
        name=moveto

        [filter]
            x=20-27
            y=45-50
            side=1
        [/filter]

        [remove_shroud]
            x=20-27
            y=45-50
            side=1
        [/remove_shroud]

        [if]
            [variable]
                name=unit.id
                not_equals=$ally_name
            [/variable]

            [then]
                {CHECK_EXPLORER}
                [message]
                    speaker=$explorer.id
                    message= _ "Whoa, what is this place? It sure seems well protected."
                [/message]
                {CLEAR_VARIABLE explorer}

                [message]
                    speaker=$ally_name
                    message= _ "This is an ancient fortress. Who lived here I do not know, but it has been long since abandoned."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=$ally_name
                    message= _ "Behold, we come now to an ancient fortress. Who lived here I do not know, but it has been long since abandoned."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Nym
            message= _ "You’ve been this way before?"
        [/message]

        [message]
            speaker=$ally_name
            message= _ "Yes, but I didn’t explore very far. This foul place is still protected by wards and guards. It reeks of dark magic."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I wish there was another path, but it seems we have no choice."
        [/message]

        [message]
            speaker=$ally_name
            message= _ "Wait. The chamber in front of us is probably trapped and well guarded. There is another way. When I explored here before, I found a secret passage that bypassed the main gate. Search along the southern wall of this cave and you should find it. The only problem is that the passage is long and windy, and it will cost us precious minutes. With the water rising that may be time we don’t have to spend. I leave the final decision up to you, Kaleh."
        [/message]
    [/event]

    # Event 4a: discover entrance to secret tunnel

    [event]
        name=moveto

        [filter]
            x=24
            y=49
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [if]
            [have_unit]
                x,y=$x1,$y1
                id=$ally_name
            [/have_unit]

            [then]
                [message]
                    speaker=unit
                    message= _ "Hmmm, the entrance to the secret tunnel should be right around here somewhere."
                [/message]

                [message]
                    speaker=unit
                    message= _ "Got it!"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message= _ "I think I see a door-shaped crack in this wall."
                [/message]

                [message]
                    speaker=$ally_name
                    message= _ "Good, that should be the entrance to the secret tunnel. Now just push hard inwards."
                [/message]

                [message]
                    speaker=unit
                    message= _ "Got it!"
                [/message]
            [/else]
        [/if]

        [terrain]
            x,y=24,50
            terrain=Uu
        [/terrain]

        [redraw]
            clear_shroud=yes
        [/redraw]
    [/event]

    # Event 4b: discover exit from secret tunnel

    [event]
        name=moveto

        [filter]
            x=13
            y=50
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [if]
            [have_unit]
                x,y=$x1,$y1
                id=$ally_name
            [/have_unit]

            [then]
                [message]
                    speaker=unit
                    message= _ "Well, this is the end of the tunnel. Which means the other secret door should be right here."
                [/message]

                [message]
                    speaker=unit
                    message= _ "Hold on, I think I’ve found it."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message= _ "The passage just halts at a dead end."
                [/message]

                [message]
                    speaker=$ally_name
                    message= _ "You didn’t expect the other end to be left wide open did you? There should be another secret door hidden right in front of you."
                [/message]

                [message]
                    speaker=unit
                    message= _ "Oh, right. Hold on, I think I’ve found it."
                [/message]
            [/else]
        [/if]

        [terrain]
            x,y=13,49
            terrain=Uu
        [/terrain]

        [terrain]
            x=8,8
            y=48,49
            terrain=Wwg
        [/terrain]

        [redraw]
            clear_shroud=yes
        [/redraw]
    [/event]

    # Event 5: Enter warded cave

    # remove runes at 20,45 and 23,48
    # do 25% 30% 35% damage to unit
    # awaken guardian undead:

    # EASY: 1 ghouls, 1 soulless, 2 skeletons
    # NORMAL: 1 ghouls, 1 necrophage, 2 skeletons
    # HARD: 2 necrophages, 2 skeletons

    [event]
        name=moveto

        [filter]
            x=19-24,21
            y=45-47,48
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [color_adjust]
            red,green,blue=255,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        [sound]
            name=magic-dark-big-miss.ogg
        [/sound]

        [delay]
            time=100
        [/delay]

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        [remove_item]
            x,y=20,45
        [/remove_item]

        [remove_item]
            x,y=23,48
        [/remove_item]

        [object]
            [filter]
                x=$x1
                y=$y1
            [/filter]

            id=RuneDamage
            silent=yes

            [effect]
                apply_to=hitpoints
                increase={ON_DIFFICULTY (-25%) (-30%) (-35%)}
            [/effect]
        [/object]

        # EASY: 1 ghoul, 1 soulless, 2 skeletons
        # NORMAL: 1 ghoul, 1 necrophage, 2 skeletons
        # HARD: 2 necrophages, 2 skeletons

#ifdef EASY
        {NAMED_UNIT 3 (Soulless) 21 48 () ( _ "Gate Guard") (upkeep=free)}
        {NAMED_UNIT 3 (Ghoul) 24 46 () ( _ "Gate Guard") (upkeep=free)}
#endif

#ifdef NORMAL
        {NAMED_UNIT 3 (Ghoul) 21 48 () ( _ "Gate Guard") (upkeep=free)}
        {NAMED_UNIT 3 (Necrophage) 24 46 () ( _ "Gate Guard") (upkeep=free)}
#endif

#ifdef HARD
        {NAMED_UNIT 3 (Necrophage) 21 48 () ( _ "Gate Guard") (upkeep=free)}
        {NAMED_UNIT 3 (Necrophage) 24 46 () ( _ "Gate Guard") (upkeep=free)}
#endif

        {NAMED_UNIT 3 (Skeleton) 22 45 () ( _ "Gate Guard") (upkeep=free)}
        {NAMED_UNIT 3 (Skeleton) 20 46 () ( _ "Gate Guard") (upkeep=free)}
    [/event]

    # Event 6: Enter central cave

    [event]
        name=moveto

        [filter]
            x=16-21
            y=41-45
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [remove_shroud]
            x=15-22,15-20
            y=41-44,45
            side=1
        [/remove_shroud]

        [if]
            [variable]
                name=unit.id
                not_equals=$ally_name
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "This cave seems pretty empty, except for those two glowing runes in the center. This fort must have once been heavily occupied because countless feet have left well worn paths leading in several directions. $unittest.name which way should we go?"
                [/message]

                [message]
                    speaker=$ally_name
                    message= _ "I don’t know. When I last came this way I got scared by all the runes and things moving in the shadows, and I explored no further."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message= _ "The many tracks left by countless feet clearly show that this fort must have once been heavily occupied, but now this area is empty, except for those two glowing runes in the center. When I last came this way I got scared by the runes and other things moving in the shadows and explored no further. I’m afraid I cannot advise you which way to go from here."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Nym
            message= _ "Well, we can’t spend all day thinking about it. Pick a direction, Kaleh."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Wait, those runes are giving off a cool blue light and for some reason they don’t seem as threatening as the burning red ones we saw before. Perhaps some of the magic left behind here could help us, if someone was brave enough to step into them."
        [/message]
    [/event]

    # Event 6a: Step on healing runes (17,44) (19,43)

    # EASY: rune1 heals 1 time, rune2 heals 2 times
    # NORMAL: rune1 heals 1 times, rune2 heals 1 time
    # HARD: rune1 heals 1 time, rune2 heals 1 time

    # when a unit steps on the runes, it is healed
#define UTBS_HEALING_RUNE X Y RUNE_VAR
    [event]
        name=moveto
        first_time_only=no

        [filter]
            x={X}
            y={Y}
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [filter_condition]
            [variable]
                name={RUNE_VAR}
                greater_than=0
            [/variable]
        [/filter_condition]

        [color_adjust]
            red,green,blue=31,122,255
        [/color_adjust]

        [redraw]
        [/redraw]

        [sound]
            name=heal.wav
        [/sound]

        [delay]
            time=100
        [/delay]

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        [heal_unit]
        [/heal_unit]

        [message]
            speaker=unit
            message= _ "I feel refreshed and rejuvenated!"
        [/message]

        [set_variable]
            name={RUNE_VAR}
            sub=1
        [/set_variable]

        [if]
            [variable]
                name={RUNE_VAR}
                numerical_equals=0
            [/variable]

            [then]
                [remove_item]
                    x,y=$x1,$y1
                [/remove_item]

                [message]
                    speaker=unit
                    message= _ "The rune is gone. I guess the magic only had limited uses."
                [/message]
            [/then]
        [/if]
    [/event]
#enddef

    {UTBS_HEALING_RUNE 17 44 healing_rune1}
    {UTBS_HEALING_RUNE 19 43 healing_rune2}
#undef UTBS_HEALING_RUNE

    # Event 7: Enter dining cavern

    # water pours in from the west
    # 1/2/3 water snakes come out of the water and attack

    [event]
        name=moveto

        [filter]
            x=7-14
            y=46-49
            side=1
        [/filter]

        [terrain]
            x=8,8
            y=48,49
            terrain=Wwg
        [/terrain]

        [remove_shroud]
            x=5-11,12-15
            y=46-51,46-49
            side=1
        [/remove_shroud]

        {CHECK_EXPLORER}
        [message]
            speaker=$explorer.id
            message= _ "There isn’t much left of the furnishings of this room. I think it was some sort of storeroom, but it looks like scavengers have taken anything useful."
        [/message]

        [message]
            speaker=$explorer.id
            message= _ "Curse Uria! The water is rising over here as well. Already the western end of this chamber is flooded. And I think I see shapes rising out of the water. Whatever they are, it can’t be good."
        [/message]

        {NOTRAIT_UNIT 3 (Water Serpent) 7 48}
#ifndef EASY
        {NOTRAIT_UNIT 3 (Water Serpent) 8 49}
#endif
#ifdef HARD
        {NOTRAIT_UNIT 3 (Water Serpent) 7 49}
#endif
    [/event]

    # Event 8: Training Hall

    # one turn after you enter the hall, ghostly warriors arise and attack
    # should be harder because it's the fast path

    [event]
        name=moveto

        [filter]
            x=8-13
            y=40-44
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [remove_shroud]
            x=7-12,13-14
            y=39-45,40-45
            side=1
        [/remove_shroud]

        #activate flooding of dining cavern

        [terrain]
            x=8,8
            y=48,49
            terrain=Wwg
        [/terrain]

        [message]
            speaker=unit
            message= _ "This looks like a training hall. There are still a few old swords and spears lying in the corners. But otherwise it seems quite abandoned."
        [/message]

        [event]
            #at next turn create haunt trainer and ghost novices
            name=new turn
            [fire_event]
                name=start training
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=start training

        # create wraith and ghosts
        {NAMED_UNIT 3 (Haunt) 9 40 (Blessed Kali) ( _ "Blessed Kali") (upkeep=free)}
        [fire_event]
            name=respawn_trainees
        [/fire_event]

        # wmllint: local spelling Kali Pior Iona Dani
        # wmllint: recognize Novice Pior
        # wmllint: recognize Novice Dani
        # wmllint: recognize Novice Iona

        [message]
            speaker=Blessed Kali
            message= _ "All right you runts, let’s try this again. Pior, remember to swing your sword with your whole body, not just your arms."
        [/message]

        [message]
            speaker=Novice Pior
            message= _ "Yes, sir."
        [/message]

        [message]
            speaker=Blessed Kali
            message= _ "Dani, keep your feet moving. If you stand still you’re a dead man."
        [/message]

        [message]
            speaker=Novice Dani
            message= _ "Right, sir."
        [/message]

        [message]
            speaker=Blessed Kali
            message= _ "Iona, try to vary your attacks more. You’re becoming too predictable."
        [/message]

        [message]
            speaker=Novice Iona
            message= _ "I’ll try, sir."
        [/message]

        [message]
            speaker=Blessed Kali
            message= _ "And remember, everyone, we’re going to keep practicing until I’m satisfied. So, ready... attack!"
        [/message]

        [message]
            x,y=8-14,40-45
            side=1
            [not]
                type=Dust Devil
            [/not]
            message= _ "Wait a minute, I don’t see any targets or practice dummies. Who are they supposed to be attacking?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I believe that would be us. But perhaps we can give them a few lessons in proper fighting style."
        [/message]
    [/event]

    # while trainer is alive, replace any defeated ghosts

    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_unit]
                id=Blessed Kali
            [/have_unit]

            [not]
                [have_unit]
                    id=Novice Iona,Novice Dani,Novice Pior
                    count=3
                [/have_unit]
            [/not]
        [/filter_condition]

        [message]
            speaker=Blessed Kali
            message= _ "Come on! I ain’t going anywhere for the rest of the day, and unless you can fight better than that, neither are you. Now get your sorry behinds up off the ground and do it all over again. You numbskulls aren’t getting the easy treatment on my watch, no sir!"
        [/message]

        [fire_event]
            name=respawn_trainees
        [/fire_event]
    [/event]

    #when blessed kali dies, the rest of his ghost students leave too

    [event]
        name=die

        [filter]
            id=Blessed Kali
        [/filter]

        [kill]
            id=Blessed Kali
            animate=no
            fire_event=no
        [/kill]

        [fire_event]
            name=respawn_trainees
        [/fire_event]

        [message]
            speaker=Novice Pior
            message= _ "Finally, we get to take a break. I am so sick of fighting practice."
        [/message]

        [message]
            speaker=Novice Dani
            message= _ "Kali’s just a hardass because he’s bitter that he never became a high priest."
        [/message]

        [message]
            speaker=Novice Iona
            # wmllint: local spelling c'mon
            message= _ "Hey, c’mon, maybe we can grab some food from the kitchen before we have to go to prayers."
        [/message]

        [message]
            speaker=Novice Pior
            message= _ "Good idea! I hope they let us go outside tomorrow; I so miss the sun."
        [/message]

        [kill]
            id=Novice Iona,Novice Dani,Novice Pior
            animate=no
            fire_event=no
        [/kill]

        [message]
            speaker=Nym
            message= _ "Still lambasting those novices after all these years, that guy definitely had too much of a work ethic."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Sniff, who were those children? Why did they die, in the dark, so many years ago? May Eloh shine her eternal light upon their souls."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "The past is the past, and there’s nothing we can do about it. Right now we have our own people to worry about."
        [/message]
    [/event]

    [event]
        name=respawn_trainees
        first_time_only=no

        [if]
            [not]
                [have_unit]
                    id=Novice Dani
                [/have_unit]
            [/not]

            [then]
                {NAMED_UNIT 3 (Ghost) 12 42 (Novice Dani) ( _ "Novice Dani") (upkeep=free)}
                [+unit]
                    animate=yes
                [/unit]
            [/then]
        [/if]

        [if]
            [not]
                [have_unit]
                    id=Novice Iona
                [/have_unit]
            [/not]

            [then]
                {NAMED_UNIT 3 (Ghost) 11 41 (Novice Iona) ( _ "Novice Iona") (upkeep=free)}
                [+unit]
                    animate=yes
                [/unit]
            [/then]
        [/if]

        [if]
            [not]
                [have_unit]
                    id=Novice Pior
                [/have_unit]
            [/not]

            [then]
                {NAMED_UNIT 3 (Ghost) 9 43 (Novice Pior) ( _ "Novice Pior") (upkeep=free)}
                [+unit]
                    animate=yes
                [/unit]
            [/then]
        [/if]
    [/event]

    # Event 9: Enter sleeping area

    # several skeletons arise and attack
    # EASY: 2 skeletons, 1 skeleton archer
    # NORMAL: 2 skeletons, 2 skeleton archers
    # HARD: 1 deathblade, 1 skeleton, 1 bone shooter, 1 skeleton archer

    [event]
        name=moveto

        [filter]
            x=13-19
            y=36-40
            side=1
        [/filter]

        [remove_shroud]
            x=11-20
            y=35-39
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=14-17
            y=38-41
            side=1
        [/remove_shroud]

        #activate flooding of dining cavern

        [terrain]
            x=8,8
            y=48,49
            terrain=Wwg
        [/terrain]

        {CHECK_EXPLORER}

        [message]
            speaker=$explorer.id
            message= _ "This must have been the barracks. Remains of cots and beds litter the floor. Whatever happened here, it must have been sudden. Several skeletons still lie in their beds, sleeping for eternity."
        [/message]

        {CLEAR_VARIABLE explorer}

        {NAMED_UNIT 3 (Skeleton) 15 40 () ( _ "Restless Dead") (upkeep,animate=free,yes)}
        {NAMED_UNIT 3 (Skeleton Archer) 14 36 () ( _ "Restless Dead") (upkeep,animate=free,yes)}

#ifdef HARD
        {NAMED_UNIT 3 (Deathblade) 13 39 () ( _ "Restless Dead") (upkeep,animate=free,yes)}
#else
        {NAMED_UNIT 3 (Skeleton) 13 39 () ( _ "Restless Dead") (upkeep,animate=free,yes)}
#endif

#ifdef HARD
        {NAMED_UNIT 3 (Bone Shooter) 17 37 () ( _ "Restless Dead") (upkeep,animate=free,yes)}
#endif

#ifdef NORMAL
        {NAMED_UNIT 3 (Skeleton Archer) 17 37 () ( _ "Restless Dead") (upkeep,animate=free,yes)}
#endif

        [message]
            side=3
            type=Skeleton
            x,y=14-16,39-41
            message= _ "Revenge!"
        [/message]

        [message]
            speaker=Nym
            message= _ "Well, so much for sleeping for eternity."
        [/message]
    [/event]

    # event for secret door to wizard's lair

    [event]
        name=moveto

        [filter]
            x=17
            y=36
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [message]
            speaker=unit
            message= _ "Hey, what’s this? There seems to be an outline of a door in this wall. Maybe if I give it a push..."
        [/message]

        [terrain]
            x,y=18,35
            terrain=Uu
        [/terrain]

        [redraw]
            clear_shroud=yes
        [/redraw]

        [message]
            speaker=unit
            message= _ "What do you know? A secret door!"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Well, what’s behind the door?"
        [/message]

        [message]
            speaker=unit
            message= _ "Uh oh. The path is blocked by another of those red glowing runes. I’m not sure crossing it would be a good idea."
        [/message]
    [/event]

    # Event 10: Enter Wizard's Lair

    # strange monsters are trapped on the runes

    # Kromph offers to help you (10-3 impact berserk chaotic)

    [event]
        name=moveto

        [filter]
            x=16-20
            y=27-34
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [remove_shroud]
            x=15-21
            y=27-34
            side=1
        [/remove_shroud]

        # upon entering chamber, remove entry rune and damage and
        # poison invading unit

        [color_adjust]
            red,green,blue=255,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        [sound]
            name=magic-dark-big-miss.ogg
        [/sound]

        [delay]
            time=100
        [/delay]

        [color_adjust]
            red,green,blue=0,0,0
        [/color_adjust]

        [redraw]
        [/redraw]

        [remove_item]
            x,y=18,34
        [/remove_item]

        [store_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            variable=unitstats
        [/store_unit]

        [harm_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            amount=$($unitstats.max_hitpoints/{ON_DIFFICULTY 5 4 3})
            kill=no
            poisoned=yes
        [/harm_unit]

        {CLEAR_VARIABLE unitstats}

        {NAMED_UNIT 3 (Crab Man) 17 32 (Failed Experiment 1) ( _ "Failed Experiment") (upkeep=free)}
        {NAMED_UNIT 3 (Young Ogre) 19 32 (Failed Experiment 2) ( _ "Failed Experiment") (upkeep=free)}

        [message]
            speaker=unit
            message= _ "This chamber seems to have been some sort of laboratory. The floor is littered with broken bottles and other strange equipment. What is more striking are the glowing runes and the creatures that just appeared on them. Some sort of clawed creature and a tortured young ogre. And behind them is some huge beast floating in the middle of a magic circle. The beast seems asleep, but the front two are very much awake. And boy do they seem angry."
        [/message]

        [message]
            speaker=Failed Experiment 1
            message= _ "Graaww!" # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Failed Experiment 2
            message= _ "Make pain end!"
        [/message]
    [/event]

    #disrupt magical circle

    [event]
        name=moveto
        id=break_circle
        first_time_only=no

        [filter]
            x=17-19
            y=28-30
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [message]
            speaker=unit

            message= _ "In the center of this circle is a huge creature, with surging muscles and bloodshot eyes. I would think it was just a very big man, except for the fine stitches that cover its entire body. In fact it seems to be composed of many body parts all sewn together. It seems to be floating asleep in the center of the glowing magical circle. I could scratch out part of the circle and break it, but I have no idea what the consequences would be. I’m not sure I want something with that kind of strength attacking me."
            [option]
                label= _ "Break the circle."
                [command]
                    [remove_event]
                        id=break_circle
                    [/remove_event]

                    [remove_item]
                        x,y=$x1,$y1
                    [/remove_item]

                    # Kill old unit which couldn’t move and
                    # Just replace with new version of unit
                    # since new golem is on player’s side, it is
                    # no longer allied with undead

                    [remove_item]
                        x,y=18,29
                    [/remove_item]

                    {NAMED_UNIT 1 (Flesh Golem) 18 29 (Kromph) ( _ "Kromph") (upkeep=loyal)}

                    [message]
                        speaker=Kromph
                        message= _ "Master, what is your command?"
                    [/message]

                    [message]
                        speaker=unit
                        message= _ "What?!"
                    [/message]

                    [message]
                        speaker=Kromph
                        message= _ "Kromph need command. Command me!"
                    [/message]

                    [message]
                        speaker=Nym
                        message= _ "Follow us. Attack our enemies."
                    [/message]

                    [message]
                        speaker=Kromph
                        message= _ "Yes, mistress. Kromph follow you. Kill enemies."
                    [/message]

                    [message]
                        speaker=Zhul
                        message= _ "Quick thinking, Nym. It seems to be some sort of magical creation. Lucky that it thought we were its master."
                    [/message]

                    [message]
                        speaker=Kaleh
                        message= _ "Looks like you have your own rather large pet, Nym."
                    [/message]

                    [message]
                        speaker=Nym
                        message= _ "It wouldn’t have been my first choice. But it could prove useful. I wonder what it likes to eat?"
                    [/message]
                [/command]
            [/option]

            [option]
                label= _ "Leave that thing alone."

                [command]
                    [allow_undo]
                    [/allow_undo]
                [/command]
            [/option]
        [/message]
    [/event]

    # Event 11: Enter Unholy Sanctuary

    [event]
        name=moveto

        [filter]
            x=5-10
            y=32-37
            side=1
            [not]
                type=Dust Devil,Flesh Golem
            [/not]
        [/filter]

        [remove_shroud]
            x=3-11
            y=31-37
            side=1
        [/remove_shroud]

        [message]
            speaker=unit
            message= _ "All the paths lead to this chamber. Is this just a dead end? It seems to be some sort of temple, but it has obviously been abandoned for a long time. All that is left is that stone altar. What god they were worshiping I have no idea, but the dried blood and cracked bones on the altar do not bode well."
        [/message]

        [message]
            speaker=$ally_name
            message= _ "I don’t like the smell of this place."
        [/message]

        [message]
            speaker=Zhul
            message= _ "I feel some sort of presence... Ugh... it makes my skin crawl."
        [/message]

        {MESSAGE_DEPEND_ON_ALLY
        (
            [message]
                speaker=Nym
                message= _ "Grog, I thought you said that you’d been here before? Where are we supposed to go from here?"
            [/message]
        )
        (
            [message]
                speaker=Nym
                message= _ "Nog, I thought you said that you’d been here before? Where are we supposed to go from here?"
            [/message]
        )
        (
            [message]
                speaker=Nym
                message= _ "Rogrimir, I thought you said that you’d been here before? Where are we supposed to go from here?"
            [/message]
        )
        (
            [message]
                speaker=Nym
                message= _ "Jarl, I thought you said that you’d been here before? Where are we supposed to go from here?"
            [/message]
        )}

        [message]
            speaker=$ally_name
            message= _ "I never explored this deep into the complex. But every lair has to have a back door somewhere."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Well I refuse to give up. There must be some way out. Search everywhere, people."
        [/message]

        [event]
            name=new turn

            [color_adjust]
                red,green,blue=255,0,0
            [/color_adjust]

            [redraw]
            [/redraw]

            [sound]
                name=magic-dark-big-miss.ogg
            [/sound]

            [delay]
                time=100
            [/delay]

            [color_adjust]
                red,green,blue=0,0,0
            [/color_adjust]

            [redraw]
            [/redraw]

            {NAMED_UNIT 3 (Ixthala Demon) 5 35 (Ancient Guardian 1) ( _ "Ancient Guardian") (upkeep=free)}
            {NAMED_UNIT 3 (Ixthala Demon) 8 33 (Ancient Guardian 2) ( _ "Ancient Guardian") (upkeep=free)}

            [message]
                speaker=Ancient Guardian 1
                message= _ "Zantoff tharqan yur glit zarf!" # wmllint: no spellcheck
            [/message]

            [message]
                speaker=Ancient Guardian 2
                message= _ "Uqtor dunil olgluck vara nir!" # wmllint: no spellcheck
            [/message]

            [message]
                speaker=Zhul
                message= _ "It seems that the temple had some power left in it after all."
            [/message]

            [message]
                speaker=Nym
                message= _ "I have no idea what they just said, but their meaning is quite clear."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "Actions speak louder than words, and I intend to send them back to whatever stygian pits they came from!"
            [/message]
        [/event]
    [/event]

    # Altar contains hidden lever which open secret exit

    [event]
        name=moveto
        id=pull_lever
        first_time_only=no

        [filter]
            [filter_location]
                x,y=6,33
                radius=1
            [/filter_location]
            side=1
            [not]
                type=Dust Devil,Flesh Golem
            [/not]
        [/filter]

        [message]
            speaker=unit

            message= _ "What’s this? Hidden underneath the edge of the altar is an iron lever. It looks slightly rusted, but with some effort I could pull it. I have no idea what it will do, but we’re running out of options."
            [option]
                label= _ "Pull the lever."
                [command]
                    [remove_event]
                        id=pull_lever
                    [/remove_event]

                    {UTBS_SHAKE_SCREEN}
                    [sound]
                        name=rumble.ogg
                    [/sound]

                    [terrain]
                        x=9,9
                        y=31,32
                        terrain=Uu
                    [/terrain]

                    [terrain]
                        x=1
                        y=33
                        terrain=Wo
                    [/terrain]

                    [terrain]
                        x=2,2,3
                        y=33,34,35
                        terrain=Wwg
                    [/terrain]

                    [remove_shroud]
                        x=2-5
                        y=33-36
                        side=1
                    [/remove_shroud]

                    [redraw]
                    [/redraw]

                    [message]
                        speaker=unit
                        message= _ "What?! Two secret passages? What do you think this once was, a trap? Or possibly a back door?"
                    [/message]

                    [message]
                        speaker=Zhul
                        message= _ "I can’t even begin to fathom what these cultists were up to. But more importantly, which way do we go?"
                    [/message]

                    [message]
                        speaker=unit
                        message= _ "Look, the western passage is already flooding! It must connect back somehow to the other tunnels."
                    [/message]

                    [message]
                        speaker=Nym
                        message= _ "There’s no time to ponder the history of this place. We’ve got to get out of here!"
                    [/message]

                    [message]
                        speaker=Kaleh
                        message= _ "Right, the eastern passage it is. I have no idea where it goes, but with the water rising, soon anywhere will be better than here."
                    [/message]
                [/command]
            [/option]

            [option]
                label= _ "Leave it alone."

                [command]
                    [allow_undo]
                    [/allow_undo]
                [/command]
            [/option]
        [/message]
    [/event]

    # Event 12: Enter Secret Crypt

    [event]
        name=moveto

        [filter]
            x=8-14
            y=24-30
            side=1
        [/filter]

        [remove_shroud]
            x=8-14
            y=24-31
            side=1
        [/remove_shroud]

        {CHECK_EXPLORER}
        [message]
            speaker=$explorer.id
            message= _ "This looks like some kind of burial chamber."
        [/message]
        {CLEAR_VARIABLE explorer}

        [message]
            speaker=Zhul
            message= _ "Crypts like these are often heavily guarded, we would do well not to disturb the sarcophagi."
        [/message]

        #create crypt guardian unit

        {NAMED_UNIT 3 (Spider Lich) 12 25 (Crypt Guardian) ( _ "Crypt Guardian") (upkeep=free)}

        [message]
            speaker=Crypt Guardian
            message= _ "I have long waited for fools such as yourselves to dare to disturb our rest, elf. Pay the price of all such defilers!"
        [/message]

        [message]
            speaker=Nym
            message= _ "Got any other timely advice, Zhul?"
        [/message]

        [message]
            speaker=$ally_name
            message= _ "We’re in luck, a fissure has opened up a crack in the northern wall. We may be able to escape that way."
        [/message]
    [/event]

    # Event 13: Encounter Cloaked Figure for a third time

    [event]
        name=moveto

        [filter]
            x=8-12
            y=19-23
            side=1
        [/filter]

        [remove_shroud]
            x=7-13
            y=19-24
            side=1
        [/remove_shroud]

        [unit]
            type=Dark Assassin3
            id=Cloaked Figure
            name= _ "Cloaked Figure"
            side=7
            x=10
            y=19
            placement=map
            passable=yes
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [message]
            speaker=Cloaked Figure
            image=portraits/cloaked.png
            message= _ "You run, but you shall not escape death!"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "In Eloh’s name, not you again. Must I fight you a third time?"
        [/message]

        [message]
            speaker=Cloaked Figure
            image=portraits/cloaked.png
            message= _ "You abandoned them, Kaleh, to eternal suffering and torment. And now you shall pay the price! You too shall watch the black waters consume those you love. Embrace the darkness, Kaleh, it is coming for you too."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Even you shall not stop me. You shall taste the might of the Quenoth elves!"
        [/message]

        [message]
            speaker=Cloaked Figure
            image=portraits/cloaked.png
            message= _ "Ha! Foolish boy, you know nothing."
        [/message]
    [/event]

    # Event 14: Defeat of Cloaked Figure (kaleh carries him himself)

    [event]
        name=last breath

        [filter]
            id=Cloaked Figure
        [/filter]

        [message]
            speaker=Kaleh
            message= _ "Quick, grab him! Don’t let him escape again."
        [/message]

        [message]
            speaker=Cloaked Figure
            image=portraits/cloaked.png
            message= _ "No, no, no more escaping. Please kill me, just make the pain end."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "No, you have hounded me with your riddles for too long. I want some answers. Who are you? What’s behind that black mask?"
        [/message]

        [message]
            speaker=Cloaked Figure
            image=portraits/uncloaked.png
            message= _ "Behold, Kaleh, your own worst enemy. Do you now see the irony?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Oh Eloh save us, it’s... it’s an elf."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Keratur, son of Tanuil. What in Eloh’s name are you doing here? How could you do this? We thought you were dead."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Kaleh, we don’t have time for questions. The water is still rising and we must get our people to safety."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "No matter what you have done, you are one of us, Keratur, and I will not leave you here to die in the darkness. I will carry you myself if I have to."
        [/message]

        [message]
            speaker=Cloaked Figure
            image=portraits/uncloaked.png
            message= _ "So be it. I care not."
        [/message]

        [kill]
            id=Cloaked Figure
            animate,fire_event=no,no
        [/kill]

        # When a unit moves into human outpost cavern, they see the human base
        # and the dead guards. If unit is not Kaleh, Kaleh comes up to see.
        # Then Cloaked Figure asks Kaleh to put him down and a conversation ensues.
        [event]
            name=moveto

            [filter]
                x=17-24
                y=15-23
                side=1
            [/filter]

            # reveal interior of entrance cave
            [remove_shroud]
                x=16-21,21-24
                y=15-22,17-21
                side=1
            [/remove_shroud]

            {CHECK_EXPLORER}
            [message]
                speaker=$explorer.id
                message= _ "Look, daylight! I think we finally made it out of the caves!"
            [/message]

            [message]
                speaker=$explorer.id
                message= _ "What’s this? Someone has built an outpost at the end of the cave. Where are its occupants?"
            [/message]

            [if]
                [variable]
                    name=unit.id
                    not_equals=Kaleh
                [/variable]

                [then]
                    [message]
                        speaker=$explorer.id
                        message= _ "Kaleh, I think you should come up and see this."
                    [/message]

                    {MOVE_UNIT (id=Kaleh) $x1 $y1}
                [/then]
            [/if]

            {CLEAR_VARIABLE explorer}

            [message]
                speaker=Kaleh
                message= _ "Oh, Eloh. They’re all dead. Butchered. Quick, we have to clean this up, we don’t want the rest of our people to have to see such horror."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "Now, Keratur, I will have my answers. Did you have a hand in this?"
            [/message]

            #create keratur in a blank space near kaleh

            [unit]
                type=Dark Assassin3
                id=Keratur
                name= _ "Keratur"
                profile=portraits/uncloaked.png
                x=$x1
                y=$y1
                side=1
                hitpoints=5
                placement=map
                passable=yes
                [modifications]
                    {TRAIT_INTELLIGENT}
                    {TRAIT_RESILIENT}
                [/modifications]
            [/unit]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "They heard me and... and they got in the way. But they aren’t even elves, what do they matter?"
            [/message]

            [message]
                speaker=Nym
                message= _ "You idiot—"
            [/message]

            [message]
                speaker=Kaleh
                message= _ "Quiet, Nym. But I still don’t understand how you got here. We were sure you were dead. We searched and searched, but never found your body."
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "Heh, heh, no you didn’t find me. I awoke trapped under the rubble, and when I finally escaped the village was deserted. Just the stink of death and destruction. And then I saw them, hordes of undead pouring down from across the dunes. A cabal of necromancers... they found me and made me watch, they made me watch it all!"
            [/message]

            [message]
                speaker=Kaleh
                message= _ "Watch what?"
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "They brought some humans, bound up tight. So beautiful... she had flaming red hair... they cut her... I can still hear her screaming. But that was only the beginning. They chanted words of power, and spilled the hot blood onto the sand and then I heard their screams of agony and pain..."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "From the humans?"
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "Faugh. No, I heard the screams of the dead, torn from their rest, their souls rose into the air howling in agony."
            [/message]

            [message]
                speaker=Zhul
                message= _ "But, but we burned the bodies so they couldn’t be raised."
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "Fool. That did not stop their dark power. Nothing could stop them. I felt the rush of flying spirits, and the unbearable cold, so cold. For a moment I felt their torment. But no, they wouldn’t kill me. They let me go as a witness and laughed as I scrambled over the dunes."
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "I was able to follow your trail, and I slipped among your people. No one noticed me, no I was too sneaky. And you wondered how I managed to follow you through the tunnels? Hah, you escorted me."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "But why, why did you want to kill us?"
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "You abandoned them! The pain, the agony, I still see their ghostly faces and hear their wails. And the necromancers kept chanting one name over and over: Yechnagoth, Yechnagoth, it reverberated in my ears. And every time I sleep I hear that name, and laughter, hideous laughter. She kept telling me it was your fault. And I believed her. Kaleh, forgive me, I just wanted to make the pain stop."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "I... I forgive you."
            [/message]

            [message]
                speaker=Keratur
                image=portraits/uncloaked.png
                message= _ "I do not fear death any more."
            [/message]

            #kill keratur

            [kill]
                id=Keratur
                animate=yes
                fire_event=no
            [/kill]

            [message]
                speaker=Kaleh
                message= _ "He’s dead. Rest in peace. Oh, what have I done? All our dead kin, desecrated and tormented for eternity."
            [/message]

            [message]
                speaker=Zhul
                message= _ "As you said yourself, the past is the past, there is nothing you can do now."
            [/message]

            [message]
                speaker=Nym
                message= _ "Don’t blame yourself. You didn’t know. If we had stayed behind we too would have been killed by the undead; we could not have defended our village against so many. We had no choice."
                image=portraits/nym_moody.png
            [/message]

            [message]
                speaker=Kaleh
                message= _ "That is small consolation. My deeds have turned to ashes in my mouth. Eloh forgive me. I did not know."
            [/message]

            [delay]
                time=1000
            [/delay]

            # Nym asks to be allowed to scout outside

            [message]
                speaker=Nym
                message= _ "With your permission, Kaleh, I think I should go scout around a bit outside. We have no idea what lies out there. And I can sneak around unseen many places you can’t."
            [/message]

            [message]
                speaker=Kaleh
                message= _ "You can go Nym, just be careful."
            [/message]

            [message]
                speaker=Nym
                message= _ "I’m always careful. I’ll be back soon."
            [/message]

            [store_unit]
                [filter]
                    id=Nym
                [/filter]
                kill=yes
                variable=Nymstats
            [/store_unit]

            [delay]
                time=500
            [/delay]

            [message]
                speaker=Kaleh
                message= _ "Well, at least we can use this outpost to rally our surviving troops. How many of our people made it out of the caves, Zhul?"
            [/message]

            [message]
                speaker=Zhul
                message= _ "We’re still trying to get a head count, but between the underground horrors and the water, we lost quite a few. Recruiting new warriors is going to be even more difficult. Still we should thank Eloh, and you, Kaleh, that so many of us did survive."
            [/message]

            {INCREASE_RECRUIT_COSTS 2}

            [message]
                speaker=Kaleh
                message= _ "Well, Nym’s right, we don’t know what’s out there. So we should set up a perimeter guard around the cave mouth and start discovering what this side of the mountains looks like."
            [/message]

            {VARIABLE ally_must_live no}

            [show_objectives]
            [/show_objectives]

            [event]
                name=new turn
                [fire_event]
                    name=ally_conversation
                [/fire_event]
            [/event]

            # change the music playing
            [music]
                name=elf-land.ogg
                immediate=yes
            [/music]

            # remove hero icon from troll/dwarf ally

            [remove_unit_overlay]
                id=$ally_name
                image=misc/hero-icon.png
            [/remove_unit_overlay]
        [/event]
    [/event]

    [event]
        name=moveto

        [filter]
            x=12-20
            y=1-18
            side=1
            [not]
                type=Dust Devil,Flesh Golem
            [/not]
        [/filter]

        [message]
            speaker=unit
            message= _ "Look, the tunnel slopes sharply downwards to the left. And it’s big enough that it should divert most of the rising water."
        [/message]

        [message]
            speaker=unit
            message= _ "And I think I see a faint light off to the right."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Could it be? Could we actually be almost out of this seemingly never-ending darkness?"
        [/message]
    [/event]

    # The conversation between Kaleh and the dwarf/troll ally
    # occurs the turn after the player finds the exit and Keratur dies.
    # Use custom event to clarify structure

    [event]
        name=ally_conversation

        {MESSAGE_DEPEND_ON_ALLY
        (
            [message]
                speaker=Kaleh
                message= _ "Grog, thank you so much for leading us out of the caves. We never would have found our way without your help. But with the tunnels flooded, how are you going to find your way back to your people?"
            [/message]

            [message]
                speaker=Grog
                message= _ "Grog proud of little elves too. He would not have made it this far without all your help. Grog is surprised by your bravery and strength."
            [/message]

            [message]
                speaker=Grog
                message= _ "Truth is that Grog not know much of sunlight lands. Sun and stars are scary, everything is open, exposed, no safe places to hide. But Grog cannot go back through all that water. And Grog doesn’t know where to find other tunnels back to his home. He is as lost as elves are."
            [/message]

            [message]
                speaker=Grog
                message= _ "But Grog not afraid. Great leader told Grog to guide and protect elves, and Grog will keep his oath. Grog will follow elves wherever they may go and protect them from danger as best he can. Maybe later, Grog will find another way back down to the caves of his people. But for now, Grog will continue to serve and protect you."
            [/message]
        )
        (
            [message]
                speaker=Kaleh
                message= _ "Nog, thank you so much for leading us out of the caves. We never would have found our way without your help. But with the tunnels flooded, how are you going to find your way back to your people?"
            [/message]

            [message]
                speaker=Nog
                message= _ "Nog proud of little elves too. He would not have made it this far without all your help. Nog is surprised by your bravery and strength."
            [/message]

            [message]
                speaker=Nog
                message= _ "Truth is that Nog not know much of sunlight lands. Sun and stars are scary, everything is open, exposed, no safe places to hide. But Nog cannot go back through all that water. And Nog doesn’t know where to find other tunnels back to his home. He is as lost as elves are."
            [/message]

            [message]
                speaker=Nog
                message= _ "But Nog not afraid. Great leader told Nog to guide and protect elves, and Nog will keep his oath. Nog will follow elves wherever they may go and protect them from danger as best he can. Maybe later, Nog will find another way back down to the caves of his people. But for now, Nog will continue to serve and protect you."
            [/message]
        )
        (
            [message]
                speaker=Kaleh
                message= _ "Rogrimir, I want to thank you so much for guiding us out of the caves. We never would have found our way without your help. But with the tunnels flooded, how are you going to find your way back to your people?"
            [/message]

            [message]
                speaker=Rogrimir
                message= _ "Och, it is I who should be congratulating you, laddie. I showed you the way, but it was you and your people who defeated the many perils and obstacles to your escape. In all my years such bravery and courage I have rarely seen."
            [/message]

            [message]
                speaker=Rogrimir
                message= _ "But truly I cannot return the way I came and even if there are other tunnels which lead back down to my homeland, I do not know where to search for them. I know as little about the land above ground as you do."
            [/message]

            [message]
                speaker=Rogrimir
                message= _ "But my king told me to protect you from all dangers, and I plan to keep that oath. I do not like the above ground, it is too open and exposed; I feel that I could be attacked from any direction. But an oath is an oath and so I will follow you and your people wherever you may go and protect you as best I can. The tunnels cannot stay flooded forever; later perhaps if am able to return this way, I may be able to find my way back to my homeland. But for now I am yours to command."
            [/message]
        )
        (
            [message]
                speaker=Kaleh
                message= _ "Jarl, I want to thank you so much for guiding us out of the caves. We never would have found our way without your help. But with the tunnels flooded, how are you going to find your way back to your people?"
            [/message]

            [message]
                speaker=Jarl
                message= _ "Och, it is I who should be congratulating you, laddie. I showed you the way, but it was you and your people who defeated the many perils and obstacles to your escape. In all my years such bravery and courage I have rarely seen."
            [/message]

            [message]
                speaker=Jarl
                message= _ "But truly I cannot return the way I came and even if there are other tunnels which lead back down to my homeland, I do not know where to search for them. I know as little about the land above ground as you do."
            [/message]

            [message]
                speaker=Jarl
                message= _ "But my king told me to protect you from all dangers, and I plan to keep that oath. I do not like the above ground, it is too open and exposed; I feel that I could be attacked from any direction. But an oath is an oath and so I will follow you and your people wherever you may go and protect you as best I can. The tunnels cannot stay flooded forever; later perhaps if am able to return this way, I may be able to find my way back to my homeland. But for now I am yours to command."
            [/message]
        )}

        [message]
            speaker=Kaleh
            message= _ "Your loyalty is a credit to your people. I am glad indeed to have you fighting by my side."
        [/message]
    [/event]

    # This rather long macro ensures that if Kaleh is asked to come up next to
    # the unit that fires the event he doesn't appear in a cave wall. Instead
    # the macro finds an empty hex next to the unit. Since this event fires
    # the first time any unit moves into target area, I am sure there will
    # be an empty spot adjacent to the unit.

    # Event 14.5 Player discovers human’s chest of gold at cave mouth

    [event]
        name=moveto

        [filter]
            x,y=17,21
            side=1
            [not]
                type=Dust Devil,Flesh Golem
            [/not]
        [/filter]

        {PLACE_IMAGE items/chest-plain-open.png 17 21}

        [sound]
            name=gold.ogg
        [/sound]

        [message]
            speaker=unit
            message= _ "Looks like the guards at this outpost had been saving away a bit of loot. I don’t suppose they’re going to mind anymore if we made use of it."
        [/message]

        # Modify gold as though the scenario had ended (multiply by 0.4 then add new award)
        # However, ensure that players receive at least 50 gold if they are doing well
        # This reduces the tomato surprise aspect of adding a fight at the end and
        # reduces the reward that careful players will receive, making it slightly harder for them
        [store_gold]
            side=1
            variable=gold_amount
        [/store_gold]
        [if]
            [variable]
                name=gold_amount
                greater_than=0
            [/variable]
            [then]
                [set_variable]
                    name=gold_amount
                    multiply=-0.6
                [/set_variable]
                [set_variable]
                    name=gold_amount
                    round=floor
                [/set_variable]
            [/then]
            [else]
                [set_variable]
                    name=gold_amount
                    multiply=-1
                [/set_variable]
            [/else]
        [/if]
        [set_variable]
            name=gold_amount
            add={ON_DIFFICULTY 125 100 100}
        [/set_variable]
        [if]
            [variable]
                name=gold_amount
                less_than=50
            [/variable]
            [then]
                {VARIABLE gold_amount 50}
            [/then]
        [/if]

        [gold]
            amount=$gold_amount
            side=1
        [/gold]
        {CLEAR_VARIABLE gold_amount}
    [/event]

    # Event 15: Elves step out into the daylight, Eloh appears

    # asks for Kaleh, he goes outside, conversation ensues
    # human leader rides up, talks, leaves

    [event]
        name=moveto

        #event should only fire when unit steps several hexes out into the dunes

        [filter]
            x=25-50
            y=19-31
            side=1
            [not]
                type=Dust Devil,Flesh Golem
            [/not]
        [/filter]

        [if]
            [have_unit]
                x,y=$x1,$y1
                race=elf
            [/have_unit]

            [then]
                [message]
                    speaker=unit
                    message= _ "Praise Eloh, it is so good to be outside again. To see the sky stretching out above me, to feel the wind in my face..."
                [/message]
            [/then]
        [/if]

        [if]
            [have_unit]
                x,y=$x1,$y1
                id=$ally_name
            [/have_unit]

            [then]
                {MESSAGE_DEPEND_ON_ALLY
                (
                    [message]
                        speaker=unit
                        message= _ "We made it. Outside look strange to Grog, Grog not used to big open spaces."
                    [/message]
                )
                (
                    [message]
                        speaker=unit
                        message= _ "We made it. Outside look strange to Nog, Nog not used to big open spaces."
                    [/message]
                )
                (
                    [message]
                        speaker=unit
                        message= _ "I think we finally made it outside. I’d forgotten how big the sky is and how windy it can be."
                    [/message]
                )
                (
                    [message]
                        speaker=unit
                        message= _ "I think we finally made it outside. I’d forgotten how big the sky is and how windy it can be."
                    [/message]
                )}
            [/then]
        [/if]

        #from an elf still in the cave
        [message]
            x,y=12-23,15-20
            side=1
            race=elf
            message= _ "Can you see very far? Do you have any idea where we are?"
        [/message]

        [message]
            speaker=unit
            message= _ "We’ve come out on the side of a mountain, overlooking a large valley. The land seems to be much the same as the foothills south of the mountains. The valley is filled with sand dunes, though the center is flat. There seems to be some sort of settlement in the center of the valley. And far to the north I can see something sparkling on the horizon, but I don’t know what it is."
        [/message]

        #reveal most of the valley to player

        #central corridor
        [remove_shroud]
            x=26-49
            y=0-30
            side=1
        [/remove_shroud]

        #NW cave wall right above unit
        [remove_shroud]
            x=25-31
            y=19-20
            side=1
        [/remove_shroud]

        #SW edge of valley, southern cave wall near player

        [remove_shroud]
            x=21-31,23-31,25-31
            y=27   ,28   ,29
            side=1
        [/remove_shroud]

        #South and SE edge of valley
        [remove_shroud]
            x=48-56,48-54,48-53,48-51,27-49,29-31,35-47
            y=17-26,27   ,28   ,29-30,31   ,32   ,32
            side=1
        [/remove_shroud]

        #eloh appears

        {NAMED_UNIT 2 (Divine Avatar) 30 22 (Eloh) ( _ "Eloh") (
            upkeep=free
            facing=sw
            random_traits=no
            profile=portraits/eloh.png
        )}

        [if]
            [variable]
                name=unit.id
                not_equals=Kaleh
            [/variable]

            [then]
                #if Kaleh isn't the unit moving outside then Eloh calls for him

                [message]
                    speaker=Eloh
                    message= _ "Kaleh, Kaleh, come to me."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "What is the voice? It sounds so familiar."
                [/message]

                [message]
                    speaker=Eloh
                    message= _ "Come out so that I might see you. Your god calls to you."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "Am I dreaming? Is this real? I’m coming, I’m coming."
                [/message]

                {MOVE_UNIT (id=Kaleh) 25 23}
            [/then]

            [else]
                [message]
                    speaker=Eloh
                    message= _ "Hail Kaleh, it is I, Eloh."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Kaleh
            message= _ "But I am not asleep? And yet I can see you? How is this possible?"
        [/message]

        [message]
            speaker=Eloh
            message= _ "Do you doubt my powers? You have come out of the darkness, and I appear unto you to congratulate you."
        [/message]

        # if kaleh didn't go outside first, the unit who did asks kaleh who is
        # is talking to. Otherwise Zhul asks him.

        [if]
            [variable]
                name=unit.id
                not_equals=Kaleh
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "Kaleh, who are you talking to?"
                [/message]

                [message]
                    speaker=Eloh
                    message= _ "For now, I appear only to you, for you, Kaleh, are special, you are the Chosen One."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "$unit.name|, be quiet, I’ll explain it all later."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Zhul
                    message= _ "Kaleh, who are you talking to?"
                [/message]

                [message]
                    speaker=Eloh
                    message= _ "For now, I appear only to you, for you, Kaleh, are special, you are the Chosen One."
                [/message]

                [message]
                    speaker=Kaleh
                    message= _ "Be quiet Zhul, I’ll explain it all later."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Eloh
            message= _ "Yes, I have chosen you as the one to lead my people out of danger and death and into a life of eternal salvation. Crossing under the mountains was a very important step, and your destruction of the unbelievers proves your—"
        [/message]

        #troll/dwarf ally teleports to just outside of cave

        {MOVE_UNIT (id=$ally_name) 21 23}

        [message]
            speaker=$ally_name
            message= _ "Kaleh, a quick question—"
        [/message]

        {MESSAGE_DEPEND_ON_ALLY
        (
            [message]
                speaker=Kaleh
                message= _ "Not now Grog, I’m busy."
            [/message]
        )
        (
            [message]
                speaker=Kaleh
                message= _ "Not now Nog, I’m busy."
            [/message]
        )
        (
            [message]
                speaker=Kaleh
                message= _ "Not now Rogrimir, I’m busy."
            [/message]
        )
        (
            [message]
                speaker=Kaleh
                message= _ "Not now Jarl, I’m busy."
            [/message]
        )}

        [message]
            speaker=Eloh
            message= _ "What’s this? You did not kill the unbelievers?!"
        [/message]

        [if]
            [variable]
                name=ally_race
                equals=dwarf
            [/variable]

            [then]
                [message]
                    speaker=Kaleh
                    message= _ "I am sorry I could not have fulfilled your command, but we found ourselves in the middle of a war. We were vastly outnumbered and we needed help. In fact the dwarves have been very helpful. They helped protect us from the trolls and without their guidance we would not have made it out of the caves alive."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Kaleh
                    message= _ "I am sorry I could not have fulfilled your command, but we found ourselves in the middle of a war. We were vastly outnumbered and we needed help. In fact the trolls have been very helpful. They helped protect us from the dwarves and without them we would not have made it out of the caves alive."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Eloh
            message= _ "You were weak and foolish, but I forgive you. You must remember, Kaleh, that without my guidance, your people would have died out years ago. I am your god, and you must follow my every command."
        [/message]

        [message]
            speaker=Eloh
            message= _ "Now, in the valley live a group of humans who have also seen the light. They may seem strange, but they are my obedient followers. You must trust them, they will show you the way north. Follow them and they will lead you to me."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "What do you mean ‘lead you to me’? You are a god, don’t you exist everywhere? I thought you were going to show us our new home."
        [/message]

        [message]
            speaker=Eloh
            message= _ "Of course I am. Oh, how little you understand. Do not worry yourself with all those tiny questions. Come to me and all will be made clear."
        [/message]

        [delay]
            time=100
        [/delay]

        # wmllint: directory spelling Durstrag
        {NAMED_UNIT 2 (Human Commander) 30 25 (Sergeant Durstrag) ( _ "Sergeant Durstrag") (facing=nw)}
        {NAMED_UNIT 2 (Dragoon) 31 25 () ( _ "Human Guard") (facing=nw)}
        {NAMED_UNIT 2 (Dragoon) 31 26 () ( _ "Human Guard") (facing=nw)}
        {NAMED_UNIT 2 (Swordsman) 30 24 () ( _ "Human Guard") (facing=nw)}
        {NAMED_UNIT 2 (Longbowman) 30 26 () ( _ "Human Guard") (facing=nw)}

        [message]
            speaker=Sergeant Durstrag
            message= _ "I saw the distress signal from the outpost on the bluff. Who in the Dark Lady’s name are you and what have you done with my men?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "My name is Kaleh, and these are my people. We come from the south and unfortunately we found your men dead—"
        [/message]

        [message]
            speaker=Sergeant Durstrag
            message= _ "Dead?! You ‘found’ them you say? You’ll pardon me if I don’t take you at your word. We haven’t seen elves for generations, but we remember your ancient betrayal. What are elves doing sneaking up through the caves out onto our back doorstep?"
        [/message]

        [message]
            speaker=$ally_name
            message= _ "Well, actually they were fleeing from—"
        [/message]

        [if]
            [variable]
                name=ally_race
                equals=troll
            [/variable]

            [then]
                [message]
                    speaker=Sergeant Durstrag
                    message= _ "A troll! This just gets better and better. We haven’t seen one of your kind up here for many years, but I have a long memory. I still remember the troll raids when I was a youth."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Sergeant Durstrag
                    message= _ "A dwarf! This just gets better and better. We haven’t seen one of your kind up here for many years, but we have long memories. I remember how your ‘traders’ used to come up and cheat us out of our valuables. You’ll find we’re not so easy to fool this time."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Kaleh
            message= _ "Look, if you’ll just let me explain—"
        [/message]

        [if]
            [variable]
                name=ally_race
                equals=troll
            [/variable]

            [then]
                [message]
                    speaker=Sergeant Durstrag
                    message= _ "Oh there is no need to explain, it’s pretty obvious what you’re up to. Here we have a whole legion of elves, consorting with trolls, sneaking up behind our defenses. This looks an awful lot like an invasion to me."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Sergeant Durstrag
                    message= _ "Oh there’s no need to explain, it’s pretty obvious what you’re up to. Here we have a whole legion of elves, consorting with dwarves, sneaking up behind our defenses. This looks an awful lot like an invasion to me."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Kaleh
            message= _ "No, no. You don’t understand! We were told you could help us."
        [/message]

        [message]
            side=2
            type=Swordsman
            message= _ "Sir, remember the edict passed down by councilman Noblis? About any foreigners spotted on the borders?"
        [/message]

        [message]
            speaker=Sergeant Durstrag
            message= _ "I have no idea what you’re babbling about, elf, but you’re just lucky you caught me on a good day. You get to explain everything to the Iron Council. Now you and your people just lay down your weapons and we will take you into custody to be judged. They’ll deal with you as they see fit."
        [/message]

        [message]
            speaker=Eloh
            message= _ "Everything will be fine. Do as he says."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I am my own master. I will not be ordered around, not even by you, Eloh."
        [/message]

        [message]
            speaker=Sergeant Durstrag
            message= _ "What’s that, boy? Are you talking back to me? This isn’t a negotiation. You are on my land, and under my jurisdiction. Lay down your weapons and submit peacefully or I’ll make you sorry you didn’t."
        [/message]

        [message]
            speaker=Eloh
            # wmllint: local spelling Ishtar
            message= _ "Kaleh, I am Eloh, bearer of the staff of Ishtar and slayer of the demon-god Zhangor. Do as I say! Submit to him or I will abandon your people to suffering and death. Your bones will litter the sand dunes, and vultures shall pick at your flesh. I am not a forgiving god, Kaleh."
            image=portraits/eloh_rage.png
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Then kill me if you must, but I will not give myself over to those who threaten me and my people. I have not come through peril and darkness just to surrender to a man such as you."
        [/message]

        [message]
            speaker=Sergeant Durstrag
            message= _ "Your dare defy me?! All who refuse to submit to the authority of the Iron Council shall be killed. By the Dark Lady, I shall not put up with this bickering any longer. To battle, men! Drive those heathens back into the caves!"
        [/message]

        # Move Durstag and his guards back to human base

        [kill]
            side=2
            [not]
                id=Eloh
            [/not]
            animate=no
            fire_event=no
        [/kill]

        [unit]
            type=Human Commander
            id=Sergeant Durstrag
            name= _ "Sergeant Durstrag"
            canrecruit=yes
            x=44
            y=27
            side=2
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        {NAMED_NOTRAIT_UNIT 2 (Dragoon) 43 28 () ( _ "Human Guard")}
        {NAMED_NOTRAIT_UNIT 2 (Dragoon) 44 26 () ( _ "Human Guard")}
        {NAMED_NOTRAIT_UNIT 2 (Swordsman) 43 27 () ( _ "Human Guard")}
        {NAMED_NOTRAIT_UNIT 2 (Longbowman) 44 27 () ( _ "Human Guard")}

        [message]
            speaker=Eloh
            message= _ "You disappoint me, Kaleh. You are weak, and not worthy of my guidance. Do what you will, but this is not over. You may be the appointed leader of your people but I am your god, and I will not let you usurp my authority."
        [/message]

        [kill]
            id=Eloh
            animate=no
            fire_event=no
        [/kill]

        [message]
            speaker=Kaleh
            message= _ "You are not the god I grew up with. You may be all-powerful, but I will not be your puppet. I am still their leader and as long as I draw breath I will do what I think is best for my people."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Kaleh, would you mind telling me what in Uria’s name is going on."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "There’s no time. Right now we have to prepare ourselves for another battle. I’d better head back to the outpost and rally our troops. I fear a whole lot of hurt is going to be coming up through those hills very soon."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Well, now we’re really in for it. I hope you know what you’re doing, Kaleh."
        [/message]

        {MOVE_UNIT (id=Kaleh) 18 19}

        {MESSAGE_DEPEND_ON_ALLY
        (
            [message]
                speaker=Grog
                message= _ "Grog no like humans either. They mean. But they sound great when they go squish."
            [/message]
        )
        (
            [message]
                speaker=Nog
                message= _ "Nog no like humans either. They mean. But they sound great when they go squish."
            [/message]
        )
        (
            [message]
                speaker=Rogrimir
                message= _ "I never liked humans much anyway. I’ll be glad to be fighting something besides undead."
            [/message]
        )
        (
            [message]
                speaker=Jarl
                message= _ "I never liked humans much anyway. I’ll be glad to be fighting something besides undead."
            [/message]
        )}

        [modify_side]
            side=2
            {INCOME 9 11 13}
            {GOLD 150 150 175}
        [/modify_side]

        #capture some of the nearby villages
        [capture_village]
            x,y=34-37,25-26
            side=2
        [/capture_village]

        [capture_village]
            x,y=41-43,19-23
            side=2
        [/capture_village]

        [show_objectives]
        [/show_objectives]

        [event]
            name=new turn
            [fire_event]
                name=nym_return
            [/fire_event]
        [/event]

        # change the music playing
        [music]
            name=loyalists.ogg
            immediate=yes
        [/music]
    [/event]

    # Event 16: Nym returns

    # Next turn after big Eloh/Durstrag conversation, Nym returns and
    # tells Kaleh that Durstrag plans to send for reinforcements

    [event]
        name=nym_return

        [store_unit]
            [filter]
                id=Kaleh
            [/filter]
            variable=kaleh_location
            kill=no
        [/store_unit]

        [unstore_unit]
            variable=Nymstats
            find_vacant=yes
            check_passability=yes
            x=$kaleh_location.x
            y=$kaleh_location.y
        [/unstore_unit]

        {CLEAR_VARIABLE Nymstats,kaleh_location}

        [message]
            speaker=Nym
            message= _ "I’m back, Kaleh."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Ah! You scared me, Nym. I didn’t hear you coming."
        [/message]

        [message]
            speaker=Nym
            message= _ "Of course you didn’t. That’s why it’s called sneaking."
        [/message]

        [message]
            speaker=Nym
            message= _ "Anyway you’ve really gotten us into a mess. The good news is that the outpost isn’t guarded as heavily as you might think. The garrison seems only half-manned. They obviously didn’t expect any serious attack to come from this direction."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "And what’s the bad news?"
        [/message]

        [message]
            speaker=Nym
            message= _ "The bad news is that I overheard the commander ordering a special group of his men to get ready to ride north and summon reinforcements. It seems that the humans have a bigger village to the north. This outpost is lightly guarded enough that we might be able to defeat them, but in our weakened state if they bring the full strength of their army against us I fear we may be crushed."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Then we’ll just have to make sure that no messenger escapes this valley to summon reinforcements."
        [/message]

        #set messenger timer at 2, so first messenger goes in 6,5,4 turns

        [set_variable]
            name=messenger_timer
            value=2
        [/set_variable]
        {VARIABLE messengers_incoming yes}

        [show_objectives]
        [/show_objectives]

        # schedule events that occur after the humans start fighting
        [event]
            name=new turn

            [filter_condition]
                # The first night after meeting the humans
                [have_location]
                    x,y=44,27 # location of Sgt Durstrag's keep - should be in normal time
                    time_of_day_id=dusk1,dusk2,short_dark,long_dark1,long_dark2,long_dark3,long_dark4
                [/have_location]
            [/filter_condition]

            [fire_event]
                name=undead_emissary
            [/fire_event]
        [/event]

        [event]
            name=new turn
            first_time_only=no

            [if]
                [variable]
                    name=messenger_timer
                    numerical_equals=1
                [/variable]

                [then]
                    [fire_event]
                        name=human_conversation
                    [/fire_event]
                [/then]
            [/if]

            [fire_event]
                name=messengers
            [/fire_event]
        [/event]
    [/event]

    # Event 17: Undead Emissary

    [event]
        name=undead_emissary

        [move_unit_fake]
            type=ENightgaunt
            side=5
            x=34,35,36,36,35
            y=32,32,31,30,30
        [/move_unit_fake]

        {NAMED_UNIT 5 (ENightgaunt) 35 30 (Undead Emissary) ( _ "Undead Emissary") ()}

        [message]
            speaker=Undead Emissary
            message= _ "Cursed elves, you tracked your filth through our halls and you defiled our sanctuary. You have besmirched our honor, and we will have our revenge. We are the Order of the Crimson Talon, and even death shall not stop us. You shall rue the day that you ever trespassed into our lair!"
        [/message]

        [kill]
            id=Undead Emissary
            animate=no
        [/kill]

        [move_unit_fake]
            type=ENightgaunt
            side=5
            x=35,35,35,35
            y=30,31,32,33
        [/move_unit_fake]

        [message]
            speaker=Nym
            message= _ "Can’t the dead ever just stay dead? And aren’t they trapped by the flooded tunnels and caves?"
        [/message]

        [message]
            speaker=Zhul
            message= _ "Undead don’t have to breathe and I don’t think a little water is going to stop them. Besides, you saw how the ghost just flew through the rock; if they can move through walls then what do they care about flooded tunnels?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Great. So now we’re fighting in a haunted valley."
        [/message]

        [modify_side]
            side=5
            {INCOME 9 11 13}
            {GOLD 100 125 150}
        [/modify_side]

        [unit]
            type=Spectre
            id=Undead Leader
            name= _ "Undead Leader"
            canrecruit=yes
            side=5
            x=28
            y=37
        [/unit]
    [/event]

    #Event 17.5 A conversation about the humans

    [event]
        name=human_conversation

        [message]
            speaker=Kaleh
            message= _ "I don’t understand. What are these humans doing here? I’ve never seen so many in one place before."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Humans aren’t just the bandits and outlaws you’re familiar with from the deserts, Kaleh. Remember that long ago the great human empire of Wesnoth spread all across the known lands. Some of our people say that it was the humans who brought the Great Fall upon us. But to blame others is folly. Eloh says that it was not the darkness without, but the darkness within us that was the cause of our corruption and downfall."
        [/message]

        [message]
            speaker=Zhul
            message= _ "But now is not a time for preaching. Humans once spread to many lands, and despite all the ravages of time, I have no doubt that at least a few of them have survived. They are a hardy people and quickly adapt to new conditions. I only wish that the same could be said of our brethren."
        [/message]

        [message]
            speaker=Nym
            message= _ "There might be other elves somewhere. We can’t be sure."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "No, we can’t. But for now we must deal with the problem at hand. Thank you for the information, Zhul; these humans are good fighters but they are no match for our speed and skill. I grew up fighting in dunes such as these, and I will not be bested by a bunch of ruffians."
        [/message]
    [/event]

    # Event 18: Sending for Reinforcements

    # EASY: 1 dragoon, 2 cavalryman, 2 spearmen
    # NORMAL: 1 dragoon, 2 cavaliers, 1 javelineer, 1 longbowman
    # HARD: 3 dragoons, 1 swordsman, 1 longbowman

    # EASY: once every 8 turns
    # NORMAL: once every 7 turns
    # HARD: once every 6 turns

    [event]
        name=messengers
        first_time_only=no

        # timer to store when to send off a human messenger
        [set_variable]
            name=messenger_timer
            add=1
        [/set_variable]

        [if]
            [variable]
                name=messenger_timer
                numerical_equals={ON_DIFFICULTY 8 7 6}
            [/variable]

            [then]
                [set_variable]
                    name=messenger_timer
                    value=0
                [/set_variable]

                [message]
                    speaker=Sergeant Durstrag
                    message= _ "Send forth the messenger and his escort. Go north and bring help as soon as possible!"
                [/message]

                [set_variable]
                    name=loc_x
                    rand=44..51
                [/set_variable]

                [set_variable]
                    name=loc_y
                    rand=23..25
                [/set_variable]

                [unit]
                    type=Dragoon
                    id=messenger
                    name= _ "Human Messenger"
                    canrecruit=yes
                    x=$loc_x
                    y=$loc_y
                    side=8
                [/unit]

                [unit]
                    type={ON_DIFFICULTY (Cavalryman) (Cavalier) (Dragoon)}
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    side=8
                [/unit]

                [unit]
                    type={ON_DIFFICULTY (Cavalryman) (Cavalier) (Dragoon)}
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    side=8
                [/unit]

                [unit]
                    type={ON_DIFFICULTY (Spearman) (Javelineer) (Swordsman)}
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    side=8
                [/unit]

                [unit]
                    type={ON_DIFFICULTY (Spearman) (Longbowman) (Master Bowman)}
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    side=8
                [/unit]

                [message]
                    speaker=Kaleh
                    message= _ "If that messenger escapes the valley, we’ll be in trouble. We have to stop him!"
                [/message]

                {CLEAR_VARIABLE loc_x}
                {CLEAR_VARIABLE loc_y}

                # Set up the Messenger Escort Micro AI
                [micro_ai]
                    side=8
                    ai_type=messenger_escort
                    action=add

                    [filter]
                        id=messenger
                    [/filter]
                    waypoint_x,waypoint_y=42,1
                [/micro_ai]
            [/then]
        [/if]
    [/event]

    # Event 18.5: Messenger Dies

    [event]
        name=last breath

        [filter]
            id=messenger
        [/filter]

        [message]
            speaker=messenger
            message= _ "No! I must get help!"
        [/message]
    [/event]

    [event]
        name=die

        [filter]
            id=messenger
        [/filter]

        [message]
            speaker=Kaleh
            message= _ "Good. We’re safe for now. We just have to defeat Durstrag before he sends another messenger for reinforcements."
        [/message]

        # Remaining units of the messenger side must remain active
        [modify_ai]
            side=8
            action=add
            path=goal
            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=10
            [/goal]
        [/modify_ai]
    [/event]

    # Event 19: Messenger Escapes!

    [event]
        name=moveto

        [filter]
            side=8
            id=messenger
            y=1
        [/filter]

        [kill]
            id=messenger
            animate=no
            fire_event=no
        [/kill]

        [message]
            speaker=Kaleh
            message= _ "The messenger has escaped! He will surely return with reinforcements. We are doomed!"
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # Event 20: Defeat of Sergeant Durstrag

    [event]
        name=last breath

        [filter]
            id=Sergeant Durstrag
        [/filter]

        [message]
            speaker=Kaleh
            message= _ "Don’t worry. We’re not the monsters you seem to think we are. I will not kill you in cold blood."
        [/message]

        [message]
            speaker=Sergeant Durstrag
            message= _ "Faugh, boy, you know nothing! There are fates worse than death."
        [/message]

        [kill]
            id=Sergeant Durstrag
            animate=yes
            fire_event=no
        [/kill]

        [message]
            speaker=Nym
            message= _ "He killed himself rather than surrender to us!"
        [/message]

        [message]
            side=2
            message= _ "They killed Sergeant Durstrag! Run for your lives!"
        [/message]

        [kill]
            side=2
            animate=no
            fire_event=no
        [/kill]

        [kill]
            side=5
            animate=no
            fire_event=no
        [/kill]

        [message]
            speaker=Zhul
            message= _ "The rest of the humans are fleeing."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Let them go. We have won this battle and I am weary of all this bloodshed."
        [/message]

        [message]
            speaker=Zhul
            message= _ "What was it that the human Durstrag was so afraid of?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I don’t know, but I fear we may find out."
        [/message]

        [message]
            speaker=Zhul
            message= _ "You’re being very cryptic, Kaleh. Now that the battle is over would you care to explain to us who you were talking to back when we first met the humans?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "No, not yet."
        [/message]

        [message]
            speaker=Nym
            message= _ "What’s wrong, Kaleh? Don’t you trust us?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Yes, yes of course I do. But it’s just a theory. I don’t want to say more until I have proof. Give me until tomorrow night, then I’ll tell you everything."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Very well. I’ve trusted your decisions and your leadership so far; I’ll wait a little longer."
        [/message]

        [message]
            speaker=Nym
            message= _ "So what do we do now? The land seems to be about the same on the northern side of the mountains as it was on the south. And we can’t hang around here forever. The humans will be back with reinforcements eventually, and the valley is still haunted with undead."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Yes, I think the sooner we leave this valley the better. But we don’t know anything about the surrounding terrain. Without anyone to guide us, we have no idea what perils may be nearby. I don’t like sending our people across foreign lands when I don’t know what’s in front of us. We’ve lost too many people already. I don’t want to lead us into a trap."
        [/message]

        [message]
            speaker=Nym
            message= _ "When I was scouting around I think I saw a small oasis near the entrance to this valley. If we move out there we should be out of range of the undead. I think it would be safe, at least for the short term."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Indeed. Undead ghosts such as these are often bound to the places they died: the farther away they travel, the weaker they are. So if we move out of the immediate vicinity we should be pretty safe."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Good, we’ll move our people out and camp by the oasis. Now, Nym, you know who our best scouts are; I want you to lead a few elves to do some reconnaissance. We’ll send out small groups of scouts to the north, northeast and northwest. Don’t go too far, try not to be seen, and please don’t do anything dangerous. But I want to know what’s out there."
        [/message]

        [message]
            speaker=Zhul
            message= _ "But hasn’t Eloh told you where to go and what dangers you face?"
        [/message]

        [message]
            speaker=Kaleh
            message= _ "She was... rather vague. I know we’re supposed to generally go north, but I want more information before I commit us to a direction."
        [/message]

        [message]
            speaker=Nym
            message= _ "Don’t you worry about us, Kaleh. We’ll be careful. I’ll organize five bands to scout out the nearby lands. We should be back in about half a day."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Good, until then we’ll settle around that oasis and set up as good a defense as we can. Until I know what’s out there, I’m not taking any chances."
        [/message]

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

    # Flooding algorithm

    # At the end of each turn:

    # Turn shallow water hexes to deep water and
    # Turn all cave tiles within one hex of water to shallow water

    # Step by Step Process:
    # 1. change all shallow water hexes to deep water
    # 2. change all hexes adjacent to water to shallow water
    # 3. destroy any items in the new deep water
    # 4. kill any units in deep water

    [event]
        name=new turn
        id=do_flooding
        first_time_only=no

        [filter_condition]
            # don't flood before first turn
            [variable]
                name=turn_number
                greater_than=1
            [/variable]
        [/filter_condition]

        [store_locations]
            terrain=Ww*
            # some pools outside of the cave mustn't be turned to deep water.
            [not]
                x = 35, 35, 36, 42, 42, 43, 43, 60, 60, 61, 61, 62
                y = 25, 26, 25, 20, 21, 21, 22, 4, 5, 4, 5, 5
            [/not]
            variable=shallow_to_deep_locs
        [/store_locations]

        [terrain]
            terrain=Wwg

            [filter_adjacent_location]
                find_in=shallow_to_deep_locs
            [/filter_adjacent_location]
            [and]
                terrain=!,Xu,M*^Xm,Md,W*,Xo*
            [/and]
        [/terrain]

        [terrain]
            terrain=Wo
            find_in=shallow_to_deep_locs
        [/terrain]

        [remove_item]
            find_in=shallow_to_deep_locs
        [/remove_item]

        [fire_event]
            name=kill_submerged_units
        [/fire_event]

        [fire_event]
            name=check_flood_end
        [/fire_event]

        {CLEAR_VARIABLE shallow_to_deep_locs}
    [/event]

    # Killing of units who ended up in deep water
    [event]
        name=kill_submerged_units
        first_time_only=no

        [store_unit]
            [filter]
                [filter_location]
                    terrain=Wo*
                [/filter_location]

                # Only units which cannot move in deep water can drown
                movement_cost=99
            [/filter]

            kill=no
            variable=drowning_units
        [/store_unit]

        [redraw]
        [/redraw]

        # If at least one side 1 unit died then display a death message
        [message]
            find_in=drowning_units
            side=1
            [not]
                type=Dust Devil,Flesh Golem
            [/not]

            message= _ "Help, I’m drowning!"
        [/message]

        [kill]
            find_in=drowning_units
            animate=yes
            fire_event=yes
        [/kill]

        {CLEAR_VARIABLE drowning_units}
    [/event]

    # when water reaches escape passage, stop flooding and make it pour out
    # into the valley

    [event]
        name=check_flood_end

        [filter_condition]
            [have_location]
                x=12
                y=18
                terrain=Ww*, Wo*
            [/have_location]
        [/filter_condition]

        [remove_event]
            id=do_flooding
        [/remove_event]

        # flood rest of side passage with deep water
        [terrain]
            x=12,12,12,12,13,14,15,16,17,18,19,20,21,22,23,23,24,25,25,26
            y=18,17,16,15,15,15,15,14,14,14,14,13,14,13,14,15,15,16,17,17
            terrain=Wo
        [/terrain]

        # create shallow water stream in valley
        [terrain]
            x=27,28,29,30,31,32,33,34,35,35,36,37,38,39,40,41,41,42,42,42,43,43
            y=18,18,18,17,18,17,17,16,16,15,14,14,14,14,14,14,15,13,14,15,13,14
            terrain=Ww
        [/terrain]

        [fire_event]
            name=kill_submerged_units
        [/fire_event]

        [if]
            [have_unit]
                x=21-25,26-50
                y=18-33,1-33
                side=1
                [not]
                    type=Dust Devil,Flesh Golem
                [/not]
            [/have_unit]

            [then]
                [message]
                    x=21-25,26-50
                    y=18-33,1-33
                    side=1
                    [not]
                        type=Dust Devil,Flesh Golem
                    [/not]
                    message= _ "Look, the water is pouring out the side tunnel into the valley! That’s a lot of water: it’s even creating a small river. I sure wouldn’t want to be downstream of that deluge right now."
                [/message]
            [/then]

            [else]
                # the player didn't see water when it flooded out into the valley
                # as soon as he does move a unit out into the valley, comment on it
                [event]
                    name=moveto

                    [filter]
                        x=26-50
                        y=1-33
                        side=1
                        [not]
                            type=Dust Devil,Flesh Golem
                        [/not]
                    [/filter]

                    [allow_undo]
                    [/allow_undo]

                    [message]
                        speaker=unit
                        message= _ "Look, up there in the valley. The water has poured out of the side tunnel and created a small river and lake. I’m glad we weren’t downstream of that deluge when the water came rushing out of the tunnel."
                    [/message]
                [/event]
            [/else]
        [/if]
    [/event]

    #time over event

    [event]
        name=time over

        [message]
            speaker=Kaleh
            message= _ "I can see human reinforcements arriving on the horizon. We’ll surely be overwhelmed now! If only we had moved faster."
        [/message]
    [/event]

    #victory event

    [event]
        name=victory

        # reveal map in-between starting valley and location elves move to
        [remove_shroud]
            x=45-60
            y=1-6
            side=1
        [/remove_shroud]

        [teleport]
            [filter]
                id=Kaleh
            [/filter]
            x,y=61,6
        [/teleport]

        [teleport]
            [filter]
                id=Zhul
            [/filter]
            x,y=63,5
        [/teleport]

        [teleport]
            [filter]
                id=$ally_name
            [/filter]
            x,y=60,6
        [/teleport]

        [store_unit]
            [filter]
                id=Nym
            [/filter]
            kill=yes
            variable=Nymstats
        [/store_unit]

        {UNIT 1 (Quenoth Fighter) 66 2 (id,upkeep,generate_name=Dummy Unit1,free,no)}
        {UNIT 1 (Quenoth Fighter) 57 3 (id,upkeep,generate_name=Dummy Unit2,free,no)}
        {UNIT 1 (Quenoth Scout) 65 3 (id,upkeep,generate_name=Dummy Unit3,free,no)}
        {UNIT 1 (Quenoth Scout) 59 2 (id,upkeep,generate_name=Dummy Unit4,free,no)}
        {UNIT 1 (Quenoth Scout) 58 5 (id,upkeep,generate_name=Dummy Unit5,free,no)}
        {UNIT 1 (Quenoth Mystic) 62 2 (id,upkeep,generate_name=Dummy Unit6,free,no)}

        [scroll_to_unit]
            id=Kaleh
        [/scroll_to_unit]

        [delay]
            time=500
        [/delay]

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

        [move_unit_fake]
            type=$Nymstats.type
            gender=female
            side=1
            x=51,52,53,54,55,56,57,57,58,59,60,60
            y=1,1,1,1,1,1,1,2,2,2,2,3
        [/move_unit_fake]

        [set_variable]
            name=Nymstats.hitpoints
            value=12
        [/set_variable]

        [unstore_unit]
            variable=Nymstats
            x,y=60,3
        [/unstore_unit]

        {CLEAR_VARIABLE Nymstats}

        [message]
            speaker=Zhul
            message= _ "In Eloh’s name, Nym, you look terrible. Are you well?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Yes. Just... let me... catch... my breath."
        [/message]

        [delay]
            time=100
        [/delay]

        [move_unit_fake]
            type=Merman Netcaster
            side=1
            x=51,52,53,54,55,56,57,58,59,59,60
            y=1,1,1,1,2,1,2,2,3,4,4
        [/move_unit_fake]

        [unit]
            type=Merman Netcaster
            id=Esanoo
            name= _ "Esanoo"
            hitpoints=10
            x=60
            y=4
            side=1
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [delay]
            time=200
        [/delay]

        [message]
            speaker=Esanoo
            message= _ "Water. Sweet water. By the gods, I thought my scales would fall off."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "What in Uria’s name is that?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Relax, he’s a friend. Just let me explain."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "You’re really beat up, Nym. Are you sure you’re fine?"
        [/message]

        [message]
            speaker=Nym
            message= _ "I’m fine. But I found someone who really wanted to speak with you."
        [/message]

        [message]
            speaker=$ally_name
            message= _ "He looks like a half-man half-fish."
        [/message]

        [message]
            speaker=Esanoo
            message= _ "Indeed. I come from the ocean, and long have I been looking for you."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "The ocean? What are you talking about?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Don’t try to explain, Esanoo. We’ll have to show them instead."
        [/message]

        [message]
            speaker=Esanoo
            message= _ "It’s not important. What’s important is that I am an emissary from one who much desires to speak with you, Kaleh. Despite the danger, my master sent me and my brethren to scour the dry land searching for you."
        [/message]

        [message]
            speaker=Zhul
            message= _ "There are more of you? Where are the others?"
        [/message]

        [message]
            speaker=Esanoo
            message= _ "They have been captured by the foul humans. I just barely managed to hide and escape, with the help of your friend."
        [/message]

        [message]
            speaker=Zhul
            message= _ "And why should we trust anything you say?"
        [/message]

        [message]
            speaker=Esanoo
            message= _ "My master thought you might be suspicious. She said that what we must talk with you about concerns the fate of your people. Apparently it concerns ‘Yechnagoth’ and ‘Zhangor’. She said that you would understand, Kaleh."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Hmmmm... Yes, yes I think I do. I don’t know why, but I trust you."
        [/message]

        [message]
            speaker=Esanoo
            message= _ "Thank you. Now I have a boon to ask of you. Our instructions were to find you and to bring you and your people to meet with my master. The problem is that I don’t know where she is hiding."
        [/message]

        [message]
            speaker=Zhul
            message= _ "You don’t know where to find your master?"
        [/message]

        [message]
            speaker=Esanoo
            message= _ "It’s complicated, and I don’t know how much I am allowed to tell you. My people are fighting a desperate war against... against a powerful foe. Many times our enemy has tried to assassinate my master. My master worried that her presence was a danger to the rest of my kind. So right after she sent us on our mission she went into hiding. I am the youngest member of our group, and so I wasn’t told the location. You must understand, there are spies everywhere. Only the leaders of our group knew, but the rest of them were all captured by those foul humans. They are being held in the settlement to the north. If we are to have any chance of finding my master, we must first rescue them. I would do it myself, but..."
        [/message]

        [message]
            speaker=Nym
            message= _ "It would be suicide for you to try to rescue them alone. Of course we will help you."
        [/message]

        [message]
            speaker=Esanoo
            message= _ "Thank you. I am not very good at fighting on the dry ground."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "All the other scouting parties have returned, except for one. Tanstafaal and his scouts haven’t reported back yet. I’m starting to get worried."
        [/message]

        [message]
            speaker=Nym
            message= _ "They were sent due north. From Esanoo’s description it sounds like they were headed right for the human settlement. I hope nothing bad has happened to them."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Things are coming to a head. I’m worried about Tanstafaal and your merfolk friends. Time is of the essence, so let’s move out as soon as possible."
        [/message]

        [kill]
            id=Dummy Unit1,Dummy Unit2,Dummy Unit3,Dummy Unit4,Dummy Unit5,Dummy Unit6
            animate=no
        [/kill]

        {CLEAR_VARIABLE healing_rune1,healing_rune2}

        {CLEAR_VARIABLE messenger_timer,messengers_incoming}
    [/event]

    # set time for all underground areas to be always night/underground
    [time_area]
        x=0-1,2-3,4-19,10-16,12,14,20-21,20,20-22,22-23,23-24,24,25,25-26,26,26,27,27,27,28,28-36,32-34,37-42,38,40,43-45,46,47,48-49,50,51,52-53,54-55,56,57,58,59,60,61,62-63,64-65,66-67,68-69,70-71,72-73,74-75,76,77
        y=9-54,8-54,7-54,6,5,5,7-22,26,27-54,7-21,28-54,7-20,8-20,29-54,8-10,14-18,9-10,16-17,30-54,31,32-54,31,33-56,32,32,34-54,33-54,32-54,31-54,30-54,29-54,28-54,26-54,21-54,19-54,17-54,15-54,13-54,12-54,11-54,10-54,9-54,8-54,6-54,5-54,4-54,2-54,1-54
        {UNDERGROUND}
    [/time_area]

    {UTBS_INCLUDE utils/deaths.cfg}
[/scenario]
