#textdomain wesnoth-httt
[scenario]
    id=13_The_Dwarven_Doors
    name= _ "The Dwarven Doors"
    map_data="{campaigns/Heir_To_The_Throne/maps/13_The_Dwarven_Doors.map}"
    {SCENARIO_MUSIC "battle.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_dangerous_symphony.ogg"}
    {EXTRA_SCENARIO_MUSIC "legends_of_the_north.ogg"}
    {TURNS 26 20 15}
    victory_when_enemies_defeated=no

    {DUSK}
    {FIRST_WATCH}
    {SECOND_WATCH}
    {DAWN}
    {MORNING}
    {AFTERNOON}

    next_scenario=14_Plunging_into_the_Darkness

    {BIGMAP_DWARVEN_DOORS}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Move Konrad to the entrance of the dwarven tunnels"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    {PLACE_IMAGE scenery/dwarven-doors-closed.png 14 3}
    {PLACE_IMAGE scenery/mine-abandoned.png 25 2}

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad.png
        side=1
        canrecruit=yes
        team_name=elves
        user_team_name=_"Rebels"
        controller=human
        gold=200
        {FLAG_VARIANT long}
    [/side]

    [side]
        type=Orcish Slurbow
        id=Knafa-Telfar
        name= _ "Knafa-Telfar"
        side=2
        canrecruit=yes
        recruit=Troll Whelp,Orcish Grunt,Orcish Crossbowman
        {GOLD 100 120 140}
        {INCOME 14 18 22}
        [ai]
            {ATTACK_DEPTH 4 5 5}
            aggression=1.0
            grouping=no
            caution=-5.0
        [/ai]
        team_name=orcs
        user_team_name=_"Orcs"
        {FLAG_VARIANT ragged}
    [/side]

    [side]
        type=Orcish Warlord
        id=Urug-Tan
        name= _ "Urug-Tan"
        side=3
        canrecruit=yes
        recruit=Troll Whelp,Orcish Grunt,Orcish Crossbowman
        {GOLD 75 95 115}
        {INCOME 12 14 18}
        [ai]
            {ATTACK_DEPTH 4 5 5}
            aggression=1.0
            grouping=no
            caution=-5.0
        [/ai]
        team_name=orcs
        user_team_name=_"Orcs"
        {FLAG_VARIANT ragged}
    [/side]

    [side]
        type=Orcish Sovereign
        id=Shuuga-Mool
        name= _ "Shuuga-Mool"
        side=4
        canrecruit=yes
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll
        {GOLD 30 50 70}
        {INCOME 12 14 18}
        team_name=orcs
        user_team_name=_"Orcs"
        [ai]
            {ATTACK_DEPTH 4 5 5}
            aggression=1.0
            grouping=no
            caution=-5.0
        [/ai]
        {FLAG_VARIANT ragged}
    [/side]

    [side]
        side=5
        no_leader=yes
        controller=ai
    [/side]

    {STARTING_VILLAGES 2 20}
    {STARTING_VILLAGES 3 20}
    {STARTING_VILLAGES 4 20}
    [label]
        x=15
        y=21
        text= _ "Pillars of Thunedain"
    [/label]
    [label]
        x=14
        y=4
        text= _ "The Great Doors"
    [/label]

#define LISAR_GUARD_DOORS
    {NAMED_LOYAL_UNIT 2 (Royal Guard) 8 44 () ( _ "Royal Guard")}
#enddef

    [event]
        name=prestart
        #
        # Randomly set the exit location - 1=the main door and 2=the mine
        #
        {VARIABLE_OP true_entrance_location rand "1..2"}

        # {SCATTER_IMAGE (terrain=Gg) 12 scenery/pine2.png}
        # {SCATTER_IMAGE (terrain=Gg)  3 scenery/snowbits.png}
    [/event]

    # wmllint: recognize Uncle Somf

    [event]
        name=start
        [recall]
            id=Delfador
        [/recall]
        [recall]
            id=Kalenz
        [/recall]
        [recall]
            id=Haldiel
        [/recall]
        [role]
            type=Elvish Outrider,Elvish Rider,Elvish Scout,Lancer,Paladin,Grand Knight,Knight,Horseman
            role=Rider
        [/role]
        [recall]
            role=Rider
        [/recall]

        [redraw]
        [/redraw]
        [message]
            speaker=Delfador
            message= _ "At last, this is the entrance to the dwarven tunnels."
        [/message]
        [message]
            speaker=Konrad
            message= _ "All I can see are ruins and poor villages."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "The poor villagers that once lived here and traded with the dwarves are now held in slavery by the orcs."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Slaves to the evil orcs? We must liberate them!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "That would not be a wise choice, for our mission is to retrieve the Sceptre of Fire. If we tarry in this place, hordes of orcs will surround us."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "Konrad, heed the words of Delfador. We shall return to wrest the grip of the orcs from these lands. Look — orcs are already gathering. More are surely on their way."
        [/message]
        [message]
            speaker=Konrad
            message= _ "This does not please me, but I will listen to your advice."
        [/message]
        [message]
            role=Rider
            message= _ "Sir, I should like to scout out the path ahead. It would be disaster for us to find these doors sealed, leaving us as hunting fodder for the gathering horde."
        [/message]
        [message]
            speaker=Delfador
            message= _ "Excellent. We must find a way underground before we are overwhelmed."
        [/message]
        #
        # If you have outlaws in your party, you have the chance to
        # find a special unit
        #
        [role]
            type=Footpad,Thug,Poacher,Outlaw,Trapper,Bandit,Fugitive,Ranger,Huntsman,Highwayman
            role=Outlaw_Advisor
        [/role]
        [recall]
            role=Outlaw_Advisor
        [/recall]

        [if]
            [have_unit]
                role=Outlaw_Advisor
            [/have_unit]

            [then]
                [store_unit]
                    [filter]
                        role=Outlaw_Advisor
                    [/filter]

                    kill=no
                    variable=outlaw_advisor_store
                [/store_unit]

                {VARIABLE outlaw_name $outlaw_advisor_store.name}

                [message]
                    role=Outlaw_Advisor
                    message= _ "My uncle used to smuggle... err... I mean... trade food for the dwarves. He could get grain carts in under the very noses of those ugly orcs."
                [/message]
                [message]
                    role=Outlaw_Advisor
                    message= _ "He must be hiding in one of those villages."
                [/message]
            [/then]
        [/if]
    [/event]

    #
    # Some colorful talking events to make the scenario more interesting
    #

    [event]
        name=turn 2
        [message]
            speaker=Konrad
            message= _ "The defense of the dwarves must have been strong. Look at those ruined towers!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "The battle outside was fierce and lasted a full half-year. But, the battles inside the tunnels were worse."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Delfador
            x=11-19
            y=19-22
        [/filter]
        [message]
            speaker=Delfador
            # wmllint: local spelling Thunedain
            message= _ "The pillars of Thunedain. He was a legendary dwarvish lord who made his last stand here. May we triumph where he fell."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "I would settle for escape, though I know not which I dread more: foul orcs or fetid caves."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=die
        [filter_second]
            id=Haldiel
        [/filter_second]
        [message]
            speaker=second_unit
            message= _ "Back to the abyss, spawn of filth!"
        [/message]
    [/event]

    #
    # Finding the bandit uncle who gives you a big hint about the true exit
    #
    [event]
        name=moveto
        [filter]
            side=1
            x=18
            y=24
        [/filter]
        [if]
            [have_unit]
                role=Outlaw_Advisor
            [/have_unit]
            [then]
                {NAMED_LOYAL_UNIT 1 (Bandit) 18 24 (Uncle Somf) ( _ "Uncle Somf")}

                [message]
                    speaker=unit
                    message= _ "Who... who’s here?"
                [/message]

                #
                # The bandit's speech depends on who finds him
                #
                [if]
                    [have_unit]
                        role=Outlaw_Advisor
                        x,y=18,24
                    [/have_unit]
                    # the outlaw advisor finds Uncle Somf
                    [then]
                        [message]
                            speaker=Uncle Somf
                            message= _ "$outlaw_name|! How have you been? I haven’t seen you in years."
                        [/message]
                    [/then]
                    # ...or someone else finds him
                    [else]
                        [message]
                            speaker=Uncle Somf
                            message= _ "Haw! Any friend of $outlaw_name is a friend of mine too."
                        [/message]
                    [/else]
                [/if]

                [message]
                    speaker=Konrad
                    message= _ "We need to make it into the caves of the dwarves."
                [/message]

                #
                # The bandit divulges the true location of the entrance
                #
                [if]
                    [variable]
                        name=true_entrance_location
                        numerical_equals=1
                    [/variable]
                    [then]
                        [message]
                            speaker=Uncle Somf
                            message= _ "The mine entrances were all collapsed intentionally during the fighting. The doors, while heavily defended, remain accessible. The orcish hordes that assault them are repulsed, but you may be able to sneak in unnoticed."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=Uncle Somf
                            message= _ "The best way is through the mine tunnels. The orcs have never found all the mine entrances, and many still lead deep underground."
                        [/message]
                    [/else]
                [/if]
            [/then]

            [else]
                [allow_undo][/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto

        [filter]
            id=Uncle Somf

            [filter_adjacent]
                role=Outlaw_Advisor
            [/filter_adjacent]

            [or]
                role=Outlaw_Advisor

                [filter_adjacent]
                    id=Uncle Somf
                [/filter_adjacent]
            [/or]
        [/filter]

        [message]
            speaker=Uncle Somf
            message= _ "How are we doing, $outlaw_name|?"
        [/message]
        [message]
            speaker=$outlaw_advisor_store.id
            message= _ "The same as always, Uncle!"
        [/message]
        [message]
            speaker=Uncle Somf
            message= _ "That bad, huh?"
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    #
    # When any side 1 unit reaches a possible exit, we find out if it
    # is the correct one. We don't know who will reach the exit,
    # so the dialog must be general for anyone.
    # If the unit is Konrad, the victory event is handled separately.
    #
    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            x=14
            y=3
        [/filter]
        #
        # If true_entrance_location = 1 then this is the true entrance
        #
        [if]
            [variable]
                name=true_entrance_location
                numerical_equals=1
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "The doors... they can be moved!"
                [/message]
                [message]
                    speaker=Delfador
                    message= _ "Quickly, now, let us slip inside and hope the dwarves do not object..."
                [/message]
                [message]
                    speaker=Kalenz
                    message= _ "... and that the orcs do not follow."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "The doors are closed and barred from the inside!"
                [/message]
                [message]
                    speaker=Konrad
                    message= _ "We can’t get in! What should we do now?"
                [/message]
                [message]
                    speaker=Kalenz
                    message= _ "It is said that the orcs used old mine tunnels to surprise the dwarves. There appears to be one nearby, to the north-east."
                [/message]
                [message]
                    speaker=Konrad
                    message= _ "Then we must make it to that tunnel!"
                [/message]
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=25
            y=2
        [/filter]
        #
        # If true_entrance_location = 2 then this is the true entrance
        #
        [if]
            [variable]
                name=true_entrance_location
                numerical_equals=2
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "This old mine seems to be connected to the main tunnels."
                [/message]
                [message]
                    speaker=Kalenz
                    message= _ "I am hesitant to enter. It will be so difficult in the darkness!"
                [/message]
                [message]
                    speaker=Delfador
                    message= _ "There is no time for idle chatter or delay of any kind. Onward!"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "I have reached the mine entrance, but there is no tunnel here. Rock and rubble completely block the way."
                [/message]
                [message]
                    speaker=Konrad
                    message= _ "I hope we can make it through the main doors, then."
                [/message]
                [message]
                    speaker=Delfador
                    message= _ "It is our only choice now. Hurry!"
                [/message]
            [/else]
        [/if]
    [/event]

    #
    # These events end the level when Konrad makes it to the correct location.
    # This has to be a separate event from when any side 1 unit first reaches
    # a possible exit (the above events).
    #
    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Konrad
            x=14
            y=3
        [/filter]
        [if]
            [variable]
                name=true_entrance_location
                numerical_equals=1
            [/variable]
            [then]
                [message]
                    speaker=Konrad
                    message= _ "Pray that we live to see sunlight again."
                [/message]
                [set_variable]
                    name=killed_enemies
                    value=false
                [/set_variable]
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]
    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Konrad
            x=25
            y=2
        [/filter]
        [if]
            [variable]
                name=true_entrance_location
                numerical_equals=2
            [/variable]
            [then]
                [message]
                    speaker=Konrad
                    message= _ "Pray that we live to see sunlight again."
                [/message]
                [set_variable]
                    name=killed_enemies
                    value=false
                [/set_variable]
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/if]
    [/event]

    [event]
        name=enemies defeated
        [message]
            speaker=Kalenz
            message= _ "We have defeated the foul orcs guarding this land, but we must continue without rest. More will surely come!"
        [/message]
        [if]
            [variable]
                name=true_entrance_location
                numerical_equals=1
            [/variable]
            [then]
                [message]
                    speaker=Delfador
                    message= _ "Indeed we must not delay. Let us breach the great doors to the dwarven kingdom."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Delfador
                    message= _ "Indeed we must not delay. The mines in the northeast are the best way to enter."
                [/message]
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x=10-15
            y=10-15
        [/filter]

        {NAMED_LOYAL_UNIT 5 (Cuttle Fish) 13 13 (Cuttle Fish) ( _ "Cuttle Fish")}
        # wmllint: recognize Cuttle Fish

        [message]
            speaker=Cuttle Fish
            message= _ "Ruarrrrr!!!"    # wmllint: no spellcheck
        [/message]
        [message]
            speaker=unit
            message= _ "A monster was hiding in that lake!"
        [/message]
        [role]
            type=Thief,Rogue,Mage,Elvish Shaman,Elvish Druid,Elvish Archer,Elvish Fighter,Elvish Captain,Elvish Marshal,Horseman,Elvish Lord
            role=whiner
        [/role]
        [message]
            role=whiner
            message= _ "The legend was true! There are always tentacled creatures hiding in the lakes near the dwarven tunnels."
        [/message]
    [/event]

    [event]
        name=victory

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "But Konrad’s party was not alone in entering the caves..."
        [/message]

        {NAMED_LOYAL_UNIT 2 (Princess) 8 44 (Li'sar) ( _ "Li’sar")}
        # wmllint: recognize Li'sar
        {LISAR_GUARD_DOORS}
        {LISAR_GUARD_DOORS}
        {LISAR_GUARD_DOORS}
        {LISAR_GUARD_DOORS}
        {LISAR_GUARD_DOORS}
        {LISAR_GUARD_DOORS}
        [message]
            speaker="Li'sar"
            message= _ "Whew! We make our way through the dangerous fog of the mountains, and now there is all this chaos before us! Come on, men! We must make it to the caves that lie ahead of us!"
        [/message]
        {CLEAR_VARIABLE true_entrance_location}
        {CLEAR_VARIABLE outlaw_advisor_store}
        {CLEAR_VARIABLE outlaw_name}
    [/event]

    {campaigns/Heir_To_The_Throne/utils/deaths.cfg}
[/scenario]
