#textdomain wesnoth-utbs
# Level 11: The Battle for Zocthanol Isle

[scenario]

    id="11_Battle_for_Zocthanol_Isle"
    name= _ "The Battle for Zocthanol Isle"
    label= _ "The Battle for Zocthanol Isle"

    next_scenario=12_The_Final_Confrontation

    map_data="{campaigns/Under_the_Burning_Suns/maps/11_Battle_for_Zocthanol_Isle.map}"

    [music]
        name=wanderer.ogg
    [/music]
    {VICTORY_AND_DEFEAT_MUSIC}

    #don't display snapshot of map in saved games
    snapshot="no"
    victory_when_enemies_defeated=no

    #max turns in scenario varies depending on difficulty
#ifdef EASY
    turns="44"
#endif
#ifdef NORMAL
    turns="40"
#endif
#ifdef HARD
    turns="36"
#endif

    {DAWN1}
    {MORNING1}
    {MIDDAY1}
    {AFTERNOON1}
    {DUSK1}
    {SHORTDARK}
    {DAWN2}
    {MORNING2}
    {MIDDAY2}
    {AFTERNOON2}
    {DUSK2}
    {LONGDARK1}
    {LONGDARK2}
    {LONGDARK3}
    {LONGDARK4}

    #Side 1: elves
    [side]
        side=1
        description=Kaleh
        type=Desert Fighter
        canrecruit=yes
        {INCOME 0 0 0}
        controller=human
        shroud=yes
        fog=yes
        team_name=elf_ally
    [/side]

    #Side 2: Saurians (blue)
    [side]
        side=2
        type=Saurian Oracle
        description=Boyicht
        user_description= _ "Boyicht"
        upkeep=full
        canrecruit=yes
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally

#ifdef EASY
        recruit=Saurian Skirmisher, Saurian Augur
#endif

#ifdef NORMAL
        recruit=Saurian Skirmisher, Saurian Augur, Saurian Ambusher
#endif

#ifdef HARD
        recruit=Saurian Skirmisher, Saurian Augur, Saurian Ambusher, Saurian Soothsayer, Saurian Oracle
#endif

        [ai]
            recruitment_pattern=scout, healer, archer, scout, archer

            aggression=0.75
            caution=0.1

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

            passive_leader=yes
        [/ai]
    [/side]

    #Side 3: Undead (green)
    [side]
        side=3
        type=Draug
        description=Kelur
        user_description= _ "Kelur"
        upkeep=full
        canrecruit=yes
        {GOLD 125 150 150}
        {INCOME 15 17 19}
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally

#ifdef EASY
        recruit=Blood Bat, Ghost, Wraith, Revenant, Deathblade, Bone Shooter, Necrophage, Banebow
#endif

#ifdef NORMAL
        recruit=Blood Bat, Ghost, Wraith, Revenant, Deathblade, Bone Shooter, Necrophage, Banebow, Spectre
#endif

#ifdef HARD
        recruit=Blood Bat, Ghost, Wraith, Revenant, Deathblade, Bone Shooter, Necrophage, Banebow, Spectre, Draug
#endif

        [ai]
            recruitment_pattern=scout, scout, fighter, archer, fighter

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

            recruitment_pattern=scout,fighter,archer,fighter
            aggression=0.8
            caution=0.1
        [/ai]
    [/side]

    #Side 4: Orcs (yellow)
    [side]
        side=4
        type=Orcish Sovereign
        description=Graghht
        user_description= _ "Graghht"
        upkeep=full
        canrecruit=yes
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]
        {GOLD 125 150 150}
        {INCOME 15 17 19}
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally

#ifdef EASY
        recruit=Orcish Warrior, Orcish Crossbowman, Orcish Slayer, Goblin Knight, Goblin Pillager, Direwolf Rider, Orcish Warlord
#endif

#ifdef NORMAL
        recruit=Orcish Warrior, Orcish Crossbowman, Orcish Slayer, Goblin Knight, Goblin Pillager, Direwolf Rider, Orcish Warlord, Orcish Slurbow
#endif

#ifdef HARD
        recruit=Orcish Warrior, Orcish Crossbowman, Orcish Slayer, Goblin Knight, Goblin Pillager, Direwolf Rider, Orcish Warlord, Orcish Slurbow
#endif

        [ai]
            recruitment_pattern=scout, fighter, archer, fighter

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 2 3 4}

            aggression=0.8
            caution=0.1
        [/ai]
    [/side]

    #Side 5: Eloh
    [side]
        side=5
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally
    [/side]

    #Side 6: Vampire bats
    [side]
        side=6
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally
    [/side]

    #Side 7: Western Naga
    [side]
        side=7
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally

#ifdef EASY
        recruit=Naga Fighter, Naga Warrior, Naga Guardian, Naga Hunter
#endif

#ifdef NORMAL
        recruit=Naga Fighter, Naga Warrior, Naga Guardian, Naga Hunter, Naga Warden
#endif

#ifdef HARD
        recruit=Naga Fighter, Naga Warrior, Naga Guardian, Naga Hunter, Naga Warden, Naga Myrmidon
#endif

        [ai]
            aggression=0.75
            caution=0.1

            recruitment_pattern=fighter, archer, fighter, fighter

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

#ifdef EASY
            passive_leader=yes
#endif
        [/ai]
    [/side]

    #Side 8: Eastern Naga
    [side]
        side=8
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally

#ifdef EASY
        recruit=Naga Fighter, Naga Warrior, Naga Guardian, Naga Hunter
#endif

#ifdef NORMAL
        recruit=Naga Fighter, Naga Warrior, Naga Guardian, Naga Warden, Naga Hunter
#endif

#ifdef HARD
        recruit=Naga Fighter, Naga Warrior, Naga Myrmidon, Naga Warden, Naga Guardian, Naga Hunter
#endif

        [ai]
            aggression=0.75
            caution=0.1

            recruitment_pattern=fighter, archer, fighter, fighter

            # AI will attack a weak unit with a max of 3,4,5 units
            # depending on the difficulty (default=5)
            {ATTACK_DEPTH 3 4 5}

#ifdef EASY
            passive_leader=yes
#endif
        [/ai]
    [/side]

    #Side 9: trapped merfolk
    [side]
        side=9
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=elf_ally
    [/side]

    [story]
        [part]
            story= _ "Chapter 11: Our boats slipped softly through the water, shrouded in the predawn darkness. At this moment the merfolk would be launching their diversionary attack, but the fact that we had not encountered any resistance was still eerily disturbing. Ahead of us, the large island loomed, dark and menacing."
        [/part]

        [part]
            story= _ "In the end, almost all of my people decided to join in this final battle. I was surprised. They had gone through so much and yet they still had faith in me. Looking around at them, I could not help noticing how many familiar faces were missing. Barely a fourth of those who set out with us on our journey had survived. If I had known it would be this bad would I have ever left in the first place? I thought Eloh was protecting us and guiding our steps, but in truth it was all me. For better or for worse I have no one to blame but myself."
        [/part]

        [part]
            story= _ "But Zhul is right, if we came all this way just for a chance to help the merfolk defeat Yechnagoth then our journey was not in vain. We were searching for a new home, safe from all the horrors and death of the desert, but now this struggle seems more important. Could these islands possibly become a home for my people? It is a prospect too wonderful to dare to hope for. But in the end that is not what is driving me. All I care about is vengeance upon her that did this to us. Garak, Keratur, Tanstafaal, all those poor souls we left behind in our village and the many who have marked our path with their blood, they all shall be avenged."
        [/part]

        [part]
            story= _ "This conflict is greater than just us. These lands were once places of beauty and hope. The great empires may be gone, but still people struggle to survive. As bad as it all seems, there is still some beauty and light left, hidden away. I will not let it all be swallowed by a second darkness. I do not care what happens to me, but I pray to Eloh (if she is even listening) that if I die, then I die making these lands a better place. Please may this not all be in vain..."
        [/part]
    [/story]

    # Prestart functions:
    # increase cost of all units by 2
    # insert items onto map
    # increase cost of recruiting units
    # place item images on map
    # recall main heroes
    # initialize starting variables
    # remove shroud surrounding starting position
    # set starting scenario objectives
    # capture elves' starting villages

    [event]
        name=prestart

        # scenario testing units

        # increase cost of all units by 2

        [if]
            [variable]
                name=scen3
                numerical_equals=2
            [/variable]

            [then]
                #go from 8 to 10

                [disallow_recruit]
                    type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
                    side=1
                [/disallow_recruit]

                [disallow_recruit]
                    type=Desert Fighter9, Desert Archer9, Desert Hunter9, Desert Shaman9, Desert Scout9
                    side=1
                [/disallow_recruit]

                [allow_recruit]
                    type=Desert Fighter10, Desert Archer10, Desert Hunter10, Desert Shaman10, Desert Scout10
                    side=1
                [/allow_recruit]
            [/then]

            [else]
                [if]
                    [variable]
                        name=scen3
                        numerical_equals=1
                    [/variable]

                    [then]
                        #go from 7 to 9

                        [disallow_recruit]
                            type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter8, Desert Archer8, Desert Hunter8, Desert Shaman8, Desert Scout8
                            side=1
                        [/disallow_recruit]

                        [allow_recruit]
                            type=Desert Fighter9, Desert Archer9, Desert Hunter9, Desert Shaman9, Desert Scout9
                            side=1
                        [/allow_recruit]
                    [/then]
                [/if]

                [if]
                    [variable]
                        name=scen3
                        numerical_equals=3
                    [/variable]

                    [then]
                        #go from 9 to 11

                        [disallow_recruit]
                            type=Desert Fighter, Desert Archer, Desert Hunter, Desert Shaman, Desert Scout
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter2, Desert Archer2, Desert Hunter2, Desert Shaman2, Desert Scout2
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter3, Desert Archer3, Desert Hunter3, Desert Shaman3, Desert Scout3
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter4, Desert Archer4, Desert Hunter4, Desert Shaman4, Desert Scout4
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter5, Desert Archer5, Desert Hunter5, Desert Shaman5, Desert Scout5
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter8, Desert Archer8, Desert Hunter8, Desert Shaman8, Desert Scout8
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter9, Desert Archer9, Desert Hunter9, Desert Shaman9, Desert Scout9
                            side=1
                        [/disallow_recruit]

                        [disallow_recruit]
                            type=Desert Fighter10, Desert Archer10, Desert Hunter10, Desert Shaman10, Desert Scout10
                            side=1
                        [/disallow_recruit]

                        [allow_recruit]
                            type=Desert Fighter11, Desert Archer11, Desert Hunter11, Desert Shaman11, Desert Scout11
                            side=1
                        [/allow_recruit]
                    [/then]
                [/if]
            [/else]
        [/if]

        # add items to map

        # Eloh's temple

        #{PLACE_IMAGE scenery/temple1.png 26 18}

        # add elven ship to landing point

        {PLACE_IMAGE "units/transport/transport-galleon.png~RC(magenta>red)" 39 44}

        # wrecked ship was 13,14

        {PLACE_IMAGE scenery/wreck.png 13 9}

        # trapped merman in cage

        {PLACE_IMAGE units/merfolk/triton.png 10 5}
        {PLACE_IMAGE items/cage.png 10 5}

        [unit]
            type=Merman Triton
            description="Trapped Merman"
            user_description= _ "Trapped Merman"
            x,y=10,5
            side=2
            ai_special=guardian
        [/unit]

        # recall heroes

        [recall]
            description=Zhul
        [/recall]
        [recall]
            description=Nym
        [/recall]
        # recall dwarf/troll
        [recall]
            description=$ally_name
        [/recall]

        #recall merfolk

        [recall]
            description=Esanoo
        [/recall]
        [recall]
            description=Urruga
        [/recall]
        [recall]
            description=Nuvassa
        [/recall]
        [recall]
            description=Yantili
        [/recall]
        [recall]
            description=Il-tian
        [/recall]
        [recall]
            description=We-jial
        [/recall]

        #teleport merfolk to nearby water

        [teleport]
            [filter]
                description=Esanoo
            [/filter]
            x,y=42,42
        [/teleport]

        [teleport]
            [filter]
                description=Urruga
            [/filter]
            x,y=42,42
        [/teleport]

        [teleport]
            [filter]
                description=Nuvassa
            [/filter]
            x,y=42,42
        [/teleport]

        [teleport]
            [filter]
                description=Yantili
            [/filter]
            x,y=42,42
        [/teleport]

        [teleport]
            [filter]
                description=Il-tian
            [/filter]
            x,y=42,42
        [/teleport]

        [teleport]
            [filter]
                description=We-jial
            [/filter]
            x,y=42,42
        [/teleport]

        #initialize starting variables

        [set_variable]
            name=encountered_saurians
            value=0
        [/set_variable]

        [set_variable]
            name=captured_fort
            value=0
        [/set_variable]

        [set_variable]
            name=found_door
            value=0
        [/set_variable]

        [set_variable]
            name=num_keys_found
            value=0
        [/set_variable]

        # clock variable, starts at 1
        [set_variable]
            name=time_of_day
            value=1
        [/set_variable]

        # flag to store if first night has happened or not, starts at false
        [set_variable]
            name=first_night
            value=0
        [/set_variable]

        # flag to store if second_dawn has happened or not, starts at false
        [set_variable]
            name=second_dawn
            value=0
        [/set_variable]

        # number of bats to appear each night

#ifdef EASY
        [set_variable]
            name=number_vamp_bats
            value=5
        [/set_variable]

        [set_variable]
            name=number_blood_bats
            value=0
        [/set_variable]
#endif

#ifdef NORMAL
        [set_variable]
            name=number_vamp_bats
            value=3
        [/set_variable]

        [set_variable]
            name=number_blood_bats
            value=3
        [/set_variable]
#endif

#ifdef HARD
        [set_variable]
            name=number_vamp_bats
            value=3
        [/set_variable]

        [set_variable]
            name=number_blood_bats
            value=4
        [/set_variable]
#endif

        [set_variable]
            name=immortal_hero
            value=0
        [/set_variable]

        # set starting scenario objectives

        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Kaleh must capture a keep"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kaleh, Nym, Zhul"
                condition=lose
            [/objective]
        [/objectives]

        #create starting elves

        [unit]
            type=Desert Hunter
            description=Eagath
            user_description= _ "Eagath"
            upkeep=full
            x=37
            y=42
            side=1
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Desert Archer
            description=Alusan
            user_description= _ "Alusan"
            upkeep=full
            x=35
            y=43
            side=1
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        #create starting undead and orc guards

        [unit]
            description=Undead High Guard
            type=Revenant
            side=3
            x,y=25,20
            ai_special=guardian
        [/unit]

        [unit]
            description=Orcish High Guard
            type=Orcish Warrior
            side=4
            x,y=27,20
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
            ai_special=guardian
        [/unit]
    [/event]

    # Event 1: Starting dialogue

    [event]
        name=start

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Where did this fog come from? I can't see a thing!"
        [/message]

        [message]
            race=merman
            message= _ "Fog and darkness cloud this place, but we can use it to our advantage. The other ships will be safe hidden out in the deep water."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "We should find a fort before we land the rest of our people. I do not like the idea of landing everyone without a fort to protect us. Shrouded by the fog, they will be safe for the moment. Once we find a place to rally our people, we can bring the rest of them in and start fighting in earnest."
        [/message]

        [message]
            race=merman
            message= _ "I think there were some human ruins in the southwestern part of the island. If you explore the land to the west, then we will swim through the shallows and see what we can find."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "That is a good plan. First find a fort, then we can explore the rest of the island."
        [/message]

        # remove merfolk from map
        [store_unit]
            [filter]
                race=merman
            [/filter]
            kill=yes
            variable=merfolk_units
        [/store_unit]

        # capture villages for saurians

        [capture_village]
            x=8-29
            y=38-45
            side=2
        [/capture_village]

        # merfolk testing units

        #{UNIT_T (Merman Triton) (test) ( _ "test") 1 3 15}
        #{UNIT_T (Merman Entangler) (test) ( _ "test") 1 3 15}
        #{UNIT_T (Mermaid Siren) (test) ( _ "test") 1 3 15}
    [/event]

    # Event 2: Jungle Warning

    # keep player from entering jungle too early

    [event]
        name=moveto

        [filter]
            x=31-36
            y=32-37
            side=1
        [/filter]

        [if]
            [variable]
                name=captured_fort
                numerical_equals=0
            [/variable]

            [then]
                [message]
                    description=Zhul
                    image=portraits/zhul.png
                    message= _ "Ugh. That jungle seems dark and foreboding. Do you see those eyes? There are things staring at us from the depths of the jungle, but I can't tell what they are. As much as I love plants and trees, I don't like the look of it."
                [/message]

                [message]
                    description=Kaleh
                    image=portraits/kaleh.png
                    message= _ "Indeed. It seems much more open to the south. The merfolk mentioned that there were human ruins to the southwest. Maybe we should explore there first. I don't think I want to hack through the jungle until we have more elves at our side."
                [/message]
            [/then]
        [/if]
    [/event]

    # Event 3: Silence and Suspense

    [event]
        name=moveto

        [filter]
            x=1-27
            y=37-41
            side=1
        [/filter]

        [if]
            [variable]
                name=captured_fort
                numerical_equals=0
            [/variable]

            [then]
                [message]
                    description=Nym
                    image=portraits/nym.png
                    message= _ "I don't get it. All we see are ruins, bones, some sand and patches of grass. I thought we would be attacked the moment we set foot on this island. Where is everybody?"
                [/message]

                [message]
                    description=Kaleh
                    image=portraits/kaleh.png
                    message= _ "That's what worries me. I keep thinking that something is going to jump out from behind the next rock or stone wall and attack, but everything is silent. Too silent."
                [/message]
            [/then]
        [/if]
    [/event]

    # Event 3.5 Reset Saurians Gold to 0

    # Until player meets Saurians, keep their gold at 0

    [event]
        name=new turn
        first_time_only=no

        [if]
            [variable]
                name=encountered_saurians
                numerical_equals=0
            [/variable]

            [then]
                [modify_side]
                    side=2
                    gold=0
                [/modify_side]
            [/then]
        [/if]
    [/event]

    # Event 4: Encountering the Saurians

    [event]
        name=sighted

        [filter]
            description=Boyicht
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            description=Boyicht
            message= _ "You trespass on holy ground, The One says you must die!"
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Paugh! Little one, you are not worth our time. We are the Quenoth Elves! Flee and trouble us no longer or we will squash you like a bug."
        [/message]

        [message]
            description=Boyicht
            message= _ "No, you are not The One. You no command Boyicht. Attack!"
        [/message]

        # Saurians ambush

#ifdef EASY
        {UNIT_T (Saurian Skirmisher) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 17 39}
        {UNIT_T (Saurian Skirmisher) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 16 43}

        {UNIT_T (Saurian Augur) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 20 42}
#endif

#ifdef NORMAL
        #{UNIT_T (Saurian Ambusher) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 17 39}
        #{UNIT_T (Saurian Skirmisher) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 16 43}

        #{UNIT_T (Saurian Augur) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 20 42}
#endif

#ifdef HARD
        #{UNIT_T (Saurian Ambusher) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 17 39}
        #{UNIT_T (Saurian Skirmisher) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 16 43}

        #{UNIT_T (Saurian Oracle) (Fanatical Saurian) ( _ "Fanatical Saurian") 2 20 42}
#endif

        [set_variable]
            name=encountered_saurians
            value=1
        [/set_variable]

        [modify_side]
            side=2

#ifdef EASY
            income=3
            gold=20
#endif

#ifdef NORMAL
            income=4
            gold=30
#endif

#ifdef HARD
            income=5
            gold=40
#endif
        [/modify_side]
    [/event]

    # Death of Boyicht

    [event]
        name=die

        [filter]
            description=Boyicht
        [/filter]

        [message]
            description=Boyicht
            message= _ "My death matters not. The One will kill you all. None can resist her."
        [/message]

        [kill]
            description=Boyicht
            animate=yes
            fire_event=no
        [/kill]

        [message]
            speaker=second_unit
            message= _ "I say good riddance. He creeped me out."
        [/message]
    [/event]

    # Event 4.5 Naga leaders appear, activate sides 7 + 8

    # side 8 naga on eastern side of island are a bit stronger
    # than side 7 than those on western side

    [event]
        name=turn 4

        [unit]
            type=Naga Myrmidon
            description=Naga Leader
            user_description= _ "Naga Leader"
            canrecruit=yes
            side=7
            x,y=3,23
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [modify_side]
            side=7

#ifdef EASY
            income=7
            gold=75
#endif
#ifdef NORMAL
            income=9
            gold=95
#endif
#ifdef HARD
            income=11
            gold=115
#endif
        [/modify_side]

        [unit]
            type=Naga Myrmidon
            description=Naga Leader
            user_description= _ "Naga Leader"
            canrecruit=yes
            side=8
            x,y=46,28
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [modify_side]
            side=8

#ifdef EASY
            income=9
            gold=75
#endif
#ifdef NORMAL
            income=11
            gold=95
#endif
#ifdef HARD
            income=13
            gold=115
#endif
        [/modify_side]
    [/event]

    # Event 5: Capture the castle, merfolk and elves return

    [event]
        name=moveto

        [filter]
            description=Kaleh
            x,y=13,41
        [/filter]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "I have captured the keep. This castle is somewhat ruined, but it will serve our purposes. Now, I wonder where the merfolk are?"
        [/message]

        [set_variable]
            name=array_length
            value=$merfolk_units.length
        [/set_variable]

        [set_variable]
            name=counter
            value=0
        [/set_variable]

        [while]
            [variable]
                name=counter
                less_than=$array_length
            [/variable]

            [do]
                [unstore_unit]
                    variable=merfolk_units[$counter]
                    find_vacant=yes
                [/unstore_unit]

                [set_variable]
                    name=counter
                    add=1
                [/set_variable]
            [/do]
        [/while]

        {CLEAR_VARIABLE array_length}

        #teleport merfolk to nearby water

        [teleport]
            [filter]
                description=Esanoo
            [/filter]
            x,y=6,42
        [/teleport]

        [teleport]
            [filter]
                description=Urruga
            [/filter]
            x,y=6,42
        [/teleport]

        [teleport]
            [filter]
                description=Nuvassa
            [/filter]
            x,y=6,42
        [/teleport]

        [teleport]
            [filter]
                description=Yantili
            [/filter]
            x,y=6,42
        [/teleport]

        [teleport]
            [filter]
                description=Il-tian
            [/filter]
            x,y=6,42
        [/teleport]

        [teleport]
            [filter]
                description=We-jial
            [/filter]
            x,y=6,42
        [/teleport]

        [message]
            race=merman
            message= _ "Fear not, here we are! We have explored the southern half of the island. And except for those lizards you found, and some abandoned villages, it seem to be empty. We captured those villages for you, to help support your troops."
        [/message]

        [capture_village]
            x=8-29
            y=42-45
            side=1
        [/capture_village]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Thanks, I think we're going to need all the support we can get."
        [/message]

        [remove_shroud]
            x=1-50
            y=37-52
            side=1
        [/remove_shroud]

        [message]
            race=merman
            message= _ "Now that you have found a fortress to protect your people, we can bring in the other ships."
        [/message]

        # animations of ships landing

        [move_unit_fake]
            type=Galleon
            x=1,2,3,4,5,6,7,8,9,10
            y=41,40,40,39,39,38,38,37,38,38
        [/move_unit_fake]

        {PLACE_IMAGE "units/transport/transport-galleon.png~RC(magenta>red)" 10 38}

        [move_unit_fake]
            type=Galleon
            x=1,2,3,4,5,6,7,8,9
            y=42,41,41,40,40,39,40,39,39
        [/move_unit_fake]

        {PLACE_IMAGE "units/transport/transport-galleon.png~RC(magenta>red)" 9 39}

        [move_unit_fake]
            type=Galleon
            x=1,2,3,4,5,6,7,8,9
            y=43,42,42,41,41,40,40,39,40
        [/move_unit_fake]

        {PLACE_IMAGE "units/transport/transport-galleon.png~RC(magenta>red)" 9 40}

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Good, now we can start recruiting and recalling our warriors. Of course with so few people left, training new warriors will be very difficult and expensive. But if we lose this battle, then what use will gold be to us?"
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Now that we've set up a base of operations we should make our way to the black citadel in the mountains at the center of the island. I bet it's somewhere in the middle of that dark jungle."
        [/message]

        [message]
            race=merman
            message= _ "In our exploration we found a group of reinforcements, who were sent to help you, compliments of Melusand. You can recruit them into service at your base, if you wish. We may not be much use to you on land, but we will protect you against any threats from the water."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Thank you. I'm sure the reinforcements will be very useful."
        [/message]

        [allow_recruit]
            type=Mermaid Initiate, Merman Fighter, Merman Hunter
            side=1
        [/allow_recruit]

        [set_variable]
            name=captured_fort
            value=1
        [/set_variable]

        [objectives]
            summary= _ "New Objectives:"
            [objective]
                description= _ "Reach the black citadel in the center of the island."
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kaleh, Nym, Zhul"
                condition=lose
            [/objective]
        [/objectives]

        # change the music playing
        [music]
            name=battle.ogg
            immediate=yes
        [/music]
    [/event]

    # Event 6: Encounter the undead leader

    [event]
        name=sighted

        [filter]
            description=Kelur
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            description=Kelur
            message= _ "Feel the cold touch of death!"
        [/message]
    [/event]

    # Event 7: Encounter the orc leader

    [event]
        name=sighted

        [filter]
            description=Graghht
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            description=Graghht
            message= _ "I will slaughter you all and bathe in your blood!"
        [/message]
    [/event]

    # Event 8: Encounter stone citadel

    # this event is used if the unit triggering the event is not Kaleh

    [event]
        name=moveto

        [filter]
            x=25-27
            y=19-20
            side=1
            [not]
                description=Kaleh
            [/not]
        [/filter]

        [if]
            [variable]
                name=found_door
                numerical_equals=0
            [/variable]

            [then]
                [if]
                    [variable]
                        name=num_keys_found
                        numerical_equals=2
                    [/variable]

                    [then]
                        [message]
                            speaker=unit
                            message= _ "We've reached what looks like the citadel, but it is surrounded by a huge perfectly smooth obsidian wall. I can't find any way to get in."
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "Are you sure? Search carefully. The orc and skeleton must have been guarding some sort of entrance."
                        [/message]

                        [message]
                            speaker=unit
                            message= _ "Wait a minute. There's a tiny outline of a door in the stone. But there's no way to open it. All I see are what look like two tiny keyholes in the stone. Now I wonder where we might find the right keys?"
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "Hey, what about the two keys that we found on the bodies of the undead and orc leaders?"
                        [/message]

                        [endlevel]
                            name=victory
                            bonus=yes
                        [/endlevel]
                    [/then]

                    [else]
                        [message]
                            speaker=unit
                            message= _ "We've reached what looks like the citadel, but it is surrounded by a huge perfectly smooth obsidian wall. I can't find any way to get in."
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "Are you sure? Search carefully. The orc and skeleton must have been guarding some sort of entrance."
                        [/message]

                        [message]
                            speaker=unit
                            message= _ "Wait a minute. There's a tiny outline of a door in the stone. But there's no way to open it. All I see are what look like two tiny keyholes in the stone. Now I wonder where we might find the right keys?"
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "I have an idea. I bet Eloh has given them to those she trusts most. And one orc and one skeleton were guarding the door. The keys must be being held by one of each faction. I bet the leaders would be in charge of such valuable objects."
                        [/message]

                        [set_variable]
                            name=found_door
                            value=1
                        [/set_variable]

                        [objectives]
                            summary= _ "New Objectives:"
                            [objective]
                                description= _ "Defeat enemy leaders, find both keys"
                                condition=win
                            [/objective]
                            [objective]
                                description= _ "Death of Kaleh, Nym, Zhul"
                                condition=lose
                            [/objective]
                        [/objectives]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    # Event 8: alternate dialogue, if unit is Kaleh

    [event]
        name=moveto

        [filter]
            x=25-27
            y=19-20
            description=Kaleh
        [/filter]

        [if]
            [variable]
                name=found_door
                numerical_equals=0
            [/variable]

            [then]
                [if]
                    [variable]
                        name=num_keys_found
                        numerical_equals=2
                    [/variable]

                    [then]
                        [message]
                            speaker=unit
                            message= _ "We've reached what looks like the citadel, but it is surrounded by a huge perfectly smooth obsidian wall. I can't find any entrances or exits."
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "There's got to be something here. The orc and skeleton must have been guarding some sort of entrance."
                        [/message]

                        [message]
                            speaker=unit
                            message= _ "Wait a minute. There's a tiny outline of a door in the stone. But there's no way to open it. All I see are what look like two tiny keyholes in the stone. Now I wonder where we might find the right keys?"
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "Hey, what about the two keys that we found on the bodies of the undead and orc leaders?"
                        [/message]

                        [endlevel]
                            name=victory
                            bonus=yes
                        [/endlevel]
                    [/then]

                    [else]
                        [message]
                            speaker=unit
                            message= _ "We've reached what looks like the citadel, but it is surrounded by a huge perfectly smooth obsidian wall. I can't find any entrances or exits."
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "There's got to be something here. The orc and skeleton must have been guarding some sort of entrance."
                        [/message]

                        [message]
                            speaker=unit
                            message= _ "Wait a minute. There's a tiny outline of a door in the stone. But there's no way to open it. All I see are what look like two tiny keyholes in the stone. Now I wonder where we might find the right keys?"
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "I have an idea. I bet Eloh has given them to those she trusts most. And one orc and one skeleton were guarding the door. The keys must be being held by one of each faction. I bet the leaders would be in charge of such valuable objects."
                        [/message]

                        [set_variable]
                            name=found_door
                            value=1
                        [/set_variable]

                        [objectives]
                            summary= _ "New Objectives:"
                            [objective]
                                description= _ "Defeat enemy leaders, find both keys"
                                condition=win
                            [/objective]
                            [objective]
                                description= _ "Death of Kaleh, Nym, Zhul"
                                condition=lose
                            [/objective]
                        [/objectives]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    # Macro: defeat both leaders, now have to take keys back to citadel door

#define ELOH_MACRO

    [if]
        [variable]
            name=found_door
            numerical_equals=1
        [/variable]

        [then]
            [message]
                description=Kaleh
                image=portraits/kaleh.png
                message= _ "We've found both keys. Now we just have to take them and open the door to the black citadel. I tire of all this bloodshed. Wherever Yechnagoth hides, we will find her and make her pay for all she has done."
            [/message]

            [objectives]
                summary= _ "New Objectives:"
                [objective]
                    description= _ "Any unit must reach the black citadel"
                    condition=win
                [/objective]
                [objective]
                    description= _ "Death of Kaleh, Nym, Zhul"
                    condition=lose
                [/objective]
            [/objectives]
        [/then]
    [/if]

#enddef

    # Event 9: Defeat the undead leader

    [event]
        name=die

        [filter]
            description=Kelur
        [/filter]

        [message]
            description=Kelur
            message= _ "Aaaargh!"
        [/message]

        [kill]
            description=Kelur
            animate=yes
            fire_event=no
        [/kill]

        [if]
            [variable]
                name=found_door
                numerical_equals=1
            [/variable]

            [then]
                [message]
                    speaker=second_unit
                    message= _ "Look, I found a gold key on a chain around his neck. This must be one of the keys needed to enter the black citadel."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=second_unit
                    message= _ "Look, I found a gold key on a chain around his neck. I wonder what this key is for? I bet it will become useful eventually. I'll keep it just in case."
                [/message]
            [/else]
        [/if]

        [set_variable]
            name=num_keys_found
            add=1
        [/set_variable]

        [if]
            [variable]
                name=num_keys_found
                numerical_equals=2
            [/variable]

            [variable]
                name=found_door
                numerical_equals=1
            [/variable]

            [then]
                {ELOH_MACRO}
            [/then]
        [/if]
    [/event]

    # Event 10: Defeat the orc leader

    [event]
        name=die

        [filter]
            description=Graghht
        [/filter]

        [message]
            description=Graghht
            message= _ "Nooooo!!!"
        [/message]

        [kill]
            description=Graghht
            animate=yes
            fire_event=no
        [/kill]

        [if]
            [variable]
                name=found_door
                numerical_equals=1
            [/variable]

            [then]
                [message]
                    speaker=second_unit
                    message= _ "Look, I found an iron key on a chain around his neck. This must be one of the keys needed to enter the black citadel."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=second_unit
                    message= _ "Look, I found an iron key on a chain around his neck. I wonder what this key is for? I bet it will become useful eventually. I'll keep it just in case."
                [/message]
            [/else]
        [/if]

        [set_variable]
            name=num_keys_found
            add=1
        [/set_variable]

        [if]
            [variable]
                name=num_keys_found
                numerical_equals=2
            [/variable]

            [variable]
                name=found_door
                numerical_equals=1
            [/variable]

            [then]
                {ELOH_MACRO}
            [/then]
        [/if]
    [/event]

    # Event 11: An elf goes to open the doors

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            x=25-27
            y=19-21
        [/filter]

        [if]
            [variable]
                name=num_keys_found
                numerical_equals=2
            [/variable]

            [then]
                [endlevel]
                    name=victory
                    bonus=yes
                [/endlevel]
            [/then]
        [/if]
    [/event]

    # Event 12: Player gets close to trapped merman

    [event]
        name=sighted

        [filter]
            description=Trapped Merman
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            description=Trapped Merman
            # FIXME: This wants to be a portrait, not just a unit icon
            image="units/merfolk/triton.png"
            message= _ "Help me..."
        [/message]

        [message]
            speaker=second_unit
            message= _ "A merman! He looks like he's in bad shape."
        [/message]

        [kill]
            description=Trapped Merman
            animate=no
            fire_event=no
        [/kill]
    [/event]

    # Event 13: Player gets close to wrecked ship

    [event]
        name=moveto

        [filter]
            side=1
            [filter_location]
		            radius=5 
		            x,y=13,9
		            [filter_radius]
		                terrain=W*
		            [/filter_radius]
		        [/filter_location]
        [/filter]

        {UNIT_T (Sea Serpent) (Sea Serpent) ( _ "Sea Serpent") 2 13 9}
        # wmllint: recognize Sea Serpent

        [message]
            description=Sea Serpent
            message= _ "Raurrgghhh!!"
        [/message]

        [message]
            speaker=second_unit
            message= _ "A sea serpent! That thing must be 20 cubits long! It must have been living among the wreckage of that ship. I shudder to think what it was feasting on."
        [/message]
    [/event]

    # Event 14: Player rescues trapped merman

    [event]
        name=moveto

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

        [removeitem]
            x,y=10,5
        [/removeitem]

        [unit]
            type=Merman Triton
            description=Grateful Merman
            user_description= _ "Grateful Merman"
            x,y=10,5
            side=1
            upkeep=free
            hitpoints=12
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [message]
            description=Grateful Merman
            message= _ "Thank you. I got captured by the naga and have been trapped here for ages, I don't know how long. So close to the water, but so far. I don't think I could have lasted much longer. It was horrible."
        [/message]

        [message]
            speaker=unit
            message= _ "Well, help us get revenge on the naga. We are here to destroy Yechnagoth."
        [/message]

        [message]
            description=Grateful Merman
            message= _ "Gladly. Just let me recover my strength first."
        [/message]
    [/event]

    # player find gold in wrecked ship

    [event]
        name=moveto

        [filter]
            x,y=13,9
            side=1
        [/filter]

        [sound]
            name=gold.ogg
        [/sound]

        [message]
            speaker=unit
            message= _ "I found a chest in the hold of this wrecked ship. It looks like sunken treasure!"
        [/message]

        [gold]
            amount=150
            side=1
        [/gold]
    [/event]

    # Event 15: time over event

    [event]
        name=time over

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "We've run out of time! The forces that the merfolk helped distract have returned and will surely kill us all."
        [/message]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    # Event 16: VICTORY!

    [event]
        name=victory

        [terrain]
            x,y=26,19
            terrain=Uu
        [/terrain]

        [unit]
            type=Divine Avatar
            gender=female
            description=Eloh
            user_description= _ "Eloh"
            side=5
            x,y=26,19
            ai_special=guardian
        [/unit]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            description=Eloh
            message= _ "So I see that you have finally slain both of my lieutenants. I wondered how long it would take you."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "We have your keys. You cannot hide from us now."
        [/message]

        [message]
            description=Eloh
            message= _ "Did you really think something as simple as a pair of keys was needed to enter and leave my sanctum? The entire thing was just a charade to see how much trouble you would go through on your pathetic little quest."
        [/message]

        [message]
            description=Eloh
            message= _ "Sigh, you elves are so predictable."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Talk all you want, we will have our vengeance!"
        [/message]

        [message]
            description=Eloh
            message= _ "Is that what you want? I suppose I do owe Kaleh a personal audience, after all I have put him through. Well here's your chance. Come to me boy, and prove that you have what it takes. All you others, stay away unless you want a slow and painful death. I will deal with you later."
        [/message]

        [kill]
            description=Eloh
            animate=no
        [/kill]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "I must go and end this. But first I want to thank you all for your faith in me throughout this long journey. If I do not prevail than please flee this place with the merfolk and find somewhere where you can have peace and safety. My last wish is that no matter what happens you all live long and fruitful lives. Don't let our sacrifices be forgotten..."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Kaleh, you can't just go in there alone. She'll kill you!"
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "I must. Too many others have died because of my actions. I couldn't face losing you, Nym. Now it is time for me to finish it, alone."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "May Eloh protect you."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Her will be done. "
        [/message]

        # Kaleh disappears

        [store_unit]
            [filter]
                description=Kaleh
            [/filter]
            kill=yes
            variable=Kaleh_var
        [/store_unit]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Well, now we just have to wait... "
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "You aren't actually going to let him face her alone!?!"
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Yes I am. In the end it is his decision."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "I've saved his sorry ass all this way, I'm not going to let him go and let himself get killed now."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Nymphtessa, my darling, you have always been a rebel. But eventually you must learn to respect your leaders' decisions. Kaleh has made his choice, and if Eloh wills it he will prevail. You see how all our losses weigh upon him. He would not want us to disobey him and sacrifice our lives too."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "I don't care! Do you think I'm going to let him go in there and fight alone? He'll be slaughtered! He needs our help. Without us he never would have even made it out of the desert. The rest of you can just sit on your hands and pray, but I'm going in there!"
        [/message]

        # Nym disappears

        [store_unit]
            [filter]
                description=Nym
            [/filter]
            kill=yes
            variable=Nym_var
        [/store_unit]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Curse that girl! She'll be the death of me. But still she doesn't stand a chance without me. Kaleh is one thing, but Nym needs my protection. All right, I'm going in. The rest of you stand guard, if we don't come out in half a hour then flee the island with the merfolk."
        [/message]

        # Zhul disappears

        [store_unit]
            [filter]
                description=Zhul
            [/filter]
            kill=yes
            variable=Zhul_var
        [/store_unit]

        [if]
            [variable]
                name=ally_race
                equals=Dwarf
            [/variable]

            [then]
                [message]
                    description=$ally_name
                    image=portraits/rogrimir.png
                    message= _ "I've followed that boy this far, I'm not going to just let him march in there without me. Besides, whoever heard of a dwarf being afraid of going underground? I just hope they save some of the fighting for me."
                [/message]
            [/then]

            [else]
                [message]
                    description=$ally_name
                    image=portraits/grog.png
                    message= _ " $ally_name not going to just sit here while Kaleh does all the fighting. Kaleh will need strong fighter like $ally_name. Other elves may be scared, but $ally_name fear no dark place. $ally_name just hope there still something to smash when he gets there."
                [/message]
            [/else]
        [/if]

        [unstore_unit]
            variable=Kaleh_var
        [/unstore_unit]

        [unstore_unit]
            variable=Nym_var
        [/unstore_unit]

        [unstore_unit]
            variable=Zhul_var
        [/unstore_unit]

        {CLEAR_VARIABLE captured_fort}
        {CLEAR_VARIABLE found_door}
        {CLEAR_VARIABLE num_keys_found}
        {CLEAR_VARIABLE encountered_saurians}
        {CLEAR_VARIABLE first_night}

        {CLEAR_VARIABLE Kaleh_var}
        {CLEAR_VARIABLE Nym_var}
        {CLEAR_VARIABLE Zhul_var}

        {CLEAR_VARIABLE temp_x}
        {CLEAR_VARIABLE temp_y}

        {CLEAR_VARIABLE locs}
        {CLEAR_VARIABLE counter}
        {CLEAR_VARIABLE number_vamp_bats}
        {CLEAR_VARIABLE number_blood_bats}
    [/event]

    # I NEED THE CLOCK FUNCTION TO GO FIRST BECAUSE LATER EVENTS CHECK TO SEE
    # WHAT TIME IT IS

    #clock function
    #Step 0: if blackhand sign hasn't appeared, make sure leader has no gold
    #Step 1: if we are going into night or day, flip daytime boolean
    #Step 2: advance clock

    #first day
    #dawn		1
    #morning	2
    #mid-day	3
    #afternoon	4
    #dusk		5
    #shortdark	6

    #second day
    #dawn		-1
    #morning	-2
    #mid-day	-3
    #afternoon	-4
    #dusk		-5
    #longdark 1	-6
    #longdark 2	-7
    #longdark 3	-8
    #longdark 4	-9

    [event]
        name=new turn
        first_time_only=no

        [if]
            [variable]
                name=time_of_day
                numerical_equals=-9
            [/variable]

            [then]
                [set_variable]
                    name=time_of_day
                    value=1
                [/set_variable]
            [/then]

            [else]
                [if]
                    [variable]
                        name=time_of_day
                        numerical_equals=6
                    [/variable]

                    [then]
                        [set_variable]
                            name=time_of_day
                            value=-1
                        [/set_variable]
                    [/then]

                    [else]
                        [if]
                            [variable]
                                name=time_of_day
                                greater_than=0
                            [/variable]

                            [then]
                                [set_variable]
                                    name=time_of_day
                                    add=1
                                [/set_variable]
                            [/then]

                            [else]
                                [set_variable]
                                    name=time_of_day
                                    add=-1
                                [/set_variable]
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/else]
        [/if]
    [/event]

    # create bats at dusk function

    # at first dusk, Kaleh comments strange noises in jungle

    # pick random hex
    # of hex is a jungle, create a bat, increment counter
    # else pick new random hex

    # keep going until counter = number of bats to create

    [event]
        name=new turn
        first_time_only=no

        [if]
            #time of day is 5 or -5

            [variable]
                name=time_of_day
                numerical_equals=5
            [/variable]

            [or]
                [variable]
                    name=time_of_day
                    numerical_equals=-5
                [/variable]
            [/or]

            [then]
                [if]
                    [variable]
                        name=first_night
                        numerical_equals=0
                    [/variable]

                    [then]
                        [set_variable]
                            name=first_night
                            value=1
                        [/set_variable]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "What's that strange screeching sound coming from the jungle?"
                        [/message]
                    [/then]
                [/if]

                # create vampire bats and blood bats based on numbers defined in prestart

                # create vampire bats

                [set_variable]
                    name=counter
                    value=0
                [/set_variable]

                [while]
                    [variable]
                        name=counter
                        less_than=$number_vamp_bats
                    [/variable]

                    [do]
                        [store_locations]
                            terrain=Gs^Ft
                            variable=locs
                        [/store_locations]

                        [set_variable]
                            name=array_length
                            value=$locs.length
                        [/set_variable]

                        # array is indexed to 1 less than it's length
                        [set_variable]
                            name=array_length
                            add=-1
                        [/set_variable]

                        [set_variable]
                            name=random_string
                            format=0..$array_length
                        [/set_variable]

                        [set_variable]
                            name=index
                            random=$random_string
                        [/set_variable]

                        [set_variable]
                            name=temp_x
                            to_variable=locs[$index].x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            to_variable=locs[$index].y
                        [/set_variable]

                        {CLEAR_VARIABLE array_length}
                        {CLEAR_VARIABLE random_string}

                        {FREE_UNIT (Vampire Bat) (Nocturnal Pest) ( _ "Nocturnal Pest") 6 $temp_x $temp_y}

                        [set_variable]
                            name=counter
                            add=1
                        [/set_variable]
                    [/do]
                [/while]

                # create blood bats on medium and hard difficulties

#ifdef EASY
#else

                [set_variable]
                    name=counter
                    value=0
                [/set_variable]

                [while]
                    [variable]
                        name=counter
                        less_than=$number_blood_bats
                    [/variable]

                    [do]
                        [store_locations]
                            terrain=Gs^Ft
                            variable=locs
                        [/store_locations]

                        [set_variable]
                            name=array_length
                            value=$locs.length
                        [/set_variable]

                        # array is indexed to 1 less than it's length
                        [set_variable]
                            name=array_length
                            add=-1
                        [/set_variable]

                        [set_variable]
                            name=random_string
                            format=0..$array_length
                        [/set_variable]

                        [set_variable]
                            name=index
                            random=$random_string
                        [/set_variable]

                        [set_variable]
                            name=temp_x
                            to_variable=locs[$index].x
                        [/set_variable]

                        [set_variable]
                            name=temp_y
                            to_variable=locs[$index].y
                        [/set_variable]

                        {CLEAR_VARIABLE array_length}
                        {CLEAR_VARIABLE random_string}

                        {FREE_UNIT (Blood Bat) (Nocturnal Pest) ( _ "Nocturnal Pest") 6 $temp_x $temp_y}

                        [set_variable]
                            name=counter
                            add=1
                        [/set_variable]
                    [/do]
                [/while]

#endif
            [/then]
        [/if]
    [/event]

    # destroy all bats at morning

    # at first morning, Nym comments on bats fleeing

    [event]
        name=new turn
        first_time_only=no

        [if]
            #time of day is 2 or -2

            [variable]
                name=time_of_day
                numerical_equals=-2
            [/variable]

            [or]
                [variable]
                    name=time_of_day
                    numerical_equals=2
                [/variable]
            [/or]

            [then]
                [kill]
                    side=6
                    animate=no
                    fire_event=no
                [/kill]

                [if]
                    [variable]
                        name=first_night
                        numerical_equals=1
                    [/variable]

                    [variable]
                        name=second_dawn
                        numerical_equals=0
                    [/variable]

                    [then]
                        [set_variable]
                            name=second_dawn
                            value=1
                        [/set_variable]

                        [message]
                            description=Nym
                            image=portraits/nym.png
                            message= _ "That's odd. Why did those bats suddenly fly off?"
                        [/message]

                        [message]
                            description=Zhul
                            image=portraits/zhul.png
                            message= _ "They must be nocturnal."
                        [/message]
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]

    {@campaigns/Under_the_Burning_Suns/utils/kaleh-abilities.cfg}
    {@campaigns/Under_the_Burning_Suns/utils/deaths.cfg}
    {KALEH_DEATH}
    {FRIEND_DEATH}
    {ESANOO_DEATH}
    {LATE_ALLY_DEATH}

    {@campaigns/Under_the_Burning_Suns/utils/global-events.cfg}
[/scenario]
