#textdomain wesnoth-httt
[scenario]
    id=20b_Underground_Channels
    name= _ "Underground Channels"
    map_file=20b_Underground_Channels.map
    {TURNS 55 50 45}

    next_scenario="21_Elven_Council"
    victory_when_enemies_defeated=no

    {HTTT_TRACK {JOURNEY_20B_NEW} }

    {UNDERGROUND}

    [time_area]
        x=0-21,22, 0-20, 0-17,  0-2,  0-4,    5,    6, 7,38-51,41,43,45-51,47-51,48-51,49-51
        y= 0-9, 6,10-12,13-14,15-18,19-36,32-36,35-36,36,  0-2, 3, 3,    3,    4,    5,    6
        {DEFAULT_SCHEDULE}
    [/time_area]

    {SCENARIO_MUSIC "underground.ogg"}
    {EXTRA_SCENARIO_MUSIC "nunc_dimittis.ogg"}
    {EXTRA_SCENARIO_MUSIC "the_deep_path.ogg"}
    {EXTRA_SCENARIO_MUSIC "into_the_shadows.ogg"}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Find the exit from the underground and move Konrad to it"
                condition=win
            [/objective]
            [objective]
                [show_if]
                    {CHECK_VARIABLE met_wose yes}
                [/show_if]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Help the wose fend off the undead attack"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Li’sar"
                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]

    {campaigns/Heir_To_The_Throne/utils/deaths.cfg}

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad-human.webp
        side=1
        canrecruit=yes
        controller=human
        team_name=elves
        user_team_name=_"Rebels"
        {GOLD 225 200 175}
        fog=yes
        shroud=yes
        share_vision=none
        {FLAG_VARIANT long}
    [/side]

    [side]
        side=2
        type=Saurian Oracle
        id=Szerkz
        name= _ "Szerkz"
        controller=ai
        canrecruit=yes
        team_name=saurians
        user_team_name=_"Saurians"
        recruit=Saurian Skirmisher,Saurian Augur,Saurian Ambusher,Saurian Flanker,Saurian Oracle,Saurian Soothsayer
        {GOLD 100 150 200}
        {INCOME 6 9 12}
        [ai]
            passive_leader=yes
        [/ai]
    [/side]

    [side]
        side=3
        type=Ancient Lich
        id=Muff Argulak
        name= _ "Muff Argulak"
        controller=ai
        canrecruit=yes
        team_name=undead
        user_team_name=_"Undead"
        recruit=Wraith,Shadow,Spectre,Nightgaunt,Revenant,Deathblade,Draug,Bone Shooter,Necrophage,Banebow
        {GOLD 150 200 250}
        {INCOME 8 12 16}
        [ai]
            passive_leader=yes
        [/ai]
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=4
        type=Ancient Wose
        id=Haralamdum
        # po: Haralamdum is ancient, and his mind does not work well any more. He takes things very slowly and carefully, even for a Wose. He halts and pauses, often searching for something in his memory, using meaningless syllables to fill the gap. The syllables of his name come from the phrase he uses to mean "that is all" or "I am done" which he says often, usually out of frustration with how hasty everyone seems. Nobody alive knows his real name, and he has likely forgotten as well. Feel free to add, move, or remove pauses to break up, or even scatter, his train of thought. For inspiration, think of Asperger Syndrome.
        name= _ "Haralamdum"
        controller=ai
        canrecruit=yes
        team_name=elves
        user_team_name=_"Rebels"
        recruit=Wose,Elder Wose
        {GOLD 150 100 70}
        {INCOME 10 6 2}
#ifdef EASY
        [ai]
            passive_leader=yes
        [/ai]
#endif
    [/side]

    [side]
        side=5
        type=Elvish Enchantress
        id=Bona-Melodia
        name= _ "Bona-Melodia"
        controller=ai
        canrecruit=yes
        team_name=elves
        user_team_name=_"Rebels"
        recruit=Elvish Fighter,Elvish Archer,Elvish Shaman,Elvish Scout,Elvish Hero,Elvish Captain,Elvish Ranger,Elvish Marksman,Elvish Druid,Elvish Sorceress,Elvish Rider
        gold=50
        [ai]
            [avoid]
                [not]
                    x=41,42,43-44,45-46,47-48,49-50
                    y=3,2,1-3,1-4,1-5,1-6
                [/not]
            [/avoid]
        [/ai]
        {FLAG_VARIANT wood-elvish}
    [/side]

    [event]
        name=prestart
        {NEED_DELFADOR placement=leader}
        {NEED_LISAR placement=leader}
        {NEED_KALENZ placement=leader}
    [/event]

    [event]
        name=start
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "The party enters the mysterious cave, ready to face the unknown..."
        [/message]
        [message]
            speaker=Delfador
            message= _ "It is unfortunate that the drakes distrusted us. Keh Ohn seemed noble and powerful, and under different circumstances, might have provided us with some insights about these caves."
        [/message]
        [message]
            speaker="Li'sar"
            message= _ "He was just someone who couldn’t handle the power given to him."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "You would do well to learn the lesson he did not."
        [/message]
        [message]
            speaker="Li'sar"
            message= _ "Move along, elf, unless you enjoy making camp in this dank cave. I, for one, do not!"
        [/message]
        [message]
            speaker=Kalenz
            message= _ "Indeed..."
        [/message]
        [message]
            speaker="Li'sar"
            message= _ "Listen, you whose eyes are fair but hide a vacuum, do you think I do not know what power can do to one’s soul? What evils a person is capable of when truth and righteousness are but scrolls that can be rewritten when a queen grows tired of them?"
        [/message]
        [message]
            speaker="Li'sar"
            message= _ "I spent my entire childhood listening to my mother give orders and command armies around. I hid in the throne room as a little girl as she met with her generals. I now know she was having people killed... entire towns of people killed!"
        [/message]
        [message]
            speaker="Li'sar"
            message= _ "I became my mother’s most trusted aide-de-camp. I was sent to quiet the worst of the rebellion. Of course they fought back. I never knew who these people were or why they fought my mother. Konrad, you are lucky. You do not know what Wesnoth has been like these past many years. There is no peace. I have never known peace."
        [/message]
        [message]
            speaker=Delfador
            message= _ "I do know the cup of bitterness poured out on Wesnoth by your mother, child. The land has been torn apart. The elves know this. The orcs know this. Undead can feel it. Large armies of men march across the plains hunting each other, and when no men remain, outsiders will claim Wesnoth as their home."
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION mad}
            message= _ "Enough! I can listen to no more of this. Li’sar, you may want to end your mother’s rule, but I will end her life as she ended the life of my father and my brothers. Asheviere’s masterwork of treachery will end, and it will end by my blade!"
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x=41,42,43-44,45-46,47-48,49-50
            y=3,2,1-3,1-4,1-5,1-6
            id=Konrad
        [/filter]

        [if]
            [have_unit]
                id=Bona-Melodia
            [/have_unit]
            [then]
                [message]
                    speaker=Bona-Melodia
                    message= _ "Get that vile creature!"
                [/message]

                [message]
                    speaker=Kalenz
                    message= _ "Hold!"
                [/message]

                [message]
                    speaker=Bona-Melodia
                    message= _ "Milord Kalenz! My apologies. I mistook you for one of those foul lizardmen. How came you to be traveling such paths?"
                [/message]

                [message]
                    speaker=Kalenz
                    message= _ "Change is coming to the human lands. We rush to Elensiria seeking assistance, and the perils of the Arkan-thoria presented the quickest route."
                [/message]

                [message]
                    speaker=Bona-Melodia
                    message= _ "Uradredia has already called a meeting of the Council of Lintanir. You must hurry, for they gather even now."
                [/message]

                [message]
                    speaker=Kalenz
                    message= _ "Then there is little time! Fare well."
                [/message]
            [/then]
            [elseif]
                [have_unit]
                    side=5
                [/have_unit]
                [then]
                    [message]
                        speaker=Kalenz
                        message= _ "What is this? Where is your leader?"
                    [/message]

                    [message]
                        side=5
                        message= _ "We were beset by many foul lizardmen. Alas, Bona-Melodia has fallen."
                    [/message]

                    [message]
                        speaker=Kalenz
                        message= _ "This bodes ill for Lintanir. We rush to Elensiria on other matters but will carry word of what has transpired here."
                    [/message]

                    [message]
                        side=5
                        message= _ "Lord Uradredia has called a meeting of the Council of Lintanir. Rumor is there are greater needs than ours."
                    [/message]

                    [message]
                        speaker=Kalenz
                        message= _ "Then we must hurry. Stand fast! We shall send reinforcements."
                    [/message]
                [/then]
            [/elseif]
            [else]
                [message]
                    speaker=Kalenz
                    message= _ "What is this? Where are the guardians? I see signs of battle everywhere: saurian footprints, elvish blood. This bodes ill for Lintanir. We must hurry onward to Elensiria. Quickly, before we, too, are beset."
                [/message]
            [/else]
        [/if]

        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    # This place was virtually empty, but there were notes indicating something more was intended.
    #
    # Sub-quest: help the wose with the undead (per original notes).
    # Requirements: the undead and wose leaders must still be alive
    # Start Trigger: first meeting with any wose
    # Success Trigger: the death of the undead leader at the hands of side 1; the wose leader must still be alive
    # Complication: other sides might kill the undead leader first.
    # Result: a book appears at (1,1)
    # Effect: taking the book grants movement cost 1 through forest, forest defense 70%, and ambush (like Elvish Ranger)
    # Only some units can read the book. Those who cannot: Delfador, Elves, Dwarves, Merfolk, Horsemen and Mages.
    #
    # I chose these effects because we're close to the end, the next scenario (S22) has some large forests but,
    # thereafter, there is not a lot of use for forest skills, since most of the territory is open grasslands.
    # So these effects should not have too large an effect upon the remaining parts of the campaign.
    #
    # GL-2016JUL

    # For background references, see Delfador's Memoirs, scenario 8 ("Ur Thorodor").

    [event]
        name=prestart

        {VARIABLE met_wose no}
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE book_taken,met_wose}
    [/event]

    [event]
        name=die
        [filter]
            id=Haralamdum
        [/filter]

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "From far in the distance comes the sound of branches snapping, followed by a long, hollow boom. The world goes silent for a moment."
        [/message]

        [message]
            speaker=Kalenz
            message= _ "Can you feel it? It is as if the entire forest is stunned! Something has happened and, I fear, not for the good."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Muff Argulak
        [/filter]

        [message]
            speaker=narrator
            image="wesnoth-icon.png"
            message= _ "A hollow screech echoes throughout the caverns. The air suddenly seems fresher and lighter."
        [/message]

        [if]
            [not]
                {CHECK_VARIABLE second_unit.side 1}
            [/not]
            [then]
                [message]
                    speaker=Delfador
                    message= _ "Whatever that was, the world rejoices."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=sighted
        [filter]
            side=4
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [filter_condition]
            [have_unit]
                id=Muff Argulak
            [/have_unit]
            [have_unit]
                id=Haralamdum
            [/have_unit]
        [/filter_condition]

        [if]
            {CHECK_VARIABLE unit.id Haralamdum}
            [then]
                [message]
                    speaker=second_unit
                    message= _ "Greetings, Sir Wose. We seek the exit to these caverns."
                [/message]
                [message]
                    speaker=Haralamdum
                    message= _ "If ... hmm dum ... you could help rid us of these ... alam hurum ... infernal undead, I would be ... alam alam ... look to the north and east ... hmm ... most grateful. Har alam dum."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit

                    # po: Intentionally courtly and formal here as a counter-point to the rough going when talking to Haralamdum.

                    message= _ "Well met, stranger."
                [/message]
                [message]
                    speaker=second_unit
                    message= _ "Well met, indeed. We seek the exit to these caverns."
                [/message]
                [message]
                    speaker=unit
                    message= _ "Then you should look to the north and east. But, if you would, might we ask your assistance?"
                [/message]
                [message]
                    speaker=second_unit
                    message= _ "What aid might we offer?"
                [/message]
                [message]
                    speaker=unit
                    message= _ "If you would help rid these caverns of those infernal undead, the Ancient One would be most grateful."
                [/message]
                [message]
                    speaker=second_unit
                    message= _ "Ancient one?"
                [/message]
                [message]
                    speaker=unit
                    message= _ "Our elder. Called, by some, Haralamdum."
                [/message]
            [/else]
        [/if]

        {VARIABLE met_wose yes}
        [show_objectives][/show_objectives]

        [event]
            name=die
            [filter]
                id=Haralamdum
            [/filter]

            {VARIABLE met_wose no}
        [/event]

        [event]
            name=die
            [filter]
                id=Muff Argulak
            [/filter]
            [filter_second]
                [not]
                    side=1
                [/not]
            [/filter_second]

            {VARIABLE met_wose no}
        [/event]

        [event]
            name=die
            [filter]
                id=Muff Argulak
            [/filter]
            [filter_second]
                side=1
            [/filter_second]
            [filter_condition]
                {CHECK_VARIABLE met_wose yes}
                [have_unit]
                    id=Haralamdum
                [/have_unit]
            [/filter_condition]

            [message]
                speaker=Haralamdum

                message= _ "Har hum har ... hmm ... well ... har alam dum ... good."
            [/message]

            [message]
                speaker=Konrad
                message= _ "Those undead will bother you no more, Sir Wose."
            [/message]

            [delay]
                time=2000
            [/delay]

            [message]
                speaker=Delfador
                message= _ "We still must find the exit from these caverns, Konrad."
            [/message]

            [message]
                speaker=Konrad
                message= _ "Yes, Delfador. I’m afraid we must be going, Sir Wose."
            [/message]

            [message]
                speaker=Haralamdum
                message= _ "Well, I say ... hmm dum har ... young Master Delfador? Harum-alam-alam. So it is! Hmm hmm alam ... how is your head?"
            [/message]

            [message]
                speaker=Delfador
                message= _ "My head?"
            [/message]

            [message]
                speaker=Haralamdum

                # po: "just the other day" probably means a few decades ago. To Haralamdum, Ur Thorodor is a very young wose … a small, young twig on the end of a new branch of an ancient tree, who has not yet earned the honorific 'Ur'

                message= _ "Just the other day ... hmm ... I was speaking with that twig ... alam ... alam dum ... Thorodor? Hmm ... yes ... hum ... he said you took a ... alam har ... nasty blow to the head ... hmm ... and he feared you were dead."
            [/message]

            [message]
                speaker=Delfador

                # po: Over 50 years ago, probably 52, to be more precise.

                message= _ "That was many years ago, I’m afraid. Now, we really must be moving along ..."
            [/message]

            [message]
                speaker=Haralamdum
                message= _ "So hasty ... hmm ... there was something ..."
            [/message]

            [message]
                speaker=Haralamdum
                message= _ "Har dum ... oh, yes, the book."
            [/message]

            [message]
                speaker=Delfador
                message= _ "Book?"
            [/message]

            [message]
                speaker=Haralamdum
                message= _ "When you asked Thorodor for ... harum ... assistance? Hmm ... hmm ... He thought you meant the book ... har hmm ... but you had rushed off ... alam ... alam dum ... and died before he could tell you I have it."
            [/message]

            [message]
                speaker=Delfador
                message= _ "I remember no book."
            [/message]

            [message]
                speaker=Haralamdum
                message= _ "I am sure ... dum hum ... well, the head ... alam lum alam ... yes, it was somewhere around here ... hum dum da dum ... Thorodor thought it ... hmm ... quite important ... lum harum dum ... perhaps near my home stump?"
            [/message]

            [message]
                speaker=Delfador
                message= _ "I am sorry, I remember no book. Now, we really must be off."
            [/message]

            [message]
                speaker=Haralamdum
                message= _ "So hasty. Har alam dum."
            [/message]

            [message]
                speaker=narrator
                image="wesnoth-icon.png"
                message= _ "The wose silently fade into the forest."
            [/message]

            [kill]
                side=4
            [/kill]

            {PLACE_IMAGE items/book4.png 1 1}
            {VARIABLE book_taken no}
            {VARIABLE met_wose no}

            [event]
                name=moveto
                first_time_only=no
                [filter]
                    side=1
                    x,y=1,1
                [/filter]

                [if]
                    [not]
                        {CHECK_VARIABLE book_taken yes}
                    [/not]
                    [then]
                        [message]
                            speaker=$unit.id|
                            caption=""
                            image="wesnoth-icon.png"
                            male_message= _ "Should $unit.name| read the book?"
                            female_message= _ "female^Should $unit.name| read the book?"
                            [option]
                                label= _ "Yes"
                                [command]
                                    [object]
                                        id=wose_lore
                                        name= _ "Wose Lore"
                                        image="items/book4.png"
                                        duration=forever
                                        description= _ "This massive book is filled with the Lore and Legends of the Wose. Any who read it learn deeply of the ways of the twig and leaf, the tree and the forest."
                                        cannot_use_message= _ "The book is filled with meaningless tales of sticks and leaves, and childish stories about trees and forest creatures."
                                        [filter]
                                            x,y=1,1
                                            [not] # Elvish Rangers already know this
                                                type_adv_tree=Elvish Ranger
                                            [/not]
                                        [/filter]
                                        [then]
                                            {VARIABLE book_taken yes}
                                            [remove_item]
                                                x,y=1,1
                                            [/remove_item]
                                            [message]
                                                speaker=$unit.id|
                                                caption=""
                                                image="wesnoth-icon.png"
                                                male_message= _ "$unit.name| becomes entranced and greatly gains affinity with the forest, its nature and ways, and all the creatures within it. He feels he will quickly become more experienced once reaching the surface. Unfortunately, as the last page was turned, the book crumbled to dust."
                                                female_message= _ "female^$unit.name| becomes entranced and greatly gains affinity with the forest, its nature and ways, and all the creatures within it. She feels she will quickly become more experienced once reaching the surface. Unfortunately, as the last page was turned, the book crumbled to dust."
                                            [/message]
                                        [/then]
                                        [effect]
                                            apply_to=new_ability
                                            [abilities]
                                                {ABILITY_AMBUSH}
                                            [/abilities]
                                        [/effect]
                                        [effect]
                                            apply_to=defense
                                            replace=yes
                                            [defense]
                                                forest=30
                                            [/defense]
                                        [/effect]
                                        [effect]
                                            apply_to=movement_costs
                                            replace=yes
                                            [movement_costs]
                                                forest=1
                                            [/movement_costs]
                                        [/effect]
                                        [effect]
                                            apply_to=max_experience
                                            increase=-20%
                                        [/effect]
                                    [/object]
                                [/command]
                            [/option]
                            [option]
                                label= _ "No"
                                [command]
                                    [allow_undo][/allow_undo]
                                [/command]
                            [/option]
                        [/message]
                    [/then]
                    [else]
                        [allow_undo][/allow_undo]
                    [/else]
                [/if]
            [/event]
        [/event]
    [/event]
[/scenario]
