#textdomain wesnoth-did

[scenario]
    id=07_A_Small_Favor
    name= _ "A Small Favor"
    map_data="{campaigns/Descent_Into_Darkness/maps/07_A_Small_Favor.map}"
    {TURNS 20 18 16}
    next_scenario=08_A_Small_Favor2
    victory_when_enemies_defeated=no

#ifdef EASY
    {FIRST_WATCH_HOUR2}
    {FIRST_WATCH_HOUR2}
    {FIRST_WATCH_HOUR3}
    {FIRST_WATCH_HOUR3}
    {FIRST_WATCH_HOUR4}
    {FIRST_WATCH_HOUR4}
    {MIDNIGHT_HOUR}
    {MIDNIGHT_HOUR}
    {SECOND_WATCH_HOUR1}
    {SECOND_WATCH_HOUR1}
    {SECOND_WATCH_HOUR2}
    {SECOND_WATCH_HOUR2}
    {SECOND_WATCH_HOUR3}
    {SECOND_WATCH_HOUR3}
    {SECOND_WATCH_HOUR4}
    {SECOND_WATCH_HOUR4}
    {SECOND_WATCH_HOUR5}
    {SECOND_WATCH_HOUR5}
    {SECOND_WATCH_HOUR6}
    {SECOND_WATCH_HOUR6}
    {DAWN_HOUR}
#endif

#ifdef NORMAL
    {FIRST_WATCH_HOUR2}
    {FIRST_WATCH_HOUR3}
    {FIRST_WATCH_HOUR3}
    {FIRST_WATCH_HOUR4}
    {FIRST_WATCH_HOUR4}
    {MIDNIGHT_HOUR}
    {MIDNIGHT_HOUR}
    {SECOND_WATCH_HOUR1}
    {SECOND_WATCH_HOUR1}
    {SECOND_WATCH_HOUR2}
    {SECOND_WATCH_HOUR2}
    {SECOND_WATCH_HOUR3}
    {SECOND_WATCH_HOUR3}
    {SECOND_WATCH_HOUR4}
    {SECOND_WATCH_HOUR4}
    {SECOND_WATCH_HOUR5}
    {SECOND_WATCH_HOUR5}
    {SECOND_WATCH_HOUR6}
    {DAWN_HOUR}
#endif

#ifdef HARD
    {FIRST_WATCH_HOUR2}
    {FIRST_WATCH_HOUR3}
    {FIRST_WATCH_HOUR3}
    {FIRST_WATCH_HOUR4}
    {FIRST_WATCH_HOUR4}
    {MIDNIGHT_HOUR}
    {MIDNIGHT_HOUR}
    {SECOND_WATCH_HOUR1}
    {SECOND_WATCH_HOUR1}
    {SECOND_WATCH_HOUR2}
    {SECOND_WATCH_HOUR3}
    {SECOND_WATCH_HOUR3}
    {SECOND_WATCH_HOUR4}
    {SECOND_WATCH_HOUR4}
    {SECOND_WATCH_HOUR5}
    {SECOND_WATCH_HOUR6}
    {DAWN_HOUR}
#endif

    {SCENARIO_MUSIC       elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}
    {EXTRA_SCENARIO_MUSIC the_deep_path.ogg}

    [story]
        [part]
            music=underground.ogg
            story= _ "Fleeing from the city of his birth, Malin escapes into the forested hills north of the Great River. Some distance west, he finally stops after several days bereft of rest and sleep. He closes his eyes, trying to purge the last few hours from his mind, but the darkness only makes the images all the more vivid. He is tired, <i>so</i> tired, but sleep does not come."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story= _ "<i>“No regrets. No regrets...”</i> He repeats it under his breath like a chant, murmuring over and over in his half-conscious state. After a while, a second voice joins, a voice that sounds very much like his own, but somehow feels foreign and alien. <i>‘There could have been another way. You might have been wrong.’</i>"
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story= _ "<i>“No, no. Even if there were another way, they would have spurned me all the same. They are wrong... blind. I have no regrets about what I did. No regrets...”</i> He quells the voice. Sleep comes, long stretches of dreamless darkness punctuated briefly by nightmarish forms — distorted, grotesque things that whisper in eerily familiar voices. <i>‘You are cursed, Malin the Damned! Cursed! Cursed. Cursed...’</i> They echo over and over, first a choir, then a duet, both male, then just one, a single voice alone in the darkness."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story= _ "Malin wakes up to a plume of smoke rising in the east. He gives it only a brief thought before heading farther west toward Tath. Soon, he reunites with his teacher."
            {STORYTXT_BACKGROUND travel.jpg}
        [/part]
        [part]
            story=_ "<i>“For your final test as my apprentice, you will aid me in retrieving a book,”</i> the necromancer says. <i>“The book was... stolen from me long ago. It has personal value to me, so you may think of this as a small favor. However, this task will require you to act against your countrymen of Wesnoth, since it was one of them who took it from me.”</i>"
            {STORYTXT_BACKGROUND book.jpg}
        [/part]
        [part]
            story= _ "Malin replies, <i>“They are no longer countrymen of mine.”</i>"
            {STORYTXT_BACKGROUND book.jpg}
        [/part]
        [part]
            story= _ "Darken Volk continues, <i>“Excellent. There is a lord of Tath by the name of Karres. He was trained as a mage in his youth and now uses his wealth to support a large number of mages in their studies. Among his library is the book we seek. We shall break into his manor to seek the book.”</i>"
            {STORYTXT_BACKGROUND book.jpg}
        [/part]
    [/story]

    {DID_TRACK {JOURNEY_07_NEW}}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept DiD
        {GOLD 180 150 120}
        team_name=intruders
        user_team_name= _ "Intruders"
        {FLAG_VARIANT undead}

        village_gold=2
        village_support=1

        # wmllint: recognize Malin Keshar
        {CHARACTER_STATS_MALIN_KESHAR}

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

    [side]
        side=2
        controller=ai
        recruit=Swordsman,Pikeman,Longbowman,Cavalryman,Dragoon,Mage,Heavy Infantryman,Shock Trooper
        gold=0
        team_name=defenders
        user_team_name= _ "Defenders"
        {FLAG_VARIANT loyalist}

        village_gold=0
        income=-2

        type=General
        id=Taylor
        name= _ "General Taylor"
        canrecruit=yes

        fog=yes
        share_vision=none
        color=green
        facing=se

        # Place city guards

        {NAMED_LOYAL_UNIT 2 Bowman 2 17  (Guard1) ( _ "Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 4 17  (Guard2) ( _ "Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 4 18 (Guard3) ( _ "Night Watchman")} {GUARDIAN}

        {NAMED_LOYAL_UNIT 2 Spearman 11 3 (Guard4) ( _ "Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Bowman 11 4 (Guard5) ( _ "Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 13 4 (Guard6) ( _ "Night Watchman")} {GUARDIAN}

        {NAMED_LOYAL_UNIT 2 Pikeman  18 18 () ( _ "Gate Guard")}     {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Swordsman  16 20 () ( _ "Gate Guard")}     {GUARDIAN}

        {NAMED_LOYAL_UNIT 2 (Heavy Infantryman) 20 22 () ( _ "Gate Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Heavy Infantryman) 24 20 () ( _ "Gate Guard")} {GUARDIAN}

        {NAMED_LOYAL_UNIT 2 (Heavy Infantryman) 3 12 () ( _ "City Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Shock Trooper) 5 15 () ( _ "City Guard")} {GUARDIAN}

        # More guards, depending on the difficulty
#ifdef EASY
        {NAMED_LOYAL_UNIT 2 Mage      7  9 () ( _ "Mage Guard")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Mage      8  7 () ( _ "Mage Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Sergeant 6 13 () ( _ "Head Trainer")}   {GUARDIAN}
#endif

#ifdef NORMAL
        {NAMED_LOYAL_UNIT 2 Mage      7  9 () ( _ "Mage Guard")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Red Mage)   8  7  () ( _ "Mage Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Heavy Infantryman)   12 16  () ( _ "City Guard")}     {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Lieutenant) 6 13 () ( _ "Head Trainer")}   {GUARDIAN}
#endif

#ifdef HARD
        {NAMED_LOYAL_UNIT 2 (White Mage)      7  9 () ( _ "Mage Guard")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Red Mage)    8   7 () ( _ "Mage Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Shock Trooper)     12 16 () ( _ "City Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Lieutenant)  6 13 () ( _ "Head Trainer")}   {GUARDIAN}
#endif

        [ai]
            passive_leader=yes
            aggression=1.0
            caution=0.4
            grouping=offensive

            [goal]
                name=protect_location
                [criteria]
                    # Manor entrance
                    x,y=7,8
                [/criteria]
                protect_radius=5
                value=4
            [/goal]

            [goal]
                name=protect_location
                [criteria]
                    # Rest of city
                    x=3-22
                    y=6-22
                [/criteria]
                protect_radius=1
                value=2
            [/goal]

            [goal]
                name=protect_unit
                [criteria]
                    side=2
                    canrecruit=yes
                [/criteria]
                value=2
            [/goal]
        [/ai]
    [/side]

    {STARTING_VILLAGES 1 3}
    {STARTING_VILLAGES 2 15}

    # City
    {PLACE_IMAGE scenery/well.png 16 12}
    {PLACE_IMAGE scenery/well.png 19 14}
    {PLACE_IMAGE scenery/tent-shop-weapons.png 3 17}
    {PLACE_IMAGE scenery/monolith1.png 11 5}
    {PLACE_IMAGE scenery/monolith1.png 13 6}
    {PLACE_IMAGE scenery/monolith1.png 10 6}
    {PLACE_IMAGE scenery/signpost.png 15 16}
    {PLACE_IMAGE scenery/signpost.png 11 12}
    {PLACE_IMAGE scenery/temple1.png 10 18}
    {PLACE_IMAGE scenery/tent-fancy-red.png 9 15}
    {PLACE_IMAGE items/dragonstatue.png 12 14}

    {PLACE_IMAGE "items/dummy.png~RC(magenta>green)" 7 12}
    {PLACE_IMAGE "items/dummy.png~RC(magenta>green)" 4 11}
    {PLACE_IMAGE items/armor.png 4 12}
    {PLACE_IMAGE items/armor.png 4 16}
    {PLACE_IMAGE items/armor.png 6 16}
    {PLACE_IMAGE items/flower2.png 13 7}
    {PLACE_IMAGE items/flower1.png 16 8}
    {PLACE_IMAGE items/flower3.png 12 7}
    {PLACE_IMAGE items/flower4.png 17 8}

    # Manor
    {PLACE_IMAGE scenery/trapdoor-closed.png 3 6}
    {PLACE_IMAGE items/cloak-green.png 2 6}
    {PLACE_IMAGE items/ornate1.png 5 5}
    {PLACE_IMAGE items/potion-blue.png 4 5}
    {PLACE_IMAGE items/potion-red.png 6 5}
    {PLACE_IMAGE items/altar.png 3 7}

#define WATCHMAN_PATROL_MOVEMENT
    [set_variable]
        name=turn_mod
        value=$($turn_number % 5)
    [/set_variable]

    [switch]
        variable=turn_mod
        [case]
            value=1,0
            [move_unit]
                id=Guard3
                side=2
                to_x,to_y=5,22
            [/move_unit]
            [move_unit]
                id=Guard2
                side=2
                to_x,to_y=4,21
            [/move_unit]
            [move_unit]
                id=Guard1
                side=2
                to_x,to_y=4,20
            [/move_unit]

            [move_unit]
                id=Guard6
                side=2
                to_x,to_y=18,7
            [/move_unit]
            [move_unit]
                id=Guard5
                side=2
                to_x,to_y=16,6
            [/move_unit]
            [move_unit]
                id=Guard4
                side=2
                to_x,to_y=14,5
            [/move_unit]
        [/case]
        [case]
            value=2,4
            [move_unit]
                id=Guard3
                side=2
                to_x,to_y=10,24
            [/move_unit]
            [move_unit]
                id=Guard2
                side=2
                to_x,to_y=10,23
            [/move_unit]
            [move_unit]
                id=Guard1
                side=2
                to_x,to_y=9,24
            [/move_unit]

            [move_unit]
                id=Guard6
                side=2
                to_x,to_y=22,11
            [/move_unit]
            [move_unit]
                id=Guard5
                side=2
                to_x,to_y=21,11
            [/move_unit]
            [move_unit]
                id=Guard4
                side=2
                to_x,to_y=20,9
            [/move_unit]
        [/case]
        [case]
            value=3
            [move_unit]
                id=Guard3
                side=2
                to_x,to_y=14,22
            [/move_unit]
            [move_unit]
                id=Guard2
                side=2
                to_x,to_y=13,23
            [/move_unit]
            [move_unit]
                id=Guard1
                side=2
                to_x,to_y=12,22
            [/move_unit]

            [move_unit]
                id=Guard6
                side=2
                to_x,to_y=20,16
            [/move_unit]
            [move_unit]
                id=Guard5
                side=2
                to_x,to_y=21,16
            [/move_unit]
            [move_unit]
                id=Guard4
                side=2
                to_x,to_y=21,15
            [/move_unit]
        [/case]
    [/switch]

    {CLEAR_VARIABLE turn_mod}
#enddef

    [event]
        name=prestart

        {CLEAR_CORPSE_HORDE}

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Move Malin and Darken Volk into the Mage Lord’s manor"
            [/objective]
            [objective]
                condition=win
                description= _ "OR: Defeat General Taylor"
            [/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]

            [note]
                description= _ "This scenario takes place entirely at night."
            [/note]
            [note]
                description= _ "Enemy units have reduced vision (radius 3)"
            [/note]
        [/objectives]

        # Place Darken Volk
        {VARIABLE darken_volk_store.x recall}
        {VARIABLE darken_volk_store.y recall}

        [unstore_unit]
            variable=darken_volk_store
        [/unstore_unit]

        {CLEAR_VARIABLE darken_volk_store}

        [recall]
            id=Darken Volk
            x,y=36,15
        [/recall]

        {MODIFY_UNIT (side=1) facing nw}

        [modify_unit]
            [filter]
                side=2
            [/filter]
            vision=2
        [/modify_unit]

        {VARIABLE guard_alerted 0}
    [/event]

    [event]
        name=start

        [message]
            speaker=Darken Volk
            message= _ "The stolen book lies within Lord Karres’s manor at the north end of the city. It will be difficult for us to defeat the entire city guard, so we must stay hidden as long as possible. For now, we can use this fog to our advantage. I shall use it to cast a spell to obscure the town guards’ vision. It should not affect us, however."
        [/message]

        [delay]
            time=450
        [/delay]
        [animate_unit]
            [filter]
                id=Darken Volk
            [/filter]
            [primary_attack]
                range=ranged
            [/primary_attack]
            flag=attack
        [/animate_unit]
        [delay]
            time=350
        [/delay]

        [message]
            speaker=Darken Volk
            message= _ "This spell will not hide us completely. If we stray too close to the guards, they will still be able to see us. Once we are spotted, we shall have to make a run for it. The faster we enter the manor, the more time we shall have to search for the book before the guards can pursue us."
        [/message]

        [message]
            speaker=narrator
            message= _ "Note: Only the units you recruit now will be available to you once inside."
            image=wesnoth-icon.png
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            side=2
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=unit
            message= _ "This blasted fog is so thick! I can’t see a thing!"
        [/message]

        [message]
            speaker=Taylor
            message= _ "Stay alert, soldier. Report anything unusual immediately."
        [/message]
    [/event]

    [event]
        name=sighted
        [filter]
            side=1
        [/filter]
        [filter_second]
            side=2
        [/filter_second]

        [if]
            [variable]
                name=second_unit.id
                not_equals=Taylor
            [/variable]
            [then]
                [message]
                    speaker=second_unit
                    message= _ "Undead are emerging from the forest!"
                [/message]
            [/then]
        [/if]
        [message]
            speaker=Taylor
            message= _ "Wake the guard! To arms, men!"
        [/message]

        [modify_side]
            side=2
            {GOLD 140 170 200}
            {INCOME 12 16 20}
        [/modify_side]

        {VARIABLE guard_alerted 1}
    [/event]

    [event]
        name=side 2 turn refresh
        first_time_only=no
        [filter_condition]
            [variable]
                name=guard_alerted
                numerical_equals=0
            [/variable]
        [/filter_condition]

        {MODIFY_UNIT (side=2) moves 0}
        {WATCHMAN_PATROL_MOVEMENT}
    [/event]

    # Undead unit kicks the holy water
    [event]
        name=moveto
        [filter]
            x,y=5,5
            race=undead
        [/filter]

        [message]
            speaker=unit
            # po: Ooouuuh is a cry of pain
            message= _ "Ooouuuh! It burns... burrrrnnns..."  # wmllint: no spellcheck
        [/message]

        [harm_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            amount=1
            kill=no
            animate=yes
        [/harm_unit]

        [floating_text]
            x,y=$x1,$y1
            text="<span color='#ff0000'>-1</span>" # wmllint: ignore
        [/floating_text]

        [remove_item]
            x,y=5,5
        [/remove_item]

        [message]
            speaker=Malin Keshar
            message= _ "What was that?!"
        [/message]

        [message]
            speaker=Darken Volk
            message= _ "That was the impact of what is known as holy water among commoners. It is brewed in a complicated procedure only known to a few priests. As you might imagine, it is quite effective against undead."
        [/message]
    [/event]

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

        [message]
            speaker=Taylor
            message= _ "The undead are too strong! Retreat and regroup!"
        [/message]

        [kill]
            side=2
        [/kill]
        [endlevel]
            result=victory
            linger_mode=no
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    # Victory Conditions
    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Malin Keshar,Darken Volk
            x=2-6
            y=5-7
        [/filter]
        [filter_condition]
            [have_unit]
                id=Malin Keshar
                x=2-6
                y=5-7
            [/have_unit]
            [have_unit]
                id=Darken Volk
                x=2-6
                y=5-7
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Darken Volk
            message= _ "Here is the entrance! Hurry!"
        [/message]

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

    [event]
        name=victory

        {SET_GOT_INSIDE_MANOR}

#ifdef EASY
        [set_variable]
            name=S7_turns
            value=$("23 - ($turn_number)")
        [/set_variable]
#endif
#ifdef NORMAL
        [set_variable]
            name=S7_turns
            value=$("20 - ($turn_number)")
        [/set_variable]
#endif
#ifdef HARD
        [set_variable]
            name=S7_turns
            value=$("18 - ($turn_number)")
        [/set_variable]
#endif

        {CLEAR_VARIABLE guard_alerted}
    [/event]

    {HERODEATH_MALIN}
    {HERODEATH_VOLK}

    [event]
        name=time over

        [message]
            speaker=Darken Volk
            message= _ "We have no hope of entering the manor now that dawn has broken and the entire city guard is alerted to our presence. Your incompetence is truly appalling."
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]
[/scenario]
