#textdomain wesnoth-sof
[scenario]
    name= _ "Hills of the Shorbear Clan"
    id=5_Hills_of_the_Shorbear_Clan
    turns=24
    map_file=5_Hills_of_the_Shorbear_Clan.map
    next_scenario=6_Towards_the_Caves

    # the music will change in the end of the opening dialogue
    {SCENARIO_MUSIC knolls.ogg}

    {DEFAULT_SCHEDULE}

    [side]
        type=Dwarvish Fighter
        id=Rugnur
        side=1
        canrecruit=yes
        controller=human
        recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Dwarvish Scout
        {GOLD 240 200 160}
        team_name=dwarves
        user_team_name= _ "Dwarves"
        [village]
            x,y=5,2
        [/village]
        [village]
            x,y=10,1
        [/village]
        {FLAG_VARIANT knalgan}
    [/side]

    [side]
        type=Dwarvish Lord
        id=Glonoin
        name= _ "Glonoin"
        side=2
        canrecruit=yes
        {RECRUIT (Dwarvish Fighter,Dwarvish Steelclad,Dwarvish Thunderer,Dwarvish Guardsman) (Dwarvish Steelclad,Dwarvish Thunderguard,Dwarvish Thunderer,Dwarvish Guardsman) (Dwarvish Steelclad,Dwarvish Thunderguard,Dwarvish Thunderer,Dwarvish Stalwart,Dwarvish Pathfinder,Dwarvish Scout)}
        {GOLD 250 300 350}
        [ai]
            recruitment_pattern=fighter,fighter,fighter,mixed fighter
            aggression=-0.5
            caution=0.5
            village_value=0.1
            leader_value=0
            villages_per_scout=0
            grouping=defensive
            [goal]
                name=protect_unit
                [criteria]
                    side=2
                    canrecruit=yes
                [/criteria]
                protect_radius=4
                value=2
            [/goal]
        [/ai]
        team_name=enemies
        user_team_name= _ "Enemies"
        {FLAG_VARIANT knalgan}
    [/side]

    {STARTING_VILLAGES 2 6}

    # Rugnur's elven nemesis
    [side]
        type=Elvish Marshal
        id=Glildur
        name= _ "Glildur"
        canrecruit=yes
        side=3
        persistent=yes
        save_id=Glildur
        {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]
        {RECRUIT (Elvish Ranger,Elvish Scout,Elvish Hero) (Elvish Ranger,Elvish Marksman,Elvish Scout,Elvish Hero) (Elvish Ranger,Elvish Marksman,Elvish Scout,Elvish Hero)}
        {GOLD 210 240 270}
        [ai]
            recruitment_pattern=scout,scout,fighter,archer
            turns=1-6
            aggression=1.0
            caution=0.1
            village_value=2
            leader_value=1
            grouping=no
            [goal]
                name=protect_unit
                [criteria]
                    side=3
                    canrecruit=yes
                [/criteria]
                value=0.5
            [/goal]
        [/ai]
        [ai]
            recruitment_pattern=fighter,fighter,archer
            turns=6-20
            aggression=0.5
            caution=0.2
            village_value=2
            grouping=offensive
            [goal]
                name=protect_unit
                [criteria]
                    side=3
                    canrecruit=yes
                [/criteria]
                value=1
            [/goal]
        [/ai]
        [ai]
            recruitment_pattern=fighter,fighter,archer,scout
            turns=20-24
            aggression=1.0
            caution=0
            village_value=0
            leader_value=10
            grouping=no
            [goal]
                name=protect_unit
                [criteria]
                    side=3
                    canrecruit=yes
                [/criteria]
                value=0
            [/goal]
        [/ai]
        team_name=enemies
        user_team_name= _ "Enemies"
        {FLAG_VARIANT wood-elvish}
    [/side]

    [story]
        [part]
            story= _ "All dwarves are known for a love of gold and a heart of stone, and the Shorbears were no exception. They were very skilled crafters for a very select clientele, and were compensated quite handsomely. They were not exactly meek or humble..."
        [/part]
    [/story]

    {SOF_TRACK {JOURNEY_05_NEW} }

    {SOF_DEATHS}

    [label]
        x,y=19,17
        text= _ "Shorbear caves"
    [/label]

    {SOF_RUNIC_EVENTS}

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat Glonoin, the Shorbear clan leader"
                condition=win
                [show_if]
                    [have_unit]
                        id=Glonoin
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Have all heroes, and no enemies, in the Shorbear caves"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL elves_come boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Rugnur"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Alanin"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Krawg"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Thursagan"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Durstorn"
                condition=lose
            [/objective]

            {RUNE_MECHANIC_NOTE}

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=no
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
        [store_unit]
            [filter]
                id=Glildur
            [/filter]
            variable=glildur
            kill=yes
        [/store_unit]
    [/event]

    # wmllint: directory spelling Shorbear Shorbears
    [event]
        name=start
        #durstorn, noiraran and kuhnar
        [unit]
            x,y=11,1
            type=Dwarvish Lord
            id=Durstorn
            name= _ "Durstorn"
            unrenamable=yes
            side=1
            profile=portraits/durstorn.webp
            random_traits=no
            [modifications]
                {TRAIT_LOYAL_HERO}
            [/modifications]
        [/unit]
        [unit]
            x,y=11,1
            type=Dwarvish Thunderguard
            id=Noiraran
            name= _ "Noiraran"
            side=1
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
        [unit]
            x,y=11,1
            type=Dwarvish Steelclad
            id=Kuhnar
            name= _ "Kuhnar"
            side=1
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
        #alanin, baglur, krawg and thursagan
        [recall]
            id=Alanin
        [/recall]
        [recall]
            id=Baglur
        [/recall]
        [recall]
            id=Krawg
        [/recall]
        [recall]
            id=Thursagan
        [/recall]

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

        #dialogue starts
        [message]
            speaker=Kuhnar
            message= _ "Here we are! The hills of the Shorbear clan!"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "We’re here to bargain with the Shorbears for their tools, who should take lead?"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "I could-"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "<i>I’ll</i> be doing the talking! I remember what happened last time you negotiated a deal, Rugnur! We lost five thousand pieces of silver!"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Och, it’s some o’ them cave-dwarves. What business do you have here?"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "I’m Lord Durstorn, ruler of the Chaincolt Range. I have been told you are great jewel-workers, and so we come to rent some of your tools for a short time, a few years at most."
        [/message]
        [message]
            speaker=Glonoin
            message= _ "You’re a <i>lord</i>?! Must be a pretty small clan for you to come yourself to bargain with us!"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "You insult me! Do you want my business, or not?"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Well, fine, I’ll hear your offer."
        [/message]
        [message]
            speaker=Durstorn
            message= _ "We’d like to rent your best tools for a short period of time. We’ll only be cutting one jewel with it. My starting offer is two hundred silver."
        [/message]
        [message]
            speaker=Glonoin
            message= _ "It must be worth a lot for you to come this way and offer that much! How much are you going to sell it for, eh?"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "That’s none of your concern!"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "I’ll take twenty-five hundred, minimum."
        [/message]
        [message]
            speaker=Rugnur
            message={WHISPER _"Durstorn, that would be a quarter of all our profits!"}
        [/message]
        [message]
            speaker=Durstorn
            message= _ "I know that. Uh, Glonoin, how about five hundred?"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Twenty-three hundred is my lowest offer. I can tell I don’t need the money as much as you need the jewel cut!"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "You must be mad! I’ll offer one thousand, but no higher!"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Two thousand, and I’ll go no lower!"
        [/message]
        [message]
            speaker=Rugnur
            message={WHISPER _"What are we going to do? We can’t go much higher!"}
        [/message]
        [message]
            speaker=Baglur
            message= {WHISPER _"Offer him fifteen hundred, but don’t go up, even if he refuses."}
        [/message]
        [message]
            speaker=Durstorn
            message= {WHISPER _"Bah! Getting this cut isn’t worth that much — what with Rugnur’s mistake earlier, and all the other expenses. If we pay more than a thousand, we’ll barely even make a profit!"}
        [/message]
        [message]
            speaker=Thursagan
            message= {WHISPER _"So what are you going to do?"}
        [/message]
        [message]
            speaker=Durstorn
            message= {WHISPER _"Fight him, and take the tools by force."}
        [/message]
        [message]
            speaker=Thursagan
            message= {WHISPER _"Are you mad?!"}
        [/message]
        # this is causing errors, so doing it the hard way for now but this could be fixed
        #        [modify_unit]
        #            [filter]
        #                id=Durstorn
        #            [/filter]
        #            profile=portraits/durstorn-insane.webp
        #        [/modify_unit]
        [message]
            speaker=Durstorn
            message= _ "Of course not!"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "Glonoin, yah scoundrel! One thousand was my final offer, and if you won’t accept that, we will take the tools from you by force!"
            image=portraits/durstorn-insane.webp
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Hah! I’d like to see you try!"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "You’re making a mistake, Durstorn."
        [/message]

        [music]
            name=the_city_falls.ogg
            immediate=yes
            append=no
        [/music]
        [music]
            name=battle.ogg
            append=yes
        [/music]

        [message]
            speaker=Durstorn
            message= _ "Shut up, all of you! Attack them!"
            image=portraits/durstorn-insane.webp
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Krawg
        [/filter]
        [message]
            speaker=Rugnur
            # po: he’s a gryphon, "flying" is used in the literal rather than figurative meaning
            message= _ "Look at him fly... if only we could move that fast."
        [/message]
        [message]
            speaker=Krawg
            message= _ "Krah!"
        [/message]
        [message]
            speaker=narrator
            message= _ "Suddenly, the air was filled with the cries of another gryphon responding to Krawg’s call. The dwarves heard the flaps of wings and looked up to the sky to see another gryphon arriving."
            image=wesnoth-icon.png
        [/message]
        [move_unit_fake]
            type=Gryphon
            x=1,1
            y=12,3
            side=1
        [/move_unit_fake]
        [unit]
            x,y=1,3
            type=Gryphon Rider
            side=1
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
        [message]
            speaker=narrator
            # po: The mount is a gryphon.
            message= _ "A brave dwarf ran out, grabbed it by the sturdy neck-feathers, and hauled himself up over its back. The big animal was friendly, took it all in stride, and seemed to understand what the pats and strokes of the dwarf’s hands meant."
            image=wesnoth-icon.png
        [/message]
        [message]
            speaker=narrator
            message= _ "You may now recruit Gryphon Riders."
            image=wesnoth-icon.png
        [/message]

        [allow_recruit]
            side=1
            type=Gryphon Rider
        [/allow_recruit]
    [/event]

    [event]
        name=turn 3
        [unstore_unit]
            x,y=1,35
            variable=glildur
        [/unstore_unit]
        {CLEAR_VARIABLE glildur}
        {MOVE_UNIT id=Glildur 3 33}
        [terrain]
            terrain=Cea
            x,y=3,33
            radius=1
        [/terrain]
        [terrain]
            terrain=Ke
            x,y=3,33
        [/terrain]
        [terrain]
            terrain=Ce
            x,y=2,33
        [/terrain]
        [message]
            speaker=Glildur
            message= _ "Aha! I’ve been looking all over for you dwarves, but now I’ve found you! Prepare to die!"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Who in the earth’s guts are you?"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "I thought we left the elves behind at the gates way back when... it seems we have two enemies now!"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "So, elves, are you against these dwarves too? They’re attacking my clan for absolutely no reason!"
        [/message]
        [message]
            speaker=Glildur
            message= _ "No reason? So you don’t have the ruby?"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "What ruby? They wanted to rent my tools to cut something, probably your ruby, but they didn’t offer me nearly enough!"
        [/message]
        [message]
            speaker=Glildur
            message= _ "How about this — we defeat these crazed cave-dwellers, then you keep the spoils and their territory, and we keep the ruby?"
        [/message]
        [message]
            speaker=Glonoin
            message= _ "Deal! Not like this is the first time we’ve faced this sort of insanity. We have no idea what this ruby is, and don’t care!"
        [/message]
        [message]
            speaker=Durstorn
            message= _ "Ah, they don’t scare me! We can take both of them!"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Don’t be a fool! We can’t take the elves, and it was a mistake to attack these dwarves, but if we have to fight, we should retreat once we get what we came for, the tools!"
        [/message]

        {VARIABLE elves_come yes}
        [show_objectives]
        [/show_objectives]
    [/event]

#define IN_CAVES
    [filter_location]
        x,y=19,17
        radius=6
        # x=16-22,15-23,13-25,15-22,17-21
        # y=   11,   12,13-19,   20,   21
    [/filter_location]
#enddef

    [event]
        name=die
        [filter]
            id=Glonoin
        [/filter]
        [kill]
            id=Glonoin
            animate=no
            fire_event=no
        [/kill]
        [message]
            speaker=Durstorn
            message= _ "Ha! Now we can easily take their tools back to our own caves."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "And how do you plan on doing that? There are elves swarming these hills, trying to kill us."
        [/message]
        [message]
            speaker=Durstorn
            message= _ "I’m aware! Close the gates and keep them out! It should be easy to come up with a plan to outwit them later. Meanwhile, since the Shorbear’s rune workshops are in here, you and your runecrafters might as well make the sceptre now."
        [/message]
        [if]
            [have_unit]
                id=Rugnur
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Alanin
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Krawg
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Thursagan
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Durstorn
                {IN_CAVES}
            [/have_unit]
            [then]
                [if]
                    [have_unit]
                        side=2,3
                        {IN_CAVES}
                    [/have_unit]
                    [then]
                        [message]
                            speaker=Thursagan
                            message= _ "Well, back to the battle — all of us are already inside, but there are still some enemy forces in here with us!"
                        [/message]
                        [message]
                            speaker=Durstorn
                            message= _ "Indeed. Kill them! And make sure no more enter. Then we can close the gates."
                        [/message]

                        {VARIABLE ready_to_close yes}

                        [show_objectives]
                        [/show_objectives]
                    [/then]
                    [else]
                        [message]
                            speaker=Thursagan
                            message= _ "We have driven all of the elves and Shorbear dwarves out of these caves. They are not ours, though, and we can’t stay here forever."
                        [/message]
                        [message]
                            speaker=Durstorn
                            message= _ "True. I suspect these elves will try to besiege us."
                        [/message]
                        [endlevel]
                            result=victory
                            bonus=no
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]
                    [/else]
                [/if]
            [/then]
            [else]
                [message]
                    speaker=Thursagan
                    message= _ "Well, back to the battle — we need to get everyone into the Shorbear caves before we can close the gates."
                [/message]
                [message]
                    speaker=Durstorn
                    message= _ "Indeed. Everyone to the caves, and kill those still inside!"
                [/message]

                {VARIABLE ready_to_close yes}

                [show_objectives]
                [/show_objectives]
            [/else]
        [/if]
    [/event]

#define SOF_S5_GATES
    [terrain]
        [and]
            terrain=*^Pr/o
        [/and]
        terrain=Uu^Pr/
        layer=overlay
        replace_if_failed=yes
    [/terrain]
    [terrain]
        [and]
            terrain=*^Pr\o
        [/and]
        terrain=Uu^Pr\
        layer=overlay
        replace_if_failed=yes
    [/terrain]
    [redraw]
        side=1
    [/redraw]
    [delay]
        time=100
    [/delay]
#enddef

    [event]
        name=die
        first_time_only=no

        [filter]
            side=2,3
        [/filter]

        [if]
            [variable]
                name=ready_to_close
                equals=yes
            [/variable]
            [have_unit]
                id=Rugnur
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Alanin
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Krawg
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Thursagan
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Durstorn
                {IN_CAVES}
            [/have_unit]
            [then]
                [if]
                    [have_unit]
                        side=2,3
                        {IN_CAVES}
                    [/have_unit]
                    [else]
                        [message]
                            speaker=Durstorn
                            message= _ "We have driven all of the elves and Shorbear dwarves out of these caves! Now, seal the gates!"
                        [/message]
                        {SOF_S5_GATES}
                        [endlevel]
                            result=victory
                            bonus=no
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1

            [not]
                [not]
                    id=Rugnur
                [/not]
                [not]
                    id=Alanin
                [/not]
                [not]
                    id=Krawg
                [/not]
                [not]
                    id=Thursagan
                [/not]
                [not]
                    id=Durstorn
                [/not]
            [/not]
        [/filter]

        [if]
            [variable]
                name=ready_to_close
                equals=yes
            [/variable]
            [have_unit]
                id=Rugnur
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Alanin
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Krawg
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Thursagan
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Durstorn
                {IN_CAVES}
            [/have_unit]
            [then]
                [if]
                    [have_unit]
                        side=2,3
                        {IN_CAVES}
                    [/have_unit]
                    [then]
                        [allow_undo][/allow_undo]
                    [/then]
                    [else]
                        [message]
                            speaker=Durstorn
                            message= _ "We have driven all of the elves and Shorbear dwarves out of these caves! Now, seal the gates!"
                        [/message]
                        {SOF_S5_GATES}
                        [endlevel]
                            result=victory
                            bonus=no
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]
                    [/else]
                [/if]
            [/then]
            [else]
                [allow_undo][/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        [if]
            [variable]
                name=ready_to_close
                equals=yes
            [/variable]
            [have_unit]
                id=Rugnur
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Alanin
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Krawg
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Thursagan
                {IN_CAVES}
            [/have_unit]
            [have_unit]
                id=Durstorn
                {IN_CAVES}
            [/have_unit]
            [then]
                [if]
                    [have_unit]
                        side=2,3
                        {IN_CAVES}
                    [/have_unit]
                    [else]
                        [message]
                            speaker=Durstorn
                            message= _ "We have driven all of the elves and Shorbear dwarves out of these caves! Now, seal the gates!"
                        [/message]
                        {SOF_S5_GATES}
                        [endlevel]
                            result=victory
                            bonus=no
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    [event]
        name=enemies defeated

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

    [event]
        name=last breath
        [filter]
            id=Glildur
        [/filter]
        [message]
            speaker=Glildur
            message= _ "Well played, little dwarves, but this isn’t over..."
        [/message]
        {MOVE_UNIT (id=Glildur) 1 38}
        [heal_unit]
            [filter]
                id=Glildur
            [/filter]
            amount=full
            restore_attacks=yes
            moves=full
        [/heal_unit]
        [store_unit]
            [filter]
                id=Glildur
            [/filter]
            variable=glildur
            kill=yes
        [/store_unit]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Durstorn
        [/filter]
        [message]
            speaker=Durstorn
            message= _ "Gaanngh..." # wmllint: no spellcheck
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=victory

        {SOF_CLEAR_RUNE_VARS 1}

        {CLEAR_VARIABLE elves_come}
    [/event]

    [event]
        name=turn 10
        [gold]
            side=3
            amount=200
        [/gold]
    [/event]
[/scenario]

#undef IN_CAVES
#undef SOF_S5_GATES
