#textdomain wesnoth-utbs
# Level 8: Out of the Frying Pan...

[scenario]
    id="8_Out_of_the_Frying_Pan"
    name= _ "Out of the Frying Pan"
    next_scenario=9_Blood_is_Thicker_Than_Water
    map_data="{campaigns/Under_the_Burning_Suns/maps/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

    #max turns in scenario varies depending on difficulty
    {TURNS 72 68 64}

    victory_when_enemies_defeated=no

    {TWO_SUNS_DEFAULT_SCHEDULE}

    #Side 1: elves
    [side]
        side=1
        id=Kaleh
        type=Desert Fighter
        canrecruit=yes
        gold=200
        {INCOME 4 2 0}
        controller=human
        shroud=yes
        fog=no
        team_name=elf_ally
        user_team_name=_"Elf Ally"
    [/side]

    #Side 2: Human forces (blue)
    [side]
        side=2
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally
        user_team_name=_"Human Ally"
        {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

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

            passive_leader=yes

            [target]
                side=1
                value=10
            [/target]

            [target]
                side=5
                value=1
            [/target]
        [/ai]
    [/side]

    #Side=3 undead cultists (green)
    [side]
        side=3
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=cultists_ally
        user_team_name=_"Cultists"
        {FLAG_VARIANT undead}
        [ai]
            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

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

    #Side=4 confused ants (yellow)
    [side]
        side=4
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no

        [ai]
            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 2 3 4}

            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
        shroud=no
        fog=no
        team_name=human_ally
        user_team_name=_"Human Ally"
        {FLAG_VARIANT undead}
        recruit=EGhost, EWraith, EShadow
        [ai]
            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

            aggression=0.75
            caution=0.1

            # this code unnecessary if allied with humans

            #[target]
            #side=1
            #value=15
            #[/target]

            #[target]
            #side=2
            #value=1
            #[/target]

            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]
    [/side]

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

        [ai]
            # AI will attack a weak unit with a max of 2,3,4 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 2 3 4}

            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
        shroud=yes
        fog=no
        team_name=monster

        [ai]
            aggression=0.90
            caution=0.10

            [avoid]
                x=10-20
                y=10-18
            [/avoid]

            [target]
                id=Kaleh
                value=20
            [/target]
        [/ai]
    [/side]

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

        [ai]
            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

            aggression=0.75
            caution=0.25

            [leader_goal]
                x=29-60
                y=1
            [/leader_goal]

            protect_leader=10.0
            protect_leader_radius=20

            [target]
                side=1
                value=50
            [/target]

            [target]
                side=5
                value=1
            [/target]
        [/ai]
    [/side]

    #Side=9 temple demons

    [side]
        side=9
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=cultists_ally
        user_team_name=_"Cultists"
        {FLAG_VARIANT undead}
        [ai]
            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

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

    {campaigns/Under_the_Burning_Suns/utils/dialog-macros.cfg}

    # 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

        #escaped from caves events tests
        #{NAMED_NOTRAIT_UNIT 1 (Desert Archer) 24 23 (Test) ( _ "Test")}
        #{NAMED_NOTRAIT_UNIT 1 (Desert Fighter) 20 20 (Test) ( _ "Test")}

        #training hall test
        #{NAMED_NOTRAIT_UNIT 1 (Great Mage) 12 44 (Test) ( _ "Test")}

        #wizard lair tests
        #{NAMED_NOTRAIT_UNIT 1 (Great Mage) 16 27 (Test) ( _ "Test")}
        #{NAMED_NOTRAIT_UNIT 1 (Great Mage) 16 27 (Test) ( _ "Test")}
        #{NAMED_NOTRAIT_UNIT 1 (Desert Star) 16 27 (Test) ( _ "Test")}

        #cloaked figure tests
        #{NAMED_NOTRAIT_UNIT 1 (Great Mage) 10 21 (Test) ( _ "Test")}
        #{NAMED_NOTRAIT_UNIT 1 (Great Mage) 10 21 (Test) ( _ "Test")}

        # 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
        {PLACE_IMAGE items/dragonstatue.png 16 28}
        {PLACE_IMAGE items/dragonstatue.png 20 28}

        # 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 the cost of all units by 1
        [if]
            [variable]
                name=scen3
                numerical_equals=2
            [/variable]

            [then]
                #go from 4 to 5

                [disallow_recruit]
                    type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                    side=1
                [/disallow_recruit]

                [allow_recruit]
                    type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                    side=1
                [/allow_recruit]
            [/then]

            [else]
                [if]
                    [variable]
                        name=scen3
                        numerical_equals=1
                    [/variable]

                    [then]
                        #go from 3 to 4

                        [disallow_recruit]
                            type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                            side=1
                        [/disallow_recruit]

                        [allow_recruit]
                            type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                            side=1
                        [/allow_recruit]
                    [/then]
                [/if]

                [if]
                    [variable]
                        name=scen3
                        numerical_equals=3
                    [/variable]

                    [then]
                        #go from 5 to 6

                        [disallow_recruit]
                            type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                            side=1
                        [/disallow_recruit]

                        [allow_recruit]
                            type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                            side=1
                        [/allow_recruit]
                    [/then]
                [/if]
            [/else]
        [/if]

        # recall heroes
        # this is a placeholder unit, used to make sure heroes recall
        # in encampment hexes
        {NAMED_NOTRAIT_UNIT 1 (Desert Hero) 51 41 (Test) ( _ "Test")}

        [recall]
            id=Zhul
        [/recall]
        [recall]
            id=Nym
        [/recall]

        # recall dwarf/troll
        # name is Grog/Nog or Rogrimir/Jarl

        [recall]
            id=Rogrimir
        [/recall]
        [recall]
            id=Jarl
        [/recall]
        [recall]
            id=Grog
        [/recall]
        [recall]
            id=Nog
        [/recall]

        # kill placeholder unit
        [kill]
            x,y=51,41
            animate=no
        [/kill]

        # NOTE: we now use $intl_ally_name, which is a translatable ally name string,
        # for languages that may use a different alphabet/spelling than the western europe one
        # for proper names
        [if]
            [have_unit]
                id=Grog
            [/have_unit]

            [then]
                [set_variable]
                    name=ally_name
                    value=Grog
                [/set_variable]

                [set_variable]
                    name=ally_race
                    value=Troll
                [/set_variable]

                [set_variable]
                    name=intl_ally_name
                    value= _ "Grog" # wmllint: ignore
                [/set_variable]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Nog
            [/have_unit]

            [then]
                [set_variable]
                    name=ally_name
                    value=Nog
                [/set_variable]

                [set_variable]
                    name=ally_race
                    value=Troll
                [/set_variable]

                [set_variable]
                    name=intl_ally_name
                    value= _ "Nog"  # wmllint: ignore
                [/set_variable]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Rogrimir
            [/have_unit]

            [then]
                [set_variable]
                    name=ally_name
                    value=Rogrimir
                [/set_variable]

                [set_variable]
                    name=ally_race
                    value=Dwarf
                [/set_variable]

                [set_variable]
                    name=intl_ally_name
                    value= _ "Rogrimir" # wmllint: ignore
                [/set_variable]
            [/then]
        [/if]

        [if]
            [have_unit]
                id=Jarl
            [/have_unit]

            [then]
                [set_variable]
                    name=ally_name
                    value=Jarl
                [/set_variable]

                [set_variable]
                    name=ally_race
                    value=Dwarf
                [/set_variable]

                [set_variable]
                    name=intl_ally_name
                    value= _ "Jarl" # wmllint: ignore
                [/set_variable]
            [/then]
        [/if]

        # put hero icon on troll/dwarf ally

        {UNIT_OVERLAY id=$ally_name misc/hero-icon.png}

        # initialize starting variables

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

        [set_variable]
            name=type_of_sealife
            value=0
        [/set_variable]

        [set_variable]
            name=humans_killed
            value=0
        [/set_variable]

        # used to display alternate death message if the last of the 3 humans dies
        # from drowning instead of being killed by another unit
        [set_variable]
            name=human_drowned
            value=0
        [/set_variable]

        [set_variable]
            name=entered_gate
            value=0
        [/set_variable]

#ifdef EASY
        [set_variable]
            name=healing_rune1
            value=1
        [/set_variable]

        [set_variable]
            name=healing_rune2
            value=2
        [/set_variable]
#endif

#ifdef NORMAL
        [set_variable]
            name=healing_rune1
            value=1
        [/set_variable]

        [set_variable]
            name=healing_rune2
            value=1
        [/set_variable]
#endif

#ifdef HARD
        [set_variable]
            name=healing_rune1
            value=1
        [/set_variable]

        [set_variable]
            name=healing_rune2
            value=1
        [/set_variable]
#endif

        [set_variable]
            name=entered_training_hall
            value=0
        [/set_variable]

        [set_variable]
            name=broke_circle
            value=0
        [/set_variable]

        [set_variable]
            name=entered_temple
            value=0
        [/set_variable]

        [set_variable]
            name=pulled_lever
            value=0
        [/set_variable]

        [set_variable]
            name=ally_conversation
            value=0
        [/set_variable]

        [set_variable]
            name=pissed_off_durstrag
            value=0
        [/set_variable]

        # clock variable, starts at 1
        [set_variable]
            name=time_of_day
            value=1
        [/set_variable]

        # flag to store if we should start the messenger timer or not
        [set_variable]
            name=start_messenger_timer
            value=0
        [/set_variable]

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

        # flag to make sure that undead emissary only comes out once
        [set_variable]
            name=undead_emissary
            value=0
        [/set_variable]

        [set_variable]
            name=stop_flooding
            value=0
        [/set_variable]

        [set_variable]
            name=human_conversation
            value=0
        [/set_variable]

        [set_variable]
            name=saw_valley_river
            value=0
        [/set_variable]

        [set_variable]
            name=immortal_hero
            value=0
        [/set_variable]

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

        [remove_shroud]
            x=48-57
            y=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

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

            [then]
                [objectives]
                    summary= _ "Starting Objectives:"
                    [objective]
                        description= _ "Escape the Caves"
                        condition=win
                    [/objective]
                    [objective]
                        description= _ "Death of Kaleh, Nym, Zhul, or Dwarf Ally"
                        condition=lose
                    [/objective]

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

            [else]
                [objectives]
                    summary= _ "Starting Objectives:"
                    [objective]
                        description= _ "Escape the Caves"
                        condition=win
                    [/objective]
                    [objective]
                        description= _ "Death of Kaleh, Nym, Zhul, or Troll Ally"
                        condition=lose
                    [/objective]

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

    # I NEED THE CLOCK FUNCTION TO GO FIRST BECAUSE LATER EVENTS CHECK TO SEE
    # WHAT TIME IT IS

    # Clock Function

    # Step 0: increment messenger timer
    # Step 1: if we are going into night or day, flip daytime boolean
    # Step 2: advance clock

    #first day
    #dawn       1
    #morning    2
    #mid-day    3
    #afternoon  4
    #dusk       5
    #shortdark  6

    #second day
    #dawn       -1
    #morning    -2
    #mid-day    -3
    #afternoon  -4
    #dusk       -5
    #longdark 1 -6
    #longdark 2 -7
    #longdark 3 -8
    #longdark 4 -9

    [event]
        name=new turn
        first_time_only=no

        # timer to store when to send off a human messenger
        [if]
            [variable]
                name=start_messenger_timer
                numerical_equals=1
            [/variable]

            [then]
                [set_variable]
                    name=messenger_timer
                    add=1
                [/set_variable]
            [/then]
        [/if]

        [if]
            [variable]
                name=time_of_day
                numerical_equals=-9
            [/variable]

            [then]
                [set_variable]
                    name=time_of_day
                    value=1
                [/set_variable]
            [/then]

            [else]
                [if]
                    [variable]
                        name=time_of_day
                        numerical_equals=6
                    [/variable]

                    [then]
                        [set_variable]
                            name=time_of_day
                            value=-1
                        [/set_variable]
                    [/then]

                    [else]
                        [if]
                            [variable]
                                name=time_of_day
                                greater_than=0
                            [/variable]

                            [then]
                                [set_variable]
                                    name=time_of_day
                                    add=1
                                [/set_variable]
                            [/then]

                            [else]
                                [set_variable]
                                    name=time_of_day
                                    add=-1
                                [/set_variable]
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/else]
        [/if]
    [/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]

        [scroll]
            x=20
        [/scroll]
        [scroll]
            x=-20
        [/scroll]
        [scroll]
            x=20
        [/scroll]
        [scroll]
            x=-20
        [/scroll]

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

        [message]
            speaker=Nym
            message= _ "What?"
        [/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]
            [/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]
            [/else]
        [/if]

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

            [then]
                [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]
                [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=Ww
        [/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]

#ifdef NORMAL

        [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
            y=46-53
        [/remove_shroud]

        [remove_shroud]
            side=1
            x=36-41
            y=50-54
        [/remove_shroud]

        # check to see if Nym is the unit that triggered this event
        # to keep her from talking to herself during the dialogue

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id=Nym
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=0
            [/variable]

            [then]
                # unit that triggered event is not Nym

                [message]
                    speaker=unit
                    message= _ "Hey look, more ants!"
                [/message]

                [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 have led to more tunnels than we first thought."
                [/message]

                [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]
            [/then]

            [else]
                # Nym triggered event, change dialogue

                [message]
                    speaker=unit
                    message= _ "Hey look, more ants!"
                [/message]

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

                [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]
            [/else]
        [/if]

        {CLEAR_VARIABLE unittest}
    [/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=Ww
        [/terrain]

        [remove_shroud]
            side=1
            x=29-35
            y=41-49
        [/remove_shroud]

        [remove_shroud]
            side=1
            x=28-30
            y=44-46
        [/remove_shroud]

#ifdef EASY

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

        {NAMED_UNIT 2 (Javelineer) 33 44 (Bellerin) ( _ "Bellerin") (upkeep=free)}

        [redraw]
        [/redraw]

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

        {NAMED_UNIT 2 (Swordsman) 34 44 (Durth) ( _ "Durth") (upkeep=free)}

        [redraw]
        [/redraw]

        [move_unit_fake]
            type=Bowman
            side=2
            x=36,35,34
            y=42,43,43
        [/move_unit_fake]

        {NAMED_UNIT 2 (Bowman) 34 43 (Othgar) ( _ "Othgar") (upkeep=free)}

        [redraw]
        [/redraw]

#endif

#ifdef NORMAL

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

        {NAMED_UNIT 2 (Javelineer) 33 44 (Bellerin) ( _ "Bellerin") (upkeep=free)}

        [redraw]
        [/redraw]

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

        {NAMED_UNIT 2 (Swordsman) 34 44 (Durth) ( _ "Durth") (upkeep=free)}

        [redraw]
        [/redraw]

        [move_unit_fake]
            type=Longbowman
            side=2
            x=36,35,34
            y=42,43,43
        [/move_unit_fake]

        {NAMED_UNIT 2 (Longbowman) 34 43 (Othgar) ( _ "Othgar") (upkeep=free)}

        [redraw]
        [/redraw]

#endif

#ifdef HARD

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

        {NAMED_UNIT 2 (Javelineer) 33 44 (Bellerin) ( _ "Bellerin") (upkeep=free)}

        [redraw]
        [/redraw]

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

        {NAMED_UNIT 2 (Swordsman) 34 44 (Durth) ( _ "Durth") (upkeep=free)}

        [redraw]
        [/redraw]

        [move_unit_fake]
            type=Master Bowman
            side=2
            x=36,35,34
            y=42,43,43
        [/move_unit_fake]

        {NAMED_UNIT 2 (Master Bowman) 34 43 (Othgar) ( _ "Othgar") (upkeep=free)}

        [redraw]
        [/redraw]

#endif
        # wmllint: recognize Bellerin
        # wmllint: recognize Durth
        # wmllint: recognize Othgar

        [message]
            speaker=Durth
            # wmllint: local spelling durn
            message= _ "Huff, huff. 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]

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id=$ally_name
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=0
            [/variable]

            [then]
                [set_variable]
                    name=type_of_sealife
                    value=1
                [/set_variable]

                [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, pale hair, those shifty eyes, hearts as hard as a hermit crab's shell. It must be an invasion, they must have started the flood!"
                [/message]
            [/then]

            [else]
                [if]
                    [variable]
                        name=ally_race
                        equals=Dwarf
                    [/variable]
                    [then]
                        [message]
                            speaker=Othgar
                            message= _ "Hey look! It's a dwarf!"
                        [/message]
                        [message]
                            speaker=Durth
                            message= _ "Huh? A dwarf?"
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=Othgar
                            message= _ "Hey look! It's a troll!"
                        [/message]
                        [message]
                            speaker=Durth
                            message= _ "Huh? A troll?"
                        [/message]
                    [/else]
                [/if]
                [if]
                    [variable]
                        name=ally_race
                        equals=Troll
                    [/variable]

                    [then]
                        [set_variable]
                            name=type_of_sealife
                            value=2
                        [/set_variable]

                        [message]
                            speaker=Bellerin
                            message= _ "Yeah, just like my old grandmam used to tell us: dark green 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]
                    [/then]

                    [else]
                        [set_variable]
                            name=type_of_sealife
                            value=3
                        [/set_variable]

                        [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]
                    [/else]
                [/if]
            [/else]
        [/if]

        {CLEAR_VARIABLE unittest}

        [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
        first_time_only=no

        [filter]
            side=2
        [/filter]

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

        [if]
            [variable]
                name=humans_killed
                numerical_equals=3
            [/variable]

            [then]
                [set_variable]
                    name=humans_killed
                    add=1
                [/set_variable]

                #kill human before displaying messages
                [kill]
                    side=2
                    animate=no
                [/kill]

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

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

                    [then]
                        # case 1: humans saw an elf first and mentioned hermit crabs

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

                            [then]
                                [message]
                                    speaker=Kaleh
                                    message= _ "Fish bait? Hermit Crabs? Who are these humans and what were they talking about?"
                                [/message]
                            [/then]

                            [else]
                                {CHECK_SPEAKER}
                                [message]
                                    speaker=$speaking_unit.id
                                    message= _ "Fish bait? Hermit Crabs? Who are these humans and what were they talking about?"
                                [/message]
                                {CLEAR_VARIABLE speaking_unit}
                            [/else]
                        [/if]
                    [/then]

                    [else]
                        [if]
                            [variable]
                                name=type_of_sealife
                                numerical_equals=2
                            [/variable]

                            [then]
                                # case 2: humans saw troll ally first and mentioned barnacles

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

                                    [then]
                                        [message]
                                            speaker=Kaleh
                                            message= _ "Fish bait? Barnacles? Who are these humans and what were they talking about?"
                                        [/message]
                                    [/then]

                                    [else]
                                        {CHECK_SPEAKER}
                                        [message]
                                            speaker=$speaking_unit.id
                                            message= _ "Fish bait? Barnacles? Who are these humans and what were they talking about?"
                                        [/message]
                                        {CLEAR_VARIABLE speaking_unit}
                                    [/else]
                                [/if]
                            [/then]

                            [else]
                                # case 3: humans saw dwarf ally first and mentioned cuttlefish

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

                                    [then]
                                        [message]
                                            speaker=Kaleh
                                            message= _ "Fish bait? Cuttlefish? Who are these humans and what were they talking about?"
                                        [/message]
                                    [/then]

                                    [else]
                                        [message]
                                            speaker=second_unit
                                            message= _ "Fish bait? Cuttlefish? Who are these humans and what were they talking about?"
                                        [/message]
                                    [/else]
                                [/if]
                            [/else]
                        [/if]
                    [/else]
                [/if]

                [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]
            [/then]
        [/if]
    [/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]

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id=$ally_name
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=0
            [/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]

        {CLEAR_VARIABLE unittest}

        [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]
    [/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= _ "Okay, 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=Ww
        [/terrain]
    [/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]

        [if]
            [variable]
                name=entered_gate
                numerical_equals=0
            [/variable]

            [then]
                [set_variable]
                    name=entered_gate
                    value=1
                [/set_variable]

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

                [redraw]
                [/redraw]

                [delay]
                    time=100
                [/delay]

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

                [redraw]
                [/redraw]

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

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

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

                    id=RuneDamage
                    silent=yes

                    [effect]
                        apply_to=hitpoints
#ifdef EASY
                        increase=-25%
#endif
                    [/effect]

                    [effect]
                        apply_to=hitpoints
#ifdef NORMAL
                        increase=-30%
#endif
                    [/effect]

                    [effect]
                        apply_to=hitpoints
#ifdef HARD
                        increase=-35%
#endif
                    [/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)}
            [/then]
        [/if]
    [/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
            y=41-44
            side=1
        [/remove_shroud]

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

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id=$ally_name
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=0
            [/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]

        {CLEAR_VARIABLE unittest}

        [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

    [event]
        name=moveto
        first_time_only=no

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

        [if]
            [variable]
                name=healing_rune1
                greater_than=0
            [/variable]

            [then]
                [colour_adjust]
                    red,green,blue=31,122,255
                [/colour_adjust]

                [redraw]
                [/redraw]

                [delay]
                    time=100
                [/delay]

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

                [redraw]
                [/redraw]

                [object]
                    [filter]
                        x,y=17,44
                    [/filter]

                    silent=yes
                    duration="level"

                    [effect]
                        apply_to="hitpoints"
                        heal_full="yes"
                    [/effect]
                [/object]

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

                [set_variable]
                    name=healing_rune1
                    add=-1
                [/set_variable]

                [if]
                    [variable]
                        name=healing_rune1
                        numerical_equals=0
                    [/variable]

                    [then]
                        [removeitem]
                            x,y=17,44
                        [/removeitem]

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

                        [set_variable]
                            name=healing_rune1
                            add=-1
                        [/set_variable]
                    [/then]
                [/if]
            [/then]

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

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x=19
            y=43
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [if]
            [variable]
                name=healing_rune2
                greater_than=0
            [/variable]

            [then]
                [colour_adjust]
                    red,green,blue=31,122,255
                [/colour_adjust]

                [redraw]
                [/redraw]

                [delay]
                    time=100
                [/delay]

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

                [redraw]
                [/redraw]

                [object]
                    [filter]
                        x,y=19,43
                    [/filter]

                    silent=yes
                    description=_"The user feels much better."
                    duration="level"

                    [effect]
                        apply_to="hitpoints"
                        heal_full="yes"
                    [/effect]
                [/object]

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

                [set_variable]
                    name=healing_rune2
                    add=-1
                [/set_variable]

                [if]
                    [variable]
                        name=healing_rune2
                        numerical_equals=0
                    [/variable]

                    [then]
                        [removeitem]
                            x,y=19,43
                        [/removeitem]

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

                        [set_variable]
                            name=healing_rune2
                            add=-1
                        [/set_variable]
                    [/then]
                [/if]
            [/then]

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

    # Event 7: Enter dining cavern

    # water pours in from the west
    # 2/3/4 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=Ww
        [/terrain]

        [remove_shroud]
            x=5-15
            y=46-49
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=5-11
            y=46-51
            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]

        # I replaced the water snake units with soulless units
        # I deleted the water snake units becuase they lacked proper animation

        {NAMED_UNIT 3 (Soulless) 7 48 () ( _ "Bloated Corpse") (upkeep=free)}
        {NAMED_UNIT 3 (Soulless) 8 49 () ( _ "Bloated Corpse") (upkeep=free)}
    [/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
            y=39-45
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=7-14
            y=40-45
            side=1
        [/remove_shroud]

        #activate flooding of dining cavern

        [terrain]
            x=8,8
            y=48,49
            terrain=Ww
        [/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]

        [set_variable]
            name=entered_training_hall
            value=1
        [/set_variable]
    [/event]

    #at next turn create haunt trainer and ghost novices

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [set_variable]
                    name=entered_training_hall
                    value=2
                [/set_variable]

                #create wraith and ghosts

                {NAMED_UNIT 3 (Haunt) 9 40 (Blessed Kali) ( _ "Blessed Kali") (upkeep=free)}

                {NAMED_UNIT 3 (Ghost) 9 43 (Novice Pior) ( _ "Novice Pior") (upkeep=free)}
                {NAMED_UNIT 3 (Ghost) 11 41 (Novice Iona) ( _ "Novice Iona") (upkeep=free)}
                {NAMED_UNIT 3 (Ghost) 12 42 (Novice Dani) ( _ "Novice Dani") (upkeep=free)}

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

                [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]
            [/then]
        [/if]
    [/event]

    # while trainer is alive, replace any defeated ghosts

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [set_variable]
                    name=iona_dead
                    value=1
                [/set_variable]

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

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

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

                    [then]
                        [set_variable]
                            name=iona_dead
                            value=0
                        [/set_variable]
                    [/then]
                [/if]

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

                    [then]
                        [set_variable]
                            name=dani_dead
                            value=0
                        [/set_variable]
                    [/then]
                [/if]

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

                    [then]
                        [set_variable]
                            name=pior_dead
                            value=0
                        [/set_variable]
                    [/then]
                [/if]

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

                    [or]
                        [variable]
                            name=dani_dead
                            numerical_equals=1
                        [/variable]
                    [/or]

                    [or]
                        [variable]
                            name=pior_dead
                            numerical_equals=1
                        [/variable]
                    [/or]

                    [then]
                        [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]
                    [/then]
                [/if]

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

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

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

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

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

                    [then]
                        {NAMED_UNIT 3 (Ghost) 9 43 (Novice Pior) ( _ "Novice Pior") (upkeep=free)}
                    [/then]
                [/if]
            [/then]
        [/if]
    [/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]

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

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

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

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

            [then]
                [set_variable]
                    name=iona_dead
                    value=0
                [/set_variable]
            [/then]
        [/if]

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

            [then]
                [set_variable]
                    name=dani_dead
                    value=0
                [/set_variable]
            [/then]
        [/if]

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

            [then]
                [set_variable]
                    name=pior_dead
                    value=0
                [/set_variable]
            [/then]
        [/if]

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

            [then]
                {NAMED_UNIT 3 (Ghost) 13 43 (Novice Dani) ( _ "Novice Dani") (upkeep=free)}
            [/then]
        [/if]

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

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

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

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

        [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 Ion
            # 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
            animate=no
            fire_event=no
        [/kill]

        [kill]
            id=Novice Dani
            animate=no
            fire_event=no
        [/kill]

        [kill]
            id=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 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=Ww
        [/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]

        [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

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

        [redraw]
        [/redraw]

        [delay]
            time=100
        [/delay]

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

        [redraw]
        [/redraw]

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

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

            id=WizardDamage
            silent=yes

#ifdef EASY
            [effect]
                apply_to=hitpoints
                increase=-20%
            [/effect]
#endif

#ifdef NORMAL
            [effect]
                apply_to=hitpoints
                increase=-25%
            [/effect]
#endif

#ifdef HARD
            [effect]
                apply_to=hitpoints
                increase=-30%
            [/effect]
#endif
        [/object]

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

        [set_variable]
            name=unitstats.status.poisoned
            value="on"
        [/set_variable]

        [unstore_unit]
            variable=unitstats
        [/unstore_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= _ "Grawww!"    # wmllint: no spellcheck
        [/message]

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

    #disrupt magical circle

    [event]
        name=moveto
        first_time_only=no

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

        [if]
            [variable]
                name=broke_circle
                numerical_equals=0
            [/variable]

            [then]
                [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]
                        message= _ "Break the circle"
                        [command]
                            [set_variable]
                                name=broke_circle
                                value=1
                            [/set_variable]

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

                            # 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

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

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

                            [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]
                        message= _ "Leave that thing alone."

                        [command]
                            [allow_undo]
                            [/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]

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

    # Event 11: Enter Unholy Sanctuary

    [event]
        name=moveto

        [filter]
            x=5-10
            y=32-37
            side=1
            [not]
                type=Dust Devil
            [/not]
            [not]
                type=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]
            speaker=Nym
            message= _ "I though you said $intl_ally_name, 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]

        [set_variable]
            name=entered_temple
            value=1
        [/set_variable]
    [/event]

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [set_variable]
                    name=entered_temple
                    value=2
                [/set_variable]

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

                [redraw]
                [/redraw]

                [delay]
                    time=100
                [/delay]

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

                [redraw]
                [/redraw]

                {NAMED_UNIT 9 (Ixthala Demon) 5 35 (Ancient Guardian 1) ( _ "Ancient Guardian") (upkeep=free)}
                {NAMED_UNIT 9 (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]
            [/then]
        [/if]
    [/event]

    # Altar contains hidden lever which open secret exit

    [event]
        name=moveto
        first_time_only=no

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

        [if]
            [variable]
                name=pulled_lever
                numerical_equals=0
            [/variable]

            [then]
                [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]
                        message= _ "Pull the lever."
                        [command]
                            [set_variable]
                                name=pulled_lever
                                value=1
                            [/set_variable]

                            [scroll]
                                x=20
                            [/scroll]
                            [scroll]
                                x=-20
                            [/scroll]
                            [scroll]
                                x=20
                            [/scroll]
                            [scroll]
                                x=-20
                            [/scroll]

                            [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=Ww
                            [/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]
                        message= _ "Leave it alone."

                        [command]
                            [allow_undo]
                            [/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]

            [else]
                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/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)}
        # wmllint: recognize Crypt Guardian

        [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
    # Figure appears at 10,19

    [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]

        [store_locations]
            variable=cloaked
            x=8-12
            y=19-23
            terrain=Uu,Uh
            [not]
                [filter]
                [/filter]
            [/not]
        [/store_locations]

        [unit]
            type=Dark Assassin3
            id=Cloaked Figure
            name= _ "Cloaked Figure"
            side=7
            x=$cloaked.x
            y=$cloaked.y
            [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]

        #TODO find a better place for the macro
#define KALEH_TELEPORT X Y

    # search adjacent hexs for one that is not cave wall or chasm or water
    # when you find a hex that is valid, check to see if a unit is already
    # there, if the hex is empty teleport Kaleh there

    [store_locations]
        [filter_adjacent_location]
            x={X}
            y={Y}
        [/filter_adjacent_location]
        terrain=Uu, Re, Uu^Vu, Cud, Ke, Uh, Uu^Uf
        [not]
            [filter]
            [/filter]
        [/not]
        variable=coords
    [/store_locations]

    [if]
        [not]
            [have_unit]
                x=$coords[0].x
                y=$coords[0].y
                side=1
            [/have_unit]
        [/not]
        [then]
            [teleport]
                [filter]
                    id=Kaleh
                [/filter]
                x=$coords[0].x
                y=$coords[0].y
            [/teleport]
        [/then]
        [else]
        [/else]
    [/if]

#enddef

        [event]
            name=moveto

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

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

            [remove_shroud]
                x=21-24
                y=17-21
                side=1
            [/remove_shroud]

            # this command is to keep Durth, Othgar, and Bellerin's death counter
            # from firing once side 2 humans start dying

            [set_variable]
                name=humans_killed
                add=10
            [/set_variable]

            {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]

            [store_locations]
                x,y=$x1,$y1
                [filter]
                    id="Kaleh"
                [/filter]
                variable=kalehtest
            [/store_locations]

            [if]
                [variable]
                    name=kalehtest.length
                    numerical_equals=0
                [/variable]

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

                    {KALEH_TELEPORT $x1 $y1}
                [/then]
            [/if]

            {CLEAR_VARIABLE explorer}
            {CLEAR_VARIABLE kalehtest}

            [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
                [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=no
                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."
            [/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= _ "Okay 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]

            # price of recruits goes up based on number of turns it took to escape
            # the caves

            [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 the price of recruiting new units by 2 gold

            [if]
                [variable]
                    name=scen3
                    numerical_equals=2
                [/variable]

                [then]
                    #go from 5 to 7

                    [disallow_recruit]
                        type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                        side=1
                    [/disallow_recruit]

                    [disallow_recruit]
                        type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                        side=1
                    [/disallow_recruit]

                    [disallow_recruit]
                        type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                        side=1
                    [/disallow_recruit]

                    [disallow_recruit]
                        type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                        side=1
                    [/disallow_recruit]

                    [disallow_recruit]
                        type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                        side=1
                    [/disallow_recruit]

                    [disallow_recruit]
                        type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                        side=1
                    [/disallow_recruit]

                    [allow_recruit]
                        type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
                        side=1
                    [/allow_recruit]
                [/then]

                [else]
                    [if]
                        [variable]
                            name=scen3
                            numerical_equals=1
                        [/variable]

                        [then]
                            #go from 4 to 6

                            [disallow_recruit]
                                type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                                side=1
                            [/disallow_recruit]

                            [allow_recruit]
                                type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                                side=1
                            [/allow_recruit]
                        [/then]
                    [/if]

                    [if]
                        [variable]
                            name=scen3
                            numerical_equals=3
                        [/variable]

                        [then]
                            #go from 6 to 8

                            [disallow_recruit]
                                type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                                side=1
                            [/disallow_recruit]

                            [disallow_recruit]
                                type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
                                side=1
                            [/disallow_recruit]

                            [allow_recruit]
                                type=Desert Fighter8, Desert Archer8, Desert Hunter8, Desert Shaman8, Desert Scout8
                                side=1
                            [/allow_recruit]
                        [/then]
                    [/if]
                [/else]
            [/if]

            [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]

            [objectives]
                summary= _ "New Objectives:"
                show=yes
                [objective]
                    description= _ "Explore Outside"
                    condition=win
                [/objective]
                [objective]
                    description= _ "Death of Kaleh, Nym, or Zhul"
                    condition=lose
                [/objective]

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

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

            # 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 misc/hero-icon.png}
        [/event]
    [/event]

    [event]
        name=moveto

        [filter]
            x=12-20
            y=1-18
            side=1
            [not]
                type=Dust Devil
            [/not]
            [not]
                type=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]

    # I want the conversation between Kaleh and the dwarf/troll ally
    #  to occur the turn after the player finds the exit and Keratur dies

    # So I am putting this event out of order, so that when the
    # player enters the final cave, it checks if ally_conversation=1 before
    # ally_conversation is set to 1. So that way, this event doesn't
    # happen until the turn afterwards.

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [set_variable]
                    name=ally_conversation
                    value=2
                [/set_variable]

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

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

                    [then]
                        [message]
                            speaker=Kaleh
                            message= _ "$intl_ally_name, 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=$ally_name
                            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=$ally_name
                            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=$ally_name
                            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]
                    [/then]

                    [else]
                        [message]
                            speaker=Kaleh
                            message= _ "$intl_ally_name, 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=$ally_name
                            message= _ "$intl_ally_name proud of little elves too. He would not have made it this far without all your help. $intl_ally_name is surprised by your bravery and strength."
                        [/message]

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

                        [message]
                            speaker=$ally_name
                            message= _ "But $intl_ally_name not afraid. Great leader told $intl_ally_name to guide and protect elves, and $intl_ally_name will keep his oath. $intl_ally_name will follow elves wherever they may go and protect them from danger as best he can. Maybe later, $intl_ally_name will find another way back down to the caves of his people. But for now, $intl_ally_name will continue to serve and protect you."
                        [/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]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

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

    # 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
            [/not]
            [not]
                type=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]

#ifdef EASY
        [gold]
            amount=75
            side=1
        [/gold]
#endif

#ifdef NORMAL
        [gold]
            amount=150
            side=1
        [/gold]
#endif

#ifdef HARD
        [gold]
            amount=175
            side=1
        [/gold]
#endif
    [/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
            [/not]
        [/filter]

        [store_locations]
            x,y=$x1,$y1
            [filter]
                race=elf
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=1
            [/variable]

            [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]

        {CLEAR_VARIABLE unittest}

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id=$ally_name
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=1
            [/variable]

            [then]
                [if]
                    [variable]
                        name=ally_race
                        equals=Dwarf
                    [/variable]

                    [then]
                        # dwarf ally version

                        [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]

                    [else]
                        # troll ally version
                        [message]
                            speaker=unit
                            message= _ "We made it. Outside look strange to $intl_ally_name, $intl_ally_name not used to big open spaces."
                        [/message]
                    [/else]
                [/if]
            [/then]
        [/if]

        {CLEAR_VARIABLE unittest}

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id=Kromph
            [/filter]
            variable=unittest
        [/store_locations]

        [if]
            [variable]
                name=unittest.length
                numerical_equals=1
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "Kromph is outside, but everything looks strange. What does mistress want Kromph to do?"
                [/message]

                [message]
                    speaker=Nym
                    message= _ "Just stay where you are, I'll come up there myself"
                [/message]

                # teleport nym next to kromph to see for herself

                [teleport]
                    [filter]
                        id=Nym
                    [/filter]
                    x,y=$temp_x,$temp_y
                [/teleport]

                [redraw]
                [/redraw]

                [message]
                    speaker=Nym
                    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]

        {CLEAR_VARIABLE unittest}

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

        {CHECK_EXPLORER}
        [message]
            speaker=$explorer.id
            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
            y=27
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=23-31
            y=28
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=25-31
            y=29
            side=1
        [/remove_shroud]

        #South and SE edge of valley
        [remove_shroud]
            x=48-56
            y=17-26
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=48-54
            y=27
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=48-53
            y=28
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=48-51
            y=29-30
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=27-49
            y=31
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=29-31
            y=32
            side=1
        [/remove_shroud]

        [remove_shroud]
            x=35-47
            y=32
            side=1
        [/remove_shroud]

        #eloh appears

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

        [store_locations]
            x,y=$x1,$y1
            [filter]
                id="Kaleh"
            [/filter]
            variable=kalehtest
        [/store_locations]

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

        [if]
            [variable]
                name=kalehtest.length
                numerical_equals=0
            [/variable]

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

                [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]

                [teleport]
                    [filter]
                        id=Kaleh
                    [/filter]
                    x,y=25,23
                [/teleport]
            [/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=kalehtest.length
                numerical_equals=0
            [/variable]

            [then]
                [message]
                    speaker=$explorer.id
                    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= _ " $speaker.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

        [teleport]
            [filter]
                id=$ally_name
            [/filter]
            x,y=21,23
        [/teleport]

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

        [message]
            speaker=Kaleh
            message= _ "Not now $intl_ally_name, 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]

        {CLEAR_VARIABLE kalehtest}
        {CLEAR_VARIABLE speaker}

        [delay]
            time=100
        [/delay]

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

        [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 a 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 they're 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."
        [/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
            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]

        [teleport]
            [filter]
                id=Kaleh
            [/filter]
            x,y=18,19
        [/teleport]

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

            [then]
                [message]
                    speaker=$ally_name
                    message= _ "$intl_ally_name no like humans either. They mean. But they sound great when they go squish."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=$ally_name
                    message= _ "I never liked humans much anyway. I'll be glad to be fighting something besides undead."
                [/message]
            [/else]
        [/if]

        [modify_side]
            side=2

#ifdef EASY
            income=9
            gold=150
#endif
#ifdef NORMAL
            income=11
            gold=150
#endif
#ifdef HARD
            income=13
            gold=175
#endif
        [/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]

        [objectives]
            summary= _ "New Objectives:"
            show=yes
            [objective]
                description= _ "Defeat Sergeant Durstrag"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kaleh, Nym, or Zhul"
                condition=lose
            [/objective]

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

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

        # 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

    # Since last turn Kaleh got teleported to (18,19) he can't have moved
    # very far. If Kaleh is on player's keep hex (which is probable) then
    # teleport Nym right next to him. If he's in northern part of entrance cave
    # put her in center of cave. Else assume he's at edge of southern cave and
    # put her near him. I could just teleport Nym directly onto Kaleh's
    # location, but this often makes her appear in a cave wall.

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [set_variable]
                    name=pissed_off_durstrag
                    value=2
                [/set_variable]

                [unstore_unit]
                    variable=Nymstats
                [/unstore_unit]

                {CLEAR_VARIABLE Nymstats}

                # if Kaleh is on keep hex (18,19) teleport Nym next to him

                [if]
                    [have_unit]
                        id=Kaleh
                        x,y=18,19
                    [/have_unit]

                    [then]
                        [teleport]
                            [filter]
                                id=Nym
                            [/filter]
                            x,y=19,19
                        [/teleport]
                    [/then]

                    [else]
                        # if Kaleh is elsewhere in northern part of entrance caves,
                        # then put Nym on 21,20 (roughly center of entrance cave)

                        [if]
                            [have_unit]
                                id=Kaleh
                                x,y=13-24,16-20
                            [/have_unit]

                            [then]
                                [teleport]
                                    [filter]
                                        id=Nym
                                    [/filter]
                                    x,y=21,20
                                [/teleport]
                            [/then]

                            [else]
                                # else Kaleh must be at edge of entrance cave,
                                # so put Nym at 21,21

                                [teleport]
                                    [filter]
                                        id=Nym
                                    [/filter]
                                    x,y=21,21
                                [/teleport]
                            [/else]
                        [/if]
                    [/else]
                [/if]

                [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]

                [objectives]
                    summary= _ "New Objectives:"
                    show=yes
                    [objective]
                        description= _ "Defeat Sergeant Durstrag"
                        condition=win
                    [/objective]
                    [objective]
                        description= _ "If a human messenger escapes the valley"
                        condition=lose
                    [/objective]
                    [objective]
                        description= _ "Death of Kaleh, Nym, or Zhul"
                        condition=lose
                    [/objective]
                    note= _ "The messenger is the leader of the special white colored units"+"
"+{EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
                [/objectives]

                # flag to store if we should start the messenger timer or not
                [set_variable]
                    name=start_messenger_timer
                    value=1
                [/set_variable]

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

                [set_variable]
                    name=messenger_timer
                    value=2
                [/set_variable]
            [/then]
        [/if]
    [/event]

    # Event 17: Undead Emissary

    # If it is dusk or night

    [event]
        name=new turn
        first_time_only=no

        [if]
            [variable]
                name=time_of_day
                equals=5
            [/variable]

            [or]
                [variable]
                    name=time_of_day
                    equals=6
                [/variable]
            [/or]

            [or]
                [variable]
                    name=time_of_day
                    equals=-5
                [/variable]
            [/or]

            [or]
                [variable]
                    name=time_of_day
                    equals=-6
                [/variable]
            [/or]

            [or]
                [variable]
                    name=time_of_day
                    equals=-7
                [/variable]
            [/or]

            [or]
                [variable]
                    name=time_of_day
                    equals=-8
                [/variable]
            [/or]

            [or]
                [variable]
                    name=time_of_day
                    equals=-9
                [/variable]
            [/or]

            [then]
                [if]
                    [variable]
                        name=start_messenger_timer
                        numerical_equals=1
                    [/variable]

                    [variable]
                        name=undead_emissary
                        numerical_equals=0
                    [/variable]

                    [then]
                        [set_variable]
                            name=undead_emissary
                            value=1
                        [/set_variable]

                        [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") (upkeep=free)}
                        # wmllint: recognize 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

#ifdef EASY
                            income=9
                            gold=100
#endif
#ifdef NORMAL
                            income=11
                            gold=125
#endif
#ifdef HARD
                            income=13
                            gold=150
#endif
                        [/modify_side]

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

    #Event 17.5 A conversation about the humans

    [event]
        name=new turn
        first_time_only=no

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

            [variable]
                name=human_conversation
                numerical_equals=0
            [/variable]

            [then]
                [set_variable]
                    name=human_conversation
                    value=1
                [/set_variable]

                [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]
            [/then]
        [/if]
    [/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=new turn
        first_time_only=no

        [if]
#ifdef EASY
            [variable]
                name=messenger_timer
                numerical_equals=8
            [/variable]
#endif
#ifdef NORMAL
            [variable]
                name=messenger_timer
                numerical_equals=7
            [/variable]
#endif
#ifdef HARD
            [variable]
                name=messenger_timer
                numerical_equals=6
            [/variable]
#endif

            [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]

                {RANDOM 44..51}

                [set_variable]
                    name=loc_x
                    value=$random
                [/set_variable]

                {RANDOM 21..25}

                [set_variable]
                    name=loc_y
                    value=$random
                [/set_variable]

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

                [unit]
#ifdef EASY
                    type=Cavalryman
#endif
#ifdef NORMAL
                    type=Cavalier
#endif
#ifdef HARD
                    type=Dragoon
#endif
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    goto_y=1
                    side=8
                [/unit]

                [unit]
#ifdef EASY
                    type=Cavalryman
#endif
#ifdef NORMAL
                    type=Cavalier
#endif
#ifdef HARD
                    type=Dragoon
#endif
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    goto_y=1
                    side=8
                [/unit]

                [unit]
#ifdef EASY
                    type=Spearman
#endif
#ifdef NORMAL
                    type=Javelineer
#endif
#ifdef HARD
                    type=Swordsman
#endif
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    goto_y=1
                    side=8
                [/unit]

                [unit]
#ifdef EASY
                    type=Spearman
#endif
#ifdef NORMAL
                    type=Longbowman
#endif
#ifdef HARD
                    type=Master Bowman
#endif
                    name= _ "Human Escort"
                    upkeep=free
                    x=$loc_x
                    y=$loc_y
                    goto_y=1
                    side=8
                [/unit]

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

    # Event 18.5: Messenger Dies

    [event]
        name=last breath
        first_time_only=no

        [filter]
            id=Human Messenger
        [/filter]

        [message]
            speaker=Human Messenger
            message= _ "No! I must get help!"
        [/message]

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

    # Event 19: Messenger Escapes!

    [event]
        name=moveto

        [filter]
            side=8
            id= "Human Messenger"
            y=1
        [/filter]

        [kill]
            id= "Human 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 then 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 ice
    # 2. change hexes adjacent to ice to shallow water (except for cave wall)
    # 3. change ice to deep water
    # 4. kill any unit in deep water, destroy any items in deep water

    [event]
        name=new turn

        first_time_only=no

        [if]
            [variable]
                name=stop_flooding
                numerical_equals=0
            [/variable]

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

            [then]
                # 1. change all shallow water hexes to ice

                [store_locations]
                    terrain=Ww
                    variable=shallowwater_loc
                [/store_locations]

                {FOREACH shallowwater_loc i}
                    [set_variable]
                        name=water_x
                        to_variable=shallowwater_loc[$i].x
                    [/set_variable]

                    [set_variable]
                        name=water_y
                        to_variable=shallowwater_loc[$i].y
                    [/set_variable]

                    [terrain]
                        terrain=Ai
                        x,y=$water_x,$water_y
                    [/terrain]
                {NEXT i}

                {CLEAR_VARIABLE shallowwater_loc}

                # 2. change caves adjacent to ice to shallow water

                #That step of the algorithm was bugged and otherwise completly insane
                #So completly rewritten below
                #And mercifuly short

                [store_locations]
                    terrain=Ai
                    variable=ice_loc
                [/store_locations]

                {FOREACH ice_loc i}
                    [set_variable]
                        name=coord_x
                        to_variable=ice_loc[$i].x
                    [/set_variable]

                    [set_variable]
                        name=coord_y
                        to_variable=ice_loc[$i].y
                    [/set_variable]

                    # find adjacent hex with cave floor or dirt

                    [store_locations]
                        [filter_adjacent_location]
                            x=$coord_x
                            y=$coord_y
                        [/filter_adjacent_location]
                        terrain=Uu, Re, Uu^Vu, Ce, Ke, Ch, Rr, Qxu, Uh, Uu^Uf, Ryd
                        variable=hex_loc
                    [/store_locations]

                    {FOREACH hex_loc j}
                        [set_variable]
                            name=water_x
                            to_variable=hex_loc[$j].x
                        [/set_variable]

                        [set_variable]
                            name=water_y
                            to_variable=hex_loc[$j].y
                        [/set_variable]

                        [terrain]
                            terrain=Ww
                            x,y=$water_x,$water_y
                        [/terrain]
                    {NEXT j}
                {NEXT i}

                {CLEAR_VARIABLE ice_loc}

                # 3. change ice to deep water

                [store_locations]
                    terrain=Ai
                    variable=shallowwater_loc
                [/store_locations]

                {FOREACH shallowwater_loc i}
                    [set_variable]
                        name=water_x
                        to_variable=shallowwater_loc[$i].x
                    [/set_variable]

                    [set_variable]
                        name=water_y
                        to_variable=shallowwater_loc[$i].y
                    [/set_variable]

                    [terrain]
                        terrain=Wo
                        x,y=$water_x,$water_y
                    [/terrain]
                {NEXT i}

                # 4. kill any unit in deep water, destroy any items in deep water

                [store_locations]
                    terrain=Wo
                    variable=deepwater_loc
                [/store_locations]

                {FOREACH deepwater_loc i}
                    [set_variable]
                        name=water_x
                        to_variable=deepwater_loc[$i].x
                    [/set_variable]

                    [set_variable]
                        name=water_y
                        to_variable=deepwater_loc[$i].y
                    [/set_variable]

                    #destroy any items in deep water
                    [removeitem]
                        x,y=$water_x,$water_y
                    [/removeitem]

                    # If unit side is not 3 then kill unit. (side 3is undead who can't drown)
                    # Also if unit side is 1 then display death message: "I'm drowning!"

                    [store_locations]
                        x,y=$water_x,$water_y
                        [filter]
                            side=1,2,4,5,6,7,8,9
                        [/filter]
                        variable=victim_side
                    [/store_locations]

                    [if]
                        [variable]
                            name=victim_side.length
                            numerical_equals=1
                        [/variable]

                        [then]
                            [store_locations]
                                x,y=$water_x,$water_y
                                [filter]
                                    side=1
                                [/filter]
                                variable=victim_side
                            [/store_locations]

                            [if]
                                [variable]
                                    name=victim_side.length
                                    numerical_equals=1
                                [/variable]

                                [then]
                                    [message]
                                        x,y=$water_x,$water_y
                                        message= _ "Help, I'm drowning!"
                                    [/message]
                                [/then]
                            [/if]

                            # if it is a human that drowned, set the flag
                            # flag is used for death event of 3 human spelunkers, to display
                            # alternate death message if the last of them dies from drowning
                            [store_locations]
                                x,y=$water_x,$water_y
                                [filter]
                                    side=2
                                [/filter]
                                variable=victim_side
                            [/store_locations]

                            [if]
                                [variable]
                                    name=victim_side.length
                                    numerical_equals=1
                                [/variable]

                                [then]
                                    [set_variable]
                                        name=human_drowned
                                        value=1
                                    [/set_variable]
                                [/then]
                            [/if]

                            [kill]
                                x,y=$water_x,$water_y
                                animate=no
                                fire_event=yes
                            [/kill]

                            #clear the flag
                            [set_variable]
                                name=human_drowned
                                value=0
                            [/set_variable]
                        [/then]
                    [/if]
                {NEXT i}

                {CLEAR_VARIABLE deepwater_loc}
            [/then]
        [/if]
    [/event]

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

    [event]
        name=new turn
        first_time_only=no

        [store_locations]
            x=12
            y=18
            terrain=Ww, Wo
            variable=hex_loc
        [/store_locations]

        [set_variable]
            name=temp
            value=$hex_loc.length
        [/set_variable]

        {CLEAR_VARIABLE hex_loc}

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

            [then]
                [set_variable]
                    name=stop_flooding
                    value=1
                [/set_variable]

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

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

                    [variable]
                        name=saw_valley_river
                        numerical_equals=0
                    [/variable]

                    [then]
                        [set_variable]
                            name=saw_valley_river
                            value=1
                        [/set_variable]

                        [message]
                            x=26-50
                            y=1-33
                            side=1
                            [not]
                                type=Dust Devil
                            [/not]
                            [not]
                                type=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]
                        [if]
                            [have_unit]
                                x=21-37
                                y=18-33
                                side=1
                                [not]
                                    type=Dust Devil
                                [/not]
                                [not]
                                    type=Flesh Golem
                                [/not]
                            [/have_unit]

                            [variable]
                                name=saw_valley_river
                                numerical_equals=0
                            [/variable]

                            [then]
                                [set_variable]
                                    name=saw_valley_river
                                    value=1
                                [/set_variable]

                                [message]
                                    x=21-37
                                    y=18-33
                                    side=1
                                    [not]
                                        type=Dust Devil
                                    [/not]
                                    [not]
                                        type=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]
                        [/if]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    # if 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
            [/not]
            [not]
                type=Flesh Golem
            [/not]
        [/filter]

        [allow_undo]
        [/allow_undo]

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

            [variable]
                name=saw_valley_river
                numerical_equals=0
            [/variable]

            [then]
                [set_variable]
                    name=saw_valley_river
                    value=1
                [/set_variable]

                [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]
            [/then]
        [/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]

        {NAMED_UNIT 1 (Desert Fighter) 66 2 (Dummy Unit1) ( _ "Dummy Unit1") (upkeep=free)}
        {NAMED_UNIT 1 (Desert Fighter) 57 3 (Dummy Unit2) ( _ "Dummy Unit2") (upkeep=free)}
        {NAMED_UNIT 1 (Desert Archer) 65 3 (Dummy Unit3) ( _ "Dummy Unit3") (upkeep=free)}
        {NAMED_UNIT 1 (Desert Archer) 59 2 (Dummy Unit4) ( _ "Dummy Unit4") (upkeep=free)}
        {NAMED_UNIT 1 (Desert Hunter) 58 5 (Dummy Unit5) ( _ "Dummy Unit5") (upkeep=free)}
        {NAMED_UNIT 1 (Desert Shaman) 62 2 (Dummy Unit6) ( _ "Dummy Unit6") (upkeep=free)}

        [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
            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 okay?"
        [/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"
            profile=portraits/esanoo.png
            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 okay?"
        [/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
            animate=no
        [/kill]
        [kill]
            id=Dummy Unit2
            animate=no
        [/kill]
        [kill]
            id=Dummy Unit3
            animate=no
        [/kill]
        [kill]
            id=Dummy Unit4
            animate=no
        [/kill]
        [kill]
            id=Dummy Unit5
            animate=no
        [/kill]
        [kill]
            id=Dummy Unit6
            animate=no
        [/kill]

        {CLEAR_VARIABLE type_of_sealife}
        {CLEAR_VARIABLE humans_killed}
        {CLEAR_VARIABLE human_drowned}
        {CLEAR_VARIABLE entered_training_hall}
        {CLEAR_VARIABLE broke_circle}

        # the three undead trainees
        {CLEAR_VARIABLE iona_dead}
        {CLEAR_VARIABLE pior_dead}
        {CLEAR_VARIABLE dani_dead}

        {CLEAR_VARIABLE entered_temple}
        {CLEAR_VARIABLE pulled_lever}
        {CLEAR_VARIABLE ally_conversation}
        {CLEAR_VARIABLE pissed_off_durtarg}
        {CLEAR_VARIABLE start_messenger_timer}
        {CLEAR_VARIABLE messenger_timer}
        {CLEAR_VARIABLE loc_x}
        {CLEAR_VARIABLE loc_y}
        {CLEAR_VARIABLE undead_emissary}
        {CLEAR_VARIABLE stop_flooding}
        {CLEAR_VARIABLE human_conversation}
        {CLEAR_VARIABLE saw_valley_river}
    [/event]

    # set time for all underground areas to be always night/underground

    [time_area]
        x = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,26,27,27,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,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,78,79,80,81
        y = 9-60,9-61,8-61,8-61,7-61,7-61,7-61,7-61,7-61,7-61,6-61,6-61,5-61,6-61,5-61,6-61,6-61,7-61,7-61,7-61,7-22,26-61,7-22,27-61,7-21,27-61,7-21,28-61,7-20,28-61,8-20,29-61,8-10,14-18,29-61,9-10,16-17,30-61,31-61,32-61,32-61,32-61,31-61,31-61,31-61,32-61,32-61,33-61,32-61,33-61,32-61,33-61,33-61,34-61,34-61,34-61,33-61,32-61,31-61,31-61,30-61,29-61,28-61,28-61,26-61,26-61,21-61,19-61,17-61,15-61,13-61,12-61,11-61,11-61,10-61,10-61,9-61,9-61,8-61,8-61,6-61,6-61,5-61,5-61,4-61,4-61,2-61,2-61,2-61,0-61,0-61,0-61
        {UNDERGROUND}
    [/time_area]

    {campaigns/Under_the_Burning_Suns/utils/kaleh-abilities.cfg}
    {campaigns/Under_the_Burning_Suns/utils/deaths.cfg}
[/scenario]
