#textdomain wesnoth-httt
[scenario]
    id=10_Gryphon_Mountain
    name= _ "Gryphon Mountain"
    map_data="{campaigns/Heir_To_The_Throne/maps/10_Gryphon_Mountain.map}"
    {TURNS 27 24 21}

    {DEFAULT_SCHEDULE}

    next_scenario=11_The_Ford_of_Abez

    {SCENARIO_MUSIC "wanderer.ogg"}
    {EXTRA_SCENARIO_MUSIC "knolls.ogg"}
    {EXTRA_SCENARIO_MUSIC "loyalists.ogg"}
    {EXTRA_SCENARIO_MUSIC "battle.ogg"}
    {EXTRA_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}
    {EXTRA_SCENARIO_MUSIC "northern_mountains.ogg"}

    [event]
        name=prestart

        {VARIABLE eggs_done no}
        {CLEAR_VARIABLE gryphons_return}
        [objectives]
            side=1
            [objective]
                description= _ "Defeat the enemy leader"
                condition=win
            [/objective]
            [objective]
                [show_if]
                    {CHECK_VARIABLE eggs_done no}
                [/show_if]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Defeat the mother gryphon before the enemy does"+{OBJECTIVE_FOOTNOTE _"(special bonus)"}
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Konrad"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Delfador"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    {HTTT_TRACK {JOURNEY_10_NEW} }

    {PLACE_IMAGE scenery/nest-empty.png 10 14}
    {PLACE_IMAGE scenery/nest-empty.png 16 16}
    {PLACE_IMAGE scenery/nest-empty.png 12 18}
    {PLACE_IMAGE scenery/nest-full.png 13 16}

    {PLACE_IMAGE scenery/rock1.png 23 12}
    {PLACE_IMAGE scenery/rock2.png  8 31}
    {PLACE_IMAGE scenery/rock3.png 15  2}

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad-human.png
        side=1
        canrecruit=yes
        team_name=elves
        user_team_name=_"Rebels"
        controller=human
        gold=200
        {FLAG_VARIANT long}
    [/side]

    [side]
        type=General
        id=Robryn
        name= _ "Robryn"
        side=2
        canrecruit=yes
        recruit=Cavalryman,Swordsman,Mage,Ogre,Duelist,Longbowman
        [ai]
            {ATTACK_DEPTH 1 3 5}
            recruitment_pattern=scout,fighter,fighter,fighter,archer,mixed fighter
        [/ai]
        {GOLD 160 270 350}
        team_name=asheviere
        user_team_name=_"Asheviere"
        {FLAG_VARIANT loyalist}
    [/side]

    {STARTING_VILLAGES 2 8}

    [side]
        type=Gryphon
        id=Mother Gryphon
        name= _ "Mother Gryphon"
        side=3
        team_name=gryphons
        user_team_name=_"Gryphons"
        canrecruit=yes
        recruit=Gryphon
        gold=0
        {NO_INCOME}
        [ai]
            {ATTACK_DEPTH 1 3 5}
            passive_leader=yes
        [/ai]
    [/side]

    [event]
        name=prestart
        {CLEAR_VARIABLE get_gryphons}
        {NEED_DELFADOR placement=leader}
        {NEED_KALENZ placement=leader}

        {NAMED_LOYAL_UNIT 3 (Sleeping Gryphon) 12 18 (Graak) ( _ "Graak")}
        {NAMED_LOYAL_UNIT 3 (Sleeping Gryphon) 16 16 (Grook) ( _ "Grook")}
        {NAMED_LOYAL_UNIT 3 (Sleeping Gryphon) 10 14 (Gruak) ( _ "Gruak")}
        # wmllint: recognize Rampant Graak
        # wmllint: recognize Rampant Grook
        # wmllint: recognize Rampant Gruak

        {VARIABLE gryphon_disposition 1}
    [/event]

    [event]
        name=start
        [message]
            speaker=Konrad
            message= _ "What is this place? That is one big mountain!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "That is the fabled Gryphon Mountain."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Gryphon Mountain! Maybe we could steal some eggs from the gryphons and train the young to be flying mounts. Would that work, Delfador?"
        [/message]
        [message]
            speaker=Delfador
            message= _ "We can try to do that, but we must be careful. To disturb the gryphons could prove dangerous... and yet such mounts could help us greatly later. Whatever we do, we must pass by this place."
        [/message]
        [message]
            speaker=Konrad
            message= _ "Well, let’s start climbing the mountain!"
        [/message]
    [/event]

    #if the player kills the mother gryphon
    #and gets her eggs
    [event]
        name=die
        [filter]
            id=Mother Gryphon
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [message]
            speaker=second_unit
            message= _ "Here are the mother Gryphon’s eggs!"
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION glad}
            message= _ "Excellent! We should be able to breed Gryphons for our own uses now!"
        [/message]
        [set_variable]
            name=get_gryphons
            value=1
        [/set_variable]
        {REMOVE_IMAGE 13 16}
        {PLACE_IMAGE scenery/nest-empty.png 13 16}
        {VARIABLE eggs_done yes}
    [/event]

    [event]
        name=turn 2
        [message]
            speaker=Delfador
            message= _ "It appears that we are not the only ones interested in this mountain. Once again the Queen opposes us!"
        [/message]
        [message]
            speaker=Konrad
            {KONRAD_VARIATION mad}
            message= _ "Quickly, men! Onward!"
        [/message]
    [/event]

    #if the enemy gets to the gryphon eggs first
    [event]
        name=die
        [filter]
            id=Mother Gryphon
        [/filter]
        [filter_second]
            side=2
        [/filter_second]
        [message]
            speaker=second_unit
            message= _ "Ha ha! We have killed this foul beast of the air, and can deny the rebels its eggs!"
        [/message]
        {VARIABLE_OP gryphon_disposition sub 1}
        {REMOVE_IMAGE 13 16}
        {PLACE_IMAGE scenery/nest-empty.png 13 16}
        {VARIABLE eggs_done yes}
    [/event]
    [event]
        name=attack
        [filter]
            side=2
        [/filter]
        [filter_second]
            side=3
        [/filter_second]
        {VARIABLE_OP gryphon_disposition add 2}
    [/event]
    [event]
        name=attack
        first_time_only=no
        [filter]
            side=1
        [/filter]
        [filter_second]
            side=3
        [/filter_second]
        {VARIABLE_OP gryphon_disposition sub 1}
    [/event]
    [event]
        name=die
        [filter]
            side=3
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        {VARIABLE_OP gryphon_disposition sub 10}
    [/event]

    [event]
        name=die
        [filter]
            id=Robryn
        [/filter]
        [message]
            speaker=Konrad
            message= _ "We have defeated them! Now what do we do?"
        [/message]
        [message]
            speaker=Delfador
            message= _ "We must continue north. It is too late to return to the safety of Elensefar or Alduin before winter falls. We must therefore cross the great river and continue toward the land of the dwarves. Hurry, let us go!"
        [/message]
        [if]
            [variable]
                name=get_gryphons
                numerical_equals=1
            [/variable]
            [then]
                [message]
                    speaker=Konrad
                    message= _ "With these gryphon eggs we should be able to breed gryphons that will serve us. When they are large enough to carry mounts, we can hire gryphon riders!"
                [/message]
            [/then]
            [elseif]
                [and]
                    [variable]
                        name=gryphon_disposition
                        greater_than_equal_to=2
                    [/variable]
                    [have_unit]
                        side=3
                    [/have_unit]
                [/and]
                [then]
                    [message]
                        speaker=Konrad
                        message= _ "It is a shame we could not get those gryphon eggs. I am glad we did not slaughter any gryphons. They are magnificent animals (looks back at the mountain). Still..."
                    [/message]
                    [message]
                        speaker=Konrad
                        message= _ "Whoa!!"
                    [/message]
                    #
                    # Wake up all the sleeping gryphons
                    #
                    [store_unit]
                        variable=gryphon_store
                        [filter]
                            side=3
                        [/filter]
                    [/store_unit]
                    [foreach]
                        array=gryphon_store
                        [do]
                            {VARIABLE this_item.type Gryphon}
                            [unstore_unit]
                                variable=this_item
                            [/unstore_unit]
                        [/do]
                    [/foreach]
                    {CLEAR_VARIABLE gryphon_store}
                    #
                    # Figure out where Konrad is standing
                    #
                    [store_unit]
                        variable=konrad_store
                        [filter]
                            id=Konrad
                        [/filter]
                    [/store_unit]
                    [if]
                        [variable]
                            name=konrad_store.x
                            greater_than=13
                        [/variable]
                        [then]
                            {VARIABLE destination_x 24}
                        [/then]
                        [else]
                            {VARIABLE destination_x 1}
                        [/else]
                    [/if]
                    [if]
                        [variable]
                            name=konrad_store.y
                            greater_than=16
                        [/variable]
                        [then]
                            {VARIABLE destination_y 39}
                        [/then]
                        [else]
                            {VARIABLE destination_y 1}
                        [/else]
                    [/if]
                    #
                    # Put some more gryphons up there and view the mountain
                    #
                    {NAMED_LOYAL_UNIT 3 (Gryphon) 13 14 (Graik) ( _ "Graik")}
                    {NAMED_LOYAL_UNIT 3 (Gryphon) 13 18 (Griak) ( _ "Griak")}
                    [scroll_to]
                        x,y=13,16
                    [/scroll_to]
                    [message]
                        speaker=narrator
                        image="wesnoth-icon.png"
                        message= _ "Indeed, the majestic beasts were now circling the mountain’s peak. Several glared in Konrad’s direction, their eagle eyes fixed on him at an incredible distance."
                    [/message]
                    [sound]
                        name=gryphon-shriek-1.ogg
                    [/sound]
                    [store_unit]
                        variable=gryphon_store
                        [filter]
                            side=3
                        [/filter]
                    [/store_unit]
                    [foreach]
                        array=gryphon_store
                        [do]
                            {VARIABLE temp_x $this_item.x}
                            {VARIABLE temp_y $this_item.y}
                            {VARIABLE range_x ("$temp_x|, $destination_x")}
                            {VARIABLE range_y ("$temp_y|, $destination_y")}
                            [kill]
                                x=$temp_x
                                y=$temp_y
                            [/kill]
                            [move_unit_fake]
                                type=Gryphon
                                side=3
                                x=$range_x
                                y=$range_y
                            [/move_unit_fake]
                        [/do]
                    [/foreach]
                    {CLEAR_VARIABLE konrad_store}
                    {CLEAR_VARIABLE gryphon_store}
                    {CLEAR_VARIABLE temp_x}
                    {CLEAR_VARIABLE temp_y}
                    {CLEAR_VARIABLE range_x}
                    {CLEAR_VARIABLE range_y}
                    {CLEAR_VARIABLE destination_x}
                    {CLEAR_VARIABLE destination_y}
                    [message]
                        speaker=Delfador
                        message= _ "Amazing! I have never before heard of such behavior in gryphons."
                    [/message]
                    [message]
                        speaker=Konrad
                        message= _ "What does it mean?"
                    [/message]
                    [message]
                        speaker=Delfador
                        message= _ "I do not know. Come now, the show is over."
                    [/message]
                    {VARIABLE gryphons_return yes}
                [/then]
            [/elseif]
            [else]
                [message]
                    speaker=Konrad
                    message= _ "It is a shame we could not get those gryphon eggs — they would surely have given us an advantage sometime. Still, we must continue."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Delfador
            message= _ "Let us continue onward!"
        [/message]

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

    [event]
        name=victory

        {CLEAR_VARIABLE gryphon_disposition,eggs_done}
    [/event]

    # Sleeping Gryphons will counter if attacked, then wake up and
    # morph to new Gryphons (a different unit type). The new unit will
    # then usually fly away because the AI thinks your attacking unit
    # is too tough for it to take.  This could be fixed with some
    # WML contortions, but why do it?  The nonstandard behavior adds
    # variety and a bit of mystery.  Gryphon Mountain is a magical place.

    #
    # If the sleeping gryphon is attacked, it wakes up
    #

    [event]
        name=attack
        [filter_second]
            id=Graak
        [/filter_second]
        [modify_unit]
            [filter]
                id=Graak
            [/filter]
            type=Gryphon
            id=Rampant Graak
            name= _ "Rampant Graak"
        [/modify_unit]
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Grook
        [/filter_second]
        [modify_unit]
            [filter]
                id=Grook
            [/filter]
            type=Gryphon
            id=Rampant Grook
            name= _ "Rampant Grook"
        [/modify_unit]
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Gruak
        [/filter_second]
        [modify_unit]
            [filter]
                id=Gruak
            [/filter]
            type=Gryphon
            id=Rampant Gruak
            name= _ "Rampant Gruak"
        [/modify_unit]
    [/event]

    #
    # If the sleeping gryphon attacks you, it wakes up
    #

    [event]
        name=attack
        [filter]
            id=Graak
        [/filter]
        [modify_unit]
            [filter]
                id=Graak
            [/filter]
            type=Gryphon
            id=Rampant Graak
            name= _ "Rampant Graak"
        [/modify_unit]
    [/event]

    [event]
        name=attack
        [filter]
            id=Grook
        [/filter]
        [modify_unit]
            [filter]
                id=Grook
            [/filter]
            type=Gryphon
            id=Rampant Grook
            name= _ "Rampant Grook"
        [/modify_unit]
    [/event]

    [event]
        name=attack
        [filter]
            id=Gruak
        [/filter]
        [modify_unit]
            [filter]
                id=Gruak
            [/filter]
            type=Gryphon
            id=Rampant Gruak
            name= _ "Rampant Gruak"
        [/modify_unit]
    [/event]

    {campaigns/Heir_To_The_Throne/utils/deaths.cfg}
[/scenario]
