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

[scenario]
    id="11_Battle_for_Zocthanol_Isle"
    name= _ "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}"

    {STORY_BATTLE_FOR_ZOCTHANOL_ISLAND}

    {SCENARIO_MUSIC "wanderer.ogg"}
    {EXTRA_SCENARIO_MUSIC "vengeful.ogg"}
    {EXTRA_SCENARIO_MUSIC "heroes_rite.ogg"}

    #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

    {TWO_SUNS_DEFAULT_SCHEDULE}

    #Side 1: elves
    [side]
        side=1
        id=Kaleh
        type=Desert Fighter
        canrecruit=yes
        gold=200
        {NO_INCOME}
        controller=human
        shroud=yes
        fog=yes
        team_name=elf_ally
        user_team_name=_"Elf Ally"
    [/side]

    #Side 2: Saurians (blue)
    [side]
        side=2
        type=Saurian Oracle
        id=Boyicht
        name= _ "Boyicht"
        canrecruit=yes
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}

#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]
#ifdef HARD
            recruitment_pattern=scout, healer, scout, archer
#else
            recruitment_pattern=scout, healer, scout
#endif
            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
        id=Kelur
        name= _ "Kelur"
        upkeep=full
        canrecruit=yes
        {GOLD 125 150 150}
        {INCOME 15 17 19}
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}

#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
        id=Graghht
        name= _ "Graghht"
        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
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}

#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, mixed 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
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}
    [/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
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=7
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=eloh_ally
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}

#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
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}

#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
        user_team_name=_"Elf Ally"
    [/side]

    # 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/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~RC(magenta>red)" 10 5}
        {PLACE_IMAGE items/cage.png 10 5}

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

        # recall heroes

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

        #recall merfolk

        [recall]
            id=Esanoo
            x,y=41,43
        [/recall]
        [recall]
            id=Urruga
            x,y=41,42
        [/recall]
        [recall]
            id=Nuvassa
            x,y=42,41
        [/recall]
        [recall]
            id=Yantili
            x,y=43,42
        [/recall]
        [recall]
            id=Il-tian
            x,y=43,43
        [/recall]
        [recall]
            id=We-jial
            x,y=42,43
        [/recall]

        #initialize starting variables

        {VARIABLE encountered_saurians no}
        {VARIABLE captured_fort no}
        {VARIABLE found_door no}
        {VARIABLE num_keys_found 0}
        {VARIABLE time_of_day 1}
        # flag to store if first night has happened or not, starts at false
        {VARIABLE first_night no}
        # flag to store if second_dawn has happened or not, starts at false
        {VARIABLE second_dawn no}

        # number of bats to appear each night

#ifdef EASY
        {VARIABLE number_vamp_bats 5}
        {VARIABLE number_blood_bats 0}
#endif

#ifdef NORMAL
        {VARIABLE number_vamp_bats 3}
        {VARIABLE number_blood_bats 3}
#endif

#ifdef HARD
        {VARIABLE number_vamp_bats 3}
        {VARIABLE number_blood_bats 4}
#endif

        {VARIABLE immortal_hero 0}

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

            note={NO_GOLD_CARRYOVER_NOTE}
        [/objectives]

        #create starting elves

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

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

        #create starting undead and orc guards

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

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

    # Event 1: Starting dialogue

    [event]
        name=start

        [message]
            speaker=Nym
            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]
            speaker=Kaleh
            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]
            speaker=Kaleh
            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]
                side=1
                race=merman
                {EVERYWHERE}
            [/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

        #{NAMED_GENERIC_UNIT 1 (Merman Triton)    (test) ( _ "test") 3 15}
        #{NAMED_GENERIC_UNIT 1 (Merman Entangler) (test) ( _ "test") 3 15}
        #{NAMED_GENERIC_UNIT 1 (Mermaid Siren)    (test) ( _ "test") 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
                boolean_equals=no
            [/variable]

            [then]
                [message]
                    speaker=Zhul
                    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]
                    speaker=Kaleh
                    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
                boolean_equals=no
            [/variable]

            [then]
                [message]
                    speaker=Nym
                    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]
                    speaker=Kaleh
                    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
                boolean_equals=no
            [/variable]

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

    # Event 4: Encountering the Saurians

    [event]
        name=sighted

        [filter]
            id=Boyicht
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

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

        [message]
            speaker=Nym
            message= _ "Faugh! 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]
            speaker=Boyicht
            message= _ "No, you are not The One. You no command Boyicht. Attack!"
        [/message]

        # Saurians ambush

#ifdef EASY
        {NAMED_GENERIC_UNIT 2 (Saurian Skirmisher) 17 39 () ( _ "Fanatical Saurian")}
        {NAMED_GENERIC_UNIT 2 (Saurian Skirmisher) 16 43 () ( _ "Fanatical Saurian")}
        {NAMED_GENERIC_UNIT 2 (Saurian Augur) 20 42 () ( _ "Fanatical Saurian")}
#endif

#ifdef NORMAL
        {NAMED_GENERIC_UNIT 2 (Saurian Ambusher) 17 39 () ( _ "Fanatical Saurian")}
        {NAMED_GENERIC_UNIT 2 (Saurian Skirmisher) 16 43 () ( _ "Fanatical Saurian")}
        {NAMED_GENERIC_UNIT 2 (Saurian Augur) 20 42 () ( _ "Fanatical Saurian")}
#endif

#ifdef HARD
        {NAMED_GENERIC_UNIT 2 (Saurian Ambusher) 17 39 () ( _ "Fanatical Saurian")}
        {NAMED_GENERIC_UNIT 2 (Saurian Skirmisher) 16 43 () ( _ "Fanatical Saurian")}
        {NAMED_GENERIC_UNIT 2 (Saurian Oracle) 20 42 () ( _ "Fanatical Saurian")}
#endif

        {VARIABLE encountered_saurians 1}

        [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=last breath

        [filter]
            id=Boyicht
        [/filter]

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

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

        [message]
            speaker=second_unit
            # wmllint: local spelling creeped
            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
            id=Naga Leader
            name= _ "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
            id=Naga Leader
            name= _ "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]
            id=Kaleh
            x,y=13,41
        [/filter]

        [message]
            speaker=Kaleh
            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]

        {FOREACH merfolk_units i}
            {VARIABLE merfolk_units[$i].x 6}
            {VARIABLE merfolk_units[$i].y 42}

            [unstore_unit]
                variable=merfolk_units[$i]
                find_vacant=yes
            [/unstore_unit]
        {NEXT i}

        {CLEAR_VARIABLE merfolk_units}

        [redraw]
            side=1
        [/redraw]

        [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]
            speaker=Nym
            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
            side=1
            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/galleon.png~RC(magenta>red)" 10 38}

        [move_unit_fake]
            type=Galleon
            side=1
            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/galleon.png~RC(magenta>red)" 9 39}

        [move_unit_fake]
            type=Galleon
            side=1
            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/galleon.png~RC(magenta>red)" 9 40}

        [message]
            speaker=Zhul
            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]
            speaker=Kaleh
            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]
            speaker=Kaleh
            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]

        {VARIABLE captured_fort yes}

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

            note={NO_GOLD_CARRYOVER_NOTE}
        [/objectives]

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

    # Event 6: Encounter the undead leader

    [event]
        name=sighted

        [filter]
            id=Kelur
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

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

    # Event 7: Encounter the orc leader

    [event]
        name=sighted

        [filter]
            id=Graghht
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=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]
                id=Kaleh
            [/not]
        [/filter]

        [if]
            [variable]
                name=found_door
                boolean_equals=no
            [/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]
                            speaker=Kaleh
                            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]
                            speaker=Kaleh
                            message= _ "Hey, what about the two keys that we found on the bodies of the undead and orc leaders?"
                        [/message]

                        [endlevel]
                            result=victory
                            bonus=no
                            {NEW_GOLD_CARRYOVER 0}
                        [/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]
                            speaker=Kaleh
                            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]
                            speaker=Kaleh
                            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]

                        {VARIABLE found_door yes}

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

                            note={NO_GOLD_CARRYOVER_NOTE}
                        [/objectives]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    # Event 8: alternate dialogue, if unit is Kaleh

    [event]
        name=moveto

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

        [if]
            [variable]
                name=found_door
                boolean_equals=no
            [/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]
                            speaker=Kaleh
                            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]
                            speaker=Kaleh
                            message= _ "Hey, what about the two keys that we found on the bodies of the undead and orc leaders?"
                        [/message]

                        [endlevel]
                            result=victory
                            bonus=no
                            {NEW_GOLD_CARRYOVER 0}
                        [/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]
                            speaker=Kaleh
                            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]
                            speaker=Kaleh
                            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]

                        {VARIABLE found_door yes}

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

                            note={NO_GOLD_CARRYOVER_NOTE}
                        [/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
            boolean_equals=yes
        [/variable]

        [then]
            [message]
                speaker=Kaleh
                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]

                note={NO_GOLD_CARRYOVER_NOTE}
            [/objectives]
        [/then]
    [/if]

#enddef

    # Event 9: Defeat the undead leader

    [event]
        name=last breath

        [filter]
            id=Kelur
        [/filter]

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

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

        [if]
            [variable]
                name=found_door
                boolean_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]

        {VARIABLE_OP num_keys_found add 1}

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

            [variable]
                name=found_door
                boolean_equals=yes
            [/variable]

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

    # Event 10: Defeat the orc leader

    [event]
        name=last breath

        [filter]
            id=Graghht
        [/filter]

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

        [kill]
            id=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]

        {VARIABLE_OP num_keys_found add 1}

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

            [variable]
                name=found_door
                boolean_equals=yes
            [/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]
                    result=victory
                    bonus=no
                    {NEW_GOLD_CARRYOVER 0}
                [/endlevel]
            [/then]
        [/if]
    [/event]

    # Event 12: Player gets close to trapped merman

    [event]
        name=sighted

        [filter]
            id=Trapped Merman
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=Trapped Merman
            message= _ "Help me..."
        [/message]

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

        [kill]
            id=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]

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

        [message]
            speaker=Sea Serpent
            message= _ "Raurrgghhh!!"   # wmllint: no spellcheck
        [/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
            id=Grateful Merman
            name= _ "Grateful Merman"
            x,y=10,5
            side=1
            upkeep=free
            hitpoints=12
            unrenamable=yes
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [message]
            speaker=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]
            speaker=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]
            speaker=Kaleh
            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
            id=Eloh
            name= _ "Eloh"
            side=5
            x,y=26,19
            ai_special=guardian
        [/unit]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

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

        [message]
            speaker=Nym
            message= _ "We have your keys. You cannot hide from us now."
        [/message]

        [message]
            speaker=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]
            speaker=Eloh
            message= _ "Sigh, you elves are so predictable."
        [/message]

        [message]
            speaker=Zhul
            message= _ "Talk all you want, we will have our vengeance!"
        [/message]

        [message]
            speaker=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]
            id=Eloh
            animate=no
        [/kill]

        [redraw]
        [/redraw]

        [delay]
            time=300
        [/delay]

        [message]
            speaker=Kaleh
            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]
            speaker=Nym
            message= _ "Kaleh, you can't just go in there alone. She'll kill you!"
        [/message]

        [message]
            speaker=Kaleh
            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]
            speaker=Zhul
            message= _ "May Eloh protect you."
        [/message]

        [message]
            speaker=Kaleh
            message= _ "Her will be done. "
        [/message]

        # Kaleh disappears

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

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Zhul
            message= _ "Well, now we just have to wait... "
        [/message]

        [message]
            speaker=Nym
            message= _ "You aren't actually going to let him face her alone!?!"
        [/message]

        [message]
            speaker=Zhul
            message= _ "Yes I am. In the end it is his decision."
        [/message]

        [message]
            speaker=Nym
            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]
            speaker=Zhul
            # wmllint: local spelling Nymphtessa
            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]
            speaker=Nym
            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]
                id=Nym
            [/filter]
            kill=yes
            variable=Nym_var
        [/store_unit]

        [redraw]
        [/redraw]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Zhul
            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]
                id=Zhul
            [/filter]
            kill=yes
            variable=Zhul_var
        [/store_unit]

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

            [then]
                [message]
                    speaker=$ally_name
                    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]
                    speaker=$ally_name
                    message= _ "$intl_ally_name not going to just sit here while Kaleh does all the fighting. Kaleh will need strong fighter like $intl_ally_name|. Other elves may be scared, but $intl_ally_name fear no dark place. $intl_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]
                            speaker=Kaleh
                            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}

                        {NAMED_UNIT 6 (Vampire Bat) $temp_x $temp_y () ( _ "Nocturnal Pest") (upkeep=free)}

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

                        {NAMED_UNIT 6 (Blood Bat) $temp_x $temp_y () ( _ "Nocturnal Pest") (upkeep=free)}

                        [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]
                            speaker=Nym
                            message= _ "That's odd. Why did those bats suddenly fly off?"
                        [/message]

                        [message]
                            speaker=Zhul
                            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}
[/scenario]
