#textdomain wesnoth-sof
[scenario]
    name= _ "Towards the Caves"
    id=6_Towards_the_Caves
    {TURNS 18 16 14}
    map_file=6_Towards_the_Caves.map
    next_scenario=7_Outriding_the_Outriders

    {SCENARIO_MUSIC breaking_the_chains.ogg}

    {DEFAULT_SCHEDULE}

    [side]
        type=Dwarvish Fighter
        id=Rugnur
        side=1
        canrecruit=yes
        controller=human
        recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Dwarvish Scout,Gryphon Rider
        {GOLD 260 220 180}
        team_name=dwarves
        user_team_name= _ "Dwarves"
        {FLAG_VARIANT knalgan}
        defeat_condition=no_units_left
    [/side]

    # Rugnur starts with all villages within the captured Shorbear keep.
    # Elves will start munching on them fairly soon.
    {STARTING_VILLAGES 1 6}

    [side]
        type=Elvish Marshal
        id=Glildur
        name= _ "Glildur"
        side=2
        {SOF_GLILDUR_PORTRAIT}
        facing=sw
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_INTELLIGENT}
            [object]
                silent=yes
                [effect]
                    apply_to=image_mod
                    add=CS(-10,-25,+5)
                [/effect]
            [/object]
        [/modifications]
        canrecruit=yes
        recruit=Elvish Rider,Elvish Hero,Elvish Marksman,Elvish Ranger,Elvish Druid
        {GOLD 200 250 300}
        {INCOME 6 9 12}
        team_name=elves
        user_team_name= _ "Elves"
        [ai]
            [goal]
                name=protect_location
                [criteria]
                    x,y=36,3
                [/criteria]
                value=100
                protect_radius=10
            [/goal]
            [goal]
                name=target
                [criteria]
                    type=Gryphon,Gryphon Rider,Gryphon Master
                [/criteria]
                value=10
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Alanin
                [/criteria]
                value=2
            [/goal]
            [goal]
                name=target
                [criteria]
                    race=dwarf
                [/criteria]
                value=1
            [/goal]
        [/ai]
        {FLAG_VARIANT wood-elvish}
    [/side]

    {STARTING_VILLAGES 2 {ON_DIFFICULTY 8 10 12}}

    [side]
        type=Elvish Marshal
        id=Glinan
        name= _ "Glinan"
        side=3
        canrecruit=yes
        recruit=Elvish Rider,Elvish Hero,Elvish Marksman,Elvish Ranger,Elvish Druid

        {GOLD 140 180 220}
        {INCOME 6 8 10}
        team_name=elves
        user_team_name= _ "Elves"
        [ai]
            [goal]
                name=protect_location
                [criteria]
                    x,y=36,3
                [/criteria]
                {QUANTITY value 60 80 100}
                {QUANTITY protect_radius 8 9 10}
            [/goal]
            [goal]
                name=target
                [criteria]
                    race=dwarf
                [/criteria]
                {QUANTITY value 8 9 10}
            [/goal]
            [avoid]
                x=1-18
                y=1-38
            [/avoid]
        [/ai]
        {FLAG_VARIANT wood-elvish}
    [/side]

    {STARTING_VILLAGES 3 {ON_DIFFICULTY 6 7 8}}
    {STARTING_VILLAGES_AREA 3 34 10 {ON_DIFFICULTY 6 7 8}}

    [side]
        type=Elvish Captain
        id=Kalnar
        name= _ "Kalnar"
        side=4
        canrecruit=yes
        recruit=Elvish Scout,Elvish Fighter,Elvish Archer,Elvish Shaman
        {GOLD 80 100 120}
        {INCOME 4 5 6}
        team_name=elves
        user_team_name= _ "Elves"
        [ai]
            [goal]
                name=target
                [criteria]
                    id=Alanin
                [/criteria]
                {QUANTITY value 6 8 10}
            [/goal]
            [goal]
                name=target
                [criteria]
                    race=dwarf
                [/criteria]
                value=1
            [/goal]
        [/ai]
        {FLAG_VARIANT wood-elvish}
    [/side]

    {STARTING_VILLAGES 4 {ON_DIFFICULTY 9 10 11}}

    [story]
        [part]
            story= _ "Durstorn’s rash action led to many problems. Not the least of which was being surrounded by elves."
        [/part]
        [part]
            story= _ "The dwarves were besieged by the elves for several months, as there was no way out of the caverns other than above ground. But the elves could not enter the Shorbear hold, for the sturdy dwarven gates were closed."
        [/part]
        [part]
            story= _ "During this time, Thursagan crafted the Sceptre of Fire, cutting the ruby himself with the Shorbear tools. Eventually, the sceptre was crafted, but something was not right no matter what enchantment of runes Thursagan used. To finish the sceptre, the dwarves needed to leave the cave."
        [/part]
    [/story]

    {SOF_TRACK {JOURNEY_06_NEW} }

    {SOF_DEATHS}

    {SOF_RUNIC_EVENTS}

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description= _ "Move Rugnur to the northeast cave entrance"
                condition=win
                [show_if]
                    [have_unit]
                        id=Rugnur
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Move Alanin to the southern border east of the river"
                condition=win
                [show_if]
                    [have_unit]
                        id=Alanin
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Rugnur"
                condition=lose
                [show_if]
                    [have_unit]
                        id=Rugnur
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Alanin"
                condition=lose
                [show_if]
                    [have_unit]
                        id=Alanin
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Krawg"
                condition=lose
                [show_if]
                    [have_unit]
                        # wmllint: recognize Krawg
                        id=Krawg
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Thursagan"
                condition=lose
                [show_if]
                    [have_unit]
                        # wmllint: recognize Thursagan
                        id=Thursagan
                    [/have_unit]
                [/show_if]
            [/objective]

            {RUNE_MECHANIC_NOTE}

            {TURNS_RUN_OUT}

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

        {LOYAL_UNIT 2 "Elvish Ranger" 5 25} {GUARDIAN}
        {LOYAL_UNIT 3 "Elvish Hero" 5 7} {GUARDIAN}
        {LOYAL_UNIT 3 "Elvish Ranger" 11 5} {GUARDIAN}
        {LOYAL_UNIT 3 "Elvish Hero" 19 6} {GUARDIAN}
        {LOYAL_UNIT 3 "Elvish Captain" 24 6} {GUARDIAN}
        {LOYAL_UNIT 4 "Elvish Fighter" 31 27} {GUARDIAN}
        {LOYAL_UNIT 4 "Elvish Archer" 27 30} {GUARDIAN}
    [/event]

    [event]
        name=start
        #alanin, baglur, krawg and thursagan
        [recall]
            id=Thursagan
            x,y=18,16
        [/recall]
        [recall]
            id=Durstorn
            x,y=19,16
        [/recall]
        [recall]
            id=Alanin
        [/recall]
        [recall]
            id=Baglur
        [/recall]
        [recall]
            id=Krawg
        [/recall]

        {MODIFY_UNIT id=Alanin profile "portraits/alanin-older.webp~BLIT(portraits/alanin-winter-overlay.webp,0,0)"}

        #dialogue starts
        [message]
            speaker=Rugnur
            message= _ "Well, Thursagan has reached a conclusion. He can’t finish the sceptre with the materials he has here, but he has the final plans for it, and all the jewels and gold he needs. Shouldn’t we leave now?"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "All this time and he couldn’t make it? Fine, we should try to leave... but it’s not like we could leave if we wanted to. We’re surrounded!"
        [/message]
        [if]
            [have_unit]
                id=Baglur
            [/have_unit]
            [then]
                [message]
                    speaker=Baglur
                    message= _ "If ye’ll permit me to say so, sir, ye’re wrong. We could—"
                [/message]
                [message]
                    speaker=Durstorn
                    message= _ "Shut up, Baglur! You don’t know what you’re talking about. I’ve analyzed the situation, and we’re doomed. Our best hope is to surrender. Perhaps if we give the elves the plans for the Sceptre of Fire they will let us survive."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Rugnur
                    message= _ "If you’ll permit me to say so, sir, you’re wrong. We could —"
                [/message]
                [message]
                    speaker=Durstorn
                    message= _ "Shut up, Rugnur! You don’t know what you’re talking about. I’ve analyzed the situation, and we’re doomed. Our best hope is to surrender. Perhaps if we give the elves the plans for the Sceptre of Fire they will let us survive."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Rugnur
            message= _ "What happened to your honor, Durstorn?!"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "You little fool, honor is less important than life! Open the gates, I’m going out to negotiate our safe passage out of here!"
        [/message]
        [terrain]
            [and]
                terrain=*^Pr\
            [/and]
            terrain=Uu^Pr\o
            layer=overlay
            replace_if_failed=yes
        [/terrain]
        [terrain]
            [and]
                terrain=*^Pr/
            [/and]
            terrain=Uu^Pr/o
            layer=overlay
            replace_if_failed=yes
        [/terrain]
        [message]
            speaker=Thursagan
            message= _ "You have no right to offer the Sceptre to the elves, Durstorn, it’s not yours to give!"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "I can’t believe what I’m hearing, do all of you want to die? Enough talk!"
        [/message]
        {MOVE_UNIT (id=Durstorn) 15 22}
        [message]
            speaker=Durstorn
            message= _ "You insolent fools can thank me later, I might not banish you once we are back home."
        [/message]
        {MOVE_UNIT (id=Durstorn) 6 25}
        [message]
            speaker=Durstorn
            message= _ "Elf leader, I have an offer for you. You want the Ruby, yes?"
        [/message]
        [message]
            speaker=Glildur
            message= _ "My, you’re a bold little dwarf! You’ve brought me the Ruby?"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "I can get you the ruby, and much more treasure, if you allow my group safe passage."
        [/message]
        [message]
            speaker=Glildur
            message= _ "I see... well, we will not be fooled by your haggling and false promises. You were very foolish to come out here alone."
        [/message]
        {REPLACE_SCENARIO_MUSIC frantic.ogg}
        {MOVE_UNIT (id=Glildur) 7 26}
        [animate_unit]
            flag=attack

            [filter]
                id=Glildur
            [/filter]

            [primary_attack]
                name=bow
            [/primary_attack]

            hits=yes

            [facing]
                [filter]
                    id=Durstorn
                [/filter]
            [/facing]

            [animate]
                flag=defend

                [filter]
                    id=Durstorn
                [/filter]

                hits=yes
                text= _ "<i>Thud!</i>"
                red=255
                green=0
                blue=0

                [facing]
                    [filter]
                        id=Glildur
                    [/filter]
                [/facing]
            [/animate]
        [/animate_unit]
        [kill]
            id=Durstorn
            animate=yes
        [/kill]

        {APPEND_MUSIC           the_king_is_dead.ogg}
        {APPEND_MUSIC           casualties_of_war.ogg}
        {APPEND_MUSIC           battle.ogg}

        [message]
            speaker=Rugnur
            message= _ "Well, I suppose he should have expected that, but I don’t like this. In any case, now we should try to get out of here."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Yes. See the area to the northeast of us?"
        [/message]
        [scroll_to]
            x,y=36,3
        [/scroll_to]
        [delay]
            time=400
        [/delay]
        [item]
            image=items/gohere.png
            x,y=36,3
        [/item]
        [delay]
            time=600
        [/delay]
        [message]
            speaker=Thursagan
            message= _ "That’s where the fewest elvish guards are, we just might make it back underground before they block us completely."
        [/message]
        [message]
            speaker=Alanin
            message= _ "This plan, it isn’t worse than staying here to be killed, but it isn’t likely to succeed either. Even if it does, what will it accomplish? We will be cornered there."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "I don’t know if we will be cornered. That cave looks like it goes deep, and we can lose the elves in the caves, they move so slow there. Once we get out, we’ll make our way back to Knalga."
        [/message]
        [message]
            speaker=Rugnur
            message= _"The country between here and Knalga will be swarming with elves. We had better head back to the abandoned mines north of the Arkan-thoria, where we gathered our gold and coal. At least there Alanin will have some hope of finding us."
        [/message]
        [message]
            speaker=Alanin
            message= _ "That’s fine for you, you can run fast in caves, but I can’t! What am I supposed to do?"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "Well, you are a member of the Wesnothian army. Why don’t you rejoin it? See if you can run past those elves to our southeast..."
        [/message]
        [scroll_to]
            x,y=31,37
        [/scroll_to]
        [delay]
            time=400
        [/delay]
        [item]
            image=items/gohere.png
            x,y=30,38
        [/item]
        [delay]
            time=600
        [/delay]
        [message]
            speaker=Rugnur
            message= _ "... and then ride south until you reach one of your outposts."
        [/message]
        [message]
            speaker=Alanin
            message= _ "I’m not going to do that, it’s suicide! And in any case, I’ve been with you for ten years, almost as long as I was in the Wesnothian army; I’d prefer to fight with you."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "You going south has more of a chance of success for you than staying here or going back to the mines! And getting news to Haldric of what has happened is also the best way to get help to us."
        [/message]
#ifdef EASY
        [message]
            speaker=Thursagan
            message= _ "Here, if you are still having doubts, let me inscribe this rune for you to help you slip past their defenses."
        [/message]
        [modify_unit]
            [filter]
                id=Alanin
            [/filter]
            [object]
                silent=yes
                duration=forever
                # (originally I gave him an additional movement point here, too,
                # but that causes his dialogue in the beginning of the next scenario
                # "Outriding the Outriders" to be false, so I am removing that now.)
                [effect]
                    apply_to=new_ability
                    [abilities]
                        {ABILITY_CONCEALMENT}
                        {ABILITY_SKIRMISHER}
                    [/abilities]
                [/effect]
            [/object]
        [/modify_unit]
        [sound]
            name=mace.wav
        [/sound]
        [heal_unit]
            [filter]
                id=Alanin
            [/filter]
            moves=full
            restore_attacks=yes
        [/heal_unit]
        [message]
            speaker=Alanin
            message= _ "Thanks!"
        [/message]
        [message]
            speaker=narrator
            message= _ "Alanin has gained new abilities!"
        [/message]
#endif
        [message]
            speaker=Alanin
            message= _ "I suppose..."
        [/message]
        {MODIFY_UNIT (id=Glildur) facing ne}
        [message]
            speaker=Glildur
            message= _ "Come out, dwarves, let’s get this over with!"
        [/message]
    [/event]

    [event]
        name=turn 6
        [gold]
            side=2
            {QUANTITY amount 80 120 160}
        [/gold]
        [gold]
            side=3
            {QUANTITY amount 80 120 160}
        [/gold]
        [gold]
            side=4
            {QUANTITY amount 80 120 160}
        [/gold]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Alanin
            x=22-40
            y=38
        [/filter]
        [if]
            [have_unit]
                id=Rugnur
            [/have_unit]
            [then]
                [message]
                    speaker=Rugnur
                    message= _ "Alanin, ride south as fast as you can. Tell Haldric we are heading northeast, towards the old eastern mines. And if he wants his precious sceptre, he should send forces to meet us there as soon as he can!"
                [/message]
                [store_unit]
                    [filter]
                        id=Alanin
                    [/filter]
                    variable=alanin
                    kill=yes
                [/store_unit]
                [show_objectives]
                [/show_objectives]
            [/then]
            [else]
                [message]
                    speaker=Alanin
                    message= _ "I have made it past these elves, but they will chase me, and elvish horses are faster than mine."
                [/message]
                [store_unit]
                    [filter]
                        id=Alanin
                    [/filter]
                    variable=alanin
                    kill=yes
                [/store_unit]
                [endlevel]
                    result=victory
                    bonus=no
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/else]
        [/if]
    [/event]

    [event]
        name=enter_hex
        [filter]
            id=Rugnur
            x,y=36,3
        [/filter]

        # we cannot just put this in the victory event because units are stored and rune variables are not cleared
        {SOF_CLEAR_RUNE_VARS 1}

        [if]
            [have_unit]
                id=Alanin
            [/have_unit]
            [then]
                [message]
                    speaker=Alanin
                    message= _ "Rugnur, I am going south. What should I tell Haldric?"
                [/message]
                [message]
                    speaker=Rugnur
                    message= _ "Tell him to send forces north to aid us and fight the elves, but that we are probably going to die. We will run northeast towards the old eastern mines. And if he wants his sceptre intact, he’d best send troops to meet us there."
                [/message]
                [store_unit]
                    [filter]
                        side=1

                        [not]
                            id=Alanin
                        [/not]
                    [/filter]
                    variable=dwarves
                    kill=yes
                [/store_unit]
                # for purely flavor reasons
                [disallow_recruit]
                    side=1
                [/disallow_recruit]
                [show_objectives]
                [/show_objectives]
            [/then]
            [else]
                [message]
                    speaker=Rugnur
                    message= _ "I don’t know what is in these caves, but whatever it is can’t be worse than staying here to die."
                [/message]
                [store_unit]
                    [filter]
                        side=1

                        [not]
                            id=Alanin
                        [/not]
                    [/filter]
                    variable=dwarves
                    kill=yes
                [/store_unit]
                [endlevel]
                    result=victory
                    bonus=no
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/else]
        [/if]
    [/event]

    [event]
        name=enemies defeated

        {SOF_CLEAR_RUNE_VARS 1}

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

    [event]
        name=victory

        # This [if] is used only in the case the player happened to defeat all
        # the enemy leaders and didn't move Alanin to the signpost
        [if]
            [have_unit]
                id=Alanin
            [/have_unit]

            [then]
                [store_unit]
                    [filter]
                        id=Alanin
                    [/filter]
                    variable=alanin
                    kill=yes
                [/store_unit]
            [/then]
        [/if]

        # This [if] is used only in the case the player happened to defeat all
        # the enemy leaders and didn't move Rugnur to the caves
        [if]
            [have_unit]
                id=Rugnur
            [/have_unit]

            [then]
                [store_unit]
                    [filter]
                        side=1

                        [not]
                            id=Alanin
                        [/not]
                    [/filter]
                    variable=dwarves
                    kill=yes
                [/store_unit]
            [/then]
        [/if]

        [store_side]
            side=1
            variable=stored_Rugnur_side
        [/store_side]
    [/event]
[/scenario]
