#textdomain wesnoth-utbs
# Level 9: Blood is Thicker than Water...

[scenario]

    id="9_Blood_is_Thicker_Than_Water"
    name= _ "Blood is Thicker than Water"
    label= _ "Blood is Thicker than Water"

    next_scenario=10_Speaking_with_the_Fishes

    map_data="{campaigns/Under_the_Burning_Suns/maps/09_Blood_is_Thicker_Than_Water.map}"

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

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

    # max turns in scenario varies depending on difficulty
#ifdef EASY
    turns="58"
#endif
#ifdef NORMAL
    turns="54"
#endif
#ifdef HARD
    turns="50"
#endif

    victory_when_enemies_defeated=no

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

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

    # Side 2: Darius, leader of Human forces (blue)
    [side]
        side=2
        type=Human Commander
        description=Darius
        user_description= _ "Darius"
        upkeep=full
        canrecruit=yes
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]
        {GOLD 100 125 150}
        {INCOME 7 9 11}
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally

#ifdef EASY
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Bowman, Longbowman, Heavy Infantryman
#endif

#ifdef NORMAL
        recruit=Pikeman, Swordsman, Javelineer, Dragoon, Bowman, Longbowman, Heavy Infantryman, Shock Trooper
#endif

#ifdef HARD
        recruit=Pikeman, Swordsman, Javelineer, Dragoon, Longbowman, Shock Trooper
#endif

        [ai]
#ifdef EASY
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef NORMAL
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef HARD
            recruitment_pattern=scout,fighter,archer,mixed fighter
#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 traitorous elves (green)
    [side]
        side=3
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally

#ifdef EASY
        recruit=Desert Fighter, Desert Archer, Desert Hunter, Desert Ranger, Desert Marksman, Desert Hero, Desert Captain, Desert Sentinel, Desert Horseman
#endif

#ifdef NORMAL
        recruit=Desert Fighter, Desert Archer, Desert Hunter, Desert Ranger, Desert Marksman, Desert Hero, Desert Captain, Desert Sentinel, Desert Horseman
#endif

#ifdef HARD
        recruit=Desert Fighter, Desert Archer, Desert Hunter, Desert Ranger, Desert Marksman, Desert Hero, Desert Captain, Desert Sentinel, Desert Horseman
#endif

        [ai]
            # 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=fighter,archer,fighter,mixed fighter,scout

            aggression=0.75
            caution=0.25

            passive_leader=yes
        [/ai]
    [/side]

    # Side=4 Iron Council (yellow)

    [side]
        side=4
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally

#ifdef EASY
        recruit=Pikeman, Swordsman, Javelineer, Longbowman, Heavy Infantryman, Necromancer, Skeleton, Skeleton Archer, Bone Shooter
#endif

#ifdef NORMAL
        recruit=Pikeman, Swordsman, Javelineer, Dragoon, Longbowman, Shock Trooper, Necromancer, Revenant, Bone Shooter
#endif

#ifdef HARD
        recruit=Pikeman, Swordsman, Javelineer, Dragoon, Longbowman, Shock Trooper, Necromancer, Revenant, Bone Shooter
#endif

        [ai]
#ifdef EASY
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef NORMAL
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef HARD
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

            # 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

            passive_leader=yes
        [/ai]
    [/side]

    # Side=5 Zelgant Human Lieutenant
    [side]
        side=5
        type=Shock Trooper
        description=Zelgant
        user_description= _ "Zelgant"
        upkeep=free
        canrecruit=yes
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_LOYAL}
        [/modifications]
        {GOLD 75 100 125}
        {INCOME 5 6 7}
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally

#ifdef EASY
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Bowman, Longbowman, Heavy Infantryman
#endif

#ifdef NORMAL
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Dragoon, Bowman, Longbowman, Shock Trooper
#endif

#ifdef HARD
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Dragoon, Bowman, Longbowman, Shock Trooper
#endif

        [ai]
#ifdef EASY
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef NORMAL
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef HARD
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

            aggression=0.6
            caution=0.25

            # 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=6 Alastra Human Lieutenant
    [side]
        side=6
        type=Javelineer
        description=Alastra
        user_description= _ "Alastra"
        upkeep=full
        canrecruit=yes
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_INTELLIGENT}
        [/modifications]
        {GOLD 75 100 125}
        {INCOME 5 6 7}
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally

#ifdef EASY
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Bowman, Longbowman, Heavy Infantryman
#endif

#ifdef NORMAL
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Dragoon, Bowman, Longbowman, Shock Trooper
#endif

#ifdef HARD
        recruit=Spearman, Pikeman, Swordsman, Javelineer, Cavalryman, Dragoon, Bowman, Longbowman, Shock Trooper
#endif

        [ai]
#ifdef EASY
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef NORMAL
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

#ifdef HARD
            recruitment_pattern=scout,fighter,archer,mixed fighter
#endif

            aggression=0.6
            caution=0.25

            # 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=7 Crab Man's side
    [side]
        side=7
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
    [/side]

    # Side=8 Eloh's side
    [side]
        side=8
        no_leader=yes
        gold=0
        income=0
        controller=ai
        shroud=no
        fog=no
        team_name=human_ally
    [/side]

    [story]
        [part]
            story= _ "Chapter 9: Nym and Esanoo led us north, across the sands and through the dunes, towards the human encampment where the merfolk were being held. I asked Nym where Esanoo had come from, but she wouldn't answer, she just said that I had to see for myself."
        [/part]

        [part]
            story= _ "Just then we crested over the last dune and I indeed saw what she meant. Sparkling blue covered the entire horizon. I fell to my knees in awe, I had never seen so much water in one place. I cannot write down in words the shock and amazement I felt. To have grown up in a land where water was as precious as gold, and then see miles and miles of it. It was only then that I understood where the merfolk truly came from. I'd been to some strange places, high up in the mountains, deep down under thousands of tons of rock, but this world of water was the most alien of them all."
        [/part]

        [part]
            story= _ "Which brings me to the other alien concept I was trying to figure out: our goddess Eloh. What was her plan? Why did she want me to surrender to the humans? Do the humans worship her as well? The humans seem so brutish and vile, that I can't imagine them worshipping the same god. I thought Eloh was just our god, I don't remember Zhul mentioning any other races worshipping her after the Great Fall, though perhaps things have changed. Her commands don't make any sense; she doesn't seem at all like the goddess Zhul told me about. And what was Esanoo talking about? How did his master know about 'Yechnagoth' and 'Yanqui'? If Eloh won't help me, then I really need some answers. I pray to whatever gods may be left that I'm not leading my people into a trap..."
        [/part]
    [/story]

    {@campaigns/Under_the_Burning_Suns/utils/dialog-macros.cfg}

    # Prestart functions:
    # increase cost of all units by 1
    # 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

        #{UNIT_ (Desert Fighter) (Test) ( _ "Test") 1 16 13}
        #{UNIT_ (Desert Fighter) (Test) ( _ "Test") 1 10 16}

        # units to free merfolk instantly
        #{UNIT_ (Desert Marshal) (Lycia) ( _ "Lycia") 1 27 18}
        #{UNIT_ (Desert Druid) (Shea) ( _ "Shea") 1 32 25}
        #{UNIT_ (Desert Avenger) (Pythos) ( _ "Pythos") 1 18 31}
        #{UNIT_ (Desert Marksman) (Larea) ( _ "Larea") 1 26 36}
        #{UNIT_ (Desert Horseman) (Nonthar) ( _ "Nonthar") 1 33 32}

        # increase cost of all units by 1

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

            [then]
                #go from 7 to 8

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

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

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

                    [then]
                        #go from 6 to 7

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

                        [allow_recruit]
                            type=Desert Fighter7, Desert Archer7, Desert Hunter7, Desert Shaman7, Desert Scout7
                            side=1
                        [/allow_recruit]
                    [/then]
                [/if]

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

                    [then]
                        #go from 8 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]
            [/else]
        [/if]

        # add items to map

        # merfolk trapped in cages
        {PLACE_IMAGE units/merfolk/warrior.png 25 36}
        {PLACE_IMAGE items/cage.png 25 36}

        {PLACE_IMAGE units/merfolk/warrior.png 34 31}
        {PLACE_IMAGE items/cage.png 34 31}

        {PLACE_IMAGE units/merfolk/spearman.png 18 32}
        {PLACE_IMAGE items/cage.png 18 32}

        {PLACE_IMAGE units/merfolk/priestess.png 31 25}
        {PLACE_IMAGE items/cage.png 31 25}

        {PLACE_IMAGE units/merfolk/enchantress.png 27 19}
        {PLACE_IMAGE items/cage.png 27 19}

        # human ships
        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>purple)" 12 10}

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>purple)" 9 12}

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>purple)" 15 14}

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>purple)" 10 15}

        # recall heroes

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

        #initialize starting variables

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

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

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

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

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

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

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

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

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

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

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

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

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

        #remove shroud surrounding starting position
        [remove_shroud]
            x=37-55
            y=41-51
            side=1
        [/remove_shroud]

        # set starting scenario objectives

        [objectives]
            summary= _ "Starting Objectives:"
            [objective]
                description= _ "Rescue at least two merfolk by turn 16"
                condition=win
            [/objective]
            [objective]
                description= _ "Three merfolk must survive"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kaleh, Nym, Zhul"
                condition=lose
            [/objective]
        [/objectives]

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

        [terrain]
            x,y=45,46
            terrain=Hd
        [/terrain]

        #create starting elves
        [unit]
            type=Desert Fighter
            description=Ulothanir
            user_description= _ "Ulothanir"
            upkeep=full
            x=47
            y=48
            side=1
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            type=Desert Archer
            description=Elonea
            user_description= _ "Elonea"
            upkeep=full
            x=44
            y=48
            side=1
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        # capture elves' starting villages
        [capture_village]
            x=42-49
            y=45-47
            side=1
        [/capture_village]
    [/event]

    # Event 1: Starting dialogue & humans jump out of forest and attack Esanoo

    [event]
        name=start

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Now that we're down off the hills, you can't even see all that water, it's hidden by the trees. I never thought I would see so many trees in one place."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "Compared to the desert it seems almost like a paradise. All this growth and vegetation, I can feel it pulsing with life."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "And yet these trees seem different, the forest seems darker, somehow. I prefer to stay out in the open where I can see my enemies coming."
        [/message]

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

            [then]
                [message]
                    description=$ally_name
                    image=portraits/rogrimir.png
                    message= _ "It looks nice and dark under the trees, less exposed to that blazing sun. I'm exhausted after walking across all that harsh sand."
                [/message]
            [/then]

            [else]
                [message]
                    description=$ally_name
                    image=portraits/grog.png
                    message= _ "Trees look big and strong, like trolls. Dark, too. $ally_name tired of walking under hot sun."
                [/message]
            [/else]
        [/if]

        [message]
            description=Esanoo
            message= _ "This is where the human encampments lie, to the northwest. They have settled a chain of islands along the coast of the water. If you break through these trees you will soon see them. I think that's where they are holding the rest of my group. "
        [/message]

        [message]
            description=Esanoo
            message= _ "My master wanted to make sure that if one of us was captured, we couldn't betray his location. So she didn't tell us where she was, but she taught us a simple spell to divine her hiding place. But it requires three merfolk to cast. So in order to find her, we must rescue at least two of my people. Though I hope we can save all of them."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "And you said that there are only five others in your group left?"
        [/message]

        [message]
            description=Esanoo
            message= _ "We originally numbered much more, but we were ambushed by a band of naga on the way here. Half of our force held off the naga while the rest of us fled. By the time we got to these shores, only six of us were left. But for the grace of the Sea God I managed to hide when the rest of my group was ambushed and captured. I doubt that they have been broken yet, but I do not know how long they can last. Remember, without three of us, you will not be able to find my master."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Wait, did you hear that?"
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Someone's coming. Quick, hide!"
        [/message]

        [message]
            description=Esanoo
            message= _ "What? Huh?"
        [/message]

        [scroll_to]
            x=46
            y=39
        [/scroll_to]

        {RANDOM_TRAIT_UNIT 2 "Spearman"   45 42   "Human Scout" ( _ "Human Scout") ()}
        {RANDOM_TRAIT_UNIT 2 "Javelineer" 47 42   "Human Scout" ( _ "Human Scout") ()}

        [redraw]
        [/redraw]

        [message]
            x,y=45,42
            message= _ "Hey, what do we have here?"
        [/message]

        [message]
            description=Esanoo
            message= _ "Uh....Uh..."
        [/message]

        [message]
            x,y=47,42
            message= _ "It's another one of those fish creatures. It must have come back to try to rescue its friends. "
        [/message]

        [message]
            x,y=45,42
            message= _ "Ha, stupid creature. But we're in luck, the council was looking for the last of these spies."
        [/message]

        [message]
            x,y=47,42
            message= _ "We'd better get him back to the base. They're going to sacrifice them all in some big holy ceremony at dawn just two days from now."
        [/message]

        [message]
            x,y=45,42
            message= _ "Yeah, we'll be heroes!"
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Not if we gut you first. Attack!"
        [/message]

        [message]
            x,y=45,42
            message= _ "The Dark Lady protect us, they're elves!"
        [/message]

        [message]
            x,y=47,42
            message= _ "There's tons of them! Flee, we must warn the others!"
        [/message]

        [kill]
            x,y=45,42
            animate=no
        [/kill]

        [kill]
            x,y=47,42
            animate=no
        [/kill]

        [move_unit_fake]
            type=Spearman
            x=45,45,45,44
            y=42,41,40,39
        [/move_unit_fake]

        [move_unit_fake]
            type=Javelineer
            x=47,47,46,46,46
            y=42,41,40,39,38
        [/move_unit_fake]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Well, so much for the element of surprise."
        [/message]

        [message]
            description=Esanoo
            message= _ "Thank you. I'm sorry, I don't know what came over me. They just jumped out of nowhere."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "It's okay, you're not used to being on dry ground, and you've been through a lot. Even if the humans know we're coming, we can still take them. Just be careful and stay in the back until we reach the water again."
        [/message]

        [message]
            description=Esanoo
            message= _ "I sure will look forward to that. I'm afraid my scales have all dried out again. It itches something terrible."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Well if we're going to save those merfolk, then we don't have any time to lose. The humans said they would be sacrificed in just two days. We'd better set up camp here and push on north west as soon as possible. I just hope we can make it in time."
        [/message]

        [terrain]
            x,y=45,46
            terrain=Ke
        [/terrain]

        [terrain]
            x=44,45,46,44,45,46
            y=45,45,45,46,47,46
            terrain=Ce
        [/terrain]

        #add human scouts to jungle

        #western peninsula
        {UNIT_T (Swordsman) (Human Scout) ( _ "Human Scout") 6 28 43}

        #central peninsula

        {UNIT_T (Javelineer) (Human Scout) ( _ "Human Scout") 2 34 40}
        {UNIT_T (Bowman) (Human Scout) ( _ "Human Scout") 2 26 38}

#ifdef EASY
#else
        {UNIT_T (Spearman) (Human Scout) ( _ "Human Scout") 2 32 37}
#endif

        #north eastern peninsula
        {UNIT_T (Cavalryman) (Human Scout) ( _ "Human Scout") 5 42 34}

#ifdef EASY
#else
        {UNIT_T (Heavy Infantryman) (Human Scout) ( _ "Human Scout") 5 42 37}
#endif

        # changed from Pikeman to Spearman
        {UNIT_T (Spearman) (Human Scout) ( _ "Human Scout") 5 46 36}

        #add a few human soldiers to islands

        #two southern islands with caged merfolk
        #{UNIT_T (Spearman) (Human Soldier) ( _ "Human Soldier") 6 25 34}
        {UNIT_T (Bowman) (Human Soldier) ( _ "Human Soldier") 5 34 30}

        #western island with base
        {UNIT_T (Heavy Infantryman) (Human Soldier) ( _ "Human Soldier") 6 20 33}

        #north eastern island with base
        {UNIT_T (Pikeman) (Human Soldier) ( _ "Human Soldier") 5 33 26}

        #central island
        {UNIT_T (Cavalryman) (Human Soldier) ( _ "Human Soldier") 2 23 30}

        #capture villages

        [capture_village]
            x,y=16-44,22-45
            side=2
        [/capture_village]

        [capture_village]
            x=30,35,16
            y=45,42,35
            side=6
        [/capture_village]

        [capture_village]
            x=44,42,32
            y=37,34,31
            side=5
        [/capture_village]
    [/event]

    # Macro: Appearance of Eloh and Tanstafaal

    # eloh and tanstafaal appear
    # kaleh's can no longer recruit elves
    # merfolk offer to help kaleh cross the water

    # I need to define this before macro 3 and event 4, because they call
    # this macro

#define ELOH_APPEARS

    [remove_shroud]
        x=51-55
        y=14-17
        side=1
    [/remove_shroud]

    [unit]
        type=Desert Captain
        description=Tanstafaal
        user_description= _ "Tanstafaal"
        side=3
        x=52
        y=15
        canrecruit=yes
        [modifications]
            {TRAIT_LOYAL}
            {TRAIT_RESILIENT}
        [/modifications]
    [/unit]

    # conversation between Tanstafaal, Eloh and Elves

    [message]
        description=Tanstafaal
        message= _ "Hail, my brothers, I have returned!"
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Tanstafaal, where have you been? We have been looking for you."
    [/message]

    [message]
        description=Tanstafaal
        message= _ "I have gone on a journey and I have seen the light. No longer will I blindly follow in your footsteps, Kaleh. I have come back to lead our people on the truth path. She has spoken to me, and I am but an implement of her divine will."
    [/message]

    [message]
        description=Nym
        image=portraits/nym.png
        message= _ "Who has spoken to you?"
    [/message]

    [unit]
        type=Divine Avatar
        description=Eloh
        user_description= _ "Eloh"
        side=8
        x,y=53,16
        ai_special=guardian
        gender=female
    [/unit]

    [scroll_to_unit]
        description=Eloh
    [/scroll_to_unit]

    [message]
        description=Tanstafaal
        message= _ "Behold, our goddess has returned to us. All bow down to Eloh, our savior!"
    [/message]

    [message]
        type=Desert Fighter3, Desert Fighter4, Desert Fighter5, Desert Fighter6, Desert Fighter7, Desert Fighter8, Desert Hunter3, Desert Hunter4, Desert Hunter5, Desert Hunter6, Desert Hunter7, Desert Hunter8
        side=1
        message= _ "The Goddess!"
    [/message]

    [message]
        type=Desert Archer3, Desert Archer4, Desert Archer5, Desert Archer6, Desert Archer7, Desert Archer8
        side=1
        message= _ "Forgive me my sins!"
    [/message]

    [message]
        description=Zhul
        image=portraits/zhul.png
        message= _ "That I am so blessed to gaze upon Eloh herself..."
    [/message]

    [message]
        description=Eloh
        image=portraits/eloh.png
        message= _ "Hail my people. In your time of trial I appear to you, to save you yet again."
    [/message]

    [message]
        description=Eloh
        image=portraits/eloh.png
        message= _ "I come to you with dire news: one of you has betrayed me, and is a traitor to your cause."
    [/message]

    [message]
        type=Desert Fighter3, Desert Fighter4, Desert Fighter5, Desert Fighter6, Desert Fighter7, Desert Fighter8
        side=1
        message= _ "What?"
    [/message]

    [message]
        type=Desert Hunter3, Desert Hunter4, Desert Hunter5, Desert Hunter6, Desert Hunter7, Desert Hunter8
        side=1
        message= _ "No!"
    [/message]

    [message]
        type=Desert Archer3, Desert Archer4, Desert Archer5, Desert Archer6, Desert Archer7, Desert Archer8
        side=1
        message= _ "Who?"
    [/message]

    [message]
        description=Eloh
        image=portraits/eloh.png
        message= _ "Did I not say that I would deliver you from evil and bring you to the promised land? I have shepherded you out of the harsh deserts and under the mountains. And your salvation was almost at hand."
    [/message]

    [message]
        description=Eloh
        image=portraits/eloh.png
        message= _ "But there was one who grew corrupted by his power and rejected my divine plan. He sought to usurp my authority. He had no faith and believed that he knew better than me, I who have watched over you for generations. He wanted to lead you astray. In these perilous lands, the fate of your journey stands upon the edge of a knife, falter once and all shall fail."
    [/message]

    [message]
        description=Eloh
        image=portraits/eloh.png
        message= _ "Yes, I speak of your so-called leader, Kaleh. I did call out to him initially because I thought he was one of the faithful, but he betrayed my trust. The humans you are slaughtering wanted to help you, until Kaleh foolishly attacked them. And now Kaleh has you serving the evil merfolk and their insidious plans. Follow his path and he would have you bow down and serve the merfolk's foul god."
    [/message]

    [message]
        description=Eloh
        image=portraits/eloh.png
        message= _ "That is why I called out to Tanstafaal, one of my loyal followers. All is not yet lost. Follow him and I can still deliver you from your peril. But first, come back to me, stop fighting these humans, and kill this heretic Kaleh and his cronies."
    [/message]

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

        [then]
            [message]
                description=Kaleh
                image=portraits/kaleh.png
                message= _ "Wait, my people, do not be deceived. This thing that appears by Tanstafaal's side is not our god. I too was fooled at first, but I have come to realize by her actions that she is an imposter. When she appeared to me the night before Garak died, she told me to kill all that lived under the mountains, even the dwarves who ended up helping us. Likewise when we escaped from the caves, she appeared to me again, and told me to bow down to the humans, else she would destroy me. Never has Eloh threatened one of us or dictated our actions."
            [/message]

            [message]
                type=Desert Fighter3, Desert Fighter4, Desert Fighter5, Desert Fighter6, Desert Fighter7, Desert Fighter8, Desert Hunter3, Desert Hunter4, Desert Hunter5, Desert Hunter6, Desert Hunter7, Desert Hunter8, Desert Archer3, Desert Archer4, Desert Archer5, Desert Archer6, Desert Archer7, Desert Archer8
                side=1
                message= _ "Why should we trust you? We have not heard Eloh's words directly. Only now that you have led us into this folly has Eloh appeared to us."
            [/message]

            [message]
                description=Kaleh
                image=portraits/kaleh.png
                message= _ "She claims to be the one who has shepherded us during his journey, but who protected you across the harsh sands, who fought the orcs and led you under the mountains, who led you out again, against all odds? I did. I have bled for you, every step of the way. If you will not trust me based on my words, then trust me based on my actions. I have done the best I could for my people, and I stand by my actions. I believe that the merfolk are our friends, as the dwarves were. I refuse to bow down to harsh words and threats; we elves have always been free to make our own choices. We are not slaves, and will not blindly follow either humans or some false god."
            [/message]
        [/then]

        [else]
            [message]
                description=Kaleh
                image=portraits/kaleh.png
                message= _ "Wait, my people, do not be deceived. This thing that appears by Tanstafaal's side is not our god. I too was fooled at first, but I have come to realize by her actions that she is an imposter. When she appeared to me the night before Garak died, she told me to kill all that lived under the mountains, even the trolls who ended up helping us. Likewise when we escaped from the caves, she appeared to me again, and told me to bow down to the humans, else she would destroy me. Never has Eloh threatened one of us or dictated our actions."
            [/message]

            [message]
                type=Desert Fighter3, Desert Fighter4, Desert Fighter5, Desert Fighter6, Desert Fighter7, Desert Fighter8, Desert Hunter3, Desert Hunter4, Desert Hunter5, Desert Hunter6, Desert Hunter7, Desert Hunter8, Desert Archer3, Desert Archer4, Desert Archer5, Desert Archer6, Desert Archer7, Desert Archer8
                side=1

                message= _ "Why should we trust you? We have not heard these words directly. Only now that you have led us into this folly has she appeared to us. "
            [/message]

            [message]
                description=Kaleh
                image=portraits/kaleh.png
                message= _ "She claims to be the one who has shepherded us during his journey, but who protected you across the harsh sands, who fought the orcs and led you under the mountains, who led you out again, against all odds? I did. I have bled for you, every step of the way. If you will not trust me based on my words, then trust me based on my actions. I have done the best I could for my people, and I stand by my actions. I believe that the merfolk are our friends, as the trolls were. I refuse to bow down to harsh words and threats; we elves have always been free to make our own choices. We are not slaves, and will not blindly follow either the humans or some false god."
            [/message]
        [/else]
    [/if]

    [message]
        description=Tanstafaal
        message= _ "Your words are meaningless, Kaleh. My brethren, Eloh has appeared to you. She has spoken. Defy her at your own peril. I declare all who oppose Eloh heretics. All who are faithful, join me and let us kill the usurpers!"
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Eloh would never ask elf to kill elf. But it seems I have little choice. My people, I have led you this far, join with me and help me crush this new rebellion!"
    [/message]

    [message]
        description=Nym
        image=portraits/nym.png
        message= _ "I have followed you this far Kaleh, I will not abandon you now. But I admit that my faith is shaken. If that is not our god, than what is it?"
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "I do not know, but given what I have seen of the humans, I think following her would lead us down a dark road indeed. One that I personally do not want to discover the end of."
    [/message]

    [message]
        description=Zhul
        image=portraits/zhul.png
        message= _ "Forgive me, Kaleh. I do not know what to believe. I...I have to ponder this."
    [/message]

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

        [then]
            [message]
                description=$ally_name
                image=portraits/rogrimir.png
                message= _ "The chieftain told me to serve you, and it will take more than this to shatter my confidence in you, lad. But those elves must be out on a different island, how will we cross the deep water?"
            [/message]
        [/then]

        [else]
            [message]
                description=$ally_name
                image=portraits/grog.png
                message= _ "Great Leader told $ally_name to serve you, and so $ally_name will still follow your command. But other elves must be out on a separate island. How will we cross deep water?"
            [/message]
        [/else]
    [/if]

    # merfolk offer to help

    [message]
        role=merfolk
        message= _ "I believe that in this we can help. We are very grateful for all you have done for us Kaleh, and though we assure that we mean you no harm, you are right that actions speak louder than words. We are more familiar with the waters than you are, and we noticed that there are two shallow paths leading to the island where the other elves must be. We can show you these paths and help you across so that you may put down this rebellion."
    [/message]

    # change water terrain

    #western bridge

    [terrain]
        terrain=Ww
        x=36,37,37,37,37,38,39,39,39,39,40,40,40,41
        y=23,23,24,25,26,24,22,23,24,25,21,22,23,24
    [/terrain]

    [terrain]
        terrain=Wwf	# wmllint: ignore
        x=36,38,40,41
        y=24,23,24,23
    [/terrain]

    #southern bridge

    [terrain]
        terrain=Ww
        x=48,50,50,50,51,51,51,52,52,52,53
        y=27,27,28,30,28,29,30,26,28,29,30
    [/terrain]

    [terrain]
        terrain=Wwf	# wmllint: ignore
        x=51,52,50,49,51
        y=31,30,29,28,27
    [/terrain]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Thank you, I'm sure you will be very useful in the shallow waters. All right people, I don't want to kill any more than I have to. Too much blood has been spilled already. Knock 'em out, wound them, kill them only if you must. But we must stop Tanstafaal in his lunacy before he destroys us entirely."
    [/message]

    [message]
        description=Nym
        image=portraits/nym.png
        message= _ "We who have fought by your side before will stand with you Kaleh, but many of our people are fleeing and joining Tanstafaal. I'm afraid that while you can recall past warriors, you won't be able to recruit any new ones."
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Then we will make do with those few that we have."
    [/message]

    # change scenario objectives

    [objectives]
        summary= _ "New Objectives:"
        [objective]
            description= _ "Defeat Tanstafaal and Eloh"
            condition=win
        [/objective]
        [objective]
            description= _ "Three merfolk must survive"
            condition=win
        [/objective]
        [objective]
            description= _ "Death of Kaleh, Nym, Zhul"
            condition=lose
        [/objective]
    [/objectives]

    # move tanstafaal to keep

    [teleport]
        [filter]
            description=Tanstafaal
        [/filter]
        x,y=50,17
    [/teleport]

    # give tanstafaal some recruits

    {UNIT_T (Desert Fighter) (Elvish Rebel) ( _ "Elvish Rebel") 3 48 16}

    {UNIT_T (Desert Archer) (Elvish Rebel) ( _ "Elvish Rebel") 3 48 18}

    {UNIT_T (Desert Hunter) (Elvish Rebel) ( _ "Elvish Rebel") 3 51 19}

    {UNIT_T (Desert Hero) (Elvish Rebel) ( _ "Elvish Rebel") 3 47 18}

    {UNIT_T (Desert Ranger) (Elvish Rebel) ( _ "Elvish Rebel") 3 50 20}

    # modify income and gold for rebels

    [modify_side]
        side=3

#ifdef EASY
        income=9
        gold=100
#endif
#ifdef NORMAL
        income=11
        gold=125
#endif
#ifdef HARD
        income=13
        gold=150
#endif
    [/modify_side]

    # cut off all recruiting for side 1 elves

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

#enddef

    #Macro (event 3): check if all merfolk have been freed

    # if number_merfolk_freed = 5
    # then set merfolk_dead to 1
    # have humans retreat, go to eloh event

    # I need to put this before events 2 (rescuing of merfolk) because this
    # is actually a macro that gets called by events 2

#define CHECK_IF_FREED_ALL_MERFOLK

    [if]
        [variable]
            name=number_merfolk_freed
            numerical_equals=5
        [/variable]

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

            [if]
                [have_unit]
                    description=Esanoo
                [/have_unit]

                [then]
                    [message]
                        description=Esanoo
                        message= _ "Wonderful! We have rescued all of my band from the humans. I cannot thank you enough."
                    [/message]

                    [message]
                        role=merfolk
                        message= _ "Indeed, we owe you a great debt. You have done well Esanoo, better than I could have hoped."
                    [/message]
                [/then]

                [else]
                    [message]
                        description=Nym
                        image=portraits/nym.png
                        message= _ "Esanoo said there were five merfolk left in his band. I think we have rescued them all!"
                    [/message]

                    [message]
                        role=merfolk
                        message= _ "Indeed, I think you have now freed all of us. We owe you a great debt. We are sorry that Esanoo has fallen, but we will honor him and tell everyone the story of his great deeds. Glad are we that he found you and brought you to us. Even the smallest fish can change the course of the sea."
                    [/message]
                [/else]
            [/if]

            # have humans retreat

            [if]
                [have_unit]
                    description=Darius
                [/have_unit]

                [then]
                    [remove_shroud]
                        x=20-24
                        y=21-25
                        side=1
                    [/remove_shroud]

                    [message]
                        description=Darius
                        message= _ "Curse them! The elves have freed the merfolk. We will be have our vengeance. Keep fighting, and execute plan C!"
                    [/message]

                    [message]
                        description=Darius
                        message= _ "I must go report to the Iron Council. Keep fighting!"
                    [/message]

                    [kill]
                        description=Darius
                        animate=no
                        fire_event=no
                    [/kill]

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

                    [if]
                        [have_unit]
                            description=Zelgant
                        [/have_unit]

                        [then]
                            [message]
                                description=Zelgant
                                message= _ "I go to marshall reinforcements. Do not lose heart, we will crush these puny elves."
                            [/message]

                            [kill]
                                description=Zelgant
                                animate=no
                                fire_event=no
                            [/kill]

                            [set_variable]
                                name=zelgant_returns
                                value=1
                            [/set_variable]
                        [/then]
                    [/if]

                    [if]
                        [have_unit]
                            description=Alastra
                        [/have_unit]

                        [then]
                            [message]
                                description=Alastra
                                message= _ "I must leave for now, fight on in my stead."
                            [/message]

                            [kill]
                                description=Alastra
                                animate=no
                                fire_event=no
                            [/kill]

                            [set_variable]
                                name=alastra_returns
                                value=1
                            [/set_variable]
                        [/then]
                    [/if]
                [/then]

                [else]
                    # introduce new necromancer triad member

                    [remove_shroud]
                        x=13-17
                        y=26-30
                        side=1
                    [/remove_shroud]

                    {UNIT_ (Necromancer) (Hekuba) ( _ "Hekuba") 4 15 28}

                    [message]
                        side=4
                        type=Necromancer
                        message= _ "Curse them! The elves have stolen our offering to the Lady. We will have our vengeance. Keep fighting and execute plan C!"
                    [/message]

                    [kill]
                        description=Hekuba
                        animate=no
                        fire_event=no
                    [/kill]

                    [message]
                        description=Nym
                        image=portraits/nym.png
                        message= _ "Who was that?"
                    [/message]

                    [message]
                        role=merfolk
                        message= _ "That was one of the Iron Triad. Rarely do they leave their sanctuary. They prefer to let their minions do the dirty work."
                    [/message]

                    # Darius is dead

                    [if]
                        [have_unit]
                            description=Zelgant
                        [/have_unit]

                        [then]
                            [message]
                                description=Zelgant
                                message= _ "I go to marshall reinforcements. Do not lose heart, we will crush these puny elves."
                            [/message]

                            [kill]
                                description=Zelgant
                                animate=no
                                fire_event=no
                            [/kill]

                            [set_variable]
                                name=zelgant_returns
                                value=1
                            [/set_variable]
                        [/then]
                    [/if]

                    [if]
                        [have_unit]
                            description=Alastra
                        [/have_unit]

                        [then]
                            [message]
                                description=Alastra
                                message= _ "I must go report to the Iron Council. Keep fighting!"
                            [/message]

                            [kill]
                                description=Alastra
                                animate=no
                                fire_event=no
                            [/kill]

                            [set_variable]
                                name=alastra_returns
                                value=1
                            [/set_variable]
                        [/then]
                    [/if]
                [/else]
            [/if]

            #cut income for side 2,5,6
            [modify_side]
                side=2
                income=0
                gold=0
            [/modify_side]

            [modify_side]
                side=5
                income=0
                gold=0
            [/modify_side]

            [modify_side]
                side=6
                income=0
                gold=0
            [/modify_side]

            # activate eloh event

            {ELOH_APPEARS}
        [/then]
    [/if]

#enddef

    # Event 2: Freeing Merfolk

    # locations of first 4 merfolk
    # x=25,34,18,31
    # y=36,31,32,25
    # 1 Merman Warrior  Urruga (1st NW island) - quick
    # 2 Merman Warrior  Nuvassa (1st NE island) - strong
    # 3 Merman Spearman Yantili (2nd NW sandy island) - resilient
    # 4 Mermaid Priestess  Il-tian (2nd NE grass island) - quick

    # 5 Mermaid Enchantress is in NE cave 9 - intelliegt

    # Merman Warrior Urruga (1st NW island)

    [event]
        name=moveto

        [filter]
            x,y=25,36
            side=1
        [/filter]

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

            [then]
                [removeitem]
                    x,y=25,36
                [/removeitem]

                [unit]
                    type=Merman Warrior
                    description=Urruga
                    user_description= _ "Urruga"
                    upkeep=loyal
                    side=1
                    x=25
                    y=36
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_QUICK}
                    [/modifications]
                [/unit]

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

                    [then]
                        [if]
                            [have_unit]
                                description=Esanoo
                            [/have_unit]

                            [then]
                                [message]
                                    description=Urruga
                                    message= _ "Free at last. Thanks be to the Sea God. But wait a minute, you're elves!?! "
                                [/message]

                                [message]
                                    description=Esanoo
                                    message= _ "I have returned with the elves we sought. They have agreed to help me rescue the rest of our group from the foul humans."
                                [/message]

                                [message]
                                    description=Urruga
                                    message= _ "Indeed you have done well, far better than I could have hoped. We shall talk more later, but for now we have to free the rest of our brethren."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "Greetings. Esanoo told us that you were looking for us, and he bravely led us here. Though he has fallen in combat, we have come to rescue the rest of your kind."
                                [/message]

                                [message]
                                    description=Urruga
                                    message= _ "Yes, I recognize your face, young elf. We will remember Esanoo's sacrifice. But for now we must rescue the rest of my brethren before they too are slain by the foul humans."
                                [/message]

                                [message]
                                    description=Nym
                                    image=portraits/nym.png
                                    message= _ "How could he recognize your face? We've never seen him before."
                                [/message]

                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "We'll ask later, for now we've got to keep fighting."
                                [/message]
                            [/else]
                        [/if]
                    [/then]

                    [else]
                        [message]
                            description=Urruga
                            message= _ "Thank you for rescuing me. We'll show those humans the true fury of the merfolk!"
                        [/message]
                    [/else]
                [/if]

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

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

                [role]
                    role=merfolk
                    type=Merman Warrior
                [/role]

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

    # Merman Warrior Nuvassa (1st NE island)

    [event]
        name=moveto

        [filter]
            x,y=34,31
            side=1
        [/filter]

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

            [then]
                [removeitem]
                    x,y=34,31
                [/removeitem]

                [unit]
                    type=Merman Warrior
                    description=Nuvassa
                    user_description= _ "Nuvassa"
                    upkeep=loyal
                    side=1
                    x=34
                    y=31
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_RESILIENT}
                    [/modifications]
                [/unit]

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

                    [then]
                        [if]
                            [have_unit]
                                description=Esanoo
                            [/have_unit]

                            [then]
                                [message]
                                    description=Esanoo
                                    message= _ "I have returned with the elves we sought. They have agreed to help me rescue the rest of our group from the foul humans."
                                [/message]

                                [message]
                                    description=Nuvassa
                                    message= _ "Indeed you have done well, far better than I could have hoped. We shall talk more later, but for now we have to free the rest of our brethren."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "Greetings. Esanoo told us that you were looking for us, and he bravely led us here. Though he has fallen in combat, we have come to rescue the rest of your kind."
                                [/message]

                                [message]
                                    description=Nuvassa
                                    message= _ "Yes, I recognize your face, young elf. We will remember Esanoo's sacrifice. But for now we must rescue the rest of my brethren before they too are slain by the foul humans."
                                [/message]

                                [message]
                                    description=Nym
                                    image=portraits/nym.png
                                    message= _ "How could he recognize your face? We've never seen him before."
                                [/message]

                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "We'll ask later, for now we've got to keep fighting."
                                [/message]
                            [/else]
                        [/if]
                    [/then]

                    [else]
                        [message]
                            description=Nuvassa
                            message= _ "Thank you for rescuing me. You elves are very skilled at fighting on the dry land. I envy you."
                        [/message]

                        [message]
                            description=$unit.description
                            race=elf
                            message= _ "As I envy your kind's prowess when fighting in the water."
                        [/message]
                    [/else]
                [/if]

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

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

                [role]
                    role=merfolk
                    type=Merman Warrior
                [/role]

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

    # Merman Spearman Yantili (2nd NW sandy island)

    [event]
        name=moveto

        [filter]
            x,y=18,32
            side=1
        [/filter]

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

            [then]
                [removeitem]
                    x,y=18,32
                [/removeitem]

                [unit]
                    type=Merman Spearman
                    description=Yantili
                    user_description= _ "Yantili"
                    upkeep=loyal
                    side=1
                    x=18
                    y=32
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_RESILIENT}
                    [/modifications]
                [/unit]

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

                    [then]
                        [if]
                            [have_unit]
                                description=Esanoo
                            [/have_unit]

                            [then]
                                [message]
                                    description=Esanoo
                                    message= _ "I have returned with the elves we sought. They have agreed to help me rescue the rest of our group from the foul humans."
                                [/message]

                                [message]
                                    description=Yantili
                                    message= _ "Indeed you have done well, far better than I could have hoped. We shall talk more later, but for now we have to free the rest of our brethren."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "Greetings. Esanoo told us that you were looking for us, and he bravely led us here. Though he has fallen in combat, we have come to rescue the rest of your kind."
                                [/message]

                                [message]
                                    description=Yantili
                                    message= _ "Yes, I recognize your face, young elf. We will remember Esanoo's sacrifice. But for now we must rescue the rest of my brethren before they too are slain by the foul humans."
                                [/message]

                                [message]
                                    description=Nym
                                    image=portraits/nym.png
                                    message= _ "How could he recognize your face? We've never seen him before."
                                [/message]

                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "We'll ask later, for now we've got to keep fighting."
                                [/message]
                            [/else]
                        [/if]
                    [/then]

                    [else]
                        [message]
                            description=Yantili
                            message= _ "Thank you for rescuing me. I never imagined that we would actually be able to find you elves. Our master was right after all. But more of that later..."
                        [/message]
                    [/else]
                [/if]

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

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

                [role]
                    role=merfolk
                    type=Merman Spearman
                [/role]

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

    # Mermaid Priestess  Il-tian (2nd NE grass island)

    [event]
        name=moveto

        [filter]
            x,y=31,25
            side=1
        [/filter]

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

            [then]
                [removeitem]
                    x,y=31,25
                [/removeitem]

                [unit]
                    type=Mermaid Priestess
                    gender=female
                    description=Il-tian
                    user_description= _ "Il-tian"
                    upkeep=loyal
                    side=1
                    x=31
                    y=25
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_QUICK}
                    [/modifications]
                [/unit]

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

                    [then]
                        [if]
                            [have_unit]
                                description=Esanoo
                            [/have_unit]

                            [then]
                                [message]
                                    description=Esanoo
                                    message= _ "I have returned with the elves we sought. They have agreed to help me rescue the rest of our group from the foul humans."
                                [/message]

                                [message]
                                    description=Il-tian
                                    message= _ "Indeed you have done well, far better than I could have hoped. We shall talk more later, but for now we have to free the rest of our brethren."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "Greetings. Esanoo told us that you were looking for us, and he bravely led us here. Though he has fallen in combat, we have come to rescue the rest of your kind."
                                [/message]

                                [message]
                                    description=Il-tian
                                    message= _ "Yes, I recognize your face, young elf. We will remember Esanoo's sacrifice. But for now we must rescue the rest of my brethren before they too are slain by the foul humans."
                                [/message]

                                [message]
                                    description=Nym
                                    image=portraits/nym.png
                                    message= _ "How could he recognize your face? We've never seen him before."
                                [/message]

                                [message]
                                    description=Kaleh
                                    image=portraits/kaleh.png
                                    message= _ "We'll ask later, for now we've got to keep fighting."
                                [/message]
                            [/else]
                        [/if]
                    [/then]

                    [else]
                        [message]
                            description=Il-tian
                            message= _ "Thank you for rescuing me. May the Sea God's bounty bless you and protect you. If you have any wounded I can help heal them. The blades of the vile humans are terrible indeed."
                        [/message]
                    [/else]
                [/if]

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

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

                [role]
                    role=merfolk
                    type=Mermaid Priestess
                [/role]

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

    # We-jial Mermaid Enchantress, trapped in cave

    # when unit enters cave

    [event]
        name=moveto

        [filter]
            x=27-32
            y=17-20
            side=1
        [/filter]

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

        [message]
            speaker=unit
            message= _ "What a dark nasty place. Something smells horrible."
        [/message]

#ifdef EASY
        {FREE_UNIT (Walking Corpse) (Undead Warden) ( _ "Undead Warden") 4 27 18}
        {FREE_UNIT (Walking Corpse) (Undead Warden) ( _ "Undead Warden") 4 28 19}
#else
        {FREE_UNIT (Soulless) (Undead Warden) ( _ "Undead Warden") 4 27 18}
        {FREE_UNIT (Walking Corpse) (Undead Warden) ( _ "Undead Warden") 4 28 19}
#endif
    [/event]

    # freeing mermaid enhcantress trapped in cave

    [event]
        name=moveto

        [filter]
            x,y=27,19
            side=1
        [/filter]

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

            [then]
                [removeitem]
                    x,y=27,19
                [/removeitem]

                [unit]
                    type=Mermaid Enchantress
                    gender=female
                    description=We-jial
                    user_description= _ "We-jial"
                    upkeep=loyal
                    side=1
                    x=27
                    y=19
                    [modifications]
                        {TRAIT_LOYAL}
                        {TRAIT_INTELLIGENT}
                    [/modifications]
                [/unit]

                [message]
                    description=We-jial
                    message= _ "Thank you for rescuing me. How did you manage to escape?"
                [/message]

                {CHECK_EXPLORER}
                [message]
                    description=$explorer.description
                    message= _ "Esanoo found the elves that we were searching for. He brought them back and they helped free us. I can't believe the humans imprisoned you in such a horrible place. To be stuck in the darkness with those undead. We will make them pay for what they have done!"
                [/message]

                [message]
                    description=We-jial
                    message= _ "Do not worry yourself, now that I am free all will be set to rights. It is not our mission to defeat all the evil in this world. Protecting the elves is most important. We must bring them to our master; all else is secondary."
                [/message]

                [message]
                    description=$explorer.description
                    message= _ "Yes, you are right, of course. Pardon me."
                [/message]
                {CLEAR_VARIABLE explorer}

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

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

                [role]
                    role=merfolk
                    type=Mermaid Enchantress
                [/role]

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

    # Event 2.1: Merfolk death counter

    # Each time a merfolk dies, decrement number_merfolk_alive counter
    # after caged merfolk have been killed, if number_merfolk_alive < 3
    # then defeat

    # But before caged merfolk have been killed
    # if number_merfolk_alive + (5 - number_merfolk_freed)
    # drops below 3, then it is impossible to have 3 live merfolk, so defeat

    [event]
        name=die
        first_time_only=no

        [filter]
            race=merman
            side=1
        [/filter]

        [set_variable]
            name=number_merfolk_alive
            add=-1
        [/set_variable]

        # if all merfolk in cages have been sacrificed, then if the number of
        # merfolk alive drops below 3, then player has lost.

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

            [then]
                [if]
                    [variable]
                        name=number_merfolk_alive
                        less_than=3
                    [/variable]

                    [then]
                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "No, too many merfolk have died! There are not enough of them left to divine the location of their master. We should have protected the merfolk more carefully. Now our search is hopeless."
                        [/message]

                        [endlevel]
                            result=defeat
                        [/endlevel]
                    [/then]
                [/if]
            [/then]

            # else if merfolk in cages haven't been killed. Then add number of
            # merfolk alive to number still in cages. If total is less than 3
            # then player has lost.

            [else]
                # total = number player has alive + number in cages
                [set_variable]
                    name=total_merfolk_alive
                    value=$number_merfolk_alive
                [/set_variable]

                # take number of merfolk freed, multiply by -1, add to 5, and this
                # gives you the number still left in cages

                [set_variable]
                    name=merfolk_in_cages
                    value=5
                [/set_variable]

                [set_variable]
                    name=temp
                    value=$number_merfolk_freed
                [/set_variable]

                [set_variable]
                    name=temp
                    multiply=-1
                [/set_variable]

                [set_variable]
                    name=merfolk_in_cages
                    add=$temp
                [/set_variable]

                # add number in cages to number player has to get total
                [set_variable]
                    name=total_merfolk_alive
                    add=$merfolk_in_cages
                [/set_variable]

                {CLEAR_VARIABLE merfolk_in_cages}
                {CLEAR_VARIABLE temp}

                [if]
                    [variable]
                        name=total_merfolk_alive
                        less_than=3
                    [/variable]

                    [then]
                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "Too many merfolk have died! Even if we save the rest, there will not be enough for them to divine the location of their master. We should have protected the merfolk more carefully. Now our search is hopeless."
                        [/message]

                        [endlevel]
                            result=defeat
                        [/endlevel]
                    [/then]
                [/if]
            [/else]
        [/if]
    [/event]

    # Event 2.2 Elves discover salt water

    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=1
            race=elf
        [/filter]

        [allow_undo]
        [/allow_undo]

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

            [then]
                [store_locations]
                    x=$x1
                    y=$y1
                    terrain=Ww
                    variable=locs
                [/store_locations]

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

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

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

                        [message]
                            speaker=unit
                            message= _ "Woah, this water is warm. Imagine if we had this back home, more water than I could drink in a lifetime! Hey...wait a minute. Paugh! This water is salty! It tastes terrible, I can't drink this! What use is all this water if you can't drink it?"
                        [/message]
                    [/then]
                [/if]

                {CLEAR_VARIABLE locs}
                {CLEAR_VARIABLE temp}
            [/then]
        [/if]
    [/event]

    # Event 2.3 Easter egg message
    # If an elf or merfolk goes out to the end of the island chain

    # if unit is an elf

    [event]
        name=moveto

        [filter]
            x,y=6,38
            side=1
            race=elf
        [/filter]

        [if]
            [have_unit]
                description=Eloh
            [/have_unit]

            [then]
                [message]
                    speaker=unit
                    message= _ "It really is beautiful out here, looking out over the sparkling water. If I didn't have vile humans and traitorous elves at my back I could spend all day just sitting out here. But I really should get back to the battle. Ah, it's a hard knock life."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message= _ "It really is beautiful out here, looking out over the sparkling water. If I didn't have vile humans and Eloh knows what else at my back I could spend all day just sitting out here. But I really should get back to the battle. Ah, it's a hard knock life."
                [/message]
            [/else]
        [/if]
    [/event]

    # if unit is a merfolk

    [event]
        name=moveto

        [filter]
            x,y=6,38
            side=1
            race=merman
        [/filter]

        [message]
            speaker=unit
            message= _ "If I was a landwalker, I might think the view from this sandbar to be amazing. But I am a creature of the sea and I see views like this every day."
        [/message]
    [/event]

    # Event 2.5 Elves encounter human leaders

    [event]
        name=moveto

        [filter]
            x=27-35
            y=23-28
            side=1
        [/filter]

        [if]
            [have_unit]
                description=Zelgant
            [/have_unit]

            [then]
                [message]
                    description=Zelgant
                    message= _ "You trespass upon our land at your own peril. All who oppose the will of the Iron Council shall be crushed!"
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto

        [filter]
            x=15-21
            y=31-36
            side=1
        [/filter]

        [if]
            [have_unit]
                description=Alastra
            [/have_unit]

            [then]
                [message]
                    description=Alastra
                    message= _ "Foolish elves. We have heard of your pitiful kind. You are but worms compared to the might of the Dark Lady. Coming here shall be your undoing."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto

        [filter]
            x=19-26
            y=22-26
            side=1
        [/filter]

        [if]
            [have_unit]
                description=Darius
            [/have_unit]

            [then]
                [message]
                    description=Darius
                    message= _ "She said you would come. You may be able to defeat us, but none can defy her. You will bow down in the end. It is your destiny."
                [/message]
            [/then]
        [/if]
    [/event]

    # Event 4: Time runs out

    # turn = 16 and merfolk_dead = 0
    # kill all captured merfolk
    # (if all merfolk have been freed except hidden mermaid enchantress
    # then change the message that gets displayed, because player will not
    # see mermaid die)
    # then set merfolk_dead to 1
    # if number_merfolk_freed is less than 2, defeat
    # else, have humans retreat, go to eloh event

    [event]
        name=turn 16

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

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

                # To do: add dialogue when merfolk die

                # remove shroud around human leader

                [if]
                    [have_unit]
                        description=Darius
                    [/have_unit]

                    [then]
                        [remove_shroud]
                            x=20-24
                            y=21-25
                            side=1
                        [/remove_shroud]

                        [message]
                            description=Darius
                            message= _ "The time has come. On this most holy day, let us sacrifice these infidels unto the Dark Lady. Their suffering shall be a testament to her power and glory!"
                        [/message]
                    [/then]

                    [else]
                        # introduce new necromancer triad member

                        [remove_shroud]
                            x=13-17
                            y=26-30
                            side=1
                        [/remove_shroud]

                        {UNIT_T (Necromancer) (Hekuba) ( _ "Hekuba") 4 15 28}
                        # wmllint: recognize Hekuba

                        [message]
                            description=Hekuba
                            message= _ "The time has come, my brethren. On this most holy day, let us sacrifice these infidels unto The Dark Lady. Their suffering shall be a testament to her power and glory!"
                        [/message]

                        # Hekuba disappears again
                        [kill]
                            description=Hekuba
                            animate=no
                            fire_event=no
                        [/kill]
                    [/else]
                [/if]

                #have screen flash red

                [colour_adjust]
                    red,green,blue=255,0,0
                [/colour_adjust]

                [redraw]
                [/redraw]

                [delay]
                    time=100
                [/delay]

                [colour_adjust]
                    red,green,blue=0,0,0
                [/colour_adjust]

                [redraw]
                [/redraw]

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

                    [variable]
                        name=number_merfolk_freed
                        numerical_equals=4
                    [/variable]

                    [then]
                        [if]
                            [have_unit]
                                description=Esanoo
                            [/have_unit]

                            [then]
                                [message]
                                    description=Esanoo
                                    message= _ "Oh no! Our enchantress, We-jial. Where did they hide her? What horrible fate has befallen her? If only we could have saved her in time. "
                                [/message]

                                [message]
                                    role=merfolk
                                    message= _ "The Sea God will carry her soul out to sea and bear it to the deeps. May he watch over her until the day we are all together again."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    description=Zhul
                                    image=portraits/zhul.png
                                    message= _ "Esanoo said there were five merfolk captured. We only found four. Where did they hide the last one? What horrible fate has befallen her?"
                                [/message]

                                [message]
                                    role=merfolk
                                    message= _ "They took We-jial, our enchantress, away from us. But she is at peace now. The Sea God will carry her soul out to sea and bear it to the deeps. May he watch over her until the day we are all together again."
                                [/message]
                            [/else]
                        [/if]
                    [/then]

                    [else]
                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "The bars of the cages are smoking and glowing red hot!"
                        [/message]

                        [if]
                            [have_unit]
                                description=Esanoo
                            [/have_unit]

                            [then]
                                [message]
                                    description=Esanoo
                                    message= _ "May the Sea God protect us. They are being burnt alive! It's terrible, I can't bear to watch."
                                [/message]

                                [message]
                                    role=merfolk
                                    message= _ "The Sea God will carry their souls out to sea and bear them to the deeps. May he watch over them until the day we are all together again."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    description=Zhul
                                    image=portraits/zhul.png
                                    message= _ "Eloh protect us. They are being burnt alive! I do not know what the purpose of the unholy sacrifice is, but it is sickening to watch."
                                [/message]

                                [message]
                                    role=merfolk
                                    message= _ "The Sea God will carry their souls out to sea and bear them to the deeps. May he watch over them until the day we are all together again."
                                [/message]
                            [/else]
                        [/if]
                    [/else]
                [/if]

                # destroy images of captured merfolk
                [removeitem]
                    x=25
                    y=36
                [/removeitem]

                [removeitem]
                    x=34
                    y=31
                [/removeitem]

                [removeitem]
                    x=18
                    y=32
                [/removeitem]

                [removeitem]
                    x=31
                    y=25
                [/removeitem]

                [removeitem]
                    x=27
                    y=19
                [/removeitem]

                # if player hasn't saved 2 merfolk then defeat
                [if]
                    [variable]
                        name=number_merfolk_freed
                        less_than=2
                    [/variable]

                    [then]
                        [message]
                            description=Esanoo
                            message= _ "They are all dead. We were too late. Forgive me master."
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "We couldn't save enough of the merfolk. We have failed. Now we shall never be able to meet the merfolk's leader!"
                        [/message]

                        [endlevel]
                            result=defeat
                        [/endlevel]
                    [/then]

                    # Else esanoo laments those who died
                    # Assume that at least some merfolk have died
                    # becuase if all 5 merfolk were saved then this event
                    # would never have fired

                    [else]
                        [message]
                            description=Esanoo
                            message= _ "Oh Master, forgive me. I could not save them all in time. Vile humans, you shall pay twice over for what you have done!"
                        [/message]
                    [/else]
                [/if]

                # have humans retreat

                [if]
                    [have_unit]
                        description=Darius
                    [/have_unit]

                    [then]
                        [remove_shroud]
                            x=20-24
                            y=21-25
                            side=1
                        [/remove_shroud]

                        [message]
                            description=Darius
                            message= _ "The stinkin' elves have freed some of the merfolk. And still they fight on. Execute plan B. And kill those merfolk!"
                        [/message]

                        [message]
                            description=Darius
                            message= _ "I must go report to the Iron Council. Keep fighting!"
                        [/message]

                        [kill]
                            description=Darius
                            animate=no
                            fire_event=no
                        [/kill]

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

                        [if]
                            [have_unit]
                                description=Zelgant
                            [/have_unit]

                            [then]
                                [message]
                                    description=Zelgant
                                    message= _ "I go to marshall reinforcements. Do not lose heart, we will crush these puny elves."
                                [/message]

                                [kill]
                                    description=Zelgant
                                    animate=no
                                    fire_event=no
                                [/kill]

                                [set_variable]
                                    name=zelgant_returns
                                    value=1
                                [/set_variable]
                            [/then]
                        [/if]

                        [if]
                            [have_unit]
                                description=Alastra
                            [/have_unit]

                            [then]
                                [message]
                                    description=Alastra
                                    message= _ "I must leave for now, fight on in my stead."
                                [/message]

                                [kill]
                                    description=Alastra
                                    animate=no
                                    fire_event=no
                                [/kill]

                                [set_variable]
                                    name=alastra_returns
                                    value=1
                                [/set_variable]
                            [/then]
                        [/if]
                    [/then]

                    [else]
                        # introduce new necromancer triad member

                        [remove_shroud]
                            x=13-17
                            y=26-30
                            side=1
                        [/remove_shroud]

                        {UNIT_ (Necromancer) (Hekuba) ( _ "Hekuba") 4 15 28}
                        # wmllint: recognize Hekuba

                        [message]
                            description=Hekuba
                            message= _ "Curse them! The elves have stolen our offering to the Lady. We will have our vengeance. Keep fighting and execute plan C!"
                        [/message]

                        [kill]
                            description=Hekuba
                            animate=no
                            fire_event=no
                        [/kill]

                        [message]
                            description=Nym
                            image=portraits/nym.png
                            message= _ "Who was that?"
                        [/message]

                        [message]
                            role=merfolk
                            message= _ "That was one of the Iron Triad. Rarely do they leave their sanctuary. They prefer to let their minions do the dirty work."
                        [/message]

                        # Darius is dead

                        [if]
                            [have_unit]
                                description=Zelgant
                            [/have_unit]

                            [then]
                                [message]
                                    description=Zelgant
                                    message= _ "I go to marshall reinforcements. Do not lose heart, we will crush these puny elves."
                                [/message]

                                [kill]
                                    description=Zelgant
                                    animate=no
                                    fire_event=no
                                [/kill]

                                [set_variable]
                                    name=zelgant_returns
                                    value=1
                                [/set_variable]
                            [/then]
                        [/if]

                        [if]
                            [have_unit]
                                description=Alastra
                            [/have_unit]

                            [then]
                                [message]
                                    description=Alastra
                                    message= _ "I must go report to the Iron Council. Keep fighting!"
                                [/message]

                                [kill]
                                    description=Alastra
                                    animate=no
                                    fire_event=no
                                [/kill]

                                [set_variable]
                                    name=alastra_returns
                                    value=1
                                [/set_variable]
                            [/then]
                        [/if]
                    [/else]
                [/if]

                #cut income for side 2,5,6

                [modify_side]
                    side=2
                    income=0
                    gold=0
                [/modify_side]

                [modify_side]
                    side=5
                    income=0
                    gold=0
                [/modify_side]

                [modify_side]
                    side=6
                    income=0
                    gold=0
                [/modify_side]

                # activate eloh event

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

    # Event 4.5 Eloh turn counter: count each turn since Eloh arrived

    # For some reason this event fires but the variable does get incremented
    # if I put this event later down in the file. So that's why I put it
    # first

    # Event 5: One turn after Eloh appears Zhul leaves Kaleh and is imprisoned

    # Event 6: If Flesh Golem is alive, 4-6 turns after eloh appears
    # he turns against the elves

    # Event 4.5:
    [event]
        name=new turn
        first_time_only=no

        [if]
            [have_unit]
                description=Eloh
            [/have_unit]

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

                # Event 5: Zhul & Eloh conversation
                [if]
                    [variable]
                        name=test_counter
                        numerical_equals=2
                    [/variable]

                    [then]
                        [message]
                            description=Zhul
                            image=portraits/zhul.png
                            message= _ "I'm sorry Kaleh, I cannot let our people slaughter each other. There must be a way to stop this."
                        [/message]

                        [message]
                            description=Kaleh
                            image=portraits/kaleh.png
                            message= _ "No, don't..."
                        [/message]

                        [message]
                            description=Zhul
                            image=portraits/zhul.png
                            message= _ "I have no choice, goodbye."
                        [/message]

                        [teleport]
                            [filter]
                                description=Zhul
                            [/filter]
                            x,y=52,15
                        [/teleport]

                        [message]
                            description=Zhul
                            image=portraits/zhul.png
                            message= _ "Oh Eloh, you know how long I have faithfully served you. I ask you now a boon in return. Do not kill the boy Kaleh, he is just doing what his heart tells him to do. Did you not say: 'to err is elven, but to forgive divine'? "
                        [/message]

                        [message]
                            description=Eloh
                            message= _ "You dare to lecture me? I am a god and you are but a mortal. You of all people should know that your position is to enforce my will, not question it!"
                        [/message]

                        [message]
                            description=Zhul
                            image=portraits/zhul.png
                            message= _ "But you yourself can see that many of our people's faith is wavering. You cannot gain their loyalty by slaughtering the boy and his friends. Be merciful and kind, as you have always been, and there may be no need for this self-annihilating conflict."
                        [/message]

                        [message]
                            description=Eloh
                            message= _ "Times have changed, mercy is a sign of weakness. Let this be a lesson to everyone, absolute loyalty is absolute strength. It is clear that you do not understand this concept, Zhul. My people, now is a time to tear down the old guard and create a new empire of strength, fealty and glory! I shall grant those who are loyal eternal life and we will triumph over all enemies!"
                        [/message]

                        [message]
                            description=Zhul
                            image=portraits/zhul.png
                            message= _ "No, I..."
                        [/message]

                        [message]
                            description=Eloh
                            message= _ "No, I don't think you shall pester me any more. You shall be as a statue, forced to watch events unfold and helpless to interfere. Yes, I think this will be an appropriate punishment. Then perhaps you will learn not to question my divine will."
                        [/message]

                        [store_unit]
                            [filter]
                                description=Zhul
                            [/filter]
                            kill=yes
                            variable=Zhul_statue
                            # wmllint: recognize Zhul_statue 
                        [/store_unit]

                        {VARIABLE Zhul_statue.description "Zhul_statue"}
                        {VARIABLE Zhul_statue.status.stone "on"}

                        [unstore_unit]
                            variable=Zhul_statue
                        [/unstore_unit]
                    [/then]
                [/if]

                # Event 6: Kromph gets controlled by Eloh

                [if]
                    [variable]
                        name=test_counter
                        numerical_equals=5
                    [/variable]

                    [have_unit]
                        description=Kromph
                    [/have_unit]

                    [then]
                        [message]
                            description=Kromph
                            message= _ "Aaarrrgggh! Voices in my head, make them stop!"
                        [/message]

                        [message]
                            description=Nym
                            image=portraits/nym.png
                            message= _ "What? What do you hear?"
                        [/message]

                        [message]
                            description=Kromph
                            message= _ "Must...Can't...Must...Help me!"
                        [/message]
                    [/then]
                [/if]

                [if]
                    [variable]
                        name=test_counter
                        numerical_equals=6
                    [/variable]

                    [have_unit]
                        description=Kromph
                    [/have_unit]

                    [then]
                        [message]
                            description=Kromph
                            message= _ "Must obey...Can't resist...I...Yes, Mistress, I am yours."
                        [/message]

                        [message]
                            description=Kromph
                            message= _ "Pretty lady say elves bad. Kill elves. Kill!"
                        [/message]

                        [store_unit]
                            [filter]
                                description=Kromph
                            [/filter]
                            kill=yes
                            variable=unitstats
                        [/store_unit]

                        [set_variable]
                            name=unitstats.side
                            value=3
                        [/set_variable]

                        [unstore_unit]
                            variable=unitstats
                        [/unstore_unit]
                    [/then]
                [/if]
            [/then]
        [/if]
    [/event]

    # Event 7: Crabmen attack elves

    [event]
        name=moveto

        [filter]
            x=46-54
            y=26-30
            side=1
        [/filter]

        {RANDOM_PLACEMENT_AREA 50 28 3}

        {PLACE_UNITS_RANDOMLY 3 7 "Crab Man" "Angry Crab" ( _ "Angry Crab") ()}
        # wmllint: recognize Angry Crab

        {CLEAR_PLACEMENT_AREA}

        [message]
            description=Angry Crab
            message= _ "Aaaargh! Fresh meat!"
        [/message]

        [message]
            speaker=unit
            message= _ "Where did those things come from? They look dangerous."
        [/message]
    [/event]

    [event]
        name=moveto

        [filter]
            x=39-43
            y=21-26
            side=1
        [/filter]

        {RANDOM_PLACEMENT_AREA 41 23 3}

        {PLACE_UNITS_RANDOMLY 3 7 "Crab Man" "Angry Crab" ( _ "Angry Crab") ()}
        # wmllint: recognize Angry Crab

        {CLEAR_PLACEMENT_AREA}

        [message]
            description=Angry Crab
            message= _ "Gaaaggghhh! Kill!"
        [/message]

        [message]
            speaker=unit
            message= _ "What are those things? They looked like ticked off giant crabs."
        [/message]
    [/event]

    # MACRO: Grand Appearance of the Iron Council
    # which happens when both Tanstafaal and Eloh die

#define COUNCIL_MACRO

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "It is finished. See, my people, Tanstafaal has been killed by his own hand, and the thing pretending to be our god is gone."
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "You who call yourself Eloh, I challenge you, if you are truly our god, then show yourself, and strike me down where I stand!"
    [/message]

    [delay]
        time=1000
    [/delay]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Nothing. Eloh may still watch over us, but that thing was not her. And yet, I do not hold a grudge against all of you who rebelled. I too was deceived at first, and unlike the pretender, I am merciful. For there are too few of us left for us to slaughter each other over minor grievances. Let us declare a general amnesty and unite again, going forward hand in hand, for, god or no god, I will help us find a better land, or die trying."
    [/message]

    # convert all rebel elves into loyal elves

    [message]
        side=3
        message= _ "I think I speak for all of us when I say that we accept your offer of amnesty and will follow you again. You have proved yourself capable as a leader and we too tire of this bloodshed. In hindsight perhaps we were wrong about Eloh and Tanstafaal; we shall have to think about this long and hard."
    [/message]

    [while]
        [have_unit]
            side=3
        [/have_unit]

        [do]
            [store_unit]
                [filter]
                    side=3
                [/filter]
                variable=unitstats
            [/store_unit]

            [set_variable]
                name=unitstats.side
                value=1
            [/set_variable]

            [unstore_unit]
                variable=unitstats
            [/unstore_unit]
        [/do]
    [/while]

    {CLEAR_VARIABLE unitstats}

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Thank you. And I have also not forgotten the pledge I made to our merfolk friends. If it is possible, I would like to meet with your master. Your conduct is a testament to your people, and I, at least, trust you."
    [/message]

    [message]
        role=merfolk
        message= _ "Thank you."
    [/message]

    [remove_shroud]
        x=8-10
        y=8-10
        side=1
    [/remove_shroud]

    # create iron council triad members

    [unit]
        side=4
        type=Necromancer
        description=Hekuba
        user_description= _ "Hekuba"
        canrecruit=yes
        x,y=9,9
        upkeep=full
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
    [/unit]

    [unit]
        side=4
        type=Necromancer
        description=Zilchis
        user_description= _ "Zilchis"
        x,y=10,8
        upkeep=full
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
    [/unit]

    [unit]
        side=4
        type=Necromancer
        description=Sultaria
        user_description= _ "Sultaria"
        x,y=8,8
        upkeep=full
        [modifications]
            {TRAIT_LOYAL}
            {TRAIT_RESILIENT}
        [/modifications]
    [/unit]

    [message]
        description=Hekuba
        message= _ "And what about us, little elf, did you forget about us?"
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "I could never forget what you did to those merfolk."
    [/message]

    [message]
        description=Hekuba
        message= _ "Good, for that is just a taste. You are fools to interfere with our affairs, and the Iron Council does not tolerate fools. The Dark Lady shall swallow your souls and you shall writhe in eternal torment. Arise my brethren, by her power those who have died shall rise up and join us! The very rocks too shall rise up out of the water to aid our crossing. Like a plague we shall pour forth and drive the non-believers before us!"
    [/message]

    # edit terrain to open entrance to NW island lagoon

    [terrain]
        terrain=Ww
        x=15
        y=17
    [/terrain]

    # edit terrain to add paths to NW island

    # NE path

    [terrain]
        terrain=Ww
        x=18,20,20,20,20,21,21,21,21
        y=17,16,17,18,20,16,18,20,21
    [/terrain]

    [terrain]
        terrain=Wwf	# wmllint: ignore
        x=18,19,19,20,20,21,21,22
        y=16,16,17,19,21,17,19,20
    [/terrain]

    # SW path

    [terrain]
        terrain=Ww
        x=12,14,14,15,15,16,17,18,18,18
        y=20,20,21,20,22,22,22,22,23,24
    [/terrain]

    [terrain]
        terrain=Wwf	# wmllint: ignore
        x=13,14,14,15,16,17
        y=20,18,19,21,21,23
    [/terrain]

    # create undead units on islands

    # NW base island

    {FREE_UNIT (Revenant) (Arisen Warrior) ( _ "Arisen Warrior") 4 17 14}
    {FREE_UNIT (Bone Shooter) (Arisen Warrior) ( _ "Arisen Warrior") 4 11 18}
    {FREE_UNIT (Skeleton) (Arisen Warrior) ( _ "Arisen Warrior") 4 8 12}
    {FREE_UNIT (Skeleton Archer) (Arisen Warrior) ( _ "Arisen Warrior") 4 14 10}

    [message]
        description=Nym
        image=portraits/nym.png
        message= _ "Gosh, just when things were starting to calm down."
    [/message]

    [message]
        description=Zhul
        image=portraits/zhul.png
        message= _ "Our people are scattered and exhausted, where will we go now Kaleh? Shall we retreat back into the dunes?"
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Before I decide, I have just one question: How did you merfolk plan on bringing us to meet your master, if she dwells far beneath the sea?"
    [/message]

    [message]
        role=merfolk
        message= _ "Actually we prefer to dwell in the shallow waters, where we may frolic in the great coral reefs under the sun and moon. But I digress, we realize that you people cannot swim like us, and I believe I may have a solution."
    [/message]

    [message]
        role=merfolk
        message= _ "The humans of the Iron Council dwell in a large island to the northwest; I was taken there several times for interrogation. It is a fearsome place, full of black rock and tall peaks, but in the center is a lagoon. In the lagoon, I saw several ships anchored, which we might be able to use to transport your people across the waves."
    [/message]

    [message]
        description=Zhul
        image=portraits/zhul.png
        message= _ "Across the waves!?! We are a people of the desert, we know nothing of piloting such vessels. And I do not like the idea of putting my life at the mercy of some human-built ship."
    [/message]

    [message]
        role=merfolk
        message= _ "We have often spied on the humans and have picked up some knowledge of piloting. We also have some magical skills that allow us to control the winds and thus we can easily propel the ships in the right direction. Once out on the open sea we should be safe from danger. Besides our master lives far out in the waters, trying to find her and bearing her back here would take too long and there is no other way to get you to her."
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "We have already gone to many strange places and survived. I trust the merfolk, if they believe that they can transport us safely across the waters, then I will put my life in their hands."
    [/message]

    [message]
        description=Nym
        image=portraits/nym.png
        message= _ "Wherever you go Kaleh, I will follow."
    [/message]

    [message]
        description=Zhul
        image=portraits/zhul.png
        message= _ "Very well. You have not led us astray so far, I will not leave you now."
    [/message]

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

        [then]
            [message]
                description=$ally_name
                image=portraits/rogrimir.png
                message= _ "Ach, being stuck between the water and the sun is a terrible place to be, but where you go I will follow."
            [/message]
        [/then]

        [else]
            [message]
                description=$ally_name
                image=portraits/grog.png
                message= _ " $ally_name scared of big water and bright sun, but $ally_name will not dishonor Great Leader. Great Leader say follow Kaleh, and $ally_name will do so."
            [/message]
        [/else]
    [/if]

    [message]
        role=merfolk
        message= _ "We have attacked the humans in the past, when their boats trespass in our waters, and so they fear us greatly. Their dark mages have cast protective spells upon their boats, preventing any of our kind from boarding them. I am afraid that we cannot capture the boats for you. We will, of course, help you hold off the humans. Later, once we escape, with your help I think we can dispel the protections, but for now you must seize them yourselves."
    [/message]

    [message]
        role=merfolk
        message= _ "There are four boats in the lagoon. Once you have captured each of the four then we can help you steer them out into the open water and to freedom. Then we can pilot them to shore, safely away from the humans, and load the rest of your people onboard. But we will need all four boats to fit all of your remaining people. "
    [/message]

    [message]
        description=Nym
        image=portraits/nym.png
        message= _ "Truly, there are not as many of us as there once were."
    [/message]

    [message]
        description=Kaleh
        image=portraits/kaleh.png
        message= _ "Though the cost be high, we do what we must. Come let us go capture those boats."
    [/message]

    # change scenario objectives

    [objectives]
        summary= _ "New Objectives:"
        [objective]
            description= _ "Capture all 4 human ships"
            condition=win
        [/objective]
        [objective]
            description= _ "Three merfolk must survive"
            condition=win
        [/objective]
        [objective]
            description= _ "Death of Kaleh, Nym, Zhul"
            condition=lose
        [/objective]
    [/objectives]

    # allow player's elves to recruit units again
    # same code as start of scenario

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

        [then]
            #go from 6 to 7

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

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

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

                [then]
                    #go from 5 to 6

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

                    [allow_recruit]
                        type=Desert Fighter6, Desert Archer6, Desert Hunter6, Desert Shaman6, Desert Scout6
                        side=1
                    [/allow_recruit]
                [/then]
            [/if]

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

                [then]
                    #go from 7 to 8

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

                    [allow_recruit]
                        type=Desert Fighter8, Desert Archer8, Desert Hunter8, Desert Shaman8, Desert Scout8
                        side=1
                    [/allow_recruit]
                [/then]
            [/if]
        [/else]
    [/if]

    # modify side 4 iron council to add income and gold

    [modify_side]
        side=4

#ifdef EASY
        income=5
        gold=100
#endif
#ifdef NORMAL
        income=7
        gold=110
#endif
#ifdef HARD
        income=9
        gold=130
#endif
    [/modify_side]

    # capture villages for Iron Council (side 4)

    [capture_village]
        x,y=7-18,9-17
        side=4
    [/capture_village]

    # bring back Alastra, Darius and Zelgant if they haven't died

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

        [then]
            [unit]
                type=Javelineer
                description=Alastra
                user_description= _ "Alastra"
                side=4
                upkeep=full
                x,y=9,14
                [modifications]
                    {TRAIT_RESILIENT}
                    {TRAIT_INTELLIGENT}
                [/modifications]
            [/unit]
        [/then]
    [/if]

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

        [then]
            [unit]
                type=Shock Trooper
                description=Zelgant
                user_description= _ "Zelgant"
                side=4
                upkeep=full
                x,y=15,12
                [modifications]
                    {TRAIT_STRONG}
                    {TRAIT_LOYAL}
                [/modifications]
            [/unit]
        [/then]
    [/if]

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

        [then]
            [unit]
                type=Human Commander
                description=Darius
                user_description= _ "Darius"
                side=4
                upkeep=full
                x,y=11,10
                [modifications]
                    {TRAIT_STRONG}
                    {TRAIT_RESILIENT}
                [/modifications]
            [/unit]
        [/then]
    [/if]

    # the ship events have now been moved into the council
    # macro to prevent capricious players from capturing
    # the ships before the council appears

    # Capturing ships by elves

    # each ship is actually a village, when player captures a village
    # increment counter, when enemy captures a village, decrement it.

    #elf captures a ship

    [event]
        name=capture
        first_time_only=no

        [filter]
            x=9,10,12,15
            y=12,15,10,14
            side=1
        [/filter]

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

        [removeitem]
            x,y=$x1,$y1
        [/removeitem]

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>red)" $x1 $y1}

        [if]
            [variable]
                name=ships_captured
                numerical_equals=4
            [/variable]

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

    #enemy captures a ship

    [event]
        name=capture
        first_time_only=no

        [filter]
            x=9,10,12,15
            y=12,15,10,14
            [not]
                side=1
            [/not]
        [/filter]

        [set_variable]
            name=ships_captured
            add=-1
        [/set_variable]

        [removeitem]
            x,y=$x1,$y1
        [/removeitem]

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>purple)" $x1 $y1}
    [/event]

#enddef

    # Event 8: Meeting and Death of Eloh

    [event]
        name=moveto

        [filter]
            x=51-55
            y=14-18
            side=1
        [/filter]

        [if]
            [have_unit]
                description=Eloh
            [/have_unit]

            [then]
                [message]
                    description=Eloh
                    message= _ "You think you can strike me down. This is just a small part of my true power."
                [/message]

                [message]
                    description=Kaleh
                    image=portraits/kaleh.png
                    message= _ "Small part or no, if it is mortally possible to destroy you, I shall. Your hands are stained in our blood, you are not our god."
                [/message]
            [/then]
        [/if]
    [/event]

    # Eloh's death frees Zhul from her stasis

    [event]
        name=die

        [filter]
            description=Eloh
        [/filter]

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

        [message]
            description=Eloh
            message= _ "Don't worry Kaleh, we will see each other again...I promise."
        [/message]

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

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "She freaks me out, but at least it seems that she can be destroyed."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "That was just an apparition, but if we meet again I will make her pay for all that she has done."
        [/message]

        # Eloh's death causes Kromph to go nuts and attack elves
        [if]
            [have_unit]
                description=Kromph
            [/have_unit]

            [then]
                [message]
                    description=Kromph
                    message= _ "Mistress gone, must follow commands, but Nym master too, Nym say must protect elves, but mistress say must kill elves, but must protect, must kill, protect, kill, protect, kill, aauuggghhhhh!!!"
                [/message]

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

                [message]
                    description=Kaleh
                    message= _ "He just collapsed, the conflicting orders must have been too much for him."
                [/message]

                [message]
                    description=Nym
                    message= _ "Poor Kromph, at least he's finally at rest."
                [/message]
            [/then]
        [/if]

        [store_unit]
            variable=zhul_statue
            kill=yes
            [filter]
                description=Zhul_statue
            [/filter]
        [/store_unit]
        {VARIABLE zhul_statue.status.stoned "off"}
        {VARIABLE zhul_statue.description "Zhul"}
        {VARIABLE zhul_statue.user_description _"Zhul"}
        [unstore_unit]
            variable=zhul_statue
        [/unstore_unit]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "I'm sorry, Kaleh. My faith clouded my reason. But I wanted so very much to believe."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "You do not need to apologize. What you did was very brave. I wish to...to whatever god still watches over us, that this bloodshed was not necessary. But I could not let half my people be co-opted by that thing. As horrible as it sounds, even death is a better fate."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "So when you had the strange encounter with that human Durstrag and his guards, just after we escaped the caves, you were talking to Eloh, or whatever she is?"
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Yes, she appeared only to me and demanded that I surrender to the humans. When I refused she threatened me, saying she would kill me if I refused. That's when I really started to get suspicious."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "It is clear that that thing was not our god. I do not know what it was, but I have to keep believing that Eloh is out there somewhere. Without our faith, what do we have left?"
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "We have each other."
        [/message]

        [message]
            description=Zhul
            image=portraits/zhul.png
            message= _ "That's not enough. Look, you're a wonderful girl Nym, and Kaleh, you've shown yourself to be a great leader, but our actions have to mean something more than just our day-to-day survival. There has to be a higher purpose, Eloh must have some sort of plan for us. We have to keep believing."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Peace Zhul, we can discuss theology later. We still have work to do."
        [/message]

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

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

    # Event 9: Meeting and Death of Tanstafaal

    [event]
        name=moveto

        [filter]
            x=48-52
            y=15-19
            side=1
        [/filter]

        [if]
            [have_unit]
                description=Tanstafaal
            [/have_unit]

            [then]
                [message]
                    description=Tanstafaal
                    message= _ "You cannot defeat me, I am protected by the goddess now. Finally, Kaleh, I will show everyone who is stronger!"
                [/message]

                [message]
                    description=Kaleh
                    image=portraits/kaleh.png
                    message= _ "Oh Tanstafaal, I pity you. This battle was never about you."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=die

        [filter]
            description=Tanstafaal
        [/filter]

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

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "No, do not kill him. He may deserve it, but he will not die at my hands."
        [/message]

        [message]
            description=Tanstafaal
            message= _ "Never Kaleh. I will not be your lackey again!"
        [/message]

        [kill]
            description=Tanstafaal
            fire_event=no
        [/kill]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Why did he have to kill himself? Oh poor misguided Tanstafaal. We have lost too many elves today."
        [/message]

        [message]
            description=Nym
            image=portraits/nym.png
            message= _ "Do not blame yourself too much, it is Eloh who persuaded him to rebel."
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Yes, she too will pay for her part in all of this."
        [/message]

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

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

    # Event 10: time over event

    [event]
        name=time over

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "We've run out of time. The humans are gaining strength and will surely overwhelm us now."
        [/message]

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

    # Event 11: VICTORY!

    [event]
        name=victory

        [message]
            x=9,10,12,15
            y=12,15,10,14
            message= _ "We've captured all four boats!"
        [/message]

        [message]
            description=Kaleh
            image=portraits/kaleh.png
            message= _ "Good, then let's get out of here. The merfolk will help you guide the ships. I'll marshall the rest of our people and retreat from this bloody battlefield. We'll meet you along the coastline west of here. Don't worry about losing us, we'll stick to the coast and the merfolk will help us keep in contact. Once we've escaped and are out of range of any counterattacks by the humans, we can load the rest of our people onto the ships."
        [/message]

        [message]
            role=merfolk
            message= _ "Then by the Sea God's hand I call forth the winds. May they confound our enemies and blow these ships to safety!"
        [/message]

        [terrain]
            terrain=Ww
            x=9,10,12,15
            y=12,15,10,14
        [/terrain]

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

        [move_unit_fake]
            type=Galleon
            x=10,11,12,13,14,15,15,15,15,15,14,13,13,12,11,10,9,8,7
            y=15,15,15,16,16,17,18,19,20,21,21,22,23,23,24,24,25,25,25
        [/move_unit_fake]

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>red)" 7 25}

        [removeitem]
            x,y=9,12
        [/removeitem]

        [move_unit_fake]
            type=Galleon
            x=9,10,11,11,11,12,13,14,15,15,15,15,15,14,13,13,12,11,10,9,8
            y=12,12,13,14,15,15,16,16,17,18,19,20,21,21,22,23,23,24,24,25,24
        [/move_unit_fake]

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>red)" 8 24}

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

        [move_unit_fake]
            type=Galleon
            x=12,12,12,13,14,14,14,14,15,15,15,15,15,14,13,13,12,11,10,9,8
            y=10,11,12,13,13,14,15,16,17,18,19,20,21,21,22,23,23,24,24,25,25
        [/move_unit_fake]

        {PLACE_IMAGE "units/transport/galleon.png~RC(magenta>red)" 8 25}

        [removeitem]
            x,y=15,14
        [/removeitem]

        [move_unit_fake]
            type=Galleon
            x=15,14,14,15,15,15,15,15,15,14,13,13,12,11,10,9
            y=14,14,15,16,17,18,19,20,21,21,22,23,23,24,24,25
        [/move_unit_fake]

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

        {CLEAR_VARIABLE number_merfolk_freed}
        {CLEAR_VARIABLE number_merfolk_alive}
        {CLEAR_VARIABLE saw_mermaid_enchantress}
        {CLEAR_VARIABLE merfolk_dead}
        {CLEAR_VARIABLE elf_entered_water}
        {CLEAR_VARIABLE alastra_returns}
        {CLEAR_VARIABLE zelgant_returns}
        {CLEAR_VARIABLE darius_returns}
        {CLEAR_VARIABLE test_counter}
        {CLEAR_VARIABLE eloh_dead}
        {CLEAR_VARIABLE tanstafaal_dead}
        {CLEAR_VARIABLE Zhul_var}
        {CLEAR_VARIABLE ships_captured}
        {CLEAR_VARIABLE unitstats}
    [/event]

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

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