#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 18_The_Portal_of_Doom.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=scenery/summoning-center.png
    [/item]

    [item]
        x=19
        y=22
        image=scenery/summoning-center.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=4000
            show_title=yes
        [/part]
    [/story]
    {DM_TRACK {TRIUMPH_STAGE2}}

    [side]
        {YOUNG_DELFADOR}
        side=1
        save_id=Player
        persistent=yes
        controller=human
        recruit={LOYALISTS}
        team_name=allies
        user_team_name= _ "Loyalists"
        {GOLD 200 180 160}
        {FLAG_VARIANT loyalist}
    [/side]
    [event]
        name=prestart

        [unit]
            {ULREK}
            placement=leader
        [/unit]
        {DELFADOR_GETS_DWARVES}
        {MODIFY_UNIT (side=1) facing se}
    [/event]

    [side]
        type=Death Knight
        id=Prepolur
        name=_ "Prepolur"
        facing=nw
        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
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value=3.0
            [/goal]
        [/ai]
        {GOLD 200 200 250}
        team_name=enemies
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
    [/side]
    [side]
        type=Necromancer
        id=Unuvim-Malal
        name=_ "Unuvim-Malal"
        facing=nw
        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
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value=3.0
            [/goal]
        [/ai]
        {GOLD 200 200 250}
        team_name=enemies
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
    [/side]
    [side]
        no_leader=yes #Iliah-Malal arrives later
        side=4
        controller=ai
        hidden=yes
        team_name=enemies
        user_team_name= _ "Undead"
#ifdef EASY
        recruit=Skeleton, Skeleton Archer, Vampire Bat, Ghost
#endif

#ifdef NORMAL
        recruit=Skeleton, Revenant, Skeleton Archer, Bone Shooter, Ghost, Vampire Bat, Blood Bat, Chocobone, Dark Adept
#endif

#ifdef HARD
        recruit=Skeleton, Skeleton Archer, Revenant, Draug, Banebow, Bone Shooter, Deathblade, Ghost, Wraith, Shadow, Nightgaunt, Chocobone, Dark Adept, Spectre, Blood Bat, Vampire Bat
#endif
        gold=0
        {NO_INCOME}
        [ai]
            recruitment_pattern=scout,fighter,archer
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value=10
            [/goal]
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    {MEMOIRS_DEATHS}

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description=_ "Move Delfador to close the Portal and then return everyone to the tunnel"
                condition=win
            [/objective]
            [objective]
                description=_ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description=_ "Death of Ulrek"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=80
            [/gold_carryover]
        [/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 the 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]

        [delay]
            time=1500
        [/delay]

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

        {MODIFY_UNIT (id=Delfador) facing nw}
        [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=_"(<i>To the dwarves</i>). Now that the portal is closed, his power will start to weaken, but that doesn't help us now. 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 scenery/mine-abandoned.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=_ "Death of Ulrek"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=80
            [/gold_carryover]
        [/objectives]

        [event]
            name=moveto
            first_time_only=no
            [filter]
                side=1
                x=2
                y=19
                [not]
                    id=Delfador
                [/not]
            [/filter]
            [put_to_recall_list]
                id=$unit.id
                heal=yes
            [/put_to_recall_list]
        [/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]

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

                    [delay]
                        time=10
                    [/delay]

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

    [event]
        name=die

        [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 the bad guy on his keep
        [unit]
            {ILIAH_MALAL (Ancient Lich)}
            facing=sw
            side=4
            x=18
            y=3
        [/unit]

        {NAMED_UNIT 4 (Draug)      18 4 Samun _"Samun" (facing=sw)}
        {NAMED_UNIT 4 (Banebow)    17 3 Skoogal _"Skoogal" (facing=sw)}
        {NAMED_UNIT 4 (Deathblade) 17 4 Skulrag _"Skulrag" (facing=sw)}
        {NAMED_UNIT 4 (Nightgaunt) 19 4 Idthom _"Idthom" (facing=sw)}
        {NAMED_UNIT 4 (Chocobone)  16 2 Hyvrun _"Hyvrun" (facing=sw)}
        {NAMED_UNIT 4 (Blood Bat)  14 2 Blud _"Blud" (facing=sw)}

        [modify_side]
            side=4
            hidden=no
            {INCOME 10 20 30}
        [/modify_side]

        [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
        first_time_only=no
        [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 destroy you!"
        [/message]
        [message]
            id=Delfador
            message= _ "We cannot defeat him now. We must carry out our mission first, so we will be able to defeat him later."
        [/message]
        # He gets a full heal, not an advance, otherwise we'd have to make sure we ported him to the next scenario properly
        [heal_unit]
            [filter]
                id=Iliah-Malal
            [/filter]
        [/heal_unit]
    [/event]

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

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

        [delay]
            time=10
        [/delay]

        [color_adjust]
            red=0
            green=0
            blue=0
        [/color_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
        [remove_item]
            x=20
            y=20
            image=scenery/summoning-center.png
        [/remove_item]
        [remove_item]
            x=19
            y=22
            image=scenery/summoning-center.png
        [/remove_item]
        # 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]
