#textdomain wesnoth-tsg
[scenario]
    id=7a_Into_The_Depths

    name= _ "Into The Depths"
    next_scenario=8a_Return_To_Kerlath

    {SCENARIO_MUSIC the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC knalgan_theme.ogg}

    map_data="{campaigns/The_South_Guard/maps/7a_Into_The_Depths.map}"

    {campaigns/The_South_Guard/utils/sg_deaths.cfg}

    {UNDERGROUND}

    victory_when_enemies_defeated=no
    {TURNS 50 45 40}

    # The South Guard.

    [side]
        side=1
        type=Horseman Commander
        id=Deoran
        name= _ "Deoran"
        unrenamable=yes

        team_name=South_Guard
        user_team_name=_"South Guard"
        controller=human
        {CUSTOM_SG_FLAG}

        fog=yes
        shroud=yes

        share_view=yes

        {GOLD 125 100 80}
        {INCOME 10 8 6}
    [/side]

    # The Undead Hordes

    [side]
        side=2
        type=Lich
        id="Mal M'Brin"
        name= _ "Mal M'Brin"
        profile=portraits/mal-mbrin.png

        team_name=undead_hordes
        user_team_name=_"Undead"
        controller=ai

        {GOLD 20 80 140}

        canrecruit=yes
        [ai]
#ifdef EASY
            recruitment_pattern=fighter,scout,fighter
#endif
#ifdef NORMAL
            recruitment_pattern=fighter,scout,fighter
#endif
#ifdef HARD
            recruitment_pattern=fighter,scout,archer,fighter
#endif
            recruitment_ignore_bad_movement=yes
            aggression=0.8
            village_value=0.1

            [avoid]
                x,y=2-14,16-26
            [/avoid]
        [/ai]

#ifdef EASY
        recruit=Skeleton,Ghost,Vampire Bat,Walking Corpse
#endif
#ifdef NORMAL
        recruit=Skeleton,Ghoul,Ghost,Vampire Bat,Walking Corpse
#endif
#ifdef HARD
        recruit=Deathblade,Ghoul,Ghost,Wraith,Blood Bat,Walking Corpse,Dark Adept
#endif
    [/side]

#ifdef HARD
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Deathblade" 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Wraith" 2}
#else
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Vampire Bat" 4}
#endif

    [side]
        side=3
        type=Soulless
        id=Groth
        name= _ "Groth"

        team_name=undead_hordes
        user_team_name=_"Undead"
        controller=ai

        {GOLD 20 50 125}

        canrecruit=yes
        [ai]
            recruitment_pattern=fighter
            recruitment_ignore_bad_movement=yes
            aggression=0.6
            village_value=0.3

            [avoid]
                x,y=2-14,16-26
            [/avoid]
        [/ai]

#ifdef EASY
        recruit=Walking Corpse,Ghoul
#endif

#ifdef NORMAL
        recruit=Walking Corpse,Ghoul
#endif

#ifdef HARD
        recruit=Walking Corpse,Soulless,Ghoul,Necrophage
#endif
    [/side]

    # Passive trolls

    [side]
        side=4
        type=Troll Hero
        id=Grek
        name= _ "Grek"

        team_name=South_Guard
        user_team_name=_"South Guard"
        controller=ai

        {GOLD 60 30 10}

        canrecruit=yes

        [ai]
#ifdef EASY
            recruitment_pattern=fighter,fighter,mixed fighter
#else
            recruitment_pattern=fighter
#endif
            aggression=0.1
            caution=0.9
            [avoid]
                x,y=14-38,1-35
            [/avoid]
        [/ai]

#ifdef EASY
        recruit=Troll, Troll Rocklobber
#endif

#ifdef NORMAL
        recruit=Troll Whelp
#endif

#ifdef HARD
        recruit=Troll Whelp
#endif
    [/side]

    {STARTING_VILLAGES 4 8}

    # Aggressive trolls; the trolls turn to this side and start being useful if
    # the player pays them

    [side]
        side=5
        no_leader=yes
        team_name=South_Guard
        user_team_name=_"South Guard"
        controller=ai
        colour=purple

        fog=yes
        share_view=yes

        [ai]
            recruitment_pattern=fighter,fighter,mixed fighter
            aggression=0.9
            caution=0.5
            village_value=0.0

            [target]
                side=2
                value=5
            [/target]
        [/ai]

        recruit=Troll Whelp,Troll,Troll Rocklobber
    [/side]

    # Scenario Setup

    [event]
        name=prestart

        {CLEAR_VARIABLE stored_Deoran_side}

        [unit]
            side=2
            type=Eyestalk
            x,y=10,8
            id=Eye Guardian
            name=_ "Eye Guardian"
            facing=sw
        [/unit]

        [unit]
            side=2
            type=Revenant
            x,y=13,9
            facing=sw
            ai_special=guardian
        [/unit]
    [/event]

    # Scenario Beginning

    [event]
        name=start

        [set_recruit]
            side=1
            recruit=Bowman,Spearman,Cavalryman,Elvish Shaman,Elvish Fighter
        [/set_recruit]

        [recall]
            id=Ethiliel
        [/recall]

        [recall]
            id=Minister Hylas
        [/recall]

#ifdef __UNUSED__
        [message]
            speaker=Deoran
            message= _ "My mount will not help me in these rocky paths - I will leave him here at the entrance and proceed on foot."
        [/message]
        [message]
            speaker=Ethiliel
            message= _ "That is wise. Speed is less valuable in caves than toughness."
        [/message]

        # Transform Deoran into a Foot Commander - thanks to Shadow for the graphics!

        [store_unit]
            [filter]
                id=Deoran
            [/filter]

            kill=yes
            variable=stored_Deoran
        [/store_unit]

        [if]
            [variable]
                name=stored_Deoran.type
                equals=Junior Commander
            [/variable]
            [then]
                {VARIABLE stored_Deoran.type "Dismounted Commander 1"}
                {VARIABLE stored_Deoran.moves 5}
            [/then]
        [/if]
        [if]
            [variable]
                name=stored_Deoran.type
                equals=Horseman Commander
            [/variable]
            [then]
                {VARIABLE stored_Deoran.type "Dismounted Commander 2"}
                {VARIABLE stored_Deoran.moves 6}
            [/then]
        [/if]
        [if]
            [variable]
                name=stored_Deoran.type
                equals=Mounted General
            [/variable]
            [then]
                {VARIABLE stored_Deoran.type "Dismounted Commander 3"}
                {VARIABLE stored_Deoran.moves 6}
            [/then]
        [/if]

        [unstore_unit]
            variable=stored_Deoran
            find_vacant=no
        [/unstore_unit]

        {FULL_HEAL id=Deoran}
#endif

        [message]
            speaker=Ethiliel
            message= _ "Proceed slowly, who knows what evils inhabited these parts before Mebrin was turned! We cannot be too careful."
        [/message]

#ifdef EASY
        [message]
            speaker=narrator
            message= _ "Cavalrymen and Dragoons will be less useful in the caves than soldiers who fight on foot."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=narrator
            message= _ "Also, soldiers with the -quick- trait will be useful in the dark."
            image=wesnoth-icon.png
        [/message]
#endif

        [objectives]
            side=1
            [objective]
                description= _ "Find the source of the undead under the citadel"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Deoran"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Minister Hylas"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Ethiliel"
                condition=lose
            [/objective]
            [objective]
                description= _ "Time runs out"
                condition=lose
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/objectives]
    [/event]

    [event]
        name=sighted

        [filter]
            type=Eyestalk
        [/filter]

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Minister Hylas
            message= _ "What horrid creature may that be? I've seen many wicked things in my life, but never one such as that."
        [/message]

        [message]
            speaker=Ethiliel
            message= _ "It must be a guardian of some kind set here by Mebrin. We elves have heard stories of these creatures but I wouldn't have expected to come across one... the least of all here. Let us proceed with caution."
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            side=4
        [/filter]

        [redraw][/redraw]
        [message]
            speaker=Grek
            message= _ "Ha! Humans and elves! What are you doing in our caves, and why shouldn't we grind your bones and gnaw on your flesh?"
        [/message]

        [message]
            speaker=Deoran
            message= _ "We mean no trespass. We are hunting the undead."
        [/message]

        [message]
            speaker=Grek
            message= _ "Undead! Ha! We kill undead all the time. You be friendly enough so we won't kill you, but why should we help you?"
        [/message]

#ifdef EASY
        {VARIABLE troll_help_cost 100}
#endif
#ifdef NORMAL
        {VARIABLE troll_help_cost 150}
#endif
#ifdef HARD
        {VARIABLE troll_help_cost 200}
#endif

        # The help from the trolls can be received either on first sighting of them or
        # later; so here's what the trolls do to help you wrapped inside a macro so that
        # the WML doesn't need to be duplicated by hand

#define TROLL_HELP
    [gold]
        side=1
        amount=-$troll_help_cost
    [/gold]

    [remove_shroud]
        side=1
        x,y=1-38,1-35
    [/remove_shroud]

    [store_side]
        side=4
        variable=stored_side_4
    [/store_side]

    [modify_side]
        side=5
        gold=$stored_side_4.gold
    [/modify_side]

    # Note: the order of storing the villages, flipping the
    # units and recapturing the villages is important, because a
    # side with no leader cannot own villages.

    [store_villages]
        owner_side=4
        variable=side_4_villages
    [/store_villages]

    {MODIFY_UNIT side=4 side 5}

    {FOREACH side_4_villages i}
        [capture_village]
            x,y=$side_4_villages[$i].x,$side_4_villages[$i].y
            side=5
        [/capture_village]
    {NEXT i}

    {CLEAR_VARIABLE stored_side_4}
    {CLEAR_VARIABLE side_4_villages}

    [message]
        speaker=Grek
        message= _ "Gold is good. We can trade gold for weapons and fire. We will help you defeat the undead now."
    [/message]
    [message]
        speaker=Deoran
        message= _ "What aid can you offer us? We are not well suited to fighting in the caves."
    [/message]
    [message]
        speaker=Grek
        message= _ "We already planned to kill the undead ourselves... First we kill dwarves though! Now we have dwarvish thunder fire and many trolls ready for fighting. They come too and help you smash them undead."
    [/message]
    [message]
        speaker=Grek
        message= _ "Go here and light the thunder fire and it will blast a back door into the lich's lair!"
    [/message]

    {HIGHLIGHT_IMAGE 17 24 items/bomb.png ()}

    {VARIABLE bomb_status ready}
    {VARIABLE troll_allies yes}
#enddef

        [message]
            speaker=Deoran
            message= _ "What should we offer them for their help?"
            [option]
                message= _ "We will give you $troll_help_cost gold pieces if you help us defeat the undead."
                [command]
                    [store_side]
                        side=1
                        variable=stored_side_1
                    [/store_side]

                    [if]
                        [variable]
                            name=stored_side_1.gold
                            greater_than_equal_to=$troll_help_cost
                        [/variable]

                        [then]
                            {TROLL_HELP}
                        [/then]

                        [else]
                            [message]
                                speaker=Grek
                                message= _ "Haha, you humans and elves poor, you have not enough gold! If you want troll help, you must come to me when you have the gold."
                            [/message]

                            [objectives]
                                side=1
                                [objective]
                                    description= _ "Find the source of the undead under the citadel"
                                    condition=win
                                [/objective]
                                [objective]
                                    description= _ "Meet with and pay the troll leader $troll_help_cost gold to receive their help"
                                    condition=win
                                [/objective]
                                [objective]
                                    description= _ "Death of Deoran"
                                    condition=lose
                                [/objective]
                                [objective]
                                    description= _ "Death of Minister Hylas"
                                    condition=lose
                                [/objective]
                                [objective]
                                    description= _ "Death of Ethiliel"
                                    condition=lose
                                [/objective]
                                [objective]
                                    description= _ "Time runs out"
                                    condition=lose
                                [/objective]

                                note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
                            [/objectives]

                            {VARIABLE late_payment_for_troll_help yes}
                        [/else]
                    [/if]
                [/command]
            [/option]

            [option]
                message= _ "We will offer you freedom and a place in our lands."
                [command]
                    [message]
                        speaker=Grek
                        message= _ "Ha! Who wants stupid human lands!"
                    [/message]
                    [message]
                        speaker=Minister Hylas
                        message= _ "Then you will not aid us in our quest to destroy the undead menace?"
                    [/message]
                    [message]
                        speaker=Grek
                        # wmllint: local spelling "Bah"
                        message= _ "Bah! We destroy the undead when we want. Maybe wait for a few years first. If you want troll help, you come see me and give proper payment!"
                    [/message]
                    [message]
                        speaker=Ethiliel
                        message= _ "These creatures are much too simpleminded to be of any help to us but at least they will not attack us outright. We will have to face Mebrin alone."
                    [/message]

                    [objectives]
                        side=1
                        [objective]
                            description= _ "Find the source of the undead under the citadel"
                            condition=win
                        [/objective]
                        [objective]
                            description= _ "Meet with and pay the troll leader $troll_help_cost gold to receive their help"
                            condition=win
                        [/objective]
                        [objective]
                            description= _ "Death of Deoran"
                            condition=lose
                        [/objective]
                        [objective]
                            description= _ "Death of Minister Hylas"
                            condition=lose
                        [/objective]
                        [objective]
                            description= _ "Death of Ethiliel"
                            condition=lose
                        [/objective]
                        [objective]
                            description= _ "Time runs out"
                            condition=lose
                        [/objective]

                        note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
                    [/objectives]

                    {VARIABLE late_payment_for_troll_help yes}
                [/command]
            [/option]
        [/message]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            [filter_adjacent]
                id=Grek
            [/filter_adjacent]
        [/filter]

        [if]
            [variable]
                name=late_payment_for_troll_help
                equals=yes
            [/variable]

            [variable]
                name=troll_allies
                not_equals=yes
            [/variable]

            [then]
                [store_side]
                    side=1
                    variable=stored_side_1
                [/store_side]

                [message]
                    speaker=Grek
                    message= _ "Ha, you can afford troll help this time?"
                    [option]
                        [show_if]
                            [variable]
                                name=stored_side_1.gold
                                greater_than_equal_to=$troll_help_cost
                            [/variable]
                        [/show_if]

                        message= _ "Here's $troll_help_cost for your help against the undead."

                        [command]
                            {TROLL_HELP}
                        [/command]
                    [/option]

                    [option]
                        message= _ "No, sorry."

                        [command]
                            [allow_undo][/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]

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

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            x,y=17,24
        [/filter]

        [if]
            [variable]
                name=bomb_status
                equals=ready
            [/variable]

            [then]
                [message]
                    speaker=unit
                    message= _ "I'm lighting it!"
                [/message]
                [sound]
                    name=fuse.ogg
                [/sound]
                [delay]
                    time=2000
                [/delay]
                [sound]
                    name=explosion.ogg
                [/sound]

                [removeitem]
                    x,y=17,24
                [/removeitem]

                [scroll]
                    x,y=10,10
                [/scroll]
                [scroll]
                    x,y=-10,-10
                [/scroll]
                [scroll]
                    x,y=10,10
                [/scroll]
                [scroll]
                    x,y=-10,-10
                [/scroll]
                {MODIFY_TERRAIN Re 18 23}
                {MODIFY_TERRAIN Ww 18 24}

                [redraw][/redraw]
                [message]
                    speaker=unit
                    message= _ "I've broken through!"
                [/message]

                {VARIABLE bomb_status blown}
            [/then]

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

    # Confrontation with Mal Brin
    [event]
        name=sighted
        [filter]
            id="Mal M'Brin"
        [/filter]

        [redraw][/redraw]
        [message]
            speaker="Ethiliel"
            message= _ "Mebrin! My teacher of old! Can that truly be you?"
        [/message]

        [message]
            speaker="Mal M'Brin"
            # wmllint: local spelling Eth
            message = _ "Eth...Ethiliel? You are here?"
        [/message]

        [message]
            speaker="Ethiliel"
            message= _ "How did you come to be here, you of all people, shut away from the trees and the light of the sun?"
        [/message]

        [message]
            speaker="Mal M'Brin"
            message = _ "I broke their chains. They bound me, the accursed humans. Bound me! Kidnapped me to raise undead for them. Menaced me with cold iron...ahh, the iron on my skin, it burned, it burned!"
        [/message]

        [message]
            speaker="Deoran"
            message= _ "What is this? Elves bear steel swords."
        [/message]

        [message]
            speaker="Ethiliel"
            message= _ "They are but warriors. All elves feel the shadow of iron, and to those who walk our higher paths it is a bane, interfering with our magic. But this touches on mysteries that are not for men to know, human. I bind you never to speak of it."
        [/message]

        [message]
            speaker="Mal M'Brin"
            message = _ "Humans! Betrayers! Tree-killers! They are a blight on the world! I shall bring my new servants north to the lands we so foolishly granted to men in ages past, and destroy them all!"
        [/message]

        [message]
            speaker="Ethiliel"
            message= _ "Your servants! Your servants are abominations worse than any human. They stink of the grave. This cannot be the sage Mebrin that I knew and revered speaking. He would never have allied himself with the dead against the living!"
        [/message]

        [message]
            speaker="Mal M'Brin"
            message= _ "I am called Mal M'Brin now, Ethiliel, best student of mine. It is time for a new lesson. I was such as you, full of doubt and weakness, but now I have passed over and become more than you know. There is infinity in death; I have touched the void at the heart of all things. You, too, can partake of its boundless power."
        [/message]

        [message]
            speaker="Mal M'Brin"
            message= _ "Join me! Stand by my side! We shall rise and sweep the humans from the green world. Their corpses will serve us; their bones will dance for our pleasure."
        [/message]

        [message]
            speaker="Ethiliel"
            message= _ "And when we were done, what would we have become? Unlife. Hungering shadows, devouring all we once cherished."
            image=portraits/ethiliel-mad.png
        [/message]

        [message]
            speaker="Ethiliel"
            message= _ "No. It shall not be. The sage Mebrin is dead. It is time to put him to rest."
        [/message]

        [message]
            speaker=Deoran
            image=portraits/deoran-mad.png
            message= _ "Even a mere human can see that you have become a mockery of all that you once believed in. I will destroy you and your works if it's the last thing I do!"
        [/message]
        [message]
            speaker="Mal M'Brin"
            message= _ "You, destroy me? Fool human. You will die, and the elves you have seduced with you. And you shall serve me beyond death, forever."
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id="Mal M'Brin"
        [/filter]

        [message]
            speaker="Mal M'Brin"
            message= _ "Nooo! This cannot be. The elves I once led have destroyed me. After all I have sacrificed, I still die...."
        [/message]

        {CLEAR_VARIABLE bomb_status}
        {CLEAR_VARIABLE troll_allies}
        {CLEAR_VARIABLE stored_side_1}
        {CLEAR_VARIABLE late_payment_for_troll_help}

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