#textdomain wesnoth-dm
[scenario]
    name=_ "The Portal of Doom"
    id=18_the_portal_of_doom
    next_scenario=19_showdown_in_the_northern_swamp
    {MEMOIRS_MAP portal.map}
    turns=40
    victory_when_enemies_defeated=no
    {DEFAULT_SCHEDULE}

    {INTRO_AND_SCENARIO_MUSIC northerners.ogg the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC breaking_the_chains.ogg}
    {EXTRA_SCENARIO_MUSIC the_king_is_dead.ogg}
    {EXTRA_SCENARIO_MUSIC battle.ogg}

    # If this were intended to be a longer campaign, we might insert a
    # fight with trolls or something during Delfador's odyssey through
    # the tunnels. This does not have to be a picnic excursion.

    [item]
        x=2
        y=19
        image=scenery/mine-abandoned.png
    [/item]

    [item]
        x=20
        y=20
        image=items/ward-circle.png
    [/item]

    [item]
        x=19
        y=22
        image=items/ward-circle.png
    [/item]

    [story]
        [part]
            story= _ "The dwarves led Delfador through a veritable maze of tunnels. Delfador was amazed at the speed with which the dwarves could move through their tunnels. Far sooner than he would have believed possible they reached their destination, undetected by Iliah-Malal."
            delay=8000
            show_title=yes
            {TO_THE_PORTAL_OF_DOOM}
        [/part]
    [/story]

    [side]
        {YOUNG_DELFADOR}
        type=Journeyman Mage
        canrecruit=yes
        recruit={LOYALISTS}
        {GOLD 200 180 160}
    [/side]
    [event]
        name=prestart
        {RECALL_OR_CREATE_UNIT {ULREK} Ulrek}
        {DELFADOR_GETS_DWARVES}
    [/event]

    [side]
        type=Death Knight
        id=Prepolur
        name=_ "Prepolur"
        side=2
        canrecruit=yes
        controller=ai
#ifdef EASY
        recruit=Skeleton, Skeleton Archer
#endif

#ifdef NORMAL
        recruit=Skeleton, Revenant, Skeleton Archer, Bone Shooter
#endif

#ifdef HARD
        recruit=Skeleton, Skeleton Archer, Revenant, Draug, Banebow, Bone Shooter, Deathblade
#endif
        [ai]
            aggression=0.0
            #recruitment_pattern=scout, mixed fighter, archer
            # there are a lot of close villages
            #villages_per_scout=6

            # attack Delfador   heavily
            leader_value=2.0
            [target]
                id=Delfador
                value=3.0
            [/target]
        [/ai]
        {GOLD 200 200 250}
        team_name=foe
    [/side]
    [side]
        type=Dark Adept
        id=Unuvim
        name=_ "Unuvim"
        side=3
        canrecruit=yes
        controller=ai
#ifdef EASY
        recruit=Ghost, Vampire Bat
#endif

#ifdef NORMAL
        recruit=Ghost, Vampire Bat, Blood Bat, Chocobone, Dark Adept, Wraith
#endif

#ifdef HARD
        recruit=Ghost, Vampire Bat, Shadow, Nightgaunt, Spectre, Blood Bat, Vampire Bat, Wraith
#endif
        [ai]
            aggression=0.0
            #recruitment_pattern=scout, mixed fighter, archer
            # there are a lot of close villages
            #villages_per_scout=6

            # attack Delfador   heavily
            leader_value=2.0
            [target]
                id=Delfador
                value=3.0
            [/target]
        [/ai]
        {GOLD 200 200 250}
        team_name=foe
    [/side]

    {MEMOIRS_DEATHS}

#define MATERIALIZE_ILIAH_MALAL
    # Materialize the bad guy on his keep
    #wmllint: recognize Iliah-Malal
    [unit]
        id=Iliah-Malal
        name=_ "Iliah-Malal"
        type=Lich
        side=3
        x=17
        y=1
    [/unit]
#enddef

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description=_ "Close the Portal and return Delfador to his keep"
                condition=win
            [/objective]
            [objective]
                description=_ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description=_ "Time runs out"
                condition=lose
            [/objective]
            note={EARLY_FINISH_BONUS_NOTE}
        [/objectives]

        # Capturing 2,18 is because Ulrek is likely to materialize on top of
        # this village, and it's just silly for him to have to step
        # out and back to capture it.
        [capture_village]
            x,y=2,18
            side=1
        [/capture_village]
        # We have mercy on the player and don't make him slog a unit
        # through mountains to get this one.
        [capture_village]
            x,y=2,21
            side=1
        [/capture_village]
    [/event]

    #############################
    # opening dialog
    #############################
    [event]
        name=start
        [message]
            speaker=Prepolur
            message=_"Living men and dwarves are nearing. Rise, Portal Guard and slay those intruders!"
        [/message]
        [message]
            speaker=Delfador
            message=_"The portal must be closed at any cost. You must allow me to get close to it, so I can seal it."
        [/message]
        [message]
            speaker=Ulrek
            message=_"Ye all heard! Naught will ever say dwarves ever feared anyone. Attack!"
        [/message]

        # Show player where to go to close the portal.
        {HIGHLIGHT_IMAGE 19 21 items/gohere.png ()}

        [delay]
            time=1000
        [/delay]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Delfador
            x=19
            y=21
        [/filter]

        [fire_event]
            name=iliah-malal
        [/fire_event]

        [message]
            speaker=Delfador
            message=_"Earth, rise and shut this gate of evil for good!"
        [/message]
        [scroll_to_unit]
            id=Delfador
        [/scroll_to_unit]

        [fire_event]
            name=close_portal
        [/fire_event]

        # If Iliah-Malal got killed before this point,
        # rematerialize him on his keep so we can have
        # final dialog - the "join me" is referred to later.
        [if]
            [have_unit]
                side=3
                id=Iliah-Malal
            [/have_unit]
            [else]
                {MATERIALIZE_ILIAH_MALAL}
            [/else]
        [/if]

        [message]
            speaker=Iliah-Malal
            message=_"Portal, reopen! No! What have you done? "
        [/message]

        [message]
            speaker=Delfador
            message=_"Your portal is shut. And you cannot open another one."
        [/message]
        [message]
            speaker=Iliah-Malal
            message=_"Delfador, you have proven your skill. I have an offer for you. Join me and you will live as my right hand. Together our magic skills will be unmatched and irresistible."
        [/message]
        [message]
            speaker=Delfador
            message=_"Join you?"
        [/message]
        [message]
            speaker=Iliah-Malal
            message=_"Or, fight me and die. I will then resurrect you as my slave."
        [/message]
        [message]
            speaker=Delfador
            message=_"My path is set. Your path must end. I will not dishonor my oaths, and will not abandon friends and country."
        [/message]
        [message]
            speaker=Iliah-Malal
            message=_"Then you shall perish. After I finish with these pesky elves and dwarves, Weldyn will be mine. Wesnoth has no army to resist me."
        [/message]
        [message]
            speaker=Delfador
            message=_"(to the dwarves). Quickly, back in the tunnel. I will stay last to seal the entrance."
        [/message]
        #Delf collapses the cave entrance

        {REMOVE_IMAGE 19 21}

        # Prompt player to go back to starting location
        {HIGHLIGHT_IMAGE 2 19 items/gohere.png ()}

        [delay]
            time=2000
        [/delay]

        [objectives]
            side=1
            [objective]
                description=_ "All the player's units must reach the tunnel. Then Delfador."
                condition=win
            [/objective]
            [objective]
                description=_ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description=_ "Time runs out"
                condition=lose
            [/objective]
        [/objectives]

        [event]
            name=moveto
            first_time_only=no
            [filter]
                side=1
                x=2
                y=19
                [not]
                    id=Delfador
                [/not]
            [/filter]
            [kill]
                id=$unit.id
                animate=no
            [/kill]
            #   [store_unit]
            #       kill=yes
            #       variable=temp
            #       [filter]
            #           id=$unit.id
            #       [/filter]
            #   [/store_unit]
            [unstore_unit]
                variable=unit
                x,y=recall,recall
            [/unstore_unit]
            {CLEAR_VARIABLE temp}
        [/event]

        [event]
            name=moveto
            first_time_only=no

            [filter]
                id=Delfador
                x=2
                y=19
            [/filter]

            [if]
                [have_unit]
                    side=1
                    [not]
                        id=Delfador
                    [/not]
                [/have_unit]
                [then]
                    [message]
                        id=Delfador
                        message=_ "Hurry up!"
                    [/message]
                [/then]
                [else]
                    [message]
                        speaker=Delfador
                        message=_"We're in. Now: Earth, seal this entrance!"
                    [/message]
                    [scroll_to_unit]
                        id=Delfador
                    [/scroll_to_unit]

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

                    [colour_adjust]
                        red=100
                        green=100
                        blue=100
                    [/colour_adjust]

                    [delay]
                        time=10
                    [/delay]

                    [colour_adjust]
                        red=0
                        green=0
                        blue=0
                    [/colour_adjust]
                    [endlevel]
                        result=victory
                    [/endlevel]
                [/else]
            [/if]
        [/event]
    [/event]

    [event]
        name=die
        first_time_only=true
        [filter_second]
            id=Delfador
        [/filter_second]

        [scroll_to_unit]
            id=Delfador
        [/scroll_to_unit]

        {DELFADOR_LIGHTNING}

        [message]
            speaker=Delfador
            message= _ "Out of my way, foul creatures!"
        [/message]
    [/event]

    #############################
    # closing dialog
    #############################
    #    [event]
    #        name=victory
    #
    #    [/event]

    [event]
        name=iliah-malal

        {MATERIALIZE_ILIAH_MALAL}

        [unit]
            id=Samun
            name=_ "Samun"
            type=Draug
            side=3
            x=17
            y=2
        [/unit]

        [unit]
            id=Skoogal
            name=_ "Skoogal"
            type=Banebow
            side=3
            x=15
            y=1
        [/unit]

        [unit]
            id=Skulrag
            name=_ "Skulrag"
            type=Deathblade
            side=3
            x=16
            y=1
        [/unit]

        [unit]
            id=Idthom
            name=_ "Idthom"
            type=Nightgaunt
            side=3
            x=18
            y=2
        [/unit]

        [unit]
            id=Hyvrun
            name=_ "Hyvrun"
            type=Chocobone
            side=3
            x=14
            y=1
        [/unit]

        [unit]
            id=Blud
            name=_ "Blud"
            type=Blood Bat
            side=3
            x=12
            y=1
        [/unit]

        [message]
            id=Iliah-Malal
            message= _ "What's going on here? Is this Delfador? Welcome to your doom, Delfador!"
        [/message]
        [message]
            id=Delfador
            message= _ "They have reinforcements. Hurry, we must close the portal before we are overrun!"
        [/message]
        [message]
            id=Iliah-Malal
            message= _ "Slay them all!"
        [/message]
    [/event]

    [event]
        name=turn 9
        [fire_event]
            name=iliah-malal
        [/fire_event]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Iliah-Malal
        [/filter]
        [message]
            speaker="Iliah-Malal"
            message=_ "Fool! You could not kill me in the land of the dead, nor can you in the land of the living! I transcend both death and life, and I will return to destroy you!"
        [/message]
    [/event]

    # Isolate special effects from story logic for testing.
    [event]
        name=close_portal
        [sound]
            name=lightning.ogg
        [/sound]

        [colour_adjust]
            red=100
            green=100
            blue=100
        [/colour_adjust]

        [delay]
            time=10
        [/delay]

        [colour_adjust]
            red=0
            green=0
            blue=0
        [/colour_adjust]

        # First, turn the Ethereal Abyss tiles to lava chasm
        [terrain]
            x=20,20,21,21,21,21
            y=21,22,20,21,22,23
            terrain=Ql
        [/terrain]
        # Next, remove the summoning circles
        [removeitem]
            x=20
            y=20
            image=items/ward-circle.png
        [/removeitem]
        [removeitem]
            x=19
            y=22
            image=items/ward-circle.png
        [/removeitem]
        # Now, crumble the castle
        [terrain]
            x=19,19,20,20,21,21,18,18,19,19,20,20,21,21
            y=17,18,17,18,18,19,23,24,24,25,23,24,24,25
            terrain=Chr
        [/terrain]
        [terrain]
            x=20,19
            y=19,23
            terrain=Khr
        [/terrain]
    [/event]
[/scenario]
