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

        [part]
            background=dead-water-map.png
            show_title=yes
            {OLD_BATTLE 746 673}
            {OLD_JOURNEY 729 657}
            {OLD_JOURNEY 734 635}
            {OLD_BATTLE 732 615}
            {OLD_JOURNEY 708 612}
            {OLD_JOURNEY 681 607}
            {OLD_JOURNEY 654 600}
            {OLD_JOURNEY 647 573}
            {OLD_JOURNEY 640 546}
            {OLD_BATTLE 650 522}
            {OLD_JOURNEY 637 497}
            {OLD_JOURNEY 628 473}
            {OLD_JOURNEY 610 454}
            {OLD_JOURNEY 589 437}
            {OLD_JOURNEY 576 412}
            {OLD_JOURNEY 575 388}
            {OLD_JOURNEY 552 381}
            {OLD_BATTLE 542 361}
            {OLD_JOURNEY 523 370}
            {OLD_JOURNEY 501 381}
            {OLD_JOURNEY 477 391}
            {OLD_BATTLE 455 401}
            {OLD_JOURNEY 434 414}
            {OLD_JOURNEY 414 428}
            {OLD_BATTLE 395 446}
            {OLD_JOURNEY 402 471}
            {OLD_JOURNEY 396 495}
            {OLD_JOURNEY 387 518}
            {OLD_JOURNEY 369 537}
            {OLD_JOURNEY 344 548}
            {OLD_JOURNEY 319 542}
            {OLD_JOURNEY 307 523}
            {OLD_REST 306 497}
            {NEW_JOURNEY 286 479}
            {NEW_JOURNEY 265 467}
            {NEW_JOURNEY 266 444}
            {NEW_JOURNEY 279 424}
            {NEW_JOURNEY 301 413}
            {NEW_JOURNEY 321 399}
            {NEW_JOURNEY 339 378}
            {NEW_JOURNEY 354 356}
            {NEW_JOURNEY 368 334}
            {NEW_JOURNEY 384 315}
            {NEW_JOURNEY 395 293}
            {NEW_JOURNEY 375 278}
            {NEW_JOURNEY 357 264}
            {NEW_BATTLE 355 242}
        [/part]
    [/story]

    # Don't change this order without modifying the turns on which the
    # bats appear and disappear.
    {DUSK}
    {FIRST_WATCH}
    {SECOND_WATCH}
    {DAWN}
    {MORNING}
    {AFTERNOON}

    {TURNS4 16 17 18 19}
    victory_when_enemies_defeated=no

    # wmllint: validate-off
    [side]
        # wmllint: recognize Kai Krellis
        {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}
        # wmllint: recognize Gwabbo
        # wmllint: recognize Cylanna
        # wmllint: recognize Friendly Bat

        [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

        # Put in a bunch of scorpions. The number of them depends on
        # the difficulty:
        [set_variable]
            name=number_of_scorpions
#ifdef EASY
            value=10
#endif
#ifdef NORMAL
            value=13
#endif
#ifdef HARD
            value=16
#endif
#ifdef NIGHTMARE
            value=19
#endif
        [/set_variable]

        # The location starts out with a code meaning "find another location"
        [set_variable]
            name=scorp_x
            value=-999
        [/set_variable]

        # Put a scorpion in a random location with some
        # constraints. (If the same location gets chosen a second
        # time, the new scorpion at that location could get forced
        # into an impossible spot. That’s OK because it would only be off
        # by one hex, and it will have been able to move by the time the
        # player sees it.)
        {REPEAT $number_of_scorpions (
            # While x and y don't correspond to a good location...
            [while]
                [variable]
                    name=scorp_x
                    equals=-999
                [/variable]
                [or]
                    [have_location]
                        x=$scorp_x
                        y=$scorp_y
                        terrain=Qx*,W*    # In water or a chasm

                        [or]
                            terrain=K*
                            [and]
                                x=$scorp_x
                                y=$scorp_y
                                radius=8      # Too close to the player’s keep
                            [/and]
                        [/or]
                    [/have_location]
                [/or]
                [do]
                    # ...pick a random location x and y
                    {RANDOM 1..18}
                    [set_variable]
                        name=scorp_x
                        value=$random
                    [/set_variable]
                    {RANDOM 1..24}
                    [set_variable]
                        name=scorp_y
                        value=$random
                    [/set_variable]
                [/do]
            [/while]

            [unit]
                type=Giant Scorpion
                x=$scorp_x
                y=$scorp_y
                side=2
            [/unit]

            # Code to tell the while loop to find another location
            [set_variable]
                name=scorp_x
                value=-999
            [/set_variable]
        )}
    [/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 chasm_hexes hex}
        {RANDOM ({BAT_TYPES_VALUE})}
        [unit]
            type=$random
            x=$chasm_hexes[$hex].x
            y=$chasm_hexes[$hex].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]
    {NEXT hex}

    {CLEAR_VARIABLE chasm_hexes}
    {CLEAR_VARIABLE hex}
#enddef

#define BATS_ENTER_CAVE
#enddef

    [event]
        name=ai 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 bats bat}
                    {NEAREST_HEX $bats[$bat].x $bats[$bat].y 99 (terrain=Qx*) chasm_hex}
                    [kill]
                        id=$bats[$bat].id
                        animate=no
                    [/kill]
                    [move_unit_fake]
                        type=$bats[$bat].type
                        x=$bats[$bat].x, $chasm_hex.x
                        y=$bats[$bat].y, $chasm_hex.y
                        side=2
                    [/move_unit_fake]
                {NEXT bat}

                {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/transparent/caladon.png
        [/unit]

        [if]
            [variable]
                name=unit.id
                equals=Keshan
            [/variable]
            [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.id
                            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_x
        [/clear_variable]
        [clear_variable]
            name=scorp_y
        [/clear_variable]
        [clear_variable]
            name=number_of_scorpions
        [/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]
