#textdomain wesnoth-did

[scenario]
    id=11_Descent_into_Darkness
    name= _ "Descent into Darkness"
    map_data="{campaigns/Descent_Into_Darkness/maps/11a_Descent_into_Darkness.map}"
    turns=unlimited
    next_scenario=12_Endless_Night
    victory_when_enemies_defeated=no

    {UNDERGROUND}

    {INTRO_AND_SCENARIO_MUSIC heroes_rite.ogg underground.ogg}

    # This is a 3 part scenario that goes as follows (SPOILERS HERE)
    # Part 1 - Malin completes the ritual that is his declension into lichdom
    #       Gameplay - fight against ghouls+corpses, skeletons, then ghosts in that order
    #       Stand on runes that will give you buffs that help you beat the ritual
    # Part 2 - explore the new lair and complete some puzzles
    #       Puzzles give some small dmg bonuses
    #       You can regain health and get some exp from creeps, but be wary of the giant spider lurking somewhere
    # Part 3 - Boss battle with fire dragon
    #       Fight against respawning fire elementals, step onto runes to gain some free units (differs depending on rune)
    #       You get 3 ghost-type units (from recall list) that will help you
    #       When you defeat the dragon, you will get a special skeletal dragon with feeding

    [story]
        [part]
            story= _ "<i>“To become a lich, one must first die.”</i>"
            {STORYTXT_BACKGROUND book.jpg}
        [/part]
        [part]
            story= _ "So reads the book that Malin has reclaimed. <i>“The spells of necromancy can free the spirit from the limitations of the flesh, but only once the soul has been unbound from the body. The necromancer must make the necessary incantations with his dying breaths, then conquer his own spirit much the same way he binds the spirits of others. Because he retains his own will, however, the lich can call upon the awesome powers of the spirit world.”</i>"
            {STORYTXT_BACKGROUND book.jpg}
        [/part]
        [part]
            story= _ "Malin closes the book. After all this time and all that he has struggled for, could he just surrender to despair and perish? Could he... would he just give up, just like that? Still, the words, that terrifying idea, stick in the back of his mind. Life has offered him nothing; could death be any worse? Death... and not rebirth, but undeath."
            {STORYTXT_BACKGROUND book.jpg}
        [/part]
        [part]
            story= _ "With all of Wesnoth forbidden to him, Malin finds refuge in a secluded frontier village where few questions are asked. When word eventually filters to the town that Parthyn has been overrun by orcs, Malin rouses himself from his listless state without really knowing why, and heads northward."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story= _ "Malin soon finds the track of an enormous orc army and follows them until he reaches their camps. As he sees the number of orcs, he begins to realize the futility of his quest — harassing and harrying one clan of orcs is a far different task than waging a truly meaningful war against them as a whole. Then again, perhaps he is beyond the point of ordinary reason."
            {STORYTXT_BACKGROUND end.jpg}
        [/part]
        [part]
            story= _ "<i>There is nothing else left for me to do anyway,</i> Malin thinks, and raises his undead to assault the camp. Within mere minutes, nearly his entire army is destroyed and he is badly injured by a poisoned dagger. Malin retreats and finds refuge in a small cave."
            {STORYTXT_BACKGROUND end.jpg}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_11_NEW}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=
        gold=0
        team_name=good
        village_gold=0
        village_support=4
        user_team_name= _ "Malin Keshar"
        {FLAG_VARIANT undead}

        income=-2

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

        facing=ne
        fog=yes
        shroud=yes
    [/side]

    # wmllint: validate-on

    [side]
        side=2
        controller=ai
        no_leader=yes
        hidden=yes
        gold=0
        income=-2
        team_name=monsters
        color=black
        [ai]
            aggression=1.0
            caution=0.0
            grouping=no
            simple_targeting=yes
            village_value=0
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=100
            [/goal]
        [/ai]
    [/side]

    # Monsters
    [side]
        side=3
        team_name=monsters
        gold=0
        controller=ai
        no_leader=yes
        hidden=yes
        income=-2

        fog=yes
        shroud=yes
        [ai]
            aggression=0.9
            caution=0.1
            grouping=no
            simple_targeting=yes
            village_value=0
        [/ai]
    [/side]

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        [store_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            variable=malin
        [/store_unit]

        [kill]
            id=Malin Keshar
        [/kill]

        [unit]
            id=Malin Keshar
            name= _ "Malin Keshar"
            type=Dark Mage
            side=1
            x,y=5,17
            profile=portraits/malin_old-decay.png
            canrecruit=yes
            unrenamable=yes

            hitpoints=11
            facing=ne

            [status]
                poisoned=yes
            [/status]
        [/unit]

        [disallow_recruit]
            side=1
        [/disallow_recruit]

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        {VARIABLE scenario_stage 1}
    [/event]

#define GENERATE_VOID
    [store_locations]
        variable=hex
        terrain=Uu,Uu^*,Uh,Uh^*
        [filter_adjacent_location]
            terrain=Qxu
        [/filter_adjacent_location]
        [not]
            [filter][/filter]
        [/not]
    [/store_locations]
    [for]
        array=hex
        [do]
            [set_variable]
                name=change_terrain
                rand=1..4
            [/set_variable]
            [if]
                [variable]
                    name=change_terrain
                    less_than=2
                [/variable]
                [then]
                    [terrain]
                        x,y=$hex[$i].x,$hex[$i].y
                        terrain=Qxu
                    [/terrain]
                [/then]
            [/if]
            {CLEAR_VARIABLE change_terrain}
        [/do]
    [/for]
    {CLEAR_VARIABLE hex}
    [redraw][/redraw]
    [store_locations]
        variable=hex
        terrain=Uh,Uh^*
        [not]
            [filter][/filter]
        [/not]
    [/store_locations]
    [for]
        array=hex
        [do]
            [set_variable]
                name=change_terrain
                rand=1..3
            [/set_variable]
            [if]
                [variable]
                    name=change_terrain
                    less_than=2
                [/variable]
                [then]
                    [terrain]
                        x,y=$hex[$i].x,$hex[$i].y
                        terrain=Qxu
                    [/terrain]
                [/then]
            [/if]
            {CLEAR_VARIABLE change_terrain}
        [/do]
    [/for]
    {CLEAR_VARIABLE hex}
    [redraw][/redraw]
#enddef

    [event]
        name=start

        [message]
            speaker=Malin Keshar
            message= _ "Cursed beasts!"
        [/message]

        {MOVE_UNIT (id=Malin Keshar) 8 14}

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        [message]
            speaker=Malin Keshar
            message= _ "I won’t go down like this, felled by an orc’s blade!"
        [/message]

        {MOVE_UNIT (id=Malin Keshar) 11 13}

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        [delay]
            time=300
        [/delay]
        [scroll_to]
            x,y=11,12
        [/scroll_to]
        {MOVE_UNIT (id=Malin Keshar) 11 12}
        [delay]
            time=100
        [/delay]
        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=1
            animate=no
        [/harm_unit]

        [delay]
            time=400
        [/delay]
        [scroll_to]
            x,y=11,11
        [/scroll_to]
        {MOVE_UNIT (id=Malin Keshar) 11 11}
        [delay]
            time=100
        [/delay]
        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=1
            animate=no
        [/harm_unit]

        [delay]
            time=700
        [/delay]
        [scroll_to]
            x,y=12,10
        [/scroll_to]
        {MOVE_UNIT (id=Malin Keshar) 12 10}
        [delay]
            time=100
        [/delay]
        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=1
            animate=no
        [/harm_unit]

        [delay]
            time=1000
        [/delay]
        [scroll_to]
            x,y=12,9
        [/scroll_to]
        {MOVE_UNIT (id=Malin Keshar) 12 9}
        [delay]
            time=100
        [/delay]
        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=2
            animate=no
        [/harm_unit]
        [delay]
            time=300
        [/delay]
        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=2
            animate=no
        [/harm_unit]

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        [delay]
            time=500
        [/delay]

        {CREATE_ADVISOR}

        [message]
            role=advisor
            message= _ "Master, you are gravely injured!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "So it seems..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Perhaps it would be a suitable end. The orcs were the ones who provoked this journey of mine. Would it not be fitting for them to end my quest as well?"
        [/message]

        [message]
            role=advisor
            message= _ "There is another way, master. Remember the book!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Yes... yes. The book. That half-rotten, tattered tome which I gave my blood and soul for. I forsook my people, my family, my home... to follow that damned necromancer! And in the end, he betrayed me too, just like Drogan, just like Dela..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Everyone has betrayed me. I am alone. All that is left..."
        [/message]

        [delay]
            time=700
        [/delay]
        {MOVE_UNIT (id=Malin Keshar) 12 8}
        [delay]
            time=300
        [/delay]
        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=3
            animate=no
        [/harm_unit]

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "Leave me while I prepare."
        [/message]

        [message]
            role=advisor
            message= _ "Yes, master."
        [/message]

        {PUT_TO_RECALL_LIST (role=advisor)}

        [scroll_to]
            x,y=12,7
        [/scroll_to]
        [terrain]
            x=12
            y=7
            terrain=Urb
        [/terrain]
        [redraw][/redraw]
        [item]
            x,y=12,7
            image=misc/makeshift-altar.png
        [/item]

        [delay]
            time=500
        [/delay]

        [terrain]
            x=11,13,11,13,10,14
            y= 6, 6, 9, 9, 7, 7
            terrain=Urb
        [/terrain]
        [redraw][/redraw]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "... I suppose I have never been one for regrets..."
        [/message]

        [delay]
            time=1000
        [/delay]

        [recall]
            role=advisor
            x,y=11,8
        [/recall]

        {MODIFY_UNIT role=advisor facing se}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "I’m ready. Do it."
        [/message]

        [animate_unit]
            flag=attack
            hits=yes

            [filter]
                role=advisor
            [/filter]

            [primary_attack]
                range=melee
            [/primary_attack]

            [facing]
                [filter]
                    id=Malin Keshar
                [/filter]
            [/facing]

            [animate]
                flag=defend

                [filter]
                    id=Malin Keshar
                [/filter]

                hits=no

                [facing]
                    [filter]
                        role=advisor
                    [/filter]
                [/facing]
            [/animate]
        [/animate_unit]

        [kill]
            id=Malin Keshar
            fire_event=no
            animate=yes
        [/kill]

        {PUT_TO_RECALL_LIST (role=advisor)}

        {REPLACE_SCENARIO_MUSIC silence.ogg}

        {FADE_TO_BLACK}

        [place_shroud]
            side=1
            x,y=0-23,0-20
        [/place_shroud]

        [replace_schedule]
            [time]
                id=limbo1
                name= _ "Limbo"
                image=misc/time-schedules/after-the-fall/6shortdark.png
                lawful_bonus=-30
                red=-50
                green=-50
                blue=-15
            [/time]
        [/replace_schedule]

        [terrain]
            x=0-8
            y=13-20
            terrain=Xu
        [/terrain]
        [redraw][/redraw]

        {GENERATE_VOID}

        [random_placement]
            num_items=1
            variable=loc
            min_distance=5
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh
                x=7-9,3-5,16-19
                y=1-3,4-6,11-14
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    id=MKFlesh
                    name= _ "Flesh of Malin Keshar"
                    type=Necrophage
                    moves=0
                    max_moves=2
                    side=2
                    x,y=$loc.x,$loc.y
                    unrenamable=yes
                [/unit]
            [/command]
        [/random_placement]

        [delay]
            time=1500
        [/delay]

        [unstore_unit]
            variable=malin
            x,y=12,7
        [/unstore_unit]
        {CLEAR_VARIABLE malin}

        {MODIFY_UNIT (id=Malin Keshar) profile (portraits/malin_young.png)}
        {MODIFY_UNIT (id=Malin Keshar) max_moves 4}
        {MODIFY_UNIT (id=Malin Keshar) moves 4}

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        {PLACE_IMAGE scenery/rune4.png 13 6}
        {PLACE_IMAGE scenery/rune4.png 11 9}
        {PLACE_IMAGE scenery/rune3.png 14 7}
        {PLACE_IMAGE scenery/rune3.png 10 7}
        {PLACE_IMAGE scenery/rune1.png 11 6}
        {PLACE_IMAGE scenery/rune1.png 13 9}

        {FADE_IN}
        {REPLACE_SCENARIO_MUSIC into_the_shadows.ogg}
        {APPEND_MUSIC           weight_of_revenge.ogg}
        {APPEND_MUSIC           underground.ogg}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "I feel... different. Where am I?"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Why is my body still intact? Am I still alive? Or..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... something isn’t quite right."
        [/message]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]

        [unit]
            type=Ghoul
            x,y=15,8
            side=2
            animate=yes
            max_moves=4
        [/unit]

        [message]
            speaker=Malin Keshar
            message= _ "I see, accepting death was not enough. To become a lich, I must master it."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "First comes the flesh, the physical form of life. Blood is the crux of life for mortal creatures, but if I wish to ascend beyond that..."
        [/message]

        [random_placement]
            num_items={ON_DIFFICULTY 2 3 4}
            variable=loc
            min_distance=3
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh
                [not]
                    x=18-23
                    y=1-5
                [/not]
                [not]
                    x,y=12,7
                    radius=3
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    type=Ghoul
                    side=2
                    x,y=$loc.x,$loc.y
                    max_moves=4
                    ai_special=guardian
                [/unit]
            [/command]
        [/random_placement]
        [random_placement]
            num_items={ON_DIFFICULTY 4 5 6}
            variable=loc
            min_distance=1
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh
                [not]
                    x=18-23
                    y=1-5
                [/not]
                [not]
                    x,y=12,7
                    radius=3
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    type=Walking Corpse
                    side=2
                    x,y=$loc.x,$loc.y
                    max_moves=3
                [/unit]
            [/command]
        [/random_placement]

        [message]
            speaker=narrator
            message= _ "Stepping on runes provides Malin with a temporary buff. He loses any additional abilities he obtains if he steps off of the corresponding runestone."
            image=wesnoth-icon.png
        [/message]

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Complete the ritual"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [note]
                description= _ "While Malin is standing on a runestone, he receives additional abilities"
            [/note]
        [/objectives]
    [/event]

#define RESET_RUNES
    {REMOVE_IMAGE 13 6}
    {REMOVE_IMAGE 11 9}
    {REMOVE_IMAGE 14 7}
    {REMOVE_IMAGE 10 7}
    {REMOVE_IMAGE 11 6}
    {REMOVE_IMAGE 13 9}
    {PLACE_IMAGE scenery/rune4.png 13 6}
    {PLACE_IMAGE scenery/rune4.png 11 9}
    {PLACE_IMAGE scenery/rune3.png 14 7}
    {PLACE_IMAGE scenery/rune3.png 10 7}
    {PLACE_IMAGE scenery/rune1.png 11 6}
    {PLACE_IMAGE scenery/rune1.png 13 9}
#enddef

    # Ritual part 2

    [event]
        name=die
        first_time_only=no
        [filter]
            id=MKFlesh
        [/filter]

        [kill]
            side=2
        [/kill]

        [message]
            speaker=Malin Keshar
            message= _ "The flesh dies, and then..."
        [/message]

        [delay]
            time=1000
        [/delay]
        {FADE_TO_BLACK}

        {RESET_RUNES}

        [store_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            variable=malin
        [/store_unit]

        [kill]
            id=Malin Keshar
        [/kill]

        [place_shroud]
            side=1
            x,y=0-23,0-20
        [/place_shroud]

        [replace_schedule]
            [time]
                id=limbo2
                name= _ "Limbo"
                image=misc/time-schedules/after-the-fall/6shortdark.png
                lawful_bonus=-35
                red=-60
                green=-60
                blue=-20
            [/time]
        [/replace_schedule]

        {GENERATE_VOID}

        [delay]
            time=1500
        [/delay]

        [unstore_unit]
            variable=malin
            x,y=12,7
        [/unstore_unit]
        {CLEAR_VARIABLE malin}
        {FULL_HEAL (id=Malin Keshar)}
        {MODIFY_UNIT (id=Malin Keshar) attacks_left 1}
        {MODIFY_UNIT (id=Malin Keshar) max_moves 4}
        {MODIFY_UNIT (id=Malin Keshar) moves 4}

        {MODIFY_UNIT (id=Malin Keshar) profile (portraits/malin_old.png)}

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        {FADE_IN}

        [message]
            speaker=Malin Keshar
            message= _ "Drain the blood, strip away the meat, and all that is left is the bone."
        [/message]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]

        [unit]
            type=Skeleton
            x,y=11,7
            side=2
            max_moves=4
            animate=yes
        [/unit]

        [message]
            speaker=Malin Keshar
            message= _ "I remember a time when I thought skeletons were repulsive, sickening things. I suppose it is only natural for the living to fear the most prominent figure of death. Even if I grew out of such a naive thought... I suppose I could not have expected Drogan and Dela to follow suit so easily. My family and friends, yes, but they were nothing but simpletons. Would that they had tried to understand me instead of shunning me outright."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I do not really regret following my own path that much."
        [/message]

        [random_placement]
            num_items={ON_DIFFICULTY 3 4 5}
            variable=loc
            min_distance=3
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh
                [not]
                    x=18-23
                    y=1-5
                [/not]
                [not]
                    x,y=12,7
                    radius=3
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    type=Skeleton
                    side=2
                    x,y=$loc.x,$loc.y
                    max_moves=4
                    ai_special=guardian
                [/unit]
            [/command]
        [/random_placement]
        [random_placement]
            num_items={ON_DIFFICULTY 3 4 4}
            variable=loc
            min_distance=1
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh
                [not]
                    x=18-23
                    y=1-5
                [/not]
                [not]
                    x,y=12,7
                    radius=3
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    type=Skeleton Archer
                    side=2
                    x,y=$loc.x,$loc.y
                    max_moves=3
                [/unit]
            [/command]
        [/random_placement]

        [random_placement]
            num_items=1
            variable=loc
            min_distance=3
            [filter_location]
                x=8-9,6,6-7,16,11-14
                y=  4,6,  8,10,   12
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    id=MKBone
                    name= _ "Bones of Malin Keshar"
                    type=Revenant
#ifdef EASY
                    hitpoints=60
                    max_hitpoints=60
#endif
#ifdef NORMAL
                    hitpoints=75
                    max_hitpoints=75
#endif
#ifdef HARD
                    hitpoints=90
                    max_hitpoints=90
#endif
                    moves=0
                    max_moves=2
                    side=2
                    x,y=$loc.x,$loc.y
                    unrenamable=yes
                [/unit]
            [/command]
        [/random_placement]

        {MODIFY_UNIT (side=2) attacks_left 0}
        {MODIFY_UNIT (side=2) moves 0}
    [/event]

    # Ritual part 3

    [event]
        name=die
        first_time_only=no
        [filter]
            id=MKBone
        [/filter]

        [kill]
            side=2
        [/kill]

        [message]
            speaker=Malin Keshar
            message= _ "The physical form collapses altogether. What remains?"
        [/message]

        [delay]
            time=1000
        [/delay]
        {FADE_TO_BLACK}

        {RESET_RUNES}

        [store_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            variable=malin
        [/store_unit]

        [kill]
            id=Malin Keshar
        [/kill]

        [place_shroud]
            side=1
            x,y=0-23,0-20
        [/place_shroud]

        [replace_schedule]
            [time]
                id=limbo3
                name= _ "Limbo"
                image=misc/time-schedules/after-the-fall/6shortdark.png
                lawful_bonus=-40
                red=-70
                green=-70
                blue=-30
            [/time]
        [/replace_schedule]

        {GENERATE_VOID}
        {GENERATE_VOID}
        {GENERATE_VOID}

        [delay]
            time=1500
        [/delay]

        [unstore_unit]
            variable=malin
            x,y=12,7
        [/unstore_unit]
        {CLEAR_VARIABLE malin}
        {FULL_HEAL (id=Malin Keshar)}
        {MODIFY_UNIT (id=Malin Keshar) attacks_left 1}
        {MODIFY_UNIT (id=Malin Keshar) max_moves 4}
        {MODIFY_UNIT (id=Malin Keshar) moves 4}

        {MODIFY_UNIT (id=Malin Keshar) profile (portraits/malin_old-decay.png)}

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        {FADE_IN}

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]

        [unit]
            type=Ghost
            x,y=14,5
            side=2
            animate=yes
        [/unit]

        [message]
            speaker=Malin Keshar
            message= _ "The soul. Dela always said I was a creature without a soul. I suppose she was jesting at the time, but perhaps not after I killed Drogan."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Bah! Two can play that game. I have only ever fought to protect my people and my family, but the only thing I received in return was scorn and exile. My own sister would not listen to me. My people would rather feed themselves to orcs than follow my ‘sorcerous ways’. Drogan, Dela... all of them! They are the ones without souls, not me!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I should not really care anymore. According to them, I have forsaken my soul already. So what does it matter?"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I should not regret anything. I’m not really one for regrets..."
        [/message]

        [random_placement]
            num_items={ON_DIFFICULTY 3 3 4}
            variable=loc
            min_distance=3
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh,Qxu
                [not]
                    x=18-23
                    y=1-5
                [/not]
                [not]
                    x,y=12,7
                    radius=4
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 2 "Ghost" $loc.x $loc.y}
            [/command]
        [/random_placement]

        [random_placement]
            num_items={ON_DIFFICULTY 1 2 2}
            variable=loc
            min_distance=3
            [filter_location]
                terrain=Uu^*,Uu,Uh^*,Uh,Qxu
                [not]
                    x=18-23
                    y=1-5
                [/not]
                [not]
                    x,y=12,7
                    radius=4
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 2 "Wraith" $loc.x $loc.y}
            [/command]
        [/random_placement]

        {MODIFY_UNIT (side=2) attacks_left 0}
        {MODIFY_UNIT (side=2) moves 0}
        {MODIFY_UNIT (side=2) max_moves 2}

        [random_placement]
            num_items=1
            variable=loc
            min_distance=3
            [filter_location]
                x=7-9,3-5,16-19
                y=1-3,4-6,11-14
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    id=MKSpirit
                    name= _ "Soul of Malin Keshar"
                    type=Spectre
#ifdef EASY
                    hitpoints=50
                    max_hitpoints=50
#endif
#ifdef NORMAL
                    hitpoints=60
                    max_hitpoints=60
#endif
#ifdef HARD
                    hitpoints=70
                    max_hitpoints=70
#endif
                    moves=0
                    max_moves=2
                    side=2
                    x,y=$loc.x,$loc.y
                    unrenamable=yes
                [/unit]
            [/command]
        [/random_placement]
    [/event]

    # Malin gets to heal upon killing a unit
    [event]
        name=die
        first_time_only=no
        [filter]
            side=2
            [not]
                id=MKFlesh,MKBone,MKSpirit
            [/not]
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [heal_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=8
            restore_statuses=yes
            animate=yes
        [/heal_unit]

        [fire_event]
            name=heal_on_kill_dialogue
        [/fire_event]
    [/event]

    [event]
        name=heal_on_kill_dialogue

        [message]
            speaker=Malin Keshar
            message= _ "These thralls contain only a meager amount of energy, but enough to sustain me."
        [/message]
    [/event]

    # Sighting the bosses
    [event]
        name=sighted
        [filter]
            id=MKFlesh
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "The flesh appears, distorted and warped, but somehow strangely familiar."
        [/message]
    [/event]
    [event]
        name=sighted
        [filter]
            id=MKBone
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "I feel an aching in my bones, as if my joints are about to fall apart."
        [/message]
    [/event]
    [event]
        name=sighted
        [filter]
            id=MKSpirit
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "Cold... it’s so very cold. Not a biting chill, but a numbness, an emptiness, as if there is nothing left inside of me..."
        [/message]
    [/event]

    # Ritual runes

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Malin Keshar
            x=13,11
            y=6,9
        [/filter]

        {REMOVE_IMAGE $x1 $y1}
        {PLACE_IMAGE scenery/rune4-glow.png $x1 $y1}

        [sound]
            name=magic-dark.ogg
        [/sound]

        [object]
            id=precision_rune
            take_only_once=no
            silent=yes
            duration=scenario
            [filter]
                id=Malin Keshar
            [/filter]
            [effect]
                apply_to=new_ability
                [abilities]
                    [leadership]
                        id=conscience
                        name= _ "conscience"
                        name_inactive= _ "conscience"
                        description= _ "This unit has its damage increased by 50%"
                        description_inactive= _ "This unit has its damage increased by 50%"
                        value=50
                        affect_self=yes
                        affect_enemies=no
                        affect_allies=no
                        [filter]
                            id=Malin Keshar
                            x=13,11
                            y=6,9
                        [/filter]
                    [/leadership]
                [/abilities]
            [/effect]
        [/object]

        [fire_event]
            name=rune dialogue
        [/fire_event]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Malin Keshar
            x=13,11
            y=9,6
        [/filter]

        {REMOVE_IMAGE $x1 $y1}
        {PLACE_IMAGE scenery/rune1-glow.png $x1 $y1}

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

        [object]
            id=carapace_rune
            take_only_once=no
            silent=yes
            duration=scenario
            [filter]
                id=Malin Keshar
            [/filter]
            [effect]
                apply_to=new_ability
                [abilities]
                    [resistance]
                        id=carapace
                        max_value=90
                        add=40
                        name= _ "carapace"
                        name_inactive= _ "carapace"
                        description= _ "This unit gains 40% to all resistances."
                        description_inactive= _ "This unit gains 40% to all resistances."
                        affect_self=yes
                        [filter]
                            id=Malin Keshar
                            x=13,11
                            y=9,6
                        [/filter]
                    [/resistance]
                [/abilities]
            [/effect]
        [/object]

        [fire_event]
            name=rune dialogue
        [/fire_event]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Malin Keshar
            x=14,10
            y=7,7
        [/filter]

        {REMOVE_IMAGE $x1 $y1}
        {PLACE_IMAGE scenery/rune3-glow.png $x1 $y1}

        [sound]
            name=magic-missile-1.ogg
        [/sound]

        [object]
            id=lifeblood_rune
            take_only_once=no
            silent=yes
            duration=scenario
            [filter]
                id=Malin Keshar
            [/filter]
            [effect]
                apply_to=new_ability
                [abilities]
                    [regenerate]
                        id=lifeblood
                        value=40
                        name= _ "lifeblood"
                        name_inactive= _ "lifeblood"
                        description= _ "This unit will heal 40 HP every turn. If it is poisoned, it will remove the poison instead of healing."
                        description_inactive= _ "This unit will heal 40 HP every turn. If it is poisoned, it will remove the poison instead of healing."
                        affect_self=yes
                        poison=cured
                        [filter]
                            id=Malin Keshar
                            x=14,10
                            y=7,7
                        [/filter]
                    [/regenerate]
                [/abilities]
            [/effect]
        [/object]

        [fire_event]
            name=rune dialogue
        [/fire_event]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Malin Keshar
            x,y=1-23,1-20
        [/filter]

        [if]
            [variable]
                name=x2
                numerical_equals=13
            [/variable]
            [then]
                [if]
                    [variable]
                        name=y2
                        numerical_equals=6
                    [/variable]
                    [then]
                        {REMOVE_IMAGE $x2 $y2}
                        {PLACE_IMAGE scenery/rune4.png $x2 $y2}
                    [/then]
                    [elseif]
                        [variable]
                            name=y2
                            numerical_equals=9
                        [/variable]
                        [then]
                            {REMOVE_IMAGE $x2 $y2}
                            {PLACE_IMAGE scenery/rune1.png $x2 $y2}
                        [/then]
                    [/elseif]
                [/if]
            [/then]
            [elseif]
                [variable]
                    name=x2
                    numerical_equals=11
                [/variable]
                [then]
                    [if]
                        [variable]
                            name=y2
                            numerical_equals=6
                        [/variable]
                        [then]
                            {REMOVE_IMAGE $x2 $y2}
                            {PLACE_IMAGE scenery/rune1.png $x2 $y2}
                        [/then]
                        [elseif]
                            [variable]
                                name=y2
                                numerical_equals=9
                            [/variable]
                            [then]
                                {REMOVE_IMAGE $x2 $y2}
                                {PLACE_IMAGE scenery/rune4.png $x2 $y2}
                            [/then]
                        [/elseif]
                    [/if]
                [/then]
            [/elseif]
            [elseif]
                [variable]
                    name=x2
                    numerical_equals=10
                [/variable]
                [then]
                    [if]
                        [variable]
                            name=y2
                            numerical_equals=7
                        [/variable]
                        [then]
                            {REMOVE_IMAGE $x2 $y2}
                            {PLACE_IMAGE scenery/rune3.png $x2 $y2}
                        [/then]
                    [/if]
                [/then]
            [/elseif]
            [elseif]
                [variable]
                    name=x2
                    numerical_equals=14
                [/variable]
                [then]
                    [if]
                        [variable]
                            name=y2
                            numerical_equals=7
                        [/variable]
                        [then]
                            {REMOVE_IMAGE $x2 $y2}
                            {PLACE_IMAGE scenery/rune3.png $x2 $y2}
                        [/then]
                    [/if]
                [/then]
            [/elseif]
        [/if]

        {MODIFY_UNIT (id=Malin Keshar) max_moves 4}
    [/event]

    [event]
        name=rune dialogue

        [message]
            speaker=Malin Keshar
            message= _ "These runes seem to be useful."
        [/message]
    [/event]

    # Ritual completion

    [event]
        name=last breath
        [filter]
            id=MKSpirit
        [/filter]

        {REPLACE_SCENARIO_MUSIC silence.ogg}
        [kill]
            side=2
        [/kill]
        [delay]
            time=1000
        [/delay]

        [harm_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            amount=999
            kill=no
        [/harm_unit]
        [delay]
            time=1000
        [/delay]

        [kill]
            id=Malin Keshar
            animate=yes
        [/kill]
        [delay]
            time=1000
        [/delay]

        {FADE_TO_BLACK}

        {REMOVE_IMAGE 13 6}
        {REMOVE_IMAGE 11 9}
        {REMOVE_IMAGE 14 7}
        {REMOVE_IMAGE 10 7}
        {REMOVE_IMAGE 11 6}
        {REMOVE_IMAGE 13 9}
        {REMOVE_IMAGE 12 7}

        [place_shroud]
            side=1
            x,y=0-23,0-20
        [/place_shroud]

        [message]
            speaker=narrator
            message= _ "There is darkness..."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=narrator
            message= _ "and peace..."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=narrator
            message= _ "for a moment."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=narrator
            message= _ "Then, they are replaced by a pulling, a pain too strong to resist, and then..."
        [/message]

        [message]
            speaker=narrator
            message= _ "... by emptiness."
        [/message]

        [replace_map]
            map="{campaigns/Descent_Into_Darkness/maps/11_Descent_into_Darkness.map}"
            expand=yes
            shrink=yes
        [/replace_map]

        [place_shroud]
            side=1
            x,y=0-30,0-36
        [/place_shroud]

        {PLACE_IMAGE scenery/signpost.png 13 27}

        {PLACE_IMAGE items/altar-evil.png 6 15}
        {PLACE_IMAGE items/potion-clear.png 15 22}
        {PLACE_IMAGE items/stone-tablet.png 16 17}

        {PLACE_IMAGE items/coffin-closed.png 3 2}
        {PLACE_IMAGE items/bones.png 1 3}
        {PLACE_IMAGE items/key.png 2 1}
        {PLACE_IMAGE items/stone-tablet.png 2 4}

        # treasure boxes
        {PLACE_IMAGE items/chest-plain-closed.png 4 19}
        {PLACE_IMAGE items/chest-plain-closed.png 28 23}
        {PLACE_IMAGE items/chest-plain-closed.png 27 6}
        {PLACE_IMAGE items/chest-plain-closed.png 4 26}

        [replace_schedule]
            {UNDERGROUND}
        [/replace_schedule]

        [delay]
            time=1000
        [/delay]

        [remove_shroud]
            side=1
            x,y=3,34
            radius=3
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=3,34
            radius=3
            multiturn=yes
        [/lift_fog]

        {FADE_IN}

        # And is reborn as a lich
        [unit]
            side=1
            x,y=3,34
#ifdef HARD
            hitpoints=19
#endif
#ifdef NORMAL
            hitpoints=27
#endif
#ifdef EASY
            hitpoints=33
#endif
            facing=se
            animate=yes

            # wmllint: recognize Mal Keshar
            {CHARACTER_STATS_MAL_KESHAR}
        [/unit]

        [modify_side]
            side=1
            user_team_name= _ "Mal Keshar"
        [/modify_side]

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        {INCIDENTAL_MUSIC the_dangerous_symphony.ogg}
        [music]
            name=knolls.ogg
            append=yes
        [/music]
        [music]
            name=underground.ogg
            append=yes
        [/music]
        [music]
            name=weight_of_revenge.ogg
            append=yes
        [/music]

        # He's not necessarily totally happy about this
        [message]
            speaker=Mal Keshar
            sound=lich-die.ogg
            message= _ "<big>AAAaaiiigghh!!</big>" # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "The cold, it burns!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I need warmth... life..."
        [/message]

        [remove_shroud]
            side=1
            x=8-9,10
            y=29-31,29-30
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x=8-9,10
            y=29-31,29-30
            multiturn=yes
        [/lift_fog]

        [animate_unit]
            flag=attack
            hits=yes

            [filter]
                id=Mal Keshar
            [/filter]

            [primary_attack]
                name=shadow wave
            [/primary_attack]
        [/animate_unit]

        [scroll_to]
            x,y=9,30
        [/scroll_to]

        {QUAKE cave-in.ogg}

        [item]
            x,y=10,29
            image=misc/blank-hex.png
            # HACK: An item can't be removed after only one cycle, so set the blank hex at the end
            halo="halo/undead/dark-magic-[1~6].png,misc/blank-hex.png:100000"
        [/item]

        [delay]
            time=1000
        [/delay]

        [terrain]
            x,y=10-11,29
            terrain=Qxu^Bcx/
        [/terrain]

        [remove_item]
            x,y=10,29
        [/remove_item]

        [message]
            speaker=Mal Keshar
            message= _ "I sense some primitive life in that direction. Perhaps I can sustain myself upon them."
        [/message]

        [reset_fog]
            [filter_side]
                side=1
            [/filter_side]
        [/reset_fog]

        [random_placement]
            num_items=5
            variable=loc
            min_distance=3
            [filter_location]
                x,y=1-29,1-24
                terrain=Uu,Uu^*
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 3 "Vampire Bat" $loc.x $loc.y} {GUARDIAN}
            [/command]
        [/random_placement]

        [random_placement]
            num_items={ON_DIFFICULTY 1 2 2}
            variable=loc
            min_distance=3
            [filter_location]
                x,y=1-29,1-24
                terrain=Uu,Uu^*
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    type=Blood Bat
                    side=3
                    x,y=$loc.x,$loc.y
                    max_moves=4
                [/unit]
            [/command]
        [/random_placement]

        [random_placement]
            num_items={ON_DIFFICULTY 2 3 3}
            variable=loc
            min_distance=3
            [filter_location]
                x,y=1-29,1-24
                terrain=Uu,Uu^*
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 3 "Giant Rat" $loc.x $loc.y}
            [/command]
        [/random_placement]

        {MODIFY_UNIT (type=Giant Rat) max_moves 3}

        [random_placement]
            num_items=3
            variable=loc
            min_distance=3
            [filter_location]
                x,y=1-29,1-24
                terrain=Uu,Uu^*
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 3 "Giant Rat" $loc.x $loc.y} {GUARDIAN}
            [/command]
        [/random_placement]

        [random_placement]
            num_items=10
            variable=loc
            min_distance=3
            [filter_location]
                x,y=1-29,1-24
                terrain=Uu,Uu^*
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 3 "Giant Scorpling" $loc.x $loc.y} {GUARDIAN}
            [/command]
        [/random_placement]

        [random_placement]
            num_items=1
            variable=loc
            min_distance=11
            [filter_location]
                x,y=1-29,1-24
                terrain=Uu,Uu^*
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NOTRAIT_UNIT 3 "Giant Spider" $loc.x $loc.y} {GUARDIAN}
            [/command]
        [/random_placement]

        [unit]
            type=Dread Bat
            side=3
            x,y=2,23
            max_hitpoints=60
            hitpoints=60
            max_moves=5
            ai_special=guardian
            moves=5
            level=3
        [/unit]

        {MODIFY_UNIT (type=Giant Spider) max_moves 3}

        # Previously recruited and new adepts can now also become liches
        [lua]
            code = <<
                for i, u in ipairs(wesnoth.get_recall_units { type = 'Dark Adept DiD, Dark Sorcerer DiD' }) do
                    if u.type == 'Dark Adept DiD' then
                        u:transform('Dark Adept')
                    elseif u.type == 'Dark Sorcerer DiD' then
                        u:transform('Dark Sorcerer')
                    end
                end
            >>
        [/lua]

        [disallow_recruit]
            side=1
            type=Dark Adept DiD
        [/disallow_recruit]

        [allow_recruit]
            side=1
            type=Dark Adept
        [/allow_recruit]

        {VARIABLE scenario_stage 2}
        {VARIABLE puzzle_coffin 0}
        {VARIABLE puzzle_potion 0}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Regain your strength"
            [/objective]
            [objective]
                condition=lose
                description= _ "Destruction of Mal Keshar"
            [/objective]

            [gold_carryover]
                bonus=no
                carryover_percentage=100
            [/gold_carryover]
        [/objectives]
    [/event]

    # text at lair entrance
    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=13,27
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=narrator
            # wmllint: local spelling Zephryn
            message= _ "<s><i>Welcome to Zephryn’s laboratory. Please be mindful of ongoing experiments during your visit.</i></s>
<big><i><b>This territory is the domain of the mighty Xanthric. All unwelcome intruders shall die.</b></i></big>"
            image=wesnoth-icon.png
        [/message]

        [fire_event]
            name=lair text
        [/fire_event]
    [/event]

    [event]
        name=lair text

        [message]
            speaker=Mal Keshar
            message= _ "That mage’s name is suspiciously... familiar."
        [/message]
    [/event]

    # small flavor events
    [event]
        name=attack
        [filter]
            type=Blood Bat
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            message= _ "Why are these bats chasing me?"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            type=Giant Rat
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            message= _ "Blasted rats!"
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            type=Giant Spider
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            message= _ "Dela used to be afraid of spiders. Imagine if I showed her something like this..."
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            type=Dread Bat
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [modify_unit]
            [filter]
                type=Dread Bat
            [/filter]
            [effect]
                apply_to=status
                remove=guardian
            [/effect]
        [/modify_unit]

        [message]
            speaker=Mal Keshar
            message= _ "What an unusual bat."
        [/message]
    [/event]

    [event]
        name=attacker_hits
        id=lich_attacker
        first_time_only=yes
        [filter]
            id=Mal Keshar
        [/filter]
        [filter_attack]
            name=touch
        [/filter_attack]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            message= _ "Yes! I can draw energy from even these insignificant creatures."
        [/message]
        [remove_event]
            id=lich_defender
        [/remove_event]
    [/event]

    [event]
        name=defender_hits
        id=lich_defender
        first_time_only=yes
        [filter_second]
            id=Mal Keshar
        [/filter_second]
        [filter_second_attack]
            name=touch
        [/filter_second_attack]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Mal Keshar
            message= _ "Yes! I can draw energy from even these insignificant creatures."
        [/message]
        [remove_event]
            id=lich_attacker
        [/remove_event]
    [/event]

    # treasure boxes
    [event]
        name=moveto
        [filter]
            id=Mal Keshar
            x,y=4,19
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "You found some gold!"
            image=wesnoth-icon.png
        [/message]

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

        {PLACE_IMAGE items/chest-plain-open.png 4 19}

        [gold]
            side=1
            {QUANTITY amount 25 20 15}
        [/gold]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Mal Keshar
            x,y=28,23
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "You found some gold!"
            image=wesnoth-icon.png
        [/message]

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

        {PLACE_IMAGE items/chest-plain-open.png 28 23}

        [gold]
            side=1
            {QUANTITY amount 25 20 15}
        [/gold]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Mal Keshar
            x,y=27,6
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "You found some gold!"
            image=wesnoth-icon.png
        [/message]

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

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

        [gold]
            side=1
            {QUANTITY amount 50 40 30}
        [/gold]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Mal Keshar
            x,y=4,26
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "You found some gold!"
            image=wesnoth-icon.png
        [/message]

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

        {PLACE_IMAGE items/chest-plain-open.png 4 26}

        [gold]
            side=1
            {QUANTITY amount 25 20 15}
        [/gold]
    [/event]

    # potion puzzle
    # Solution: Pick up the brazier and melt the ice, creating water
    # pick up the empty flask and move to the water, then pick up the filled flask
    # go to the altar, which puts the filled flask there and creates a potion

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=21,18
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
            [and]
                [variable]
                    name=puzzle_potion
                    numerical_equals=0
                [/variable]
            [/and]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "You picked up a brazier!"
            image=wesnoth-icon.png
        [/message]

        [terrain]
            x,y=21,18
            terrain=Urb
        [/terrain]
        [redraw][/redraw]
        {VARIABLE puzzle_potion 1}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=15,22
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_potion
                numerical_equals=2
            [/variable]
            [then]
                [message]
                    speaker=narrator
                    message= _ "You picked up an empty flask."
                    image=wesnoth-icon.png
                [/message]

                {REMOVE_IMAGE 15 22}
                {VARIABLE puzzle_potion 3}
            [/then]

            [elseif]
                [variable]
                    name=puzzle_potion
                    less_than=2
                [/variable]
                [then]
                    [sound]
                        name=magic-dark-big-miss.ogg
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You should do something else first."
                        image=wesnoth-icon.png
                    [/message]
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=15,18
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_potion
                numerical_equals=1
            [/variable]
            [then]
                [sound]
                    name=flame-big.ogg
                [/sound]

                [message]
                    speaker=narrator
                    message= _ "You melted the ice."
                    image=wesnoth-icon.png
                [/message]

                [terrain]
                    x,y=15,18
                    terrain=Wog
                [/terrain]
                [redraw][/redraw]
                {VARIABLE puzzle_potion 2}
            [/then]

            [elseif]
                [variable]
                    name=puzzle_potion
                    numerical_equals=3
                [/variable]
                [then]
                    [sound]
                        name=water-blast.wav
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You filled the flask."
                        image=wesnoth-icon.png
                    [/message]

                    {PLACE_IMAGE items/potion-blue.png 14 18}
                    {VARIABLE puzzle_potion 4}
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=14,18
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_potion
                numerical_equals=4
            [/variable]
            [then]
                [message]
                    speaker=narrator
                    message= _ "You picked up the flask of water."
                    image=wesnoth-icon.png
                [/message]

                {REMOVE_IMAGE 14 18}
                {VARIABLE puzzle_potion 5}
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=6,15
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_potion
                numerical_equals=5
            [/variable]
            [then]
                [sound]
                    name=magic-dark-big.ogg
                [/sound]

                [message]
                    speaker=narrator
                    message= _ "You created a new potion!"
                    image=wesnoth-icon.png
                [/message]

                [message]
                    speaker=narrator
                    message= _ "Mal Keshar drinks the potion and feels energy flow through his skeletal form. The power of death surges in his vacant body, threatening to overflow, to burst free, but at the last moment, he reins it in. The stream of magic trickles down to drops, diminished, tempered, but manageable."
                    image=wesnoth-icon.png
                [/message]

                # reward: +1 RANGED DMG
                [object]
                    silent=yes
                    duration=forever
                    [filter]
                        id=Mal Keshar
                    [/filter]
                    [effect]
                        apply_to=attack
                        range=ranged
                        increase_damage=1
                    [/effect]
                [/object]

                {REMOVE_IMAGE 16 17}
                {REMOVE_IMAGE 6 15}
                {VARIABLE puzzle_potion 6}
            [/then]

            [elseif]
                [variable]
                    name=puzzle_potion
                    less_than=6
                [/variable]
                [then]
                    [sound]
                        name=magic-dark-big-miss.ogg
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You should do something else first."
                        image=wesnoth-icon.png
                    [/message]
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=16,17
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
            [and]
                [variable]
                    name=puzzle_potion
                    less_than=6
                [/variable]
            [/and]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "<i>Dark water beneath crystal ice,
Unmasked by a lick of flame,
Transmuted by the altar of darkness
Into pitch black shadow.</i>"
            image=wesnoth-icon.png
        [/message]
        [fire_event]
            name=potion text
        [/fire_event]
    [/event]

    [event]
        name=potion text
        [message]
            speaker=Mal Keshar
            message= _ "Someone left their experiment unfinished here."
        [/message]
    [/event]

    # coffin puzzle
    # Solution: pick up the key, move to the coffin to open it
    # then, pick up the bones, put them in the coffin
    # finally, pick up the brazier and cremate the bones

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=2,1
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
            [and]
                [variable]
                    name=puzzle_coffin
                    numerical_equals=0
                [/variable]
            [/and]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "You picked up a key!"
            image=wesnoth-icon.png
        [/message]

        {REMOVE_IMAGE 2 1}
        {VARIABLE puzzle_coffin 1}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=1,3
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_coffin
                numerical_equals=2
            [/variable]
            [then]
                [message]
                    speaker=narrator
                    message= _ "You found a skeleton."
                    image=wesnoth-icon.png
                [/message]

                [message]
                    speaker=Mal Keshar
                    message= _ "There are some robe scraps stuck to this skeleton. This must have once been a mage."
                [/message]

                {REMOVE_IMAGE 1 3}
                {VARIABLE puzzle_coffin 3}
            [/then]

            [elseif]
                [variable]
                    name=puzzle_coffin
                    less_than=2
                [/variable]
                [then]
                    [sound]
                        name=magic-dark-big-miss.ogg
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You should do something else first."
                        image=wesnoth-icon.png
                    [/message]
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=5,3
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_coffin
                numerical_equals=4
            [/variable]
            [then]
                [message]
                    speaker=narrator
                    message= _ "You picked up a brazier."
                    image=wesnoth-icon.png
                [/message]

                [terrain]
                    x,y=5,3
                    terrain=Irs
                [/terrain]
                [redraw][/redraw]
                {VARIABLE puzzle_coffin 5}
            [/then]

            [elseif]
                [variable]
                    name=puzzle_coffin
                    less_than=4
                [/variable]
                [then]
                    [sound]
                        name=magic-dark-big-miss.ogg
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You should do something else first."
                        image=wesnoth-icon.png
                    [/message]
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=3,2
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
        [/filter_condition]
        [if]
            [variable]
                name=puzzle_coffin
                numerical_equals=1
            [/variable]
            [then]
                [sound]
                    name=open-chest.wav
                [/sound]

                [message]
                    speaker=narrator
                    message= _ "You opened the coffin."
                    image=wesnoth-icon.png
                [/message]

                {PLACE_IMAGE items/coffin-open.png 3 2}
                {VARIABLE puzzle_coffin 2}
            [/then]

            [elseif]
                [variable]
                    name=puzzle_coffin
                    numerical_equals=3
                [/variable]
                [then]
                    [sound]
                        name=skeleton-hit-1.ogg
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You placed the skeleton in the coffin."
                        image=wesnoth-icon.png
                    [/message]

                    {VARIABLE puzzle_coffin 4}
                [/then]
            [/elseif]

            [elseif]
                [variable]
                    name=puzzle_coffin
                    numerical_equals=5
                [/variable]
                [then]
                    [sound]
                        name=flame-big.ogg
                    [/sound]

                    [message]
                        speaker=narrator
                        message= _ "You cremated the bones!"
                        image=wesnoth-icon.png
                    [/message]

                    [message]
                        speaker=narrator
                        message= _ "Ash swirls upward, charred remnants of the once living. Charcoal from bone, embers from flesh, he consumes the pallid cinders, siphoning away the energy with a draining touch."
                        image=wesnoth-icon.png
                    [/message]

                    # reward: +2 MELEE DMG
                    [object]
                        silent=yes
                        duration=forever
                        [filter]
                            id=Mal Keshar
                        [/filter]
                        [effect]
                            apply_to=attack
                            range=melee
                            increase_damage=2
                        [/effect]
                    [/object]

                    {REMOVE_IMAGE 3 2}
                    {REMOVE_IMAGE 2 4}
                    [terrain]
                        x,y=3,2
                        terrain=Irs
                    [/terrain]
                    [redraw][/redraw]
                    {VARIABLE puzzle_coffin 6}
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
            x,y=2,4
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
            [and]
                [variable]
                    name=puzzle_coffin
                    less_than=6
                [/variable]
            [/and]
        [/filter_condition]

        [message]
            speaker=narrator
            message= _ "<i>Bones, scattered carelessly onto the floor,
Remains laid without rest,
Reside outside their coffin, locked away,
In eternal wakefulness.
Then, the key is found and the lid opened,
And the tongue of fire begets ashen repose.</i>"
            image=wesnoth-icon.png
        [/message]
    [/event]

    # Sighting the enemy lair
    [event]
        name=moveto
        [filter]
            side=1
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
            [and]
                [have_location]
                    terrain=Ql
                    [filter_vision]
                        side=1
                    [/filter_vision]
                [/have_location]
            [/and]
        [/filter_condition]

        [remove_shroud]
            side=1
            x,y=17,7
            radius=3
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=17,7
        [/scroll_to]

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "I sense the lair of something powerful nearby. Capturing that castle may be a worthwhile endeavor, but I shall have to approach carefully."
        [/message]

        [cancel_action][/cancel_action]
    [/event]

    # Initiate boss battle
    [event]
        name=enter hex
        [filter]
            side=1
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=2
            [/variable]
            [and]
                [have_location]
                    x,y=17,7
                    radius=2
                    [filter_vision]
                        side=1
                    [/filter_vision]
                [/have_location]
            [/and]
        [/filter_condition]

        [remove_shroud]
            side=1
            x,y=17,7
            radius=6
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=17,7
            radius=6
            multiturn=yes
        [/lift_fog]

        {MODIFY_UNIT (id=Mal Keshar) moves 6}
        {MODIFY_UNIT (id=Mal Keshar) vision 6}
        {MODIFY_UNIT (id=Mal Keshar) attacks_left 1}

        {REPLACE_SCENARIO_MUSIC silence.ogg}

        [scroll_to]
            x,y=17,7
        [/scroll_to]

        [delay]
            time=2000
        [/delay]

        {QUAKE cave-in.ogg}

        [delay]
            time=500
        [/delay]

        [sound]
            name=flame-big.ogg
        [/sound]

        [delay]
            time=500
        [/delay]

        {QUAKE cave-in.ogg}

        [delay]
            time=500
        [/delay]

        [sound]
            name=flame-big.ogg
        [/sound]

        [delay]
            time=250
        [/delay]

        [sound]
            name=flame-big.ogg
        [/sound]

        [scroll_to]
            x,y=17,7
        [/scroll_to]

        [unit]
            id=Xanthric
            name= _ "Xanthric"
            type=Fire Dragon
            side=2
            x,y=17,7
#ifdef EASY
            hitpoints=150
            max_hitpoints=150
#endif
#ifdef NORMAL
            hitpoints=190
            max_hitpoints=190
#endif
#ifdef HARD
            hitpoints=230
            max_hitpoints=230
#endif
            unrenamable=yes
            canrecruit=yes
        [/unit]

        [capture_village]
            [not]
                owner_side=1
            [/not]
            side=2
        [/capture_village]

        {REPLACE_SCENARIO_MUSIC frantic.ogg}
        {APPEND_MUSIC           vengeful.ogg}

        [message]
            speaker=Xanthric
            message= _ "<i><big>What manner of vile creature intrudes upon my domain?!</big></i>"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "<i>I suppose there is some irony in this.</i>"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I was not aware that dragons still existed. This was most unexpected. Nevertheless, this shall be a worthwhile test of my new powers."
        [/message]

        [message]
            speaker=Xanthric
            message= _ "<i><big>A derelict corpse like you has no business challenging a dragon! Even my lowly elementals will be more than a match for you. Rise, my thralls!</big></i>"
        [/message]

        [random_placement]
            num_items={ON_DIFFICULTY 3 4 5}
            variable=loc
            min_distance=1
            [filter_location]
                terrain=Ql
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    side=2
                    type=Fire Guardian
                    x,y=$loc.x,$loc.y
                    animate=yes
                [/unit]
            [/command]
        [/random_placement]

        [message]
            speaker=Mal Keshar
            message= _ "Fire magic. Annoying, but you are not the only one who can summon minions to your aid."
        [/message]

        [if]
            [have_unit]
                side=1
                type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
                search_recall_list=yes
            [/have_unit]
            [then]
                [recall]
                    type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
                [/recall]
            [/then]
            [else]
                [unit]
                    type=Ghost
                    side=1
                    animate=yes
                    placement=leader
                [/unit]
            [/else]
        [/if]
        [if]
            [have_unit]
                side=1
                type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
                search_recall_list=yes
            [/have_unit]
            [then]
                [recall]
                    type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
                [/recall]
            [/then]
            [else]
                [unit]
                    type=Ghost
                    side=1
                    animate=yes
                    placement=leader
                [/unit]
            [/else]
        [/if]
        [if]
            [have_unit]
                side=1
                type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
                search_recall_list=yes
            [/have_unit]
            [then]
                [recall]
                    type=Spectre,Nightgaunt,Wraith,Shadow,Ghost
                [/recall]
            [/then]
            [else]
                [unit]
                    type=Ghost
                    side=1
                    animate=yes
                    placement=leader
                [/unit]
            [/else]
        [/if]

        [message]
            speaker=Xanthric
            message= _ "<i><big>A few decrepit souls will do you no good, necromancer. Your bones shall soon join my garden of carcasses!</big></i>"
        [/message]

        [reset_fog]
            [filter_side]
                side=1
            [/filter_side]
        [/reset_fog]

        {VARIABLE scenario_stage 3}
        {VARIABLE runes_activated 0}

        {PLACE_IMAGE scenery/summoning-circle1.png 19 3}
        {PLACE_IMAGE scenery/summoning-circle5.png 22 4}
        {PLACE_IMAGE scenery/summoning-circle3.png 10 6}
        {PLACE_IMAGE scenery/summoning-circle6.png 15 3}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Defeat Xanthric"
            [/objective]
            [objective]
                condition=lose
                description= _ "Destruction of Mal Keshar"
            [/objective]
            [gold_carryover]
                bonus=no
                carryover_percentage=100
            [/gold_carryover]
            [note]
                description= _ "At most one rune may be activated each turn"
            [/note]
        [/objectives]

        [cancel_action][/cancel_action]
    [/event]

    # flavor text if you capture the dragon's keep
    [event]
        name=moveto
        [filter]
            x,y=17,7
            side=1
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=3
            [/variable]
        [/filter_condition]

        [message]
            speaker=Xanthric
            message= _ "<i><big>How dare you?! That stone is <b>my</b> throne! I am the king of this domain!</big></i>"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Peasant, warrior, king or emperor, all living things are the subjects of death. Eternity will claim your soul as its own if I do not."
        [/message]
    [/event]

    # spawns
    [event]
        name=new turn
        first_time_only=no
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=3
            [/variable]
        [/filter_condition]

        [if]
            [have_unit]
                side=2
                type=Fire Guardian
                count="0-5"
            [/have_unit]
            [then]
                [random_placement]
                    num_items={ON_DIFFICULTY 1 2 2}
                    variable=loc
                    min_distance=1
                    [filter_location]
                        terrain=Ql
                        [not]
                            [filter][/filter]
                        [/not]
                    [/filter_location]
                    [command]
                        {NOTRAIT_UNIT 2 "Fire Guardian" $loc.x $loc.y}
                    [/command]
                [/random_placement]
            [/then]
        [/if]

        {VARIABLE runes_activated 0}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Mal Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=scenario_stage
                numerical_equals=3
            [/variable]
            [and]
                [variable]
                    name=runes_activated
                    numerical_equals=0
                [/variable]
            [/and]
        [/filter_condition]

        [if]
            [have_unit]
                id=Mal Keshar
                x,y=10,6
            [/have_unit]
            [then]
                [sound]
                    name=skeleton-big-hit-1.wav
                [/sound]

                [fire_event]
                    name=raise undead
                [/fire_event]

                [animate_unit]
                    [filter]
                        id=Mal Keshar
                    [/filter]
                    [primary_attack]
                        range=ranged
                    [/primary_attack]
                    flag=attack
                [/animate_unit]

                [unit]
                    side=1
                    type=Ghoul
                    x,y=10,7
                    animate=yes
                    passable=yes
                    overwrite=no
                [/unit]
                [unit]
                    side=1
                    type=Walking Corpse
                    x,y=11,7
                    animate=yes
                    passable=yes
                    overwrite=no
                [/unit]

                {VARIABLE runes_activated 1}
            [/then]

            [elseif]
                [have_unit]
                    id=Mal Keshar
                    x,y=19,3
                [/have_unit]
                [then]
                    [sound]
                        name=skeleton-big-hit-1.ogg
                    [/sound]

                    [fire_event]
                        name=raise undead
                    [/fire_event]

                    [animate_unit]
                        [filter]
                            id=Mal Keshar
                        [/filter]
                        [primary_attack]
                            range=ranged
                        [/primary_attack]
                        flag=attack
                    [/animate_unit]

                    [unit]
                        side=1
                        type=Skeleton
                        x,y=19,4
                        animate=yes
                        passable=yes
                        overwrite=no
                    [/unit]
                    [unit]
                        side=1
                        type=Walking Corpse
                        x,y=20,3
                        animate=yes
                        passable=yes
                        overwrite=no
                    [/unit]

                    {VARIABLE runes_activated 1}
                [/then]
            [/elseif]

            [elseif]
                [have_unit]
                    id=Mal Keshar
                    x,y=22,4
                [/have_unit]
                [then]
                    [sound]
                        name=skeleton-big-hit-1.ogg
                    [/sound]

                    [fire_event]
                        name=raise undead
                    [/fire_event]

                    [animate_unit]
                        [filter]
                            id=Mal Keshar
                        [/filter]
                        [primary_attack]
                            range=ranged
                        [/primary_attack]
                        flag=attack
                    [/animate_unit]

                    [unit]
                        side=1
                        type=Ghost
                        x,y=21,5
                        animate=yes
                        passable=yes
                        overwrite=no
                    [/unit]
                    [unit]
                        side=1
                        type=Walking Corpse
                        x,y=23,5
                        animate=yes
                        passable=yes
                        overwrite=no
                    [/unit]

                    {VARIABLE runes_activated 1}
                [/then]
            [/elseif]

            [elseif]
                [have_unit]
                    id=Mal Keshar
                    x,y=15,3
                [/have_unit]
                [then]
                    [sound]
                        name=skeleton-big-hit-1.ogg
                    [/sound]

                    [fire_event]
                        name=raise undead
                    [/fire_event]

                    [animate_unit]
                        [filter]
                            id=Mal Keshar
                        [/filter]
                        [primary_attack]
                            range=ranged
                        [/primary_attack]
                        flag=attack
                    [/animate_unit]

                    [unit]
                        side=1
                        type=Skeleton Archer
                        x,y=14,2
                        animate=yes
                        passable=yes
                        overwrite=no
                    [/unit]
                    [unit]
                        side=1
                        type=Walking Corpse
                        x,y=14,3
                        animate=yes
                        passable=yes
                        overwrite=no
                    [/unit]

                    {VARIABLE runes_activated 1}
                [/then]
            [/elseif]
        [/if]
    [/event]

    [event]
        name=raise undead

        [message]
            speaker=Mal Keshar
            message= _ "There are many corpses around here. I can use them to my advantage."
        [/message]
    [/event]

    # Victory
    [event]
        name=last breath
        [filter]
            id=Xanthric
        [/filter]

        [delay]
            time=500
        [/delay]

        [kill]
            side=2
            [not]
                id=Xanthric
            [/not]
        [/kill]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Xanthric
            message= _ "How could this happen..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "You were not as powerful as you thought."
        [/message]

        [animate_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [message]
            speaker=Xanthric
            message= _ "<i>I feel... so... cold...</i>"
        [/message]

        [kill]
            id=Xanthric
            animate=yes
        [/kill]

        [message]
            speaker=Mal Keshar
            message= _ "So, the beast dies. I will have to make a few modifications to this lair later. First, I shall have to test the extent to which I can push these new powers."
        [/message]

        [animate_unit]
            [filter]
                id=Mal Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=1000
        [/delay]

        [sound]
            name=magic-dark.ogg
        [/sound]

        [delay]
            time=250
        [/delay]

        {QUAKE cave-in.ogg}

        [delay]
            time=1000
        [/delay]

        [sound]
            name=magic-dark.ogg
        [/sound]

        [delay]
            time=250
        [/delay]

        {QUAKE cave-in.ogg}

        [delay]
            time=1000
        [/delay]

        [sound]
            name=magic-dark.ogg
        [/sound]

        [delay]
            time=250
        [/delay]

        [sound]
            name=magic-dark.ogg
        [/sound]

        [delay]
            time=250
        [/delay]

        [sound]
            name=magic-dark-big.ogg
        [/sound]

        [delay]
            time=250
        [/delay]

        [unit]
            id=Xanthric
            name= _ "Xanthric"
            type=Skeletal Dragon
            side=1
            x,y=$x1,$y1
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
                [object]
                    take_only_once=yes
                    silent=yes
                    duration=forever
                    [filter]
                        id=Xanthric
                    [/filter]
                    [effect]
                        apply_to=new_ability
                        [abilities]
                            {ABILITY_FEEDING}
                        [/abilities]
                    [/effect]
                [/object]
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [object]
            take_only_once=yes
            silent=yes
            duration=forever
            [filter]
                id=Xanthric
            [/filter]
            [effect]
                apply_to=attack
                name=jaw
                defense_weight=0.8
            [/effect]
            [effect]
                apply_to=attack
                name=claws
                defense_weight=0.2
            [/effect]
        [/object]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Mal Keshar
            message= _ "Excellent! My will is even strong enough to conquer a dragon. None can stand against me any longer! To those who cursed me prior: I spit at thee! For I am Mal Keshar the Damned, spurned by all men, forsaken by all who live and draw breath! I laugh, for now, you are all naught but remains and dust, and I live on, alone..."
        [/message]

        [endlevel]
            result=victory
            bonus=no
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Malin Keshar
        [/filter]

        [message]
            speaker=unit
            message= _ "So this is how it ends..."
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE scenario_stage}
        {CLEAR_VARIABLE puzzle_coffin}
        {CLEAR_VARIABLE puzzle_potion}
        {CLEAR_VARIABLE runes_activated}

        {VARIABLE timesForever 0}
    [/event]

    {HERODEATH_MALIN_LICH}
[/scenario]
