#textdomain wesnoth-sof
[scenario]
    name= _ "The Dragon"
    id=8_The_Dragon
    turns=unlimited
    map_file=8_The_Dragon.map
    next_scenario=9_Caverns_of_Flame

    victory_when_enemies_defeated=no

    {SCENARIO_MUSIC "knalgan_theme.ogg"}

    {UNDERGROUND}

    [time_area]
        x=0-4, 0-3,  0-2,0-4,0-3,  0-2
        y=0-5,6-10,11-14, 15, 16,17-24
        {DEFAULT_SCHEDULE}
    [/time_area]

    [side]
        type=Dwarvish Fighter
        id=Rugnur
        save_id=Rugnur
        side=1
        canrecruit=yes
        controller=human
        recruit=Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Guardsman,Dwarvish Scout,Gryphon Rider
        {GOLD 300 250 200}
        shroud=yes
        fog=yes
        {FLAG_VARIANT knalgan}
        team_name=dwarves
        user_team_name= _ "Dwarves"
    [/side]

    [side]
        type=Elvish Marshal
        id=Crintil
        name= _ "Crintil"
        side=2
        canrecruit=yes
        controller=ai
        recruit=Elvish Avenger,Elvish Marshal,Elvish Champion,Elvish Outrider,Dwarvish Thunderguard,Dwarvish Berserker,Dwarvish Steelclad
        gold=1000
        income=50
        [ai]
            aggression=1.0
            caution=0.0
            leader_value=0
            village_value=0
            recruitment_pattern=scout,fighter,fighter,mixed fighter
            grouping=no
            passive_leader=yes

            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=2
            [/goal]
        [/ai]
        team_name=elves
        user_team_name= _ "Elves"
        {FLAG_VARIANT wood-elvish}
    [/side]

    [side]
        type=Fire Dragon
        id=Khrakrahs
        name= _ "Khrakrahs"
        side=3
        canrecruit=yes
        controller=ai
        {RECRUIT (Cave Wyrmlet,Red Wyrmlet) (Cave Wyrmlet,Cave Wyrm,Red Wyrmlet) (Cave Wyrmlet,Cave Wyrm,Red Wyrmlet,Red Wyrm)}
        {GOLD 175 250 325}
        {INCOME 6 12 18}
        [ai]
            recruitment_pattern=scout
            aggression=0.9
            leader_aggression=0.9
            caution=0.1
            grouping=offensive
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=2
            [/goal]
        [/ai]
        team_name=khrakrahs
        user_team_name= _ "Khrakrahs"
    [/side]

#ifdef EASY
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Cave Wyrmlet) 5}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Red Wyrmlet) 4}
#endif
#ifdef NORMAL
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Cave Wyrmlet) 6}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Red Wyrmlet) 4}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Cave Wyrm) 1}
#endif
#ifdef HARD
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Cave Wyrmlet) 6}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Red Wyrmlet) 5}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Cave Wyrm) 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Red Wyrm) 1}
#endif

    [story]
        [part]
            story= _ "Thus, Alanin escaped from his elvish pursuers. But the dwarves were not so lucky, for the section of the old eastern mines that they reached in their flight had become the lair of the dragon Khrakrahs."
        [/part]
    [/story]

    {SOF_TRACK {JOURNEY_08_NEW} }

    {SOF_DEATHS}

    {SOF_RUNIC_EVENTS}

    [event]
        name=prestart

        {VARIABLE found_forge no}

        [objectives]
            side=1
            [objective]
                description= _ "Get all heroes to the end of the tunnel"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL found_forge boolean_equals no}
                    [have_unit]
                        # wmllint: recognize Thursagan
                        id=Thursagan
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Move Thursagan to the forge"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL found_forge boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Defend Thursagan until the Sceptre of Fire is complete"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL found_forge boolean_equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Survive until turns run out"
                condition=win
                show_turn_counter=yes
                [show_if]
                    [not]
                        [have_unit]
                            id=Thursagan
                        [/have_unit]
                    [/not]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Rugnur"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Krawg"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Thursagan"
                condition=lose
                [show_if]
                    [have_unit]
                        id=Thursagan
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "An enemy moves onto the forge"
                condition=lose
                [show_if]
                    [not]
                        [have_unit]
                            id=Thursagan
                        [/have_unit]
                    [/not]
                [/show_if]
            [/objective]

            {RUNE_MECHANIC_NOTE}

            [gold_carryover]
                carryover_percentage=0
            [/gold_carryover]
        [/objectives]
        # to make the dragon unique
        # this may be a bit too cheap and subtle, but a true solution would be to fix the dragon sprite
        [modify_unit]
            [filter]
                id=Khrakrahs
            [/filter]
            experience=22
            [effect]
                apply_to=image_mod
                add="CS(-25,-60,-70)"
            [/effect]
        [/modify_unit]
        # some decorations for the dragon lair
        [item]
            image=items/gold-coins-small.png
            x,y=10,19
        [/item]
        [item]
            image=items/ornate1.png
            x,y=11,20
        [/item]
        [item]
            image=items/chest.png
            x,y=7,17
        [/item]
        [item]
            image=items/armor-golden.png
            x,y=4,17
        [/item]
        [item]
            image=items/gold-coins-medium.png
            x,y=4,18
        [/item]
        [item]
            image=items/gold-coins-small.png
            x,y=8,16
        [/item]
        [item]
            image=items/gold-coins-small.png
            x,y=9,25
        [/item]
    [/event]

#define RANDOM_MERCENARY TYPE X Y WML
    {UNIT 2 {TYPE} {X} {Y} (
        generate_name=yes
        random_gender=yes
        upkeep=full
        {WML}
    )}
#enddef
    [event]
        name=start

        {MOVE_UNIT id=Rugnur 12 7}

        [redraw]
            side=1
        [/redraw]

        [recall]
            id=Baglur
        [/recall]
        [recall]
            id=Krawg
        [/recall]
        [recall]
            id=Thursagan
        [/recall]

        # The enemy gets mercenaries; berserker traits defined to prevent them
        # from being quick... except one on hard
        {RANDOM_MERCENARY "Dwarvish Berserker" 1 13 (
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_HEALTHY}
            [/modifications]
        )}
        {RANDOM_MERCENARY "Dwarvish Berserker" 1 14 (
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        )}
        {RANDOM_MERCENARY "Dwarvish Berserker" 1 15 (
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_HEALTHY}
            [/modifications]
        )}
#ifdef EASY
#else
        {RANDOM_MERCENARY "Dwarvish Berserker" 1 16 (
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        )}
#endif
#ifdef HARD
        {RANDOM_MERCENARY "Dwarvish Berserker" 1 17 (
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}
#endif
        {RANDOM_MERCENARY "Dwarvish Lord" 2 12 ()}
        {RANDOM_MERCENARY "Dwarvish Lord" 2 13 ()}
        {RANDOM_MERCENARY "Dwarvish Lord" 2 14 ()}
        {RANDOM_MERCENARY "Dwarvish Dragonguard" 2 15 ()}
        {RANDOM_MERCENARY "Dwarvish Dragonguard" 1 12 ()}

        [message]
            speaker=Rugnur
            message= _ "Well, Thursagan, we’ve reached the eastern mine, but the elves are hot on our trail. What do we do now?"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Well, we have two choices. We may either stand and fight, and assuredly die, or run as quickly as possible down this path into the depths of the cave, where we may find something that will help us. Also, remember, the elves can’t run as fast in caves as we can, so we may be able to get ahead of them and perhaps lay a trap."
        [/message]
        [message]
            speaker=Krawg
            message= _ "Krah! Surrender ruby?"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "If we give them the ruby, then what? They’ll probably kill us anyway. And, that ruby has the power to do great things, evil things. We can’t let it fall into the wrong hands."
        [/message]
        [message]
            speaker=Thursagan
            message= _ "Then we shall run. I suggest calling to arms every last dwarf we possibly can here. This might be the last chance we’ll get to do so."
        [/message]
        [if]
            [have_unit]
                id=Baglur
            [/have_unit]
            [then]
                [message]
                    speaker=Baglur
                    message= _ "So we’re running away, eh? I dinna’ like that, but it seems it’s our only option."
                [/message]
                [message]
                    speaker=Rugnur
                    message= _ "If it makes you feel any better, we’ll probably die this way, too."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=enter_hex
        [filter]
            side=1
            x=14,15-16
            y=14,15
        [/filter]
        [remove_shroud]
            side=1
            x=4-11
            y=15-21
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x=4-11
            y=15-21
            multiturn=no
        [/lift_fog]
        [redraw]
            side=1
        [/redraw]
        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
        [set_variable]
            name=dragon_sighted
            value=yes
        [/set_variable]
        [message]
            speaker=Rugnur
            message= _ "Look, there’s a dragon in these caves!"
        [/message]
        {MODIFY_UNIT id=Khrakrahs facing ne}
        [message]
            speaker=Khrakrahs
            message= _ "You dare trespass into <i>my</i> lair?"
        [/message]
        [message]
            speaker=Thursagan
            message= _ "And which of the great dragons are you?"
        [/message]
        [message]
            speaker=Khrakrahs
            # wmllint: local spelling Shek'kahan
            message= _ "I am Khrakrahs, greatest dragon of all time! Haldric killed Shek’kahan my rival, but he was weaker than me, and you will not find me so easy to defeat. Now get out of my volcano!"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "I’d rather face one powerful dragon than hundreds of mighty elves. Continue!"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            side=3
            level=0
        [/filter]
        [filter_condition]
            [variable]
                name=dragon_sighted
                equals=yes
            [/variable]
        [/filter_condition]
        [message]
            speaker=Khrakrahs
            message= _ "Stop that! Leave my pets alone!"
        [/message]
        {CLEAR_VARIABLE dragon_sighted}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=9,25
        [/filter]
        [remove_item]
            image=items/gold-coins-small.png
            x,y=9,25
        [/remove_item]
        [gold]
            side=1
            amount=120
        [/gold]
        # it is probably Krawg, or another gryphon
        [message]
            speaker=unit
            message= _ "Kraw!"
        [/message]
        [message]
            speaker=Rugnur
            message= _ "That’s great, we could really use some resources about now."
        [/message]
        [message]
            speaker=Khrakrahs
            message= _ "Thieves! I won’t forget this..."
        [/message]
        [message]
            side=2
            message= _ "Haha, you’re making friends all over, you cowards!"
        [/message]
        [message]
            speaker=Khrakrahs
            message= _ "I don’t care about your petty squabbles, I curse all of you! I curse all who invade my lair!"
        [/message]
        {CLEAR_VARIABLE dragon_sighted}
    [/event]

    [event]
        name=sighted,moveto
        [filter]
            race=dwarf
            side=2
            [filter_vision]
                side=1
            [/filter_vision]
        [/filter]
        [redraw]
            side=1
        [/redraw]
        [scroll_to]
            x,y=$x1,$y1
        [/scroll_to]
        [message]
            speaker=Thursagan
            message= _ "What’s this? A dwarf fighting against us with the elves?!"
        [/message]
        [message]
            speaker=Baglur
            # wmllint: local spelling Surghan
            message= _ "It must be one of those Surghan mercenaries. I’ll bet those elves have hired more of them. That’s bad news for us, for they’ll go as fast in caves as we do."
        [/message]
    [/event]

    [item]
        x,y=16,25
        image=items/altar.png
    [/item]

    [event]
        name=moveto
        [filter]
            x,y=16,25
            side=1
        [/filter]
        [if]
            [variable]
                name=unit.id
                equals=Krawg
            [/variable]
            [then]
                [message]
                    speaker=Krawg
                    #po: "(excited bird cry) Look! Forge here!"
                    message= _ "Raaaawww! Loook! Forge heeeere!" # wmllint: no spellcheck
                [/message]

                [message]
                    speaker=Thursagan
                    message= _ "It looks like a forge, heated by the lava. It also looks enchanted... and hot enough to make the Sceptre."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Look, I’ve found something here. It looks like a forge, heated by the lava. It also looks enchanted... and hot enough to make the sceptre."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Khrakrahs
            message= _ "That’s my rock slab, leave it be!"
        [/message]

        {VARIABLE found_forge yes}

        [show_objectives]
        [/show_objectives]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=16,25
            id=Thursagan
        [/filter]
        [message]
            speaker=Thursagan
            message= _ "This forge will work perfectly. Give me a day or two here, and I can reforge the Sceptre of Fire to fulfill its purpose."
        [/message]

        [modify_turns]
            value="$($turn_number + 9)"
        [/modify_turns]

        [store_unit]
            [filter]
                id=Thursagan
            [/filter]
            variable=thur
            kill=yes
        [/store_unit]
        {CLEAR_VARIABLE found_forge}

        [show_objectives]
        [/show_objectives]
        [event]
            name=moveto
            [filter]
                x,y=16,25
                side=2,3
            [/filter]
            [message]
                speaker=narrator
                caption= _ "Thursagan"
                image=portraits/thursagan.webp
                message= _ "You fool, you let the enemy get at me when I was unarmed!"
            [/message]
            [message]
                speaker=narrator
                caption= _ "Thursagan"
                image=portraits/thursagan.webp
                message= _ "Ayahahh..." # wmllint: no spellcheck
                sound=dwarf-die-1.ogg
            [/message]
            [endlevel]
                result=defeat
            [/endlevel]
        [/event]

        [event]
            name=time over

            [unstore_unit]
                variable=thur
                find_vacant=yes
            [/unstore_unit]
            {CLEAR_VARIABLE thur}

            {SOF_CLEAR_RUNE_VARS 1}

            [object]
                id=sceptre of fire
                silent=yes
                duration=forever

                [filter]
                    id=Thursagan
                [/filter]

                {SCEPTRE_OF_FIRE_EFFECT}
            [/object]
            [message]
                speaker=Thursagan
                message= _ "I have completed my work. Now it is truly the Sceptre of Fire, a powerful magical artifact."
            [/message]
            [message]
                speaker=Rugnur
                message= _ "Good! Now, let’s get out of this cave, before the elves, dwarves or wyrms kill us all!"
            [/message]

            [endlevel]
                result=victory
                bonus=no
                {NEW_GOLD_CARRYOVER 0}
            [/endlevel]
        [/event]
    [/event]
[/scenario]
