#textdomain wesnoth-did

[scenario]
    id=04_Spring_of_Reprisal
    name= _ "Spring of Reprisal"
    map_file=04_Spring_of_Reprisal.map
    {TURNS 30 28 26}
    next_scenario=05_Schism
    victory_when_enemies_defeated=yes

    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC       the_city_falls.ogg}
    {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}
    {EXTRA_SCENARIO_MUSIC vengeful.ogg}

    [story]
        [part]
            music=underground.ogg
            story= _ "Weeks pass in the cold, bare caverns. As the grip of black magic grows stronger, so does Malin’s control of the undead. He finds it to be a mastery of a different sort than what he was taught at the Academy. The magic reaches out to him as it never has before; he listens and it speaks back — he senses its will and lets it guide him — he embraces the dark magic as an extension of himself."
            {STORYTXT_BACKGROUND travel.webp}
        [/part]
        [part]
            story= _ "When spring comes, Darken Volk leads Malin toward the jagged mountain peaks in the north. In the higher reaches, snow begins to melt into rivulets of water, streaming downward and fracturing the surface of the ice that blankets the river Listra. Though the unstable terrain is hazardous to traverse, the elder necromancer insists that they press on, saying that he hopes to catch the orcish fighters unprepared by arriving early in the year."
            {STORYTXT_BACKGROUND travel.webp}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_04_NEW}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton
        {GOLD 180 150 120}
        team_name=good
        user_team_name= _ "Malin Keshar"
        {FLAG_VARIANT undead}
        color=darkblue

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

        facing=nw
    [/side]
    # wmllint: validate-on

    {STARTING_VILLAGES 1 5}

    [side]
        side=2
        controller=ai
        recruit=Orcish Archer,Orcish Crossbowman,Wolf Rider,Orcish Grunt
        {GOLD 15 30 45}
        {INCOME 2 4 6}
        team_name=orcs
        user_team_name= _ "Orcs"
        {FLAG_VARIANT6 ragged}
        color=white

#ifdef HARD
        type=Orcish Warlord
#else
        type=Orcish Warrior
#endif
        id="Gron'r Hronk"
        name= _ "Gron’r Hronk"
        canrecruit=yes

        facing=nw

        [ai]
            aggression=0.5
            caution=0.1
            villages_per_scout=8
            village_value=0.5
            recruitment_pattern=scout,archer,archer,fighter
        [/ai]
    [/side]

    {STARTING_VILLAGES 2 5}

    [side]
        side=3
        controller=ai
        recruit=Orcish Archer,Orcish Crossbowman,Wolf Rider,Goblin Pillager,Orcish Grunt
        {GOLD 50 60 70}
        {INCOME 2 3 4}
        team_name=orcs
        user_team_name= _ "Orcs"
        {FLAG_VARIANT6 ragged}
        color=white

        type=Orcish Warlord
        id="K'rrlar Oban"
        name=_ "K’rrlar Oban"
        canrecruit=yes

        facing=sw

        [ai]
            aggression=0.5
            caution=0.2
            villages_per_scout=6
            recruitment_pattern=archer,scout,fighter
        [/ai]
    [/side]

    {STARTING_VILLAGES 3 5}

    # Signpost at the end of the pass
    {PLACE_IMAGE scenery/signpost.png 17 1}
    {PLACE_IMAGE scenery/whitefang-flag.png 11 6}
    {PLACE_IMAGE scenery/whitefang-flag.png 8 24}
    {PLACE_IMAGE items/burial.png 13 24}
    {PLACE_IMAGE items/book2.png 24 6}
    {PLACE_IMAGE items/bones.png 3 3}
    {PLACE_IMAGE scenery/orcish-flag-flat.png 2 2}

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        # we're looking at DiD through Malin's eyes, so scenarios get slightly darker as time goes on...
        {COLOR_ADJUST -10 -10 -10}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Move Malin to the end of the mountain pass"
            [/objective]
            [objective]
                {ALTERNATIVE_OBJECTIVE_CAPTION}
                condition=win
                description= _ "Kill the orc leaders"
            [/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]

        [lua]
            code=<<
-- For prime-time use the filter terrain needs to come in and the convert
-- table needs to be VERY complete. Or, rename this to morph_terrain and
-- have the conversion table come in as an argument, too.

local locations = wesnoth.map.find{terrain = 'Gd,Gd^Es,Gd^Em,Gd^Fmw,Gd^Fdw,Hh,Hh^Fdw,Hh^Fmw,Mm,Mm^Xm'}

local coverage = 0.25
-- Constant 25% random coverage.
-- Valid range is (0.0 .. 1.0)
-- Do not raise too high or player may not be able to make it in the time allotted.

local snowNeeded = (#locations * coverage)

local convert = {
    ['Gd'] = 'Aa',
    ['Gd^Es'] = 'Aa',
    ['Gd^Em'] = 'Aa^Vca',
    ['Gd^Fmw'] = 'Aa^Fma',
    ['Gd^Fdw'] = 'Aa^Fpa',
    ['Hh'] = 'Ha',
    ['Hh^Fdw'] = 'Ha^Fdw',
    ['Hh^Fmw'] = 'Ha^Fmw',
    ['Mm'] = 'Ms',
    ['Mm^Xm'] = 'Ms^Xm'
}

local loopCounter
for loopCounter = 1, snowNeeded do
    local locationsIndex = mathx.random(#locations)
    local coordinate = locations[locationsIndex]
    local terrainCode = wesnoth.current.map[coordinate]
    wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode)
    table.remove(locations, locationsIndex)
end
            >>
        [/lua]

        [recall]
            id=Darken Volk
        [/recall]

        {MODIFY_UNIT (id=Malin Keshar) profile (portraits/malin_old.webp)}
        {MODIFY_UNIT (side=1)          facing   nw}

        {VARIABLE slain_orcs 0}
    [/event]

    [event]
        name=start

        [message]
            speaker=Darken Volk
            message= _ "Across this pass lies the eastern edge of the Heart Mountains proper. For their distinctive shape, the orcs call these the ‘Whitefang’ Mountains, which is also the namesake of the dominant clan in this region. They are the very same who killed your father."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "The Whitefang orcs... so that’s their name. When I was younger, I remember fearing the sight of their banners rais’d across the river. Now, though, it’s something totally different. Loathing? Disgust? A desire for vengeance? Certainly... this is no longer a fight merely to protect Parthyn."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Then it is a fight of enmity. For that, you must ensure that your hatred of these orcs is strong enough, else you will never be able to achieve your goal."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "You needn’t worry about my will to fight. I only ask that you lead me to them."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "The fastest way to the core of their dominion lies through this mountain pass. Beyond here lies your main target."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Then let’s go."
        [/message]
    [/event]

    # In-scenario events

    [event]
        name=moveto
        [filter]
            x,y=24,6
            id=Malin Keshar
        [/filter]

        # this is a latin proverb
        [message]
            speaker=narrator
            message= _ "Revenge is a confession of pain."
        [/message]

        {GIVE_MALIN_EXPERIENCE 6}
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=13,24
            side=1
        [/filter]

        # these skulls are close to a fire
        [message]
            speaker=Malin Keshar
            message= _ "These skulls appear to have been gnawed on."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x,y=4,3
            side=1
        [/filter]

        # there's also an orcish flag nearby of a different color
        # I guess the whitefangs are kind of brutal
        [message]
            speaker=Malin Keshar
            message= _ "Someone was pushed off from here."
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            race=orc
            [not]
                canrecruit=yes
            [/not]
        [/filter]

        [filter_second]
            id=Malin Keshar
        [/filter_second]

        [switch]
            variable=slain_orcs
            [case]
                value=0
                [message]
                    speaker=Malin Keshar
                    message=_ "The best orc is a dead orc."
                [/message]
            [/case]
            [case]
                value=1
                [message]
                    speaker=Malin Keshar
                    message=_ "There is a strange comfort in watching you die."
                [/message]
            [/case]
            [case]
                value=2
                [message]
                    speaker=Malin Keshar
                    message=_ "Feel my wrath!"
                [/message]
            [/case]
            [case]
                value=3
                # this is a quote from warcraft 3's dreadlord
                [message]
                    speaker=Malin Keshar
                    message=_ "Your soul is mine!"
                [/message]
            [/case]
        [/switch]
        {VARIABLE_OP slain_orcs add 1}
    [/event]

    [event]
        name=die
        [filter]
            id="Gron'r Hronk"
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message=_ "These orcs aren’t so strong after all!"
        [/message]
    [/event]

    [event]
        name=last breath
        first_time_only=yes
        [filter]
            id="K'rrlar Oban"
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker="K'rrlar Oban"
            message=_ "Wait, human! I may be of use to you! What is it that you desire? Slaves? Gold? Land?"
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "What I desire is your death."
        [/message]

        [kill]
            id="K'rrlar Oban"
            animate=yes
            fire_event=yes
        [/kill]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1

            [not]
                type_adv_tree=Ghost,Vampire Bat
            [/not]
            [and]
                [not]
                    type=Spectral Servant,Phantom,Eidolon
                [/not]
            [/and]

            [filter_location]
                terrain=Ai
            [/filter_location]
        [/filter]

        [message]
            speaker=Malin Keshar
            message= _ "The ice doesn’t look very thick..."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "..."
        [/message]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        [store_locations]
            [filter]
                [not]
                    type_adv_tree=Ghost,Vampire Bat
                [/not]
                [and]
                    [not]
                        type=Spectral Servant,Phantom,Eidolon
                    [/not]
                [/and]
            [/filter]

            find_in=weakened_ice

            variable=breaking_ice
        [/store_locations]

        [foreach]
            array=breaking_ice
            [do]
                [scroll_to]
                    x,y=$this_item.x,$this_item.y
                [/scroll_to]

                [terrain]
                    x,y=$this_item.x,$this_item.y
                    terrain=Wo
                [/terrain]

                [remove_item]
                    x,y=$this_item.x,$this_item.y
                    image=misc/weakened-ice.png
                [/remove_item]

                [redraw][/redraw]

                [if]
                    [have_unit]
                        x,y=$this_item.x,$this_item.y
                        race=undead
                    [/have_unit]
                    [then]
                        [message]
                            speaker=narrator
                            image=wesnoth-icon.png
                            message= _ "The weak ice gives way beneath the undead creature, who becomes mired in the thick mud at the lake’s bottom."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=narrator
                            image=wesnoth-icon.png
                            message=_ "The weak ice gives way beneath the heavy warrior, who drowns in the frigid mountain waters."
                        [/message]
                    [/else]
                [/if]

                [sound]
                    name=water-blast.wav
                [/sound]

                [kill]
                    x,y=$this_item.x,$this_item.y
                    animate=yes
                    fire_event=yes
                [/kill]
            [/do]
        [/foreach]

        [store_locations]
            terrain=Ai
            [filter]
                [not]
                    type_adv_tree=Ghost,Vampire Bat
                [/not]
                [and]
                    [not]
                        type=Spectral Servant,Phantom,Eidolon
                    [/not]
                [/and]
            [/filter]

            [or]
                terrain=Ai

                find_in=weakened_ice
            [/or]

            variable=weakened_ice
        [/store_locations]

        [foreach]
            array=weakened_ice
            [do]
                [item]
                    x,y=$this_item.x,$this_item.y
                    image=misc/weakened-ice.png
                [/item]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE breaking_ice}
    [/event]

    # Victory Condition
    [event]
        name=moveto
        [filter]
            id=Malin Keshar
            x,y=17,1
        [/filter]

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

    [event]
        name=enemies defeated

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

    [event]
        name=victory

        # At last... we shall have revenge is a quote from Illidan, the demon hunter in warcraft 3
        [message]
            speaker=Malin Keshar
            message= _ "We’ve finally a chance to strike at the heart of the Whitefang’s territory. At last... we shall have revenge."
        [/message]

        {CLEAR_VARIABLE weakened_ice,slain_orcs}
    [/event]

    {HERODEATH_MALIN}
    {HERODEATH_VOLK}

    {TIME_OVER_DEFEAT}
[/scenario]
