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

[scenario]
    id=04_Descending_into_Darkness
    name= _ "Descending into Darkness"
    next_scenario=05_A_Subterranean_Struggle
    {UTBS_MAP 04_Descending_into_Darkness.map}
    victory_when_enemies_defeated=no
    #don't display snapshot of map in saved games?
    snapshot="no"

    {TWO_SUNS_DEFAULT_SCHEDULE}
    {TURNS 50 48 46}

    {INTRO_AND_SCENARIO_MUSIC "northerners.ogg" "suspense.ogg"}
    {EXTRA_SCENARIO_MUSIC "vengeful.ogg"}
    {EXTRA_SCENARIO_MUSIC "frantic.ogg"}

    {STORY_DESCENDING_INTO_DARKNESS}

    [side]
        side=1
        id=Kaleh
        type=Desert Fighter
        canrecruit=yes
        gold=200
        {INCOME 6 4 2}
        controller=human
        shroud=yes
        fog=no
        {FLAG_VARIANT long}
    [/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
        id=Panok
        name= _ "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
        user_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,archer
#endif
#ifdef HARD
            recruitment_pattern=scout,scout,fighter,fighter,archer,fighter
#endif
        [/ai]
        {FLAG_VARIANT ragged}
    [/side]

    # this orc tribe specialized in ranged combat
    [side]
        side=3
        id=Turg
        name= _ "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
        user_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,mixed fighter

#ifdef EASY
            recruitment_pattern=scout,fighter,archer,fighter,fighter,mixed fighter
#endif
        [/ai]
        {FLAG_VARIANT ragged}
    [/side]

    # this orc tribe specialized in melee combat
    [side]
        side=4
        id="Ug'lok"
        name= _ "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
        user_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
            recruitment_pattern=scout,fighter,archer,fighter,archer,mixed fighter
        [/ai]
        {FLAG_VARIANT ragged}
    [/side]

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

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

    {UTBS_INCLUDE 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
        #{NAMED_NOTRAIT_UNIT 1 (Troll2) 7 2 (Kaleh) ( _ "Kaleh")}

        # 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"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Nym"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Zhul"
                condition=lose
            [/objective]

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

        #recall heroes
        [unit]
            {NYM}
            placement=leader
        [/unit]

        [unit]
            {ZHUL}
            placement=leader
        [/unit]

        [recall]
            id=Elyssa
        [/recall]

        #initialize variables
        [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=took_dagger
            value=0
        [/set_variable]

        # added extra NW bridge in EASY
        [terrain]
            x=7
            y=14
            terrain=Wwg^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=Wwg
                [/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]
                id=Panok
            [/filter]
        [/object]

        #then increase current moves for this turn by 1 to match max
        [store_unit]
            [filter]
                id=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]
            speaker=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]
            speaker=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]
            speaker=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]
            speaker=Nym
            message= _ "Underneath them? But how?"
        [/message]

        [message]
            speaker=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]
            speaker=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]
            speaker=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]
            speaker=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]
            speaker=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,
    [time_area]
        x = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,33,34,35,36,37,38,39,40,41
        y = 0-41,0-41,0-41,0-37,0-34,0-32,0-31,0-29,0-28,0-26,0-23,0-22,0-21,0-21,0-20,0-20,0-19,0-19,0-18,0-18,0-18,0-18,0-17,0-17,0-17,0-17,0-15,0-15,0-15,0-13,14-15,0-15,0-15,0-14,0-15,0-15,0-15,0-15,0-15,0-14,0-15,0-15,0-10
        {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
    # second rectangle x 23-31 y 30-40

    [event]
        name=moveto

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

        [event]
            name=side 1 turn

            #If Easy: 5 goblins

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

#ifdef EASY

#else

            #If Medium: +2 goblins (5)

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

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

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

#endif

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

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

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

            [message]
                speaker=Zhul
                message= _ "Goblins are so predictable."
            [/message]
        [/event]
    [/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
    {NAMED_NOTRAIT_UNIT 2 (Orcish Assassin) 24 32 (Orac) ( _ "Orac")}
#else
    {NAMED_NOTRAIT_UNIT 2 (Orcish Slayer) 24 32 (Orac) ( _ "Orac")}
#endif
    # wmllint: recognize Orac

    #2 two goblins back him up

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

    #3 nagas appear at edge of lake

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

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

#ifdef HARD
    {NAMED_NOTRAIT_UNIT 2 (Naga Warrior) 20 35 () ( _ "Lake Naga")}
#else
    {NAMED_NOTRAIT_UNIT 2 (Naga Fighter) 20 35 () ( _ "Lake Naga")}
#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]
                    speaker=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]
                    speaker=Scylla
                    message= _ "Sssslay them all! In the name of the Ssscaled One!" # wmllint: no spellcheck
                [/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]
            id=Panok
        [/filter_second]

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

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

        [filter]
            id=Panok
        [/filter]

        [message]
            speaker=Panok
            message= _ "Gaaghh!!" # wmllint: no spellcheck
        [/message]

        [kill]
            id=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]
            speaker=$speaking_unit.id
            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]
                {NAMED_NOTRAIT_UNIT 2 (Orcish Slayer) 24 32 (Orac) ( _ "Orac")}

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

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

                [message]
                    speaker=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]
                    speaker=Scylla
                    message= _ "Sssslay them all! In the name of the Ssscaled One!" # wmllint: no spellcheck
                [/message]
            [/then]

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

#endif

#ifdef HARD

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

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

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

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

                [message]
                    speaker=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]
                    speaker=Scylla
                    message= _ "Sssslay them all! In the name of the Ssscaled One!" # wmllint: no spellcheck
                [/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]

        [remove_item]
            x=$ring_x
            y=$ring_y
        [/remove_item]
    [/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]
        speaker=$explorer.id
        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]

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

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

        [message]
            speaker=Greebo
            # wmllint: local spelling shinies orcses
            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]
            speaker=$explorer.id
            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. <i>“If you dare to take this blade here, your greatest fear will surely appear.”</i> 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]
                            {NAMED_NOTRAIT_UNIT 3 (Dawarf) 14 15 (Purple Abomination) ( _ "Purple Abomination")}
                            # wmllint: recognize Purple Abomination
                        [/command]

                        [command]
                            [message]
                                speaker=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]
                                speaker=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}
        [if]
            [not]
                # Dust devil is supposed to be mute.  FThis isn't like
                # the other cases, where Nym could plausibly speak the line.
                [variable]
                    name=unit.type
                    equals=Dust Devil
                [/variable]
            [/not]
            [then]
                [message]
                    speaker=$explorer.id
                    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]
            [/then]
        [/if]
        {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
    # When Kaleh enters either the left or right hand cave, trigger
    # call_assassin variable, which makes the cloaked figure appear
    # the next turn

    [event]
        name=moveto

        [filter]
            id=Kaleh

            [and]
                x=5-9
                y=16-20

                [or]
                    x=29-36
                    y=5-13
                [/or]
            [/and]
        [/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 that is not impassable)

    [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_FOR_DARK_ASSASSIN}

                [unit]
                    type=Dark Assassin1
                    id=Cloaked Figure
                    name= _ "Cloaked Figure"
                    side=5
                    x,y=$dark_assassin_location.x,$dark_assassin_location.y
                    [modifications]
                        {TRAIT_INTELLIGENT}
                        {TRAIT_RESILIENT}
                    [/modifications]
                [/unit]

                [delay]
                    time=200
                [/delay]

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

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

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

    [event]
        name=last breath

        [filter]
            id=Cloaked Figure
        [/filter]

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

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

        [message]
            speaker=Kaleh
            message= _ "He just disappeared. That’s odd."
        [/message]
    [/event]

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

    [event]
        name=moveto

        [filter]
            y=1
            side=1
            id=Kaleh
        [/filter]

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

    #victory event
    [event]
        name=victory

        [message]
            speaker=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]
            speaker=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]
                    speaker=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]
                    speaker=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]
            speaker=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]
            speaker=Kaleh
            message= _ "Well, there’s only one way to find out."
        [/message]

        {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}
    [/event]

    # if player runs out of time, display time over message
    [event]
        name=time over
        [message]
            speaker=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]

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