#textdomain wesnoth-did
[scenario]
    id=Descent_into_Darkness
    next_scenario=Endless_Night

    name=_ "Descent into Darkness"
    map_data="{campaigns/Descent_Into_Darkness/maps/Descent_into_darkness.map}"
    turns=-1

    {INTRO_AND_SCENARIO_MUSIC the_city_falls.ogg the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC the_king_is_dead.ogg}
    {EXTRA_SCENARIO_MUSIC revelation.ogg}

    victory_when_enemies_defeated=no

    [story]
        [part]
            story=_ "'To become a lich, one must first die.'"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "So reads the book that Malin has reclaimed. 'The spells of necromancy bind the spirit, but only once it has been unbound from the body. To become a lich, the mage must make the necessary incantations with his dying breaths. He thus binds his own spirit in much the same way necromancers bind the spirits of others. Because he retains his own will, however, the lich can call upon the awesome powers of the spirit world.'"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "The words, and the idea, stick in the back of his mind. With all of Wesnoth forbidden to him, Malin finds refuge in a nameless frontier village where few questions are asked. When word filters to the town that Parthyn has been overrun by orcs, it rekindles hatred within him. With renewed purpose, he raises his undead minions and travels northward."
            background=story/travel.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "Malin soon finds the track of an enormous orc army, and follows them until he reaches their camp. As he sees the number of orcs, the enormity of his quest begins to dawn on him. He attacks the camp anyway but is quickly driven back, and badly injured by a thrown orcish dagger as he retreats. He finds refuge in a small cave."
            background=story/end.jpg
            scale_background=no
        [/part]
        [part]
            show_title=yes
            {TO_DESCENT_INTO_DARKNESS}
        [/part]
    [/story]

    {UNDERGROUND}

    [side]
        side=1
        controller=human
        type=Apprentice Mage
        id=Malin Keshar
        name=_ "Malin Keshar"
        unrenamable=yes
        canrecruit=yes
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept DiD
        income=0
        gold=100
        fog=yes
        shroud=yes
        {FLAG_VARIANT undead}
    [/side]

    [side]
        # Troll leader
        side=2
        team_name=trolls
        user_team_name=_"Trolls"
        controller=ai
        # place leader later
        no_leader=yes
        gold=60
        recruit=Troll Whelp,Troll,Troll Rocklobber,Troll Warrior,Troll Shaman
        [ai]
            caution=0.5
            grouping=defensive
            protect_leader=10
            recruitment_pattern=fighter,fighter,mixed fighter
            # Avoid the spiders, the wose, and the beginning area
            [avoid]
                x=2-9,2-27,5-9
                y=11-15,30-35,19-23
            [/avoid]
        [/ai]
        fog=yes
        shroud=no
    [/side]

    [side]
        # Eastern village trolls
        side=3
        team_name=trolls
        user_team_name=_"Trolls"
        controller=ai
        no_leader=yes
        [ai]
            # Avoid the spiders, the wose, and the beginning area
            [avoid]
                x=2-9,2-27,5-9
                y=11-15,30-35,19-23
            [/avoid]
        [/ai]
        fog=yes
        shroud=no
    [/side]

    [side]
        # Western village trolls
        side=4
        team_name=trolls
        user_team_name=_"Trolls"
        controller=ai
        no_leader=yes
        [ai]
            # Avoid the spiders, the wose, and the beginning area
            [avoid]
                x=2-9,2-27,5-9
                y=11-15,30-35,19-23
            [/avoid]
        [/ai]
        fog=yes
        shroud=no
    [/side]

    [side]
        # Monsters
        side=5
        controller=ai
        no_leader=yes
        [ai]
            # This is mostly for the Wose -- the others are guardians
            [target]
                side=1
                value=5
            [/target]
        [/ai]
        fog=yes
        shroud=yes
    [/side]

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Become a Lich"
            [/objective]
        [/objectives]

        [if]
            [have_unit]
                id=Malin Keshar

                [and]
                    type=Apprentice Necromancer

                    [or]
                        type=Apprentice Mage
                    [/or]
                [/and]
            [/have_unit]

            [then]
                [kill]
                    id=Malin Keshar
                [/kill]

                [unit]
                    id=Malin Keshar
                    name=_ "Malin Keshar"
                    type=Dark Mage
                    side=1
                    x,y=3,34
                    profile=portraits/malold.png
                    unrenamable=yes
                    canrecruit=yes
                [/unit]
            [/then]
        [/if]

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

            kill=yes
            variable=stored_Malin
        [/store_unit]

        # Malin starts injured and poisoned
        {VARIABLE stored_Malin.hitpoints 9}
        {VARIABLE stored_Malin.status.poisoned on}

        [unstore_unit]
            variable=stored_Malin
        [/unstore_unit]

        {CLEAR_VARIABLE stored_Malin}

        # Castle trolls - all difficulties
        {UNIT 2 (Troll) 14 7 (ai_special=guardian)}
        {UNIT 2 (Troll) 8 7 (ai_special=guardian)}
        {UNIT 2 (Troll) 16 3 (ai_special=guardian)}
        {UNIT 2 (Troll Rocklobber) 12 1 (ai_special=guardian)}
        {UNIT 2 (Troll Shaman) 7 4 (ai_special=guardian)}

        # Eastern village trolls - all difficulties
        {UNIT 3 (Troll) 30 19 (ai_special=guardian)}
        {UNIT 3 (Troll) 31 12 (ai_special=guardian)}
        {UNIT 3 (Troll Shaman) 33 14 (ai_special=guardian)}

        # Western village trolls - all difficulties
        {UNIT 4 (Troll Shaman) 4 21 (ai_special=guardian)}
        {UNIT 4 (Troll) 10 26 (ai_special=guardian)}
        {UNIT 4 (Troll Whelp) 2 25 (ai_special=guardian)}
        {UNIT 4 (Troll) 10 16 (ai_special=guardian)}

        # Monsters
        {UNIT 5 (Giant Rat) 14 29 (ai_special=guardian)}
        {UNIT 5 (Giant Rat) 21 28 (ai_special=guardian)}
        {UNIT 5 (Giant Rat) 24 34 (ai_special=guardian)}
        {UNIT 5 (Giant Rat) 18 18 (ai_special=guardian)}
        {UNIT 5 (Giant Rat) 22 5 (ai_special=guardian)}
        {UNIT 5 (Vampire Bat) 29 26 (ai_special=guardian)}
        {UNIT 5 (Vampire Bat) 26 31 (ai_special=guardian)}
        {UNIT 5 (Vampire Bat) 19 32 (ai_special=guardian)}
        {UNIT 5 (Vampire Bat) 19 23 (ai_special=guardian)}
        {UNIT 5 (Vampire Bat) 18 13 (ai_special=guardian)}
        {UNIT 5 (Vampire Bat) 18 34 (ai_special=guardian)}
        {UNIT 5 (Giant Spider) 7 12 (ai_special=guardian)}
        {UNIT 5 (Giant Spider) 8 13 (ai_special=guardian)}
        {UNIT 5 (Giant Spider) 6 15 (ai_special=guardian)}

#ifdef NORMAL
        {UNIT 2 (Troll) 7 7 (ai_special=guardian)}
        {UNIT 4 (Troll Whelp) 4 19 (ai_special=guardian)}
        {UNIT 3 (Troll Whelp) 31 16 (ai_special=guardian)}
#endif

#ifdef HARD
        {UNIT 2 (Troll) 7 7 (ai_special=guardian)}
        {UNIT 4 (Troll Rocklobber) 8 18 (ai_special=guardian)}
        {UNIT 3 (Troll Rocklobber) 27 16 (ai_special=guardian)}
#endif

        # The wose
        [unit]
            type=Ancient Wose
            side=5
            x,y=7,21
            id=Dumdumbadoom
            name= _"Dumdumbadoom"
            ai_special=guardian
        [/unit]
    [/event]

    [event]
        name=start
        {MOVE_UNIT (id=Malin Keshar) 5 32}
        [redraw]
            side=1
        [/redraw]
        {CREATE_ADVISOR}

        [message]
            role=advisor
            message=_ "Master, you are gravely injured!"
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "I won't go down like this, felled by an orc's blade. I won't see them defeat me!"
        [/message]
        [message]
            role=advisor
            message=_ "There is another way, master. Remember the book..."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "Yes... yes. The orcs are too strong for me now, but once I have undergone the transformation they'll begin to fall before me. And I will continue to hound them until the last one falls!"
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "Leave me now while I prepare."
        [/message]
        [message]
            role=advisor
            message=_ "Yes, master."
        [/message]

        {PUT_TO_RECALL_LIST (role=advisor)}

        [message]
            speaker=narrator
            message=_ "With his last bits of strength, Malin assembles an altar as the book instructs."
            image=wesnoth-icon.png
        [/message]

        [item]
            x,y=6,31
            image=misc/makeshift-altar.png
        [/item]

        [recall]
            role=advisor
            x,y=7,31
        [/recall]

        [delay]
            time=500
        [/delay]

        {MOVE_UNIT (id=Malin Keshar) 6 31}

        {MODIFY_UNIT role=advisor facing sw}

        [message]
            speaker=Malin Keshar
            message=_ "I pray that I am strong enough to complete the spell."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "I'm ready. Do it."
        [/message]

        [delay]
            time=500
        [/delay]

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

            [primary_attack]
                range=melee
            [/primary_attack]

            hits=yes
        [/animate_unit]

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

        {PUT_TO_RECALL_LIST (role=advisor)}

        {FADE_TO_BLACK}

        [redraw]
        [/redraw]

        {DELAY 1000}

        [message]
            speaker=narrator
            message=_ "There is darkness..."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=narrator
            message=_ "and peace..."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=narrator
            message=_ "for a moment."
            image=wesnoth-icon.png
        [/message]
        {DELAY 500}
        [message]
            speaker=narrator
            message=_ "Then they are replaced by a pulling, a pain too strong to resist, and then..."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=narrator
            message=_ "by emptiness."
            image=wesnoth-icon.png
        [/message]

        {FADE_IN}

        # and is reborn as a lich
        [unit]
            type=Lich DiD
            side=1
            id=Mal Keshar
            name=_ "Mal Keshar"
            unrenamable=yes
            canrecruit=yes
            profile=portraits/malinlich.png
            x,y=6,31
            hitpoints=9
            facing=se
            animate=yes
        [/unit]

        [redraw]
        [/redraw]

        # He's not necessarilly totally happy about this
        [message]
            speaker=Mal Keshar
            message=_ "AAAAAAAAAAaaaaaaaiiiiiiiiiggggggggghhhhhh!!!!!!!"	# wmllint: no spellcheck
            sound=lich-die.ogg
        [/message]
        [message]
            speaker=Mal Keshar
            message=_ "The cold, it burns!"
        [/message]
        [message]
            speaker=Mal Keshar
            message=_ "I need warmth... life... I sense some here!"
        [/message]

        {DELAY 500}

        {INCIDENTAL_MUSIC the_dangerous_symphony.ogg}
        [music]
            name=knalgan_theme.ogg
            append=yes
        [/music]
        [music]
            name=heroes_rite.ogg
            append=yes
        [/music]

        {DELAY 500}

        [sound]
            name=lich-hit-1.ogg
        [/sound]

        # Blow open a wall
        [move_unit_fake]
            type=Iceball
            side=1
            x=6,10
            y=31,31
        [/move_unit_fake]
        {QUAKE "cave-in.ogg"}
        [terrain]
            x,y=10,31
            terrain=Uh
        [/terrain]

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

        # Previously recruited and new adepts can now also become liches
        {MODIFY_UNIT (type=Dark Adept DiD) advances_to (Dark Sorcerer)}
        {MODIFY_UNIT (type=Dark Sorcerer DiD) advances_to (Lich,Necromancer)}
        [disallow_recruit]
            side=1
            type=Dark Adept DiD
        [/disallow_recruit]
        [allow_recruit]
            side=1
            type=Dark Adept
        [/allow_recruit]
    [/event]

    # Ensure that you can't lose to the first couple of bats and rats simply by
    # getting unlucky.
    {FORCE_CHANCE_TO_HIT id="Mal Keshar" side=5 100 (
        [variable]
            name=turn_number
            less_than=5
        [/variable]
    )}

    [event]
        name=attacker_hits
        first_time_only=yes
        [filter]
            id=Mal Keshar
        [/filter]
        [filter_attack]
            name=touch
        [/filter_attack]

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

    [event]
        # See your goal
        name=moveto
        [filter]
            id=Mal Keshar
            x=20-25
            y=27-29
        [/filter]
        [remove_shroud]
            # See the road to the castle and the castle itself
            side=1
            x=3-13,20-22,18-20,17-19,13-16,11-15
            y=2-8,18-28,15-17,14-16,12-13,9-11
        [/remove_shroud]
        [redraw]
            side=1
        [/redraw]
        [scroll_to]
            x,y=8,5
        [/scroll_to]
        {DELAY 2000}

        [message]
            speaker=Mal Keshar
            message=_ "There, in along this old road, I sense a place worthy of being my home. From there I will build by armies. But I am still too weak to clear the vermin from it. I must finish regaining my strength."
        [/message]
        [message]
            speaker=Mal Keshar
            message=_ "I will need a castle from which to call upon my soldiers. I sense one nearby."
        [/message]

        [remove_shroud]
            x=27-32
            y=23-27
        [/remove_shroud]
        [redraw]
            side=1
        [/redraw]
        [scroll_to]
            x,y=34,24
        [/scroll_to]
        {DELAY 1500}

        [message]
            speaker=Mal Keshar
            message=_ "Yes, this will do until I can take my new home."
        [/message]

        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Clear your new home of trolls"
            [/objective]
            [objective]
                condition=lose
                description=_ "Destruction of Mal Keshar"
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/objectives]

        # Turns are measured from here
        {VARIABLE totalTurns 50}
        {VARIABLE_OP totalTurns add $turn_number}
        [modify_turns]
            value=$totalTurns
        [/modify_turns]
        {CLEAR_VARIABLE totalTurns}
    [/event]

    [event]
        # Set the troll enemy and return income to normal when you reach your keep
        name=moveto
        [filter]
            id=Mal Keshar
            x,y=30,25
        [/filter]
        [unit]
            # Troll leader
            type=Troll Hero
            side=2
            id=Grnknrr
            x,y=10,6
            canrecruit=yes
        [/unit]
        [modify_side]
            side=1
            income=2
        [/modify_side]
    [/event]

    [event]
        name=turn refresh
        first_time_only=no

        [if]
            [variable]
                name=side_number
                equals=5
            [/variable]

            [variable]
                name=wose_awakened
                not_equals=yes
            [/variable]

            [then]
                {MODIFY_UNIT id=Dumdumbadoom moves 0}
            [/then]
        [/if]
    [/event]

    [event]
        # Fun with the wose
        name=moveto
        [filter]
            side=1
            [filter_adjacent]
                id=Dumdumbadoom
            [/filter_adjacent]
        [/filter]
        [terrain]
            x,y=7,21
            terrain=Gg
        [/terrain]
        [message]
            speaker=Dumdumbadoom
            message=_ "Who has awoken me from my slumber? Undead? I shall not suffer the existence of such foul creatures."
        [/message]

        {VARIABLE wose_awakened yes}
    [/event]

    [event]
        # Have a nice trip, see you in the fall. . .
        name=moveto
        first_time_only=no
        [filter]
            x,y=24,13
            [not]
                type=Vampire Bat,Blood Bat,Dread Bat,Ghost,Wraith,Spectre,Shadow,Nightgaunt
            [/not]
        [/filter]
        [message]
            x,y=24,13
            message=_ "AAAAAAAaaaaaaaggggggghhhhhhh!!!!...... . . . ."
        [/message]
        {MOVE_UNIT (x,y=24,13) 25 13}
        [kill]
            x,y=25,13
            animate=no
            fire_event=yes
        [/kill]
    [/event]

    # Defeat Conditions
    {MAL_DEATH}

    # Victory Condition
    [event]
        # Kill the troll leader
        name=die
        [filter]
            side=2
            canrecruit=yes
        [/filter]
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=victory
        {VARIABLE timesForever 1}
    [/event]
[/scenario]
