#textdomain wesnoth-httt
[scenario]
    id=12_Northern_Winter
    name= _ "Northern Winter"
    map_data="{campaigns/Heir_To_The_Throne/maps/12_Northern_Winter.map}"
    {SCENARIO_MUSIC "elvish-theme.ogg"}
    {EXTRA_SCENARIO_MUSIC "wanderer.ogg"}
    {TURNS 50 40 40}
    # when changing the turn limits, also change this event accordingly
    [event]
        name=prestart
        [set_variable]
            name=turn_limit
            {QUANTITY value 50 40 40}
        [/set_variable]
    [/event]

    {DEFAULT_SCHEDULE}

    next_scenario=13_The_Dwarven_Doors

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat all enemy leaders"
                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]

    # wmllint: local spelling thutter
    [story]
        [part]
            story= _ "Across the river were lands few humans had ever visited. The occasional distant thutter of orcish signal drums made the abundant pine forests nestled in rolling foothills both breathtaking and ominous."
            background="maps/wesnoth.png"
            show_title=no
        [/part]
        [part]
            story= _ "Swirling, snow-laden winds tore at Konrad’s army, signaling the final exit of autumn and the onset of what would be a harsh winter."
            background="maps/wesnoth.png"
            show_title=no
        [/part]
    [/story]

    {BIGMAP_NORTHERN_WINTER}

    [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=Orcish Warrior
        id="Halgar Du'nar"
        name= _ "Halgar Du’nar"
        experience=0
        side=2
        canrecruit=yes
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll Whelp,Ogre
        [ai]
            {ATTACK_DEPTH 4 5 5}
            recruitment_pattern=scout,scout,fighter,fighter,archer
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=-1.0
        [/ai]
        {GOLD 90 150 210}
        {INCOME 2 4 8}
        team_name=orcs
        user_team_name=_"Orcs"
        {FLAG_VARIANT ragged}
    [/side]

    {STARTING_VILLAGES 2 5}

    [side]
        type=Orcish Warrior
        id="Gorlak"
        name= _ "Gorlak"
        experience=0
        side=3
        canrecruit=yes
        recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll
        [ai]
            {ATTACK_DEPTH 4 5 5}
            recruitment_pattern=scout,scout,fighter,fighter,archer
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=-1.0
        [/ai]
        {GOLD 110 170 230}
        {INCOME 2 4 8}
        team_name=orcs
        user_team_name=_"Orcs"
        {FLAG_VARIANT ragged}
    [/side]

    {STARTING_VILLAGES 3 5}

    [event]
        name=prestart

        [role]
            role=human-advisor
            type=Knight,Paladin,White Mage,Mage of Light,Red Mage,Arch Mage,Great Mage,Horseman
        [/role]
        [recall]
            role=human-advisor
        [/recall]
        [recall]
            id=Delfador
        [/recall]
        [recall]
            id=Kalenz
        [/recall]
    [/event]

    [event]
        name=start
        [message]
            speaker=Konrad
            message= _ "This winter is bitterly cold! Perhaps we should stop here and rest a while."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "Stop and rest? My lord, we must go hard after the Sceptre of Fire, lest it fall into the hands of our enemies!"
        [/message]
        [message]
            speaker=Konrad
            message= _ "We have had a hard march ever since we were besieged by the undead in that foul valley. Now winter bears down upon us, and we have spent most of our money. This land looks fertile enough. Surely we can settle here for the winter!"
        [/message]
        [message]
            role=human-advisor
            message= _ "Yes, let us rest a while! I am sure there are many challenges ahead, and I do not think I could endure another like the fording of the river for many days."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "We are pursued by the forces of your arch-enemy, chasing the Sceptre of Fire, the fate of the realm in our hands, and you humans want to stop and rest? Onward, I say!"
        [/message]
        [message]
            speaker=Delfador
            message= _ "They are right, Kalenz. I had wanted to acquire the Sceptre within a moon, but it is not to be. Our soldiers will begin to desert if they do not rest soon. But in these wild north lands, we must fight even for the right to rest. Look to the north! Those foul orcs will not allow us any peace!"
        [/message]
        [message]
            speaker=Konrad
            message= _ "Then we shall wrest control of the land from them. To arms men!"
        [/message]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=Konrad
            message= _ "More snow is falling. We must finish this battle quickly. Onward men!"
        [/message]

        # This event makes snow fall on random non-snowy locations at such a
        # constant pace that snow will be everywhere exactly when turns run out
        [event]
            name=new turn
            first_time_only=no
            delayed_variable_substitution=yes

            [store_locations]
                terrain=Gs,Gd,Co,Ko,Re,Rb,Gll^Fp,Gll^Fmw,Gll^Fdw,Gd^Vo,Gd^Vc,Hhd^Vo ,Hhd^Vc

                variable=non_snowy_locs
            [/store_locations]

            {VARIABLE turns_left $turn_limit}
            {VARIABLE_OP turns_left sub $turn_number}

            {VARIABLE num_of_falling_snow $non_snowy_locs.length}
            {VARIABLE_OP num_of_falling_snow divide $turns_left}

            # {DEBUG_MSG "stored $non_snowy_locs.length  non-snowy locs, putting snow on $num_of_falling_snow"}

            {VARIABLE i 0}

            [while]
                [variable]
                    name=i
                    less_than=$num_of_falling_snow
                [/variable]

                [do]
                    {RANDOM "1..$non_snowy_locs.length"}
                    {VARIABLE_OP random sub 1}

                    [switch]
                        variable=non_snowy_locs[$random].terrain

                        [case]
                            value=Gs

                            {VARIABLE terrain Aa}
                        [/case]

                        [case]
                            value=Gd

                            {VARIABLE terrain Aa}
                        [/case]

                        [case]
                            value=Co

                            {VARIABLE terrain Coa}
                        [/case]

                        [case]
                            value=Ko

                            {VARIABLE terrain Koa}
                        [/case]

                        [case]
                            value=Coa

                            {VARIABLE terrain Aa}
                        [/case]

                        [case]
                            value=Hhd

                            {VARIABLE terrain Ha}
                        [/case]

                        [case]
                            value=Gll^Fp

                            {VARIABLE terrain Aa^Fpa}
                        [/case]

                        [case]
                            value=Gll^Fmw

                            {VARIABLE terrain Aa^Fma}
                        [/case]

                        [case]
                            value=Gll^Fdw

                            {VARIABLE terrain Aa^Fda}
                        [/case]

                        [case]
                            value=Gd^Vo

                            {VARIABLE terrain Aa^Voa}
                        [/case]

                        [case]
                            value=Gd^Vc

                            {VARIABLE terrain Aa^Vca}
                        [/case]

                        [case]
                            value=Hhd^Vo

                            {VARIABLE terrain Ha^Voa }
                        [/case]

                        [case]
                            value=Hhd^Vc

                            {VARIABLE terrain Ha^Vca }
                        [/case]

                        # just a fallback in case something goes wrong
                        [else]
                            {VARIABLE terrain $non_snowy_locs[$random].terrain}
                        [/else]
                    [/switch]

                    [terrain]
                        x,y=$non_snowy_locs[$random].x,$non_snowy_locs[$random].y
                        terrain=$terrain
                    [/terrain]

                    [store_locations]
                        find_in=non_snowy_locs

                        [not]
                            x,y=$non_snowy_locs[$random].x,$non_snowy_locs[$random].y
                        [/not]

                        variable=non_snowy_locs
                    [/store_locations]

                    {VARIABLE_OP i add 1}
                [/do]
            [/while]

            {CLEAR_VARIABLE non_snowy_locs}
        [/event]
    [/event]

    [event]
        name=turn 10

        [message]
            speaker=Konrad
            message= _ "We must make haste before the snow overwhelms us!"
        [/message]
    [/event]

    [event]
        name=enemies defeated
        [message]
            speaker=Delfador
            message= _ "Victory is ours! We have secured the land from the orcs. Now we can rest here while the cold winter passes."
        [/message]
        [message]
            speaker=Kalenz
            message= _ "Let us not rest for too long though, friends. We must still reach the ancient dwarven lands before our foes do."
        [/message]

        [if]
            [variable]
                name=get_gryphons
                numerical_equals=1
            [/variable]
            [then]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "A camp was pitched in a secluded valley that protected its occupants from the worst of the winter weather and roving orc patrols. During this time, the valley walls echoed with the squeaks of gryphon hatchlings, who happily frolicked across the camp."
                [/message]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "Konrad set his shamans to the task of corralling the animals. The elvish shamans had a natural rapport with the gryphlets, whose wings were still too small to carry a mount."
                [/message]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "Konrad finally decided he could not wait until the gryphons grew to maturity — Delfador’s insistence that the scepter must be recovered was too compelling. And so after many days of rest, the party set out once again for the dwarven kingdom..."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "A camp was pitched in a secluded valley that protected its occupants from the worst of the winter weather and roving orc patrols."
                [/message]
                [message]
                    speaker=narrator
                    image="wesnoth-icon.png"
                    message= _ "Eventually Delfador’s insistence that the scepter must be recovered proved too compelling, even when it meant dismantling the camp without the spring having yet fully arrived. And so after many days of rest, the party set out once again for the dwarven kingdom..."
                [/message]
            [/else]
        [/if]

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

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