#textdomain wesnoth-utbs
# Level 6.b: In the Domain of the Dwarves

[scenario]
    id="6b_In the Domain of the Dwarves"
    name= _ "In the Domain of the Dwarves"

    map_data="{campaigns/Under_the_Burning_Suns/maps/06b_In_the_Domain_of_the_Dwarves.map}"

    {STORY_IN_THE_DOMAIN_OF_THE_DWARVES}

    {SCENARIO_MUSIC "knolls.ogg"}

    next_scenario=7b_Talking_with_Trolls

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

    #max turns in scenario varies depending on difficulty
#ifdef EASY
    turns="62"
#endif
#ifdef NORMAL
    turns="58"
#endif
#ifdef HARD
    turns="56"
#endif

    victory_when_enemies_defeated=no

    {UNDERGROUND}

    #Side=1 elf player
    [side]
        side=1
        id=Kaleh
        type=Desert Fighter
        canrecruit=yes
        gold=200
        {INCOME 5 3 1}
        controller=human
        shroud=yes
        fog=no
        team_name=Allies
        user_team_name=_"Allies"
    [/side]

    #Side=2 dwarf 1 (guarding advance base)
    [side]
        side=2
        colour=orange
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        #so that the lake bats won't go after dwarves
        team_name=enemies
        user_team_name=_"Enemies"

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

            aggression=0.9
            caution=0.1

            #defend advance outpost, don't retreat
            [avoid]
                x,y=19-26,30-32
            [/avoid]

            [avoid]
                x,y=16-18,33-35
            [/avoid]
        [/ai]
    [/side]

    #Side=3 troll 3 (troll allies)
    [side]
        side=3
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=Allies
        user_team_name=_"Allies"
    [/side]

    #Side=4 empty side
    [side]
        side=4
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
    [/side]

    #Side=5 empty side
    [side]
        side=5
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
    [/side]

    #Side=6 dwarf 2 (main base guards)
    [side]
        side=6
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        #so that lake bats won't go after dwarves
        team_name=enemies
        user_team_name=_"Enemies"

#ifdef EASY
        recruit=Dwarvish Fighter, Dwarvish Steelclad, Dwarvish Thunderer, Dwarvish Berserker, Dwarvish Thunderguard, Dwarvish Guardsman, Dwarvish Pathfinder
#endif

#ifdef NORMAL
        recruit=Dwarvish Fighter, Dwarvish Steelclad, Dwarvish Thunderer, Dwarvish Berserker, Dwarvish Thunderguard, Dwarvish Guardsman, Dwarvish Pathfinder, Dwarvish Explorer

#endif

#ifdef HARD
        recruit=Dwarvish Fighter, Dwarvish Steelclad, Dwarvish Thunderer, Dwarvish Berserker, Dwarvish Thunderguard, Dwarvish Guardsman, Dwarvish Dragonguard, Dwarvish Sentinel, Dwarvish Pathfinder, Dwarvish Explorer

#endif

        [ai]
#ifdef EASY
            recruitment_pattern=scout,fighter,mixed fighter,mixed fighter,fighter
#endif

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

#ifdef HARD
            recruitment_pattern=scout,fighter,mixed fighter,mixed fighter,fighter,archer
#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}

            aggression=0.6

            # makes the dwarves group defensively
            grouping=defensive
        [/ai]
    [/side]

    #Side=7 empty side
    [side]
        side=7
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
    [/side]

    #Side=8 vampire bats (white)
    [side]
        side=8
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=enemies
        user_team_name=_"Enemies"

#ifdef EASY
        recruit=Vampire Bat, Blood Bat
#endif

#ifdef NORMAL
        recruit=Vampire Bat, Blood Bat, Dread Bat
#endif

#ifdef HARD
        recruit=Vampire Bat, Blood Bat, Dread Bat
#endif

        [ai]
            aggression=0.8
            caution=0.1

            village_value=0

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

            recruitment_pattern=scout
            recruitment_ignore_bad_combat=yes

            #bats can't go down SW tunnel
            [avoid]
                x,y=24-42, 23-50
            [/avoid]

            #bats cant go west and attack dwarves
            [avoid]
                x,y=33-35,13-15
            [/avoid]

            passive_leader=yes
        [/ai]
    [/side]

#ifdef EASY
    {LIMIT_CONTEMPORANEOUS_RECRUITS 8 "Vampire Bat" 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 8 "Blood Bat" 2}
#else
    {LIMIT_CONTEMPORANEOUS_RECRUITS 8 "Dread Bat" 2}
#endif

    #Side=9 Secrets & Tentacles (brown)
    [side]
        side=9
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=yes
        fog=no
        team_name=enemies
        user_team_name=_"Enemies"

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

            aggression=0.90
            caution=0.10
        [/ai]

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

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

    # Prestart functions:
    # set starting scenario objectives
    # increase cost of recruiting units
    # place item images on map
    # recall main heroes
    # initialize starting variables
    # remove keep
    # create elf units
    # create AI=guardian starting units

    [event]
        name=prestart

        # Test Units

        #{NAMED_NOTRAIT_UNIT 1 (Troll) 19 37 (Test) ( _ "Test")}
        #{NAMED_NOTRAIT_UNIT 1 (Troll) 21 25 (Test) ( _ "Test")}

        # tentacle secret event test
        # {NAMED_NOTRAIT_UNIT 1 (Desert Prowler) 20 13 (Test) ( _ "Test")}
        # {NAMED_NOTRAIT_UNIT 1 (Troll) 20 14 (Test) ( _ "Test")}

        #set starting scenario objectives

        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Kill Dwarf Chieftain"
                condition=win
            [/objective]

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

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

        #increase the cost of all units by 1
        [if]
            [variable]
                name=scen3
                numerical_equals=2
            [/variable]

            [then]
                #go from 3 to 4

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

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

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

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

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

                    [then]
                        #go from 2 to 3

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

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

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

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

                    [then]
                        #go from 4 to 5

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

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

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

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

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

        #secret tomb furnishings
        {PLACE_IMAGE items/rune-violet2.png 45 21}
        {PLACE_IMAGE items/coffin-closed.png 49 24}

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

        #initialize starting variables

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

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

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

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

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

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

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

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

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

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

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

        # Pre-set units

        # Event 2.1
        # Dwarvish sergeant guardian

        [unit]
            type=Dwarvish Steelclad
            id=Dwarf Sergeant
            name= _ "Dwarf Sergeant"
            x=11
            y=36
            side=2
            ai_special=guardian
            facing=nw
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        # Event 2.2
        # Vengeful Dwarf

        [unit]
            type=Dwarvish Fighter
            id=Vengeful Dwarf
            name= _ "Vengeful Dwarf"
            x=7
            y=29
            side=2
            ai_special=guardian
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        #Troll ally shaman, doesn't move
        [unit]
            type=Troll Shaman
            id=Zurg
            name= _ "Zurg"
            x=33
            y=30
            side=3
            ai_special=guardian
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        # Event 3: Tunnel cave-ins

        [unit]
            type=Dwarvish Stalwart
            id=Dwarf Scout
            name= _ "Dwarf Scout"
            x=22
            y=30
            side=6
            ai_special=guardian
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
                [object]
                    id=o1
                    silent=yes
                    [effect]
                        apply_to=movement_costs
                        replace=true
                        [movement_costs]
                            cave={UNREACHABLE}
                            grass={UNREACHABLE}
                            shallow_water={UNREACHABLE}
                        [/movement_costs]
                    [/effect]
                [/object]
            [/modifications]
        [/unit]

        [unit]
            type=Dwarvish Stalwart
            id=Dwarf Scout
            name= _ "Dwarf Scout"
            x=17
            y=31
            side=6
            ai_special=guardian
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
                [object]
                    id=o2
                    silent=yes
                    [effect]
                        apply_to=movement_costs
                        replace=true
                        [movement_costs]
                            cave={UNREACHABLE}
                            grass={UNREACHABLE}
                            shallow_water={UNREACHABLE}
                        [/movement_costs]
                    [/effect]
                [/object]
            [/modifications]
        [/unit]
    [/event]

    # starting events

    [event]
        name=start

        # starting dialogue

        [message]
            speaker=Zurg
            message= _ "This amazing tunnel, it leads very close to dwarves' main lair. You can hear their tiny footsteps just on other side of wall. All that separates us from the dwarves is a thin wall of stone. When you move a unit adjacent to the final wall, on your order Zurg will destroy it with fire magic. Dwarf chieftain is only lightly guarded, he send best warriors to hunt trolls. Heh, we give you easy task. You know dwarf chieftain when you see him, he shorter and uglier than most."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Did you dig these tunnels all by yourselves?"
        [/message]

        [message]
            speaker=Zurg
            message= _ "No, most are tiny dwarf tunnels. We like natural tunnels, big and tall enough for mighty trolls. When the world was young, Griknagh cut many tunnels and caverns into the rock far below us. We traveled deep deep down, following the trickle of ancient streams, far deeper than the puny dwarves. But now we come back up, great leader say there bad things now deep below. Bad for trolls. We come back up to reclaim ancient lands. But we find them filled with many many little stinky dwarves. All the beautiful stones are gone, greedy dwarves take them all. So we fight to reclaim our lands. But Zurg talk too much. We have job to do. Find dwarven leader and kill him and we will reward you well."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "It shall be done."
        [/message]
    [/event]

    # Event 1: Blow up wall, encounter advance dwarf guards

    # when player moves next wall trigger variable
    [event]
        name=moveto

        [filter]
            x,y=28,32
            side=1
        [/filter]

        [message]
            speaker=Zurg
            message= _ "Once you done moving into position, Zurg will destroy wall."
        [/message]

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

    # at start of player's next turn, blow charges and destroy wall

    [event]
        name=new turn
        first_time_only=no

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

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

                # Place dwarf guards

                # EASY: 1 dwarf steelclad, 2 thunderer, 3 scouts
                # NORMAL: 1 dwarf steelclad, 2 thunderguard, 3 scouts
                # HARD: 1 dwarf steelclad, 2 thunderguard, 3 pathfinders

                # 1 Dwarf Sergeant
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Fighter) 22 33 (Dwarf Sergeant) ( _ "Dwarf Sergeant")}

                # 2 Dwarf shooters
#ifdef EASY
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Thunderer) 21 34 (Dwarf Guard) ( _ "Dwarf Guard")}
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Thunderer) 23 34 () ( _ "Dwarf Guard")}
#else
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Thunderguard) 21 34 () ( _ "Dwarf Guard")}
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Thunderguard) 23 34 () ( _ "Dwarf Guard")}
#endif

                # 3 dwarf scouts occupy base and villages

#ifdef HARD
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Pathfinder) 22 34 () ( _ "Dwarf Guard")}
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Pathfinder) 20 34 () ( _ "Dwarf Guard")}
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Pathfinder) 24 34 () ( _ "Dwarf Guard")}
#else
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Scout) 22 34 () ( _ "Dwarf Guard")}
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Scout) 20 34 () ( _ "Dwarf Guard")}
                {NAMED_NOTRAIT_UNIT 2 (Dwarvish Scout) 24 34 () ( _ "Dwarf Guard")}
#endif
                # wmllint: recognize Dwarf Guard

                # Have Zurg cast spell to destroy wall

                [message]
                    speaker=Zurg
                    message= _ "Fist and fire, crumble stone!"
                [/message]

                # Have screen flash red

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

                [redraw]
                [/redraw]

                [delay]
                    time=100
                [/delay]

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

                [redraw]
                [/redraw]

                # Have wall shake, then be replaced by dirt, then add rubble

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

                [terrain]
                    x,y=27,33
                    terrain=Re
                [/terrain]

                {PLACE_IMAGE scenery/rubble.png 27 33}

                # Reveal dwarven cavern
                [remove_shroud]
                    x=19-30
                    y=32-39
                    side=1
                [/remove_shroud]

                [redraw][/redraw]

                # Have Zurg say goodbye

                [message]
                    speaker=Zurg
                    message= _ "My work here is done. Zurg must report back to Great Leader. Many things to do and dwarves to kill before rest. Zurg return later to see how little elves are doing. Fight well!"
                [/message]

                # Have Zurg leave
                [kill]
                    id=Zurg
                    animate=no
                    fire_event=no
                [/kill]

                [move_unit_fake]
                    type=Troll Shaman
                    side=3
                    x=33,34,35,36,37,38,39
                    y=30,30,30,29,30,30,31
                [/move_unit_fake]

                [terrain]
                    x,y=45,36
                    terrain=Xu
                [/terrain]

                {PLACE_IMAGE scenery/rubble.png 44 35}

                # Have dwarf guards talk

                [message]
                    speaker=Dwarf Guard
                    message= _ "Intruders! Sound the alarm!"
                [/message]
            [/then]
        [/if]
    [/event]

    # Event 2: If player tries to go back up escape passage
    # This event is disabled becuase player can go back up escape passage
    # before he triggers Event 1 and ally leaves. Thus you could trap
    # a unit behind the cave-in. Since this event is just for flavor,
    # I'm disabling it.

    #[event]
    #name=moveto

    #[filter]
    #   x,y=42-45,33-36
    #   side=1
    #[/filter]

    #[message]
    #speaker=unit
    #message= _ "Zurg must have collapsed the tunnel. Perhaps he didn't want to give #the dwarves an easy access route if they defeated us. So much for an escape #route, I guess we'll just have to be sure not to fail."
    #[/message]

    #[/event]

    # Event 2.1 2.2: Dwarf Sergeant and his Conscripts

    # deleted text from alternate version
    # I tried to make different versions depending on if the unit is an elf
    # or a troll. But I gave up that idea. This is the deleted dialogue:

    #[message]
    #x,y=9,36
    #message= _ "No, it's an elf!"
    #[/message]

    #[message]
    #id=Dwarf Sergeant
    #message= _ "What!?!.....Right...First task boys, kill the intruder!"
    #[/message]

    # moveto version, when dwarf sees enemy (sighted version disabled)

    [event]
        name=moveto

        [filter]
            x,y=9-16,35-38
            side=1
        [/filter]

        #[filter]
        #   id=Dwarf Sergeant
        #[/filter]

        #[filter_second]
        #   side=1
        #[/filter_second]

        [remove_shroud]
            side=1
            x=8-14
            y=33-38
        [/remove_shroud]

        # if Hard, add a third Dwarf Conscript

        {NAMED_GENERIC_UNIT 2 (Dwarvish Thunderer) 9 36 (Dwarf Conscript) ( _ "Dwarf Conscript")}
        {NAMED_GENERIC_UNIT 2 (Dwarvish Scout) 10 34 () ( _ "Dwarf Conscript")}

#ifdef HARD
        {NAMED_GENERIC_UNIT 2 (Dwarvish Fighter) 9 35 () ( _ "Dwarf Conscript")}
#endif
        # wmllint: recognize Dwarf Conscript

        [message]
            speaker=Dwarf Sergeant
            message= _ "Do you know what the first task of any dwarven warrior is, runt?"
        [/message]

        [message]
            x,y=10,34
            message= _ "Sir?"
        [/message]

        [message]
            speaker=Dwarf Sergeant
            message= _ "Constant vigilance, boys; the enemy could be anywhere!"
        [/message]

        [message]
            x,y=9,36
            message= _ "But Sir..."
        [/message]

        [message]
            speaker=Dwarf Sergeant
            message= _ "Did I give you permissions to speak? Did I?"
        [/message]

        [message]
            speaker=Dwarf Sergeant
            message= _ "I was killing trolls when you were in swaddling clothes. I wrote the book on killing trolls. And you're not going anywhere until I'm done with you."
        [/message]

        [message]
            x,y=10,34
            message= _ "But Sir, behind you..."
        [/message]

        [message]
            speaker=Dwarf Sergeant
            message= _ "Oh let me guess, a big nasty troll, right? And when I turn around you flee like the cowards you are. Do you think I'm stupid enough to fall for that one?"
        [/message]

        [message]
            x,y=9,36
            message= _ "I'm too young to die, save me!"
        [/message]

        [message]
            speaker=Dwarf Sergeant
            message= _ "Oh grow a backbone...Huh? Hey, for once the runt was telling the truth. Come on boys, kill the intruder!"
        [/message]
    [/event]

    # funny death message from one of the conscripts
    [event]
        name=last breath

        [filter]
            id=Dwarf Conscript
        [/filter]

        [if]
            [have_unit]
                id=Dwarf Sergeant
            [/have_unit]

            [then]
                [message]
                    speaker=unit
                    message= _ "I love you, Sarge..."
                [/message]
            [/then]
        [/if]
    [/event]

    # Event 2.2: Wounded Troll

    # When player sees Vengeful Dwarf and troll prisoner (sighted version disabled)

    [event]
        name=moveto

        [filter]
            x,y=6-8,28-34
            side=1
        [/filter]

        [remove_shroud]
            side=1
            x=5-9
            y=27-34
        [/remove_shroud]

        [unit]
            type=Troll
            id=Grog
            name= _ "Grog"
            profile=portraits/grog.png
            x=7
            y=28
            side=3
            hitpoints=25
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=Vengeful Dwarf
            message= _ "Ha, you're trapped. I've got you right where I want you, and this time no one is gonna save you."
        [/message]

        [message]
            speaker=second_unit
            message= _ "How did a troll get stuck all the way back here?"
        [/message]
    [/event]

    # When Vengeful Dwarf dies
    [event]
        name=die

        [filter]
            id=Vengeful Dwarf
        [/filter]

        [kill]
            id=Vengeful Dwarf
            animate=no
        [/kill]

        [if]
            [have_unit]
                id=Grog
            [/have_unit]

            [then]
                [message]
                    speaker=Grog
                    message= _ "Thank you. Grog got lost and there were so many smelly dwarves. If you hadn't come Grog would have been killed. Grog owes you his life."
                [/message]

                [store_unit]
                    [filter]
                        id=Grog
                    [/filter]

                    variable=trollstats
                [/store_unit]

                [set_variable]
                    name=trollstats.side
                    value=1
                [/set_variable]

                [set_variable]
                    name=trollstats.moves
                    value=5
                [/set_variable]

                [unstore_unit]
                    variable=trollstats
                [/unstore_unit]

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

    # Event 3: Tunnel cave-ins

    # Eastern tunnel
    [event]
        name=moveto

        [filter]
            x,y=22-24,30-32
            side=1
        [/filter]

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

            [then]
                [delay]
                    time=200
                [/delay]

                [message]
                    speaker="Dwarf Scout"
                    message= _ "Here they come! Blow the charges!"
                [/message]

                [kill]
                    id="Dwarf Scout"
                    animate=no
                [/kill]

                [move_unit_fake]
                    type=Dwarvish Stalwart
                    side=6
                    x=22,21,20,20,20,19,18,18
                    y=30,30,29,28,27,27,26,25
                [/move_unit_fake]

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

                [terrain]
                    x,y=22,30
                    terrain=Xu
                [/terrain]

                {PLACE_IMAGE scenery/rubble.png 21 30}
                {PLACE_IMAGE scenery/rubble.png 23 30}

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

            [else]
                [message]
                    speaker="Dwarf Scout"
                    message= _ "They're coming this way too! Blow the charges!"
                [/message]

                [redraw]
                [/redraw]

                [delay]
                    time=1000
                [/delay]

                [message]
                    speaker="Dwarf Scout"
                    message= _ "What!?! Nothing happened! Who in Moradin's name rigged the darn charges anyway? I'm going to have to hold them off by myself. "
                [/message]
            [/else]
        [/if]
    [/event]

    # Western tunnel

    [event]
        name=moveto

        [filter]
            x,y=15-16,31-34
            side=1
        [/filter]

        [filter_second]
            x,y=17,31
        [/filter_second]

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

            [then]
                [delay]
                    time=200
                [/delay]

                [message]
                    speaker=Dwarf Scout
                    message= _ "Here they come! Blow the charges!"
                [/message]

                [kill]
                    id=Dwarf Scout
                    animate=no
                [/kill]

                [move_unit_fake]
                    type=Dwarvish Stalwart
                    side=6
                    x=17,18,18,18,18,18,18,18,17,17
                    y=31,30,29,28,27,26,25,24,24,23
                [/move_unit_fake]

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

                [terrain]
                    x,y=16,31
                    terrain=Xu
                [/terrain]

                {PLACE_IMAGE scenery/rubble.png 15 32}
                {PLACE_IMAGE scenery/rubble.png 17 31}

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

            [else]
                [message]
                    speaker="Dwarf Scout"
                    message= _ "They're coming this way too! Blow the charges!"
                [/message]

                [redraw]
                [/redraw]

                [delay]
                    time=1000
                [/delay]

                [message]
                    speaker="Dwarf Scout"
                    message= _ "What!?! Nothing happened! Who in Moradin's name rigged the darn charges anyway? I'm going to have to hold them off by myself. "
                [/message]
            [/else]
        [/if]
    [/event]

    # Event 4: Bridge/Chasm Fight

    # Dwarf guards challenge elves to stand and fight, Jorgi doesn't want
    # to have to resort to trickery

    [event]
        name=moveto

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

        [remove_shroud]
            x=16-23
            y=23-32
            side=1
        [/remove_shroud]

        {NAMED_GENERIC_UNIT 6 (Dwarvish Sentinel) 19 25 (Jorgi) ( _ "Jorgi")}
        # wmllint: recognize Jorgi

#ifdef HARD
        {NAMED_GENERIC_UNIT 6 (Dwarvish Steelclad) 18 26 () ( _ "Dwarf Guard")}
        {NAMED_GENERIC_UNIT 6 (Dwarvish Steelclad) 19 27 () ( _ "Dwarf Guard")}
        {NAMED_GENERIC_UNIT 6 (Dwarvish Steelclad) 20 26 () ( _ "Dwarf Guard")}
#else
        {NAMED_GENERIC_UNIT 6 (Dwarvish Fighter) 18 26 () ( _ "Dwarf Guard")}
        {NAMED_GENERIC_UNIT 6 (Dwarvish Fighter) 19 27 () ( _ "Dwarf Guard")}
        {NAMED_GENERIC_UNIT 6 (Dwarvish Fighter) 20 26 () ( _ "Dwarf Guard")}
#endif

        {NAMED_GENERIC_UNIT 6 (Dwarvish Pathfinder) 18 25 () ( _ "Dwarf Guard")}
        {NAMED_GENERIC_UNIT 6 (Dwarvish Pathfinder) 20 25 () ( _ "Dwarf Guard")}

#ifdef EASY
        {NAMED_GENERIC_UNIT 6 (Dwarvish Thunderguard) 19 26 () ( _ "Dwarf Guard")}
#else
        {NAMED_GENERIC_UNIT 6 (Dwarvish Dragonguard) 19 26 () ( _ "Dwarf Guard")}
#endif

        [message]
            speaker=Jorgi
            message= _ "It was a mistake to depend on trickery, we will defeat you fighting face to face. A true dwarf always looks his opponent in the eye when he kills him!"
        [/message]

        [message]
            speaker=Jorgi
            message= _ "So I challenge you, man to man. If you are not cowards, step out onto these bridges and meet your fate!"
        [/message]
    [/event]

    # defines macro to explode backup charges to destroy tunnel leading
    # directly to main dwarf base

#define BACKUP_CHARGES

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

    [terrain]
        x=12,12
        y=19,20
        terrain=Xu
    [/terrain]

    {PLACE_IMAGE scenery/rubble.png 11 19}
    {PLACE_IMAGE scenery/rubble.png 13 21}

#enddef

    # When Jorgi dies, blow charges to destroy tunnel leading to dwarf base

    [event]
        name=last breath

        [filter]
            id=Jorgi
        [/filter]

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

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

                [message]
                    speaker=Jorgi
                    message= _ "I couldn't do it. Blow the backup charges! If we can't stop them then maybe the black lake will."
                [/message]

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

    # if player crosses bridge before killing Jorgi, then blow charges
    # to destroy tunnel leading to dwarf base

    [event]
        name=moveto

        # wmllint: recognize Dwarf High Guard
        [filter]
            x=12-21
            y=19-26
            side=1
        [/filter]

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

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

                [if]
                    [have_unit]
                        id=Jorgi
                    [/have_unit]

                    [then]
                        [message]
                            speaker=Jorgi
                            message= _ "They've crossed the chasm! Blow the backup charges! If we can't stop them then maybe the black lake will."
                        [/message]
                    [/then]

                    [else]
                        [message]
                            role=Dwarf High Guard
                            message= _ "They've crossed the chasm! Blow the backup charges! If we can't stop them then maybe the black lake will."
                        [/message]
                    [/else]
                [/if]

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

    # Before you have tripped the bats event, keep them from gaining any gold
    # Before you have gotten close to dwarf lair, keep them from gaining any gold

    [event]
        name=new turn
        first_time_only=no

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

            [then]
                [modify_side]
                    side=8
                    income=0
                    gold=0
                [/modify_side]
            [/then]
        [/if]

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

            [then]
                [modify_side]
                    side=6
                    income=0
                    gold=0
                [/modify_side]
            [/then]
        [/if]
    [/event]

    # Event 5: Vampire Bats

    [event]
        name=moveto

        [filter]
            x=25-34
            y=10-22
            side=1
        [/filter]

        {CHECK_EXPLORER}
        [message]
            speaker=$explorer.id
            message= _ "It's a huge underground lake. The water looks dark and deep and is cold to the touch. There also seems to be some glowing moss on the walls which illuminates the cavern, making it easier to see."
        [/message]
        {CLEAR_VARIABLE explorer}
    [/event]

    #activate bats and create dwarvish hermit unit

    [event]
        name=moveto

        [filter]
            x=26-28
            y=15-20
            side=1
        [/filter]

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

        [unit]
            id=Extra Hairy Bat
            name= _ "Extra Hairy Bat"
            type=Dread Bat
            x=42
            y=9
            side=8
            canrecruit=yes
            upkeep=free
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        #on easy, don't allow side to recruit dread bats, but create one at start

#ifdef EASY
        [unit]
            type=Dread Bat
            side=8
            x=41
            y=10
            moves=0
        [/unit]
#endif

        [modify_side]
            side=8

#ifdef EASY
            income=8
            gold=90
#endif
#ifdef NORMAL
            income=10
            gold=110
#endif
#ifdef HARD
            income=12
            gold=130
#endif
        [/modify_side]

        [unit]
            type=Dwarvish Stalwart
            id=Dwarf Hermit
            name= _ "Dwarf Hermit"
            x=21
            y=6
            side=6
            ai_special=guardian
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [capture_village]
            x,y=22,5
            side=6
        [/capture_village]
    [/event]

    # when player sees bats

    [event]
        name=sighted

        [filter]
            type=Vampire Bat,Blood Bat,Dread Bat
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=second_unit
            message= _ "Incoming! Ugh, it's big, hairy, and nasty. I hate bats, I really hate bats."
        [/message]
    [/event]

    [event]
        name=last breath

        # wmllint: recognize Big Hairy Bat
        [filter]
            id=Big Hairy Bat
        [/filter]

        [message]
            speaker=unit
            message= _ "Grrraaawwwkkk!" # wmllint: no spellcheck
        [/message]

        {CHECK_SPEAKER}
        [message]
            speaker=$speaking_unit.id
            message= _ "Good riddance."
        [/message]
        {CLEAR_VARIABLE speaking_unit}
    [/event]

    # allow units around lake to look out over deep water
    # artificially increase sight for units walking around lake
    # TODO/FIXME: commented out because it invalidates undo on every move there.
    #    [event]
    #        name=moveto
    #        first_time_only=no
    #
    #        [filter]
    #            x=19-41
    #            y=3-22
    #            side=1
    #        [/filter]
    #
    #        [set_variable]
    #            name=x_left
    #            value=$x1
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=x_left
    #            add=-4
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=x_right
    #            value=$x1
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=x_right
    #            add=4
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=y_up
    #            value=$y1
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=y_up
    #            add=-3
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=y_down
    #            value=$y1
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=y_down
    #            add=3
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=lake_x
    #            format=$x_left-$x_right
    #        [/set_variable]
    #
    #        [set_variable]
    #            name=lake_y
    #            format=$y_up-$y_down
    #        [/set_variable]
    #
    #        [remove_shroud]
    #            x=$lake_x
    #            y=$lake_y
    #            side=1
    #        [/remove_shroud]
    #    [/event]

    # Event 6: Tentacles attack

    # (2-3 level 1 tentacles appear every turn that player
    # is in 27-30,13-16) Give warning when player reaches edge of ledge

    # tentacles appear at start of player's turn

    [event]
        name=moveto

        [filter]
            x=27
            y=17
            side=1
        [/filter]

        {CHECK_EXPLORER}

        [message]
            speaker=$explorer.id
            message= _ "The ledge just drops off here. The water might be shallow enough to wade across, but I think I vaguely see something moving underneath the surface. Maybe it's just fish, but I don't like the look of it."
        [/message]

        {CLEAR_VARIABLE explorer}
    [/event]

#define FIND_WATER_LOCATION

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

    [while]
        [variable]
            name=location_match
            numerical_equals=0
        [/variable]

        [do]
            {RANDOM 28..31}

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

            {RANDOM 13..17}

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

            [store_locations]
                x=$tempx
                y=$tempy
                terrain=Ww, Wo
                variable=locs
            [/store_locations]

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

            {CLEAR_VARIABLE locs}

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

                [then]
                    [set_variable]
                        name=location_match
                        value=1
                    [/set_variable]
                [/then]
            [/if]
        [/do]
    [/while]

#enddef

#define CREATE_TENTACLES

    {FIND_WATER_LOCATION}

    [unit]
        type=Tentacle of the Deep
        side=9
        x=$tempx
        y=$tempy
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
    [/unit]

    {FIND_WATER_LOCATION}

    [unit]
        type=Tentacle of the Deep
        side=9
        x=$tempx
        y=$tempy
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
    [/unit]

#ifdef EASY
#else

    {FIND_WATER_LOCATION}

    [unit]
        type=Tentacle of the Deep
        side=9
        x=$tempx
        y=$tempy
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
    [/unit]

#endif

#enddef

    # create a bunch of tentacles every time a side 1 unit is in area
    # do this 3 times, then stop

    [event]
        name=new turn
        first_time_only=no

        [store_locations]
            x=27-30
            y=13-17
            [filter]
                side=1
            [/filter]
            variable=lake_list
        [/store_locations]

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

        {CLEAR_VARIABLE lake_list}

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

            [then]
                [if]
                    [variable]
                        name=tentacle_count
                        less_than=3
                    [/variable]

                    [then]
                        {CREATE_TENTACLES}

                        #choose what message to say
                        [if]
                            [variable]
                                name=tentacle_count
                                numerical_equals=0
                            [/variable]

                            [then]
                                [message]
                                    x,y=24-30,12-20
                                    side=1
                                    message= _ "What are those?!?"
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    x,y=24-30,12-20
                                    side=1
                                    message= _ "Here come more of them!"
                                [/message]
                            [/else]
                        [/if]
                    [/then]
                [/if]

                #either way, whenever a unit is in the area, increase the counter
                [if]
                    [variable]
                        name=tentacle_count
                        less_than=3
                    [/variable]

                    [then]
                        [set_variable]
                            name=tentacle_count
                            add=1
                        [/set_variable]
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]

    #tentacle death counter

    [event]
        name=die
        first_time_only=no

        [filter]
            type=Tentacle of the Deep
        [/filter]

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

        [if]
#ifdef EASY
            [variable]
                name=tentacle_deaths
                numerical_equals=6
            [/variable]
#else
            [variable]
                name=tentacle_deaths
                numerical_equals=9
            [/variable]
#endif

            [then]
                [message]
                    x,y=21-30,12-19
                    side=1
                    message= _ "The movement under the water has stopped. I think we killed the last of them. Whatever 'them' was."
                [/message]

                [modify_side]
                    side=8
                    income=2
                [/modify_side]
            [/then]
        [/if]
    [/event]

    # Event 7: Trigger Dwarf Lord's side
    # (also create hermit and capture village)

    [event]
        name=moveto

        [filter]
            x=13-22
            y=11-17
            side=1
        [/filter]

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

        #create dwarf chieftain
        [unit]
            type=Dwarvish Lord
            id=Dwarf Chieftain
            name= _ "Dwarf Chieftain"
            canrecruit=yes
            x=6
            y=16
            side=6
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [modify_side]
            side=6

#ifdef EASY
            income=2
            gold=120
#endif
#ifdef NORMAL
            income=4
            gold=140
#endif
#ifdef HARD
            income=6
            gold=160
#endif
        [/modify_side]

        #create dwarven defenders:

        #on EASY difficulty, don't create Dwarvish Pathfinder

        {NAMED_GENERIC_UNIT 6 (Dwarvish Fighter) 11 10 () ( _ "Dwarf High Guard")}
        [+unit]
            role=Dwarf High Guard
        [/unit]
#ifdef EASY
#else
        {NAMED_GENERIC_UNIT 6 (Dwarvish Pathfinder) 5 13 () ( _ "Dwarf High Guard")}
        [+unit]
            role=Dwarf High Guard
        [/unit]
#endif
        {NAMED_GENERIC_UNIT 6 (Dwarvish Thunderguard) 7 15 () ( _ "Dwarf High Guard")}
        [+unit]
            role=Dwarf High Guard
        [/unit]
        {NAMED_GENERIC_UNIT 6 (Dwarvish Guardsman) 7 19 () ( _ "Dwarf High Guard")}
        [+unit]
            role=Dwarf High Guard
        [/unit]

        #capture dwarf chieftan's villages

        [capture_village]
            x,y=6,11
            side=6
        [/capture_village]
        [capture_village]
            x,y=8,14
            side=6
        [/capture_village]
        [capture_village]
            x,y=9,19
            side=6
        [/capture_village]
        [capture_village]
            x,y=14,16
            side=6
        [/capture_village]
        [capture_village]
            x,y=11,10
            side=6
        [/capture_village]
    [/event]

    # Event 8: Dwarf Lord sighted event and death event

    [event]
        name=sighted

        [filter]
            id=Dwarf Chieftain
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Dwarf Chieftain
            message= _ "So you've come at last. Let it end, here and now!"
        [/message]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Dwarf Chieftain
        [/filter]

        [message]
            speaker=Dwarf Chieftain
            message= _ "Faugh! Even in death I curse you! You will never escape these tunnels alive!"
        [/message]

        [message]
            speaker=second_unit
            message= _ "And so, at last, it ends."
        [/message]

        [message]
            side=6
            [not]
                canrecruit=yes
            [/not]
            message= _ "The chieftain has fallen! Flee for your lives!"
        [/message]

        [kill]
            side=6
            animate=no
        [/kill]

        [terrain]
            x=4,4,4,5,5,6
            y=23,22,21,21,20,19
            terrain=Uu
        [/terrain]

        [move_unit_fake]
            type=Troll Whelp
            side=2
            x=4,4,4,4,5,5,6
            y=24,23,22,21,21,20,19
        [/move_unit_fake]

        {NAMED_NOTRAIT_UNIT 2 (Troll Shaman) 6 19 (Zurg) ( _ "Zurg")}

        [remove_shroud]
            x=5-7
            y=18-20
            side=1
        [/remove_shroud]

        [redraw][/redraw]

        [delay]
            time=200
        [/delay]

        [message]
            speaker=Zurg
            message= _ "Little elves fight good. Zurg impressed. With dwarf chieftain dead, cowardly dwarves flee before us. Our struggle not over, still much more fighting, but elf and troll have won this battle. We thank you. Great Leader has allowed you to come speak with him. Great honor, never has one of your kind been allowed in his presence. But he wishes to talk with you and reward you. Please come with me."
        [/message]

        [message]
            speaker=Nym
            message= _ "With their knowledge of all these secret tunnels, you'd think they could have led us straight here instead of making us go through those 'light defenses'. It would have saved us a lot of unnecessary fighting in actually getting to the dwarf chieftain."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Perhaps they wanted to further test our prowess in battle. And besides, every dwarf we kill is one they don't have to. Still, I think we caused a bigger distraction then they were expecting."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Shhhh, you two. Yes, of course, we would be honored to come and meet the Great Leader. But first, we left many of our people back up near the entrance to the great cave where you first met us and I fear that even now those caves aren't safe. Can you help us escort my people to safety?"
        [/message]

        [message]
            speaker=Zurg
            message= _ "Hmmmm, yes, yes we can help. We have a few big caves you little people can stay in, and I get some big trolls to help escort you there. The Great Leader wouldn't want any unpleasant surprises. Show me where your people are hiding and we will help you move them to our caves."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "I thank you. Come on people, no celebrating yet, we still have work left to do!"
        [/message]

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

    # DWARF EASTER EGG EVENTS

    # Event 19: Hermit Intro and Death events (sighted intro version disabled)

    # Hermit lives alone on island in the lake, guarding his amulet

    [event]
        #name=sighted

        name=moveto

        [filter]
            x,y=18-24,3-8
            side=1
        [/filter]

        [message]
            speaker=Dwarf Hermit
            message= _ "They've come for my precious. It's mine, yes it is. They shan't have it, no they shan't. We shall kill them all, yes, yes we will."
        [/message]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Dwarf Hermit
        [/filter]

        [message]
            speaker=Dwarf Hermit
            message= _ "Curse them! We hates them!"
        [/message]

        [message]
            speaker=second_unit
            message= _ "What's this? His clothes were in rags, and yet he had this ancient jeweled amulet hanging around his neck. It contains a huge amethyst that seems to glow faintly with a strange purple light. I wonder where he got such a trinket?"
        [/message]

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

    # Event 19.5 baby tentacles attack any unit that tries to walk around
    # the edge of cave (except for flying shyde/star)
    # 2 if easy difficulty, 3 if challenging or hard difficulty

    [event]
        name=moveto

        [filter]
            [not]
                type=Desert Shyde, Desert Star
            [/not]
            x=17-21
            y=8-11
            side=1
        [/filter]

#ifdef HARD
        [unit]
            type=Tentacle of the Deep
            id=Smaller Tentacle
            side=9
            x,y=18,10
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
#endif

        [unit]
            type=Tentacle of the Deep
            id=Smaller Tentacle
            side=9
            x,y=19,9
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [unit]
            type=Tentacle of the Deep
            id=Smaller Tentacle
            side=9
            x,y=20,10
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [message]
            speaker=Smaller Tentacle
            message= _ "Splash! Splash!"
        [/message]

        {CHECK_EXPLORER}
        [message]
            speaker=$explorer.id
            message= _ "More tentacles?!? What, did that thing have a baby?"
        [/message]
        {CLEAR_VARIABLE explorer}
    [/event]

    # Event 20: Moveto rune statue, open door events

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x,y=45,21
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        # if dwarf_amulet = 1 open door desc set dwarf_door to 2

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

            [then]
                [message]
                    speaker=unit
                    message= _ "Hey wait a minute, that amulet glows the same color as this rune. Maybe if I put the amulet on and step into the rune..."
                [/message]

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

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

                [terrain]
                    x,y=46,21
                    terrain=Uu
                [/terrain]

                {PLACE_IMAGE scenery/rubble.png 46 21}

                [redraw][/redraw]

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

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

                [message]
                    speaker=unit
                    message= _ "Whoa. That was pretty impressive. The amulet stopped glowing and the rune is gone, but what have they revealed? "
                [/message]

                [set_variable]
                    name=dwarf_amulet
                    value=2
                [/set_variable]

                [set_variable]
                    name=dwarf_door
                    value=2
                [/set_variable]
            [/then]
        [/if]

        # if dwarf_door = 1 repeat description

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

            [then]
                [message]
                    speaker=unit
                    message= _ "The rune is still there, glowing mysteriously. I still have no idea why it was put here, but it's obviously powerful and magical, a combination of things which I am hesitant to mess with."
                [/message]
            [/then]
        [/if]

        # if dwarf_door = 0 print initial rune description set dwarf_door to 1

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

            [then]
                [message]
                    speaker=unit
                    message= _ "What in Eloh's name is this? Someone has carved a glowing purple rune in the floor at the end of this passage. It must be magical. And this passage ends suddenly in a smooth stone wall. This can't be a coincidence. But the wall seems quite solid. I wonder who carved that rune and why?"
                [/message]

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

    # Event 21: Ransack Dwarven Tomb

    # if unit is a desert shyde, star, ranger or avenger
    # then use alternate events so they don't lose their melee attack
    # special abilities when they gain first strike

    [event]
        name=moveto
        first_time_only=no

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

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

            [then]
                [message]
                    speaker=unit

                    message= _ "Based on the runes covering the walls this must be the tomb of some ancient dwarf. The tomb seems empty except for this ornate stone coffin. The skeleton inside the coffin has long since vanished into dust. All that's left are a few ceremonial trinkets and this shining golden belt. Inscribed on this inside are the words: 'May you have the toughness to stay standing long after your enemies fall' Grave robbing is never a good thing to do, but this belt looks magical and its former owner certainly won't miss it."
                    [option]
                        message= _ "I fear no ghosts, I'll take it."
                        [command]
                            [set_variable]
                                name=took_belt
                                value=1
                            [/set_variable]
                        [/command]
                        [command]
                            [message]
                                speaker=unit
                                message= _ "The belt fits perfectly! Somehow I feel stronger and tougher. This is too easy, there seem to have been no traps set upon the coffin. Today's my lucky day."
                            [/message]
                        [/command]

                        [command]
                            [object]
                                [filter]
                                    x=49
                                    y=24
                                    side=1
                                [/filter]

                                id=DwarvenBelt
                                name= _ "Dwarven Belt"
                                description= _ "The maximum hit points of the unit who wears this belt will increase by 12."

                                [effect]
                                    apply_to=hitpoints
                                    increase_total=12
                                [/effect]
                            [/object]
                        [/command]

                        [command]
                            {NAMED_NOTRAIT_UNIT 9 (Ghost) 47 22 (Angry Ghost) ( _ "Angry Ghost")}
                            # wmllint: recognize Angry Ghost

                            [message]
                                speaker=Angry Ghost
                                message= _ "You who disturb my rest, come and join me in death!"
                            [/message]

                            [message]
                                speaker=unit
                                message= _ "Then again, maybe I spoke too soon."
                            [/message]
                        [/command]
                    [/option]

                    [option]
                        message= _ "On second thought, it's better to leave the dead in peace."

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

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

    #at victory, clear variables:
    [event]
        name=victory
        {CLEAR_VARIABLE destroy_wall}

        {CLEAR_VARIABLE i}
        {CLEAR_VARIABLE first_tunnel}
        {CLEAR_VARIABLE bridge_blown}
        {CLEAR_VARIABLE temp}
        {CLEAR_VARIABLE tempx}
        {CLEAR_VARIABLE tempy}
        {CLEAR_VARIABLE tentacle_count}
        {CLEAR_VARIABLE tentacle_deaths}
        {CLEAR_VARIABLE tripped_bats}
        {CLEAR_VARIABLE x_left}
        {CLEAR_VARIABLE x_right}
        {CLEAR_VARIABLE y_up}
        {CLEAR_VARIABLE y_down}
        {CLEAR_VARIABLE dwarf_door}
        {CLEAR_VARIABLE dwarf_amulet}
        {CLEAR_VARIABLE took_belt}

        {CLEAR_VARIABLE entered_dwarf_lair}
    [/event]

    [event]
        name=time over

        [message]
            speaker=Kaleh
            message= _ "Oh no, we took too long and enemy reinforcements have arrived. We'll surely be overwhelmed now!"
        [/message]
    [/event]

    #if troll prisoner Grog dies in battle, record it

    [event]
        name=die

        [filter]
            id=Grog
        [/filter]

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

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