#textdomain wesnoth-dm
[scenario]
    id=18_The_Portal_of_Doom
    name=_ "The Portal of Doom"
    {MEMOIRS_MAP 18_The_Portal_of_Doom.map}
    next_scenario=19_Showdown_in_the_Northern_Swamp
    {TURNS 44 42 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.

    {PLACE_IMAGE scenery/mine-abandoned.png 2 19}
    {PLACE_IMAGE scenery/summoning-center.png 20 20}
    {PLACE_IMAGE scenery/summoning-center.png 19 22}

    [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 them. Far sooner than he would have believed possible, they reached their destination, undetected by Iliah-Malal."
            show_title=yes
        [/part]
    [/story]
    {DM_TRACK {TRIUMPH_STAGE2}}

    #wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit={LOYALISTS}
        {GOLD 220 190 160}
        {INCOME 3 2 1}
        save_id=Player
        team_name=allies
        user_team_name= _ "Loyalists"
        side_name= _ "Delfador"
        {FLAG_VARIANT loyalist}
        [leader]
            {YOUNG_DELFADOR}
        [/leader]
        [unit]
            {ULREK}
            placement=leader
        [/unit]
    [/side]
    [event]
        name=prestart
        {DELFADOR_GETS_DWARVES}
        {MODIFY_UNIT (side=1) facing se}
    [/event]

    [side]
        side=2
        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
        {GOLD 150 200 250}
        team_name=enemies
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        [leader]
            id=Prepolur
            name=_ "Prepolur"
            type=Death Knight
            facing=nw
        [/leader]
        [ai]
            aggression=0.0
#ifdef CUSTOMIZED_AI
            recruitment_pattern=scout, mixed fighter, archer
            # there are a lot of close villages
            villages_per_scout=6
#endif

            # attack Delfador heavily
            leader_value={ON_DIFFICULTY 1.9 2.0 2.1}
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value={ON_DIFFICULTY 2.9 3.0 3.1}
            [/goal]
        [/ai]
    [/side]

    [side]
        side=3
        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
        {GOLD 150 200 250}
        team_name=enemies
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        [leader]
            id=Unuvim-Malal
            name=_ "Unuvim-Malal"
            type=Necromancer
            facing=nw
        [/leader]
        [ai]
            aggression=0.0
#ifdef CUSTOMIZED_AI
            recruitment_pattern=scout, mixed fighter, archer
            # there are a lot of close villages
            villages_per_scout=6
#endif

            # attack Delfador heavily
            leader_value={ON_DIFFICULTY 1.9 2.0 2.1}
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value={ON_DIFFICULTY 2.9 3.0 3.1}
            [/goal]
        [/ai]
    [/side]

    [side]
        side=4
        controller=ai
        hidden=yes
#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}
        team_name=enemies
        user_team_name= _ "Undead"
        [ai]
            recruitment_pattern=scout,fighter,archer
            [goal]
                name=target
                [criteria]
                    id=Delfador
                [/criteria]
                value={ON_DIFFICULTY 8 9 10}
            [/goal]
        [/ai]
        {FLAG_VARIANT undead}
        no_leader=yes #Iliah-Malal arrives later
    [/side]
    #wmllint: validate-on

    [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]

        # Capture this one because Ulrek is likely to materialize on top of it,
        # and it's just silly for him to have to step out and back to capture it.
        {CAPTURE_VILLAGES 1 02 18 1}
        # We have mercy on the player and don't make him slog a unit
        # through mountains to get this one.
        {CAPTURE_VILLAGES 1 02 21 1}
    [/event]

    [event]
        name=start
        [message]
            speaker=Prepolur
            message=_"Living men and dwarves are nearing. Rise, my fellow dead, and slay the intruders!"
        [/message]
        [message]
            speaker=Delfador
            message=_"The portal must be closed at all costs. 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=iliah-malal
        # Materialize the bad guy on his keep
        [unit]
            side=4
            {ILIAH_MALAL (Ancient Lich)}
            canrecruit=yes
            x,y=18,3
            facing=sw
        [/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 12 18 24}
        [/modify_side]
        [message]
            speaker=Iliah-Malal
            message= _ "What’s going on here? Is this Delfador? Welcome to your doom, Delfador!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "(<i>To the dwarves</i>). Their master has arrived with reinforcements. Hurry, we must close the portal before we are overrun!"
        [/message]
        [message]
            speaker=Iliah-Malal
            message= _ "Slay them all!"
        [/message]
    [/event]

    [event]
        name={ON_DIFFICULTY (turn 16) (turn 14) (turn 12)}
        [fire_event]
            name=iliah-malal
        [/fire_event]
    [/event]

    # Isolate special effects from story logic for testing.
    [event]
        name=close_portal
        # First, a flash of light
        [sound]
            name=lightning.ogg
        [/sound]
        {COLOR_ADJUST 100 100 100}
        [delay]
            time=10
        [/delay]
        {COLOR_ADJUST 0 0 0}
        # Then, 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_IMAGE 20 20}
        {REMOVE_IMAGE 19 22}
        # 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]

    [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]

    [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]
            speaker=Delfador
            #po: The same text is used both before and after closing the portal.
            #po: Shown if the player kills Iliah-Malal instead of following the hints to run away,
            #po: this is his last breath event, but he gets fully healed and the battle continues.
            message= _ "We cannot defeat him now. We must allow some time to pass after the portal has been closed. By then, his power will have weakened, rendering him vulnerable."
        [/message]
        # He gets a full heal, not an advance, otherwise we'd have to make sure we ported him to the next scenario properly
        {FULL_HEAL id=Iliah-Malal}
    [/event]

    [event]
        name=moveto
        [filter]
            id=Delfador
            x,y=19,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. It will be some time until he is rendered vulnerable; at the moment, we must flee. Quickly, back to the tunnel! I will enter it 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,y=2,19
                [not]
                    id=Delfador
                [/not]
            [/filter]
            {DELFADOR_ESCAPED_UNITS}
        [/event]

        [event]
            name=moveto
            first_time_only=no
            [filter]
                id=Delfador
                x,y=2,19
            [/filter]
            [if]
                [have_unit]
                    side=1
                    [not]
                        id=Delfador
                    [/not]
                [/have_unit]
                [then]
                    [message]
                        id=Delfador
                        message=_ "Hurry up!"
                    [/message]
                [/then]
                [else]
                    # victory dialog
                    [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 100 100 100}
                    [delay]
                        time=10
                    [/delay]
                    {COLOR_ADJUST 0 0 0}
                    {MEMOIRS_UNSTORE_UNITS delfador_escaped_units}
                    {CLEAR_VARIABLE delfador_escaped_units}
                    [endlevel]
                        result=victory
                    [/endlevel]
                [/else]
            [/if]
        [/event]
    [/event]

    {MEMOIRS_DEATHS}
[/scenario]
