#textdomain wesnoth-did

[scenario]
    id=07c_A_Small_Favor3
    name= _ "A Small Favor — III"
    map_file=07c_A_Small_Favor3.map
    {TURNS 21 18 15}
    next_scenario=08_Alone_at_Last
    victory_when_enemies_defeated=no

    {UNDERGROUND}

    {SCENARIO_MUSIC       the_city_falls.ogg}
    {EXTRA_SCENARIO_MUSIC the_king_is_dead.ogg}

    # No story; this occurs immediately after the previous scenario

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        gold=0
        team_name=intruders
        user_team_name= _ "Intruders"
        {FLAG_VARIANT undead}
        color=darkblue

        income=-2

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

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

    [side]
        side=2
        controller=ai
        team_name=defenders
        user_team_name= _ "Defenders"
        no_leader=yes
        hidden=yes
        color=purple

        {NAMED_NOTRAIT_UNIT 2 (Silver Mage) 11 9 ("")
        # po: Book guards
        ( _ "Guardian")
        # po: Book guards
        FEMALE_NAME=_"female^Guardian"} {GUARDIAN}
        {NAMED_NOTRAIT_UNIT 2 (Silver Mage) 13 7 ("") ( _ "Guardian") FEMALE_NAME=_"female^Guardian"} {GUARDIAN}

        [ai]
            village_value=0
            aggression=0.8
        [/ai]
    [/side]

    [side]
        side=3
        controller=ai
        team_name=intruders
        user_team_name= _ "Intruders"
        no_leader=yes
        color=black
        hidden=yes
        shroud=yes
        share_vision=none

        [ai]
            village_value=0
            aggression=0.8
            [goal]
                name=protect_unit
                [criteria]
                    id=Darken Volk
                [/criteria]
                value=20
            [/goal]
            [goal]
                name=protect_unit
                [criteria]
                    id=Darken Volk
                [/criteria]
                protect_radius=6
                value=20
            [/goal]
        [/ai]
    [/side]
    # City guard
    [side]
        side=4
        controller=ai
        team_name=defenders
        user_team_name= _ "Defenders"
        no_leader=yes
        hidden=yes
        {FLAG_VARIANT loyalist}
        color=gold
        [ai]
            village_value=0
            aggression=0.8
        [/ai]
    [/side]

    # This macro places the doors and adds the door-opening event
    {MANOR_DOORS 1,3}

    # scenery

    {PLACE_IMAGE items/dragonstatue.png 23 16}
    {PLACE_IMAGE items/dragonstatue.png 24 15}
    {PLACE_IMAGE items/dragonstatue.png 31 12}
    {PLACE_IMAGE scenery/monolith4.png 34 11}
    {PLACE_IMAGE scenery/monolith3.png 29 14}
    {PLACE_IMAGE scenery/monolith1.png 29 16}
    {PLACE_IMAGE scenery/monolith3.png 26 15}
    {PLACE_IMAGE scenery/monolith4.png 26 18}
    {PLACE_IMAGE scenery/castle-ruins2.png 32 15}
    {PLACE_IMAGE scenery/castle-ruins3.png 32 14}
    {PLACE_IMAGE scenery/castle-ruins3.png 25 15}
    {PLACE_IMAGE scenery/castle-ruins2.png 24 18}
    {PLACE_IMAGE scenery/castle-ruins.png 33 4}
    {PLACE_IMAGE scenery/castle-ruins3.png 33 3}
    {PLACE_IMAGE scenery/castle-ruins2.png 31 5}
    {PLACE_IMAGE scenery/castle-ruins2.png 9 11}
    {PLACE_IMAGE scenery/castle-ruins.png 8 7}

    {PLACE_IMAGE items/ornate2.png 23 11}
    {PLACE_IMAGE items/ornate2.png 25 12}
    {PLACE_IMAGE items/ornate1.png 20 13}
    {PLACE_IMAGE items/coffin-open.png 22 12}

    {PLACE_IMAGE items/cloak-green.png 11 17}
    {PLACE_IMAGE items/armor.png 14 16}
    {PLACE_IMAGE items/armor.png 16 16}
    {PLACE_IMAGE items/bow.png 30 9}
    {PLACE_IMAGE items/bow-crystal.png 29 9}
    {PLACE_IMAGE items/spear-fancy.png 27 10}
    {PLACE_IMAGE items/axe.png 27 9}

    {PLACE_IMAGE items/potion-blue.png 18 3}
    {PLACE_IMAGE items/potion-blue.png 17 6}
    {PLACE_IMAGE items/potion-grey.png 17 3}
    {PLACE_IMAGE items/potion-grey.png 19 4}
    {PLACE_IMAGE items/potion-grey.png 21 5}
    {PLACE_IMAGE items/potion-green.png 19 5}
    {PLACE_IMAGE items/potion-green.png 22 3}
    {PLACE_IMAGE items/potion-red.png 19 3}
    {PLACE_IMAGE items/potion-red.png 14 3}
    {PLACE_IMAGE items/potion-yellow.png 17 4}
    {PLACE_IMAGE items/altar-evil.png 18 4}
    {PLACE_IMAGE items/altar.png 14 8}
    {PLACE_IMAGE items/holy-water.png 14 9}
    {PLACE_IMAGE items/holy-water.png 14 7}
    {PLACE_IMAGE items/holy-water.png 15 8}
    {PLACE_IMAGE items/holy-water.png 10 8}
    {PLACE_IMAGE items/stone-tablet.png 7 11}
    {PLACE_IMAGE items/stone-tablet.png 15 10}

    {PLACE_IMAGE items/dragonstatue.png 19 7}
    {PLACE_IMAGE scenery/monolith3.png 16 11}
    {PLACE_IMAGE scenery/monolith1.png 21 7}
    {PLACE_IMAGE scenery/monolith3.png 19 9}
    {PLACE_IMAGE scenery/monolith1.png 12 4}
    {PLACE_IMAGE scenery/monolith1.png 9 12}
    {PLACE_IMAGE scenery/monolith3.png 10 7}
    {PLACE_IMAGE scenery/monolith4.png 10 11}
    {PLACE_IMAGE scenery/monolith4.png 4 10}

    {PLACE_IMAGE items/barrel.png 29 17}
    {PLACE_IMAGE items/barrel.png 28 17}
    {PLACE_IMAGE items/barrel.png 28 13}
    {PLACE_IMAGE items/barrel.png 22 19}
    {PLACE_IMAGE items/barrel.png 21 19}
    {PLACE_IMAGE items/barrel.png 29 8}
    {PLACE_IMAGE items/barrel.png 30 7}
    {PLACE_IMAGE items/barrel.png 14 17}
    {PLACE_IMAGE items/barrel.png 34 4}
    {PLACE_IMAGE items/barrel.png 23 3}
    {PLACE_IMAGE items/box.png 29 13}
    {PLACE_IMAGE items/box.png 22 18}
    {PLACE_IMAGE items/box.png 13 18}
    {PLACE_IMAGE items/box.png 13 17}
    {PLACE_IMAGE items/box.png 28 4}
    {PLACE_IMAGE items/box.png 27 5}
    {PLACE_IMAGE items/box.png 26 5}

    [event]
        name=prestart

        # yes this value is not as adjusted as the previous scenario, but that's because we're underground
        {COLOR_ADJUST -10 -10 -10}

        # place the book's image
        [item]
            location_id=book_start
            image="items/book5.png"
        [/item]

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Retrieve the book and escape"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Darken Volk"
            [/objective]

            {TURNS_RUN_OUT}

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

        [set_variables]
            name=guardtypetable
            [value]
                type=Shock Trooper
            [/value]
#ifndef HARD
            [value]
                type=Spearman
            [/value]
#endif
            [value]
                type=Duelist
            [/value]
            [value]
                type=Pikeman
            [/value]
            [value]
                type=Swordsman
            [/value]
#ifndef EASY
            [value]
                type=Swordsman
            [/value]
            [value]
                type=Pikeman
            [/value]
            [value]
                type=Duelist
            [/value]
#endif
            [value]
                type=Heavy Infantryman
            [/value]
            [value]
                type=Spearman
            [/value]
            [value]
                type=Fencer
            [/value]
        [/set_variables]

        [set_variables]
            name=magetypetable
            [value]
                type=Mage
            [/value]
            [value]
                type=White Mage
            [/value]
            [value]
                type=Mage
            [/value]
            [value]
                type=Red Mage
            [/value]
            [value]
                type=Red Mage
            [/value]
#ifdef EASY
            [value]
                type=Mage
            [/value]
#endif
#ifndef EASY
            [value]
                type=White Mage
            [/value]
            [value]
                type=Red Mage
            [/value]
#endif
#ifdef HARD
            [value]
                type=Red Mage
            [/value]
            [value]
                type=White Mage
            [/value]
#endif
            [value]
                type=Mage
            [/value]
            [value]
                type=Mage
            [/value]
            [value]
                type=Mage
            [/value]
        [/set_variables]

        [random_placement]
            num_items={ON_DIFFICULTY 5 6 7}
            variable=loc
            min_distance=3
            [filter_location]
                terrain=Urb,Urb^E*,Ur,Ur^E*
                [not]
                    x=27-35
                    y=1-7
                [/not]
                [not]
                    x=20-35,24
                    y=16-20,15
                [/not]
                [not]
                    x=25-29
                    y=13-20
                [/not]
                [not]
                    x=30-35
                    y=11-20
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NAMED_NOTRAIT_UNIT 2 "$guardtypetable[$($loc.n % $guardtypetable.length)].type"
                # po: Unit name
                $loc.x $loc.y () (_ "Guard")
                # po: Unit name
                FEMALE_NAME=_"female^Guard"} {GUARDIAN}
            [/command]
        [/random_placement]
        [random_placement]
            num_items={ON_DIFFICULTY 6 6 7}
            variable=loc
            min_distance=3
            [filter_location]
                terrain=Urb,Urb^E*,Ur,Ur^E*,Isr,Isr^*
                [not]
                    x=27-35
                    y=1-7
                [/not]
                [not]
                    x=20-35,24
                    y=16-20,15
                [/not]
                [not]
                    x=25-29
                    y=13-20
                [/not]
                [not]
                    x=30-35
                    y=11-20
                [/not]
                [not]
                    [filter][/filter]
                [/not]
            [/filter_location]
            [command]
                {NAMED_NOTRAIT_UNIT 2 "$magetypetable[$($loc.n % $magetypetable.length)].type" $loc.x $loc.y () (_ "Mage") FEMALE_NAME=_"female^Mage"} {GUARDIAN}
            [/command]
        [/random_placement]

        # Who has the book?
        {VARIABLE hasBook none}

        # Switch Volk's side
        [recall]
            id=Darken Volk
            x,y=26,16
        [/recall]

        [modify_unit]
            [filter]
                id=Darken Volk
            [/filter]
            side=3
        [/modify_unit]

        [lock_view][/lock_view]
    [/event]

    [event]
        name=start

        [store_unit]
            [filter]
                [filter_wml]
                    [variables]
                        got_inside_manor=yes
                    [/variables]
                [/filter_wml]
            [/filter]

            variable=units_inside_manor
        [/store_unit]

        [foreach]
            array=units_inside_manor
            [do]
                [recall]
                    id=$this_item.id
                [/recall]

                [modify_unit]
                    [filter]
                        id=$this_item.id
                    [/filter]

                    [object]
                        duration=scenario
                        [effect]
                            apply_to=loyal
                        [/effect]
                    [/object]
                [/modify_unit]

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

        {CLEAR_VARIABLE units_inside_manor}

        # Create DV's units
        {GENERIC_UNIT 3 (Draug)    26 16}
        [+unit]
            animate=yes
        [/unit]

        {GENERIC_UNIT 3 (Deathblade) 26 16}
        [+unit]
            animate=yes
        [/unit]

        {GENERIC_UNIT 3 (Necrophage) 26 16}
        [+unit]
            animate=yes
        [/unit]

        {GENERIC_UNIT 3 (Banebow)    26 16}
        [+unit]
            animate=yes
        [/unit]

        [message]
            speaker=Darken Volk
            message= _ "The book is very close, somewhere to the northwest."
        [/message]

        [unlock_view][/unlock_view]
    [/event]

    [event]
        name=side 3 turn refresh
        first_time_only=no

        [store_unit]
            [filter]
                id=Darken Volk
            [/filter]
            variable=stored_Darken
        [/store_unit]

        [if]
            [variable]
                name=hasBook
                equals=none
            [/variable]
            [then]
                [if]
                    [variable]
                        name=turn_number
                        greater_than=4
                    [/variable]
                    [then]
                        [store_locations]
                            location_id=book_start
                            variable=dest
                        [/store_locations]
                    [/then]
                    [else]
                        {VARIABLE dest.x 16}
                        {VARIABLE dest.y 14}
                    [/else]
                [/if]
            [/then]
            [else]
                {VARIABLE dest.x 31}
                {VARIABLE dest.y 1}
            [/else]
        [/if]

        [find_path]
            [traveler]
                id=Darken Volk
            [/traveler]
            [destination]
                x=$dest.x
                y=$dest.y
            [/destination]
            variable=darken_goto
            allow_multiple_turns=yes
        [/find_path]

        [if]
            [variable]
                name=darken_goto.step.length
                greater_than=0
            [/variable]
            [then]
                {VARIABLE index "$(min($stored_Darken.max_moves,$darken_goto.step.length-1))"}
                {VARIABLE stored_Darken.goto_x $darken_goto.step[$index].x}
                {VARIABLE stored_Darken.goto_y $darken_goto.step[$index].y}
            [/then]
            [else]
                {VARIABLE stored_Darken.goto_x $dest.x}
                {VARIABLE stored_Darken.goto_y $dest.y}
            [/else]
        [/if]

        [unstore_unit]
            variable=stored_Darken
        [/unstore_unit]

        {CLEAR_VARIABLE stored_Darken,dest,darken_goto,index}
    [/event]

    # If there are no enemies, then DV's troops won't move; this event unblocks the book if necessary.
    [event]
        name=side 3 turn refresh
        first_time_only=no
        [filter_condition]
            [variable]
                name=hasBook
                equals=none
            [/variable]
            [have_unit]
                # This won't be DV himself, otherwise hasBook is not none.
                side=3
                [filter_location]
                    location_id=book_start
                [/filter_location]
            [/have_unit]
            [not]
                [have_unit]
                    # Ignore side=4, the city guard is (hopefully for the player) not near the book.
                    side=2
                    [filter_vision]
                        # There are 3 entrance rooms, one of them might still have all of its doors shut.
                        side=3
                    [/filter_vision]
                [/have_unit]
            [/not]
        [/filter_condition]
        [modify_unit]
            [filter]
                [filter_location]
                    location_id=book_start
                [/filter_location]
            [/filter]
            # Somewhere inside the tunnel, but out-of-the-way for the hexes that Malin must move to.
            goto_x=29
            goto_y=2
        [/modify_unit]
    [/event]

    # pursuer spawns

#define SPAWN_GUARD
    [random_placement]
        num_items=1
        variable=loc
        min_distance=1
        [filter_location]
            x=33-34,35
            y=17-18,18-19
            [not]
                [filter][/filter]
            [/not]
        [/filter_location]
        [command]
            [set_variable]
                name=ind
                rand=1..$guardtypetable.length
            [/set_variable]
            {VARIABLE_OP ind sub 1}
            {GENERIC_UNIT 4 "$guardtypetable[$ind].type" $loc.x $loc.y}
            {CLEAR_VARIABLE ind}
        [/command]
    [/random_placement]
#enddef
#define SPAWN_MAGE
    [random_placement]
        num_items=1
        variable=loc
        min_distance=1
        [filter_location]
            x=33-34,35
            y=17-18,18-19
            [not]
                [filter][/filter]
            [/not]
        [/filter_location]
        [command]
            [set_variable]
                name=ind
                rand=1..$magetypetable.length
            [/set_variable]
            {VARIABLE_OP ind sub 1}
            {GENERIC_UNIT 4 "$magetypetable[$ind].type" $loc.x $loc.y}
            {CLEAR_VARIABLE ind}
        [/command]
    [/random_placement]
#enddef

    [event]
        name=new turn
        first_time_only=no

        [if]
            [variable]
                name=turn_number
                greater_than_equal_to={ON_DIFFICULTY 14 12 10}
            [/variable]
            [then]
                {RANDOM 0..2}
                [switch]
                    variable=random
                    [case]
                        value=0
                        {SPAWN_GUARD}
                        {SPAWN_GUARD}
                    [/case]
                    [case]
                        value=1
                        {SPAWN_MAGE}
#ifdef HARD
                        {SPAWN_MAGE}
#else
                        {SPAWN_GUARD}
#endif
                    [/case]
                    [case]
                        value=2
                        {SPAWN_GUARD}
                        {SPAWN_MAGE}
                    [/case]
                [/switch]
            [/then]
            [elseif]
                [variable]
                    name=turn_number
                    greater_than_equal_to={ON_DIFFICULTY 8 7 6}
                [/variable]
                [then]
                    [set_variable]
                        name=turn_mod
                        value=$("($turn_number - {ON_DIFFICULTY 8 7 6}) % 2")
                    [/set_variable]
                    [if]
                        [variable]
                            name=turn_mod
                            numerical_equals=0
                        [/variable]
                        [then]
                            {RANDOM 0..3}
                            [switch]
                                variable=random
                                [case]
                                    value=0
                                    {SPAWN_GUARD}
#ifdef HARD
                                    {SPAWN_GUARD}
#endif
                                [/case]
                                [case]
                                    value=1
                                    {SPAWN_GUARD}
                                    {SPAWN_GUARD}
                                [/case]
                                [case]
                                    value=2
                                    {SPAWN_MAGE}
                                [/case]
                                [case]
                                    value=3
                                    {SPAWN_GUARD}
                                    {SPAWN_MAGE}
                                [/case]
                            [/switch]
                        [/then]
                    [/if]
                    {CLEAR_VARIABLE turn_mod}
                [/then]
            [/elseif]
            [elseif]
                [variable]
                    name=turn_number
                    greater_than_equal_to=2
                [/variable]
                [then]
                    [set_variable]
                        name=turn_mod
                        value=$("($turn_number - 2) % 3")
                    [/set_variable]
                    [if]
                        [variable]
                            name=turn_mod
                            numerical_equals=0
                        [/variable]
                        [then]
                            {RANDOM 0..3}
                            [switch]
                                variable=random
                                [case]
                                    value=0
                                    {SPAWN_GUARD}
                                    {SPAWN_GUARD}
                                [/case]
                                [case]
                                    value=1
                                    {SPAWN_GUARD}
#ifdef HARD
                                    {SPAWN_GUARD}
#endif
                                [/case]
                                [case]
                                    value=2
                                    {SPAWN_MAGE}
                                [/case]
                                [case]
                                    value=3
                                    {SPAWN_GUARD}
                                    {SPAWN_MAGE}
                                [/case]
                            [/switch]
                        [/then]
                    [/if]
                    {CLEAR_VARIABLE turn_mod}
                [/then]
            [/elseif]
        [/if]

        [fire_event]
            name=city guard dialogue
        [/fire_event]
        [fire_event]
            name=city guard dialogue2
        [/fire_event]
    [/event]

    [event]
        name=city guard dialogue
        [filter_condition]
            [variable]
                name=turn_number
                equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Darken Volk
            message= _ "The guards continue to pursue us."
        [/message]
    [/event]
    [event]
        name=city guard dialogue2
        [filter_condition]
            [variable]
                name=turn_number
                equals={ON_DIFFICULTY 14 12 10}
            [/variable]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "The guards are catching up to us."
        [/message]
    [/event]

    # Flavor text

    [event]
        name=moveto
        [filter]
            x,y=15,10
            side=1
        [/filter]
        [message]
            speaker=narrator
            message= _ "<i>Beware that, when fighting monsters, you yourself do not become a monster...</i>"
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=7,11
            side=1
        [/filter]
        [message]
            speaker=narrator
            message= _ "<i>Death is the twilight that follows the light of day.
Life fades with the setting sun into darkness.
Existence churns and the soul is reborn into endless night.</i>"
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=18,4
            side=1
        [/filter]
        [message]
            speaker=Malin Keshar
            message= _ "There are quite a few failed potions around here."
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=22,12
            side=1
        [/filter]
        [message]
            speaker=Malin Keshar
            message= _ "This coffin is empty."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x=20,23,25
            y=13,11,12
            race=undead
            side=1
        [/filter]

        # throwback to S7 when you knock over the holy water
        [message]
            speaker=Malin Keshar
            message= _ "Be careful around those urns."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=11,17
            id=Malin Keshar
        [/filter]

        [message]
            speaker=Malin Keshar
            message= _ "Fancy, but I’ve no use for a new cloak right now."
        [/message]
    [/event]

    # the armory
    # only allow level 3s and your fancy chocobone (if you got it) to take items
    # also make it silent besides some small sound effects
    [event]
        name=moveto
        [filter]
            x,y=27,9
            side=1
            type=Draug
        [/filter]

        [sound]
            name=skeleton-big-hit-1.ogg
        [/sound]

        [object]
            silent=yes
            duration=forever
            [filter]
                x,y=27,9
            [/filter]
            [effect]
                apply_to=attack
                range=melee
                increase_damage=1
            [/effect]
        [/object]

        {REMOVE_IMAGE 27 9}
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=29,9
            side=1
            type=Banebow
        [/filter]

        [sound]
            name=skeleton-big-hit-2.ogg
        [/sound]

        [object]
            silent=yes
            duration=forever
            [filter]
                x,y=29,9
            [/filter]
            [effect]
                apply_to=attack
                range=ranged
                increase_damage=1
            [/effect]
        [/object]

        {REMOVE_IMAGE 29 9}
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=30,9
            side=1
            type=Banebow
        [/filter]

        [sound]
            name=skeleton-big-hit-1.ogg
        [/sound]

        [object]
            silent=yes
            duration=forever
            [filter]
                x,y=30,9
            [/filter]
            [effect]
                apply_to=attack
                range=ranged
                increase_damage=1
            [/effect]
        [/object]

        {REMOVE_IMAGE 30 9}
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=27,10
            side=1
            type=Chocobone
        [/filter]

        [sound]
            name=skeleton-big-hit-3.ogg
        [/sound]

        [object]
            silent=yes
            duration=forever
            [filter]
                x,y=27,10
            [/filter]
            [effect]
                apply_to=attack
                range=melee
                increase_damage=2
            [/effect]
        [/object]

        {REMOVE_IMAGE 27 10}
    [/event]

    [event]
        # a side 1 unit finds the book
        name=moveto
        [filter]
            side=1
            canrecruit=no
            [filter_location]
                location_id=book_start
            [/filter_location]
        [/filter]
        [filter_condition]
            [variable]
                name=hasBook
                equals=none
            [/variable]
        [/filter_condition]

        [if]
            [have_unit]
                [filter_location]
                    location_id=book_start
                [/filter_location]
                race=undead
            [/have_unit]
            [then]
                [message]
                    id=Darken Volk
                    # po: The speaker addresses an undead minion.
                    message=_ "The book! Guard it with your unlife while I come to fetch it."
                [/message]
            [/then]
            [else]
                [message]
                    id=Darken Volk
                    # po: The speaker addresses a human or a bat.
                    message=_ "The book! Guard it with your life while I come to fetch it."
                [/message]
            [/else]
        [/if]
    [/event]

    [event]
        # Malin gets the book
        name=moveto
        [filter]
            id=Malin Keshar
            [filter_location]
                location_id=book_start
            [/filter_location]
        [/filter]
        [filter_condition]
            [variable]
                name=hasBook
                equals=none
            [/variable]
        [/filter_condition]

        [remove_item]
            location_id=book_start
        [/remove_item]

        {VARIABLE hasBook Malin}

        [message]
            speaker=Darken Volk
            message= _ "Hand that over."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Can’t it wait until we’re away from all these guards?"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "... Fine. There is a small tunnel in the cellar to the northeast. It will lead us far enough out of the city that we can escape pursuit."
        [/message]

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Escape via the tunnel in the northeast cellar"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Darken Volk"
            [/objective]

            {TURNS_RUN_OUT}

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

        [event]
            name=moveto
            [filter]
                id=Malin Keshar
                x,y=29-32,1-3
            [/filter]

            [message]
                speaker=Malin Keshar
                message= _ "Let’s get out of here."
            [/message]

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

    [event]
        # DV gets the book
        name=moveto
        [filter]
            id=Darken Volk
            [filter_location]
                location_id=book_start
            [/filter_location]
        [/filter]
        [filter_condition]
            [variable]
                name=hasBook
                equals=none
            [/variable]
        [/filter_condition]

        [remove_item]
            location_id=book_start
        [/remove_item]

        {VARIABLE hasBook Darken}

        # A second, non-silent, update triggers when DV moves again (next turn, he's still set to go to the book_start hex this turn).
        [objectives]
            side=1
            silent=yes
            [objective]
                condition=win
                description= _ "Escape via the tunnel in the northeast cellar"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Darken Volk"
            [/objective]

            {TURNS_RUN_OUT}
        [/objectives]

        [event]
            name=moveto
            [filter]
                id=Darken Volk
                side=3
            [/filter]

            [message]
                speaker=Malin Keshar
                message= _ "We’ve got the book, but how do we get out of here?"
            [/message]

            [scroll_to_unit]
                id=Darken Volk
            [/scroll_to_unit]

            [delay]
                time=500
            [/delay]

            [message]
                speaker=Malin Keshar
                message= _ "Wait, you aren’t leaving me behind, are you?"
            [/message]

            [objectives]
                side=1
                [objective]
                    condition=win
                    description= _ "Escape the manor (Malin reaches the tunnel in the northeast cellar before Darken Volk)"
                [/objective]
                [objective]
                    condition=lose
                    description= _ "Darken Volk reaches the tunnel before Malin does"
                [/objective]
                [objective]
                    condition=lose
                    description= _ "Death of Malin Keshar"
                [/objective]
                [objective]
                    condition=lose
                    description= _ "Death of Darken Volk"
                [/objective]

                {TURNS_RUN_OUT}
            [/objectives]
        [/event]

        [event]
            name=moveto
            [filter]
                id=Darken Volk
                x,y=30-31,1
            [/filter]

            [message]
                speaker=Darken Volk
                message= _ "You have served me well, boy."
            [/message]

            [message]
                speaker=narrator
                image=wesnoth-icon.png
                message= _ "As he heads into the tunnel, Darken Volk collapses the entrance, leaving Malin to be captured and executed by the city guards."
            [/message]

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

        [event]
            name=moveto
            [filter]
                id=Malin Keshar
                x,y=29-32,1-3
            [/filter]

            [message]
                speaker=Malin Keshar
                message= _ "Let’s get out of here."
            [/message]

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

    [event]
        name=time over

        [remove_shroud]
            side=1
            x=29-33
            y=0-4
        [/remove_shroud]

        [unit]
            type=Royal Guard
            side=4
            x,y=32,2
            id=RGuard
            canrecruit=yes
            animate=yes
            facing=sw
        [/unit]
        {GENERIC_UNIT 4 (Pikeman) 30 2} {FACING sw}
        {GENERIC_UNIT 4 (Longbowman) 30 1} {FACING sw}
        {GENERIC_UNIT 4 (Swordsman) 31 2} {FACING sw}
        {GENERIC_UNIT 4 (Mage of Light) 31 1} {FACING sw}

        [message]
            speaker=RGuard
            message= _ "Surround those necromancers! They cannot escape now!"
        [/message]

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

    [event]
        name=victory

        {CLEAR_VARIABLE guardtypetable}
        {CLEAR_VARIABLE magetypetable}
        {CLEAR_VARIABLE random}
        {MODIFY_UNIT (id=Darken Volk) side 1}
    [/event]

    {HERODEATH_MALIN}
    {HERODEATH_VOLK_B}
[/scenario]

#undef SPAWN_GUARD
#undef SPAWN_MAGE
