#textdomain wesnoth-nr

[scenario]
    id=05a_01_The_Pursuit
    name= _ "The Pursuit"
    map_file=05a_01_The_Pursuit.map
    turns=unlimited
    next_scenario=05a_02_Dealings
    victory_when_enemies_defeated=no

    {UNDERGROUND}

    {SCENARIO_MUSIC       underground.ogg}
    {EXTRA_SCENARIO_MUSIC the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC vengeful.ogg}
    {EXTRA_SCENARIO_MUSIC suspense.ogg}

    [story]
        [part]
            story= _ "Leaving most of the dwarves behind, Tallin and his party set off in pursuit of Malifor."
        [/part]
    [/story]

    # Players side
    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Peasant,Woodsman,Thug,Poacher,Footpad
        {GOLD 600 400 300}
        team_name=rebels
        user_team_name= _ "Alliance"

        # wmllint: recognize Tallin
        {CHARACTER_STATS_TALLIN}

        shroud=yes
    [/side]
    # wmllint: validate-on

    # Main enemy
    [side]
        side=2
        controller=ai
        recruit=Deathblade,Revenant,Bone Shooter,Necromancer
        gold=0
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}

        type=Ancient Lich
        id=Malifor
        name= _ "Malifor"
        profile=portraits/Malifor.webp
        canrecruit=yes

        facing=sw

        # These two have a role for 'sighted' events

        {LOYAL_UNIT 2 Draug 26 13}
        [+unit]
            role=Study Guard
            ai_special=guardian
        [/unit]

        # Draug guards
        {LOYAL_UNIT 2 Draug 20 10} {GUARDIAN}
        {LOYAL_UNIT 2 Draug 20 12} {GUARDIAN}
        {LOYAL_UNIT 2 Draug 24 14} {GUARDIAN}

        {LOYAL_UNIT 2 Draug 23 6} {GUARDIAN}
        {LOYAL_UNIT 2 Draug 24 3} {GUARDIAN}
        {LOYAL_UNIT 2 Draug 29 3} {GUARDIAN}
        {LOYAL_UNIT 2 Draug 30 9} {GUARDIAN}
        {LOYAL_UNIT 2 Draug 35 8} {GUARDIAN}

        # Revenants guards
        {LOYAL_UNIT 2 Revenant 19 21} {GUARDIAN}
        {LOYAL_UNIT 2 Revenant 19 26} {GUARDIAN}
        {LOYAL_UNIT 2 Revenant 21 21} {GUARDIAN}
        {LOYAL_UNIT 2 Revenant 21 26} {GUARDIAN}
        {LOYAL_UNIT 2 Revenant 21 35} {GUARDIAN}
        {LOYAL_UNIT 2 Revenant 19 35} {GUARDIAN}
        [+unit]
            # Speaks during the starting event
            role=starting_speaker
        [/unit]
    [/side]

#define MALIFORS_GUARD_RECRUITS
    {ON_DIFFICULTY
    (recruit=Skeleton,Skeleton Archer,Revenant)
    (recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter)
    (recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade)}
#enddef

    # Enemies to the immediate left and right of the first chamber
    [side]
        side=3
        controller=ai

        {MALIFORS_GUARD_RECRUITS}

        gold=0
        # {GOLD 100 150 250}
        {INCOME 10 16 22}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}

        type=Death Knight
        id=Hettel
        name= _ "Hettel"
        canrecruit=yes

        {LOYAL_UNIT 3 Revenant 33 31} {GUARDIAN}
        {LOYAL_UNIT 3 Revenant 35 29} {GUARDIAN}
        {LOYAL_UNIT 3 Revenant 36 33} {GUARDIAN}
    [/side]

    # Dungeon guard
    [side]
        side=4
        controller=ai

        {MALIFORS_GUARD_RECRUITS}

        gold=0
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}

        type=Death Knight
        id=Tervor
        name= _ "Tervor"
        canrecruit=yes

        {LOYAL_UNIT 4 Revenant 3 32} {GUARDIAN}
        {LOYAL_UNIT 4 Revenant 4 39} {GUARDIAN}
        {LOYAL_UNIT 4 Revenant 9 36} {GUARDIAN}
        {LOYAL_UNIT 4 Revenant 10 39} {GUARDIAN}
        {LOYAL_UNIT 4 Revenant 13 37} {GUARDIAN}
    [/side]

    # Treasury guards
    [side]
        side=5
        controller=ai

        {MALIFORS_GUARD_RECRUITS}

        gold=0
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}

        type=Death Knight
        id=Author
        name=_ "Author"
        canrecruit=yes

        {LOYAL_UNIT 5 Draug 15 23} {GUARDIAN}
        {LOYAL_UNIT 5 Draug 11 23}
        [+unit]
            role=Treasury Guard
            ai_special=guardian
        [/unit]

        {LOYAL_UNIT 5 Revenant 5 19} {GUARDIAN}
        {LOYAL_UNIT 5 Revenant 6 20} {GUARDIAN}
        {LOYAL_UNIT 5 Revenant 7 16} {GUARDIAN}
        {LOYAL_UNIT 5 Revenant 6 22} {GUARDIAN}
        {LOYAL_UNIT 5 Revenant 9 15} {GUARDIAN}
        {LOYAL_UNIT 5 Revenant 9 21} {GUARDIAN}
        {LOYAL_UNIT 5 Revenant 15 20} {GUARDIAN}
    [/side]

    # Study Guards
    [side]
        side=6
        controller=ai

        {MALIFORS_GUARD_RECRUITS}

        gold=0
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}

        type=Death Knight
        id=Boblin
        name= _ "Boblin"
        canrecruit=yes

        {LOYAL_UNIT 6 Revenant 26 21} {GUARDIAN}
        {LOYAL_UNIT 6 Revenant 28 21} {GUARDIAN}
        {LOYAL_UNIT 6 Revenant 31 16} {GUARDIAN}
    [/side]

    [side]
        side=7
        controller=ai

        {MALIFORS_GUARD_RECRUITS}

        gold=0
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}

        type=Death Knight
        id=Antrasis
        name= _ "Antrasis"
        canrecruit=yes

        {LOYAL_UNIT 7 Revenant 7 7}  {GUARDIAN}
        {LOYAL_UNIT 7 Revenant 10 8}  {GUARDIAN}
        {LOYAL_UNIT 7 Revenant 14 10}  {GUARDIAN}
        {LOYAL_UNIT 7 Revenant 19 16}  {GUARDIAN}
        {LOYAL_UNIT 7 Revenant 22 18} {GUARDIAN}
        {LOYAL_UNIT 7 Revenant 21 17} {GUARDIAN}
    [/side]

    # Giant Spiders and Tentacles of the Deep
    [side]
        side=8
        controller=ai
        hidden=yes

        gold=0
        team_name=monsters
        user_team_name= _ "Monsters"
        no_leader=yes

        # If the players opens the other door, the spiders attack the undead too
        # They can't harm Malifor, but they should not gather around him either
        [ai]
            [avoid]
                [filter]
                    id=Malifor
                [/filter]
                radius=3
            [/avoid]
        [/ai]
    [/side]

    # Whole lot of doors
    {PLACE_IMAGE scenery/dwarven-doors-closed.png 33 9}
    {PLACE_IMAGE scenery/dwarven-doors-closed.png 19 3}
    {PLACE_IMAGE scenery/dwarven-doors-closed.png 19 4}
    {PLACE_IMAGE scenery/dwarven-doors-closed.png 9 3}
    {PLACE_IMAGE scenery/dwarven-doors-closed.png 9 4}
    {PLACE_IMAGE scenery/dwarven-doors-closed.png 34 28}

    # Prisoners
    {PLACE_PRISONER_IMAGE units/human-magi/white-mage.png 8 32}
    {PLACE_PRISONER_IMAGE units/human-magi/white-mage+female.png 5 29}
    {PLACE_PRISONER_IMAGE units/elves-wood/druid.png 3 40}
    {PLACE_PRISONER_IMAGE units/drakes/burner.png  9 39}

    # Corpses in the water.
    {PLACE_IMAGE "floor-corpse.png" 40 22}
    {PLACE_IMAGE "floor-corpse.png" 35 15}
    {PLACE_IMAGE "floor-corpse.png" 36 20}
    {PLACE_IMAGE "floor-corpse.png" 35 3}

    # Signposts
    {PLACE_IMAGE scenery/signpost.png 15 33}
    {PLACE_IMAGE scenery/signpost.png 25 33}
    {PLACE_IMAGE scenery/signpost.png 25 28}
    {PLACE_IMAGE scenery/signpost.png 20 25}
    {PLACE_IMAGE scenery/signpost.png 15 28}
    {PLACE_IMAGE scenery/signpost.png 35 27}

    # Treasury chests
    {PLACE_IMAGE "items/chest.png~FL(horiz)" 6 22}
    {PLACE_IMAGE "items/chest.png~FL(horiz)" 9 21}
    {PLACE_IMAGE "items/chest.png~FL(horiz)" 5 19}
    {PLACE_IMAGE items/chest.png 6 20}
    {PLACE_IMAGE items/chest.png 7 16}
    {PLACE_IMAGE items/chest.png 9 15} # Rod of Justice here

    {PLACE_IMAGE items/bonestack.png 30 4}
    {PLACE_IMAGE items/bonestack.png 34 6}

    # Place holy water - uses core macro to set up required pickup event as well
    {OBJ_POTION_HOLY_ALT 34 26 object7_holywater}
    {OBJ_POTION_HOLY_ALT 33 27 object7_holywater2}
    {OBJ_POTION_HOLY_ALT 33 28 object7_holywater3}
    {OBJ_POTION_HOLY_ALT 32 26 object7_holywater4}
    {OBJ_POTION_HOLY_ALT 32 27 object7_holywater5}

    [event]
        name=prestart

        # Set up some variables that need an initial value
        {VARIABLE back_door_opened no}
        {VARIABLE main_door_opened no}
        {VARIABLE spider_door_opened no}
        {VARIABLE got_rod_of_justice no}

        [hide_unit]
            id=Tallin
        [/hide_unit]

        [store_unit]
            [filter]
                id=Tallin
            [/filter]
            variable=tallin_store
        [/store_unit]

        [objectives]
            side=1
            [objective]
                description= _ "Get past the Revenants."
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL keep_reached boolean_equals no}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Find Malifor and destroy him"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL keep_reached boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Tallin"
                condition=lose
            [/objective]

            [gold_carryover]
                bonus=no
                carryover_percentage=40
            [/gold_carryover]

            [note]
                description= _ "Be sure to explore"
                [show_if]
                    {VARIABLE_CONDITIONAL keep_reached boolean_equals yes}
                [/show_if]
            [/note]
        [/objectives]

        [lock_view][/lock_view]
    [/event]

    [event]
        name=start

        # Malifor escapes into shroud
        [move_unit_fake]
            type=Ancient Lich
            side=2
            x=20,20
            y=39,33
        [/move_unit_fake]

        [delay]
            time=1000
        [/delay]

        [move_unit_fake]
            type=$tallin_store.type
            side=1
            x=20,$tallin_store.x
            y=40,$tallin_store.y
        [/move_unit_fake]

        [unhide_unit]
            id=Tallin
        [/unhide_unit]

        {CLEAR_VARIABLE tallin_store}

        # Recall some units
        {RECALL_SUPPORTER}

        {RECALL_OR_REPLACE race=dwarf}

        {RECALL_OR_REPLACE id=Camerin}

        [message]
            speaker=Tallin
            message= _ "There he goes! Quick, get him!"
        [/message]

        [message]
            role=starting_speaker
            message= _ "I don’t think so, you living vermin."
        [/message]

        [message]
            speaker=Tallin
            message= _ "We’ll have to kill these revenants to get after him. There are only two of them. This shouldn’t last long."
        [/message]

        [unlock_view][/unlock_view]
    [/event]

    # Player enters the first chamber - more initial dialog and objectives
    [event]
        name=moveto
        [filter]
            side=1
            x=19-21
            y=29-31
        [/filter]

        [message]
            speaker=unit
            message= _ "Uh... Which way?"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Blast it! We lost him."
        [/message]

        [message]
            speaker=Tallin
            message= _ "It makes no difference in the end, because we will hunt him down and crush him to powder. HEAR THAT, YOU OLD SKELETON?"
        [/message]

        [message]
            speaker=Malifor
            message= _ "(<i>Faint cackle of laughter in the distance</i>)"
        [/message]

        [message]
            #wmllint: recognize Camerin
            speaker=Camerin
            message= _ "Yeah! This is gonna be fun!"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Let us proceed with caution. Nobody is to go off by himself. We don’t know what could be lurking in these tunnels."
        [/message]

        {VARIABLE keep_reached yes}
        [show_objectives]
        [/show_objectives]
    [/event]

    # From this point on we can go in five directions. Three of five
    # paths lead to an entrance to the end goal - Malifor's study.
    # Going clockwise, we have:

    # ================================================================
    # 1: PRISON MODULE
    #
    # Room with four support units you can free, two of which are
    # necessary for ending the scenario.
    # ================================================================

    # Signpost and alarm
    [event]
        name=moveto
        [filter]
            side=1
            x,y=15,33
        [/filter]

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "The Dungeon"
        [/message]

        [message]
            speaker=unit
            message= _ "Those poor wretches!"
        [/message]

        [message]
            speaker=Tallin
            message= _ "We won’t leave them in Malifor’s chains!"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    # Raise alarm in the prison section, this gives enemies there more
    # gold on top of the one they had initially.
    [event]
        name=sighted
        [filter]
            side=4
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=unit
            message= _ "Intruders! Stop them before they free the prisoners!"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Good luck with that."
        [/message]

        [gold]
            side=4
            amount={ON_DIFFICULTY 200 350 500}
        [/gold]
    [/event]

    # Father Morvin
    [event]
        name=moveto
        [filter]
            side=1
            x,y=8,32
        [/filter]

        # Remove the caged white mage image from hex
        [remove_item]
            x,y=$x1,$y1
        [/remove_item]

        # Spawn unit
        [unit]
            side=1
            x,y=9,32

            # wmllint: recognize Father Morvin
            {CHARACTER_STATS_FATHER_MORVIN}
        [/unit]

        [message]
            speaker=Father Morvin
            message= _ "Finally! I am free. Lord Tallin, I am forever in your debt! We will follow you to the end of the world if need be."
        [/message]

        [message]
            speaker=Tallin
            message= _ "It’s just ‘Tallin’, no ‘Lord’. And no problem."
        [/message]

        # If he was freed after sister Thera, there is no need to repeat the exposition
        [if]
            [have_unit]
                # wmllint: recognize Sister Thera
                id="Sister Thera"
            [/have_unit]
            [then]
                [message]
                    speaker=Sister Thera
                    message= _ "Morvin!"
                [/message]

                [message]
                    speaker=Father Morvin
                    message= _ "Thera!"
                [/message]

                [if]
                    [variable]
                        name=unit.id
                        equals="Sister Thera"
                    [/variable]
                    [then]
                        [message]
                            speaker=Tallin
                            message= _ "Please, folks, not now."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=unit
                            message= _ "Please, folks, not now."
                        [/message]
                    [/else]
                [/if]

                [message]
                    speaker=Sister Thera
                    message= _ "Oh, sorry."
                [/message]
            [/then]
            # Else explain how they ended up down here and why are they still alive
            [else]
                [message]
                    speaker=Tallin
                    message= _ "Who are you? How did you end up down here?"
                [/message]

                [message]
                    speaker=Father Morvin
                    message= _ "My name is Morvin. My wife, Thera and I were advisers and healers for the dwarvish nobles. We could not shield them from the wrath of Khazg Black-Tusk, but we survived the orcs and trolls — only to be captured by these skeletons."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Funny, why would the bonebag keep you as his prisoners? He doesn’t really seem to be the merciful type."
                [/message]

                [message]
                    speaker=Father Morvin
                    message= _ "He didn’t keep us alive out of mercy, he wanted to study us to see if there was a way to counteract our arcane attacks. His kind are very vulnerable to such attacks."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Indeed, that is good to know. But you are now free to go wherever you like. May the Lords of Light guide your path."
                [/message]

                [message]
                    speaker=Father Morvin
                    message= _ "As I have said, Tallin, I am eternally in your debt, and I take my debts seriously. If you have no objection, I will serve you until one of us departs this life."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Oh, think nothing of it. Let no talk of debts come between us; rather let us join hands as allies in restoring these Northlands to sanity."
                [/message]

                [message]
                    speaker=Father Morvin
                    message= _ "Thank you, Tallin."
                [/message]
            [/else]
        [/if]
    [/event]

    # Sister Thera
    # Prison escape route here
    [event]
        name=moveto
        [filter]
            side=1
            x,y=5,29
        [/filter]

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

        [unit]
            side=1
            x,y=6,29

            # wmllint: recognize Sister Thera
            {CHARACTER_STATS_SISTER_THERA}
        [/unit]

        [message]
            speaker=Sister Thera
            message= _ "Freedom at last! Thank you, Lord Tallin."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Just ‘Tallin’. I am no Lord, just a humble peasant trying to restore our people to freedom."
        [/message]

        [if]
            [have_unit]
                id="Father Morvin"
            [/have_unit]
            [then]
                [message]
                    speaker=Sister Thera
                    message= _ "Morvin!"
                [/message]

                [message]
                    speaker=Father Morvin
                    message= _ "Thera!"
                [/message]
                [if]
                    [variable]
                        name=unit.id
                        equals="Father Morvin"
                    [/variable]
                    [then]
                        [message]
                            speaker=Tallin
                            message= _ "Please, folks, not now."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=unit
                            message= _ "Please, folks, not now."
                        [/message]
                    [/else]
                [/if]
                [message]
                    speaker=Sister Thera
                    message= _ "Oh, sorry."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Tallin
                    message= _ "Who are you? How did you end up down here?"
                [/message]

                [message]
                    speaker=Sister Thera
                    message= _ "My name is Thera. My husband Morvin and I were advisers and healers for the dwarvish nobles of Knalga. We could not save them from Khazg Black-Tusk’s troops, but we survived the orcs and trolls only to be captured when these skeletons appeared."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Funny, why would the bonebag keep you as his prisoners? He didn’t seem to be the merciful type."
                [/message]

                [message]
                    speaker=Sister Thera
                    message= _ "He didn’t keep us alive out of mercy, he wanted to study us to see if there was a way to counteract our arcane attacks. His kind are very vulnerable to such attacks, as I am sure you know by now."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Indeed, that is good to know. But you are now free to go wherever you like. May the Lords of Light guide your path."
                [/message]

                [message]
                    speaker=Sister Thera
                    message= _ "If you have no objection, Tallin, we would like to join you. These Northlands are hardly safe these days for anyone to be traveling on their own, and we could lend valuable help to your cause."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Very well, you are most welcome to join us."
                [/message]

                [message]
                    speaker=Sister Thera
                    message= _ "Thank you, Tallin."
                [/message]
            [/else]
        [/if]

        [delay]
            time=1000
        [/delay]

        {MODIFY_UNIT id=$unit.id facing nw}

        [message]
            speaker=unit
            message= _ "Look at this. There’s some sort of opening in the wall..."
        [/message]

        [message]
            speaker=Sister Thera
            message= _ "It was there when I was thrown down here. The hole wasn’t big enough for me to go through, but perhaps one of you might enlarge it?"
        [/message]

        [message]
            speaker=unit
            message= _ "Hmmm, let’s see..."
        [/message]

        [animate_unit]
            [filter]
                id=$unit.id
            [/filter]

            flag=attack
            hits=yes
            with_bars=no
        [/animate_unit]

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

        [terrain]
            x,y=4,28
            terrain=Uu
        [/terrain]

        [redraw]
            side=1
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=unit
            message= _ "There we go. Now let’s see where this tunnel leads."
        [/message]
    [/event]

    # Set up a flavor death event for the pair since they can't die in combat (see utils/herodeaths.cfg)
    [event]
        name=die
        [filter]
            id=Father Morvin, Sister Thera
        [/filter]

        [message]
            speaker=Tallin
            message= _ "Wow! That’s incredible. Now I understand why the bag of bones kept you in jail; he just simply couldn’t kill you!"
        [/message]

        [message]
            speaker=Sister Thera
            message= _ "(<i>Giggle</i>)"
        [/message]
    [/event]

    # Elenia
    [event]
        name=moveto
        [filter]
            side=1
            x,y=3,40
        [/filter]

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

        [unit]
            side=1
            x,y=4,39
            hitpoints=1

            # wmllint: recognize Elenia
            {CHARACTER_STATS_ELENIA}
        [/unit]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=unit
            message= _ "Tallin, look! Oh, she’s not in good shape..."
        [/message]

        # Depending whether or not Thera has been, freed dialog
        # describes Elenia healing herself or being healed.
        [if]
            [have_unit]
                id="Sister Thera"
            [/have_unit]
            [then]
                [message]
                    speaker=Sister Thera
                    message= _ "Here, let me see her."
                [/message]

                {FLASH_WHITE (
                    [teleport]
                        [filter]
                            id=Sister Thera
                        [/filter]
                        x,y=5,39
                    [/teleport]
                )}

                [message]
                    speaker=Sister Thera
                    message= _ "This should help."
                [/message]

                [heal_unit]
                    [filter]
                        id=Elenia
                    [/filter]
                    [filter_second]
                        id=Sister Thera
                    [/filter_second]

                    amount=16
                    animate=yes
                [/heal_unit]

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

                [message]
                    speaker=Elenia
                    message= _ "Uh... where... am... I...?"
                [/message]

                [message]
                    speaker=Sister Thera
                    message= _ "You are in the dungeons of Malifor. These brave people have just released you."
                [/message]

                [message]
                    speaker=Elenia
                    message= _ "... Thanks."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "No problem. Sister Thera, you take care of her. If she wants to join us she would make a powerful ally."
                [/message]

                [message]
                    speaker=Elenia
                    message= _ "Yes, I would... like to join you... Lord Tallin."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Just Tallin; I am no lord. But gee, that sure is some powerful spell you used on her, Thera. She’s looking better already."
                [/message]

                [message]
                    speaker=Elenia
                    message= _ "And I feel better too. Now where’s that disgusting skeleton?"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "I wish we had some healers with us; I’ll try to help her as best I can."
                [/message]

                [delay]
                    time=1000
                [/delay]

                [message]
                    speaker=Elenia
                    message= _ "Uh... where... am... I...?"
                [/message]

                [message]
                    speaker=unit
                    message= _ "You are in the dungeons of Malifor. We have just released you."
                [/message]

                [message]
                    speaker=Elenia
                    message= _ "... Thanks."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "No problem. Just take it easy. If you would like to join us your help could mean life or death for a lot of us."
                [/message]

                [message]
                    speaker=Elenia
                    message= _ "Yes, I would... like to join you... Lord Tallin."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Just Tallin, I am no lord. And you are looking better already."
                [/message]

                [heal_unit]
                    [filter]
                        id=Elenia
                    [/filter]
                    # We do this so she gets animated healing herself
                    [filter_second]
                        id=Elenia
                    [/filter_second]

                    animate=yes
                    amount=16
                [/heal_unit]

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

                [message]
                    speaker=Elenia
                    message= _ "Oh, just a few tricks I know, otherwise I probably would be dead by now. Now where’s that disgusting skeleton?"
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Tallin
            message= _ "Why did the bag of bones capture you in the first place?"
        [/message]

        [message]
            speaker=Elenia
            message= _ "Because he thought I was pretty."
        [/message]

        [message]
            speaker=Tallin
            # wmllint: local spelling Geez nutcase
            message= _ "That old skeleton? Geez, what a nutcase."
        [/message]

        [message]
            speaker=Elenia
            message= _ "You’re telling me."
        [/message]
    [/event]

    # Krash
    [event]
        name=moveto
        [filter]
            side=1
            x,y=9,39
        [/filter]

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

        [unit]
            side=1
            x,y=8,38

            # wmllint: recognize Krash
            {CHARACTER_STATS_KRASH}
        [/unit]

        # I'm not checking for existence of Camerin since the
        # dialog still looks decent without his lines.
        [message]
            speaker=unit
            message= _ "Holy cow! What did I just let out of that cage? Look out everyone!"
        [/message]

        [message]
            speaker=Camerin
            message= _ "Oooooh, cool, it’s a drake!"
        [/message]

        [message]
            speaker=Krash
            message= _ "(<i>Whimper</i>)"
        [/message]

        [message]
            speaker=unit
            message= _ "Bright Gods, such a fierce creature whimpering! What the heck have they done to it?"
        [/message]

        [message]
            speaker=Camerin
            message= _ "The bastards!"
        [/message]

        # On the other hand, the following two look awkward without Morvin in play.
        [if]
            [have_unit]
                id="Father Morvin"
            [/have_unit]
            [then]
                [message]
                    speaker=Father Morvin
                    message= _ "Probably another one of Malifor’s experiments."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "I don’t know, see if it talks."
                [/message]
            [/then]
        [/if]

        [message]
            speaker=unit
            message= _ "Hey, big guy. We aren’t gonna hurt you. We wanna be your friends."
        [/message]

        [message]
            speaker=Krash
            message= _ "... Not... going... to... hurt... me?"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Hey, it talks!"
        [/message]

        [message]
            speaker=Camerin
            message= _ "It’s a ‘he’, and yes, they’re actually very intelligent creatures."
        [/message]

        [message]
            speaker=unit
            message= _ "Hush, I am trying to talk to him. Nope, we’ll never hurt you. But if you want to you can hurt some skeletons."
        [/message]

        [message]
            speaker=Krash
            message= _ "Skeletons! GRRRR!!" # wmllint: no spellcheck
        [/message]

        [message]
            speaker=unit
            message= _ "Look out! He is ready to go! Hey, is that smoke coming out of his ears?"
        [/message]

        # Set up a flavor attack event for Krash, placed as a
        # subevent since there is no need to have it in memory before
        # he's found
        [event]
            name=attack
            [filter]
                id=Krash
            [/filter]

            [message]
                speaker=Krash
                message= _ "ROOOAARR!" # wmllint: no spellcheck
            [/message]

            [message]
                role=Supporter
                message= _ "Whoa! Maybe he isn’t so friendly after all... or at least to some things."
            [/message]
        [/event]
    [/event]

    # Escape tunnel
    [event]
        name=moveto
        [filter]
            side=1
            x=2-4
            y=17-21
        [/filter]

        [message]
            speaker=unit
            message= _ "(<i>Sigh</i>) There doesn’t seem to be anything down this tunnel."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    # ================================================================
    # 2: TREASUREY MODULE
    #
    # Room stuffed full of treasure chests. All but one are full of
    # gold. The other contains the Rod of Justice.
    # ================================================================

    # Signpost event, there is nothing like pure greed ;)
    [event]
        name=moveto
        [filter]
            side=1
            x,y=15,28
        [/filter]

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "The Treasury"
        [/message]

        [message]
            speaker=unit
            message= _ "The Treasury! Excellent, let’s clean out the gold!"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    # Alarm
    # If alarm wasn't raised yet, raise it on first sight of treasury guard.
    [event]
        name=sighted
        [filter]
            role=Treasury Guard
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [fire_event]
            name=treasury_guard_alert
        [/fire_event]
    [/event]

    [event]
        name=treasury_guard_alert
        first_time_only=yes

        # Just in case we came from the hidden entrance
        [redraw]
            side=1
        [/redraw]

        [message]
            role=Treasury Guard
            message= _ "Intruders! Get them!"
        [/message]

        [message]
            role=Supporter
            message= _ "Bring it on!"
        [/message]

        # Add 200, 350 or 500 gold to treasury guards.
        [gold]
            side=5
            amount={ON_DIFFICULTY 200 350 500}
        [/gold]
    [/event]

#define TREASURY_GOLD_EVENT _X _Y _AMOUNT _MESSAGE
    [event]
        name=moveto
        [filter]
            x,y={_X},{_Y}
            side=1
        [/filter]

        [message]
            speaker=unit
            message={_MESSAGE}
        [/message]

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

        [gold]
            side=1
            amount={_AMOUNT}
        [/gold]

        [floating_text]
            x,y={_X},{_Y}
            color=225,225,25
            text={_AMOUNT}
        [/floating_text]

        [remove_item]
            x,y=$x1,$y1
        [/remove_item]
    [/event]
#enddef

    # Gold chests. The main feature of this room.
    {TREASURY_GOLD_EVENT 6 22 800  ( _ "There are at least several hundred gold coins in here!")}

    {TREASURY_GOLD_EVENT 9 21 500  ( _ "I don’t think the undead will be be needing this anyway.")}

    {TREASURY_GOLD_EVENT 6 20 1000 ( _ "Our people could rebuild their lives ten-fold with the gold in this treasury.")}

    {TREASURY_GOLD_EVENT 5 19 300  ( _ "We’re rich!")}

    {TREASURY_GOLD_EVENT 7 16 1500 ( _ "Why do these skeletons have so much gold just sitting around?")}

#undef TREASURY_GOLD_EVENT

    # The Rod of Justice!
    # Uberpowerful artifact that can be picked up by any unit with exception of Abhai.
    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            # wmllint: recognize Abhai
            id=Abhai
            x,y=9,15
        [/filter]
        [filter_condition]
            [variable]
                name=got_rod_of_justice
                boolean_equals=no
            [/variable]
        [/filter_condition]

        {INCIDENTAL_MUSIC "revelation.ogg"}

        [message]
            speaker=Abhai
            message= _ "The Rod of Justice! What in the world is it doing all the way down here?"
        [/message]

        [message]
            speaker=Tallin
            message= _ "What do you have there, Abhai?"
        [/message]

        [message]
            speaker=Abhai
            message= _ "This is the Great Rod of Justice, my boy. It was an ancient artifact even when I was young. They say it was crafted by the Great Gods themselves, and given to the first true Ruler of Men to ensure peace, harmony and above all — justice. For hundreds of years it did just that, for during the time it was wielded, the ruling class never became corrupt, the people never lacked justice, and neither evil nor wars troubled the land."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Well, if you don’t mind me saying — that certainly isn’t the state of affairs now. Knalga lies in ruins, orcs ravage the surface, and these dark and evil creatures haunt the underground passages. In the meantime, Wesnoth is said to be ruled by the wicked and cruel Queen Asheviere, while the rightful heir must have long since perished in his vain quest for the Sceptre of Fire."
        [/message]

        [message]
            speaker=Abhai
            message= _ "Ahh, with the Rod of Justice down here it is to be expected. Come Tallin, either you or one of your trusted men must wield this staff and bring peace and justice back into this world."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Why can’t you wield it, Abhai?"
        [/message]

        [message]
            speaker=Abhai
            message= _ "I am a creature of the past, and thus my time to wield it is long gone. This is your era, Tallin, and thus it is your responsibility to see to it that your people receive peace, prosperity and justice. Quickly, come forth or send one of your men for time is waning."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Very well."
        [/message]
    [/event]

    [event]
        first_time_only=no
        name=moveto
        [filter]
            side=1
            x,y=9,15
            [not]
                id=Abhai
            [/not]
        [/filter]
        [filter_condition]
            [variable]
                name=got_rod_of_justice
                boolean_equals=no
            [/variable]
        [/filter_condition]

        [message]
            speaker=narrator
            image=items/staff.png
            message= _ "An elegantly carved sceptre rests at the bottom of the chest. Precious jewels glitter across its surface, and it exudes a great aura of power."
            [option]
                label= _ "rod of justice^Take it"
                [command]
                    [message]
                        speaker=unit
                        message= _ "This thing is... incredible! What is such a powerful artifact doing hidden all the way back here?"
                    [/message]

                    [if]
                        [have_unit]
                            id=Camerin
                        [/have_unit]
                        [then]
                            [message]
                                speaker=Camerin
                                message= _ "That’s... that’s the Rod of Justice!"
                            [/message]

                            [message]
                                speaker=Tallin
                                message= _ "Do you know anything about it, Camerin?"
                            [/message]

                            [message]
                                speaker=Camerin
                                message= _ "I don’t think there is a person alive who knows anything more solid than rumors and legends. There are very few people who even knows it exists!"
                            [/message]

                            [message]
                                speaker=Tallin
                                message= _ "How did you come to know of it?"
                            [/message]

                            [message]
                                speaker=Camerin
                                message= _ "Some of the most ancient elvish legends make some vague mention of this artifact. But beyond that..."
                            [/message]

                            [message]
                                speaker=Tallin
                                message= _ "Interesting. I wonder who — or what — could have created such a powerful artifact. There must be one heck of a story behind this thing."
                            [/message]
                        [/then]
                    [/if]

                    # Remove the icon
                    [remove_item]
                        x,y=$x1,$y1
                    [/remove_item]

                    # Apply the effects
                    [object]
                        id=justice_rod
                        name= _ "Rod of Justice"
                        image=attacks/staff-magic.png
                        duration=forever
                        description= _ "A magical staff of tremendous power and unknown origin. Although the full extent of its power has not been fathomed, there are a few features about it that will be obvious to any master of lore. The wielder of this staff gains a dramatic increase in strength, speed and intelligence, and is granted the ability to fire devastating lightning bolts at his opponents. Only a person who is good at heart and who is willing to sacrifice his life on the path of justice can wield this staff."
                        [filter]
                            id=$unit.id
                        [/filter]

                        # New 16-4 fire attack with cool lightning animation
                        [effect]
                            apply_to=new_attack
                            name=rod of justice
                            description= _ "rod of justice"
                            type=fire
                            range=ranged
                            damage=16
                            number=4
                            icon=attacks/lightning.png
                            [specials]
                                {WEAPON_SPECIAL_MAGICAL}
                            [/specials]
                        [/effect]

                        # The halo mod is used to give the bolts a slightly
                        # different color than the originals
                        [effect]
                            apply_to=new_animation
                            [attack_anim]
                                [filter_attack]
                                    name=rod of justice
                                [/filter_attack]
                                {LIGHTNING_BOLT 1}
                                [+missile_frame]
                                    halo_mod="~SWAP(alpha,green,green)"
                                [/missile_frame]
                                {SOUND:HIT_AND_MISS lightning.ogg lightning-miss.ogg -300}
                            [/attack_anim]
                            [attack_anim]
                                [filter_attack]
                                    name=rod of justice
                                [/filter_attack]
                                {LIGHTNING_BOLT 2}
                                [+missile_frame]
                                    halo_mod="~SWAP(alpha,green,green)"
                                [/missile_frame]
                                {SOUND:HIT_AND_MISS lightning.ogg lightning-miss.ogg -300}
                            [/attack_anim]
                            [attack_anim]
                                [filter_attack]
                                    name=rod of justice
                                [/filter_attack]
                                {LIGHTNING_BOLT 3}
                                [+missile_frame]
                                    halo_mod="~SWAP(alpha,green,green)"
                                [/missile_frame]
                                {SOUND:HIT_AND_MISS lightning.ogg lightning-miss.ogg -300}
                            [/attack_anim]
                        [/effect]

                        # Increase the movement by 2
                        [effect]
                            apply_to=movement
                            increase=2
                        [/effect]

                        # If the unit has melee attacks, increase the damage of
                        # all of them by two
                        [effect]
                            apply_to=attack
                            range=melee
                            increase_damage=2
                        [/effect]

                        # Give the unit additional 10 HP and heal it
                        [effect]
                            apply_to=hitpoints
                            increase_total=10
                            heal_full=yes
                        [/effect]

                        # Reduce the amount of experience required for next level
                        # by 20%
                        [effect]
                            apply_to=max_experience
                            increase=-20%
                        [/effect]
                    [/object]

                    {VARIABLE got_rod_of_justice yes}
                [/command]
            [/option]
            [option]
                label= _ "rod of justice^Leave it"
                [command]
                    [allow_undo][/allow_undo]
                [/command]
            [/option]
        [/message]
    [/event]

    # ================================================================
    # 3: CHAMBER OF DEATH MODULE
    #
    # Path leading toward the Chamber of Death By Spiders, and a
    # back entrance to Malifor's study, as well as the prison escape
    # path and treasury back entrance.
    # ================================================================

    # The Great Chamber - signpost
    [event]
        name=moveto
        [filter]
            side=1
            x,y=20,25
        [/filter]

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "The Great Chamber"
        [/message]

        [message]
            speaker=unit
            message= _ "‘The Great Chamber’? Hmmm, wonder what that could be."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=sighted
        [filter]
            side=7
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=unit
            message= _ "Halt! You’re not allowed to be here! Authorized undead only!"
        [/message]

        [gold]
            side=7
            amount={ON_DIFFICULTY 200 350 500}
        [/gold]
    [/event]

    # Runaway dwarves
    # Once you kill the leader near the spider room, you meet three dwarves
    # that escaped from the dungeon some time ago.
    # They join the army and show a back entrance to the treasury
    [event]
        name=die
        [filter]
            side=7
            canrecruit=yes
        [/filter]

        [unit]
            type=Dwarvish Steelclad
            id=Dulcatas
            name= _ "Dulcatas"
            side=1
            x,y=4,8
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_HEALTHY}
            [/modifications]
        [/unit]

        [unit]
            type=Dwarvish Thunderguard
            id=Antolos
            name= _ "Antolos"
            side=1
            x,y=7,10
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Dwarvish Fighter
            id=Varem
            name= _ "Varem"
            side=1
            x,y=6,13
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [message]
            speaker=Dulcatas
            message= _ "Halt! Who goes there? Friend or foe?"
        [/message]

        [message]
            speaker=second_unit
            message= _ "Depends. Are you loyal to Malifor?"
        [/message]

        [message]
            speaker=Dulcatas
            message= _ "Never! If you ha’ been sent by Malifor, then know that we will never yield! Come and meet your death!"
        [/message]

        [message]
            speaker=second_unit
            message= _ "Hold! We aren’t friends of Malifor in the least. Rather, we have come to destroy him."
        [/message]

        [message]
            speaker=Dulcatas
            message= _ "Finally! You don’t know how long we have been waiting for this day."
        [/message]

        [message]
            speaker=second_unit
            message= _ "How did you get here and how long have you been here?"
        [/message]

        [message]
            speaker=Dulcatas
            message= _ "We were originally prisoners of Malifor, but we tunneled out and escaped. Since then, we have eked out a precarious survival on what we have been able to steal or raid from Malifor."
        [/message]

        [message]
            speaker=second_unit
            message= _ "By now you have tunnels all through this place."
        [/message]

        [message]
            speaker=Dulcatas
            message= _ "Aye. That seemingly blank wall to the south there is actually a hidden entrance to the treasury."
        [/message]

        [message]
            speaker=second_unit
            message= _ "Awesome, let’s go!"
        [/message]

        # wmllint: deathcheck off

        # Since the player doesn't know about the entrance until shown it this event can be set up only after meeting the dwarfs
        [event]
            name=moveto
            [filter]
                side=1
                x,y=8,13
            [/filter]

            # Open the back entrance
            [message]
                speaker=unit
                message= _ "Here we go."
            [/message]

            [terrain]
                x,y=8,14
                terrain=Uh
            [/terrain]

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

            [redraw]
                side=1
            [/redraw]

            # If the treasury alarm wasn't raised yet, this will fire and do so
            [fire_event]
                name=treasury_guard_alert
            [/fire_event]
        [/event]

        # wmllint: deathcheck on
    [/event]

    # The spider ambush
    # On entering the great chamber two stone blocks cut off the way
    # back and a number of giant spiders spawn to harass the player.
    [event]
        name=moveto
        [filter]
            side=1
            x=10-18,11-17
            y=1-6,7
        [/filter]

        [scroll_to]
            x,y=14,4
        [/scroll_to]

        [message]
            speaker=unit
            message= _ "So this is the Great Chamber, eh? Doesn’t look like there is much to see here."
        [/message]

        {QUAKE "rumble.ogg"}

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "The ground shakes."
        [/message]

        [message]
            speaker=unit
            message= _ "Perhaps I spoke too soon..."
        [/message]

        {QUAKE "cave-in.ogg"}
        {QUAKE "cave-in.ogg"}

        # Cutting off the exit
        [terrain]
            x=9,10
            y=7,7
            terrain=Xu
        [/terrain]

        # When cutting off the exit, test for units on the wall, if there are units on the wall, teleport them back

        [if]
            [have_unit]
                side=1
                x=9,7
            [/have_unit]
            [then]
                [teleport]
                    [filter]
                        x,y=9,7
                    [/filter]
                    x,y=10,7
                    check_passability=yes
                [/teleport]
            [/then]
        [/if]

        [if]
            [have_unit]
                side=1
                x=10,7
            [/have_unit]
            [then]
                [teleport]
                    [filter]
                        x,y=10,7
                    [/filter]
                    x,y=9,7
                    check_passability=yes
                [/teleport]
            [/then]
        [/if]

        [redraw][/redraw]

        [message]
            speaker=unit
            message= _ "What is this? Our retreat is cut off!"
        [/message]

        # Spawning spiders depending on difficulty
        {NOTRAIT_UNIT 8 "Giant Spider" 6 2}
        {NOTRAIT_UNIT 8 "Giant Spider" 6 3}
        {NOTRAIT_UNIT 8 "Giant Spider" 5 5}
        {NOTRAIT_UNIT 8 "Giant Spider" 5 3}
        {NOTRAIT_UNIT 8 "Giant Spider" 5 2}
        {NOTRAIT_UNIT 8 "Giant Spider" 20 2}
        {NOTRAIT_UNIT 8 "Giant Spider" 20 1}
#ifndef EASY
        {NOTRAIT_UNIT 8 "Giant Spider" 8 2}
        {NOTRAIT_UNIT 8 "Giant Spider" 8 3}
        {NOTRAIT_UNIT 8 "Giant Spider" 22 2}
        {NOTRAIT_UNIT 8 "Giant Spider" 22 3}
#ifndef NORMAL
        {NOTRAIT_UNIT 8 "Giant Spider" 4 2}
        {NOTRAIT_UNIT 8 "Giant Spider" 5 4}
        {NOTRAIT_UNIT 8 "Giant Spider" 20 3}
#endif
#endif

        {QUAKE "cave-in.ogg"}
        {QUAKE "cave-in.ogg"}

        # Break some walls exposing side tunnels
        [terrain]
            x=19,19,9,9
            y=3,4,3,4
            terrain=Uu
        [/terrain]

        {PLACE_IMAGE scenery/dwarven-doors-closed.png 22 4}

        [redraw]
            side=1
        [/redraw]

        [message]
            type=Giant Spider
            message= _ "Hsssss" # wmllint: no spellcheck
        [/message]

        [message]
            speaker=unit
            message= _ "‘Great Chamber’, my foot! This is a death chamber!"
        [/message]

        #You can enter from the study, but only if you've already triggered the spiders
        [event]
            name=moveto
            first_time_only=no
            [filter]
                x,y=23,5
            [/filter]
            [filter_condition]
                [variable]
                    name=spider_door_opened
                    boolean_equals=no
                [/variable]
            [/filter_condition]

            [message]
                speaker=unit
                message= _ "Hmmm. The wall appears weak here. I think there might be something on the other side."
            [/message]

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

            [terrain]
                x,y=22,4
                terrain=Uu
            [/terrain]

            [message]
                speaker=unit
                message= _ "There we go."
            [/message]

            {VARIABLE spider_door_opened yes}
        [/event]
    [/event]

    # ================================================================
    # 4: STUDY MODULE
    #
    # This path leads directly to Malifor's Study.
    # Nothing hard in this module either, just dialog.
    # ================================================================

    # Signpost
    [event]
        name=moveto
        [filter]
            side=1
            x,y=25,28
        [/filter]

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "Malifor the Great’s Study"
        [/message]

        [message]
            speaker=unit
            message= _ "There we go! This way!"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    # Study alarm
    [event]
        name=sighted
        [filter]
            role=Study Guard
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            role=Study Guard
            message= _ "They are attacking the master’s study! We must stop them! Call the reserves!"
        [/message]

        [gold]
            side=6
            amount={ON_DIFFICULTY 200 350 500}
        [/gold]
    [/event]

    # ================================================================
    # 5: FLOODED PATH MODULE
    #
    # Flooded path leading to the holy water storage, underground lake,
    # and a back entrance to Malifor's study.
    # ================================================================

    # In the beginning, there was a signpost...
    # The flooded path - Signpost
    [event]
        name=moveto
        [filter]
            side=1
            x,y=25,33
        [/filter]

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "Caution! Tunnel flooded and infested with aquatic monsters. Enter at the risk of your unlife."
        [/message]

        [message]
            speaker=unit
            message= _ "Interesting. It seems like someone really doesn’t want us going down this tunnel."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=sighted
        [filter]
            id=Hettel
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        # He's not very bright, is he
        [message]
            speaker=unit
            message= _ "Intruders? Capture them and throw them in with the toxic waste!"
        [/message]

        [gold]
            side=3
            amount={ON_DIFFICULTY 200 250 300}
        [/gold]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=34,29
        [/filter]

        [terrain]
            x,y=34,28
            terrain=Uu
        [/terrain]

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

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "A section of wall slides away."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=unit
            message= _ "Holy water! For a certainty, those skeletons won’t like us getting our hands on this stuff. But that’s probably why they kept them back here in the first place."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=35,27
        [/filter]

        [message]
            speaker=narrator
            image=scenery/signpost.png
            message= _ "Warning! These bottles contain toxic waste. Causes disintegration on contact."
        [/message]

        [message]
            speaker=unit
            message= _ "(<i>rolls eyes</i>) Oh, the hazardous life of a skeleton."
        [/message]
    [/event]

    # Which pointed towards the lake with a creepy tentacled monster...
    [event]
        name=moveto
        [filter]
            side=1
            x=34-36
            y=22-25
        [/filter]

        [message]
            speaker=unit
            message= _ "Hey, an underground lake."
        [/message]

        # We don't have tentacled monsters as such but we do have a single tentacle unit
        {NOTRAIT_UNIT 8 "Tentacle of the Deep" 35 23}
        {NOTRAIT_UNIT 8 "Tentacle of the Deep" 33 25}
        {NOTRAIT_UNIT 8 "Tentacle of the Deep" 33 23}
        {NOTRAIT_UNIT 8 "Tentacle of the Deep" 34 21}
#ifndef EASY
        {NOTRAIT_UNIT 8 "Tentacle of the Deep" 31 23}
#ifndef NORMAL
        {NOTRAIT_UNIT 8 "Tentacle of the Deep" 32 22}
#endif
#endif

        [message]
            speaker=unit
            message= _ "Ack! What are those things!"
        [/message]

        [if]
            [have_unit]
                id=Camerin
            [/have_unit]
            [then]
                [message]
                    speaker=Camerin
                    message= _ "Oh yeah, those things. Watch out, they are the arms of some sort of underwater creature. They’ll try to pummel you to death, then drag you under for dinner."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Then how do we get past? I can see that the passage continues to both the north and south, and we haven’t found Malifor yet..."
                [/message]

                [message]
                    speaker=Camerin
                    message= _ "Creatures of that type regenerate over time; it’s doubtful we can destroy it completely. But if we destroy its arms we’ll be relatively safe until they regenerate."
                [/message]

                [message]
                    speaker=Tallin
                    message= _ "Let’s get to it, then."
                [/message]
            [/then]
        [/if]
    [/event]

    # If you decide to capture the village you might see a ghost...
    # Runaway spectre
    [event]
        name=capture
        [filter]
            side=1
            x,y=31,25
        [/filter]

        [sound]
            name=wail-long.wav
        [/sound]

        [unit]
            side=1
            x,y=32,24
            type=Wraith
            id=Abhai
            name= _ "Abhai"
            [modifications]
                {TRAIT_UNDEAD}
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        [message]
            speaker=unit
            message= _ "AH! A ghost!"
        [/message]

        [message]
            speaker=Abhai
            message= _ "Who are you that dares to venture down these tunnels?"
        [/message]

        [message]
            speaker=unit
            message= _ "I... I am one of Tallin’s men..."
        [/message]

        [message]
            speaker=Abhai
            message= _ "Who is this ‘Tallin’?"
        [/message]

        [message]
            speaker=Tallin
            message= _ "That would be me."
        [/message]

        [message]
            speaker=Abhai
            message= _ "What is your purpose in coming here?"
        [/message]

        [message]
            speaker=Tallin
            message= _ "We seek the destruction of the lich Malifor."
        [/message]

        [message]
            speaker=Abhai
            message= _ "Malifor...! Finally someone here in force to deal with that menace!"
        [/message]

        [message]
            speaker=Tallin
            # po: "this spirit" is referring to the Ghost named Abhai.
            message= _ "<i>Did this spirit get even paler?</i> Can you tell us where he is? And, if I may ask, who are — or rather, were — you?"
        [/message]

        [message]
            speaker=Abhai
            message= _ "I am Lord Abhai, the ruler... once... of a great kingdom far to the west. In time, as all men do, I grew old and passed to the Land of the Dead. I know not how long I dwelt there, before I was wrenched from my peace and drawn into this realm by a terrible power."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Let me guess. Malifor?"
        [/message]

        [message]
            speaker=Abhai
            message= _ "Indeed. He was once a great sorcerer, but he coveted wealth and power. To gain his ends, he allied himself with the Lich-Lords, and from them he learned their craft. When the orcish menace first appeared on the continent and the Wesfolk fled to the east, Malifor left their service and followed. No word surfaced of his fate from then on, but it seems he became a lich himself. I am not surprised he took up residence in these mines, all these years later — he always had a love of gold, and a special hatred of me. He tried to break me into mindless slavery, but I resisted his power and fled. I have been hiding in these flooded tunnels ever since. Some monster that Malifor’s minions greatly fear lives in these waters; they do not molest me here."
        [/message]

        [message]
            speaker=Tallin
            message= _ "I am afraid times have changed much. Our first king, Haldric I, fled the Green Isle with the Wesfolk, the orcs in pursuit. He came ashore on this land that we now call the Great Continent and destroyed the Lich-Lord Jevyan before founding the Kingdom of Wesnoth. That was centuries ago."
        [/message]

        [message]
            speaker=Abhai
            message= _ "So... much time has passed indeed."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Would you join us to defeat this evil creature?"
        [/message]

        [message]
            speaker=Abhai
            # wmllint: local spelling er
            message= _ "Wouldn’t miss it. Maybe after he is destroyed my kind and I can live... er... be dead peacefully."
        [/message]

        [message]
            speaker=Abhai
            message= _ "Keep following these flooded tunnels. I think they might lead you directly to Malifor."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Great. Forward, men!"
        [/message]

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

    # And going forward is a sure way to find some bodies
    # A string of corpses
    [event]
        name=moveto
        [filter]
            side=1
            x,y=36,20
        [/filter]

        [message]
            speaker=unit
            message= _ "Ugh, a corpse. And it — (<i>gags</i>) — reeks!"
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=35,15
        [/filter]

        [message]
            speaker=unit
            message= _ "Gee, what’s with these bodies floating around? Is this river some sort of body disposal?"
        [/message]
    [/event]

    # A dead end
    [event]
        name=moveto
        [filter]
            side=1
            x,y=40,22
        [/filter]

        [message]
            speaker=unit
            message= _ "Just great, I am cold, wet, and tired and what have we here? Another dead body. This place is starting to get on my nerves!"
        [/message]
    [/event]

    # Eventually you'll always find some bad guy sidekicks. Just waiting to get mauled...
    # Naga guardians
    [event]
        name=moveto
        [filter]
            side=1
            x=35-38
            y=12-14
        [/filter]

        [message]
            speaker=unit
            message= _ "Hold it, people, there’s something just ahead!"
        [/message]

        {LOYAL_UNIT 2 "Naga Warrior" 38 11}
        {LOYAL_UNIT 2 "Naga Fighter" 38 10}
        {LOYAL_UNIT 2 "Naga Fighter" 37 11}
#ifndef EASY
        {LOYAL_UNIT 2 "Naga Fighter" 37 12}
#ifndef NORMAL
        {LOYAL_UNIT 2 "Naga Fighter" 36 12}
#endif
#endif

        [remove_shroud]
            side=1
            x=36-39
            y=9-13
        [/remove_shroud]

        [message]
            type=Naga Warrior
            message= _ "(<i>sniff</i>) I smell humans."
        [/message]

        [message]
            type=Naga Fighter
            message= _ "You are just plain deaf. I heard them coming a mile off."
        [/message]

        [message]
            type=Naga Warrior
            message= _ "Ahh, shut up. Let’s go kill them."
        [/message]
    [/event]

    # ================================================================
    # MALIFOR'S LAIR
    #
    # Once you open a door to the Study, the final confrontation
    # begins. There are three pairs of them, and the player can choose
    # not to open any of them immediately.
    # ================================================================

    # The doors can be opened from following coordinates:
    # Spider (22,3), Main [(22,9) (23,10) (24,10)], and Flooded (34,9)

    # Main doors
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x=22,23,24
            y=9,10,10
        [/filter]
        [filter_condition]
            [variable]
                name=main_door_opened
                boolean_equals=no
            [/variable]
        [/filter_condition]

        [message]
            speaker=unit
            message= _ "It looks like this is it. Here is the door to Malifor’s study. Are we all ready for this?"
            [option]
                label= _ "Get those doors open!"
                [command]
                    [sound]
                        name=gate-fall.ogg
                    [/sound]

                    [terrain]
                        x=23,24,25
                        y=9,9,10
                        terrain="^Pr\o"
                        layer=overlay
                    [/terrain]

                    [message]
                        speaker=unit
                        message= _ "Let’s go!"
                    [/message]

                    {VARIABLE main_door_opened yes}

                    [fire_event]
                        name=confront_malifor
                    [/fire_event]
                [/command]
            [/option]
            [option]
                label= _ "Just wait a sec."
                [command]
                    [message]
                        speaker=unit
                        message= _ "Very well."
                    [/message]
                [/command]
            [/option]
        [/message]
    [/event]

    #main gates from inside
    [event]
        name=moveto
        [filter]
            side=1
            x=24,25,26
            y=8,9,9
        [/filter]
        [filter_condition]
            [variable]
                name=main_door_opened
                boolean_equals=no
            [/variable]
        [/filter_condition]

        [message]
            speaker=Tallin
            message= _ "Get those doors open!"
        [/message]

        [sound]
            name=gate-fall.ogg
        [/sound]

        [remove_item]
            x=23,24,25
            y=9,9,10
        [/remove_item]

        [terrain]
            x=23,24,25
            y=9,9,10
            terrain="^" # Intentional, to remove the overlay
            layer=overlay
        [/terrain]

        {VARIABLE main_door_opened yes}
    [/event]

    # Spider chamber door
    [event]
        name=moveto
        first_time_only=no
        [filter]
            x,y=22,3
        [/filter]
        [filter_condition]
            [variable]
                name=spider_door_opened
                boolean_equals=no
            [/variable]
        [/filter_condition]

        [message]
            speaker=unit
            message= _ "Hmmm. The wall appears weak here. I think there might be something on the other side."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Anything you can’t handle?"
        [/message]

        [message]
            speaker=unit
            message= _ "Nope. Should I open it?"
            [option]
                label= _ "Go for it!"
                [command]
                    {MODIFY_UNIT (x,y=$x1,$y1) facing se}

                    [animate_unit]
                        [filter]
                            x,y=$x1,$y1
                        [/filter]

                        flag=attack
                        hits=yes
                        with_bars=no
                    [/animate_unit]

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

                    [terrain]
                        x,y=22,4
                        terrain=Uu
                    [/terrain]

                    [redraw]
                        side=1
                    [/redraw]

                    [message]
                        speaker=unit
                        message= _ "There we go."
                    [/message]

                    {VARIABLE spider_door_opened yes}

                    [fire_event]
                        name=confront_malifor
                    [/fire_event]
                [/command]
            [/option]
            [option]
                label= _ "Just wait a sec."
                [command]
                    [message]
                        speaker=unit
                        message= _ "Very well."
                    [/message]
                [/command]
            [/option]
        [/message]
    [/event]

    # Flooded passage door
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=34,9
        [/filter]
        [filter_condition]
            [variable]
                name=back_door_opened
                boolean_equals=no
            [/variable]
        [/filter_condition]

        [message]
            speaker=unit
            message= _ "Hey, check this out, it looks like some sort of lever."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Throw it and see what it does."
        [/message]

        [message]
            speaker=unit
            message= _ "Should I throw it?"
            [option]
                label= _ "Go for it!"
                [command]
                    [delay]
                        time=2000
                    [/delay]

                    [message]
                        speaker=unit
                        message= _ "Nothing. That door is not moving."
                    [/message]

                    [message]
                        speaker=Tallin
                        message= _ "Why don’t you try ‘knocking’?"
                    [/message]

                    [message]
                        speaker=unit
                        message= _ "Very well."
                    [/message]

                    {MODIFY_UNIT (x,y=$x1,$y1) facing nw}

                    [animate_unit]
                        [filter]
                            x,y=$x1,$y1
                        [/filter]

                        flag=attack
                        hits=yes
                        with_bars=no
                    [/animate_unit]

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

                    [terrain]
                        x,y=33,9
                        terrain=Uu
                    [/terrain]

                    [message]
                        speaker=unit
                        message= _ "Anybody home?"
                    [/message]

                    [redraw]
                        side=1
                    [/redraw]

                    {VARIABLE back_door_opened yes}

                    [fire_event]
                        name=confront_malifor
                    [/fire_event]
                [/command]
            [/option]
            [option]
                label= _ "Just wait a sec."
                [command]
                    [message]
                        speaker=unit
                        message= _ "Very well."
                    [/message]
                [/command]
            [/option]
        [/message]
    [/event]

    #flooded passage from inside
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x=32,32,33
            y=9,8,8
        [/filter]
        [filter_condition]
            [variable]
                name=back_door_opened
                boolean_equals=no
            [/variable]
        [/filter_condition]

        [message]
            speaker=unit
            message= _ "Hey, check this out, it looks like some sort of lever."
        [/message]

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

        [terrain]
            x,y=33,9
            terrain=Uu
        [/terrain]

        {VARIABLE back_door_opened yes}
    [/event]

#define MALIFOR_GUARD TYPE X Y
    [unit]
        side=2
        type={TYPE}
        x,y={X},{Y}

        generate_name=yes
        random_traits=no
        random_gender=yes

        facing=sw
        animate=yes
    [/unit]
#enddef

    # Opening the door will trigger the confrontation with Malifor
    [event]
        name=confront_malifor
        first_time_only=yes

        [remove_shroud]
            side=1
            x=23-35
            y=3-10
        [/remove_shroud]

        [delay]
            time=500
        [/delay]

        [scroll_to_unit]
            id=Malifor
        [/scroll_to_unit]

        [message]
            speaker=Malifor
            message= _ "You wretched vermin, I have had it with you! Guards!"
        [/message]

        # Give Malifor some guards and gold.
        {MALIFOR_GUARD Deathblade 25 6}
        {MALIFOR_GUARD Deathblade 29 8}
        {MALIFOR_GUARD Lich 27 5}
        {MALIFOR_GUARD Lich 32 7}

#ifndef EASY
        {MALIFOR_GUARD Deathblade 31 4}
#ifndef NORMAL
        {MALIFOR_GUARD Deathblade 29 7}
        {MALIFOR_GUARD Lich 35 6}
#endif
#endif

        [gold]
            side=2
            amount={ON_DIFFICULTY 200 300 400}
        [/gold]

        [message]
            speaker=Malifor
            message= _ "You invaded my kingdom, drove me from my mines, raided my dungeon, and plundered my treasury. Your audacity ends here!"
        [/message]

        # Second Malifor line doesn't make sense without at least one White Mage around.
        # We need to check for their presence, since they might not have been freed yet,
        # though that's very unlikely
        [if]
            [have_unit]
                id=Father Morvin,Sister Thera
            [/have_unit]
            [then]
                [message]
                    speaker=Father Morvin
                    message= _ "You are wrong, Malifor, for you shall be the one who is destroyed. You are cruel, merciless and a terror to all that lives. The world will be a better place with you gone!"
                [/message]

                [message]
                    speaker=Sister Thera
                    message= _ "To feed your greed and hunger you have terrorized all that is good. You have disturbed the rest of the brave defenders of Knalga. Now, your evil reign shall be brought to an end."
                [/message]

                [message]
                    speaker=Malifor
                    message= _ "Fools! Don’t think it’s so easy to kill me. Your corpses shall all soon be serving me. Fall on them, my hordes!"
                [/message]
            [/then]
        [/if]
    [/event]

    # Don't allow anyone but Morvin and Thera to damage Malifor
    {FORCE_CHANCE_TO_HIT (
        side=1,8
        [not]
            id=Father Morvin,Sister Thera
        [/not]
    )(id=Malifor) 0 (
    )}

#define NOT_WHITE_MAGES_ATTACK_MALIFOR_WITH_WEAPON_TYPE _TYPE
    [filter]
        side=1
        [not]
            id=Father Morvin,Sister Thera
        [/not]
    [/filter]

    [filter_attack]
        type={_TYPE}
    [/filter_attack]

    [filter_second]
        id=Malifor
    [/filter_second]
#enddef

    [event]
        name=attack end
        {NOT_WHITE_MAGES_ATTACK_MALIFOR_WITH_WEAPON_TYPE blade}

        [message]
            speaker=Malifor
            message= _ "HAHAHAHA, DEATH HAS NO EFFECT ON ME YOU FOOLS!"
        [/message]

        [message]
            speaker=unit
            message= _ "Well, blades don’t work."
        [/message]
    [/event]

    [event]
        name=attack end
        {NOT_WHITE_MAGES_ATTACK_MALIFOR_WITH_WEAPON_TYPE pierce}

        [message]
            speaker=Malifor
            message= _ "HAHAHAHA, YOUR IDIOCY AMUSES ME GREATLY!"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Geez, how are we going to kill him? This weapon is ineffective!"
        [/message]
    [/event]

    [event]
        name=attack end
        {NOT_WHITE_MAGES_ATTACK_MALIFOR_WITH_WEAPON_TYPE fire}

        [message]
            speaker=Malifor
            message= _ "YOU PUNY MORTALS SHALL SOON BE SERVING ME!"
        [/message]

        [message]
            speaker=Camerin
            message= _ "Blast it! Even fire has no effect on him!"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Let’s try using something different on him."
        [/message]
    [/event]

    [event]
        name=attack end
        [filter]
            id=Father Morvin,Sister Thera,Malifor
        [/filter]
        [filter_second]
            id=Malifor,Father Morvin,Sister Thera
        [/filter_second]

        [message]
            speaker=Malifor
            message= _ "AAAAAAHHHHHH!"
        [/message]

        [message]
            speaker=Father Morvin
            message= _ "I see now. It is impossible to destroy him by ordinary means."
        [/message]

        [message]
            speaker=Tallin
            message= _ "Then how are we going to destroy him? Surely there must be a way."
        [/message]

        [message]
            speaker=Father Morvin
            message= _ "Yes, I think there is, but only myself or Thera have the means to do it. Come on Thera, let’s destroy that old skeleton."
        [/message]

        [message]
            speaker=Sister Thera
            message= _ "Yeah, I can’t wait to get my hands on that bastard!"
        [/message]

        [message]
            speaker=Father Morvin
            message= _ "That was very unladylike of you."
        [/message]

        [message]
            speaker=Sister Thera
            message= _ "(<i>Giggle</i>) Sorry."
        [/message]
    [/event]

    # Malifor can be successfully killed only by White Mages.
    # This event handles that assumption.
    [event]
        name=last breath
        [filter]
            id=Malifor
        [/filter]
        [filter_second]
            id=Father Morvin,Sister Thera
        [/filter_second]

        [message]
            speaker=Malifor
            message= _ "AHHHH! YOU BLASTED MAGE!"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Good. We finally got him. He is dissolving."
        [/message]

        [message]
            speaker=Malifor
            message= _ "Curses on you you blasted mages, curses on you you blasted dwarves, curses on you you blasted humans, and CURSES ON YOU YOU BLASTED TALLIN! MAY YOUR MISERABLE LIVES BE FULL OF TORTURE! MAY YOUR PEOPLE NEVER BE FREE! MAY ALL YOUR NEAR AND DEAR DESERT YOU! MAY A THUNDERBOLT HIT YOUR HEAD! MAY—"
        [/message]

        [message]
            speaker=Tallin
            message= _ "May you shut your ugly mouth and hurry up and die."
        [/message]

        [message]
            speaker=Malifor
            message= _ "MAY THE EARTH OPEN UP AND SWALLOW YOU! MAY ALL YOUR TEETH FALL OUT! MAY YOU BECOME A WEAK SKINNY OLD MAN! MAY—"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Malifor
        [/filter]
        [filter_second]
            id=Father Morvin,Sister Thera
        [/filter_second]

        [message]
            speaker=second_unit
            message= _ "Finally! He has been reduced to dust."
        [/message]

        [message]
            speaker=Tallin
            message= _ "At last! Victory is ours! Good work, men!"
        [/message]

        [message]
            speaker=Father Morvin
            message= _ "So, where to now, Tallin?"
        [/message]

        [message]
            speaker=Tallin
            message= _ "Now, let’s get back to the dwarves and see what progress they have made in forging us weapons."
        [/message]

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

    [event]
        name=scenario_end

        {CLEAR_VARIABLE back_door_opened,main_door_opened,spider_door_opened,got_rod_of_justice,keep_reached}
    [/event]

    # And the usual batch of hero death macros
    {HERODEATH_TALLIN}
    {HERODEATH_CAMERIN}
    {HERODEATH_KRASH}
    {HERODEATH_ELENIA}
    {HERODEATH_THERA_AND_MORVIN_WITH_DIALOG}

    {SUPPORTER_DEATH_HANDLER}
[/scenario]

#undef MALIFORS_GUARD_RECRUITS
#undef MALIFORS_LAST_BREATH
#undef MALIFOR_RESPAWN
#undef MALIFOR_GUARD
