#textdomain wesnoth-nr
[scenario]
    id=02_Infested_Caves
    name= _ "Infested Caves"

    {INTRO_AND_SCENARIO_MUSIC "knolls.ogg" "underground.ogg"}
    {EXTRA_SCENARIO_MUSIC "revelation.ogg"}
    {EXTRA_SCENARIO_MUSIC "knalgan_theme.ogg"}

    [story]
        [part]
            story= _ "Ill-armed and untrained though they were, the people of Dwarven Doors rose against the Orcs. Although their losses had been tremendous, never once did they break or falter. In the end, the orcish host was smashed and the survivors sent scurrying for their lives."
        [/part]
        [part]
            story= _ "Grief for the fallen could not suppress the people’s joy in their newfound freedom. They ransacked the orcish storehouses, sang, danced and drank with abandon. New-fledged warriors boasted of their deeds in the battle, while the women and children looked on with awe."
        [/part]
        [part]
            story= _ "Amidst all the revelry, Tallin alone remained grave. He knew it likely that the orcs would return with a vengeance and slaughter every last one of them. The following morning, he gathered the cooler heads about him so they could set their next course. How might they, untrained in the art of war and without expectation of aid from the prosperous human lands of the south, defend themselves?"
        [/part]
        [part]
            story= _ "The war council’s thoughts quickly turned to the dwarves, close allies in the past. However, nobody knew the state of things in the Knalgan tunnels. The bravest of scouts found in there the spoor of many trolls, and of creatures darker than trolls. It was even rumored that the dwarven dead from the invasion of Knalga had risen in unlife, roaming the tunnels to slay the living. Fighting through all manner of unknown monsters in the mere hope of finding surviving dwarves held but little appeal."
        [/part]
        [part]
            # wmllint: local spelling woodsrunners
            story= _ "So the matter lay, and the peasants dithered from one suggested plan of action to the next, never arriving at any conclusion. In the meantime, some help, unlooked for, arrived in the form of a small band of woodsrunners — escapees from the orcs, grown wood-wise and crafty, and in contact with larger bands of poachers and outlaws roaming the night. Embassies were sent; agreements made. A handful of experienced fighters, scarred and closemouthed, came to Dwarven Doors to find and train the most willing in their rugged fighting style."
        [/part]
        [part]
            # wmllint: local spelling nightrunners
            story= _ "A fortnight after their victory, the town was awakened from slumber in the dead of night by the distant booming of orcish drums. Scouts training with the nightrunners returned to cry the news that a strong orcish company was approaching. Frightened as they had never been before, the folk of Dwarven Doors looked to Tallin for guidance."
        [/part]
        [part]
            story= _ "Faced with certain destruction at the hands of the orcs, or a fate unknown in the caves of Knalga, Tallin chose the latter. The people quickly gathered together and collected whatever food and weapons they could and plunged into the darkness of the caves."
        [/part]
    [/story]

    map_data="{campaigns/Northern_Rebirth/maps/02_Infested_Caves.map}"
    {TURNS4 60 55 50 45}
    # Whole scenario takes place underground thus apropriate time of day.
    {UNDERGROUND}
    next_scenario=03_To_the_Mines

    # Set sides
    # Players side - some more recruit options this time.
    [side]
        type=Peasant
        id=Tallin
        name=_ "Tallin"
        canrecruit=yes
        side=1
        controller=human
        {GOLD4 500 450 400 350}
        recruit=Peasant,Woodsman,Thug,Poacher,Footpad
        team_name=rebels
        user_team_name=_"Rebels"
        shroud=yes
        {FLAG_VARIANT ragged}
    [/side]

    # Three sides for trolls, one lead by troll warrior
    [side]
        type=Troll
        id=Knash
        name= _ "Knash"
        canrecruit=yes
        side=2
        {GOLD4 75 100 150 200}
        recruit=Troll Whelp
        team_name=trolls
        user_team_name=_"Trolls"
        shroud=yes
    [/side]

    [side]
        type=Troll
        id=Krog
        name= _ "Krog"
        canrecruit=yes
        side=3
        {GOLD4 75 100 150 200}
        recruit=Troll Whelp
        team_name=trolls
        user_team_name=_"Trolls"
    [/side]

    # Dwarven side
    [side]
        type=Dwarvish Lord
        id=Hamel
        name= _ "Hamel"
        profile=portraits/Hamel.png
        canrecruit=yes
        side=4
        {GOLD4 150 130 120 100}
        recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Dwarvish Scout
        team_name=rebels
        user_team_name=_"Rebels"
        [ai]
            recruitment_pattern=fighter,fighter,fighter,mixed fighter
        [/ai]
        {FLAG_VARIANT knalgan}
    [/side]

    # Three undead sides
    [side]
        type=Death Knight
        canrecruit=yes
        side=5
        {GOLD4 200 300 400 500}
        {INCOME4 5 10 15 20}
        recruit=Skeleton,Skeleton Archer
        team_name=undead
        user_team_name=_"Undead"
        {FLAG_VARIANT undead}
    [/side]

    [side]
        type=Troll Warrior
        id=Thung
        name= _ "Thung"
        canrecruit=yes
        side=6
        {GOLD4 200 300 400 500}
        recruit=Troll Whelp,Troll,Troll Rocklobber
        team_name=trolls
        user_team_name=_"Trolls"
    [/side]

    [side]
        type=Death Knight
        canrecruit=yes
        side=7
        {GOLD4 150 250 350 450}
        {INCOME4 2 4 6 8}
        recruit=Skeleton,Skeleton Archer
        team_name=undead
        user_team_name=_"Undead"
        {FLAG_VARIANT undead}
    [/side]

    [side]
        type=Death Knight
        canrecruit=yes
        side=8
        {GOLD4 150 250 350 450}
        {INCOME4 2 4 6 8}
        recruit=Skeleton,Skeleton Archer
        team_name=undead
        user_team_name=_"Undead"
        {FLAG_VARIANT undead}
    [/side]

    # And an empty side for the bat used in flavor event
    [side]
        no_leader=yes
        side=9
        hidden=yes
    [/side]

    # Prestart event - place some dwarven guards to increase the
    #                  survivability of the allied AI and set player
    #                  objectives.
    [event]
        name=prestart
        {NOTRAIT_UNIT 4 "Dwarvish Stalwart" 30 25}
        [+unit]
            ai_special=guardian
        [/unit]
        {NOTRAIT_UNIT 4 "Dwarvish Stalwart" 28 21}
        [+unit]
            ai_special=guardian
        [/unit]
        {NOTRAIT_UNIT 4 "Dwarvish Stalwart" 31 21}
        [+unit]
            ai_special=guardian
        [/unit]
        {NOTRAIT_UNIT 4 "Dwarvish Stalwart" 26 24}
        [+unit]
            ai_special=guardian
        [/unit]

        [objectives]
            side=1
            [objective]
                description= _ "Find the Dwarves"
                condition=win
            [/objective]
            [objective]
                description= _ "Clear the Caves"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Tallin"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Hamel"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

        {RECALL_SUPPORTER}
    [/event]

    # Start event - execute the flavour bat encounter.
    [event]
        name=start
        [message]
            role=Supporter
            message= _ "So here we are..."
        [/message]
        [message]
            role=Supporter
            message= _ "(<i>Trip</i>) <i>Oof!</i>" # wmllint: no spellcheck
        [/message]
        [message]
            role=Supporter
            message= _ "Great idea, Tallin, I probably couldn’t even fight a bat down here."
        [/message]
        [move_unit_fake]
            type=Blood Bat
            side=9
            x=15,14,13,12,11
            y=12,12,12,12,12
        [/move_unit_fake]
        {NOTRAIT_UNIT 9 "Blood Bat" 11 12}
        [message]
            type=Blood Bat
            message= _ "Neep Neep!" # wmmlint: no spellcheck
        [/message]
        [message]
            role=Supporter
            message= _ "Ahhhh!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Calm down. Come what may, we’ll handle them. Come on now, let’s find those dwarves!"
        [/message]
    [/event]

    # Find Camerin event
    [event]
        name=moveto
        [filter]
            side=1
            x=2
            y=1
        [/filter]

        [unit]
            type=Arch Mage
            id=Camerin
            profile=portraits/Camerin.png
            name= _ "Camerin"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
            {IS_LOYAL}
            side=1
            x=1
            y=1
        [/unit]
        [message]
            speaker=Camerin
            message= _ "<i>Prepare to die, you foul orc!</i>"
        [/message]
        [message]
            speaker=unit
            message= _ "Hold it! I am no orc, I am a human!"
        [/message]
        [message]
            speaker=Camerin
            message= _ "A human! Amazing, I haven’t seen a human ever since the orcs attacked."
        [/message]
        [message]
            speaker=unit
            message= _ "How have you managed to survive all this time?"
        [/message]
        [message]
            speaker=Camerin
            message= _ "By frying every orc, troll or skeleton I come across. Duh! Those monsters desecrated my life’s work, now I shall not rest till I send every last one of them to hell! Oh, and just between me and you, it is actually good fun — more fun anyway than sitting on your backside studying all day..."
        [/message]
        [message]
            speaker=unit
            message= _ "... Uh ok!" # wmllint: no spellcheck
        [/message]
        [message]
            speaker=Camerin
            message= _ "But silly me, where are my manners? Would you like to come inside for tea?"
        [/message]
        [message]
            speaker=unit
            message= _ "Um... err... well actually we are presently busy fighting our way through hordes of trolls and skeletons trying to find the dwarves... if there are any left."
        [/message]
        [message]
            speaker=Camerin
            message= _ "Hordes of trolls and skeletons! Where?! Let’s go burn ’em all!"
        [/message]
        [message]
            speaker=unit
            message= _ "Er... ok..." # wmllint: no spellcheck
        [/message]
        [message]
            speaker=unit
            message={WHISPER _"whisper^Is it safe to have this lunatic with us?"}
        [/message]
        {VARIABLE found_Camerin 1}
        # The following two events are absolutely useless if Camerin
        # was not found so we'll set them only when this happens using
        # event nesting.

        # Flavour event on Camerins first attack
        [event]
            name=attack
            [filter]
                id=Camerin
            [/filter]

            [message]
                speaker=Camerin
                message= _ "<i>Burn, you disgusting filth!</i>"
            [/message]
            [message]
                speaker=second_unit
                message= _ "Ahhh! Fire!"
            [/message]
        [/event]

        # And flavour event on his first kill
        [event]
            name=die
            [filter_second]
                id=Camerin
            [/filter_second]

            [message]
                speaker=Camerin
                message= _ "<i>Yeah! Die, scum, die!</i>"
            [/message]
        [/event]
    [/event]

    # Information for the player that he can't proceed without either
    # finding the dwarves or killing the enemies.
    [event]
        name=moveto
        [filter]
            side=1
            x=40
            y=12-15
        [/filter]

        [message]
            speaker=unit
            message= _ "This tunnel keeps on going..."
        [/message]
        [message]
            speaker=Tallin
            message= _ "I think we should finish searching this part of Knalga first before we go deeper into the caves."
        [/message]
    [/event]

    # Flavour event on first sighting of the undead
    [event]
        name=sighted,moveto
        [filter]
            race=undead
            [filter_vision]
                viewing_side=1
            [/filter_vision]
        [/filter]

        [message]
            role=Supporter
            message= _ "Grim Gods of Darkness, what are those things!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Skeletons!"
        [/message]
        [message]
            role=Supporter
            message= _ "Look at the axes they bear. At one time those skeletons must have been dwarves!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Stand firm, men. The dwarven defenders of Knalga rise again. Now it remains to be seen whether or not they recognize us as friends."
        [/message]
    [/event]

    # Flavour event for the first time they attack
    [event]
        name=attack
        [filter]
            race=undead
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            role=Supporter
            message= _ "They are attacking us!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Destroy them!"
        [/message]
    [/event]

    # Opening a pair of hidden doors - the north one
    [event]
        name=moveto
        [filter]
            side=1
            x=12,14
            y=4,5
        [/filter]

        # Check from which side do we open and use apropriate race in the dialogue.
        [if]
            [variable]
                name=unit.y
                equals=4
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "Hey look, it’s an ancient door. It seems the trolls were too stupid to find how to open it."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Hey look, it’s an ancient door. It seems the skeletons were too stupid to find how to open it."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Tallin
            message= _ "Well, let’s see what’s behind it."
        [/message]
        [message]
            speaker=unit
            message= _ "All right. (<i>Grunt... strain...</i>) It’s not moving. It seems to be stuck."
        [/message]
        [message]
            speaker=Tallin
            message= _ "Well, just kick it down then."
        [/message]
        [message]
            speaker=unit
            message= _ "... Right."
        [/message]
        [message]
            speaker=unit
            message= _ "(<i>Smash</i>)"
        [/message]
        [terrain]
            x=13
            y=5
            terrain=Uu
        [/terrain]
    [/event]

    # And the south ones
    [event]
        name=moveto
        [filter]
            side=1
            x=6,8
            y=27,28
        [/filter]

        [if]
            [variable]
                name=unit.y
                equals=4
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message= _ "Hey look, it’s an ancient door. It seems the trolls were too stupid to find how to open it."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Hey look, it’s an ancient door. It seems the skeletons were too stupid to find how to open it."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Tallin
            message= _ "Well, let’s see what’s behind it."
        [/message]
        [message]
            speaker=unit
            message= _ "All right. (<i>Grunt... strain...</i>) It’s not moving. It seems to be stuck."
        [/message]
        [message]
            speaker=Tallin
            message= _ "Well, just kick it down then."
        [/message]
        [message]
            speaker=unit
            message= _ "... Right."
        [/message]
        [message]
            speaker=unit
            message= _ "(<i>Smash</i>)"
        [/message]
        [terrain]
            x=7
            y=28
            terrain=Uu
        [/terrain]
    [/event]

    # Dwarven mushroom fields
    [event]
        name=moveto
        [filter]
            side=1
            x=22-26
            y=21-25
        [/filter]

        [message]
            speaker=unit
            message= _ "Wow, this place is interesting."
        [/message]
        [message]
            speaker=Hamel
            message= _ "This is how we get our food, me lad. Since we are a tad close to the surface here, some sunlight shines down through the cracks in the roof. If we baby the plants, we can usually get enough. They taste unco’ foul but that’s how we ha’ survived all these long years."
        [/message]
    [/event]

    # We're doomed (tm) routine on turn 9
    [event]
        name=turn 9

        # We call this macro again  in case the previous supporter got
        # killed in the meantime

        [message]
            role=Supporter
            message= _ "Tallin, this situation is hopeless — there are endless monsters swarming from all directions!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "We are in a dire situation indeed — but just see — the trolls and the skeletons are also attacking each other. We must all stay together in one group; let each man support the man next to him. If our ranks are imposing enough the monsters may shy away from us in favor of easier prey."
        [/message]
        [message]
            role=Supporter
            message= _ "But still, Tallin, we will take losses, and for each one of us, there is no replacement — whereas for every monster we kill, it seems that two more come to take its place!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Which is why we must make haste to find the dwarves. Dwarves are hardy creatures and they know their caves backwards and forwards — so I am sure at least some must have survived! Indeed, this is our only hope for otherwise, be it on the surface or be it down here, any way we turn we face certain destruction!"
        [/message]
    [/event]

    # Meeting the dwarves, set new objectives
    [event]
        name=sighted,moveto
        [filter]
            side=4
            [filter_vision]
                viewing_side=1
            [/filter_vision]
        [/filter]

        [message]
            speaker=unit
            message= _ "Stand where ye be, you... Och! A human!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "Greetings from the people of Dwarven Doors, friend."
        [/message]
        [message]
            speaker=unit
            message= _ "Dwarven Doors? I thought ye surface humans had been enslaved or slain by the orcs years ago."
        [/message]
        [message]
            speaker=Tallin
            message= _ "Yes, we were enslaved, but we rose against Al’Tar and defeated his warband. In order to stay free, we seek help and equipment from our old allies, the dwarves."
        [/message]
        [message]
            speaker=unit
            message= _ "Och, the dwarves of Knalga are themselves in desperate straits — but we havena’ forgotten the old bonds. Be welcome to our keep. Aye, and have speech with our chieftain, the Lord Hamel."
        [/message]
        [message]
            speaker=Tallin
            message= _ "Very well."
        [/message]
        {VARIABLE found_dwarves 1}
        [objectives]
            side=1
            [objective]
                description= _ "Move Tallin to a Dwarvish castle keep or..."
                condition=win
            [/objective]
            [objective]
                description= _ "Clear the caves (Bonus)"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Tallin"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Hamel"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                carryover_percentage=80
            [/gold_carryover]
        [/objectives]
    [/event]

    # Arriving at the keep, end scenario without bonus.
    [event]
        name=moveto
        [filter]
            id=Tallin
            x=33,33,34,34,35,35,35,36,36,37,37,31,32,32
            y=20,21,20,21,21,22,23,22,23,23,24,23,22,23
        [/filter]
        [message]
            speaker=Hamel
            message= _ "Well met, Tallin. My men have told me of your victory against Al’Tar."
        [/message]
        [message]
            speaker=Tallin
            message= _ "Thank you and well-met indeed, Lord Hamel."
        [/message]
        [message]
            role=Supporter
            message= _ "Whew, we did it!"
        [/message]
        [message]
            speaker=Camerin
            message= _ "Awww! Are we done already?"
        [/message]
        [endlevel]
            result=victory
            bonus=no
        [/endlevel]
    [/event]

    # All enemies defeated, choose apropriate dialogue depending on wether the dwarves were found or not.
    [event]
        name=enemies defeated

        [if]
            [variable]
                name=found_dwarves
                numerical_equals=1
            [/variable]
            [then]
                [message]
                    speaker=Tallin
                    message= _ "Good, we managed to clear the caves... for now, anyway. Now let’s get to the dwarven keep and dicker for better weapons."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Tallin
                    message= _ "Good, there are no more monsters lurking in these parts of the tunnels. I think I can hear the clamor of dwarves just ahead. Come on men, let’s go meet them."
                [/message]
            [/else]
        [/if]
    [/event]

    {campaigns/Northern_Rebirth/utils/herodeaths.cfg}

    # Hamel got killed, the scenario is lost.
    [event]
        name=die
        [filter]
            id=Hamel
        [/filter]

        {INCIDENTAL_MUSIC "sad.ogg"}
        [role]
            type=Master Bowman,Royal Guard,Halberdier,Swordsman,Pikeman,Longbowman,Javelineer,Trapper,Bandit,Highwayman,Thug,Poacher,Spearman,Bowman,Peasant
            role=Messenger
        [/role]
        [message]
            role=Messenger
            message= _ "Tallin, we have just received the news that the dwarvish Lord Hamel has just been slain. We are too late!"
        [/message]
        [message]
            speaker=Tallin
            message= _ "No! Without the dwarvish weapons we have no hope!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # If we won and Camerin wasn't found add him to the players army. Clear variables.
    [event]
        name=victory

        [if]
            [variable]
                name=found_Camerin
                numerical_equals=0
            [/variable]
            [then]
                [move_unit_fake]
                    type=Arch Mage
                    side=1
                    x=1,2,3,4,4,3,3,3,3,3,3,3,4,5,6
                    y=1,1,2,2,3,4,5,6,7,8,9,10,10,11,11
                [/move_unit_fake]
                [unit]
                    type=Arch Mage
                    id=Camerin
                    name= _ "Camerin"
                    profile=portraits/Camerin.png
                    side=1
                    x=6
                    y=11
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_STRONG}
                    [/modifications]
                    {IS_LOYAL}
                [/unit]
                [message]
                    speaker=Camerin
                    message= _ "Hey, what’s going on in here?"
                [/message]
                # Try to choose as Admirer, in order:
                # (1) A Thug or Bandit on side 1
                # (2) Otherwise, any unit other than Tallin, Camerin and Supporter on side 1
                # (3) If all else fails, Tallin
                [role]
                    type=Thug,Bandit
                    role=Admirer
                [/role]
                [if]
                    [not]
                        [have_unit]
                            role=Admirer
                        [/have_unit]
                    [/not]
                    [then]
                        [role]
                            [not]
                                id=Tallin
                            [/not]
                            [not]
                                # unit can have only one role
                                role=Supporter
                            [/not]
                            [not]
                                id=Camerin
                            [/not]
                            side=1
                            role=Admirer
                        [/role]
                    [/then]
                [/if]
                [if]
                    [not]
                        [have_unit]
                            role=Admirer
                        [/have_unit]
                    [/not]
                    [then]
                        # Supporter and Camerin shouldn’t get Admirer role
                        [role]
                            id=Tallin
                            role=Admirer
                        [/role]
                    [/then]
                [/if]
                [message]
                    role=Admirer
                    message= _ "We are killing lots of trolls and skeletons."
                [/message]
                [message]
                    speaker=Camerin
                    message= _ "Really! Did you save any for me?"
                [/message]
                [message]
                    role=Admirer
                    message= _ "Uh, not really..."
                [/message]
                [message]
                    speaker=Camerin
                    message= _ "Awww!"
                [/message]
                [message]
                    role=Admirer
                    message= _ "But hey, if you want to join us, I am sure we will be fighting a lot more orcs, trolls and skeletons in the near future."
                [/message]
                [message]
                    speaker=Camerin
                    message= _ "Really! Oh yeah, I am in!"
                [/message]
                [message]
                    speaker=Tallin
                    message= _ "... That was rather odd. Who is this guy?"
                [/message]
                [if]
                    [variable]
                        name=found_dwarves
                        numerical_equals=1
                    [/variable]
                    [then]
                        [message]
                            speaker=Hamel
                            message= _ "Oh, dinna’ mind him, that’d be Camerin. He used to be yer usual scholarly mage, and he moved awa’ up here to be alone and study. But then when the orcs invaded he went a little loony. My guess is that some roving orcs ransacked his place and burnt his notes or something. Whatever it was, he couldna’ take it and became fey. Ever since he has been roving these caves destroying any manner of monster that he comes across. They all give him a very wide berth by now. So just be polite, give him some room and you’ll find he is relatively harmless..."
                        [/message]
                    [/then]
                [/if]
            [/then]
        [/if]
        {CLEAR_VARIABLE found_Camerin}
        {CLEAR_VARIABLE found_dwarves}
    [/event]
[/scenario]
