#textdomain wesnoth-nr
[scenario]
    # Start sequence
    # Set up map, TOD scheudle, variables, place images, objects, units, execute start event
    # Leads the story to the crossroads
    #! -- Sets variables:
    # $back_door_opened, $main_door_opened, $spider_door_opened, $confronted_malifor, $treasury_alerted
    id=pursuit
    name= _ "The Pursuit"
    map_data="{campaigns/Northern_Rebirth/maps/the_pursuit.map}"
    # There is no turn limit in the scenario, whole map is underground and a special event needs to occur to achieve victory
    turns=-1
    {UNDERGROUND}
    next_scenario=old_friend
    victory_when_enemies_defeated=no

    {SCENARIO_MUSIC "underground.ogg"}	# No story part
    {EXTRA_SCENARIO_MUSIC "the_deep_path.ogg"}
    {EXTRA_SCENARIO_MUSIC "vengeful.ogg"}
    {EXTRA_SCENARIO_MUSIC "suspense.ogg"}

    # Players side
    [side]
        type=Peasant
        id=Tallin
        name=_ "Tallin"
        canrecruit=yes
        side=1
        controller=human
        {GOLD4 700 600 400 300}
        recruit=Peasant,Woodsman,Thug,Poacher,Footpad
        team_name=rebels
        user_team_name=_"Alliance"
        shroud=yes
    [/side]
    # Main enemy
    [side]
        type=Ancient Lich
        id=Malifor
        name= _ "Malifor"
        profile=portraits/Malifor.png
        canrecruit=yes
        side=2
        team_name=undead
        user_team_name=_"Undead"
        recruit=Deathblade,Revenant,Bone Shooter,Necromancer
        gold=0
    [/side]
    # Enemies to the immediate left and right of the first chamber
    [side]
        type=Death Knight
        id=Hettel
        name=_ "Hettel"
        canrecruit=yes
        side=3
        team_name=undead
        user_team_name=_"Undead"
        {GOLD4 50 100 150 250}
        {INCOME4 4 10 16 22}
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]

    [side]
        type=Death Knight
        id=Thor
        canrecruit=yes
        side=4
        team_name=undead
        user_team_name=_"Undead"
        {GOLD4 50 100 150 250}
        {INCOME4 4 10 16 22}
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]
    # Dungeon guard
    [side]
        type=Death Knight
        id=Trevor
        name=_ "Trevor"
        canrecruit=yes
        side=5
        team_name=undead
        user_team_name=_"Undead"
        gold=0
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]
    # Treasury guards
    [side]
        type=Death Knight
        id=Author
        name=_ "Author"
        canrecruit=yes
        side=6
        team_name=undead
        user_team_name=_"Undead"
        gold=0
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]

    [side]
        type=Death Knight
        id=Sam
        name=_ "Sam"
        canrecruit=yes
        side=7
        team_name=undead
        user_team_name=_"Undead"
        gold=0
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]
    # Study Guards
    [side]
        type=Death Knight
        id=Boblin
        name=_ "Boblin"
        canrecruit=yes
        side=8
        team_name=undead
        user_team_name=_"Undead"
        gold=0
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]

    [side]
        type=Death Knight
        id=Antrasis
        canrecruit=yes
        side=9
        team_name=undead
        user_team_name=_"Undead"
        gold=0
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#endif
#ifdef NORMAL
        recruit=Skeleton,Skeleton Archer,Revenant
#endif
#ifdef HARD
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter
#endif
#ifdef NIGHTMARE
        recruit=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Deathblade
#endif
    [/side]

    [event]
        name=prestart
        # Place images
        # Whole lot of doors
        {PLACE_IMAGE scenery/dwarven-doors-closed.png 23 7}
        {PLACE_IMAGE scenery/dwarven-doors-closed.png 22 9}
        {PLACE_IMAGE scenery/dwarven-doors-closed.png 22 10}
        {PLACE_IMAGE scenery/dwarven-doors-closed.png 27 13}
        {PLACE_IMAGE scenery/dwarven-doors-closed.png 19 2}
        {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}
        {PLACE_IMAGE scenery/dwarven-doors-closed.png 35 34}
        # Prisoners
        {PLACE_IMAGE units/human-magi/white-mage.png 9 40}
        {PLACE_IMAGE items/cage.png 9 40}
        {PLACE_IMAGE "units/human-magi/white-mage+female.png" 6 39}
        {PLACE_IMAGE items/cage.png 6 39}
        {PLACE_IMAGE units/elves-wood/druid.png 3 40}
        {PLACE_IMAGE items/cage.png 3 40}
        {PLACE_IMAGE units/drakes/burner.png 2 32}
        {PLACE_IMAGE items/cage.png 2 32}
        # Corpses in the water.
        {PLACE_IMAGE units/undead/soulless-die-3.png 37 19}
        {PLACE_IMAGE units/undead/soulless-die-3.png 38 13}
        {PLACE_IMAGE units/undead/soulless-die-3.png 35 7}
        {PLACE_IMAGE units/undead/soulless-die-3.png 27 5}
        # Signposts
        {PLACE_IMAGE scenery/signpost.png 15 34}
        {PLACE_IMAGE scenery/signpost.png 15 32}
        {PLACE_IMAGE scenery/signpost.png 25 32}
        {PLACE_IMAGE scenery/signpost.png 24 34}
        {PLACE_IMAGE scenery/signpost.png 24 28}
        {PLACE_IMAGE scenery/signpost.png 19 28}
        {PLACE_IMAGE scenery/signpost.png 15 29}
        {PLACE_IMAGE scenery/signpost.png 34 27}
        {PLACE_IMAGE scenery/signpost.png 32 36}
        # Treasury chests
        {PLACE_IMAGE items/chest.png 6 22}
        {PLACE_IMAGE items/chest.png 17 22}
        {PLACE_IMAGE items/chest.png 17 20}
        {PLACE_IMAGE items/chest.png 5 20}
        {PLACE_IMAGE items/chest.png 6 16}
        {PLACE_IMAGE items/chest.png 9 15}
        # Rod of justice
        {PLACE_IMAGE items/staff.png 3 7}

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

        # 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 confronted_malifor no}
        {VARIABLE treasury_alerted no}
    [/event]

    [event]
        name=start

        # Malifor escapes into shroud
        [hide_unit]
            x=20
            y=39
        [/hide_unit]
        [terrain]
            x=20
            y=39
            terrain=Rr
        [/terrain]
        [message]
            speaker=narrator
            message= _ "Leaving most of the dwarves behind, Tallin and the rest of his party set off to pursue the Sorcerer."
            image=wesnoth-icon.png
        [/message]
        [move_unit_fake]
            type=Ancient Lich
            side=2
            x=20,20,20,20,20,20,20
            y=39,38,37,36,35,34,33
        [/move_unit_fake]
        [unhide_unit]
        [/unhide_unit]
        # Recall some units

        {RECALL_SUPPORTER}
        [role]
            race=dwarf
            role=follower
        [/role]
        [recall]
            role=follower
        [/recall]
        [recall]
            id=Camerin
        [/recall]
        # Set up an army of guarding Draugs, first two have a role
        # for 'sighted' events
        {NOTRAIT_UNIT 6 Draug 10 23}
        [+unit]
            role=Treasury Guard
            ai_special=guardian
        [/unit]
        {NOTRAIT_UNIT 2 Draug 26 19}
        [+unit]
            role=Study Guard
            ai_special=guardian
        [/unit]
        {NOTRAIT_UNIT 2 Draug 18 11} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 20 11} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 20 14} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 21 13} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 23 16} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 23 22} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 23 24} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 24 14} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 26 21} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 26 23} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 26 25} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 28 20} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 28 22} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 28 24} {GUARDIAN}
        {NOTRAIT_UNIT 2 Draug 28 26} {GUARDIAN}
        # And larger army of Revenants
        {NOTRAIT_UNIT 2 Revenant 2 35} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 4 37} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 4 19} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 6 21} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 6 25} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 6 26} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 6 30} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 6 32} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 6 36} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 7 15} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 7 38} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 9 36} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 10 17} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 10 19} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 10 21} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 11 15} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 12 17} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 12 23} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 13 9} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 13 20} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 14 18} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 15 9} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 19 21} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 19 24} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 19 27} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 21 21} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 21 24} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 21 27} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 33 30} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 33 33} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 34 30} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 34 32} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 21 35} {GUARDIAN}
        {NOTRAIT_UNIT 2 Revenant 19 35} {GUARDIAN}
        # Initial dialogue and objectives
        [message]
            speaker=Tallin
            message= _ "There he goes! Quick, get him!"
        [/message]
        [message]
            speaker=Revenant
            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 is only two of them, so they shouldn't last long."
        [/message]
        [objectives]
            side=1
            [objective]
                description= _ "Get past the revenants."
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Tallin"
                condition=lose
            [/objective]
        [/objectives]
    [/event]
    # Player enters the first chamber - some more initial dialogues and objectives
    [event]
        name=moveto
        [filter]
            side=1
            x=19-21
            y=30-32
        [/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= _ " *faint cackle of laughter in the distance*"
        [/message]
        [message]
            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]
        [objectives]
            side=1
            [objective]
                description= _ "Find Malifor and Destroy Him"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Tallin"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    # From this point on we can go in seven directions, one of these
    # leads to enemy castle and has no events involved, another one
    # leads only to holy water storage and as such is merged into
    # study module. Out of the remaining, going clockwise, we have :

    # Prison
    # 1 - Prison - signpost and alarm
    [event]
        name=moveto
        [filter]
            side=1
            x=15
            y=34
        [/filter]

        [message]
            speaker=narrator
            message= _ "The Dungeon"
            image=scenery/signpost.png
        [/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=moveto
        [filter]
            side=1
            x=10-12
            y=35-40
        [/filter]

        [message]
            speaker=Trevor
            message= _ "They are trying to free the prisoners! Stop them!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Good luck, my friend."
        [/message]
        # Allways give 100 gold
        [gold]
            side=5
            amount=100
        [/gold]
        # If the difficulty level is higher than Newbie add another 100
#ifndef EASY
        [gold]
            side=5
            amount=100
        [/gold]
        # And another 150 if higher then Easy
#ifndef NORMAL
        [gold]
            side=5
            amount=150
        [/gold]
        # With last 150 thrown up on Hard
#ifndef HARD
        [gold]
            side=5
            amount=150
        [/gold]
#endif
#endif
#endif
        # Above sums up to Newbie - 100 gold, Easy - 200, Normal - 350 and Hard 500
    [/event]

    # Now freeing the prisoners, there is four of them and the nearest
    # one looking from the entrance is 1a - Father Morvin - free and
    # death event
    # wmllint: recognize Sister Thera
    [event]
        name=moveto
        [filter]
            side=1
            x=9
            y=40
        [/filter]

        # Remove the caged white mage image from hex
        [removeitem]
            x=9
            y=40
        [/removeitem]
        # Spawn unit
        [unit]
            type=White Mage
            side=1
            id=Father Morvin
            name= _ "Father Morvin"
            profile=portraits/Father_Morvin.png
            x=9
            y=39
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
        # Some dialogue
        [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]
                id="Sister Thera"
            [/have_unit]
            [then]
                [message]
                    speaker=Sister Thera
                    message= _ "Morvin!"
                [/message]
                [message]
                    speaker=Father Morvin
                    message= _ "Thera!"
                [/message]
                [message]
                    speaker=unit
                    message= _ "Please, folks, not now."
                [/message]
                [message]
                    speaker=Sister Thera
                    message= _ "Oh, sorry."
                [/message]
            [/then]
            # Else explain how did they end 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= _ "I am called Father 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]
        # Set up a flavour death event for the pair since they can't die in combat (see utils/herodeaths.cfg)
        [event]
            name=die
            [filter]
                id=Father Morvin
            [/filter]

            [message]
                speaker=Tallin
                message= _ "Wow! That's incredible. Now I understand why the Bag of Bones kept you guys in jail; He just simply couldn't kill you!"
            [/message]
            [message]
                speaker=Sister Thera
                message= _ " *giggle*"
            [/message]
        [/event]
    [/event]

    # Next prisoner in line is sister Thera, this event is essentialy
    # a clone of the previous one.
    # 1b - Sister Thera
    [event]
        name=moveto
        [filter]
            side=1
            x=6
            y=39
        [/filter]

        [removeitem]
            x=6
            y=39
        [/removeitem]
        [unit]
            type=White Mage
            gender=female
            id=Sister Thera
            name= _ "Sister Thera"
            profile=portraits/Sister_Thera.png
            side=1
            x=6
            y=38
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
        [/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]
                [message]
                    speaker=unit
                    message= _ "Please, folks, not now."
                [/message]
                [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= _ "I am called Sister 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]
    [/event]

    # Third prisoner
    # 1c - Elenia
    [event]
        name=moveto
        [filter]
            side=1
            x=3
            y=40
        [/filter]

        [removeitem]
            x=3
            y=40
        [/removeitem]
        [unit]
            type=Elvish Druid
            side=1
            id=Elenia
            name= _ "Elenia"
            profile=portraits/Elenia.png
            x=3
            y=39
            hitpoints=1
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_HEALTHY}
            [/modifications]
        [/unit]
        [message]
            speaker=unit
            message= _ "Oh my, she is almost dead!"
        [/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]
                [teleport]
                    [filter]
                        id=Sister Thera
                    [/filter]
                    x=3
                    y=38
                [/teleport]
                {FLASH_WHITE ()}
                [message]
                    speaker=Tallin
                    message= _ "Was that a teleport you just did? Wow, you guys are good!"
                [/message]
                [message]
                    speaker=Father Morvin
                    message= _ " *wink* *wink*"
                [/message]
                [message]
                    speaker=Sister Thera
                    message= _ "Here, this will help her."
                [/message]
                [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, Sister. She is looking better already."
                [/message]
                [message]
                    speaker=Elenia
                    message= _ "And I feel better too. Now let's get back at that disgusting skeleton."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Tallin
                    message= _ "I wish we had some healers with us. Just try to help her the best you can."
                [/message]
                [message]
                    speaker=unit
                    message= _ "Here, I hope that helps."
                [/message]
                [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]
                [sound]
                    name=heal.wav
                [/sound]
                [message]
                    speaker=Elenia
                    message= _ "Oh, just a few tricks I know, otherwise I probably would be dead by now. But let's get back at 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]

    # Fourth prisoner
    # 1d - Krash
    [event]
        name=moveto
        [filter]
            side=1
            x=2
            y=32
        [/filter]

        [removeitem]
            x=2
            y=32
        [/removeitem]
        [unit]
            type=Drake Burner
            id=Krash
            name= _ "Krash"
            side=1
            x=2
            y=33
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
        # I'm not checking for existence of Camerin since the
        # dialogue 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= _ " *whimper*"
        [/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! GRRRRRRRR!!!"	# 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]
        [message]
            speaker=unit
            message= _ "And look at this, there is some sort of opening in the back of his cell..."
        [/message]
        [message]
            speaker=Krash
            message= _ "It's an escape tunnel. The hole wasn't big enough for me to go through but one you little guys you might fit."
        [/message]
        [message]
            speaker=unit
            message= _ "Hmmm, it is pretty small, let's see if we can make it bigger."
        [/message]
        # Open the escape tunnel by replacing wall tile with a cave floor hex
        [terrain]
            x=2
            y=31
            terrain=Uu
        [/terrain]
        [message]
            speaker=unit
            message= _ "There we go. Now let's see where this tunnel leads to."
        [/message]
        # Set up a flavour 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= _ "ROOOOOOAAAARRRR!"	# 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]
        {VARIABLE Krash_alive yes}
    [/event]

    # 1e - Escape tunnel
    # FIXME: On encountering water in the tunnel, this line doesn't make
    # sense when seen before the sequence in flooded_path but fixing
    # that would require breaking the string or introducing a new
    # one. Both had to be avoided at the moment of writing this
    # commentary.
    [event]
        name=moveto
        [filter]
            side=1
            x=3,4,5,5,4
            y=13,13,14,15,15
        [/filter]

        [message]
            speaker=unit
            message= _ " *sigh* Great. More water. And there doesn't seem to be anything down this tunnel, either friend or foe."
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    # 1f - Runaway dwarfs
    # Player meets three dwarves that escaped from the dungeon some
    # time ago, they join the army and show a back entrance to the
    # treasury
    [event]
        name=moveto
        [filter]
            side=1
            x=9,7-10
            y=8-11,10-12
        [/filter]

        # Remove some shroud and place the units
        [remove_shroud]
            x=9,7-10
            y=8-11,10-12
        [/remove_shroud]
        [unit]
            type=Dwarvish Steelclad
            id=Dulcatas
            name= _ "Dulcatas"
            side=1
            x=6
            y=11
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_HEALTHY}
            [/modifications]
        [/unit]
        [unit]
            type=Dwarvish Thunderguard
            id=Antolos
            name= _ "Antolos"
            side=1
            x=8
            y=11
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
        [unit]
            type=Dwarvish Fighter
            id=Varem
            name= _ "Varem"
            side=1
            x=9
            y=12
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
        [message]
            speaker=Dulcatas
            message= _ "Halt! Who goes there? Friend or foe?"
        [/message]
        [message]
            speaker=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=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=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=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=unit
            message= _ "Awesome, let's go!"
        [/message]
        # 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=8
                y=13
            [/filter]

            # Open the back entrance
            [message]
                speaker=unit
                message= _ "Here we go."
            [/message]
            [terrain]
                x=7
                y=14
                terrain=Uu
            [/terrain]
            # If the treasury alarm wasn't raised yet do it now and set the flag
            [if]
                [variable]
                    name=treasury_alerted
                    equals=no
                [/variable]
                [then]
                    [message]
                        role=Treasury Guard
                        message= _ "Intruders! Get them!"
                    [/message]
                    [message]
                        speaker=unit
                        message= _ "Bring it on!"
                    [/message]
                    # For detailed explanation of how these work out
                    # see dungeon alarm event at the top of this file.
                    # Add 100,200,350 or 500 gold to both treasury
                    # guards depending on difficulty level.
                    [gold]
                        side=6
                        amount=100
                    [/gold]
                    [gold]
                        side=7
                        amount=100
                    [/gold]
#ifndef EASY
                    [gold]
                        side=6
                        amount=100
                    [/gold]
                    [gold]
                        side=7
                        amount=100
                    [/gold]
#ifndef NORMAL
                    [gold]
                        side=6
                        amount=150
                    [/gold]
                    [gold]
                        side=7
                        amount=150
                    [/gold]
#ifndef HARD
                    [gold]
                        side=6
                        amount=150
                    [/gold]
                    [gold]
                        side=7
                        amount=150
                    [/gold]
#endif
#endif
#endif
                    # Set the flag
                    {VARIABLE treasury_alerted yes}
                [/then]
            [/if]
        [/event]
    [/event]

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

        [message]
            speaker=narrator
            message= _ "The Treasury"
            image=scenery/signpost.png
        [/message]
        [message]
            speaker=unit
            message= _ "The Treasury! Cool, let's go loot some booty!"
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    # 2a - Alarm

    # If alarm wasn't raised, yet raise it on first sight of treasury
    # guard. It should probably work the other way around, but I
    # promised not to alter scenario behaviour. To much at least.
    [event]
        name=sighted

        [filter]
            role=Treasury Guard
        [/filter]

        [if]
            [variable]
                name=treasury_alerted
                equals=no
            [/variable]
            [then]
                [message]
                    role=Treasury Guard
                    message= _ "Intruders! Get them!"
                [/message]
                [message]
                    role=Supporter
                    message= _ "Bring it on!"
                [/message]

                # Add 100,200,350,500 gold to treasury guards. See dungeon alarm in
                # prison.cfg for more detailed explanation of behaviour
                [gold]
                    side=6
                    amount=100
                [/gold]
                [gold]
                    side=7
                    amount=100
                [/gold]
#ifndef EASY
                [gold]
                    side=6
                    amount=100
                [/gold]
                [gold]
                    side=7
                    amount=100
                [/gold]
#ifndef NORMAL
                [gold]
                    side=6
                    amount=150
                [/gold]
                [gold]
                    side=7
                    amount=150
                [/gold]
#ifndef HARD
                [gold]
                    side=6
                    amount=150
                [/gold]
                [gold]
                    side=7
                    amount=150
                [/gold]
#endif
#endif
#endif
                # Set the flag
                {VARIABLE treasury_alerted yes}
            [/then]
        [/if]
    [/event]

    # 2b - Gold chests
    # And the main feature of this room. Gold. Each event gives a
    # determined amount of gold and removes a chest.
    [event]
        name=moveto
        [filter]
            x=17
            y=22
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "Wow! There is at least 1000 gold in here!"
        [/message]
        [gold]
            side=1
            amount=1025
        [/gold]
        [removeitem]
            x=17
            y=22
        [/removeitem]
    [/event]

    [event]
        name=moveto
        [filter]
            x=17
            y=20
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "Holy Gods of Light! 500 gold!"
        [/message]
        [gold]
            side=1
            amount=505
        [/gold]
        [removeitem]
            x=17
            y=20
        [/removeitem]
    [/event]

    [event]
        name=moveto
        [filter]
            x=6
            y=22
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "800 gold! We're rich!!!"
        [/message]
        [gold]
            side=1
            amount=800
        [/gold]
        [removeitem]
            x=6
            y=22
        [/removeitem]
    [/event]

    [event]
        name=moveto
        [filter]
            x=5
            y=20
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "What a hoard! 2,000 gold!"
        [/message]
        [gold]
            side=1
            amount=2000
        [/gold]
        [removeitem]
            x=5
            y=20
        [/removeitem]
    [/event]

    [event]
        name=moveto
        [filter]
            x=6
            y=16
            side=1
        [/filter]

        [message]
            speaker=unit
            message= _ "500 gold! Not bad!"
        [/message]
        [gold]
            side=1
            amount=510
        [/gold]
        [removeitem]
            x=6
            y=16
        [/removeitem]
    [/event]

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

        [message]
            speaker=unit
            message= _ "10,000 gold! Wow! Where is that bag of bones getting all this?"
        [/message]
        [gold]
            side=1
            amount=10151
        [/gold]
        [removeitem]
            x=9
            y=15
        [/removeitem]
    [/event]

    # The Great Chamber
    #! -- Sets variables:
    # $chamber_of_death
    # 3 - The Great Chamber - signpost
    [event]
        name=moveto
        [filter]
            side=1
            x=19
            y=28
        [/filter]

        [message]
            speaker=narrator
            message= _ "The Great Chamber"
            image=scenery/signpost.png
        [/message]
        [message]
            speaker=unit
            message= _ " 'The Great Chamber'? Hmmm, wonder what that could be."
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    # 3a - 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
            y=1-5
        [/filter]

        [message]
            speaker=unit
            message= _ "So this is the Great Chamber eh? Doesn't look like there is much to see here."
        [/message]
        # This macro should shake the screen
        {QUAKE "rumble.ogg"}
        [message]
            speaker=narrator
            message= _ " *rumble*"
            image=misc/empty.png	# Stop wmllint from inserting the Wesnoth logo here
        [/message]
        [message]
            speaker=unit
            message= _ "Perhaps I spoke too soon..."
        [/message]
        {QUAKE "cave-in.ogg"}
        {QUAKE "cave-in.ogg"}
        [message]
            speaker=narrator
            message= _ " *CRASH*"
            image=misc/empty.png	# Stop wmllint from inserting the Wesnoth logo here
        [/message]
        [message]
            speaker=unit
            message= _ "What was that? Oh, woe - two big slabs of rock cutting off our retreat!"
        [/message]
        # Cutting off the exit
        [terrain]
            x=13,15
            y=14,14
            terrain=Xu
        [/terrain]

        # Spawning spiders 9,13,17 or 21 depending on difficulty
        # levels split in half on both sides of the chamber
        {NOTRAIT_UNIT 2 "Giant Spider" 23 4}
        {NOTRAIT_UNIT 2 "Giant Spider" 22 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 22 4}
        {NOTRAIT_UNIT 2 "Giant Spider" 20 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 21 5}
        {NOTRAIT_UNIT 2 "Giant Spider" 6 2}
        {NOTRAIT_UNIT 2 "Giant Spider" 6 4}
        {NOTRAIT_UNIT 2 "Giant Spider" 6 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 5 5}
#ifndef EASY
        {NOTRAIT_UNIT 2 "Giant Spider" 23 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 24 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 5 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 5 2}
#ifndef NORMAL
        {NOTRAIT_UNIT 2 "Giant Spider" 20 2}
        {NOTRAIT_UNIT 2 "Giant Spider" 21 3}
        {NOTRAIT_UNIT 2 "Giant Spider" 8 2}
        {NOTRAIT_UNIT 2 "Giant Spider" 8 3}
#ifndef HARD
        {NOTRAIT_UNIT 2 "Giant Spider" 21 4}
        {NOTRAIT_UNIT 2 "Giant Spider" 25 4}
        {NOTRAIT_UNIT 2 "Giant Spider" 4 2}
        {NOTRAIT_UNIT 2 "Giant Spider" 3 3}
#endif
#endif
#endif
        {QUAKE "cave-in.ogg"}
        {QUAKE "cave-in.ogg"}
        [message]
            speaker=narrator
            message= _ " *CRASH*"
            image=misc/empty.png	# Stop wmllint from inserting a Wesnoth logo here
        [/message]
        # Break some walls exposing side tunnels
        [terrain]
            x=19,19,19,9,9
            y=2,3,4,3,4
            terrain=Uu
        [/terrain]
        [message]
            speaker=Giant Spider
            message= _ "Hsssssssss"	# wmllint: no spellcheck
        [/message]
        [message]
            speaker=unit
            message= _ "This doesn't look good."
        [/message]
        [message]
            role=Supporter
            message= _ "Great Chamber my foot! This is a Death Chamber!"
        [/message]
        # Set a flag required by entering the study event
        {VARIABLE chamber_of_death visited}
    [/event]

    # 3b - Rod of Justice
    # At the end of the left side corridor. Uberpowerfull artifact
    # that can be picked up by any unit with exception of Abhai.
    [event]
        name=moveto
        [filter]
            side=1
            x=3
            y=7
        [/filter]
        [if]
            [variable]
                name=unit.id
                equals=Abhai
            [/variable]
            [then]
                {INCIDENTAL_MUSIC "sad.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 by men, 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 ravish 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 Scepter 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]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Wow! This thing is... incredible!"
                [/message]
                [message]
                    speaker=unit
                    message= _ "I wonder what such a powerful artifact is 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
                [removeitem]
                    x=3
                    y=7
                [/removeitem]
                # Apply the effects
                [object]
                    id=justice_rod
                    name= _ "Rod of Justice"
                    image=attacks/staff-magic.png
                    duration=forever
                    description= _ "This is 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 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
                    [/effect]
                    # The cool animation mentioned above, a copypasted 
                    # fragment from Delfador's attack
                    [effect]
                        apply_to=new_animation
                        [attack_anim]
                            [filter_attack]
                                name=rod of justice
                            [/filter_attack]
                            {LIGHTNING_BOLT 1}
                            [if]
                                hits=no
                                [frame]
                                    begin=-200
                                    end=0
                                    sound=lightning-miss.ogg
                                [/frame]
                            [/if]
                            [else]
                                hits=yes
                                [frame]
                                    begin=-200
                                    end=0
                                    sound=lightning.ogg
                                [/frame]
                            [/else]
                        [/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]
            [/else]
        [/if]
    [/event]

    # Malifor's Study and holy-water storage.
    # Nothing hard in this module either, mostly dialogues. The alarm
    # event is a clone of the other alarms.

    # 4 - Signpost
    [event]
        name=moveto
        [filter]
            side=1
            x=24
            y=28
        [/filter]

        [message]
            speaker=narrator
            message= _ "Malifor the Great's Study"
            image=scenery/signpost.png
        [/message]
        [message]
            speaker=unit
            message= _ "There we go! This way guys!"
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    # 4a - Holy water storage
    [event]
        name=moveto
        [filter]
            side=1
            x=34
            y=27
        [/filter]

        [message]
            speaker=narrator
            message= _ "Warning! These bottles contain toxic waste. Causes disintegration on contact."
            image=scenery/signpost.png
        [/message]
        [message]
            speaker=unit
            message= _ "Ha ha, for skeletons anyway."
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=32
            y=36
        [/filter]

        [message]
            speaker=narrator
            message= _ "Warning! These bottles contain toxic waste. Causes disintegration on contact."
            image=scenery/signpost.png
        [/message]
        [message]
            speaker=unit
            message= _ " *rolls eyes* Oh the hazardous life of a skeleton."
        [/message]
        [allow_undo][/allow_undo]
    [/event]

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

        [message]
            speaker=unit
            message= _ "A door, and a big, big lock, hmmmmm..."
        [/message]
        [message]
            speaker=unit
            message= _ "Sorry folks, this is just too tempting."
        [/message]
        [message]
            speaker=unit
            message= _ " *SMASH*"
        [/message]
        [terrain]
            x=34
            y=28
            terrain=Uu
        [/terrain]
    [/event]

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

        [message]
            speaker=unit
            message= _ "Hmmmm, this door sure is locked up pretty tight. I wonder what's behind it."
        [/message]
        [message]
            speaker=unit
            message= _ " *SMASH*"
        [/message]
        [terrain]
            x=35
            y=34
            terrain=Uu
        [/terrain]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=33,33,34,31,32,33
            y=28,27,26,37,37,37
        [/filter]

        [if]
            [variable]
                name=y1
                less_than=30
            [/variable]
            [then]
                [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]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Oh yeah, holy water!"
                [/message]
            [/else]
        [/if]
    [/event]

    # 4b - Study alarm
    [event]
        name=sighted
        [filter]
            role=Study Guard
        [/filter]

        [message]
            role=Study Guard
            message= _ "They are attacking the master's study! We must stop them! Call the reserves!"
        [/message]
        [message]
            speaker=second_unit
            message= _ " 'The master's study' eh? I bet we'll find Malifor there!"
        [/message]
        [gold]
            side=8
            amount=100
        [/gold]
        [gold]
            side=9
            amount=100
        [/gold]
#ifndef EASY
        [gold]
            side=8
            amount=100
        [/gold]
        [gold]
            side=9
            amount=100
        [/gold]
#ifndef NORMAL
        [gold]
            side=8
            amount=150
        [/gold]
        [gold]
            side=9
            amount=150
        [/gold]
#ifndef HARD
        [gold]
            side=8
            amount=150
        [/gold]
        [gold]
            side=9
            amount=500
        [/gold]
#endif
#endif
#endif
    [/event]

    # The flooded path

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

        [message]
            speaker=narrator
            message= _ "Caution! Tunnel flooded and infested with aquatic monsters. Enter at the risk of your life."
            image=scenery/signpost.png
        [/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]

    # Which pointed towards the lake with a creepy tentacled monster...
    # 5a - Monster of the lake
    [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 2 "Tentacle of the Deep" 35 23}
        {NOTRAIT_UNIT 2 "Tentacle of the Deep" 33 25}
        {NOTRAIT_UNIT 2 "Tentacle of the Deep" 33 23}
#ifndef EASY
        {NOTRAIT_UNIT 2 "Tentacle of the Deep" 34 21}
#ifndef NORMAL
        {NOTRAIT_UNIT 2 "Tentacle of the Deep" 31 23}
#ifndef HARD
        {NOTRAIT_UNIT 2 "Tentacle of the Deep" 32 22}
#endif
#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 stray into the side tunnel you might see a ghost...
    # 5b - Runaway spectre
    [event]
        name=moveto
        [filter]
            side=1
            x=28
            y=28
        [/filter]

        [message]
            speaker=unit
            message= _ "Hmm, what is this thing?"
        [/message]
        [unit]
            type=Wraith
            side=1
            x=29
            y=29
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
            id=Abhai
            name= _ "Abhai"
            #profile=Abhai.png
        [/unit]
        [message]
            speaker=Abhai
            message= _ "EEEEEEEEEEEEEEEE!"	# wmllint: no spellcheck
        [/message]
        [message]
            speaker=unit
            message= _ "AHHHHHHHHH!"	# wmllint: no spellcheeck
        [/message]
        [message]
            speaker=Abhai
            message= _ "... wait a second, who are you?"
        [/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= _ "I am."
        [/message]
        [message]
            speaker=Abhai
            message= _ "What is your purpose in coming here?"
        [/message]
        [message]
            speaker=Tallin
            message= _ "We seek the lich Malifor."
        [/message]
        [message]
            speaker=Abhai
            message= _ "Malifor!... *goes a bit paler (if possible)* What business do you have with him?"
        [/message]
        [message]
            speaker=Tallin
            message= _ "We seek to crush and destroy him."
        [/message]
        # wmllint: local spellings Kalian Hiera'Shirsha
        [message]
            speaker=Abhai
            message= _ "Oh, thank the Gods of Light! Finally there is someone here in force to deal with that menace. You must have been sent by the High Kalian of Hiera'Shirsha?"
        [/message]
        [message]
            speaker=Tallin
            message= _ "The what!?"
        [/message]
        [message]
            speaker=Camerin
            message= _ "Err, I think we might be in different... uh... time zones, here."
        [/message]
        [message]
            speaker=Abhai
            message= _ "I beg your pardon. Say, what year is it anyway?"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Uh... 534 YW..."
        [/message]
        [message]
            speaker=Abhai
            message= _ "Huh!? Can't be, the last year I remember it was 14,318 AD!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "?????"
        [/message]
        [message]
            speaker=Camerin
            message= _ "Different calendars, folks."
        [/message]
        [message]
            speaker=Tallin
            message= _ "I see, but say, who are you?"
        [/message]
        [message]
            speaker=Abhai
            message= _ "What? How can you not know who I am?"
        [/message]
        [message]
            speaker=Tallin
            message= _ "The times have changed, my friend."
        [/message]
        [message]
            speaker=Abhai
            # wmllint: local spelling Garet-Desh
            message= _ "Right... sorry about that. My name is Lord Abhai and I am... or was... the ruler of the great kingdom of Garet-Desh."
        [/message]
        [message]
            speaker=Tallin
            message= _ "What happened to you? Why are you a ghost?"
        [/message]
        [message]
            speaker=Abhai
            # wmllint: local spelling ectoplasmic
            message= _ "I grew old and died as all men do and entered the land of the dead. I don't know how long I dwelt there, I was wrenched from my peace and forced into this ectoplasmic body by a terrible power."
        [/message]
        [message]
            speaker=Tallin
            message= _ "Let me guess. Malifor?"
        [/message]
        [message]
            speaker=Abhai
            message= _ "Indeed. He tried to break my spirit 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= _ "Would you join us to defeat this evil creature?"
        [/message]
        [message]
            speaker=Abhai
            message= _ "Wouldn't miss it. Maybe after he is destroyed me and my kind can live... err.... 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]
    [/event]

    # And going forward is a sure way to find some bodies
    # 5c - A string of corpses
    [event]
        name=moveto
        [filter]
            side=1
            x=37
            y=19
        [/filter]

        [message]
            speaker=unit
            message= _ "Ugh, a dead body!"
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=38
            y=13
        [/filter]

        [message]
            speaker=unit
            message= _ "Here's another body."
        [/message]
        [allow_undo][/allow_undo]
    [/event]

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

        [message]
            speaker=unit
            message= _ "And another..."
        [/message]
        [allow_undo][/allow_undo]
    [/event]

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

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

    # 5d - A dead end
    [event]
        name=moveto
        [filter]
            side=1
            x=38
            y=16
        [/filter]

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

    # And a sea serpent
    # 5e - Sea serpent
    [event]
        name=moveto
        [filter]
            side=1
            x=32-34
            y=4-6
        [/filter]

        [message]
            speaker=unit
            # wmllint: local spelling Ssssh
            message= _ "Ssssh! I hear something."
        [/message]
        {NOTRAIT_UNIT 2 "Sea Serpent" 31 5}
        [message]
            type=Sea Serpent
            message= _ "ROOOAAARRR!"	# wmllint: no spellcheck
        [/message]
        [message]
            speaker=unit
            message= _ "Ahhhhh!"
        [/message]
    [/event]

    # Eventually you'll always find some bad guy sidekicks. Just waiting to get mauled...
    # 5f - Naga guardians
    [event]
        name=moveto
        [filter]
            side=1
            x=28,29,30,30
            y=7,8,8,9
        [/filter]

        [message]
            speaker=unit
            message= _ "Hold it, people, there is something just ahead!"
        [/message]
        {GENERIC_UNIT 2 "Naga Warrior" 28 11}
        {GENERIC_UNIT 2 "Naga Fighter" 28 11}
#ifndef EASY
        {GENERIC_UNIT 2 "Naga Fighter" 29 10}
#ifndef NORMAL
        {GENERIC_UNIT 2 "Naga Fighter" 29 11}
#ifndef HARD
        {GENERIC_UNIT 2 "Naga Fighter" 29 12}
#endif
#endif
#endif
        [remove_shroud]
            x=28-30
            y=8-12
        [/remove_shroud]
        [message]
            type=Naga Warrior
            message= _ " *sniff* I smell humans."
        [/message]
        [message]
            speaker=Naga Fighter
            message= _ "You are just plain deaf. I heard them coming from a mile off."
        [/message]
        [message]
            speaker=Naga Warrior
            message= _ "Ahh, shut up. Let's go kill them."
        [/message]
    [/event]

    # All of the above will ultimately lead to a door and a final confrontation.
    #! -- Clears variables:
    # $back_door_opened, $main_door_opened, $spider_door_opened,
    # $confronted_malifor, $treasury_alerted, $chamber_of_death

    # This event handles the opening of the doors to Malifor's
    # study. Since there are three pairs of them and player can choose
    # not to open them immediately it's somewhat complicated and long.
    [event]
        name=moveto
        first_time_only=no
        # The doors can be opened from following coordinates : spider (23,6), main [(21,9) (21,10) (21,11)], back (28,12)
        [filter]
            side=1
            x=23,28,21,21,21
            y=6,12,9,10,11
        [/filter]

        # This variable will tell us wether player decided to open the door, initialy set to no
        {VARIABLE open_the_door no}
        [if]
            # If we're at spider door (y==6) and they're still closed...
            [variable]
                name=spider_door_opened
                equals=no
            [/variable]
            [variable]
                name=y1
                equals=6
            [/variable]
            # Give the player option to open them
            [then]
                [message]
                    speaker=unit
                    message= _ "Hmmm, another door. Boy, is this one sure locked up."
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Anything you can't handle?"
                [/message]
                [message]
                    speaker=unit
                    message= _ "Nope. Should I open it?"
                    [option]
                        message= _ "Go for it!"
                        [command]
                            [message]
                                speaker=narrator
                                message= _ " *CRASH*"
                                image=misc/empty.png	# Stop wmllint from inserting Wesnoth logo
                            [/message]
                            [terrain]
                                x=23
                                y=7
                                terrain=Uu
                            [/terrain]
                            # Set the flags for future reference, player decided to open a door and it was the spider one
                            {VARIABLE open_the_door yes}
                            {VARIABLE spider_door_opened yes}
                            [message]
                                speaker=unit
                                message= _ "There we go."
                            [/message]
                        [/command]
                    [/option]
                    [option]
                        message= _ "Just wait a sec."
                        [command]
                            [message]
                                speaker=unit
                                message= _ "Very well."
                            [/message]
                        [/command]
                    [/option]
                [/message]
            [/then]
        [/if]
        [if]
            # If we're at the main door (8<y<12) and the door are closed
            [variable]
                name=main_door_opened
                equals=no
            [/variable]
            [variable]
                name=y1
                greater_than=8
            [/variable]
            [variable]
                name=y1
                less_than=12
            [/variable]
            [then]
                [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]
                        message= _ "Yeah, open those doors!"
                        [command]
                            {VARIABLE open_the_door yes}
                            {VARIABLE main_door_opened yes}
                            [message]
                                speaker=narrator
                                message= _ " *CRASH*"
                                image=misc/empty.png	# Stop wmllint from inserting a logo here
                            [/message]
                            [terrain]
                                x=22,22
                                y=9,10
                                terrain=Uu
                            [/terrain]
                            [message]
                                speaker=unit
                                message= _ "There we go."
                            [/message]
                        [/command]
                    [/option]
                    [option]
                        message= _ "Just wait a sec."
                        [command]
                            [message]
                                speaker=unit
                                message= _ "Very well."
                            [/message]
                        [/command]
                    [/option]
                [/message]
            [/then]
        [/if]
        # If we're at the back door (y==28) and they're closed
        [if]
            [variable]
                name=back_door_opened
                equals=no
            [/variable]
            [variable]
                name=y1
                equals=12
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "Hey, check this out, it looks like some sort of lever."
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Probably for that door right there."
                [/message]
                [message]
                    speaker=unit
                    message= _ "Should I throw it?"
                    [option]
                        message= _ "Go for it!"
                        [command]
                            {VARIABLE open_the_door yes}
                            {VARIABLE back_door_opened yes}
                            [message]
                                speaker=unit
                                message= _ "Here we go!"
                            [/message]
                            [message]
                                speaker=unit
                                message= _ " *creak*....."
                            [/message]
                            [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]
                            [message]
                                speaker=unit
                                message= _ " *BANG*"
                            [/message]
                            [message]
                                speaker=unit
                                message= _ "Anybody home?"
                            [/message]
                            [message]
                                speaker=unit
                                message= _ " *BOOM*"
                            [/message]
                            [message]
                                speaker=unit
                                message= _ " *CRASH!!!*"
                            [/message]
                            [terrain]
                                x=27
                                y=13
                                terrain=Uu
                            [/terrain]
                            [message]
                                speaker=unit
                                message= _ "There we go."
                            [/message]
                        [/command]
                    [/option]
                    [option]
                        message= _ "Just wait a sec."
                        [command]
                            [message]
                                speaker=unit
                                message= _ "Very well."
                            [/message]
                        [/command]
                    [/option]
                [/message]
            [/then]
        [/if]
        # Now opening the door will trigger the confrontation with Malifor
        # if it didn't happen yet. For this reason we check if player
        # decided to open one, and if that confrontation has taken place yet.
        [if]
            [variable]
                name=open_the_door
                equals=yes
            [/variable]
            [variable]
                name=confronted_malifor
                equals=no
            [/variable]
            [then]
                # Set a flag to prevent the confrontation form getting triggered more than once
                {VARIABLE confronted_malifor yes}
                [remove_shroud]
                    x=23-26
                    y=8-13
                [/remove_shroud]
                [message]
                    speaker=Malifor
                    message= _ "You wretched vermin, I have had it with you! Guards!"
                [/message]
                # Give malifor 4 guards and 150 gold at Newbie
                {NOTRAIT_UNIT 2 Deathblade 25 11}
                {NOTRAIT_UNIT 2 Deathblade 25 11}
                {NOTRAIT_UNIT 2 Lich 25 11}
                {NOTRAIT_UNIT 2 Lich 25 11}
                [gold]
                    side=2
                    amount=150
                [/gold]
                # 6 guards and 200 gold at Easy
#ifndef EASY
                {NOTRAIT_UNIT 2 Deathblade 25 11}
                {NOTRAIT_UNIT 2 Lich 25 11}
                [gold]
                    side=2
                    amount=50
                [/gold]
                # 8 guards and 300 gold at Normal
#ifndef NORMAL
                {NOTRAIT_UNIT 2 Deathblade 25 11}
                {NOTRAIT_UNIT 2 Lich 25 11}
                [gold]
                    side=2
                    amount=100
                [/gold]
                # 10 guards and 400 gold at Hard
#ifndef HARD
                {NOTRAIT_UNIT 2 Deathblade 25 11}
                {NOTRAIT_UNIT 2 Lich 25 11}
                [gold]
                    side=2
                    amount=100
                [/gold]
#endif
#endif
#endif
                [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, for this reason we need
                # to check for their presence.  I'm not assuming that
                # they might have died, but they might not have been
                # freed at this point.
                [if]
                    [have_unit]
                        id=Father Morvin
                    [/have_unit]
                    [or]
                        [have_unit]
                            id=Sister Thera
                        [/have_unit]
                    [/or]
                    [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]

                # This piece turns castles at the side of great
                # chamber into road to prevent recruiting or falling
                # back to them if the player comes from that direction
                [if]
                    [variable]
                        name=chamber_of_death
                        equals=visited
                    [/variable]
                    [then]
                        [terrain]
                            x=19,19,19,9,9
                            y=2,3,4,3,4
                            terrain=Rr
                        [/terrain]
                    [/then]
                [/if]
            [/then]
        [/if]
        {CLEAR_VARIABLE open_the_door}
    [/event]

    [event]
        name=last breath
        first_time_only=no
        [filter]
            id=Malifor
        [/filter]
        [filter_second_attack]
            type=impact
        [/filter_second_attack]
        [if]
            [variable]
                name=second_unit.race
                equals=dwarf
            [/variable]
            [then]
                {VARIABLE malifor_died_by axe}
                {VARIABLE malifor_will_respawn_at_x 23}
                {VARIABLE malifor_will_respawn_at_y 4}
            [/then]
            [else]
                {VARIABLE malifor_died_by arrow}
                {VARIABLE malifor_will_respawn_at_x 5}
                {VARIABLE malifor_will_respawn_at_y 2}
            [/else]
        [/if]
    [/event]

#define MALICORS_LAST_BREATH TYPE X Y
    [event]
        name=last breath
        first_time_only=no
        [filter]
            id=Malifor
        [/filter]
        [filter_second_attack]
            type={TYPE}
        [/filter_second_attack]
        {VARIABLE malifor_died_by {TYPE}}
        {VARIABLE malifor_will_respawn_at_x {X}}
        {VARIABLE malifor_will_respawn_at_y {Y}}
    [/event]
#enddef

    {MALICORS_LAST_BREATH pierce 5 2}
    {MALICORS_LAST_BREATH blade 14 4}
    {MALICORS_LAST_BREATH fire 30 11}
    {MALICORS_LAST_BREATH cold 30 11}
    {MALICORS_LAST_BREATH arcane 30 11}

    # Malifor can be successfully killed only by White Mages, all other
    # units only cause him to respawn somewhere on the map. This event
    # handles that assumption
    [event]
        name=die
        first_time_only=no
        [filter]
            id=Malifor
        [/filter]

        # And finally, overriding the white mages and calling scenario end
        # White Mage, Mage of Light.
        [if]
            [variable]
                name=second_unit.id
                equals=Father Morvin
            [/variable]
            [or]
                [variable]
                    name=second_unit.id
                    equals=Sister Thera
                [/variable]
            [/or]
            [then]
                [message]
                    speaker=Malifor
                    message= _ "AHHHHHH! 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]
                [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]
                {CLEAR_VARIABLE malifor_will_respawn_at_x}
                {CLEAR_VARIABLE malifor_will_respawn_at_y}
                {CLEAR_VARIABLE malifor_died_by}
                [endlevel]
                    result=victory
                    bonus=yes
                [/endlevel]
            [/then]
        [/if]

        # default spawn location
        [if]
            [variable]
                name=malifor_will_respawn_at_x
                less_than=1
            [/variable]
            [then]
                {VARIABLE malifor_will_respawn_at_x 23}
                {VARIABLE malifor_will_respawn_at_y 4}
            [/then]
        [/if]
        # If Malifor wasn't killed by white mages, respawn him at the
        # location set previously and give him some extra gold.
        [unit]
            type=Ancient Lich
            id=Malifor
            name= _ "Malifor"
            profile=portraits/Malifor.png
            canrecruit=yes
            side=2
            recruit=Skeleton,Skeleton Archer
            x=$malifor_will_respawn_at_x
            y=$malifor_will_respawn_at_y
        [/unit]
        [gold]
            side=2
            amount=300
        [/gold]
        [terrain]
            x=13,14
            y=14,14
            terrain=Uu
        [/terrain]

        [switch]
            variable=malifor_died_by
            [case]
                value=axe
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHA, FOOLS, YOU THINK YOU CAN KILL ME?"
                [/message]
                {FLASH_WHITE ()}
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHAHAHA!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "What the...!"
                [/message]
                [message]
                    speaker=second_unit
                    message= _ "How can it be?! Our axes and hammers are failing."
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Blast it! Now where did he go? Let's find him and try something else!"
                [/message]
            [/case]
            [case]
                value=blade
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHAHA, DEATH HAS NO EFFECT ON ME YOU FOOLS!"
                [/message]
                {FLASH_WHITE ()}
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHA, I CAN NEVER BE DESTROYED!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Oh yes you will! But... how?"
                [/message]
                [message]
                    speaker=second_unit
                    message= _ "Well, it sure isn't gonna be done with a blade."
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "And look, he's gone. Now we gotta find him all over again!"
                [/message]
            [/case]
            [case]
                value=pierce
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHAHA, YOUR IDIOCY AMUSES ME GREATLY!"
                [/message]
                {FLASH_WHITE ()}
                [message]
                    speaker=Malifor
                    message= _ "COME AND GET ME!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Geez, how are we going to kill him?"
                [/message]
                [message]
                    speaker=second_unit
                    message= _ "Well, obviously clubs and arrows won't work."
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Oh darn, he disappeared. Let's find him and try a different weapon."
                [/message]
            [/case]
            [case]
                value=fire
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHAHA, I AM IMMORTAL!"
                [/message]
                {FLASH_WHITE ()}
                [message]
                    speaker=Malifor
                    message= _ "YOU PUNY MORTALS SHALL SOON BE SERVING ME!"
                [/message]
                [message]
                    speaker=Camerin
                    message= _ "That blasted skeleton! Even fire has no affect on him!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Look, he disappeared again. Let's find him and try using a different weapon on him."
                [/message]
            [/case]
            [else]
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHA, FOOLS, YOU THINK YOU CAN KILL ME?"
                [/message]
                {FLASH_WHITE ()}
                [message]
                    speaker=Malifor
                    message= _ "HAHAHAHAHAHAHA!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "What the...!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "Blast it! Now where did he go? Let's find him and try something else!"
                [/message]
            [/else]
        [/switch]
        [if]
            [have_unit]
                id=Father Morvin
            [/have_unit]
            [have_unit]
                id=Sister Thera
            [/have_unit]
            [then]
                [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= _ " *giggle* Sorry."
                [/message]
            [/then]
        [/if]
        {CLEAR_VARIABLE malifor_will_respawn_at_x}
        {CLEAR_VARIABLE malifor_will_respawn_at_y}
        {CLEAR_VARIABLE malifor_died_by}
    [/event]

    [event]
        name=victory
        {CLEAR_VARIABLE back_door_opened}
        {CLEAR_VARIABLE main_door_opened}
        {CLEAR_VARIABLE spider_door_opened}
        {CLEAR_VARIABLE confronted_malifor}
        {CLEAR_VARIABLE treasury_alerted}
        {CLEAR_VARIABLE chamber_of_death}
    [/event]

    # And the usual batch of hero death macros
    {campaigns/Northern_Rebirth/utils/herodeaths.cfg}
[/scenario]
