#textdomain wesnoth-did

[scenario]
    id=10_Alone_at_Last
    name= _ "Alone at Last"
    map_data="{campaigns/Descent_Into_Darkness/maps/10_Alone_at_Last.map}"
    {TURNS 34 30 26}
    next_scenario=11_Descent_into_Darkness
    victory_when_enemies_defeated=no

    {DEFAULT_SCHEDULE_DUSK}

    {SCENARIO_MUSIC       knolls.ogg}
    {EXTRA_SCENARIO_MUSIC siege_of_laurelmor.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    [story]
        [part]
            story= _ "As he enters the tunnel underneath Lord Karres’s manor, Darken Volk gestures, causing the entrance to collapse. The two necromancers turn and begin walking down the pitch-black tunnel, temporarily safe from pursuit."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story= _ "Silence permeates the darkness, broken only by the irregular dripping of water from the musty cave walls. Malin looks toward Darken Volk occasionally, expecting something from the elder necromancer, but is met with stone-cold dispassion. There is no acknowledgment... no word of gratitude — only a sense of unease that has as much to do with the book as it does with Darken Volk."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story= _ "They continue walking through the damp, cold air all through the morning and day, finally emerging as the last rays of sunlight sink below the horizon."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_10_NEW}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept DiD
        {GOLD 260 220 180}
        team_name=good
        user_team_name= _ "Malin Keshar"
        {FLAG_VARIANT undead}
        village_gold=2
        village_support=1

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

        facing=ne
    [/side]
    # wmllint: validate-on

    # Darken Volk
    [side]
        side=2
        controller=ai
        recruit=Blood Bat,Ghost,Wraith,Necrophage,Skeleton Archer,Bone Shooter,Skeleton,Revenant,Deathblade,Dark Adept DiD,Dark Sorcerer DiD
        {GOLD 170 220 270}
        {INCOME 20 25 30}
        team_name=bad
        user_team_name= _ "Darken Volk"
        no_leader=yes

        {FLAG_VARIANT undead}

        [ai]
            village_value=0.2
            villages_per_scout=10
            [goal]
                name=target
                [criteria]
                    id=Malin Keshar
                [/criteria]
                value=2
            [/goal]

            [goal]
                name=protect_unit
                [criteria]
                    side=2
                    canrecruit=yes
                [/criteria]
                value=4
            [/goal]
        [/ai]
    [/side]

    # Paladins and co
    [side]
        side=3
        controller=ai
        recruit=Spearman,Heavy Infantryman,White Mage,Mage,Paladin
        gold=0
        team_name=wesnothians
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}

        income=-2
        no_leader=yes
        hidden=yes

        [ai]
            village_value=0.1
            villages_per_scout=10
            #recruitment_pattern=fighter,healer
            [goal]
                name=target
                [criteria]
                    side=2
                [/criteria]
                value=3
            [/goal]

            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=2
            [/goal]
        [/ai]
    [/side]

    # Dela Keshar
    [side]
        side=4
        controller=ai
        gold=0
        recruit=Spearman,Bowman,Swordsman,Longbowman,Thug,Poacher,Footpad
        team_name=wesnothians
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}

        income=-2
        no_leader=yes
        hidden=yes

        [ai]
            passive_leader=yes
            [goal]
                name=target
                [criteria]
                    id=Malin Keshar
                [/criteria]
                value=2
            [/goal]
        [/ai]
    [/side]

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Take the book back from Darken Volk"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]

            {TURNS_RUN_OUT}

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

        # Scenario variables
        {VARIABLE bookX -1}
        {VARIABLE bookY -1}

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

        [recall]
            id=Darken Volk
            x,y=2,26
        [/recall]

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

            kill=yes
            variable=stored_Darken
        [/store_unit]

        {VARIABLE stored_Darken.side       2}
        {VARIABLE stored_Darken.canrecruit yes}
        {VARIABLE stored_Darken.role       book_carrier}

        # Removes the loyal trait and other misc stuff
        {CLEAR_VARIABLE stored_Darken.modifications.trait[0]}
        {CLEAR_VARIABLE stored_Darken.overlays}
        {CLEAR_VARIABLE stored_Darken.ellipse}

        [unstore_unit]
            variable=stored_Darken
        [/unstore_unit]

        {CLEAR_VARIABLE stored_Darken}
    [/event]

    [event]
        name=start

        {MOVE_UNIT (id=Malin Keshar) 6 14}
        {MOVE_UNIT (id=Darken Volk) 9 15}

        [message]
            speaker=Malin Keshar
            message= _ "Well, we got your precious book and made it out of Tath in one piece. What do we do now?"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "‘We’? <i>We</i> do nothing."
        [/message]

        [if]
            [variable]
                name=hasBook
                equals=Malin
            [/variable]
            [then]
                # Malin has the book

                {MOVE_UNIT (id=Darken Volk) 7 14}

                [message]
                    speaker=Darken Volk
                    message= _ "Now give the book to me."
                [/message]

                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message=_ "Darken Volk grabs the mysterious book from Malin’s hands and stalks away."
                [/message]

                {MODIFY_UNIT (id=Darken Volk) facing se}
            [/then]
            [else]
                # DV already has book
                [message]
                    speaker=Darken Volk
                    message= _ "Now go your own way, and I will go mine."
                [/message]
            [/else]
        [/if]

        {CLEAR_VARIABLE hasBook}

        [unit_overlay]
            id=Darken Volk
            image="misc/book-icon.png"
        [/unit_overlay]

        {MODIFY_UNIT (id=Darken Volk) facing ne}

        {MOVE_UNIT (id=Darken Volk) 9 15}
        {MOVE_UNIT (id=Darken Volk) 11 15}

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "You can’t just leave me here!"
        [/message]

        {MOVE_UNIT (id=Malin Keshar) 7 15}
        {MOVE_UNIT (id=Malin Keshar) 8 14}

        {CREATE_ADVISOR}

        [message]
            role=advisor
            message= _ "Master, do you not see? He has merely been using you to get that book!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "What do you mean?"
        [/message]

        [message]
            role=advisor
            message= _ "He cares not about your noble quest to push back the orcs. He needed your help to fight the mages!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Wait!"
        [/message]

        {MOVE_UNIT (id=Darken Volk) 12 15}

        [message]
            speaker=Malin Keshar
            message= _ "You used me! You knew the people of Parthyn would cast me out — you knew I had nobody else to turn to! You knew I would do whatever you said..."
        [/message]

        {MOVE_UNIT (id=Darken Volk) 13 16}

        [message]
            speaker=Malin Keshar
            message= _ "... have I really just been a pawn all this time?"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Why don’t you say anything?! Don’t you care at all?!"
        [/message]

        {MOVE_UNIT (id=Darken Volk) 16 17}

        [message]
            speaker=Malin Keshar
            message= _ "... you can’t abandon me too, not the way they did... Father, Drogan, Dela..."
        [/message]

        {MOVE_UNIT (id=Darken Volk) 17 17}
        {MOVE_UNIT (id=Darken Volk) 20 18}

        [message]
            role=advisor
            message= _ "He will not help you, but perhaps the book might. You were the one who helped him retrieve it; it is rightfully yours!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Yes, perhaps, I suppose that is right..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Darken Volk! That book is as much mine as it is yours! Give it back, or I will have to take it by force!"
        [/message]

        [delay]
            time=1000
        [/delay]

        {MODIFY_UNIT (id=Darken Volk) facing nw}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Darken Volk
            message= _ "You are even more of a fool than I thought."
        [/message]

        {MOVE_UNIT (id=Darken Volk) 29 14}

        # Make camp
        [terrain]
            x,y=29,14
            radius=1
            terrain=Cer
        [/terrain]

        [terrain]
            x,y=29,14
            terrain=Ker
        [/terrain]
        [redraw][/redraw]

        {MODIFY_UNIT (id=Darken Volk) facing sw}

        {MOVE_UNIT (id=Malin Keshar) 5 13}

        [terrain]
            x,y=5,13
            radius=1
            terrain=Cer
        [/terrain]

        [terrain]
            x,y=5,13
            terrain=Ker
        [/terrain]
        [redraw][/redraw]

        {MODIFY_UNIT (id=Malin Keshar) facing ne}

        {VARIABLE dela_arrived 0}
    [/event]

    # This helps prevent Darken from getting himself killed easily by preventing
    # him from leaving his castle
    [event]
        name=side 2 turn refresh
        first_time_only=no

        [object]
            silent=yes
            duration=turn end
            take_only_once=no
            [filter]
                id=Darken Volk
            [/filter]

            [effect]
                apply_to=movement_costs
                replace=yes
                [movement_costs]
                    flat={UNREACHABLE}
                [/movement_costs]
            [/effect]
        [/object]
    [/event]

    [event]
        name=attack
        [filter]
            side=1
        [/filter]
        [filter_second]
            side=2
        [/filter_second]

        # Let's check for whether he's still alive, just in case the
        # paladins somehow killed him already
        [filter_condition]
            [have_unit]
                id=Darken Volk
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "You let me believe Parthyn would accept me back, so when they didn’t, I would be willing to attack my own countrymen!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "What you let yourself believe is no fault of mine. I gave you more power than you could have possibly dreamed. Use it to fight the orcs that annoy you so, not me."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "You took my home away from me. You took Drogan away. You turned my sister against me! You have ruined my life!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "The only thing I have done is given you the power to achieve your own goals. The rest, you have done yourself."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "That’s not true! You can’t abandon me like this!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Enough prattle from you, boy. Fighting the orcs is your ambition, not mine. You cannot expect me to help you in an endeavor that does not concern me at all."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "The very same to you! I helped you retrieve that book! If you will not help me with my mission, I will at least keep the fruits of my labor."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Hardly. I will crush you easily."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Perhaps, but I have nothing left to lose..."
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            side=1
        [/filter]
        [filter_second]
            id=Darken Volk
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "Now you shall pay for what you have done to me."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Done? I have done nothing but give you an opportunity. What you choose to do with your life is not my business. Leave me alone!"
        [/message]
    [/event]

    # Paladins!
    [event]
        name=turn 6

        # Fake move the paladin in, set up a camp, have some
        # dialog, and give him another paladin and a mage of light
        {INCIDENTAL_MUSIC loyalists.ogg}

        [move_unit_fake]
            type=Paladin
            x=40,40,39,38,37
            y=23,22,22,21,21
            side=3
        [/move_unit_fake]

        [unit]
            type=Paladin
            side=3
            x,y=37,21
            id=Sir Cadaeus
            name= _ "Sir Cadaeus"
            canrecruit=yes
            animate=no
            facing=nw
        [/unit]

        {GENERIC_UNIT 3 (Paladin)       38 20} {FACING nw}
        {GENERIC_UNIT 3 (Mage of Light) 38 21} {FACING nw}

        # Make camp
        [terrain]
            x,y=37,21
            radius=1
            terrain=Ce
        [/terrain]

        [terrain]
            x,y=37,21
            terrain=Ke
        [/terrain]

        [redraw][/redraw]

        [modify_side]
            side=3
            {QUANTITY gold 50 75 100}
            {QUANTITY income 12 16 20}
            hidden=no
        [/modify_side]

        [message]
            speaker=Sir Cadaeus
            message= _ "Your travels in this region have not gone unnoticed, necromancers! The disaster you wreaked upon the good city of Tath and the noble Lord Karres can only be paid back in turn with your blood and souls — whatever little may remain of them. Yes, on this day, you shall have to answer for your innumerable crimes."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Pompous words from an arrogant fool. We shall see how well you fare once I have finished this upstart."
        [/message]
    [/event]

    # Dela joins the party
    [event]
        name=side 4 turn 13

        {INCIDENTAL_MUSIC northern_mountains.ogg}

        [move_unit_fake]
            type=Frontier Baroness
            x=41,40,39,38,37,36
            y= 6, 6, 6, 6, 7, 7
            side=4
        [/move_unit_fake]

        [unit]
            side=4
            x,y=36,7

            animate=no
            moves=0
            facing=sw

            # wmllint: recognize Dela Keshar
            {CHARACTER_STATS_DELA_KESHAR}
        [/unit]

        # Make camp
        [terrain]
            x,y=36,7
            radius=1
            terrain=Ce
        [/terrain]

        [terrain]
            x,y=36,7
            terrain=Ke
        [/terrain]

        [redraw][/redraw]

        [modify_side]
            side=4
            {QUANTITY gold 160 200 240}
            {QUANTITY income 16 20 24}
            hidden=no
        [/modify_side]

        [message]
            speaker=Dela Keshar
            message= _ "I finally found you, Malin! At last, you will have to pay for what you have done to my people and my home. I will not let you live to see another sunset."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... I suppose you did vow to kill me..."
        [/message]

        [message]
            speaker=Dela Keshar
            message= _ "Did you not think I would keep my word? Attack him, men! Do not let the traitor escape!"
        [/message]

        {VARIABLE dela_arrived 1}
    [/event]

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

        [message]
            speaker=Dela Keshar
            message= _ "Vile fiend... I regret that I was... not strong enough... to destroy you..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "You brought this on yourself..."
        [/message]

        [if]
            [not]
                [have_unit]
                    id=Sir Cadaeus,Darken Volk
                [/have_unit]
            [/not]
            [then]
                [kill]
                    id=Dela Keshar
                    animate=yes
                [/kill]
                [fire_event]
                    name=alternate victory
                [/fire_event]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Sir Cadaeus
        [/filter]

        [message]
            speaker=Sir Cadaeus
            message= _ "For the Light I fall..."
        [/message]

        [if]
            [not]
                [have_unit]
                    id=Dela Keshar,Darken Volk
                [/have_unit]
            [/not]
            [and]
                [variable]
                    name=dela_arrived
                    numerical_equals=1
                [/variable]
            [/and]
            [then]
                [kill]
                    id=Sir Cadaeus
                    animate=yes
                [/kill]
                [fire_event]
                    name=alternate victory
                [/fire_event]
            [/then]
        [/if]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Darken Volk
        [/filter]

        [message]
            speaker=Malin Keshar
            message= _ "See? This is what happens when you abandon me!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Ungrateful wretch, this is how you repay me? Curse you, Malin the Damned!"
        [/message]

        [kill]
            id=Darken Volk
            animate=yes
        [/kill]

        {PLACE_IMAGE items/book5.png $x1 $y1}

        {VARIABLE bookX $x1}
        {VARIABLE bookY $y1}

        [message]
            speaker=Malin Keshar
            message= _ "I have already been cursed many times over. One more time is nothing..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Well, I suppose I should get that book off the battlefield."
        [/message]

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Bring the book back to Malin’s camp"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]

            {TURNS_RUN_OUT}

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

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Pick up the book by moving a unit onto it. Bats and ghosts cannot carry the book."
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            role=book_carrier
        [/filter]

        {VARIABLE bookX $x1}
        {VARIABLE bookY $y1}

        {PLACE_IMAGE (items/book5.png) ($bookX) ($bookY)}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x,y=$bookX,$bookY
            side=1
            [not]
                type_adv_tree=Ghost,Vampire Bat
            [/not]
        [/filter]

        [remove_item]
            x,y=$x1,$y1
            image="items/book5.png"
        [/remove_item]

        [role]
            x,y=$x1,$y1
            role=book_carrier
        [/role]

        [unit_overlay]
            x,y=$x1,$y1
            image="misc/book-icon.png"
        [/unit_overlay]

        [if]
            [have_unit]
                x,y=$x1,$y1
                id=Malin Keshar
            [/have_unit]
            [then]
                [message]
                    speaker=Malin Keshar
                    message= _ "I have the book."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Malin Keshar
                    message= _ "My minions have captured the book."
                [/message]
            [/else]
        [/if]

        {VARIABLE bookX -1}
        {VARIABLE bookY -1}
    [/event]

    # Inform the player if a unit cannot pick up the book
    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=$bookX
            y=$bookY
            side=1
            type=Ghost,Wraith,Spectre,Shadow,Nightgaunt
        [/filter]

        [message]
            speaker=Malin Keshar
            message= _ "I am sorry, master, but this book is too heavy for me."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=$bookX
            y=$bookY
            side=1
            type=Vampire Bat,Blood Bat,Dread Bat
        [/filter]

        [message]
            speaker=unit
            # po: this is just a squeaking sound a bat might make
            message= _ "Neep! Neep!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "It’s impossible for a bat to carry a book that heavy."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=time over

        [unit]
            type=Paladin
            side=3
            x,y=37,21
            id=Telemon
            name= _ "Telemon the Slayer"
            canrecruit=yes
            animate=yes
            facing=nw
        [/unit]
        {GENERIC_UNIT 3 (Paladin)       36 20} {FACING nw}
        {GENERIC_UNIT 3 (Paladin)       37 20} {FACING nw}
        {GENERIC_UNIT 3 (Paladin)       36 21} {FACING nw}
        {GENERIC_UNIT 3 (Mage of Light) 37 22} {FACING nw}
        {GENERIC_UNIT 3 (Mage of Light) 38 20} {FACING nw}
        {GENERIC_UNIT 3 (Mage of Light) 38 21} {FACING nw}

        [message]
            speaker=Telemon
            message= _ "Foul necromancer! Your time has come!"
        [/message]
        [message]
            speaker=Malin Keshar
            message= _ "Reinforcements! I took too long to retrieve that book and now I have no way to win this battle..."
        [/message]
    [/event]

    # Victory Conditions
    [event]
        name=moveto
        [filter]
            role=book_carrier
            side=1
            [filter_location]
                terrain=C*,K*
                [and]
                    x,y=5,13
                    radius=1
                [/and]
            [/filter_location]
        [/filter]

        {MOVE_UNIT (id=Malin Keshar) 1 8}

        [message]
            speaker=Malin Keshar
            message= _ "The terrain is hazardous in these mountains. Neither the paladins nor Dela will be able to pursue me."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... then again, is there a point? Even should I escape, then what? All that I have fought for, everyone who I have tried to protect, everything is gone to me."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Life, death... unlife — at this point, I could accept any of them and nothing would change."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... but, I suppose giving up now would be a waste..."
        [/message]

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

    [event]
        name=alternate victory

        [message]
            speaker=Malin Keshar
            message= _ "So, they are all dead. The paladin, Darken Volk, Dela..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "All that I have fought for, everyone who I have tried to protect, everything is gone. Everyone is dead. Is this truly all that I am left with?"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... nothing at all..."
        [/message]

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

    [event]
        name=victory

        [remove_unit_overlay]
            role=book_carrier
            image="misc/book-icon.png"
        [/remove_unit_overlay]
        {CLEAR_VARIABLE bookX,bookY,dela_arrived}
    [/event]

    {HERODEATH_MALIN}
[/scenario]
