#textdomain wesnoth-did
[scenario]
    id=07_A_Small_Favor
    next_scenario=08_A_Small_Favor2

    name=_ "A Small Favor"
    map_data="{campaigns/Descent_Into_Darkness/maps/07_A_Small_Favor.map}"
    {TURNS 28 26 22}
    victory_when_enemies_defeated=no

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

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

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

    {INTRO_AND_SCENARIO_MUSIC underground.ogg elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC elf-land.ogg}

    # wmllint: directory spelling Karres
    [story]
        [part]
            story=_ "Fleeing from the city of his birth, Malin heads to the west. Soon he reunites with his teacher."
            background=story/travel.jpg
            scale_background=no
        [/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. Since it has personal value to me, think of the task as a small favor. I should warn you that it will require you to act against your countrymen of Wesnoth, since it was one of them who stole it from me.”</i>"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "Malin replies, <i>“They are no longer countrymen of mine, since they have rejected me twice now.”</i>"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "Darken Volk continues, <i>“Excellent. We travel, then, to the city of Tath. There is a lord of that city 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 will need to break into his manor and seek the book inside.”</i>"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            show_title=yes
            {TO_A_SMALL_FAVOR}
        [/part]
    [/story]

    [side]
        side=1
        controller=human
        team_name=intruders
        user_team_name=_"Intruders"
        type=Apprentice Mage
        id=Malin Keshar
        name=_ "Malin Keshar"
        profile=portraits/malin_old.png
        unrenamable=yes
        canrecruit=yes
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept DiD
        {GOLD 170 130 110}
        shroud=no
        fog=yes
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=2
        color=green
        controller=ai
        team_name=defenders
        user_team_name=_"Defenders"
        type=General
        id=Taylor
        name=_ "Taylor"
        unrenamable=yes
        canrecruit=yes
        recruit=Swordsman,Pikeman,Longbowman,Cavalryman,Dragoon,Mage,Heavy Infantryman,Shock Trooper
        gold=0
        village_gold=0
        income=-2
        [ai]
            passive_leader=yes
            aggression=1.0
            caution=0.4
            [protect_area]
                # Manor entrance
                x,y=7,8
                radius=5
                value=4
            [/protect_area]
            [protect_area]
                # Rest of city
                x=3-22
                y=6-22
                radius=1
                value=2
            [/protect_area]
            grouping=offensive
            protect_leader=2
        [/ai]
        shroud=no
        fog=yes
        {FLAG_VARIANT loyalist}
    [/side]

    {STARTING_VILLAGES 2 15}

    {ANIMATED_CAMPFIRE 19 23}
    {ANIMATED_CAMPFIRE 25 20}
    {ANIMATED_CAMPFIRE 11 8}

    [event]
        name=prestart

        # wmllint: recognize Darken Volk

        [objectives]
            side=1
            [objective]
                condition=win
                description= _ "Malin and Darken Volk enter the Mage Lord’s manor"
            [/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]

        # Add a little randomness to the forest
        # {SCATTER_IMAGE (terrain=Gs^Fp) 6 scenery/pine2.png}
        # {SCATTER_IMAGE (terrain=Gs^Fp) 2 scenery/oak-leaning.png}

        # Place city pictures
        {PLACE_IMAGE scenery/well.png 17 11}
        {PLACE_IMAGE scenery/well.png 8 12}
        {PLACE_IMAGE items/dummy.png 18 15}
        {PLACE_IMAGE items/dummy.png 19 15}
        {PLACE_IMAGE items/armor.png 19 17}
        {PLACE_IMAGE items/armor.png 21 17}
        {PLACE_IMAGE items/armor.png 22 16}
        {PLACE_IMAGE scenery/tent-shop-weapons.png 17 16}
        {PLACE_IMAGE items/flower2.png 9 19}
        {PLACE_IMAGE items/flower1.png 10 18}
        {PLACE_IMAGE items/flower3.png 12 18}
        {PLACE_IMAGE items/flower4.png 13 19}
        {PLACE_IMAGE scenery/monolith1.png 11 5}
        {PLACE_IMAGE scenery/monolith1.png 12 4}
        {PLACE_IMAGE scenery/monolith1.png 13 5}
        {PLACE_IMAGE items/altar.png 12 5}

        # Place manor pictures
        {PLACE_IMAGE items/cloak-green.png 5 7}
        {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 scenery/trapdoor-closed.png 3 6}

        # Place city guards
        {NAMED_LOYAL_UNIT 2 Spearman 11 3 () (_"Night Watchman")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 17 6 () (_"Night Watchman")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 23 9 () (_"Night Watchman")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 25 14 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Pikeman  20 22 () (_"Gate Guard")}     {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Pikeman  24 20 () (_"Gate Guard")}     {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Heavy Infantryman) 19 22 () (_"Gate Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Heavy Infantryman) 24 19 () (_"Gate Guard")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 13 23 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman  7 23 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman  4 18 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman  2 14 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman 16 28 () (_"Night Watchman")} {GUARDIAN}

        # More guards, depending on the difficulty
#ifdef EASY
        {NAMED_LOYAL_UNIT 2 Mage      7  9 () (_"Night Watchman")}  {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Mage      8  7 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Sergeant 21 15 () (_"Head Trainer")}   {GUARDIAN}
#endif

#ifdef NORMAL
        {NAMED_LOYAL_UNIT 2 (Mage)     7  9  () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Red Mage) 8  7  () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Spearman   12 7  () (_"Townperson")}     {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 Lieutenant 21 15 () (_"Head Trainer")}   {GUARDIAN}
#endif

#ifdef HARD
        {NAMED_LOYAL_UNIT 2 (Silver Mage) 7   9 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Red Mage)    8   7 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Pikeman)     12  7 () (_"Night Watchman")} {GUARDIAN}
        {NAMED_LOYAL_UNIT 2 (Lieutenant)  21 15 () (_"Head Trainer")} {GUARDIAN}
#endif

        # 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=40,18
        [/recall]

        # Event variables
        {VARIABLE undeadWarning no}
    [/event]

    [event]
        name=start

        [message]
            speaker=Darken Volk
            message=_ "The stolen book lies within Lord Karres’s manor on the north end of the city. We cannot defeat the entire city guard, so we must stay hidden as long as possible. The cover of the night and this fog will aid us. Once we are seen by the night watchmen, we will have to make a run for it. Our forces are not strong enough to take the whole city."
        [/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]

    # In-scenario Events
    [event]
        # Sentry attacks an undead
        # This would be better to do when a sentry can see my units on his turn, but Wesnoth doesn't generate a "sighted" event if I move into their sight range during my turn
        name=attack
        first_time_only=no
        [filter]
            side=2
        [/filter]
        [filter_second]
            side=1
        [/filter_second]
        [if]
            [variable]
                name=undeadWarning
                equals=no
            [/variable]
            [then]
                # Sound a warning and give gold to the general

                [message]
                    x,y=$x1,$y1
                    message=_ "Sir! Undead creatures are coming out of the forest! Wake the guard immediately!"
                [/message]
                [message]
                    speaker=Taylor
                    message=_ "To arms, men!"
                [/message]

                {VARIABLE undeadWarning yes}
                [modify_side]
                    side=2
                    {GOLD 75 150 300}
                [/modify_side]
            [/then]
        [/if]
    [/event]

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

        {VARIABLE_OP unit.hitpoints sub 1}

        [if]
            [variable]
                name=unit.hitpoints
                greater_than=0
            [/variable]

            [then]
                [unstore_unit]
                    variable=unit
                    find_vacant=no
                    # intentionally left untranslatable for now
                    text="-1"   # wmllint: ignore
                    {COLOR_HARM}
                [/unstore_unit]
            [/then]
        [/if]

        [message]
            speaker=unit
            message=_ "Ooouuuh! It burns... burrrrnnns..."  # wmllint: no spellcheck
        [/message]
        [message]
            speaker=Malin Keshar
            message=_ "What in the name of all demons of hell was this thing?"
        [/message]
        [message]
            speaker=Darken Volk
            message=_ "This was the impact of what is known as holy water among common people. It is brewed in a complicated and mysterious procedure only known to a few priests and often used to fight resurrected creatures."
        [/message]

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

    # Defeat Conditions
    {MALIN_DEATH}
    {VOLK_DEATH}

    [event]
        name=time over
        #[message]
        #    speaker=narrator
        #    message=_ "Day break and stuff."
        #    image=wesnoth-icon.png
        #[/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # Victory Conditions
    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=2-6
            y=5-7

            [and]
                id=Malin Keshar

                [or]
                    id=Darken Volk
                [/or]
            [/and]
        [/filter]
        [if]
            [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]
            [then]
                [message]
                    speaker=unit
                    message=_ "Here is the entrance! Hurry!"
                [/message]

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

            [else]
                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

    [event]
        name=victory

        {MODIFY_UNIT (
            side=1
            {NOT_ON_RECALL_LIST}
            [not]
                id=Malin Keshar

                [or]
                    id=Darken Volk
                [/or]
            [/not]
        ) variables.got_inside_manor yes}

        {CLEAR_VARIABLE undeadWarning}
    [/event]
[/scenario]
