#textdomain wesnoth-did
[scenario]
    id=A_Small_Favor
    next_scenario=A_Small_Favor2

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

    {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=_ "'For your final test as my apprentice, you will aid me in retrieving a book,' the necromancer says. '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.'"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "Malin replies, 'They are no longer countrymen of mine, since they have rejected me twice now.'"
            background=story/book.jpg
            scale_background=no
        [/part]
        [part]
            story=_ "Darken Volk continues, '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.'"
            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"
        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
        colour=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
    [/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]
            [objective]
                condition=lose
                description=_ "Time runs out"
            [/objective]

            note={EARLY_FINISH_BONUS_NOTE}+{NEW_GOLD_CARRYOVER_NOTE_40}
        [/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 7}

        # 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 add -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]

        [removeitem]
            x,y=5,5
        [/removeitem]
    [/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]
            id=Malin Keshar
            x=2,  3,  4,  5,6
            y=6,6-7,5-6,5-6,5
        [/filter]
        [if]
            [have_unit]
                id=Darken Volk
                x=2,  3,  4,  5,6
                y=6,6-7,5-6,5-6,5
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message=_ "Here is the entrance! Hurry!"
                [/message]

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

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Darken Volk
            x=2,  3,  4,  5,6
            y=6,6-7,5-6,5-6,5
        [/filter]
        [if]
            [have_unit]
                id=Malin Keshar
                x=2,  3,  4,  5,6
                y=6,6-7,5-6,5-6,5
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message=_ "Here is the entrance! Hurry!"
                [/message]
                [endlevel]
                    result=victory
                    bonus=yes
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/then]
        [/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]
