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

    {DEFAULT_SCHEDULE}

    next_scenario=11_The_Ford_of_Abez

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat the mother gryphon and the enemy commander"
                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]

    {BIGMAP_GRYPHON_MOUNTAIN}

    {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}
    # {SCATTER_IMAGE (terrain=Gg) 12 scenery/oak-leaning.png}

    [side]
        type=Commander
        id=Konrad
        name= _ "Konrad"
        unrenamable=yes
        profile=portraits/konrad.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
        canrecruit=yes
        recruit=Gryphon
        gold=0
        [ai]
            {ATTACK_DEPTH 1 3 5}
            passive_leader=yes
        [/ai]
    [/side]

    [event]
        name=prestart
        [recall]
            id=Delfador
        [/recall]
        [recall]
            id=Kalenz
        [/recall]

        {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 Graak
        # wmllint: recognize Grook
        # wmllint: recognize 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
            message= _ "Excellent! We should be able to breed Gryphons for our own uses now!"
        [/message]
        [set_variable]
            name=get_gryphons
            value=1
        [/set_variable]
    [/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
            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}
    [/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=enemies defeated
        [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]
            [else]
                [if]
                    [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 gryphon_store i}
                            {VARIABLE gryphon_store[$i].type Gryphon}
                            [unstore_unit]
                                variable=gryphon_store[$i]
                            [/unstore_unit]
                        {NEXT i}
                        {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 gryphon_store i}
                            {VARIABLE_OP temp_x value $gryphon_store[$i].x}
                            {VARIABLE_OP temp_y value $gryphon_store[$i].y}
                            {VARIABLE_OP range_x value ("$temp_x|, $destination_x")}
                            {VARIABLE_OP range_y value ("$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]
                        {NEXT i}
                        {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]
                    [/then]
                    [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]
            [/else]
        [/if]
        [message]
            speaker=Delfador
            message= _ "Let us continue onward!"
        [/message]

        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/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]
        [kill]
            id=Graak
        [/kill]
        {NAMED_LOYAL_UNIT 3 (Gryphon) 12 18 (Rampant Graak) ( _ "Rampant Graak")}
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Grook
        [/filter_second]
        [kill]
            id=Grook
        [/kill]
        {NAMED_LOYAL_UNIT 3 (Gryphon) 16 16 (Rampant Grook) ( _ "Rampant Grook")}
    [/event]

    [event]
        name=attack
        [filter_second]
            id=Gruak
        [/filter_second]
        [kill]
            id=Gruak
        [/kill]
        {NAMED_LOYAL_UNIT 3 (Gryphon) 10 14 (Rampant Gruak) ( _ "Rampant Gruak")}
    [/event]

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

    [event]
        name=attack
        [filter]
            id=Graak
        [/filter]
        [kill]
            id=Graak
        [/kill]
        {NAMED_LOYAL_UNIT 3 (Gryphon) 12 18 (Rampant Graak) ( _ "Rampant Graak")}
    [/event]

    [event]
        name=attack
        [filter]
            id=Grook
        [/filter]
        [kill]
            id=Grook
        [/kill]
        {NAMED_LOYAL_UNIT 3 (Gryphon) 16 16 (Rampant Grook) ( _ "Rampant Grook")}
    [/event]

    [event]
        name=attack
        [filter]
            id=Gruak
        [/filter]
        [kill]
            id=Gruak
        [/kill]
        {NAMED_LOYAL_UNIT 3 (Gryphon) 10 14 (Rampant Gruak) ( _ "Rampant Gruak")}
    [/event]

    #
    # Neutralize the movement goal for sleeping gryphons every turn
    #
    [event]
        name=side turn
        first_time_only=no
        [store_unit]
            variable=sleepy_gryphon_store
            [filter]
                type=Sleeping Gryphon
            [/filter]
        [/store_unit]
        {FOREACH sleepy_gryphon_store i}
            {VARIABLE_OP x_temp value $sleepy_gryphon_store[$i].x}
            {VARIABLE_OP y_temp value $sleepy_gryphon_store[$i].y}
            {VARIABLE sleepy_gryphon_store[$i].goto_x x_temp}
            {VARIABLE sleepy_gryphon_store[$i].goto_y y_temp}
            [unstore_unit]
                variable=sleepy_gryphon_store[$i]
            [/unstore_unit]
        {NEXT i}
        {CLEAR_VARIABLE sleepy_gryphon_store}
        {CLEAR_VARIABLE x_temp}
        {CLEAR_VARIABLE y_temp}
    [/event]

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