#textdomain wesnoth-dw

# You need pierce and fire to take care of scorpions. Javelineers get
# one more level to shine. Diviners are also great. Hopefully you have
# Keshan and the storm trident because those will be very
# useful. Keshan is especially helpful in actually finding the
# mage. He can get there several turns ahead of even the fastest
# merman (after you take out most of the scorpions in the way), but of
# course you don't *need* him.

[scenario]
    name= _ "The Mage"
    map_data="{campaigns/Dead_Water/maps/The_Mage.map}"

    id=09_The_Mage
    next_scenario=10_The_Flaming_Sword

    [story]
        [part]
            {DW_BIGMAP}
            story= _ "The party traveled back to the mainland and followed the shore further north. Kai Krellis had much to think about. First, what Tyegëa had revealed about his ancestry gave him questions he could not answer. Second, he was nervous about the task ahead. He felt confidence in his people but feared paying too great a price in dead and wounded to pass Tyegëa’s test. He felt sometimes angry at Tyegëa for sending him on this extra journey, and sometimes grateful that she was willing to help at all."
        [/part]

        [part]
            {DW_BIGMAP}
            story= _ "After several days, the smell of the swamp was just becoming noticeable when they found a small ruined castle in the right place to be the one Tyegëa had mentioned. Night was falling, and it was very dark beneath the trees, but Krellis was in a hurry, now that the end of their journey was in sight. He decided to go ashore and try to find the mage immediately."
        [/part]
    [/story]

    {DW_TRACK {JOURNEY_09_NEW} }

    # Don't change this order without modifying the turns on which the
    # bats appear and disappear.
    {DEFAULT_SCHEDULE_DUSK}
    {TURNS4 16 17 18 19}
    victory_when_enemies_defeated=no

    # wmllint: validate-off
    [side]
        {SIDE_1}
        {GOLD4 120 110 100 90}
        shroud=yes
    [/side]
    # wmllint: validate-on

    [side]
        side=2
        controller=ai
        user_team_name= _ "Hungry Creatures"
        team_name=bad guys
        no_leader=yes
        shroud=yes
        [ai]
            village_value=0
        [/ai]
    [/side]

    [event]
        name=prestart

        [music]
            name=revelation.ogg
        [/music]

        {RECALL_LOYAL_UNITS}

        [objectives]
            side=1
            [objective]
                description= _ "Find Caladon the mage"
                condition=win
            [/objective]

            {HOW_TO_LOSE}

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

        {PLACE_IMAGE scenery/temple1.png 8 5}

        [unit]
            type=Giant Spider
            x=17
            y=4
            side=2
        [/unit]
#ifndef EASY
        [unit]
            type=Giant Spider
            x=2
            y=4
            side=2
        [/unit]
#endif
#ifdef NIGHTMARE
        [unit]
            type=Giant Spider
            x=11
            y=5
            side=2
        [/unit]
#endif
        [random_placement]
            {QUANTITY4 num_items 10 13 16 19}
            variable=scorp
            [filter_location]
                include_borders=no
                [not]
                    # In water or a chasm
                    terrain=Qx*,W*
                [/not]
                [not]
                    # Too close to the player’s keep
                    terrain=K*
                    radius=8
                [/not]
                [not]
                    # Occupied by spiders.
                    [filter]
                    [/filter]
                [/not]
            [/filter_location]
            [command]
                [unit]
                    type=Giant Scorpion
                    x=$scorp.x
                    y=$scorp.y
                    side=2
                [/unit]
            [/command]
        [/random_placement]
    [/event]

    [event]
        name=start
        [message]
            speaker=Cylanna
            message= _ "I do not much care for the look of this area. The darkness seems to hang beneath the trees, unnaturally dense."
        [/message]
        [message]
            speaker=Teeloa
            message= _ "I just heard a splash. I think something’s out there."
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "Let us find the mage quickly and leave."
        [/message]
    [/event]

    [event]
        name=turn 2
        [music]
            name=the_city_falls.ogg
            append=yes
        [/music]
    [/event]

    # *****BEGIN BATS SECTION****************BEGIN BATS SECTION*****

    # Puts bats in the southern chasm. Random bats will be chosen from
    # the BAT_TYPES_VALUE. Chasm hexes are found rather than hard-coded
    # so they can be moved or changed on the map without affecting
    # this macro. (As long as they don't go too far.) Besides, it's
    # easy to do.
#define BATS_EXIT_CAVE BAT_TYPES_VALUE
    #find chasm hexes, and put them in an array
    [store_locations]
        variable=chasm_hexes
        terrain=Qx* #Chasm
        [and]
            x=10
            y=21
            radius=5
        [/and]
    [/store_locations]

    # Put a bat into each chasm hex.
    [foreach]
        array=chasm_hexes
        [do]
            {RANDOM ({BAT_TYPES_VALUE})}
            [unit]
                type=$random
                x=$this_item.x
                y=$this_item.y
                side=2
                animate=yes  # The animation fades in, which looks good. If the animation is ever changed to something else, this might have to be changed.
            [/unit]
        [/do]
    [/foreach]

    {CLEAR_VARIABLE chasm_hexes}
#enddef

#define BATS_ENTER_CAVE
#enddef

    [event]
        name=side 2 turn
        first_time_only=no

        [set_variable]
            name=time_of_day
            value=$turn_number
        [/set_variable]
        [set_variable]
            name=time_of_day
            modulo=6
        [/set_variable]

        # The bats go in at dawn.
        [if]
            [variable]
                name=time_of_day
                equals=4
            [/variable]
            [then]
                # Each bat will move back to the nearest chasm hex and disappear.
                [store_unit]
                    [filter]
                        race=bats
                        [not]
                            side=1
                        [/not]
                    [/filter]
                    variable=bats
                [/store_unit]

                [foreach]
                    array=bats
                    [do]
                        {NEAREST_HEX $this_item.x $this_item.y 99 (terrain=Qx*) chasm_hex}
                        [kill]
                            id=$this_item.id
                            animate=no
                        [/kill]
                        [move_unit_fake]
                            type=$this_item.type
                            x=$this_item.x, $chasm_hex.x
                            y=$this_item.y, $chasm_hex.y
                            side=2
                        [/move_unit_fake]
                    [/do]
                [/foreach]

                {CLEAR_VARIABLE bats}
                {CLEAR_VARIABLE chasm_hex}
            [/then]
        [/if]

        # The bats start coming out at dusk. The number of turns they keep coming out is determined by the difficulty. So is the type of bat:
#ifdef EASY
        [if]
            [variable]
                name=time_of_day
                equals=1
            [/variable]
            [then]
                {BATS_EXIT_CAVE (Vampire Bat)}
            [/then]
        [/if]
#endif
#ifdef NORMAL
        [if]
            [variable]
                name=time_of_day
                equals=1
            [/variable]
            [or]
                [variable]
                    name=time_of_day
                    equals=2
                [/variable]
            [/or]
            [then]
                {BATS_EXIT_CAVE (Vampire Bat)}
            [/then]
        [/if]
#endif
#ifdef HARD
        [if]
            [variable]
                name=time_of_day
                equals=1
            [/variable]
            [or]
                [variable]
                    name=time_of_day
                    equals=2
                [/variable]
                [or]
                    [variable]
                        name=time_of_day
                        equals=3
                    [/variable]
                [/or]
            [/or]
            [then]
                {BATS_EXIT_CAVE (Vampire Bat)}
            [/then]
        [/if]
#endif
#ifdef NIGHTMARE
        [if]
            [variable]
                name=time_of_day
                equals=1
            [/variable]
            [or]
                [variable]
                    name=time_of_day
                    equals=2
                [/variable]
                [or]
                    [variable]
                        name=time_of_day
                        equals=3
                    [/variable]
                [/or]
            [/or]
            [then]
                {BATS_EXIT_CAVE (Vampire Bat,Blood Bat)}
            [/then]
        [/if]
#endif

        # Dialog the first time bats appear:
        [if]
            [variable]
                name=turn_number
                equals=1
            [/variable]
            [then]
                [message]
                    speaker=Teeloa
                    message= _ "Hey, that cavern is full of bats! I HATE those things."
                [/message]
                [message]
                    speaker=Kai Krellis
                    message= _ "I hope there aren’t any more bats in there."
                [/message]
#ifndef EASY
                [if]
                    [have_unit]
                        id=Gwabbo
                    [/have_unit]
                    [then]
                        [message]
                            speaker=Gwabbo
                            message= _ "This is a good place for a large colony, so I think we will see more soon."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=Cylanna
                            message= _ "This is a good place for a large colony, so I imagine we will see more soon."
                        [/message]
                    [/else]
                [/if]
#endif
            [/then]
        [/if]
    [/event]
    # ***** END BATS SECTION********************END BATS SECTION*****

    [event]
        name=moveto
        [filter]
            side=1
            x=8
            y=5
        [/filter]

        [unit]
            type=Silver Mage
            x=8
            y=5
            side=1
            id=Caladon
            name= _ "Caladon"
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
            {IS_HERO}
            profile=portraits/caladon.png
        [/unit]

        [if]
            [have_unit]
                x,y=$x1,$y1
                id=Keshan,Inky
            [/have_unit]
            [then]
                [message]
                    speaker=Keshan
                    message= _ "There is somebody here."
                [/message]
                [message]
                    speaker=Caladon
                    message= _ "Whoa there! BACK off or else!"
                [/message]
                [message]
                    speaker=Kai Krellis
                    message= _ "Do not worry about him. He is friendly."
                [/message]
            [/then]
            [else]
                [if]
                    [variable]
                        name=unit.id
                        contains=Bat
                    [/variable]
                    [then]
                        [message]
                            speaker=unit
                            message= _ "Neep, neep, neep!"
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=unit
                            message= _ "Hey, I found somebody!"
                        [/message]
                    [/else]
                [/if]
            [/else]
        [/if]
        [message]
            speaker=Kai Krellis
            message= _ "You must be Caladon. We are glad to see you."
        [/message]
        [message]
            speaker=Caladon
            message= _ "I am Caladon. Am I glad to see YOU?"
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "I am Kai Krellis of Jotha. I am seeking a flaming sword, and I am told you know where to find it."
        [/message]
        [message]
            speaker=Caladon
            message= _ "Ha! A MERman wants the Flaming Sword of AGNOVON! Why would YOU be able to get it when so many others could NOT? Although you do have an impressive collection of allies there."
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "Whether I can succeed or not, I must try. Will you help me find it?"
        [/message]
        [message]
            speaker=Caladon
            message= _ "I will show you EXACTLY where it is, but knowing where to FIND it isn’t the hard part. Oh, no! You will see, my fine merman, you will see."
        [/message]
        [message]
            speaker=Cylanna
            message= _ "We would be very grateful if you would guide us."
        [/message]
        [message]
            speaker=Caladon
            message= _ "I would be HAPPY to guide such a pretty mermaid AND her friends. Follow me everybody!"
        [/message]

        [clear_variable]
            name=scorp
        [/clear_variable]
        [clear_variable]
            name=time_of_day
        [/clear_variable]

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

    [event]
        name=die
        [filter]
            id=Cylanna
        [/filter]
        [message]
            speaker=Kai Krellis
            message= _ "Cylanna! I need you!"
        [/message]
        [message]
            speaker=Kai Krellis
            message= _ "Tyegëa will never forgive me. We are lost."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=Kai Krellis
        [/filter]
        [message]
            speaker=Cylanna
            message= _ "We are lost without our king!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]
[/scenario]
