#textdomain wesnoth-did

[scenario]
    id=03_A_Haunting_in_Winter
    name= _ "A Haunting in Winter"
    map_file=03_A_Haunting_in_Winter.map
    victory_when_enemies_defeated=no
    turns=unlimited
    next_scenario=04_Spring_of_Reprisal

    [time_area]
        x=15-16
        y=20-21
        {DEFAULT_SCHEDULE}
    [/time_area]
    {UNDERGROUND}

    {SCENARIO_MUSIC       the_deep_path.ogg}
    {EXTRA_SCENARIO_MUSIC underground.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    [story]
        [part]
            music=transience.ogg
            story=_ "Malin and Darken Volk spend the summer and fall traveling across the lower Northlands. They attack goblin villages and small orcish camps when they find them. Although Darken Volk is occasionally demanding and irritable, he proves to be an effective mentor. Malin’s power grows considerably under the necromancer’s tutelage."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story=_ "The colored patchwork of fall eventually fades to wintry snowfall drifting over barren lands. The nights grow longer as the sun disappears behind a seemingly perpetual mist of pallid clouds. Hounded by the elements, the two necromancers retreat into the hills to seek shelter. By a stroke of good fortune, they stumble across a mostly abandoned cave just as the winter sets in."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_03_NEW}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Walking Corpse,Vampire Bat,Ghoul
        income=-2
        village_gold=0
        {GOLD 60 50 40}
        village_support=2
        team_name=good
        user_team_name= _ "Malin Keshar"
        {FLAG_VARIANT undead}
        color=darkblue

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

        shroud=yes
        facing=ne
    [/side]
    # wmllint: validate-on

    [side]
        side=2
        controller=ai
        no_leader=yes
        hidden=yes
        team_name=monsters
        user_team_name= _ "teamname^Monsters"
        color=orange
        [ai]
            aggression=1.0
            caution=0.0
            grouping=no
            simple_targeting=yes
            village_value=0
            [goal]
                name=target
                [criteria]
                    side=1
                [/criteria]
                value=100
            [/goal]
            [goal]
                name=target
                [criteria]
                    side=3
                [/criteria]
                value=-100
            [/goal]
        [/ai]
    [/side]

    [side]
        side=3
        controller=ai
        no_leader=yes
        hidden=yes
        team_name=good
        user_team_name= _ "Darken Volk"
        color=black
    [/side]

    [side]
        side=4
        controller=ai
        no_leader=yes
        hidden=yes
        team_name=spirits
        user_team_name= _ "teamname^Illusion"
        color=darkblue
        # Using the same flag icon and color as the next side, one can't spot it in the top bar
        flag_icon=flags/undead-flag-icon.png
        [ai]
            aggression=1.0
            caution=0.0
        [/ai]
    [/side]

#define OBJECTIVE_EXPLORE
    [objectives]
        side=1
        [objective]
            condition=win
            description= _ "Explore"
        [/objective]
        [objective]
            condition=lose
            description= _ "Death of Malin Keshar"
        [/objective]
        [gold_carryover]
            carryover_percentage=100
        [/gold_carryover]
    [/objectives]
#enddef

#define FULL_HEAL_RESTORE FILTER
    [heal_unit]
        [filter]
            {FILTER}
        [/filter]

        amount=full
        moves=full
        restore_statuses=yes
        restore_attacks=yes
    [/heal_unit]
    {CLEAR_VARIABLE heal_amount}
#enddef

    {PLACE_IMAGE scenery/summoning-circle3.png 26 5}
    {PLACE_IMAGE items/storm-trident.png 29 10}
    {PLACE_IMAGE items/potion-clear.png 2 2}
    {PLACE_IMAGE scenery/nest-empty.png 9 7}

    {PLACE_IMAGE scenery/castle-ruins.png 5 6}
    {PLACE_IMAGE scenery/castle-ruins2.png 2 3}
    {PLACE_IMAGE scenery/orcish-flag-flat2.png 2 5}
    {PLACE_IMAGE scenery/orcish-flag-flat2.png 4 5}
    {PLACE_IMAGE scenery/orcish-flag-flat2.png 11 3}
    {PLACE_IMAGE items/bonestack.png 5 5}
    {PLACE_IMAGE scenery/whitefang-flag.png 4 6}

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        [label]
            x,y=5,17
            text= _ "Reflection pool"
        [/label]

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Kill both young ogres"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [gold_carryover]
                carryover_percentage=100
            [/gold_carryover]
        [/objectives]

        [recall]
            id=Darken Volk
        [/recall]

        [unit]
            type=Young Ogre
            x,y=25,17
            side=2
            id=YOgre1
            hitpoints=38
            facing=sw
            ai_special=guardian
            undead_variation=null
            [modifications]
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        # Non-strong one:
        # wmllint: recognize YOgre2
        [while]
            [not]
                [have_unit]
                    id=YOgre2
                    [not]
                        trait=strong
                    [/not]
                [/have_unit]
            [/not]
            [do]
                [unit]
                    type=Young Ogre
                    x,y=24,17
                    side=2
                    id=YOgre2
                    hitpoints=33
                    facing=ne
                    ai_special=guardian
                    undead_variation=null
                    overwrite=yes
                [/unit]
            [/do]
        [/while]

        {PLACE_IMAGE "items/bow.png" 17 8}
        [unit]
            type=Ogre
            x,y=18,6
            side=2
            id=Ogre3
            ai_special=guardian
            undead_variation=null
        [/unit]

        [unit]
            type=Wolf
            x,y=1,5
            side=2
            ai_special=guardian
            random_traits=no
            [modifications]
                {TRAIT_MAIMED}
            [/modifications]
        [/unit]

        [unit]
            type=Wolf
            x,y=6,8
            side=2
            ai_special=guardian
            random_traits=no
            [modifications]
                {TRAIT_MAIMED}
            [/modifications]
        [/unit]

        [unit]
            type=Wolf
            x,y=5,5
            side=2
            ai_special=guardian
            random_traits=no
            [modifications]
                {TRAIT_MAIMED}
            [/modifications]
        [/unit]

        [unit]
            type=Wolf
            x,y=4,2
            side=2
            ai_special=guardian
            random_traits=no
            [modifications]
                {TRAIT_MAIMED}
            [/modifications]
        [/unit]

#ifdef EASY
        [unit]
            type=Great Wolf
            x,y=3,7
            side=2
            ai_special=guardian
            random_traits=no
            [modifications]
                {TRAIT_MAIMED}
            [/modifications]
        [/unit]
#else
        [unit]
            type=Direwolf
            x,y=3,7
            side=2
            ai_special=guardian
            random_traits=no
            [modifications]
                {TRAIT_MAIMED}
            [/modifications]
        [/unit]
#endif
        [remove_shroud]
            x=13-16,12,12
            y=11-21,13-14,17-19
        [/remove_shroud]

        [unit]
            type=Giant Scorpion
            x,y=8,9
            side=2
            level=2
            id=Big Scorpion
            ai_special=guardian
            max_moves=1
            max_hitpoints=66
        [/unit]

        {MODIFY_UNIT (id=Darken Volk) max_moves 0}
        {MODIFY_UNIT (id=Darken Volk) moves 0}
        {MODIFY_UNIT (id=Darken Volk) side 3}

        {VARIABLE mud_puzzle 0}
        {VARIABLE rat_puzzle 0}
    [/event]

    [event]
        name=start

        [message]
            speaker=Darken Volk
            message= _ "I sense many lifeforms in this cavern, but none are very powerful. Most likely they are merely nothing more than beasts. Still, we may be able to use them to continue your training."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Better than nothing. Which way do these creatures lie?"
        [/message]

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

        [move_unit]
            id=Malin Keshar
            to_x,to_y=20,13
        [/move_unit]
        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]
        [scroll_to]
            x,y=24,17
        [/scroll_to]

        [message]
            speaker=YOgre1
            message= _ "Me kill you!"
        [/message]

        [harm_unit]
            [filter]
                id=YOgre2
            [/filter]
            [filter_second]
                id=YOgre1
            [/filter_second]
            [primary_attack]
                name=cleaver
            [/primary_attack]
            [secondary_attack]
                name=cleaver
            [/secondary_attack]
            animate=yes
            amount=6
        [/harm_unit]

        [message]
            speaker=YOgre2
            message= _ "No, me kill you!"
        [/message]

        [harm_unit]
            [filter]
                id=YOgre1
            [/filter]
            [filter_second]
                id=YOgre2
            [/filter_second]
            [primary_attack]
                name=cleaver
            [/primary_attack]
            [secondary_attack]
                name=cleaver
            [/secondary_attack]
            animate=yes
            amount=5
        [/harm_unit]

        [message]
            speaker=YOgre1
            message= _ "No, me kill— I see human!"
        [/message]

        [message]
            speaker=YOgre2
            message= _ "Human! We smash human!"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Simple-minded, obtuse creatures."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "This should be an easy task for you. Once you have slain them both, we shall turn them into skeletons."
        [/message]
    [/event]

    # First area (two young ogres)
    [event]
        name=last breath
        [filter]
            id=YOgre1
        [/filter]

        [message]
            speaker=YOgre1
            # po: this line is just a death scream
            message= _ "Arrghhaaugghhh..." # wmllint: no spellcheck
        [/message]

        {PLACE_IMAGE "items/bones.png" $x1 $y1}

        {VARIABLE loc1.x $x1}
        {VARIABLE loc1.y $y1}
    [/event]
    [event]
        name=last breath
        [filter]
            id=YOgre2
        [/filter]

        [message]
            speaker=YOgre2
            message= _ "Me... die..."
        [/message]

        {PLACE_IMAGE "items/bones.png" $x1 $y1}

        {VARIABLE loc2.x $x1}
        {VARIABLE loc2.y $y1}
    [/event]

    [event]
        name=die
        first_time_only=no

        [filter]
            id=YOgre1,YOgre2
        [/filter]

        [if]
            [not]
                [have_unit]
                    id=YOgre1,YOgre2
                [/have_unit]
            [/not]
            [then]
                # if Malin is the one to kill the last ogre, he doesn't get the exp because he gets moved off the hex
                # so this will give it to him manually
                [if]
                    [have_unit]
                        x,y=$x2,$y2
                        id=Malin Keshar
                    [/have_unit]
                    [then]
                        [store_unit]
                            [filter]
                                id=Malin Keshar
                            [/filter]
                            variable=malin
                        [/store_unit]

                        {VARIABLE_OP malin.experience add 8}
                        [unstore_unit]
                            variable=malin
                        [/unstore_unit]

                        {CLEAR_VARIABLE malin}
                    [/then]
                [/if]

                # this is necessary to stop the units from blocking their hexes
                [kill]
                    id=YOgre1,YOgre2
                [/kill]
                [fire_event]
                    name=cutscene1
                [/fire_event]
            [/then]
        [/if]
    [/event]
    [event]
        name=cutscene1

        {FULL_HEAL_RESTORE (side=1)}

        [message]
            speaker=Malin Keshar
            message= _ "The ogres are dead."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Good... I have already showed you how to raise a skeleton before, but perhaps it would be best if we... went over it once again. Other than for ghouls, flesh and blood are useless for undead creatures. First, let out the blood and innards and dispose of them."
        [/message]

        [message]
            speaker=Malin Keshar
            # po: In the sense of "Understood, I will do that", not "very good".
            message= _ "Very well."
        [/message]

        [move_unit]
            id=Malin Keshar
            to_x,to_y=$loc1.x,$loc1.y
        [/move_unit]

        [sound]
            name=axe.ogg
        [/sound]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "What a mess."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Leave it. The ghouls will take care of it in due course. Next, strip away the flesh. A little remaining is fine; too much will hamper your skeletons’ movement."
        [/message]

        [delay]
            time=350
        [/delay]

        [sound]
            name=axe.ogg
        [/sound]

        [delay]
            time=500
        [/delay]

        [sound]
            name=axe.ogg
        [/sound]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "And then?"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Bind the strings of energy to the bone. Skeletons are no more than puppets. Novices will directly control their movement with strands of dark magic, but you should have no need for such crude methods. Instead, impart your will upon the skeleton, spread the threads over the bones, then let loose the twine from your hand. If your will is strong enough, the skeleton will be able to move on its own."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I will try."
        [/message]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]

        {REMOVE_IMAGE $loc1.x $loc1.y}

        [unit]
            type=Skeleton
            x,y=$loc1.x,$loc1.y
            passable=yes
            side=1
            animate=yes
        [/unit]

        [message]
            speaker=Darken Volk
            message= _ "Do it again."
        [/message]

        [delay]
            time=750
        [/delay]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]

        {REMOVE_IMAGE $loc2.x $loc2.y}

        [unit]
            type=Skeleton
            x,y=$loc2.x,$loc2.y
            passable=yes
            side=1
            animate=yes
        [/unit]

        [terrain]
            x=19,20,20
            y=9,9,8
            terrain=Ur
        [/terrain]
        [redraw][/redraw]

        {CLEAR_VARIABLE loc1}
        {CLEAR_VARIABLE loc2}

        [message]
            speaker=Darken Volk
            message= _ "Good. Now head north. I sense another ogre there."
        [/message]

        {OBJECTIVE_EXPLORE}
    [/event]

    [event]
        name=sighted
        [filter]
            id=Ogre3
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "I can turn this one into a skeleton as well."
        [/message]
    [/event]

    # Second mini area (third young ogre)
    [event]
        name=die
        first_time_only=yes
        [filter]
            id=Ogre3
        [/filter]

        {FULL_HEAL_RESTORE (side=1)}

        {PLACE_IMAGE "items/bones.png" $x1 $y1}

        [kill]
            id=Ogre3
        [/kill]

        [remove_shroud]
            x,y=17,8
            radius=1
        [/remove_shroud]

        [scroll_to]
            x,y=17,8
        [/scroll_to]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Darken Volk
            message= _ "The ogre seems to have looted a bow. Use it to create a Skeleton Archer."
        [/message]

        [message]
            speaker=Malin Keshar
            # po: That's the case for both usages of this string.
            message= _ "Very well."
        [/message]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]

        [unit]
            type=Skeleton Archer
            x,y=$x1,$y1
            side=1
            animate=yes
            passable=yes
        [/unit]

        {REMOVE_IMAGE $x1 $y1}
        {REMOVE_IMAGE 17 8}

        [message]
            speaker=Darken Volk
            message= _ "It seems that raising skeletons is already a trivial matter for you now. You are indeed... talented."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Perhaps, but I will need more than a few skeletons to fight the orcs."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "They will come in time, when you learn to control more of them at once. For now, continue exploring these caves. We may yet find something else of use."
        [/message]

        [terrain]
            x=24,25,24,25,21,22
            y=10,10,11,11,6,6
            terrain=Rb
        [/terrain]
        [terrain]
            x=21,15,17
            y=7,5,5
            terrain=Uu
        [/terrain]
        [terrain]
            x=16,16
            y=4,5
            terrain=Ur
        [/terrain]
        [redraw][/redraw]

        {GENERIC_UNIT 2 (Giant Mudcrawler) 24 5}
        {GENERIC_UNIT 2 (Giant Mudcrawler) 26 6}
        {GENERIC_UNIT 2 (Giant Mudcrawler) 27 7}
        {GENERIC_UNIT 2 (Giant Mudcrawler) 26 4}

        [unit]
            type=Giant Rat
            x,y=8,2
            side=2
            level=1
            id=Big Rat
            ai_special=guardian
            max_moves=3
            max_hitpoints=40
        [/unit]

        {VARIABLE mud_puzzle 1}
        {VARIABLE rat_puzzle 1}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Reach the end of the cave"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [gold_carryover]
                carryover_percentage=100
            [/gold_carryover]
        [/objectives]
    [/event]

    # Third area (mudcrawler puzzle)

    # not part of the puzzle, but justifies why there's a storm trident here
    [event]
        name=moveto
        [filter]
            x,y=29,11
            side=1
        [/filter]

        {PLACE_IMAGE "items/bones.png" $x1 $y1}

        [message]
            speaker=Malin Keshar
            message= _ "It seems like a merman used to live here."
        [/message]
    [/event]
    [event]
        name=sighted
        [filter]
            type=Giant Mudcrawler
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "Ick. Mudcrawlers. How did these things end up here?"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "The magic of our world is unpredictable and random. Even without the interference of a trained mage, it sometimes coagulates by itself, giving rise to physical anomalies or breathing life into the inanimate. See there?"
        [/message]

        [remove_shroud]
            x,y=26,5
            radius=3
        [/remove_shroud]

        [scroll_to]
            x,y=26,5
        [/scroll_to]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Darken Volk
            message= _ "It is merely a small eddy of energy, but enough to animate the swamp water."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I see. Well, even if these mudcrawlers are not much of a threat, they’re still bothersome. I wonder if I could be rid of them. What is magic mud even weak to, anyway? Fire?"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "You should be able to figure it out on your own."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... I suppose you’re right."
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=29,10
            side=1
            [not]
                id=Malin Keshar
            [/not]
        [/filter]
        [filter_condition]
            [variable]
                name=mud_puzzle
                numerical_equals=1
            [/variable]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "It looks like there is something mired in the mud over there. I should have a look."
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=29,10
            id=Malin Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=mud_puzzle
                numerical_equals=1
            [/variable]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "Hmm, a storm trident. I wonder if it could be useful."
        [/message]

        {REMOVE_IMAGE 29 10}

        {VARIABLE mud_puzzle 2}
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=23,6
            id=Malin Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=mud_puzzle
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "I can use the trident to set these trees aflame."
        [/message]

        [sound]
            name=lightning.ogg
        [/sound]

        [delay]
            time=1000
        [/delay]

        [sound]
            name=fire.wav
        [/sound]

        [delay]
            time=750
        [/delay]

        [terrain]
            x,y=23,6
            terrain=Rb
        [/terrain]
        [redraw][/redraw]

        [unit_overlay]
            id=Malin Keshar
            image="misc/fire-icon.png"
            object_id="fire_icon"
        [/unit_overlay]

        {VARIABLE mud_puzzle 3}
    [/event]
    [event]
        name=moveto
        first_time_only=no
        [filter]
            x,y=26,5
            id=Malin Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=mud_puzzle
                less_than=4
            [/variable]
        [/filter_condition]

        [if]
            [variable]
                name=mud_puzzle
                numerical_equals=3
            [/variable]
            [then]
                [message]
                    speaker=Malin Keshar
                    message= _ "Let’s see if this fire does anything."
                [/message]

                [remove_object]
                    id=Malin Keshar
                    object_id="fire_icon"
                [/remove_object]

                [sound]
                    name=fire.wav
                [/sound]

                [delay]
                    time=1000
                [/delay]

                [sound]
                    name=flame-big.ogg
                [/sound]

                [delay]
                    time=500
                [/delay]

                {REMOVE_IMAGE 26 5}

                [delay]
                    time=500
                [/delay]

                [message]
                    speaker=Malin Keshar
                    message= _ "I think that did it. No more pesky crawlers."
                [/message]

#ifdef EASY
                {GIVE_MALIN_EXPERIENCE 30}
#endif
#ifdef NORMAL
                {GIVE_MALIN_EXPERIENCE 25}
#endif
#ifdef HARD
                {GIVE_MALIN_EXPERIENCE 20}
#endif

                {VARIABLE mud_puzzle 4}
            [/then]
            [else]
                [message]
                    speaker=narrator
                    message= _ "Nothing happens."
                [/message]
            [/else]
        [/if]
    [/event]

    # only give the player 1 exp on killing mudcrawlers and giant rats, otherwise it's too easy to farm exp
    # since the filter is level=0, it doesn't affect the big rat you encounter
    [event]
        name=die
        first_time_only=no
        [filter]
            level=0
            [not]
                side=1
            [/not]
        [/filter]

        [store_unit]
            [filter]
                x,y=$x2,$y2
            [/filter]
            variable=s_unit
        [/store_unit]

        {VARIABLE_OP s_unit.experience sub 3}

        [unstore_unit]
            variable=s_unit
        [/unstore_unit]

        [if]
            [variable]
                name=unit.type
                equals=Mudcrawler
            [/variable]
            [then]
                [fire_event]
                    name=crawler hint
                [/fire_event]
            [/then]
            [else]
                [fire_event]
                    name=rat hint
                [/fire_event]

                # I swear if you just sit here eating rats all day...
                [if]
                    [variable]
                        name=s_unit.type
                        equals=Necrophage
                    [/variable]
                    [or]
                        [variable]
                            name=s_unit.type
                            equals=Ghast
                        [/variable]
                    [/or]
                    [and]
                        [variable]
                            name=s_unit.max_hitpoints
                            greater_than=111
                        [/variable]
                    [/and]
                    [then]
                        [fire_event]
                            name=rat eating1
                        [/fire_event]
                    [/then]
                [/if]
                [if]
                    [variable]
                        name=s_unit.type
                        equals=Necrophage
                    [/variable]
                    [or]
                        [variable]
                            name=s_unit.type
                            equals=Ghast
                        [/variable]
                    [/or]
                    [and]
                        [variable]
                            name=s_unit.max_hitpoints
                            greater_than=419
                        [/variable]
                    [/and]
                    [then]
                        [fire_event]
                            name=rat eating2
                        [/fire_event]
                    [/then]
                [/if]
                [if]
                    [variable]
                        name=s_unit.type
                        equals=Necrophage
                    [/variable]
                    [or]
                        [variable]
                            name=s_unit.type
                            equals=Ghast
                        [/variable]
                    [/or]
                    [and]
                        [variable]
                            name=s_unit.max_hitpoints
                            greater_than=999
                        [/variable]
                    [/and]
                    [then]
                        [fire_event]
                            name=rat eating3
                        [/fire_event]
                    [/then]
                [/if]

                # there's no way you do this without debug, right?
                [if]
                    [variable]
                        name=s_unit.type
                        equals=Necrophage
                    [/variable]
                    [or]
                        [variable]
                            name=s_unit.type
                            equals=Ghast
                        [/variable]
                    [/or]
                    [and]
                        [variable]
                            name=s_unit.max_hitpoints
                            greater_than=9999
                        [/variable]
                    [/and]
                    [then]
                        [fire_event]
                            name=rat eating4
                        [/fire_event]
                    [/then]
                [/if]
            [/else]
        [/if]

        {CLEAR_VARIABLE s_unit}
    [/event]
    [event]
        name=crawler hint

        [message]
            speaker=Malin Keshar
            message= _ "Somehow, I feel that killing these mudcrawlers is a less than meaningful use of my time."
        [/message]
    [/event]
    [event]
        name=rat hint

        [message]
            speaker=Malin Keshar
            message= _ "I don’t think there’s much experience to be gained by fighting a few rats."
        [/message]
    [/event]
    [event]
        name=rat eating1

        [message]
            speaker=Malin Keshar
            message= _ "I must be absolutely mad to be spending hours here just feeding rats to this rotten pile of flesh..."
        [/message]
    [/event]
    [event]
        name=rat eating2

        [message]
            speaker=Darken Volk
            message= _ "Has this boy been smoking again?"
        [/message]
    [/event]
    [event]
        name=rat eating3

        [message]
            speaker=Malin Keshar
            message= _ "Day 1337:

All sense of time and being are entombed within darkness. How long has passed since I came here? My senses are a blur. My past life, my prior goals, my very self is all but a distant memory. All I know now is the constant squealing of rats and the ever growing mountain of flesh that feasts before me."
        [/message]
    [/event]
    [event]
        name=rat eating4

        #po: Malin Keshar breaks the fourth wall here and addresses the player, whom the 'you' refers to.
        [message]
            speaker=Malin Keshar
            message= _ "You. You there behind the screen. You are the one controlling me. Why are you doing this? What did I do to deserve this torment? Please, I beg of you. End me now. Release me from my misery!"
        [/message]
    [/event]
    # spawn crawlers
    [event]
        name=new turn
        first_time_only=no
        [filter_condition]
            [not]
                [have_unit]
                    type=Mudcrawler
                [/have_unit]
            [/not]
            [and]
                [variable]
                    name=mud_puzzle
                    greater_than=0
                [/variable]
            [/and]
            [and]
                [variable]
                    name=mud_puzzle
                    less_than=4
                [/variable]
            [/and]
        [/filter_condition]

        {GENERIC_UNIT 2 (Mudcrawler) 26 5}
    [/event]
    # spawn rats
    [event]
        name=new turn
        first_time_only=no
        [filter_condition]
            [not]
                [have_unit]
                    type=Giant Rat
                    level=0
                [/have_unit]
            [/not]
            [and]
                [variable]
                    name=rat_puzzle
                    greater_than=0
                [/variable]
            [/and]
            [and]
                [variable]
                    name=rat_puzzle
                    less_than=4
                [/variable]
            [/and]
        [/filter_condition]

        [unit]
            type=Giant Rat
            side=2
            x,y=8,7
            passable=yes
        [/unit]
    [/event]
    # Fourth area (wolves)

    # first some scenery events
    [event]
        name=sighted
        [filter]
            id=Big Rat
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "What a fat rat. I wonder where it came from?"
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            id=Big Scorpion
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Malin Keshar
            message= _ "This scorpion seems unusually large... and poisonous."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            x=10-11,12
            y=2-4,1-3
            side=1
        [/filter]

        [message]
            speaker=Malin Keshar
            message= _ "A tattered, red flag. Some orcs used to live here, but it seems like they were slain in a fierce battle."
        [/message]
    [/event]

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

        # this is a whitefang banner, but Malin only gets introduced to them in the next scenario
        [message]
            speaker=Malin Keshar
            message= _ "This banner is different than the other ones. It looks familiar."
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            type=Wolf
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [remove_shroud]
            x,y=4,4
            radius=3
        [/remove_shroud]

        # implication is that the whitefangs abandoned them because they were maimed in the battle
        [message]
            speaker=Malin Keshar
            message= _ "A pack of wolves, the same that the goblins use as mounts. They were abandoned here for some reason."
        [/message]

        [modify_unit]
            [filter]
                type=Wolf,Great Wolf,Direwolf
            [/filter]
            [effect]
                apply_to=status
                remove=guardian
            [/effect]
        [/modify_unit]
    [/event]

    # rat puzzle
    [event]
        name=moveto
        [filter]
            x,y=2,2
            id=Malin Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=rat_puzzle
                numerical_equals=1
            [/variable]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "An empty vial. I wonder if this could be useful."
        [/message]

        [unit_overlay]
            id=Malin Keshar
            image="misc/potion-icon.png"
            object_id="potion_icon"
        [/unit_overlay]

        {REMOVE_IMAGE 2 2}

        {VARIABLE rat_puzzle 2}
    [/event]
    [event]
        name=die
        [filter]
            id=Big Scorpion
        [/filter]

        {PLACE_IMAGE "items/bones.png" 8 9}
    [/event]
    [event]
        name=moveto
        [filter]
            x,y=8,9
            id=Malin Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=rat_puzzle
                numerical_equals=2
            [/variable]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "This scorpion’s poison gland is still intact. I bet I can make a potion out of it."
        [/message]

        [remove_object]
            id=Malin Keshar
            object_id="potion_icon"
        [/remove_object]

        [unit_overlay]
            id=Malin Keshar
            image="misc/potion-poison-icon.png"
            object_id="potion_poison_icon"
        [/unit_overlay]

        {VARIABLE rat_puzzle 3}
    [/event]
    [event]
        name=moveto
        first_time_only=no
        [filter]
            x,y=8,7
            id=Malin Keshar
        [/filter]
        [filter_condition]
            [variable]
                name=rat_puzzle
                less_than=4
            [/variable]
        [/filter_condition]

        [if]
            [variable]
                name=rat_puzzle
                numerical_equals=3
            [/variable]
            [then]
                [message]
                    speaker=Malin Keshar
                    message= _ "I think I can pour in the poison from here."
                [/message]

                [remove_object]
                    id=Malin Keshar
                    object_id="potion_poison_icon"
                [/remove_object]

                [sound]
                    name=poison.ogg
                [/sound]

                [delay]
                    time=500
                [/delay]

                {REMOVE_IMAGE 9 7}

                [delay]
                    time=500
                [/delay]

                [message]
                    speaker=Malin Keshar
                    message= _ "These rats will no longer bother us."
                [/message]

#ifdef EASY
                {GIVE_MALIN_EXPERIENCE 30}
#endif
#ifdef NORMAL
                {GIVE_MALIN_EXPERIENCE 25}
#endif
#ifdef HARD
                {GIVE_MALIN_EXPERIENCE 20}
#endif

                {VARIABLE rat_puzzle 4}
            [/then]
            [else]
                [fire_event]
                    name=rat nest
                [/fire_event]
            [/else]
        [/if]
    [/event]

    [event]
        name=rat nest

        [message]
            speaker=Malin Keshar
            message= _ "It appears as if there are some rats living here, but the hole in the wall is too small to reach them."
        [/message]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=5,5,6
            y=11,12,12
            id=Malin Keshar
        [/filter]

        [fire_event]
            name=water dialogue
        [/fire_event]

        [message]
            speaker=Malin Keshar
            [option]
                label= _ "I’m ready to learn about controlling spirits."
                [command]
                    [fire_event]
                        name=cutscene2
                    [/fire_event]
                [/command]
            [/option]
            [option]
                label= _ "I’m not ready yet."
            [/option]
        [/message]
    [/event]

    [event]
        name=water dialogue

        [message]
            speaker=Darken Volk
            message= _ "You have done well so far to master the reanimation of skeletons. Now, I shall teach you to control spirits. Are you ready?"
        [/message]
    [/event]

    [event]
        name=cutscene2

        [message]
            speaker=Darken Volk
            message= _ "Mastery over ghosts, especially the more powerful ones, is something even experienced necromancers may struggle with. While other undead are nothing more than mindless slaves upon reanimation, spirits are the souls of their original owners and thus retain some degree of consciousness. If the spirit is stronger than you, it will break free of your hold. To master it, your own soul must be unwavering."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I doubt I shall be overcome by the soul of an orc."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Perhaps, but that is not what I meant. Before you can begin to control other souls, you must first master your own."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "What do you mean? I am proud. I am strong. If it is a matter of conviction—"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "It is not I that you must convince, but yourself. Hold thy tongue and listen. After a great slaughter, even after the corpses are all rotted to nothing but bones, the bridge between the land of death and life is weakened. By placing yourself closer to death, you will better understand who it is that you really are. But you must not speak. Be silent and embrace the darkness."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "..."
        [/message]

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

        [delay]
            time=1500
        [/delay]

        [terrain]
            x=5,5,6
            y=11,12,12
            terrain=Wwg
        [/terrain]
        [redraw][/redraw]

        [delay]
            time=1000
        [/delay]

        [sound]
            name=wail-sml.wav
        [/sound]

        [delay]
            time=750
        [/delay]

        [sound]
            name=wail.wav
        [/sound]

        [delay]
            time=1250
        [/delay]

        [sound]
            name=wail-long.wav
        [/sound]

        [delay]
            time=1500
        [/delay]

        {FADE_TO_BLACK}

        [store_unit]
            [filter]
                [not]
                    id=Malin Keshar
                [/not]
            [/filter]
            variable=units
            kill=yes
        [/store_unit]

        [place_shroud]
            side=1
            x=1-32
            y=1-21
        [/place_shroud]

        [remove_shroud]
            side=1
            x,y=5,16
            radius=2
        [/remove_shroud]

        [store_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            variable=malin
            kill=yes
        [/store_unit]

        [unstore_unit]
            x,y=5,16
            variable=malin
        [/unstore_unit]

        {MODIFY_UNIT (id=Malin Keshar) facing nw}

        {CLEAR_VARIABLE malin}

        [delay]
            time=1500
        [/delay]

        [scroll_to]
            x,y=5,16
        [/scroll_to]

        {FADE_IN}

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "What sorcery is this? Darken Volk, what’s going... on..?"
        [/message]

        [unit]
            type=Apprentice Mage
            id=Fake Malin
            name= _ "Malin Keshar"
            profile=portraits/malin_young.png
            x,y=4,15
            side=4
            facing=se
            animate=yes
            generate_name=no
            random_traits=no
        [/unit]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "Where is everything? Who are you?"
        [/message]

        [message]
            speaker=Fake Malin
            message= _ "I am Malin Keshar."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "No, <i>I</i> am Malin Keshar. Tell me who you are, and this time, make it believable."
        [/message]

        [sound]
            name=wail-sml.wav
        [/sound]

        [unit]
            type=Apprentice Necromancer
            id=Fake Malin
            name= _ "Malin Keshar"
            profile=portraits/malin_old.png
            x,y=4,15
            side=4
            facing=se
            animate=no
            overwrite=yes
            generate_name=no
            random_traits=no
        [/unit]

        [message]
            speaker=Fake Malin
            message= _ "I am Malin Keshar, but no longer the naive, uncertain boy I once was."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I am no boy, nor am I uncertain. And I certainly won’t be questioned by a mere reflection like you."
        [/message]

        [message]
            speaker=Fake Malin
            message= _ "The distorted reflection you see mirrors the reality within. An ever morphing perspective, warped by a profusion of uncertain ambitions."
        [/message]

        # doesn't sound a lot like one goal to me... but he's just a boy, so he can't be expected to recognize that he's contradicting himself
        [message]
            speaker=Malin Keshar
            message= _ "Nonsense. My convictions are strong and my mind is set. I have but one goal. I will gain power. I will master death, and I will use it to protect my home and slaughter these orcs. And I’ll make my family and my people accept me back."
        [/message]

        [message]
            speaker=Fake Malin
            message= _ "When you are drawn in many directions at once, which one will you choose? If you try for them all, you shall be torn apart."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Protecting my home and slaying the orcs are the same thing. If you mean choosing between my family and gaining more power... they will come around and see reason. I will make sure of it."
        [/message]

        [sound]
            name=wail.wav
        [/sound]

        [unit]
            type=Dark Mage
            id=Fake Malin
            name= _ "Malin Keshar"
            profile=portraits/malin_old-decay.png
            x,y=4,15
            side=4
            facing=se
            animate=no
            overwrite=yes
            generate_name=no
            random_traits=no
        [/unit]

        [message]
            speaker=Fake Malin
            message= _ "When you do not have the wisdom to see through the veil of lies you have told yourself, you must not seek the advice of one who only spins the web of deception further."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "Enough with this. No proverbs are going to help me achieve my goals. This is just like back on Alduin. My teachers never understood what I needed. I don’t need to think and I don’t need to philosophize about “the grand nature of my life and my place in the universe.” Right now, I must train my skills with necromancy. That’s it."
        [/message]

        [message]
            speaker=Fake Malin
            message= _ "When you are sad and alone, even all the power in the world will not help you. In the barren void of endless night, will rage and hatred alone be enough to sustain you?"
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "... well, my choice is already made. Rethinking it now is pointless. I have never been one for regrets."
        [/message]

        [delay]
            time=1000
        [/delay]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [kill]
            id=Fake Malin
        [/kill]
        [terrain]
            x,y=4,15
            terrain=Wog
        [/terrain]
        [redraw][/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "... Damn it all. As if I would pay any heed to a twisted doppelganger of myself. Anyway..."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "What did Darken Volk say about it again? “After a great slaughter, even after the corpses are all rotted to nothing but bones, the bridge between the land of death and life is weakened.” If I use that knowledge..."
        [/message]

        [delay]
            time=250
        [/delay]

        [sound]
            name=wail-sml.wav
        [/sound]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "... I should be able to sense the soul past the barrier of life and death..."
        [/message]

        [delay]
            time=500
        [/delay]

        [sound]
            name=wail.wav
        [/sound]

        [delay]
            time=1500
        [/delay]

        [sound]
            name=wail.wav
        [/sound]

        [delay]
            time=1000
        [/delay]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [unit]
            type=Ghost
            x,y=4,15
            side=1
            hitpoints=10
            animate=yes
            passable=yes
            id=S3_Rebel_Soul
        [/unit]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Malin Keshar
            message= _ "I did it! I—"
        [/message]

        # aaand Malin loses control because he's not as confident as he says he is

        [delay]
            time=300
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 4}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 1}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 4}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 1}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 4}
        [delay]
            time=400
        [/delay]

        [message]
            speaker=S3_Rebel_Soul
            message=_ "Freedom! Your sorceries cannot shackle me, Malin the Damned!"
        [/message]

        [message]
            speaker=Malin Keshar
            message=_ "I failed? No... it must have been because the spell was too tricky to master on the first attempt. No matter, no matter. It’s only a single, weak spirit. It should be simple to crush it and exert my will back over it."
        [/message]

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Defeat the rebel ghost"
            [/objective]
            [objective]
                condition=lose
                description= _ "Death of Malin Keshar"
            [/objective]
            [gold_carryover]
                carryover_percentage=100
            [/gold_carryover]
        [/objectives]
    [/event]

    [event]
        name=last breath
        [filter]
            id=S3_Rebel_Soul
        [/filter]

        [message]
            speaker=Malin Keshar
            message= _ "I’ve got you!"
        [/message]

        [animate_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]

        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 1}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 4}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 1}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 4}
        [delay]
            time=400
        [/delay]
        {MODIFY_UNIT (id=S3_Rebel_Soul) side 1}
        [delay]
            time=400
        [/delay]

        [unit]
            x,y=$x1,$y1
            type=Spectral Servant
            variation=SS1
            overwrite=yes
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        [delay]
            time=900
        [/delay]

        {FADE_TO_BLACK}

        [store_unit]
            [filter]
                id=Malin Keshar
            [/filter]
            variable=malin
            kill=yes
        [/store_unit]

        [unstore_unit]
            x,y=5,11
            find_vacant=yes
            variable=malin
        [/unstore_unit]

        [store_unit]
            [filter]
                type=Spectral Servant
            [/filter]
            variable=ghost
            kill=yes
        [/store_unit]

        [unstore_unit]
            x,y=6,10
            find_vacant=yes
            variable=ghost
        [/unstore_unit]

        [place_shroud]
            side=1
            x,y=5,16
            radius=3
        [/place_shroud]

        {CLEAR_VARIABLE malin,ghost}

        [delay]
            time=1500
        [/delay]

        [foreach]
            array=units
            [do]
                [unstore_unit]
                    find_vacant=yes
                    variable=units[$i]
                [/unstore_unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE units}

        {MODIFY_UNIT (id=Darken Volk) max_moves 6}
        {MODIFY_UNIT (id=Darken Volk) moves 6}
        {MODIFY_UNIT (id=Darken Volk) side 1}

        [redraw]
            side=1
            clear_shroud=yes
        [/redraw]

        [scroll_to]
            x,y=5,11
        [/scroll_to]

        {FADE_IN}

        [message]
            speaker=Malin Keshar
            message= _ "I’ve done it! I’ve learned to summon the souls of the dead!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "So you have, and you even managed to regain control of it when it slipped out of your grasp. Well done. Now pay heed. A necromancer’s first ghost is often special — use it carefully, and it will serve you well. Let it escape your control again, and it will be lost to you forever."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "I see. I won’t make the same mistake twice."
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "We shall see. You have done well enough so far, but I still have much more to teach you. Come, we have work to do."
        [/message]

        [endlevel]
            result=victory
            bonus=no
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]

    [event]
        name=victory

        [remove_object]
            id=Malin Keshar
            object_id="fire_icon"
        [/remove_object]

        [remove_object]
            id=Malin Keshar
            object_id="potion_icon"
        [/remove_object]

        [remove_object]
            id=Malin Keshar
            object_id="potion_poison_icon"
        [/remove_object]

        {CLEAR_VARIABLE mud_puzzle,rat_puzzle}
    [/event]

    {HERODEATH_MALIN}
    {HERODEATH_VOLK}
[/scenario]

#undef OBJECTIVE_EXPLORE
#undef FULL_HEAL_RESTORE


#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.jpg}
        [/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.jpg}
        [/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.png)}
        {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]


#textdomain wesnoth-did

[scenario]
    id=05_Schism
    name= _ "Schism"
    map_file=05_Schism.map
    victory_when_enemies_defeated=yes
    turns=37
    next_scenario=06_Return_to_Parthyn

    {DEFAULT_SCHEDULE_MORNING}

    {INTRO_AND_SCENARIO_MUSIC battle.ogg northerners.ogg}
    {EXTRA_SCENARIO_MUSIC northern_mountains.ogg}
    {EXTRA_SCENARIO_MUSIC siege_of_laurelmor.ogg}

    # this is a proper battle scenario really focused on armies for once, so this one doesn't have any really special events; it's nice to have just this one vanilla scenario in the campaign
    # there's also a lot less dialogue here intentionally because Malin's focused on fighting off the orcs
    # when he does kill a chieftain, he doesn't give them time to speak (it's a tough battle, he doesn't spare the time or the energy to deal with them)
    # noting that it's a tough battle, the scenario should be appropriately difficult

    [story]
        [part]
            story=_ "The cycle of the seasons churns and summer and fall roll around once more. Malin’s thoughts turn back to Parthyn frequently, where a year prior, he had still been among family and friends in the rustic little town that he still thinks of as his home. He has since become a forsaken wanderer, he thinks, but the still burning image of his father being cut down amidst the ruins of his home is stamped deep into his thoughts."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story=_ "Companionship and peace... perhaps they are but a farce and certainly an impossibility with the threat of the orcish clans still looming. It was a choice to live and suffer the path of solitary vengeance rather than appease the law of his land... and thus watch his home burn. It was a choice, he admits, not destiny, not fate. It is a choice that he oft ponders, but usually comes to the same conclusion. Perhaps there is no point in reminiscing on his once tranquil, pastoral life. He has never been one for regrets."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story=_ "Malin turns his attention to the task at hand. Darken Volk leads him through the heart of the Whitefang territory, where they terrorize and murder entire camps of orcs with their undead minions. Word spreads among the orcish towns, which begin to post more guards and dispatch frequent patrols to exterminate the two necromancers. All of their attempts fail."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story=_ "As Malin and Darken Volk continue their raids on the orcs, they eventually force the usually fractious Whitefang chieftains to unite in opposition. The orcs pursue the two necromancers east toward the mouth of the river humans call the Longlier and elves call the Arkan-thoria, where they manage to surround the humans and force a fight."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_05_NEW}}

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

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

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

    [side]
        side=2
        controller=ai
        recruit=Goblin Spearman,Orcish Archer,Orcish Crossbowman,Orcish Grunt,Orcish Warrior
        {GOLD 30 40 50}
        {INCOME 4 7 10}
        team_name=orcs
        user_team_name=_"Orcs"
        {FLAG_VARIANT6 ragged}
        color=white

        type=Orcish Warlord
        id=Borth
        name= _ "Borth"
        profile=portraits/orcs/warlord.png
        canrecruit=yes

        facing=se

        [ai]
            villages_per_scout=8
            village_value=0.5
            [goal]
                name=target
                [criteria]
                    id=Malin Keshar
                [/criteria]
                value=3
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Darken Volk
                [/criteria]
                value=3
            [/goal]
        [/ai]
    [/side]

    [side]
        side=3
        controller=ai
        recruit=Orcish Archer,Goblin Pillager,Orcish Grunt,Wolf Rider,Goblin Knight
        {GOLD 40 50 60}
        {INCOME 6 9 12}
        team_name=orcs
        user_team_name= _ "Orcs"
        {FLAG_VARIANT6 ragged}
        color=white

        type=Orcish Warlord
        id="P'Gareth"
        name= _ "P’Gareth"
        profile=portraits/orcs/grunt-3.png
        canrecruit=yes

        facing=ne

        [ai]
            scout_village_targeting=2
            village_value=0.5
            [goal]
                name=target
                [criteria]
                    id=Malin Keshar
                [/criteria]
                value=3
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Darken Volk
                [/criteria]
                value=3
            [/goal]
        [/ai]
    [/side]

    [side]
        side=4
        controller=ai
        recruit=Orcish Archer,Troll Whelp,Troll,Troll Rocklobber,Orcish Assassin,Orcish Grunt
        {GOLD 30 45 60}
        {INCOME 4 7 10}
        team_name=orcs
        user_team_name= _ "Orcs"
        {FLAG_VARIANT6 ragged}
        color=white

        type=Orcish Warlord
        id="K'Vark"
        name= _ "K’Vark"
        profile=portraits/orcs/grunt-5.png
        canrecruit=yes

        facing=nw

        [ai]
            villages_per_scout=6
            village_value=0.5
            [goal]
                name=target
                [criteria]
                    id=Malin Keshar
                [/criteria]
                value=3
            [/goal]
            [goal]
                name=target
                [criteria]
                    id=Darken Volk
                [/criteria]
                value=3
            [/goal]
        [/ai]
    [/side]

    [label]
        x,y=16,14
        text= _ "River Longlier"
    [/label]

    {STARTING_VILLAGES 1 6}
    {STARTING_VILLAGES 2 5}
    {STARTING_VILLAGES 3 6}
    {STARTING_VILLAGES 4 5}

    {PLACE_IMAGE scenery/whitefang-flag.png 35 10}
    {PLACE_IMAGE scenery/whitefang-flag.png 5 5}
    {PLACE_IMAGE scenery/whitefang-flag.png 6 22}

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        {COLOR_ADJUST -12 -12 -12}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Kill the orcish 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]

        [recall]
            id=Darken Volk
        [/recall]

        {MODIFY_UNIT (side=1) facing sw}
    [/event]

    [event]
        name=start

        [message]
            speaker=Malin Keshar
            message= _ "Even before the very founding of Wesnoth, you have hounded my people at every turn. You have trampled our fields, slaughtered our livestock, and burned our houses. You have brought war to a place of peace and death to a place of life. You are nothing but remorseless killers and savage beasts. Your kind deserves no mercy and shall receive none. I will crush you into the dust and make you into my slaves for all eternity."
        [/message]

        [message]
            speaker=Borth
            message= _ "The silly necromancer is trying to talk us to death! You have caused us enough trouble, human. It is time for you to die."
        [/message]

        [message]
            speaker="P'Gareth"
            message= _ "Ummm... unless... you are already dead, like the skeletons?"
        [/message]

        [message]
            speaker="K'Vark"
            message= _ "Then it will be time for you to die again!"
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            side=2,3,4
            canrecruit=yes
        [/filter]
        [filter_condition]
            [have_unit]
                side=2,3,4
                canrecruit=yes

                [not]
                    side=$unit.side
                [/not]

                count=2
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "How puny and weak you look in death."
        [/message]
    [/event]

    # Victory Condition
    [event]
        name=die
        first_time_only=no
        [filter]
            side=2,3,4
            canrecruit=yes
        [/filter]
        [filter_condition]
            [have_unit]
                side=2,3,4
                canrecruit=yes

                [not]
                    side=$unit.side
                [/not]

                count=1
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Malin Keshar
            message= _ "You and your kind deserve no eternal rest in death. After this battle, I’ll raise your corpse and make your bones dance for me, orc. But for now, I’ve one last one to take care of—"
        [/message]

        [store_unit]
            [filter]
                side=2,3,4
                canrecruit=yes

                [not]
                    side=$unit.side
                [/not]
            [/filter]

            kill=no
            variable=remaining_orc_leader
        [/store_unit]

        [switch]
            variable=remaining_orc_leader.side
            [case]
                value=2
                {VARIABLE escape_to_x 11}
                {VARIABLE escape_to_y 1}
            [/case]

            [case]
                value=3
                {VARIABLE escape_to_x 8}
                {VARIABLE escape_to_y 26}
            [/case]

            [case]
                value=4
                {VARIABLE escape_to_x 40}
                {VARIABLE escape_to_y 7}
            [/case]
        [/switch]

        [object]
            silent=yes

            [filter]
                x,y=$remaining_orc_leader.x,$remaining_orc_leader.y
            [/filter]

            [effect]
                apply_to=hitpoints
                heal_full=yes
            [/effect]
        [/object]

        [message]
            speaker=$remaining_orc_leader.id
            message= _ "Retreat!"
        [/message]

        [store_unit]
            [filter]
                x,y=$remaining_orc_leader.x,$remaining_orc_leader.y
            [/filter]

            kill=yes
            variable=orc_leader_store
        [/store_unit]

        {CLEAR_VARIABLE orc_leader_store.status.poisoned}

        [move_unit_fake]
            type=$remaining_orc_leader.type
            side=$remaining_orc_leader.side
            x=$remaining_orc_leader.x,$escape_to_x
            y=$remaining_orc_leader.y,$escape_to_y
        [/move_unit_fake]

        {CLEAR_VARIABLE remaining_orc_leader,escape_to_x,escape_to_y}

        [message]
            speaker=Malin Keshar
            message= _ "He flees! The coward!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "That is no surprise. Orcs may like to make a show of strength, but will always flee in the face of an overwhelming force. Nevertheless, the Whitefangs are still numerous and have some ties to other orcish clans. You must hunt this chieftain down before he can alert the others, else we may soon have dozens more on our tail."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "By ‘you’, you mean... on my own?"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "Your apprenticeship is nearly over; you are more than capable of handling a single, half-dead orc on your own. After you have dealt with him, I do have a small favor I will ask of you. It will constitute the last part of your... training. I have some other things that I must attend to in preparation. In a few weeks, meet with me to the west, near the town of Tath."
        [/message]

        [message]
            speaker=Malin Keshar
            message= _ "It will be done."
        [/message]

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

    [event]
        name=victory

        # Heal Darken Volk and store him for his return in A Small Favor
        {FULL_HEAL (id=Darken Volk)}

        [store_unit]
            [filter]
                id=Darken Volk
            [/filter]
            variable=darken_volk_store
            kill=yes
        [/store_unit]
    [/event]

    {HERODEATH_MALIN}
    {HERODEATH_VOLK}

    {TIME_OVER_DEFEAT}
[/scenario]