#textdomain wesnoth-did
[scenario]
    id=02_Peaceful_Valley
    next_scenario=03_A_Haunting_in_Winter

    name=_ "Peaceful Valley"
    map_data="{campaigns/Descent_Into_Darkness/maps/02_Peaceful_Valley.map}"
    victory_when_enemies_defeated=no
    {TURNS 29 26 23}
    {DEFAULT_SCHEDULE_MORNING}

    {INTRO_AND_SCENARIO_MUSIC wanderer.ogg elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}
    {EXTRA_SCENARIO_MUSIC revelation.ogg}

    [story]
        [part]
            story=_ "Fighting tears and rage, Malin follows the back-trail of the orcish band. He curses the elder mages for sending him from the Isle of Alduin half-prepared, only to be thrust into conflict. He curses Drogan for lacking the courage to see what must be done. Most fiercely, he curses the orcs for ravaging his family and home through their ceaseless attacks."
            {DID_BIGMAP}
        [/part]
        [part]
            story=_ "Three days’ travel outside Parthyn, Malin meets Darken Volk, the same necromancer who had saved Parthyn and taught Malin to raise the dead not long ago. The necromancer takes pity on Malin in his friendless state, and asks Malin to travel with him. As the weeks pass, he teaches Malin more dark magic."
            background=story/travel.jpg
            scale_background=no
        [/part]
    [/story]

    {BIGMAP_02}

    [side]
        side=1
        controller=human
        type=Apprentice Mage
        id=Malin Keshar
        name=_ "Malin Keshar"
        profile=portraits/malin_young.png
        unrenamable=yes
        canrecruit=yes
        recruit=Walking Corpse,Vampire Bat
        {GOLD 120 100 80}
        fog=yes
        shroud=yes
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=2
        controller=ai
        type=Goblin Knight
        id="T'shar Lggi"
        name=_ "T’shar Lggi"
        canrecruit=yes
        recruit=Goblin Rouser,Goblin Impaler,Wolf Rider
        {GOLD 70 90 110}
        fog=yes
        shroud=no
        [ai]
            village_value=2
            caution=0.5
            recruitment_pattern=scout,fighter
        [/ai]
        {FLAG_VARIANT ragged}
    [/side]

    {STARTING_VILLAGES_ALL 2}

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Occupy all of the goblin villages"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Malin Keshar"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Darken Volk"
            [/objective]

            {TURNS_RUN_OUT}

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

    [event]
        name=start
        # {SCATTER_IMAGE (terrain=Ss) 3 scenery/pine1.png}
        [unit]
            id=Darken Volk
            name=_ "Darken Volk"
            profile=portraits/darken_volk.png
            type=Dark Sorcerer DiD
            unrenamable=yes
            random_traits=no
            [modifications]
                # NOTE: if you change these, make sure you don't break the
                # removal of the loyal trait in 'Alone at Last'
                [trait]
                    id=loyal
                    name= _ "loyal"
                    description= _ "to himself"
                    [effect]
                        apply_to=loyal
                    [/effect]
                [/trait]
                {TRAIT_QUICK}
                [object]
                    [effect]
                        apply_to=image_mod
                        # This shifts the Dark Sorcerer and Necromancer hair and
                        # robe colors a bit; first the hair, then the robes
                        replace="PAL(E3DCDC,C9C3BE,999188,6E675C,514A3F>C1C1C1,919191,646464,444444,080808)~PAL(889880,506858,283028>7C999B,4C546C,262C31)"
                    [/effect]
                [/object]
            [/modifications]
            side=1
            x=15
            y=16
            {IS_HERO}
        [/unit]

        [message]
            speaker=Darken Volk
            message=_ "In truth, I share your hatred for the orcs. The northlands have been my... home... for many years, and the orcs have been a growing infestation in them. They despoil the beauty of the land wherever they go. If you are interested, I would be happy to take you on as my apprentice so that you can... aid me in the fight against them."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "Yes! I thirst for revenge on those creatures!"
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "Who knows? Perhaps removing the threat of orc raids will persuade the people of Parthyn to... welcome you home."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "Perhaps. Even Drogan would have to be thankful for a summer without orc raids."
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "A goblin village lies in this valley, just ahead. They are a bastard race born of the orcs, and help them in their wars against humans and dwarves. These do not know of our coming. Subduing them will give us souls upon which to call in our fight against the orcs."
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "It will be a worthwhile test of your new skills."
        [/message]
    [/event]

    # In-scenario events
    [event]
        name=capture
        first_time_only=yes
        [filter]
            side=1
        [/filter]

        [message]
            speaker=Darken Volk
            message=_ "Beware the goblin guards in the villages."
        [/message]
    [/event]

    [event]
        name=capture
        first_time_only=no
        [filter]
            side=1
        [/filter]

        [filter_condition]
            [variable]
                name=village_$x1|_$y1|_cleared
                not_equals=yes
            [/variable]
        [/filter_condition]

        {VARIABLE_OP number_of_guards rand "0..2"}
        {VARIABLE guard_i 1}

        [while]
            [variable]
                name=guard_i
                less_than_equal_to=$number_of_guards
            [/variable]

            [do]
                [store_locations]
                    [filter_adjacent_location]
                        x,y=$x1,$y1
                    [/filter_adjacent_location]

                    [not]
                        [filter]
                        [/filter]
                    [/not]

                    variable=possible_guard_locations
                [/store_locations]

                {IF_VAR possible_guard_locations.length greater_than 0 (
                    [then]
                        {VARIABLE_OP random_location_index rand "0..$($possible_guard_locations.length - 1)"}

                        [move_unit_fake]
                            side=2
                            type=Goblin Spearman
                            x=$x1,$possible_guard_locations[$random_location_index].x
                            y=$y1,$possible_guard_locations[$random_location_index].y
                        [/move_unit_fake]

                        [unit]
                            id=guard_$x1|_$y1|_$guard_i
                            name= _ "Villager"
                            type=Goblin Spearman
                            side=2
                            x,y=$possible_guard_locations[$random_location_index].x,$possible_guard_locations[$random_location_index].y
                            random_traits=yes
                        [/unit]
                    [/then]
                )}

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

        {VARIABLE village_$x1|_$y1|_cleared yes}

        # Trigger an easter egg sometime after a third of villages have been taken
        [if]
            [variable]
                name=done_shaun
                not_equals=yes
            [/variable]
            [variable]
                name=number_of_guards
                numerical_equals=2
            [/variable]
            [have_location]
                owner_side=1
                count=4-99
            [/have_location]

            # Make sure the guards actually exist, in case there was no space for them
            [have_unit]
                # wmllint: recognize guard_$x1|_$y1|_1
                id=guard_$x1|_$y1|_1
            [/have_unit]
            [have_unit]
                # wmllint: recognize guard_$x1|_$y1|_2
                id=guard_$x1|_$y1|_2
            [/have_unit]

            [then]
                [modify_unit]
                    [filter]
                        id=guard_$x1|_$y1|_1
                    [/filter]
                    #po: Shaun and Ed are characters from the zombie film "Shaun of the Dead".
                    #po: If the names cannot be translated into your language so that the
                    #po: movie reference remains recognizable, then simply translate these the
                    #po: same as "Villager" above.
                    name= _ "Shaun"
                [/modify_unit]
                [modify_unit]
                    [filter]
                        id=guard_$x1|_$y1|_2
                    [/filter]
                    name= _ "Ed"
                [/modify_unit]

                {VARIABLE done_shaun yes}
            [/then]
        [/if]

        {CLEAR_VARIABLE number_of_guards,guard_i,possible_guard_locations,random_location_index}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=15,11
        [/filter]

        [message]
            speaker=Darken Volk
            message=_ "Ahhh... I did not realize there was a swamp near this village. Malin, I believe it would be beneficial for your training if you and I were to investigate the swamp."
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto
        [filter]
            [not]
                [not]
                    id=Darken Volk
                [/not]
                [not]
                    id=Malin Keshar
                [/not]
            [/not]
            x=14-15,16-20,19-20
            y=9-10,6-10,11
        [/filter]

        [message]
            speaker=Darken Volk
            message=_ "Rise, rise from the realms of death and decay!"
        [/message]

        [scroll_to]
            x,y=17,8
        [/scroll_to]
        {GENERIC_UNIT 1 Ghoul 19 7}
        [+unit]
            facing=sw
        [/unit]
        {GENERIC_UNIT 1 Ghoul 17 9}
        [+unit]
            facing=sw
        [/unit]
        {GENERIC_UNIT 1 Ghoul 17 8}
        [+unit]
            facing=sw
        [/unit]

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Malin Keshar
            message=_ "What are those things?"
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "They are ghouls. Once, they were... evil men... murderers and outlaws. Through magic they have been transformed so their outsides match the spirits within. Those that outlive their masters gravitate towards the swamps and bogs, drawn by the natural decay there."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "It seems cruel to turn men into such a hideous form."
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "In their present form they can best serve the greater good. Even now they will aid you in defeating this goblin rabble. Besides, as I said, these were men of great evil. No punishment is too great for their kind."
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "I suppose so..."
        [/message]
    [/event]

    # Defeat Conditions
    {MALIN_DEATH}
    {VOLK_DEATH}
    {TIME_OUT_LOSE}

    # Victory Condition

    [event]
        name=capture
        first_time_only=no
        [filter]
            side=1
        [/filter]
        #   {VARIABLE_OP villages_owned add 1}
        #when capturing a village we check if we own all villages of the map
        [if]
            [have_location]
                terrain=*^V*

                [not]
                    owner_side=1
                [/not]
            [/have_location]

            [else]
                [message]
                    speaker=Malin Keshar
                    message=_ "Sacking goblin villages is all well and good, but walking corpses and bats won’t stand up to full orcish warriors."
                [/message]
                [message]
                    speaker=Darken Volk
                    message=_ "Your training is just beginning, Malin. With the souls from these goblins now available for our use, you will see your forces grow quickly."
                [/message]
                [message]
                    speaker=Malin Keshar
                    message=_ "Excellent. I’m eager to move on to the real foes."
                [/message]

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

    [event]
        name=victory

        [store_villages]
            variable=villages
        [/store_villages]

        {FOREACH villages i}
            {VARIABLE_OP village_var value "village_$villages[$i].x|_$villages[$i].y|_cleared"}

            {CLEAR_VARIABLE $village_var}
        {NEXT i}

        {CLEAR_VARIABLE villages,village_var,done_shaun}
    [/event]
[/scenario]
