#textdomain wesnoth-sota

# Walking corpses are summoned from graves using the right-click menu. Each grave is
# marked by a stone on the map and has its own terrain type. Each can only be used once,
# so a pile of dirt is used to mark one after it is used. After the player captures the
# guardhouse, they can summon skeletons as well, but that ability is lost if the enemy
# units retake it. The opening has some interesting WML to keep Ardonna hidden while
# the guards are talking amongst themselves. It is explained there.

[scenario]
    name= _ "Dark Business"
    map_data="{campaigns/Secrets_of_the_Ancients/maps/02_Dark_Business.map}"

    id=02_Dark_Business
    next_scenario=03_Bandits
    victory_when_enemies_defeated=no

    [story]
        [part]
            [background_layer]
                image=story/cemetery.jpg
                scale=no
            [/background_layer]
            story= _ "16 III, 23 YW:

I decided to hide in the cemetery. That way I could try my experiment to animate a human body when night fell. With my dark cloak, I resembled the mourners, and with my hood up, nobody could see my hair."
        [/part]
        {JOURNEY_PART 2}
    [/story]

    {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}

    {DEFAULT_MUSIC_PLAYLIST}
    {TURNS 18 18 18}

    [side]
        {SIDE_1_ARDONNA_EARLY}
        {GOLD 50 40 30}
        facing=se
        # The scenario won't be shrouded, but some of the intro dialog is:
        shroud=yes
    [/side]

    [side]
        side=2
        controller=ai
        no_leader=yes
        user_team_name= _ "Guards"
        {FLAG_VARIANT loyalist}
    [/side]

    # *************************** MACROS ***************************

    # This menu item macro is used for "recruiting" walking corpses, skeletons, and skeleton
    # archers from graves. UNIT is the unit type, UNIT_STRING is similar but has underscores
    # and is used for the id and icon filename. GOLD is the cost (a number).
#define SET_MENU_ITEM_FOR UNIT UNIT_STRING GOLD
    # We need a variable to use in the switch statement:
    [set_variable]
        name=unit_string
        value={UNIT_STRING}
    [/set_variable]
    # The following sentences could be built from the macro arguments, but that might
    # make them impossible to translate properly. So, we use a switch statement instead.
    [switch]
        variable=unit_string
        [case]
            value=walking_corpse
            [set_variable]
                name=description_text
                value= _ "Raise Walking Corpse (8 Gold)"
            [/set_variable]
        [/case]
        [case]
            value=skeleton
            [set_variable]
                name=description_text
                value= _ "Raise Skeleton (15 Gold)"
            [/set_variable]
        [/case]
        [case]
            value=skeleton_archer
            [set_variable]
                name=description_text
                value= _ "Raise Skeleton Archer (14 Gold)"
            [/set_variable]
        [/case]
    [/switch]
    [clear_variable]
        name=unit_string
    [/clear_variable]

    [set_menu_item]
        id=raise_{UNIT_STRING}
        description=$description_text
        image=units/icons/icon-{UNIT_STRING}.png

        [show_if]
            [and]
                # Show if: This is a grave overlay terrain...
                [have_location]
                    terrain=*^Gryv
                    x,y=$x1,$y1

                    # ...within 1 hex of the leader...
                    [and]
                        [filter]
                            id=Ardonna
                        [/filter]
                        radius=1
                    [/and]
                [/have_location]

                # ...And there is not a unit here already.
                [not]
                    [have_unit]
                        x,y=$x1,$y1
                    [/have_unit]
                [/not]
            [/and]
        [/show_if]

        [command]
            [store_gold]
                side=1
                variable=gold
            [/store_gold]

            [if]
                [variable]
                    name=gold
                    less_than={GOLD}
                [/variable]
                [then]
                    [message]
                        speaker=narrator
                        image=items/gold-coins-message.png
                        message=_ "You don't have enough gold to raise that unit."
                    [/message]
                [/then]
                [else]
                    [gold]
                        side=1
                        amount=-{GOLD}
                    [/gold]
                    # x1 and y1 have to be stored because they can be changed by the
                    # player right-clicking again during this command:
                    [set_variable]
                        name=zombie_x
                        value=$x1
                    [/set_variable]
                    [set_variable]
                        name=zombie_y
                        value=$y1
                    [/set_variable]
                    [item]  # Marks the grave as used.
                        x,y=$zombie_x,$zombie_y
                        image=items/dirt.png
                    [/item]
                    [delay]  # This makes it a bit animated.
                        time=400
                    [/delay]
                    [unit]
                        side=1
                        x,y=$zombie_x,$zombie_y
                        type={UNIT}
                        animate=yes
                        moves=0
                        attacks_left=0
                    [/unit]

                    # Remove the overlay that defines this terrain as a grave:
                    [terrain]
                        terrain=^
                        layer=overlay
                        x,y=$zombie_x,$zombie_y
                    [/terrain]
                    [fire_event]
                        id=more_guards
                    [/fire_event]
                    [clear_variable]
                        name=zombie_x,zombie_y
                    [/clear_variable]
                [/else]
            [/if]
        [/command]
    [/set_menu_item]
#enddef

#define PLACE_GUARD X Y TYPE TRAIT1 TRAIT2 ID NAME
    [unit]
        type={TYPE}
        id={ID}
        name={NAME}
        x,y={X},{Y}
        side=2
        facing=sw
        [modifications]
            {TRAIT_{TRAIT1}}
            {TRAIT_{TRAIT2}}
        [/modifications]
    [/unit]
#enddef
    # wmllint: whofield PLACE_GUARD 6

    # *************************** PRESTART ***************************
    [event]
        name=prestart

        [hide_unit]
            id=Ardonna
        [/hide_unit]

        [objectives]
            side=1
            [objective]
                description= _ "Kill all the guards, and capture the guardhouse"
                condition=win
            [/objective]

            {HOW_TO_LOSE_WITH_ARDONNA}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]

            [note]
                description= _ "Right-click on a grave adjacent to your leader to raise a unit."
            [/note]
            [note]
                description= _ "Each grave can be used only once."
            [/note]
            [note]
                description= _ "This scenario takes place entirely at night."
            [/note]
        [/objectives]

        [label]
            x,y=10,11
            text= _ "Guardhouse"
            immutable=no
        [/label]
        [item]
            x,y=15,7
            image=scenery/temple1.png
        [/item]
        [label]
            x,y=15,7
            # This label bled into the two hexes on either side, and obscured
            # the units there. It's better on two lines. The extra spaces before
            # "Temple" are to center that word above the others.
            text= _ "  Temple
of Healing"
            immutable=no
        [/label]
        [item]
            x,y=23,8
            image=items/gravestone1.png
        [/item]

        {PLACE_GUARD 10 11 (Spearman) RESILIENT QUICK "Gwyllin" (_"Gwyllin")}
        {PLACE_GUARD 10 10 (Spearman) QUICK RESILIENT "Veomyr" (_"Veomyr")}
        {PLACE_GUARD 8 10 (Spearman) STRONG RESILIENT "Syrillin" (_"Syrillin")}
        {PLACE_GUARD 7 10 (Bowman) STRONG INTELLIGENT "Glant" (_"Glant")}

#ifdef HARD
        {PLACE_GUARD 8 9 (Spearman) STRONG INTELLIGENT "Renvan" (_"Renvan")}
        {PLACE_GUARD 10 9 (Bowman) STRONG RESILIENT "Vin" (_"Vin")}
#endif

#ifdef EASY
        {PLACE_GUARD 9 10 (Lieutenant) AGED INTELLIGENT "Caradoc" (_"Caradoc")}
#else
        {PLACE_GUARD 9 10 (Lieutenant) RESILIENT INTELLIGENT "Caradoc" (_"Caradoc")}
#endif

        # We don't want the guard on the village to move from there:
        {FREEZE_UNIT Gwyllin}

        [store_locations]
            terrain=*^Gryv
            variable=graves
        [/store_locations]

        [for]
            array=graves
            variable=i
            [do]
                [set_variable]
                    name=stone_number
                    rand=1..3
                [/set_variable]
                [item]
                    x=$graves[$i].x
                    y=$graves[$i].y
                    image=items/gravestone$stone_number|.png
                [/item]
            [/do]
        [/for]

        [clear_variable]
            name=graves,stone_number
        [/clear_variable]

        {SET_MENU_ITEM_FOR (Walking Corpse) walking_corpse 8}
    [/event]

    # *************************** PLAY ***************************
    [event]
        name=moveto
        [filter]
            side=1
            x, y=15, 7
        [/filter]

        # Choose a bat off the recall list if there is one.
        [role]
            type=Blood Bat SotA, Vampire Bat SotA  # A Dread Bat would be too powerful.
            search_recall_list=yes
            role=hiding_bat
        [/role]

        # Store the bat if there was one, or create and store one if there wasn't.
        [if]
            [have_unit]
                role=hiding_bat
                search_recall_list=yes
            [/have_unit]
            [then]
                [store_unit]
                    [filter]
                        role=hiding_bat
                    [/filter]
                    variable=frightened_bat
                [/store_unit]
            [/then]
            [else]
                [unit]
                    type=Vampire Bat SotA
                    x, y=1, 1
                [/unit]
                [store_unit]
                    [filter]
                        x, y=1, 1
                    [/filter]
                    variable=frightened_bat
                    kill=yes
                [/store_unit]
            [/else]
        [/if]
        [move_unit_fake]
            type=$frightened_bat.type
            x=15, 16
            y=7, 7
        [/move_unit_fake]

        [unstore_unit]
            variable=frightened_bat
            x, y=16, 7
        [/unstore_unit]
        # If there is a bat with a role, it's still on the recall list at this point,
        # though there is a copy of it on the map as well.

        # Ardonna's comment is different depending on whether she has seen this bat
        # before or not.
        [if]
            [have_unit]
                role=hiding_bat
                search_recall_list=yes
            [/have_unit]
            [then]
                [message]
                    speaker=Ardonna
                    message= _ "Oh, hello friend! I didn't know you were hiding in there."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Ardonna
                    message= _ "Oh, hello! You're a handsome one."
                [/message]
            [/else]
        [/if]
        [kill]
            # We can't be certain where the bat is, but we know it's the only one.
            race=bats
            x=1-26  # This keeps the bats on the recall list from going away.
        [/kill]
        # The bat is very likely on 16, 7, so we're not going to worry about if it's not.
        [move_unit_fake]
            type=$frightened_bat.type
            x=16, 17
            y=7, 1
        [/move_unit_fake]
        [message]
            speaker=Ardonna
            message= _ "Hey, come back! I didn't mean to frighten you."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "Maybe I could attract it if I jingled some coins."
        [/message]
        [if]
            [variable]
                name=frightened_bat.type
                equals=Vampire Bat SotA
            [/variable]
            [then]
                [set_variable]
                    name=message_image
                    value="units/undead/bat-se-3.png~CROP(13,15,46,39)~XBRZ(2)"
                [/set_variable]
            [/then]
            [else]
                [set_variable]
                    name=message_image
                    value="units/undead/bloodbat-se-3.png~CROP(13,15,46,39)~XBRZ(2)"
                [/set_variable]
            [/else]
        [/if]
        [message]
            speaker=narrator
            image=$message_image
            message= _ "Right-click adjacent to your leader to summon the bat."
        [/message]
        [clear_variable]
            name=message_image
        [/clear_variable]

        [set_menu_item]
            id=summon_bat
            description= _ "Summon the Bat (20 gold)"
            image=units/icons/icon-bat.png

            [show_if]
                [and]
                    [have_location]
                        [and]
                            [filter]
                                id=Ardonna
                            [/filter]
                            radius=1
                        [/and]
                    [/have_location]
                    [not]
                        [have_unit]
                            x,y=$x1,$y1
                        [/have_unit]
                    [/not]
                    [variable]
                        name=bat_summoned
                        boolean_equals=no
                    [/variable]
                [/and]
            [/show_if]

            [command]
                [store_gold]
                    side=1
                    variable=gold
                [/store_gold]

                [if]
                    [variable]
                        name=gold
                        less_than=20
                    [/variable]
                    [then]
                        [message]
                            speaker=narrator
                            image=items/gold-coins-message.png
                            message=_ "You don't have enough gold to summon the bat."
                        [/message]
                    [/then]
                    [else]
                        [gold]
                            side=1
                            amount=-20
                        [/gold]
                        # x1 and y1 have to be stored because they can be changed by the
                        # player right-clicking again during this command:
                        [set_variable]
                            name=bat_x
                            value=$x1
                        [/set_variable]
                        [set_variable]
                            name=bat_y
                            value=$y1
                        [/set_variable]
                        [set_variable]
                            name=bat_summoned
                            value=yes
                        [/set_variable]
                        [move_unit_fake]
                            type=$frightened_bat.type
                            x=17, $bat_x
                            y=1, $bat_y
                        [/move_unit_fake]

                        [if]
                            [have_unit]
                                role=hiding_bat
                                search_recall_list=yes
                            [/have_unit]
                            [then]
                                [recall]
                                    role=hiding_bat
                                    x, y=$bat_x, $bat_y
                                    show=no
                                [/recall]
                                [modify_unit]
                                    [filter]
                                        role=hiding_bat
                                    [/filter]
                                    moves=0
                                [/modify_unit]
                            [/then]
                            [else]
                                [unit]
                                    type=Vampire Bat SotA
                                    x, y=$bat_x, $bat_y
                                    moves=0
                                [/unit]
                            [/else]
                        [/if]

                        [clear_variable]
                            name=bat_x,bat_y
                        [/clear_variable]
                    [/else]
                [/if]
            [/command]
        [/set_menu_item]
    [/event]

    [event]
        name=capture
        first_time_only=no

        [filter]
            side=1
            x,y=10,11
        [/filter]

        [allow_recruit]
            type=Skeleton,Skeleton Archer
            side=1
        [/allow_recruit]
        [message]
            speaker=narrator
            # This puts images of the two units next to each other,
            # scaled to the same size:
            image=story/black-background.png~BLIT(portraits/undead/archer.png~SCALE(180,180),6,25 )~BLIT(portraits/undead/skeleton.png~SCALE(220,220),187,0)~CROP(0,0,376,205)~SCALE(171,93)
            message= _ "You can now recruit skeletons and skeleton archers!"
        [/message]
        [set_variable]
            name=can_recruit_skeletons
            value=yes
        [/set_variable]

        [fire_event]
            name=guards_emerge
        [/fire_event]

        {SET_MENU_ITEM_FOR (Skeleton) skeleton 15}
        {SET_MENU_ITEM_FOR (Skeleton Archer) skeleton_archer 14}

        [fire_event]
            name=check for win
        [/fire_event]
    [/event]

    # This macro animates guards moving out of the guardhouse. Each guard moves to the
    # nearest unoccupied, walkable, hex, without an ^Nhyr overlay. ^Nhyr ("Not here") marks
    # hexes outside the fence where the unit shouldn't be placed. We use it because it's made
    # to be invisible in the minimap. ^Fnzb is the base fence tile.
#define MOVE_AND_PLACE_GUARD TRAIT1 TRAIT2 ID NAME
    {NEAREST_HEX 10 11 20 (
        [and]
            terrain=!,*^Nhyr,*^Qov,*^Fnzb
            [not]
                x,y=10,11
            [/not]
            [not]
                [filter]
                [/filter]
            [/not]
        [/and] ) location}

        [move_unit_fake]
            type=Spearman
            x=10, $location.x
            y=11, $location.y
            side=2
        [/move_unit_fake]
        {PLACE_GUARD $location.x $location.y (Spearman) {TRAIT1} {TRAIT2} {ID} {NAME}}
        [clear_variable]
            name=location
        [/clear_variable]
#enddef
    # wmllint: whofield MOVE_AND_PLACE_GUARD 3

    [event]
        name=guards_emerge
        first_time_only=yes

        {MOVE_AND_PLACE_GUARD STRONG RESILIENT "Blollyn" (_"Blollyn")}
        {MOVE_AND_PLACE_GUARD INTELLIGENT RESILIENT "Ceoran" (_"Ceoran")}
#ifdef HARD
        {MOVE_AND_PLACE_GUARD INTELLIGENT QUICK "Vindry" (_"Vindry")}
        {MOVE_AND_PLACE_GUARD STRONG QUICK "Aethacyn" (_"Aethacyn")}
        {MOVE_AND_PLACE_GUARD STRONG INTELLIGENT "Elomyr" (_"Elomyr")}
#endif
    [/event]

    # A capture event does not fire when a leaderless side takes a village, but that is
    # what we need. The filters make this event fire when a unit from side 2 retakes the
    # "guardhouse" village. The can_recruit_skeletons variable is used to check whether
    # side 1 owned the village before.
    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=2
            x,y=10,11
        [/filter]
        [filter_condition]
            [variable]
                name=can_recruit_skeletons
                equals=yes
            [/variable]
        [/filter_condition]

        [disallow_recruit]
            type=Skeleton,Skeleton Archer
            side=1
        [/disallow_recruit]
        [message]
            speaker=narrator
            image=logo.png
            message= _ "You can no longer recruit skeletons and skeleton archers."
        [/message]
        [clear_menu_item]
            id=raise_skeleton_archer, raise_skeleton
        [/clear_menu_item]
        [set_variable]
            name=can_recruit_skeletons
            value=no
        [/set_variable]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            side=2
        [/filter]
        [fire_event]
            name=check for win
        [/fire_event]
    [/event]

    [event]
        name=check for win
        first_time_only=no

        [if]
            [and]
                [have_location]
                    x,y=10,11
                    owner_side=1
                [/have_location]
                [not]
                    [have_unit]
                        side=2
                    [/have_unit]
                [/not]
            [/and]

            [then]
                [clear_variable]
                    name=can_recruit_skeletons,gold,description_text,unit_string,bat_summoned,frightened_bat
                [/clear_variable]
                [clear_menu_item]
                    id=raise_skeleton_archer, raise_skeleton, raise_walking_corpse, summon_bat
                [/clear_menu_item]

                [allow_recruit]
                    type=Walking Corpse
                    side=1
                [/allow_recruit]

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

    [event]
        name=recruit,recall
        id=more_guards
        [message]
            speaker=Ardonna
#ifdef HARD
            message= _ "Wait, that guard said there were twelve of them, so where are the other five?"
#else
            message= _ "Wait, that guard said there were seven of them, so where are the other two?"
#endif
        [/message]
    [/event]

    # *************************** OPENING / ENDING ***************************
    [event]
        name=start

        [place_shroud]
            side=1
        [/place_shroud]
        [remove_shroud]
            side=1
            x,y=9,11
            radius=5
        [/remove_shroud]
        [message]
            speaker=Syrillin
            message= _ "Why are we stuck guarding a cemetery all night?"
        [/message]
        [message]
            speaker=Veomyr
            image=portraits/humans/spearman-2.png
#ifdef HARD
            message= _ "And why <i>twelve</i> of us? Who wants to break into a cemetery that badly?"
#else
            message= _ "And why <i>seven</i> of us? Who wants to break into a cemetery that badly?"
#endif
        [/message]
        [message]
            speaker=Glant
            message= _ "I don’t know, but this evening a mage from the academy was here talking to the mayor, my brother says."
        [/message]
        [message]
            speaker=Caradoc
            message= _ "Well <i>I</i> say you shouldn’t question orders, so pipe down."
        [/message]
        [place_shroud]
            side=1
        [/place_shroud]

        # Until now, Ardonna has been invisible. To keep her from clearing the
        # shroud around her until she is revealed in the graveyard, she started
        # buried in the middle of a void. The void kept her from seeing anything.
        # She is not in her starting location though. The position where we actually
        # want her to start would take a lot of work to un-void, so she was at the
        # edge of the map in a place where we wanted only hill terrain.
        [teleport]
            [filter]
                id=Ardonna
            [/filter]
            x,y=22,7
            animate=no
            clear_shroud=no
            check_passability=no
        [/teleport]
        [terrain]  # Turn void into hills
            terrain=Hh
            [and]
                terrain=Xv
            [/and]
        [/terrain]

        [unhide_unit]
            id=Ardonna
        [/unhide_unit]
        [remove_shroud]
            side=1
            x,y=22,7
            radius=5
        [/remove_shroud]

        [message]
            speaker=Ardonna
            message= _ "They must be guarding the cemetery from <i>me</i>! Maybe Aimucasur really was suspicious. It’s a good thing I’m here already, but how am I going to get out?

Well, I might as well do my experiment and worry about leaving later."
        [/message]

        [item]
            x,y=23,8
            image=items/dirt.png
        [/item]
        [delay]
            time=400
        [/delay]
        [unit]
            side=1
            x,y=23,8
            id=first_zombie
            type=Walking Corpse
            animate=yes
            moves=0
            attacks_left=0
            facing=nw
        [/unit]

        [message]
            speaker=Ardonna
            message= _ "Hello?"
        [/message]
        [message]
            speaker=first_zombie
            image=portraits/zombie-farmer.png
            message= _ "Uhngh."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "Do you remember anything?"
        [/message]
        [message]
            speaker=first_zombie
            image=portraits/zombie-farmer.png
            message= _ "Uhrrr."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "It seems that my first guess was correct. The poor creature is mindless."
        [/message]

        [place_shroud]
            side=1
        [/place_shroud]
        [remove_shroud]
            side=1
            x,y=9,11
            radius=5
        [/remove_shroud]
        [message]
            speaker=Veomyr
            image=portraits/humans/spearman-2.png
            message= _ "I heard something over there!"
        [/message]
        [modify_unit]
            [filter]
                side=2
            [/filter]
            facing=ne
        [/modify_unit]
        [message]
            speaker=Glant
            message= _ "Who’s there?"
        [/message]

        [remove_shroud]
            side=1
        [/remove_shroud]
        [move_unit]
            id=Ardonna
            to_x=21
            to_y=7
        [/move_unit]
        [modify_unit]
            # This is not really necessary at the moment (as of 1.11.7) because
            # dark adepts can't face north anyway. This is in case that changes.
            [filter]
                id=Ardonna
            [/filter]
            facing=sw
        [/modify_unit]
        [message]
            speaker=Ardonna
            message= _ "It’s only me. Is the cemetery closed then? I was about to leave."
        [/message]
        [message]
            speaker=Syrillin
            message= _ "You and that... other person. Who is that?"
        [/message]
        [message]
            speaker=Ardonna
            message= _ "Oh, him. See here, I don't want any trouble, but he is a little... ah..."
        [/message]
        [message]
            speaker=Caradoc
            message= _ "He's <i>dead</i>! This is dark sorcery like in my granddad’s time in the old country! The penalty is death. Attack and destroy them both!"
        [/message]
        [message]
            speaker=Ardonna
            message= _ "Hey! Don't do that, or I will need more of them."
        [/message]
        [message]
            speaker=Ardonna
            message= _ "I would do better if I had weapons, and I bet I can find some in the guardhouse. Go take it, my companions."
        [/message]
        [message]
            speaker=Caradoc
            message= _ "Gwyllin, don’t move from that guardhouse."
        [/message]
    [/event]

    [event]
        name=time over

        [message]
            speaker=Ardonna
            message= _ "The morning has come, and we have not escaped the city. We will be caught for sure!"
        [/message]
    [/event]
    {HERO_DEATHS}
    {MANAGE_PROFILE}

    # wmllint: whofield clear PLACE_GUARD MOVE_AND_PLACE_GUARD
#undef PLACE_GUARD
#undef MOVE_AND_PLACE_GUARD
#undef SET_MENU_ITEM_FOR
[/scenario]
