#textdomain wesnoth-utbs
#Level 4: Descending into Darkness

[scenario]

    id="4_Descending_into_Darkness"
    name= _ "Descending into Darkness"
    label= _ "Descending into Darkness"

    map_data="{campaigns/Under_the_Burning_Suns/maps/04_Descending_into_Darkness.map}"

    [music]
        name=northerners.ogg
    [/music]

    next_scenario=5_A_Subterranean_Struggle

    #don't display snapshot of map in saved games?
    snapshot="no"

    #max turns in scenario varies depending on difficulty
#ifdef EASY
    turns="50"
#endif
#ifdef NORMAL
    turns="48"
#endif
#ifdef HARD
    turns="46"
#endif
    victory_when_enemies_defeated=no

    {DAWN1}
    {MORNING1}
    {MIDDAY1}
    {AFTERNOON1}
    {DUSK1}
    {SHORTDARK}
    {DAWN2}
    {MORNING2}
    {MIDDAY2}
    {AFTERNOON2}
    {DUSK2}
    {LONGDARK1}
    {LONGDARK2}
    {LONGDARK3}
    {LONGDARK4}

    [story]
        [part]
            story= _ "Chapter 4: We found the crumbling obsidian tower that Eloh had described, and we camped at the edge of the foothills before the mountains. I was still shocked by the loss of Garak and all the other elves who fell in the battle last night. There was so much death in this land, was it always this way? As we traveled I pondered what this world must have been like back before the Great Fall and I remembered the tale that had been told to me many times since I was a child:"
        [/part]

        [part]
            story= _"A long, long time ago was the golden age among elves. Our people lived in harmony with nature in lands filled with trees, trees as far as the eye could see. There was peace among Elves and the other races such as Humans and Dwarves, and the evil creatures were driven deep within the earth. The foul name of Uria was not yet known among our people, and our powers were so great that we raised another sun into the sky, so that the days were lengthened and dark hours were few. Happy indeed were our people during these long years, but it was not to last forever."
        [/part]

        [part]
            story= _"Eventually peace and prosperity fostered corruption and decadence. Through her powers of deception and guile Uria cultivated secret groups of followers, promising to fulfill their darkest desires. She bided her time, and slowly stretched her black hands out across the world. At first, petty arguments between humans, elves and dwarves erupted into conflicts, embroiling our people in the first wars they had fought for ages. Then orcs and other foul creatures came back into the world and raided our settlements, razing villages and massacring hundreds. Uria's followers studied the necromantic arts and raised armies of undead. Our people had grown weak and soft in the time of peace and plenty and were ill-suited to cope with these new trials. Even nature herself seemed to quail under the onslaught: crops failed, the trees sickened and our forests started to die. Most disturbing was the way the nights lengthened, creating the long dark we suffer today. Many of our people despaired, and many embraced the oncoming darkness, worshiping Uria in hopes of saving themselves. Former friends fought over what few resources remained, and chaos threatened to overwhelm us all."
        [/part]

        [part]
            story= _"In this time of troubles Eloh first appeared to a select number of us, those few that still doggedly fought to preserve our homeland and our heritage. She told us that the old days had ended and only through strict discipline and strength could we survive in the new world. She led us out of the few remaining forests, which were being logged and burned by the orcs, into the open plains where we could roam freely. She taught us that alone we are weak, but together we can still strike fear into the hearts of our enemies. We learned that the only way to survive in this new harsh world was to always value the needs of the many over the wants of the individual. We must all work together, for without each other we are nothing. Even as the plains dried up into deserts we continued to follow her will and walk in her path, remembering our ancestors and the sacrifices they made that we might live, and always looking to create a better world for our children."
        [/part]

        [part]
            story= _"Was the golden age just a story? What kind of world could I be able to create for future generations of our people? All I knew of the past were the ruins of great castles and tales of a time when life was more than just a struggle to survive. Life did not seem to have grown easier for my people in the last few generations--if anything the land grew even more unforgiving. Was there anywhere left in this world that I could take my people which would be any better than the land we were born into?"
        [/part]
    [/story]
    [side]
        side=1
        description=Kaleh
        type=Desert Fighter
        canrecruit=yes
        {INCOME 6 4 2}
        controller=human

        recruit=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout

        shroud=yes
        fog=no
    [/side]

    # Orcish leaders

    # The front line leader is a goblin who recruits goblins and orcs,
    # more scouts/weaker units than the other orcs.
    # He is also more aggressive.
    [side]
        side=2
        description=Panok
        user_description= _ "Panok"
#ifdef HARD
        type=Direwolf Rider
#else
        type=Goblin Knight
#endif
        canrecruit=yes

        {INCOME 3 5 7}
        {GOLD 75 100 125}
        controller=ai
        shroud=no
        fog=no
        team_name=evil

#ifdef EASY
        recruit=Orcish Grunt, Wolf Rider, Goblin Spearman, Orcish Archer
#endif

#ifdef NORMAL
        recruit=Orcish Grunt, Wolf Rider, Goblin Impaler, Orcish Archer, Goblin Knight
#endif

#ifdef HARD
        recruit=Orcish Warrior, Wolf Rider, Goblin Impaler, Orcish Crossbowman, Goblin Knight
#endif

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

        [ai]
            #orc leader guarding front lines is more aggressive
            aggression=0.8
            caution=0.1

#ifdef EASY
            recruitment_pattern=scout,scout,fighter,fighter,archer
#endif

#ifdef NORMAL
            recruitment_pattern=scout,scout,fighter,fighter,fighter
#endif

#ifdef HARD
            recruitment_pattern=scout,scout,fighter,fighter,archer,fighter
#endif
        [/ai]
    [/side]

    # this orc tribe specialized in ranged combat
    [side]
        side=3
        description=Turg
        user_description= _ "Turg"
#ifdef EASY
        type=Orcish Warrior
#else
        type=Orcish Warlord
#endif
        canrecruit=yes

        {INCOME 1 3 5}
        {GOLD 75 100 125}
        controller=ai
        shroud=no
        fog=no
        team_name=evil

#ifdef EASY
        recruit=Orcish Grunt, Wolf Rider, Orcish Archer, Orcish Assassin, Orcish Crossbowman
#endif

#ifdef NORMAL
        recruit=Orcish Grunt, Wolf Rider, Orcish Archer, Orcish Crossbowman, Orcish Slayer, Orcish Warrior
#endif

#ifdef HARD
        recruit=Orcish Warrior, Wolf Rider, Orcish Crossbowman, Orcish Slayer
#endif

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

        [ai]
            aggression=0.5
            recruitment_pattern=scout,fighter,archer,fighter,archer

#ifdef EASY
            recruitment_pattern=scout,fighter,archer,fighter,fighter
#endif

#ifdef NORMAL
            recruitment_pattern=scout,fighter,archer,fighter,archer
#endif

#ifdef HARD
            recruitment_pattern=scout,fighter,archer,fighter,archer
#endif
        [/ai]
    [/side]

    # this orc tribe specialized in melee combat
    [side]
        side=4
        description="Ug'lok"
        user_description= _ "Ug'lok"
#ifdef EASY
        type=Orcish Warrior
#else
        type=Orcish Warlord
#endif
        canrecruit=yes
        {INCOME 1 3 5}
        {GOLD 75 100 125}
        controller=ai
        shroud=no
        fog=no
        team_name=evil

#ifdef EASY
        recruit=Orcish Grunt, Wolf Rider, Orcish Archer, Orcish Assassin, Orcish Warrior
#endif

#ifdef NORMAL
        recruit=Orcish Warrior, Wolf Rider, Orcish Archer, Orcish Slayer, Orcish Crossbowman
#endif

#ifdef HARD
        recruit=Orcish Warrior, Wolf Rider, Orcish Crossbowman, Orcish Slayer
#endif

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

        [ai]
            aggression=0.5

#ifdef EASY
            recruitment_pattern=scout,fighter,archer,fighter,archer
#endif

#ifdef NORMAL
            recruitment_pattern=scout,fighter,archer,fighter,archer
#endif

#ifdef HARD
            recruitment_pattern=scout,fighter,archer,fighter,archer
#endif
        [/ai]
    [/side]

    # assassin's side
    [side]
        side=5
        no_leader=yes
        controller=ai
        shroud=no
        fog=no
        team_name=evil

        [ai]
            aggression=1.0
            caution=0.0
            [target]
                description=Kaleh
                value=1000
            [/target]
        [/ai]
    [/side]

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

    # Prestart functions:
    # set starting scenario objectives
    # increase cost of recruiting units
    # recall main heroes
    # initialize starting variables
    # added extra NW bridge in EASY
    # randomly close one of the two exit tunnels at north of map
    # if EASY open up NW cave entrance bottleneck
    # give side 3 (green) control of cave villages?
    # place features on map
    # increase speed of goblin knight Panok

    [event]
        name=prestart

        # test units
        #{UNIT_ (Troll2) (Kaleh) ( _ "Kaleh") 1 7 2}

        # set starting scenario objectives

        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Kaleh Must Reach the Exit Tunnel at the North Edge of the Map"
                condition=win
            [/objective]

            [objective]
                description= _ "Death of Kaleh, Nym or Zhul"
                condition=lose
            [/objective]
        [/objectives]

        # the variable scen3 is based on how many encampments
        # were saved in scenario 3.
        # if scen3 = 2 then raise cost of units by 1,
        # else if scen3 = 3 then raise cost of units by 2
        [if]
            [variable]
                name=scen3
                numerical_equals=2
            [/variable]

            [then]
                #go from 1 to 2

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

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

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

                    [then]
                        #go from 1 to 3

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

                        [allow_recruit]
                            type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                            side=1
                        [/allow_recruit]
                    [/then]
                [/if]
            [/else]
        [/if]

        #recall heroes
        [recall]
            description=Nym
        [/recall]
        [recall]
            description=Zhul
        [/recall]
        [recall]
            description=Elyssa
        [/recall]

        #initialize variables
        [set_variable]
            name=entered_hills
            value=0
        [/set_variable]

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

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

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

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

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

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

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

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

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

        # added extra NW bridge in EASY
        [terrain]
            x=7
            y=14
            terrain=Ww^Bw|
        [/terrain]

        [terrain]
            x=8
            y=13
            terrain=Uu
        [/terrain]

        # in NORMAL and HARD tighten NW cave midsection
#ifdef EASY
#else
        [terrain]
            x=8
            y=19
            terrain=Xu
        [/terrain]
#endif

        #in HARD create bottleneck in entrance to NE cave
#ifdef HARD
        [terrain]
            x=31
            y=15
            terrain=Xu
        [/terrain]
#endif

        #close one of the two northern tunnels
        {RANDOM 1..10}

        [if]
            [variable]
                name=random
                less_than_equal_to=5
            [/variable]
            [then]
                #Eastern tunnel
                #to cavewall: 10,4

                [terrain]
                    x=10
                    y=4
                    terrain=Xu
                [/terrain]
            [/then]

            [else]
                #Western tunnel
                #to cavewall: 25,4 25,6 26,6 also 26,5 24,4
                #to shallow water 25,5

                [terrain]
                    x=24,25,25,26,26
                    y=4,4,6,5,6
                    terrain=Xu
                [/terrain]

                [terrain]
                    x=25
                    y=5
                    terrain=Ww
                [/terrain]
            [/else]
        [/if]

        #on EASY difficulty, further weaken orcs by deleting 2 more towns

#ifdef EASY

        [terrain]
            x=4
            y=19
            terrain=Uu
        [/terrain]

        [terrain]
            x=23
            y=11
            terrain=Uu
        [/terrain]

#endif

        # green (side 4) should control southern 4 cave villages at start
        # 2,15 4,19 6,17 9,16
        [capture_village]
            side=3
            x,y=2,15
        [/capture_village]
        [capture_village]
            side=3
            x,y=4,19
        [/capture_village]
        [capture_village]
            side=3
            x,y=6,17
        [/capture_village]
        [capture_village]
            side=3
            x,y=9,16
        [/capture_village]

        #side 1 (player) controls two villages at start
        [capture_village]
            side=1
            x,y=33,39
        [/capture_village]
        [capture_village]
            side=1
            x,y=39,38
        [/capture_village]

        {PLACE_IMAGE items/orcish-flag.png 36 33}
        {PLACE_IMAGE items/orcish-flag2.png 30 33}
        {PLACE_IMAGE items/orcish-flag.png 30 37}

        {PLACE_IMAGE items/orcish-flag2.png 31 16}
        {PLACE_IMAGE items/orcish-flag2.png 33 16}
        {PLACE_IMAGE items/orcish-flag.png 10 25}
        {PLACE_IMAGE items/orcish-flag.png 11 24}

        {PLACE_IMAGE scenery/signpost.png 7 1}

        #increase max moves by 1
        [object]
            id=FastGoblinKnight
            silent=yes

            [effect]
                apply_to=movement
                increase=1
            [/effect]

            [filter]
                description=Panok
            [/filter]
        [/object]

        #then increase current moves for this turn by 1 to match max
        [store_unit]
            [filter]
                description=Panok
            [/filter]
            variable=goblinstats
        [/store_unit]

        [set_variable]
            name=goblinstats.moves
            add=1
        [/set_variable]

        [unstore_unit]
            variable=goblinstats
        [/unstore_unit]
    [/event]

    # starting dialogue
    [event]
        name=start

        [message]
            description=Nym
            message= _ "Those mountains are huge! I never thought they would be so big. And what's that white stuff on the tops of the peaks?"
        [/message]

        [message]
            description=Zhul
            message= _ "I wish Garak were here, he'd know more about these lands than I do. I've never been up here, but I heard stories from the few who have made the journey and returned. That white stuff is called snow, Nym, and the mountains are very cold. These smaller hills aren't as hard to cross, but they are filled with orcs and goblins. It may look peaceful now, but they hide in the many caves and tunnels beneath the surface."
        [/message]

        [message]
            description=Kaleh
            message= _ "I had another vision last night, Eloh told me that we had to continue north, but instead of trying to go over the mountains, she said that we had to go underneath them."
        [/message]

        [message]
            description=Nym
            message= _ "Underneath them? But how?"
        [/message]

        [message]
            description=Zhul
            message= _ "Orcs and Goblins have been living here for hundreds of years and their network of tunnels and caves is more extensive than you might think. Who knows how far they go underground? We are ill-prepared for trekking over those frozen peaks. As much as I dislike those pitch-black caves, if we want to cross these mountains we may have no choice."
        [/message]

        [message]
            description=Elyssa
            message= _ "Other creatures besides orcs dig tunnels in the earth. Long ago dwarves mined mountains such as these, and huge trolls like to hide in the deep dark places under the earth. If your god is as omniscient as you seem to think, Kaleh, I wouldn't be surprised if there were a way to cross under these mountains. I fear no darkness, and you won't be lacking a source of fire or light."
        [/message]

        [message]
            description=Nym
            message= _ "Well if we are going to go under these mountains, we're certainly going to have our hands full fighting all those orcs and goblins."
        [/message]

        [message]
            description=Zhul
            message= _ "Indeed. I want to warn you again, Kaleh, this isn't the desert. The orcs love fighting in hills and caves, and we won't have the advantages of fighting on the open sands. And with our recent losses we don't have the numerical advantage we are used to. So we'd best be extra careful. Still if we can clear a path in the hills ahead of us, we should be able to escort our people into the tunnels. And hopefully underground it will be easier to protect them than out in the open."
        [/message]

        [message]
            description=Kaleh
            message= _ "Strike hard and fast and also be careful--right, this is going to be fun."
        [/message]
    [/event]

    # underground area should always have "underground" time,
    # I use rectangles to cover most of the area
    # rect 1 x 1-40 y 1-15
    [time_area]
        x=1-40
        y=1-15
        {UNDERGROUND}
    [/time_area]

    # betweem rect1 and rect2
    # 26,15 26,14 27,15 27,14 28,14 29,14
    [time_area]
        x=26,26,27,27,28,29
        y=17,16,15,14,14,14
        {UNDERGROUND}
    [/time_area]

    # rect 2 x 1-25 y 1-17
    [time_area]
        x=1-25
        y=1-17
        {UNDERGROUND}
    [/time_area]

    # rect 3 x 1-23 y 1-18
    [time_area]
        x=1-23
        y=1-18
        {UNDERGROUND}
    [/time_area]

    # betweem rect3 and rect4
    # 11: 22,21,20,19 12: 21,20,19 13: 21,20,19 14: 20,19 15: 20,19 16:19 17:19
    [time_area]
        x=11,11,11,11,12,12,12,13,13,13,14,14,15,15,16,17
        y=22,21,20,19,21,20,19,21,20,19,20,19,20,19,19,19
        {UNDERGROUND}
    [/time_area]

    # rect 4 x 1-10 y 1-22
    [time_area]
        x=1-10
        y=1-22
        {UNDERGROUND}
    [/time_area]

    # rect 5 x 1-9 y 1-26
    [time_area]
        x=1-9
        y=1-26
        {UNDERGROUND}
    [/time_area]

    # rect 6 x 1-7 y 1-29 (8,28 8,27)
    [time_area]
        x=1-7
        y=1-29
        {UNDERGROUND}
    [/time_area]

    # rect 7 x 1-5 y 1-32  (6,31 6,30)
    [time_area]
        x=1-5
        y=1-32
        {UNDERGROUND}
    [/time_area]

    # rect 8 x 1-4 y 1-34
    [time_area]
        x=1-4
        y=1-34
        {UNDERGROUND}
    [/time_area]

    # rect 9 x 1-3 y 1-37
    [time_area]
        x=1-3
        y=1-37
        {UNDERGROUND}
    [/time_area]

    # rect 10 x 1-2 y 1-40
    [time_area]
        x=1-2
        y=1-40
        {UNDERGROUND}
    [/time_area]

    # extra hexes in SW corner
    [time_area]
        x=8,8,6,6
        y=28,27,31,30
        {UNDERGROUND}
    [/time_area]

    # Event 1: goblins appear in nearby foothills

    # ambushes player at start of player's turn after player invades hills
    # in EASY there aren't enough goblins, they just flee

    # first rectangle x 30-40 y 28-35

    [event]
        name=moveto

        [filter]
            x=30-40
            y=28-35
            side=1
        [/filter]

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

            [then]
                [set_variable]
                    name=entered_hills
                    value=1
                [/set_variable]
            [/then]
        [/if]
    [/event]

    # second rectangle x 23-31 y 30-40

    [event]
        name=moveto

        [filter]
            x=23-31
            y=30-40
            side=1
        [/filter]

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

            [then]
                [set_variable]
                    name=entered_hills
                    value=1
                [/set_variable]
            [/then]
        [/if]
    [/event]

    # at end of player's turn, check to see if he has entered hills,
    # if so, erase flag and create goblins
    [event]
        name=side turn
        first_time_only=no

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

            [variable]
                name=side_number
                numerical_equals=1
            [/variable]

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

                #If Easy: 5 goblins

                {UNIT_ (Goblin Spearman) (Goblin Coward) ( _ "Goblin Coward") 2 28 37}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 29 33}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 38 31}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 37 34}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 30 38}

#ifdef EASY

#else

                #If Medium: +2 goblins (5)

                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 26 35}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 33 32}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 27 32}

                #If Hard: +2 goblins (7)
#ifdef HARD

                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 29 36}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 33 34}
                {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 31 31}

#endif

#endif
                # wmllint: recognize Goblin Scout
                # wmllint: recognize Goblin Coward

                [message]
                    description=Goblin Scout
                    message= _ "Attack!"
                [/message]

                # change message to unit named "Goblin Coward"
                [message]
                    description=Goblin Coward
                    message= _ "Run away!"
                [/message]

                [message]
                    description=Zhul
                    message= _ "Goblins are so predictable."
                [/message]
            [/then]
        [/if]
    [/event]

    # Event 2: naga appear around western guardpost

    # when player approches western guardpost have a few goblins jump out of
    # the eastern hills, and a naga or two appear in the lake

    # Easy:
    # 1 orcish assassin 23,33
    # 3 naga fighters: 20,34 19,33 20,35
    # 2 goblins spearmen: 23,32 24,32 24,33

    # Medium: 1 orcish slayer, 3 goblin impalers, 1 naga warrior, 2 naga fighters
    # Hard: 1 orcish slayer, 3 goblin impalers, 3 naga warriors

#define NAGA_ATTACK

    #1 orcish assassin/slayer leads the goblins

#ifdef EASY
    {UNIT_ (Orcish Assassin) (Orac) ( _ "Orac") 2 24 32}
#else
    {UNIT_ (Orcish Slayer) (Orac) ( _ "Orac") 2 24 32}
#endif
    # wmllint: recognize Orac

    #2 two goblins back him up

#ifdef EASY
    {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 24 31}
    {UNIT_ (Goblin Spearman) (Goblin Scout) ( _ "Goblin Scout") 2 25 33}
#else
    {UNIT_ (Goblin Impaler) (Goblin Scout) ( _ "Goblin Scout") 2 24 31}
    {UNIT_ (Goblin Impaler) (Goblin Scout) ( _ "Goblin Scout") 2 25 33}
#endif

    #3 nagas appear at edge of lake

#ifdef EASY
    {UNIT_ (Naga Fighter) (Scylla) ( _ "Scylla") 2 20 34}
#else
    {UNIT_ (Naga Warrior) (Scylla) ( _ "Scylla") 2 20 34}
#endif
    # wmllint: recognize Scylla
    #hack to make Scylla female
    [+unit]
        gender=female
    [/unit]

#ifdef HARD
    {UNIT_ (Naga Warrior) (Lake Naga) ( _ "Lake Naga") 2 19 34}
#else
    {UNIT_ (Naga Fighter) (Lake Naga) ( _ "Lake Naga") 2 19 34}
#endif

#ifdef HARD
    {UNIT_ (Naga Warrior) (Lake Naga) ( _ "Lake Naga") 2 20 35}
#else
    {UNIT_ (Naga Fighter) (Lake Naga) ( _ "Lake Naga") 2 20 35}
#endif

#enddef

    [event]
        name=moveto

        [filter]
            x=17-24
            y=29-36
            side=1
        [/filter]

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

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

                {NAGA_ATTACK}

                [message]
                    description=Orac
                    message= _ "Come forth, creatures of the lake! Fulfill the oaths you have made and help us drive these hated creatures from our lands."
                [/message]

                [message]
                    description=Scylla
                    message= _ "Sssslay them all! In the name of the ssscaled one!"
                [/message]
            [/then]
            [else]
                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

    #Event 3: The Goblin and The Ring (and maybe the Naga)

    # When the elves see Panok they notice how fast he is
    [event]
        name=sighted

        [filter]
            side=1
        [/filter]

        [filter_second]
            description=Panok
        [/filter_second]

        [message]
            description=Panok
            message= _ "These elves are stronger than we thought. Send for more reinforcements!"
        [/message]

        [message]
            description=Kaleh
            message= _ "How can he move that fast? He is faster than any goblin rider I have ever seen. It's almost unnatural."
        [/message]
    [/event]

    # When Panok dies player gets ring and naga ambush is triggered if it
    # hasn't been already
    [event]
        name=die

        [filter]
            description=Panok
        [/filter]

        [message]
            description=Panok
            message= _ "Gaagghhh!!!"
        [/message]

        [kill]
            description=Panok
            animate=yes
        [/kill]

        {PLACE_IMAGE items/ring-silver.png $x1 $y1}

        [set_variable]
            name=ring_x
            value=$x1
        [/set_variable]

        [set_variable]
            name=ring_y
            value=$y1
        [/set_variable]

        {CHECK_SPEAKER}
        [message]
            description=$speaking_unit.description
            message= _ "Wait a minute. He was wearing a silver ring on one of his fingers. I think the ring might be magical. Maybe that's why he was moving so fast."
        [/message]
        {CLEAR_VARIABLE speaking_unit}

        [message]
            speaker=Nym
            message= _ "I think, Kaleh, that you should take the ring."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Why me?"
        [/message]

        [message]
            speaker=Nym
            message= _ "Because you tend to move slowly and if we're going into the caves you'll need all the speed you can get. And besides, we can't afford to lose you; you never know when being able to run a bit faster might be the difference between life and death."
        [/message]

        #when Panok dies, if player hasn't triggered naga ambush, then units attack

        #but to avoid overwhelming the party, only Orac and the Naga attack, not the goblins

#ifdef NORMAL

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

            [then]
                {UNIT_ (Orcish Slayer) (Orac) ( _ "Orac") 2 24 32}

                {UNIT_ (Naga Fighter) (Lake Naga) ( _ "Lake Naga") 2 19 34}
                {UNIT_ (Naga Fighter) (Lake Naga) ( _ "Lake Naga") 2 20 35}
                {UNIT_ (Naga Warrior) (Scylla) ( _ "Scylla") 2 20 34}
                #hack to make Scylla female
                [+unit]
                    gender=female
                [/unit]

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

                [message]
                    description=Orac
                    message= _ "The elves have killed Panok the goblin! The other goblins may flee to the caves, but we will not give up these hills without a fight. Come forth, creatures of the lake! Fulfill the oaths you have made and help us drive these hated creatures from our lands."
                [/message]

                [message]
                    description=Scylla
                    message= _ "Sssslay them all! In the name of the ssscaled one!"
                [/message]
            [/then]

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

#endif

#ifdef HARD

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

            [then]
                {UNIT_ (Orcish Slayer) (Orac) ( _ "Orac") 2 24 32}

                {UNIT_ (Naga Warrior) (Lake Naga) ( _ "Lake Naga") 2 19 34}
                {UNIT_ (Naga Warrior) (Lake Naga) ( _ "Lake Naga") 2 20 35}
                {UNIT_ (Naga Warrior) (Scylla) ( _ "Scylla") 2 20 34}
                #hack to make Scylla female
                [+unit]
                    gender=female
                [/unit]

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

                [message]
                    description=Orac
                    message= _ "The elves have killed Panok the goblin! The other goblins may flee to the caves, but we will not give up these hills without a fight. Come forth, creatures of the lake! Fulfill the oaths you have made and help us drive these hated creatures from our lands."
                [/message]

                [message]
                    description=Scylla
                    message= _ "Sssslay them all! In the name of the ssscaled one!"
                [/message]
            [/then]

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

#endif
    [/event]

    # Get Ring event

    [event]
        name=moveto

        [filter]
            x=$ring_x
            y=$ring_y
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [object]
            id=SpeedyRing
            name= _ "Ring of Speed"
            image=items/ring-gold.png
            description= _ "This ring will increase your maximum speed by 1."
            [filter]
                x=$ring_x
                y=$ring_y
                side=1
            [/filter]

            [effect]
                apply_to=movement
                increase=1
            [/effect]
        [/object]

        [removeitem]
            x=$ring_x
            y=$ring_y
        [/removeitem]
    [/event]

    # Event 4: elvish unit afraid when entering underground tunnels

    #x=29-33, 6-9
    #y=9-12, 20-24

#define UNDERGROUND_MACRO

    [allow_undo]
    [/allow_undo]

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

    {CHECK_EXPLORER}
    [message]
        description=$explorer.description
        message= _ "Ugh! These tunnels are pitch black! It's as bad as fighting in a moonless night, and it stinks of orc filth. I can hardly think of a place I would less like to go into."
    [/message]
    {CLEAR_VARIABLE explorer}

    [message]
        speaker=Kaleh
        message= _ "We have no choice. We cannot cross over these mountains, so we must go beneath them. If the orcs skulk in their tunnels and block our way, we must enter their dark places and fight them, no matter what the conditions."
    [/message]

    [message]
        speaker=Zhul
        message= _ "Remember, Kaleh, it's nasty fighting underground. Marksmen and Sharpshooters who can shoot well anywhere will be invaluable, as will Captains and Marshals who can inspire our people."
    [/message]

    [message]
        speaker=Elyssa
        message= _ "Also, any time you find a particularly tough orc blocking a passage, my fireballs can blast him quick enough."
    [/message]

#enddef

    [event]
        name=moveto

        [filter]
            x=29-33
            y=9-15
            side=1
        [/filter]

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

            [then]
                {UNDERGROUND_MACRO}
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto

        [filter]
            x=6-9
            y=18-24
            side=1
        [/filter]

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

            [then]
                {UNDERGROUND_MACRO}
            [/then]
        [/if]
    [/event]

    # Event 5: Orc guard a chest in NW corner of map

    [event]
        name=moveto

        [filter]
            x=31-37
            y=6-9
            side=1
        [/filter]

        {UNIT_ (Goblin Impaler) (Greebo) ( _ "Greebo") 4 35 7}
        # wmllint: recognize Greebo

        {PLACE_IMAGE items/chest-plain-closed.png 35 6}

        [message]
            description=Greebo
            message= _ "Greebo keeps shinies safe from nasty orcses. And 'specially stinking elves."
        [/message]
    [/event]

    # Chest contains gold for player

    [event]
        name=moveto

        [filter]
            x=35
            y=6
            side=1
        [/filter]

        {PLACE_IMAGE items/chest-plain-open.png 35 6}

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

        {CHECK_EXPLORER}
        [message]
            description=$explorer.description
            message= _ "Looks like he's been squirreling away his stolen loot in this cave. Not that he had much. Must be hard times."
        [/message]
        {CLEAR_VARIABLE explorer}

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

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

#ifdef HARD
        [gold]
            amount=40
            side=1
        [/gold]
#endif
    [/event]

    #Event 6: Cold dagger

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x=12
            y=16
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

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

            [then]
                [message]
                    speaker=unit
                    message= _ "How odd. Someone has carved a crude fountain out of the stone at the end of the passage. The freezing water pours out into a large pool. At the bottom of the pool I can see a skeleton still gripping a sword. The blade seems to glow faintly blue. The pool isn't very deep, I could easily wade in and pick it up. But someone else has carved a crude message in the wall. 'If you dare to take this blade here, your greatest fear will surely appear' It looks like a nice sword, but do I dare chance it?"
                    [option]
                        message= _ "I fear no creature, I will take the blade!"
                        [command]
                            [set_variable]
                                name=took_dagger
                                value=1
                            [/set_variable]
                        [/command]
                        [command]
                            [message]
                                speaker=unit
                                message= _ "The blade is chill to the touch and gives off a cold glow. I wonder how it came to be here."
                            [/message]
                        [/command]

                        [command]
                            [object]
                                [filter]
                                    x=12
                                    y=16
                                    side=1
                                [/filter]

                                id=ColdBlade
                                name= _ "Cold Blade"
                                description= _ "The unit who wields this blade will deal cold damage with its melee attack."

                                [effect]
                                    apply_to=attack
                                    range=melee
                                    set_type=cold
                                [/effect]
                            [/object]
                        [/command]

                        [command]
                            {UNIT_ (Darawf) (Purple Abomination) ( _ "Purple Abomination") 3 14 15}
                            # wmllint: recognize Purple Abomination
                        [/command]

                        [command]
                            [message]
                                description=Purple Abomination
                                message= _ "I am an abomination, please kill me."
                            [/message]
                        [/command]

                        [command]
                            [message]
                                speaker=unit
                                message= _ "I've seen some ugly creatures in my day, but that thing is just wrong."
                            [/message]
                        [/command]

                        [command]
                            [message]
                                description=Purple Abomination
                                message= _ "The voices say I have no choice, I must attack!"
                            [/message]
                        [/command]
                    [/option]

                    [option]
                        message= _ "I don't like the sound of this. I'm out of here."
                    [/option]
                [/message]
            [/then]
        [/if]
    [/event]

    #Event 7: End of the River

    [event]
        name=moveto

        [filter]
            x=3
            y=10
            side=1
        [/filter]

        [allow_undo]
        [/allow_undo]

        {CHECK_EXPLORER}
        [message]
            description=$explorer.description
            message= _ "This is the end of the line. The water is too deep for me to continue any further. I'm freezing cold, wet, and I can't see a thing. I'm not exactly sure what I'm doing up here. Some strange influence made me want to come up here, but I don't know what made me think it could be of any good."
        [/message]
        {CLEAR_VARIABLE explorer}
    [/event]

    # Event 8: Enter the Assassin/Cloaked Figure (same guy, two names)

    # When the player enters one of the caves, the cloaked figure pops up
    # and attacks in a dramatic manner

    # This special macro places the cloaked figure and does the dialogue
    # once I have found a hex with no cave wall or other obstruction

#define ASSASSIN_MACRO X Y

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

    [store_locations]
        x={X}
        y={Y}
        [filter]
            [not]
                side=1
            [/not]
        [/filter]
        variable=temp
    [/store_locations]

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

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

    [store_locations]
        x={X}
        y={Y}
        [filter]
            side=1
        [/filter]
        variable=temp
    [/store_locations]

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

    # if we found a ally or enemy in target hex,
    # then store and kill it

    [if]
        [variable]
            name=enemy_in_hex
            numerical_equals=1
        [/variable]
        [or]
            [variable]
                name=ally_in_hex
                numerical_equals=1
            [/variable]
        [/or]

        [then]
            # kill/store occupant if there is one

            [store_unit]
                [filter]
                    x={X}
                    y={Y}
                [/filter]
                variable=unit_var
            [/store_unit]

            [kill]
                x,y={X},{Y}
                animate=no
                fire_event=no
            [/kill]
        [/then]
    [/if]

    [unit]
        type=Dark Assassin1
        description=Cloaked Figure
        user_description= _ "Cloaked Figure"
        side=5
        x={X}
        y={Y}
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
    [/unit]

    [delay]
        time=200
    [/delay]

    [message]
        description=Cloaked Figure
        image=portraits/cloaked.png
        message= _ "Kaleh, I am death incarnate."
    [/message]

    [message]
        description=Cloaked Figure
        image=portraits/cloaked.png
        message= _ "And I shall avenge all those you have killed!"
    [/message]

#enddef

    # When Kaleh enters either the left or right hand cave, trigger
    # call_assassin variable, which makes the cloaked figure appear
    # the next turn

    # left hand cave trigger
    [event]
        name=moveto
        first_time_only=no

        [filter]
            description=Kaleh
            x=5-9
            y=16-20
            side=1
        [/filter]

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

    # right hand cave trigger
    [event]
        name=moveto
        first_time_only=no

        [filter]
            description=Kaleh
            x=29-36
            y=5-13
            side=1
        [/filter]

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

    # Every turn check to see if the call_assassin flag was fired
    # When it does, find the location of Kaleh and then find an adjacent
    # hex the cloaked figure can pop up in. (any hex with a cave floor)
    # (if a unit is there, then the cloaked figure just replaces it, and
    # the unit reappears after the cloaked figure dies)

    [event]
        name=new turn
        first_time_only=no

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

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

                # find location of Kaleh

                [store_locations]
                    [filter]
                        description=Kaleh
                    [/filter]
                    variable=kaleh_loc
                [/store_locations]

                [set_variable]
                    name=kaleh_x
                    to_variable=kaleh_loc[0].x
                [/set_variable]

                [set_variable]
                    name=kaleh_y
                    to_variable=kaleh_loc[0].y
                [/set_variable]

                {CLEAR_VARIABLE kaleh_loc}

                # find adjacent hex that is cave floor or dirt or rocky cave or mushrooms
                # test these hexes
                # when you find a hex that is valid, create cloaked figure there

                # x+0 y+1

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x+1 y+0
                [if]
                    [variable]
                        name=found_empty_hex
                        numerical_equals=0
                    [/variable]

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x+0 y-1

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x-1 y+0

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x+1 y+1

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x+1 y-1

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x-1 y+1

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]

                # x-1 y-1

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

                    [then]
                        [set_variable]
                            name=temp_x
                            value=$kaleh_x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            value=$kaleh_y
                        [/set_variable]

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

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

                        [store_locations]
                            x=$temp_x
                            y=$temp_y
                            terrain=Uu, Re, Uu^Vu, Uh, Uu^Uf
                            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]
                                {ASSASSIN_MACRO $temp_x $temp_y}
                            [/then]
                        [/if]
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]

    # Death event for dark assassin
    # When assassin dies, return original occupant of hex if there was one

    [event]
        name=die

        [filter]
            description=Cloaked Figure
        [/filter]

        [message]
            description=Cloaked Figure
            message= _ "I promise we shall meet again."
        [/message]

        [kill]
            description=Cloaked Figure
            animate=no
            fire_event=no
        [/kill]

        [message]
            description=Kaleh
            message= _ "He just disappeared. That's odd."
        [/message]

        # if there was an enemy unit in space that the cloaked figure appeared in
        # then bring enemy back
        [if]
            [variable]
                name=enemy_in_hex
                numerical_equals=1
            [/variable]

            [then]
                #restore original occupant of hex

                [unstore_unit]
                    variable=unit_var
                    find_vacant=yes
                [/unstore_unit]

                [redraw]
                [/redraw]

                [message]
                    description=$unit_var.description
                    message= _ "Huh? What happened? Must have been another stupid elf trick! Well it won't stop me from killing you!"
                [/message]
            [/then]
        [/if]

        #if there was a friendly unit in space that the cloaked figure appeared in
        [if]
            [variable]
                name=ally_in_hex
                numerical_equals=1
            [/variable]

            [then]
                #restore original occupant of hex

                [unstore_unit]
                    variable=unit_var
                    find_vacant=yes
                [/unstore_unit]

                [redraw]
                [/redraw]

                [message]
                    description=$unit_var.description
                    message= _ "What happened? Where am I?"
                [/message]

                [message]
                    description=Kaleh
                    message= _ "Where did you go?"
                [/message]

                [message]
                    description=$unit_var.description
                    message= _ "I don't know, someone just knocked me out. I didn't get a good look at them."
                [/message]
            [/then]
        [/if]

        # for some reason right after the cloaked figure dies and
        # a hero reappears, the hero's death event is called, even though it
        # didn't die. This variable is used to make sure that if the
        # death event is accidentally called, then it does nothing.
        # (and doesn't end the scenario)

        [set_variable]
            name=temp
            value=$unit_var.description
        [/set_variable]

        [if]
            [variable]
                name=temp
                equals=Nym
            [/variable]

            [or]
                [variable]
                    name=temp
                    equals=Zhul
                [/variable]
            [/or]

            [or]
                [variable]
                    name=temp
                    equals=Elyssa
                [/variable]
            [/or]

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

        {CLEAR_VARIABLE unit_var}
    [/event]

    # if Nym causes the immortal_hero variable to be set to 1, her death event
    # should reset it back to 0. But just in case it doesn't, this event
    # resets the variable at the start of the next turn

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [set_variable]
                    name=immortal_hero
                    value=0
                [/set_variable]
            [/then]
        [/if]
    [/event]

    #Event 10: victory if Kaleh moves to north edge of map

    [event]
        name=moveto

        [filter]
            y=1-2
            side=1
            description=Kaleh
        [/filter]

        [endlevel]
            result=victory
            bonus=yes
        [/endlevel]
    [/event]

    #victory event
    [event]
        name=victory

        [message]
            description=Kaleh
            message= _ "This passage seems different from the other tunnels and caves. It is wide and smooth and leads sharply downwards. I bet this was the way that Eloh was talking about."
        [/message]

        [message]
            description=Elyssa
            message= _ "This is no natural passage, and the walls are too well carved and smooth to be made by orcs. I wouldn't be surprised if this was once carved out by dwarves. I wonder if there are any still left in these mountains..."
        [/message]

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

            [then]
                [message]
                    description=Zhul
                    message= _ "Having killed all the orc and goblin leaders in the immediate vicinity, we can take our time and should have no trouble bringing the rest of our people down this way. It's odd, I guess we're trading the dangers we know for the dangers we don't. We really are putting our lives in Eloh's palm; may she guide us as well as she has before."
                [/message]
            [/then]

            [else]
                [message]
                    description=Zhul
                    message= _ "Now that you've found the way we should be able to get the rest of our people past the orcs. It's odd, I guess we're trading the dangers we know for the dangers we don't. We really are putting our lives in Eloh's palm, may she guide as well as she has before."
                [/message]
            [/else]
        [/if]

        [message]
            description=Nym
            message= _ "I'll just be happy when I can breathe fresh air again and see the suns and stars. Still, who knows what we'll encounter deep under the earth?"
        [/message]

        [message]
            description=Kaleh
            message= _ "Well, there's only one way to find out."
        [/message]

        {CLEAR_VARIABLE entered_hills}
        {CLEAR_VARIABLE goblinstats}
        {CLEAR_VARIABLE naga_ambush}
        {CLEAR_VARIABLE tempnaga}
        {CLEAR_VARIABLE ring_x}
        {CLEAR_VARIABLE ring_y}
        {CLEAR_VARIABLE entered_caves}
        {CLEAR_VARIABLE assassinloc}
        {CLEAR_VARIABLE loc_x}
        {CLEAR_VARIABLE loc_y}
        {CLEAR_VARIABLE took_dagger}
        {CLEAR_VARIABLE call_assassin}
        {CLEAR_VARIABLE assassin_appeared}

        {CLEAR_VARIABLE immortal_hero}
        {CLEAR_VARIABLE unit_in_hex}
    [/event]

    # if player runs out of time, display time over message
    [event]
        name=time over
        [message]
            description=Kaleh
            message= _ "We've taken too long to get our people into the tunnels! Even more orcs are coming across the foothills from the east and west and flanking us. There's no way we can kill all these orcs and goblins. We'll never make it to safety now."
        [/message]
    [/event]

    {@campaigns/Under_the_Burning_Suns/utils/kaleh-abilities.cfg}
    {@campaigns/Under_the_Burning_Suns/utils/deaths.cfg}
    {KALEH_DEATH}
    {FRIEND_DEATH}
    {ELYSSA_DEATH}

    {@campaigns/Under_the_Burning_Suns/utils/global-events.cfg}
[/scenario]
