#textdomain wesnoth-utbs

[scenario]
    id=11_Battle_for_Zocthanol_Isle
    name= _ "The Battle for Zocthanol Isle"

    next_scenario=12_The_Final_Confrontation

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

    victory_when_enemies_defeated=no
    {TURNS 44 40 36}

    {TWO_SUNS_DEFAULT_SCHEDULE}

    # citadel terrain graphics
    [terrain_graphics]
        map="
.,  *,  .
, *,  *,
*,  1,  *
, *,  *,
*,  *,  *
, *,  *,
*,  *,  *
, *,  *,
.,  *,  ."
        [tile]
            pos=1
        [/tile]
        x,y=24,16
        [image]
            name=citadel_zocthanol_clouds.png
            layer=5
            base=108,290
            center=144,162
        [/image]
        [image]
            name=citadel_zocthanol.png
            layer=0
            base=108,290
            center=144,162
        [/image]
        [image]
            name=citadel_zocthanol_sub.png
            layer=-10
            base=108,290
            center=144,162
        [/image]
    [/terrain_graphics]

    #Side 1: elves
    [side]
        side=1
        id=Kaleh
        type=Quenoth Youth
        canrecruit=yes
        gold=200
        {NO_INCOME}
        controller=human
        shroud=yes
        fog=yes
        team_name=elf_ally
        user_team_name= _ "team_name^Quenoth Elves"
        {FLAG_VARIANT long}
    [/side]

    #Side 2: Saurians (blue)
    [side]
        side=2
        type=Saurian Oracle
        id=Boyicht
        name= _ "Boyicht"
        canrecruit=yes
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
        # gold and income will be set later - this ensures saurians have no gold until then
        gold=0
        income=-50
        controller=ai
        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

            passive_leader=yes
        [/ai]
    [/side]

    #Side 3: Undead (green)
    [side]
        side=3
        type=Draug
        id=Kelur
        name= _ "Kelur"
        canrecruit=yes
        {GOLD 125 150 150}
        {INCOME 15 17 19}
        controller=ai
        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,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
        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
            aggression=0.8
            caution=0.1
        [/ai]
    [/side]

    #Side 5: Eloh
    [side]
        side=5
        no_leader=yes
        gold=0
        controller=null
        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
        controller=ai
        team_name=eloh_ally
        user_team_name=_"Eloh Cultists"
        {FLAG_VARIANT undead}
    [/side]

    [side]
        side=7
        no_leader=yes
        gold=0
        controller=ai
        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

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

    #Side 8: Eastern Naga
    [side]
        side=8
        no_leader=yes
        gold=0
        controller=ai
        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

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

    # Prestart functions:
    # increase cost of all units by 2
    # place item images on map
    # recall main heroes
    # initialize starting variables
    # remove shroud surrounding starting position
    # set starting scenario objectives

    [event]
        name=prestart

        {INCREASE_RECRUIT_COSTS 2}

        # add items to map

        # 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
            random_traits=no
            max_moves=1
            ai_special=guardian
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_QUICK}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        # recall heroes

        [recall]
            id=Nym
        [/recall]

        [recall]
            id=Zhul
        [/recall]

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

        # wmllint: recognize Grog
        # wmllint: recognize Nog
        # wmllint: recognize Rogrimir
        # wmllint: recognize Jarl

        #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 found_door no}

        # set starting scenario objectives

        [objectives]
            [objective]
                description= _ "Kaleh must capture a keep"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL keep_reached boolean_equals no}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Reach the black citadel in the center of the island"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL keep_reached boolean_equals yes}
                    {VARIABLE_CONDITIONAL found_door   boolean_equals no}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Defeat enemy leaders, find both keys"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL found_door boolean_equals yes}
                    [have_unit]
                        canrecruit=yes
                        side=3,4
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Any unit must reach the black citadel"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL found_door boolean_equals yes}
                    [not]
                        [have_unit]
                            canrecruit=yes
                            side=3,4
                        [/have_unit]
                    [/not]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Kaleh"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Nym"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Zhul"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                carryover_percentage=0
            [/gold_carryover]
        [/objectives]

        #create starting elves

        [unit]
            type=Quenoth Fighter
            name= _ "Eagath"
            x=37
            y=42
            side=1
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Quenoth Scout
            name= _ "Alusan"
            x=35
            y=43
            side=1
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        #create starting undead and orc guards

        [unit]
            type=Revenant
            side=3
            x,y=25,20
            ai_special=guardian
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
            {IS_LOYAL}
        [/unit]

        [unit]
            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]
    [/event]

    # Event 2: Jungle Warning

    # keep player from entering jungle too early

    [event]
        name=moveto
        id=jungle_warning

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

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

    # Event 3: Silence and Suspense

    [event]
        name=moveto

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

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

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

        [modify_side]
            side=2
            {INCOME 3 4 5}
            {GOLD 20 30 40}
        [/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
            name= _ "Naga Leader"
            canrecruit=yes
            side=7
            x,y=3,23
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [modify_side]
            side=7
            {INCOME 7 9 11}
            {GOLD 75 95 115}
        [/modify_side]

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

        [modify_side]
            side=8
            {INCOME 9 11 13}
            {GOLD 75 95 115}
        [/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]
            array=merfolk_units
            [do]
                [unstore_unit]
                    variable=this_item
                    find_vacant=yes
                    x,y=6,42
                [/unstore_unit]
            [/do]
        [/foreach]

        {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=0-52
            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

        [sound]
            name=ambient/ship.ogg
        [/sound]

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

        [remove_event]
            id=jungle_warning
        [/remove_event]

        {VARIABLE keep_reached yes}

        [show_objectives]
        [/show_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

    [event]
        name=moveto

        [filter]
            x=25-27
            y=19-20
            side=1
            [not]
                type=Dust Devil
            [/not]
        [/filter]

        [remove_shroud]
            [filter_side]
                side=1
            [/filter_side]
            x,y=24-28,16-20
        [/remove_shroud]
        [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]

        [if]
            [variable]
                name=unit.id
                equals=Kaleh
            [/variable]
            [then]
                [message]
                    speaker=Kaleh
                    message= _ "There’s got to be something here. The orc and skeleton must have been guarding some sort of entrance."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Kaleh
                    message= _ "Are you sure? Search carefully. The orc and skeleton must have been guarding some sort of entrance."
                [/message]
            [/else]
        [/if]

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

        [if]
            [have_unit]
                canrecruit=yes
                side=3,4
                count=0
            [/have_unit]

            [then]
                [message]
                    speaker=Kaleh
                    message= _ "Hey, what about the two keys that we found on the bodies of the undead and orc leaders?"
                [/message]
            [/then]

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

                [show_objectives]
                [/show_objectives]
            [/else]
        [/if]
    [/event]

    # Defeat both leaders, now have to take keys back to citadel door
    [event]
        name=found_both_keys_and_door

        [filter_condition]
            [have_unit]
                canrecruit=yes
                side=3,4
                count=0
            [/have_unit]

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

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

        [show_objectives]
        [/show_objectives]
        [remove_shroud]
            [filter_side]
                side=1
            [/filter_side]
            x,y=24-28,16-20
        [/remove_shroud]
    [/event]

    # 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=yes
            [/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]

        [fire_event]
            name=found_both_keys_and_door
        [/fire_event]
    [/event]

    # Event 10: Defeat the orc leader

    [event]
        name=last breath

        [filter]
            id=Graghht
        [/filter]

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

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

        [if]
            [variable]
                name=found_door
                boolean_equals=yes
            [/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]

        [fire_event]
            name=found_both_keys_and_door
        [/fire_event]
    [/event]

    # Event 11: An elf goes to open the doors

    [event]
        name=moveto

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

        [filter_condition]
            [have_unit]
                canrecruit=yes
                side=3,4
                count=0
            [/have_unit]
        [/filter_condition]

        [endlevel]
            result=victory
            bonus=no
            {NEW_GOLD_CARRYOVER 0}
        [/endlevel]
    [/event]

    # Event 12: Player gets close to trapped merman

    [event]
        name=sighted

        [filter]
            id=Trapped Merman
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

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

        [message]
            speaker=$speaking_unit.id
            message= _ "A merman! He looks like he’s in bad shape."
        [/message]
        {CLEAR_VARIABLE speaking_unit}

        [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
            [not]
                type=Dust Devil
            [/not]
            [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")}

        [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
            [not]
                type=Dust Devil
            [/not]
        [/filter]

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

        [unit]
            type=Merman Triton
            id=Grateful Merman
            name= _ "Grateful Merman"
            x,y=10,5
            side=1
            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
            [not]
                type=Dust Devil
            [/not]
        [/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
            random_traits=no
        [/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 then 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!"
            image=portraits/nym_moody.png
        [/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

        [hide_unit]
            id=Kaleh
        [/hide_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?!"
            image=portraits/nym_moody.png
        [/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!"
            image=portraits/nym_moody.png
        [/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!"
            image=portraits/nym_moody.png
        [/message]

        # Nym disappears

        [hide_unit]
            id=Nym
        [/hide_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

        [hide_unit]
            id=Zhul
        [/hide_unit]

        {MESSAGE_DEPEND_ON_ALLY
        (
            [message]
                speaker=Grog
                message= _ "Grog not going to just sit here while Kaleh does all the fighting. Kaleh will need strong fighter like Grog. Other elves may be scared, but Grog fear no dark place. Grog just hope there still something to smash when he gets there."
            [/message]
        )
        (
            [message]
                speaker=Nog
                message= _ "Nog not going to just sit here while Kaleh does all the fighting. Kaleh will need strong fighter like Nog. Other elves may be scared, but Nog fear no dark place. Nog just hope there still something to smash when he gets there."
            [/message]
        )
        (
            [message]
                speaker=Rogrimir
                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]
        )
        (
            [message]
                speaker=Jarl
                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]
        )}

        {CLEAR_VARIABLE found_door}
        {CLEAR_VARIABLE keep_reached}
    [/event]

    # create bats at dusk function

    # at first dusk, Kaleh comments strange noises in jungle
    [event]
        name=bat_noise_reaction
        [message]
            speaker=Kaleh
            message= _ "What’s that strange screeching sound coming from the jungle?"
        [/message]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_location]
                time_of_day_id=dusk1,dusk2
            [/have_location]
        [/filter_condition]

        [fire_event]
            name=bat_noise_reaction
        [/fire_event]

        # create vampire bats and blood bats
# wmlindent: start ignoring
        {SCATTER_UNITS {ON_DIFFICULTY 5 3 3} (Vampire Bat) 2 (terrain=Gs^Ftr) (
            side=6
            name= _ "Nocturnal Pest"
            upkeep=free)}

        # create blood bats on medium and hard difficulties
#ifndef EASY
        {SCATTER_UNITS {ON_DIFFICULTY 0 3 4} (Blood Bat) 2 (terrain=Gs^Ftr) (
            side=6
            name= _ "Nocturnal Pest"
            upkeep=free)}
#endif
# wmlindent: stop ignoring
    [/event]

    # destroy all bats at morning

    # at first morning, Nym comments on bats fleeing
    [event]
        name=bat_leave_reaction
        [message]
            speaker=Nym
            message= _ "That’s odd. Why did those bats suddenly fly off?"
        [/message]

        [message]
            speaker=Zhul
            message= _ "They must be nocturnal."
        [/message]
    [/event]

    [event]
        name=new turn
        first_time_only=no

        [filter_condition]
            [have_location]
                time_of_day_id=dawn1,dawn2
            [/have_location]
            [have_unit]
                side=6
            [/have_unit]
        [/filter_condition]

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

        [fire_event]
            name=bat_leave_reaction
        [/fire_event]
    [/event]

    {UTBS_INCLUDE utils/deaths.cfg}
[/scenario]
