#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=19_Under_the_Sands
    name= _ "Under the Sands"
    {MAP 19_Under_the_Sands.map}
    {TURNS 66 65 64}
    next_scenario=19x_Crossroads
    victory_when_enemies_defeated=no

    {SCENARIO_MUSIC       "snowfall.ogg"}
    {EXTRA_SCENARIO_MUSIC "nunc_dimittis.ogg"}
    {EXTRA_SCENARIO_MUSIC "into_the_shadows.ogg"}

    {UNDERGROUND}
    [+time]
        red,green,blue=-30,-60,-60
    [/time]

    {STORYTXT_UNDER_THE_SANDS}

    {DEATHS_ACT_3}

    {SPAWN_CONTROLLER}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        team_name=good
        user_team_name= _ "team_name^Galas"

        shroud=yes

        {GOLD 160 150 140}

        # wmllint: recognize Galas
        {CHARACTER_STATS_GALAS}
    [/side]
    # wmllint: validate-on

    [side]
        side=2
        team_name=enemies
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}

        recruit=Chaos Invader,Chaos Invoker,Imp,Demon,Chaos Headhunter,Shadow Minion,Abomination
        {GOLD 50 100 150}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT leader_value        10.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,mixed fighter,scout,fighter,mixed fighter,scout,archer,archer"}
        [/ai]

        canrecruit=yes
        type=Chaos Razerman
        id=Renan
        name= _ "Renan"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
    [/side]

    #
    # A few L0 matrices are set to have ZoC.
    #
#define UTS_FORCE_ZOC
    [+unit]
        [modifications]
            [trait]
                id=force_zoc_trait
                [effect]
                    apply_to=zoc
                    value=yes
                [/effect]
            [/trait]
        [/modifications]
    [/unit]
#enddef

    [side]
        side=3
        team_name=enemies
        user_team_name= _ "team_name^Monsters"
        {CHAOS_FLAG}

        recruit=Shaxthal Runner Drone,Shaxthal Assault Drone,Psy Crawler,Shadow Minion,Imp,Abomination
        {GOLD 50 100 150}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT leader_value        20.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "mixed fighter,scout,mixed fighter,mixed fighter,fighter"}
        [/ai]

        canrecruit=yes
        type=Verlissh Matrix Core
        id=Alien Matrix
        name= _ "Alien Matrix"

        {SIDE_GENERIC_GUARD (Verlissh Matrix Core) 25 51}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Core) 24 42}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Core) 26 31}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Core) 2 24}

        {SIDE_GENERIC_GUARD (Psy Crawler) 20 4} {FACING sw}
        {SIDE_GENERIC_GUARD (Psy Crawler) 23 4}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 8 16}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 18 19}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 24 28}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 16 29}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 23 30}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 28 28}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 31 31}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 24 33}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 15 33}
        # Hive units
        # Note that Matrix parts may have ZoC being L0 for exploration purposes

        # Matrix conducts on "shortcut" hive channels, mainly placed to discourage the player
        # from taking the "shortcut", therefore forcing him/her to navigate thru the whole hive
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 25 41} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 26 41} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 26 42} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 26 43} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 28 41} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 28 42} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 27 43} {UTS_FORCE_ZOC}
        # Conducts on the eastern side passage; mainly placed to discourage the player
        # from exploring that zone
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 38 48} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 39 49} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 39 50} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 38 50} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 39 51} {UTS_FORCE_ZOC}
        # In village chamber
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 28 53}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 34 54}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 32 53}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 28 52} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 35 52} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 35 53} {UTS_FORCE_ZOC}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 35 54} {UTS_FORCE_ZOC}
    [/side]

    [side]
        side=4
        team_name=enemies
        user_team_name= _ "team_name^Monsters"
        {CHAOS_FLAG}

        recruit=Shaxthal Runner Drone,Shaxthal Drone,Abomination,Chaos Hound
        {GOLD 50 100 150}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT leader_value        20.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "mixed fighter,mixed fighter,fighter"}
        [/ai]

        canrecruit=yes
        type=Shaxthal Protector Drone
        [modifications]
            {TRAIT_BIOMECHANICAL}
            {TRAIT_ARMORED}
        [/modifications]

        {SIDE_GENERIC_GUARD (Shaxthal Assault Drone) 21 3}

        {SIDE_GENERIC_GUARD (Psy Crawler) 25 10} {FACING sw}
        {SIDE_GENERIC_GUARD (Psy Crawler) 20 11}
        {SIDE_GENERIC_GUARD (Psy Crawler) 28 7} {FACING sw}
        {SIDE_GENERIC_GUARD (Shaxthal Assault Drone) 17 10} {FACING sw}
        {SIDE_GENERIC_GUARD (Shadow Minion) 16 9} {FACING sw}
        {SIDE_GENERIC_GUARD (Shadow Minion) 17 11}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 16 13}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 29 7}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 17 8}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 29 15}
    [/side]

    [side]
        side=5
        team_name=enemies
        user_team_name= _ "team_name^Chaos Empire"
        {CHAOS_FLAG}

        no_leader=yes
        hidden=yes

        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 4 44}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 14 44}
        {SIDE_GENERIC_GUARD (Verlissh Matrix Flow System) 6 47}
        {SIDE_GENERIC_GUARD (Abomination) 5 41}
        {SIDE_GENERIC_GUARD (Abomination) 10 42} {FACING sw}
        {SIDE_GENERIC_GUARD (Soulless) 11 46} {FACING sw} {VARIATION swimmer}
        {SIDE_GENERIC_GUARD (Walking Corpse) 4 45} {VARIATION swimmer}
        {SIDE_GENERIC_GUARD (Giant Leech) 9 50}
        {SIDE_GENERIC_GUARD (Leech) 21 36} {FACING sw}
        {SIDE_GENERIC_GUARD (Leech) 14 16} {FACING sw}
        {SIDE_GENERIC_GUARD (Eyestalk) 6 17}
        {SIDE_GENERIC_GUARD (Eyestalk) 8 36}
        {SIDE_GENERIC_GUARD (Fire Guardian) 11 25}
        {SIDE_GENERIC_GUARD (Fire Guardian) 18 23} {FACING sw}
        {SIDE_GENERIC_GUARD (Fire Guardian) 24 20} {FACING sw}
        {SIDE_GENERIC_GUARD (Fire Wisp) 20 26}
        {SIDE_GENERIC_GUARD (Fire Wisp) 26 24} {FACING sw}
        {SIDE_GENERIC_GUARD (Fire Wisp) 14 26}
    [/side]

    {STARTING_VILLAGES_ALL 3}
    {STARTING_VILLAGES 1 6}
    {STARTING_VILLAGES 2 6}
    {STARTING_VILLAGES 4 6}

    {TIMED_DRONE_SPAWNER 9 (type="Shaxthal Drone") 3 22 18}

    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 3 22}
    {TIMED_DRONE_SPAWNER 2 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 5 23}
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 3 24}
#ifdef HARD
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 8 21}
#endif
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 1 18}
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 4 28}
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 3 30}
#ifndef EASY
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 3 33}
#endif

    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 17 42}
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 18 43}
#ifdef HARD
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 21 47}
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 32 45}
    {TIMED_DRONE_SPAWNER 6 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 40 44}
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 7 51}
#endif
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 24 43}
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 22 39}
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 27 40}
    {TIMED_DRONE_SPAWNER 6 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 29 35}
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 33 38}
#ifndef EASY
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 36 40}
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 29 44}
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 35 46}
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 38 43}

    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 5 50}
    {TIMED_DRONE_SPAWNER 7 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 2 55}
#endif
    {TIMED_DRONE_SPAWNER 5 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 30 41}
    {TIMED_DRONE_SPAWNER 4 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 34 44}
    {TIMED_DRONE_SPAWNER 3 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 35 48}

    {TIMED_DRONE_SPAWNER 1 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 40 57}
    {TIMED_DRONE_SPAWNER 2 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 34 59}
    {TIMED_DRONE_SPAWNER 2 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 36 60}
    {TIMED_DRONE_SPAWNER 1 (type="Shaxthal Drone,Shaxthal Runner Drone") 3 38 61}

    {SETUP_SHAXTHAL_ROAMING_SOUND_EFFECTS}

    # These sound sources need to be removed for the final cutscene.

    {CAVE_NOISE_SOUND_SOURCE}
    [+sound_source]
        id=cave_ambience # wmllint: ignore
    [/sound_source]

    {CAVE_WATER_SOUND_SOURCE 39 53}
    [+sound_source]
        id=water1 # wmllint: ignore
    [/sound_source]

    {CAVE_WATER_SOUND_SOURCE 11 61}
    [+sound_source]
        id=water2 # wmllint: ignore
    [/sound_source]

    [event]
        name=prestart

        {VARIABLE enemy_casualties   0}
        {VARIABLE destroyed_matrices 0}

        [count_units]
            type=Verlissh Matrix Core
            variable=total_matrices
        [/count_units]

        [time_area]
            id=outside
            x,y=11,73
            radius={INFINITY}
            [filter_radius]
                terrain=!,X*,X*^*,U*,U*^*
            [/filter_radius]

            {TWO_SUNS_DEFAULT_SCHEDULE}
        [/time_area]

        # wmllint: recognize Elynia
        {RECALL_ELYNIA}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR}
        # wmllint: recognize Erathan
        {RECALL_ERATHAN}
        # wmllint: recognize Igor
        {RECALL_IGOR}

        {OBJECTIVES (
            {OBJECTIVE_VICTORY ( _ "Proceed south to the cave exit with Elynia and Mal Keshar")}

            {OBJECTIVE_DEFEAT ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT ( _ "Death of Mal Keshar")}
            {OBJECTIVE_DEFEAT ( _ "Death of Erathan")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER_NO_BONUS}
        )}

        {LOCK_VIEW}
    [/event]

    [event]
        name=start

        [message]
            speaker=Galas
            message= _ "I am starting to think that this wasn’t such a good idea after all. The place reeks of decomposing flesh and sewage — I can hardly breathe! This impenetrable darkness does not help matters either."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Hey, the stench of putrefaction never hurt anybody before — not me, at least. But you are right, this darkness is... unnatural. We ought to be careful."
        [/message]

        [message]
            speaker=Elynia
            message= _ "The more I see the horrors created by the demons and the Chaos humans, the more I fear for Irdya’s fate. What will become of the prosperous northlands if we cannot put a stop to their invasion at its source? Why do they do this? Is there a purpose to this senseless decay and destruction? What are they going to do next if they manage to turn the entire continent into a barren wasteland?"
        [/message]

        {MYSTERIOUS_VOICE ( _ "Galas, I can do more than merely speak to you.")}

        [message]
            speaker=Galas
            message= _ "I... I’m feeling ill..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Galas? Oh, please, not again. We need to be moving, and fast. I don’t know for certain how long it will take those demons to find another way into these caves."
        [/message]

        {MYSTERIOUS_VOICE ( _ "Have you ever wondered what it would feel like if a greater being could reach into your mind and simply... crush it?")}

        [harm_unit]
            [filter]
                id=Galas
            [/filter]
            kill=no
            amount="$($this_unit.hitpoints * 0.75)"
            animate=yes
        [/harm_unit]

        [message]
            speaker=Galas
            message= _ "Aaaaaaaaaaaaaaaah!!! It hurts— Get out of my head... Please... Elynia!!!" # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Elynia
            message= _ "G— Galas!? I... What should I do?"
        [/message]

        {MYSTERIOUS_VOICE ( _ "On the surface or underground, it makes no difference to me, Galas. You will not last long if you stay in my domain, unless you abandon this foolish quest of yours and pledge allegiance to Uria and me!")}

        [message]
            speaker=Galas
            message= _ "N— n— never! Ack!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Elynia, can’t you see the darkness is trying to get into his body?! Do something to dispel the shadows or we’ll lose him!"
        [/message]

        [message]
            speaker=Galas
            message= _ "No... No! I will not do it!!! Please!"
        [/message]

        [store_unit]
            [filter]
                id=Galas
            [/filter]
            kill=no
            variable=galas_store
        [/store_unit]

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

        [item]
            x,y=$galas_store.x,$galas_store.y
            image="scenery/galas-unconscious.png~RC(magenta>brown)"
        [/item]

        {THUNDER ()}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Galas, please don’t die, we need you! Why, why couldn’t I see this? Right in front of me... For how long?!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Don’t despair, we have not lost him yet. He’s still alive, just unconscious. Just... make sure to keep him by your side until we find a way back to the surface. Your light might be the only thing that can protect him from the darkness of this place."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I understand. Let’s not tarry here any longer."
        [/message]

        [remove_item]
            x,y=$galas_store.x,$galas_store.y
        [/remove_item]

        {MOVE_UNIT id=Elynia $galas_store.x $galas_store.y}

        [store_unit]
            [filter]
                id=Elynia
            [/filter]
            variable=elynia_store
        [/store_unit]

        {VARIABLE elynia_store.canrecruit yes}
        # Remove hero overlay and ellipse for now.
        {CLEAR_VARIABLE elynia_store.overlays,elynia_store.ellipse}

        [unstore_unit]
            find_vacant=no
            variable=elynia_store
        [/unstore_unit]

        {CLEAR_VARIABLE elynia_store}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=turn 3

        [message]
            speaker=Elynia
            message= _ "Ugh, carrying Galas around is exhausting. Perhaps you could lend me a hand, Mal Keshar?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "That had better not be a poor attempt at cracking a joke at my expense."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I... What? Oh! ... Of course not, you fool! I am asking you to help me!"
        [/message]
    [/event]

    [event]
        name=turn 5

        [message]
            speaker=Erathan
            message= _ "I sorely regret accepting the council’s mission to follow you people. This is a truly dreadful place to be for someone who is neither a necromancer nor a walking light source."
        [/message]
    [/event]

    [event]
        name=turn 9

        # wmllint: local spelling Soooo

        [message]
            speaker=Mal Keshar
            message= _ "Soooo, Elynia... How did you not see the shadows closing in on Galas?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "You have to understand I spent... who knows how many thousands of years asleep underground, Mal Keshar. I have not fully regained control of my powers, and perhaps I never will. I don’t understand the magic that the enemy used against Galas, and it’s probable that only someone well attuned to the essence of darkness like yourself can sense its power."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "It worries me that Yechnagoth was said to possess the ability to infect people’s minds with her darkness. Do you believe she could have survived the fight with those elves and be behind this? Mal Hekuba did say her power still lives thanks to Uria."
        [/message]

        [message]
            speaker=Elynia
            message= _ "It is a possibility we should consider, indeed. But I’m not looking forward to confronting another false god."
        [/message]
    [/event]

    [event]
        name=turn 12

        [message]
            speaker=Mal Keshar
            message= _ "This is taking us far too long. Make haste, you fools!"
        [/message]
    [/event]

    [event]
        name=time over

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Mal Keshar
            message= _ "Argh! We have spent far too long in these caves and the darkness has surrounded us! Elynia, do something!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "I am sorry, Galas... This is all my fault..."
        [/message]
    [/event]

    {FIRE_EVENT_ON_STUMBLE_UPON "spotted core"
    type="Verlissh Matrix Core"}

    [event]
        name=spotted core

        [message]
            speaker=Mal Keshar
            message= _ "What in name of the Dark Gods is that thing? It seems to be filled with larvae of those hideous creatures. Shall we destroy it?"
        [/message]

        [message]
            speaker=Erathan
            message= _ "It shouldn’t hurt to get rid of a few of them before they have a chance to hatch."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            canrecruit=yes
            side=3
        [/filter]

        [terrain]
            x=18,17
            y=54,55
            terrain=Urb
        [/terrain]

        [terrain]
            x=21-23,22
            y=   59,58
            terrain=Wwf
        [/terrain]

        [redraw][/redraw]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message=_"Touchplate triggered. A wall moves."
        [/message]
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            type=Verlissh Matrix Core
        [/filter]

        {VARIABLE_INC destroyed_matrices}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            [not]
                side=1
            [/not]
        [/filter]

        {VARIABLE_INC enemy_casualties}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            [not]
                side=1
            [/not]
        [/filter]
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS enemy_casualties 10}
        [/filter_condition]

        [message]
            speaker=Erathan
            message= _ "Please do not forget that we came to these lands to accomplish a specific goal. Disposing of every single foe we encounter is an impossible task and can only serve to delay us."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Right, right, but it will prove impossible to get through these caverns otherwise, what with them constantly crawling out of the walls. Besides, I could use the entertainment."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Elynia,Mal Keshar
            x=20-42,24-42
            y=38-61,35-45
        [/filter]

        [allow_undo][/allow_undo]

        [redraw][/redraw]

        [message]
            speaker=Erathan
            message= _ "Where are you going? We didn’t come here to fight these creeps! We ought to focus on getting back to the surface."
        [/message]
    [/event]

    # Victory trigger
    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Elynia,Mal Keshar
            [filter_location]
                area=outside
            [/filter_location]
        [/filter]

        # Don't allow the player to escape the hive if one of the heroes are in it.
        [if]
            [have_unit]
                id=Elynia,Mal Keshar
                x=20-42,24-42,20-42,24-42
                y=38-61,35-45,38-61,35-45
            [/have_unit]
            [then]
                [if]
                    {VARIABLE_LEXICAL_EQUALS unit.id "Mal Keshar"}
                    [then]
                        [message]
                            speaker=Mal Keshar
                            message= _ "Wait! We can’t leave Elynia behind in the alien hive!"
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=Elynia
                            message= _ "Wait! We can’t leave Mal Keshar behind in the alien hive!"
                        [/message]
                    [/else]
                [/if]
            [/then]
            [else]
                [message]
                    speaker=unit
                    message= _ "Are we ready to exit these caverns?"
                    [option]
                        label={I18N:YES} # wmllint: ignore
                        [command]
                            {ENDLEVEL_VICTORY no}
                        [/command]
                    [/option]
                    [option]
                        label={I18N:NO} # wmllint: ignore
                    [/option]
                [/message]
            [/else]
        [/if]
    [/event]

#define UTS_STORE_AND_SET_LOCATION _ID _STORE_ID _X _Y _FACING
    [store_unit]
        [filter]
            id={_ID}
        [/filter]
        variable={_STORE_ID}
        kill=yes
    [/store_unit]

    {VARIABLE {_STORE_ID}.x      {_X}      }
    {VARIABLE {_STORE_ID}.y      {_Y}      }
    {VARIABLE {_STORE_ID}.facing {_FACING} }
#enddef

    [event]
        name=victory

        {LOCK_VIEW}

        #
        # Clean the map.
        #

        [kill]
            [not]
                side=1
            [/not]
        [/kill]

        {RESET_AND_SEND_TO_RECALL_LIST (
            side=1
            [not]
                id=Elynia,Mal Keshar,Erathan,Igor
            [/not]
            [not]
                x,y=recall,recall
            [/not]
        )}

        {UTS_STORE_AND_SET_LOCATION (Elynia)     elynia_store  11 73 s }
        {UTS_STORE_AND_SET_LOCATION (Mal Keshar) malin_store   10 73 se}
        {UTS_STORE_AND_SET_LOCATION (Erathan)    erathan_store 14 71 se}

        [if]
            [have_unit]
                id=Igor
            [/have_unit]
            [then]
                {UTS_STORE_AND_SET_LOCATION Igor igor_store 12 75 nw}
            [/then]
        [/if]

        [set_variables]
            name=elynia_store
            mode=merge
            [value]
                {IS_HERO}
                canrecruit=no
            [/value]
        [/set_variables]

        {FADE_TO_BLACK}

        [place_shroud]
            side=1
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [fade_out_sound_effects][/fade_out_sound_effects]

        {REMOVE_SOUND_SOURCE cave_ambience,water1,water2}

        [reset_sound_effects][/reset_sound_effects]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Time passes."
        [/message]

        {VARIABLE galas_store.x 11}
        {VARIABLE galas_store.y 74}

        [scroll_to]
            x,y=$galas_store.x,$galas_store.y
            {WARP}
        [/scroll_to]

        [item]
            x,y=$galas_store.x,$galas_store.y
            image="scenery/galas-unconscious.png~RC(magenta>brown)"
        [/item]

        [remove_shroud]
            side=1
            area=outside
        [/remove_shroud]

        [redraw]
            side=1
        [/redraw]

        {FADE_IN}

        [unstore_unit]
            variable=elynia_store
        [/unstore_unit]

        [unstore_unit]
            variable=malin_store
        [/unstore_unit]

        [unstore_unit]
            variable=erathan_store
        [/unstore_unit]

        [if]
            {VARIABLE_NUMERICAL_EQUALS igor_store.length 1}
            [then]
                [unstore_unit]
                    variable=igor_store
                [/unstore_unit]
            [/then]
        [/if]

        {CLEAR_VARIABLE elynia_store,malin_store,erathan_store,igor_store}

        [redraw][/redraw]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Galas, please wake up..."
        [/message]

        {MOVE_UNIT id=Erathan 12 72}

        [message]
            speaker=Erathan
            message= _ "(irritated) He still hasn’t regained consciousness? Huh. I have to say, I always thought you elves were more resilient than this. For how much longer do you believe we are going to have to wait here in the open, faerie?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "For as long as need be, of course. But if you really want us to go—"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "You know, human guy, you are a very obnoxious character. If you don’t think you can help us then perhaps you should have stayed back in your cozy home in the Far North. Or at the very least keep your mouth shut!"
        [/message]

        [message]
            speaker=Erathan
            message= _ "Huh, you of all people are calling me obnoxious, lich? I knew you were not the sharpest tool in the shed, but I may have overestimated your self-awareness."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Never mind what I just said, I will shut your mouth myself—"
        [/message]

        [if]
            [have_unit]
                id=Igor
            [/have_unit]
            [then]
                [message]
                    speaker=Igor
                    message= _ "Please stop! You don’t need to fight each other! We’re all in this together, aren’t we?"
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "Yes, please. If you really must kill each other, do so in silence. I am trying to focus on bringing Galas back."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "Could you two just behave for a moment? I am trying to focus here on bringing Galas back. If you really must kill each other, do so in silence."
                [/message]
            [/else]
        [/if]

        [hide_unit][/hide_unit]

        {BLACK_SCREEN}

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "A whisper..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "And a light..."
        [/message]

        [delay]
            time=1500
        [/delay]

        {FADE_IN}

        [unhide_unit][/unhide_unit]

        [delay]
            time=750
        [/delay]

        [remove_item]
            x,y=$galas_store.x,$galas_store.y
        [/remove_item]

        [unstore_unit]
            variable=galas_store
            find_vacant=yes
        [/unstore_unit]

        {CLEAR_VARIABLE galas_store}

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=Galas
            message= _ "What... happened to me?"
        [/message]

        [message]
            speaker=Igor
            message= _ "Oh, master Galas! I’m really happy to see you awake again!"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "Elynia, what happened? Where are we? Why... Weren’t we in the caves?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "“What happened?” Why the hell are you asking us?! What happened to you, is the question!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Galas, I thought for a moment you would never open your eyes again! What did the darkness do to you?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "You... you would not believe me if I told you. You would think I was insane, or that I had been possessed by the enemy."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Really kid, there is nothing to hide. We saw the shadows trying to enter your body. I mean, I saw them. Elynia did not."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Galas, please tell us. We are your friends — we have followed you this far, and we will help you no matter what."
        [/message]

        [delay]
            time=1500
        [/delay]

        [message]
            speaker=Galas
            message= _ "I should not have turned a deaf ear to the warnings... Coming to these lands on this assassination mission was ill-advised. Elynia, I saw him... I saw the dark Emperor... that metal-covered face and... He tried to tear into my mind, boasting about his power... He tried to convince me to kill you. He... he almost took control of my body."
        [/message]

        [message]
            speaker=Galas
            message= _ "I tried to resist his power, but..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "I am not strong enough to do this, Elynia. I— I am not strong enough to avenge Anlindë... I am not..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Galas, don’t feel guilty. What you experienced... Very few people have ever managed to fend off that kind of magic. You should be proud of what you did. Even if it could have killed you, you stayed loyal to your friends long enough for me to realize what was going on and protect you with my light."
        [/message]

        [message]
            speaker=Galas
            message= _ "I am truly sorry for causing you so much trouble Elynia. I really am."
        [/message]

        [message]
            speaker=Elynia
            message= _ "We have a mission to complete, don’t we? Please don’t fret about it. Some day, your kinsmen will tell stories of how the Grand Lord Galas of the Elves helped save Irdya from certain destruction by the creatures of Uria. I think it will be worth it. Just... try to stay close to us at all times and let Malin and I protect you from the darkness. Would that be all right with you?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Galas
            message= _ "Yes, I will do as you say, Elynia. Thank you... thank you all..."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Pah, suit yourself."
        [/message]

        {CLEAR_VARIABLE enemy_casualties}
        # Keep destroyed_matrices for next scenario.

        {UNLOCK_VIEW}
    [/event]
[/scenario]

#undef UTS_FORCE_ZOC
#undef UTS_STORE_AND_SET_LOCATION

# kate: indent-mode normal; encoding utf-8; space-indent on;


#textdomain wesnoth-Invasion_from_the_Unknown

[scenario]
    id=20_The_Heart
    name= _ "The Heart"
    {MAP 20_The_Heart.map}
    {TURNS 32 30 28}
    next_scenario=21_Innuendo

    {SCENARIO_MUSIC       "battle-epic.ogg"}
    {EXTRA_SCENARIO_MUSIC "loyalists.ogg"}

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

    {SHAXTHAL_SET_SURFACE_VARIATIONS_FLAG}

    {STORYTXT_THE_HEART}

    {DEATHS_ACT_3}
    {DEATHS_DWARVES}

    {SPAWN_CONTROLLER}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        team_name=good
        user_team_name= _ "team_name^Galas"

        {GOLD 320 310 300}
        {INCOME 7 5 3}

        # wmllint: recognize Galas
        {CHARACTER_STATS_GALAS}
    [/side]

    [side]
        side=2
        controller=human
        persistent=no
        team_name=good
        user_team_name= _ "team_name^Dwarves"
        {DWARVISH_FLAG}

        {GOLD 330 320 310}
        {INCOME 8 6 4}
        recruit=Dwarvish Runesmith,Dwarvish Flamethrower,Dwarvish Guardsman,Dwarvish Scout,Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Ulfserker,Gryphon Rider

        # wmllint: recognize Althurin
        canrecruit=yes
        {CHARACTER_STATS_ALTHURIN}
    [/side]
    # wmllint: validate-on

#define TH_ENEMY_AI_TARGETS
    [goal]
        [criteria]
            id=Galas
        [/criteria]
        value=8.0
    [/goal]
    [goal]
        [criteria]
            id=Elynia
        [/criteria]
        value=9.0
    [/goal]
    [goal]
        [criteria]
            id=Mal Keshar
        [/criteria]
        value=10.0
    [/goal]
#enddef

    [side]
        side=3
        team_name=enemies
        user_team_name= _ "team_name^Central Garrison"
        {CHAOS_FLAG}

        recruit=Demon,Blood Imp,Demon Grunt,Demon Zephyr,Chaos Invader,Chaos Invoker,Chaos Headhunter,Chaos Hound,Shaxthal Runner Drone,Shaxthal Protector Drone
        {GOLD 320 340 360}
        {INCOME 7 9 10}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression           1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution              0.05}
            {AI_SIMPLE_ALWAYS_ASPECT leader_value        10.00}

            {AI_RECRUITMENT_ALWAYS_ASPECT (
                {AI_RECRUIT_LIMIT "Shaxthal Protector Drone" 4}
                {AI_RECRUIT_LIMIT "Demon Zephyr"             4}
                {AI_RECRUIT_LIMIT "Demon Grunt"              4}
                {AI_RECRUIT_LIMIT "Blood Imp"                4}
            )}

            {TH_ENEMY_AI_TARGETS}
        [/ai]

        canrecruit=yes
        type=Hell Overlord
        id="General Erval"
        name= _ "General Erval"
        [modifications]
            {TRAIT_SLOW}
            {TRAIT_STRONG}
        [/modifications]
    [/side]

    [side]
        side=4
        team_name=enemies
        user_team_name= _ "team_name^Base Defenses"
        {CHAOS_FLAG}

        recruit=Chaos Hound,Demonic Hound,Chaos Invoker,Chaos Magus,Chaos Headhunter,Abomination,Imp,Automaton,Iron Golem
        {GOLD 320 340 375}
        {INCOME 6 7 8}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression           1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution              0.05}
            {AI_SIMPLE_ALWAYS_ASPECT leader_value        10.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,archer,archer,fighter,archer,scout,archer,scout,fighter,fighter,fighter"}

            {AI_RECRUITMENT_ALWAYS_ASPECT (
                {AI_RECRUIT_LIMIT "Chaos Magus"              3}
                {AI_RECRUIT_LIMIT "Abomination"              2}
                {AI_RECRUIT_LIMIT "Iron Golem"               4}
            )}

            {TH_ENEMY_AI_TARGETS}
        [/ai]

        canrecruit=yes
        type=Hell Guardian
        id="Limzer"
        name= _ "Limzer"
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    [side]
        side=5
        team_name=enemies
        user_team_name= _ "team_name^Base Defenses"
        {CHAOS_FLAG}

        recruit=Chaos Bowman,Chaos Crossbowman,Doom Guard,Chaos Headhunter,Chaos Raider,Chaos Cavalier,Demon Zephyr
        {GOLD 320 340 360}
        {INCOME 5 7 8}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression           1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution              0.00}
            {AI_SIMPLE_ALWAYS_ASPECT leader_value        10.00}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter,mixed fighter,mixed fighter,archer,scout,fighter,scout,archer"}

            {AI_RECRUITMENT_ALWAYS_ASPECT (
                {AI_RECRUIT_LIMIT "Doom Guard"               4}
                {AI_RECRUIT_LIMIT "Chaos Crossbowman"        4}
                {AI_RECRUIT_LIMIT "Chaos Cavalier"           2}
                {AI_RECRUIT_LIMIT "Demon Zephyr"             2}
            )}

            {TH_ENEMY_AI_TARGETS}
        [/ai]

        canrecruit=yes
        type=Chaos Cataphract
        id="Ilrymaea"
        name= _ "Ilrymaea"
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

#define TH_TOWER _X _Y
    [unit]
        type=Sentry Tower
        x={_X}
        y={_Y}
        upkeep=free
    [/unit]
#enddef

    [side]
        side=6
        team_name=enemies
        user_team_name= _ "team_name^Base Defenses"
        {CHAOS_FLAG}

        scroll_to_leader=no
        no_leader=yes
        hidden=yes
        defeat_condition=never

        # Has about 24 income initially from villages and is immune to the S19
        # enemy gold factor.
        recruit=Demon Zephyr,Shaxthal Rayblade,Demon Grunt,Chaos Invoker,Demon,Chaos Hound,Chaos Invader
        {GOLD 180 200 220}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression           1.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution              0.00}
            {AI_SIMPLE_ALWAYS_ASPECT village_value        0.00}
        [/ai]

        {TH_TOWER 49 23}
        {TH_TOWER 51 24}
        {TH_TOWER 52 25}
        {TH_TOWER 53 27}
        {TH_TOWER 54 28}
        {TH_TOWER 55 30}
        {TH_TOWER 55 32}
        {TH_TOWER 54 33}

        {TH_TOWER 50 35}
        {TH_TOWER 48 35}
        {TH_TOWER 46 36}
        {TH_TOWER 44 36}
        {TH_TOWER 42 37}
        {TH_TOWER 40 37}
        {TH_TOWER 38 36}
        {TH_TOWER 36 35}

        {TH_TOWER 32 33}
        {TH_TOWER 30 32}
        {TH_TOWER 28 32}
        {TH_TOWER 26 31}

        {TH_TOWER 25 28}
        {TH_TOWER 24 26}
        {TH_TOWER 25 25}
        {TH_TOWER 23 24}

        {TH_TOWER 27 22}
        {TH_TOWER 29 22}
        {TH_TOWER 31 21}
        {TH_TOWER 33 20}
        {TH_TOWER 35 20}
        {TH_TOWER 37 20}
        {TH_TOWER 39 20}
        {TH_TOWER 41 20}
        {TH_TOWER 43 20}
        {TH_TOWER 45 21}

        {SIDE_GENERIC_GUARD (Goliath) 41 32}
        {SIDE_GENERIC_GUARD (Goliath) 47 23}
        {SIDE_GENERIC_GUARD (Goliath) 27 25}
        {SIDE_GENERIC_GUARD (Goliath) 33 32}

        {SIDE_GENERIC_GUARD ({DIFF (Iron Golem) Goliath Goliath}) 36 26} {FACING se}
        {SIDE_GENERIC_GUARD ({DIFF (Iron Golem) Goliath Goliath}) 35 28} {FACING se}

        {SIDE_GENERIC_GUARD (Demon Warrior) 37 30} {FACING se}
        {SIDE_GENERIC_GUARD (Demon Warrior) 39 27} {FACING se}

        {SIDE_GENERIC_GUARD (Gutwrencher Imp) 39 32}
        {SIDE_GENERIC_GUARD (Gutwrencher Imp) 46 29}
        {SIDE_GENERIC_GUARD (Gutwrencher Imp) 47 33}
        {SIDE_GENERIC_GUARD (Gutwrencher Imp) 37 22}

        {SIDE_GENERIC_UNIT (Demon Warrior) 45 27}
        {SIDE_GENERIC_UNIT (Demon Warrior) 31 23}

#ifndef EASY
        {SIDE_GENERIC_GUARD (Chaos Marauder) 38 28}
        {SIDE_GENERIC_GUARD (Chaos Marauder) 29 31}
        {SIDE_GENERIC_GUARD (Chaos Marauder) 40 21}
#endif
    [/side]

    [side]
        side=7
        team_name=enemies
        user_team_name= _ "team_name^Heart Hive"
        {CHAOS_FLAG}

        no_leader=yes
        hidden=yes

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression             9.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution                0.00}
            {AI_SIMPLE_ALWAYS_ASPECT village_value          0.00}
            {AI_SIMPLE_ALWAYS_ASPECT simple_targeting        yes}
            {AI_SIMPLE_ALWAYS_ASPECT grouping                 no}
        [/ai]
    [/side]

    [side]
        side=8
        team_name=enemies
        user_team_name= _ "team_name^Wild Animals"

        no_leader=yes
        hidden=yes

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression       100.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution            0.00}
            {AI_SIMPLE_ALWAYS_ASPECT simple_targeting    yes}
            {AI_SIMPLE_ALWAYS_ASPECT grouping             no}
        [/ai]

        {SIDE_GENERIC_UNIT (Shaxthal Thunderbird) 22  1}
        {SIDE_GENERIC_UNIT (Shaxthal Razorbird)    7 41}
        {SIDE_GENERIC_UNIT (Shaxthal Thunderbird) 71 43}
        {SIDE_GENERIC_UNIT (Shaxthal Thunderbird) 64 25}
    [/side]

    [side]
        side=9
        team_name=enemies
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        no_leader=yes
        hidden=yes

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT aggression             9.00}
            {AI_SIMPLE_ALWAYS_ASPECT caution                0.00}
            {AI_SIMPLE_ALWAYS_ASPECT village_value          0.00}
            {AI_SIMPLE_ALWAYS_ASPECT simple_targeting        yes}
            {AI_SIMPLE_ALWAYS_ASPECT grouping                 no}
        [/ai]
    [/side]

    {NPC_BIRD_BEHAVIOR_WHOLE_MAP 8}

#define TH_DRONE_SPAWNER _TURNS _X _Y
    {TIMED_DRONE_SPAWNER {_TURNS} (variation,type=surface,"Shaxthal Drone,Shaxthal Drone,Shaxthal Drone,Shaxthal Assault Drone,Shaxthal Sentry Drone") 7 {_X} {_Y} }
#enddef

    {TH_DRONE_SPAWNER 9 35  4}
    {TH_DRONE_SPAWNER 9 27  6}
    {TH_DRONE_SPAWNER 9 33 11}
    {TH_DRONE_SPAWNER 9 42 11}

    {TH_DRONE_SPAWNER 7 47 26}
    {TH_DRONE_SPAWNER 14 43 31}
    {TH_DRONE_SPAWNER 10 44 31}
    {TH_DRONE_SPAWNER 14 49 32}
    {TH_DRONE_SPAWNER 14 31 31}
    {TH_DRONE_SPAWNER 10 30 29}
    {TH_DRONE_SPAWNER 7 35 22}
    {TH_DRONE_SPAWNER 7 38 21}

    {TH_DRONE_SPAWNER 15 15 26}
    {TH_DRONE_SPAWNER 15 23 18}

    {TH_DRONE_SPAWNER 5 61 36}
    {TH_DRONE_SPAWNER 5 65 37}
    {TH_DRONE_SPAWNER 5 68 40}
    {TH_DRONE_SPAWNER 5 67 39}
    {TH_DRONE_SPAWNER 5 70 39}
    {TH_DRONE_SPAWNER 5 53 40}
    {TH_DRONE_SPAWNER 5 60 42}
    {TH_DRONE_SPAWNER 5 59 39}
    {TH_DRONE_SPAWNER 5 51 45}
    {TH_DRONE_SPAWNER 5 64 44}
    {TH_DRONE_SPAWNER 5 69 45}
    {TH_DRONE_SPAWNER 5 38 43}
    {TH_DRONE_SPAWNER 5 43 45}
    {TH_DRONE_SPAWNER 5 31 42}
    {TH_DRONE_SPAWNER 5 21 45}
    {TH_DRONE_SPAWNER 5 27 25}
    {TH_DRONE_SPAWNER 5 20 38}
    {TH_DRONE_SPAWNER 5 21 35}
    {TH_DRONE_SPAWNER 5 11 35}
    {TH_DRONE_SPAWNER 5 19 32}
    {TH_DRONE_SPAWNER 5 12 31}
    {TH_DRONE_SPAWNER 5 17 29}
    {TH_DRONE_SPAWNER 5 11 30}

    {STARTING_VILLAGES_ALL 6}

    {STARTING_VILLAGES 1 6}
    {STARTING_VILLAGES 2 6}

    {STARTING_VILLAGES 3 3}
    {STARTING_VILLAGES 4 5}
    {STARTING_VILLAGES 5 5}

    {PLACE_IMAGE items/altar-evil.png          42 29}
    {PLACE_IMAGE items/altar-evil.png          28 30}
    {PLACE_IMAGE items/altar-bloody.png        36 23}

    {PLACE_IMAGE items/burial.png              42 35}
    {PLACE_IMAGE items/burial.png              57 14}
    {PLACE_IMAGE items/burial.png              60 14}
    {PLACE_IMAGE items/burial.png              13 20}

    {PLACE_IMAGE items/bonestack.png           44 28}
    {PLACE_IMAGE items/bonestack.png           37 34}
    {PLACE_IMAGE items/bonestack.png           30 24}
    {PLACE_IMAGE items/bonestack.png           46 24}

    {PLACE_IMAGE "items/bones.png"             71 28}
    {PLACE_IMAGE "items/bones.png~FL(horiz)"   62 44}
    {PLACE_IMAGE "items/bones.png~FL(horiz)"   15 33}
    {PLACE_IMAGE "items/bones.png~FL(horiz)"    3 16}

    {PLACE_IMAGE scenery/signpost.png           6 23}

    {PLACE_IMAGE scenery/rock-cairn.png        37  4}
    {PLACE_IMAGE scenery/monolith1.png         17 36}
    {PLACE_IMAGE scenery/monolith3.png         39 23}

    {PLACE_IMAGE scenery/village-human-burned3.png         64 33}
    {PLACE_IMAGE scenery/village-human-burned1.png         18 28}

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png       35 32}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png       43 26}
    {PLACE_IMAGE scenery/banner-uria-standing.png          52 17}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing.png    54 19}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png       20 19}
    {PLACE_IMAGE scenery/banner-yechnagoth-standing-sw.png 20 21}

    [event]
        name=prestart

        [store_starting_location]
            side=9
            variable=goal_loc
        [/store_starting_location]

        [time_area]
            id=indoors
            x,y=$goal_loc.x,$goal_loc.y
            radius=2
            {INDOORS}
        [/time_area]

        # Location of the goal marker plate.
        {VARIABLE goal_loc.x 35}
        {VARIABLE goal_loc.y 27}

        #
        # Apply matrix bonus from S19 (%matrices*40%).
        #

        [lua]
            code=<<
                local destroyed = wml.variables["destroyed_matrices"]
                local total = wml.variables["total_matrices"]
                local gfactor = 1 - 40*(destroyed/total)/100

                wprintf(W_DBG, "gold factor is %s", tostring(gfactor))

                for i = 3, 5 do
                    local side = wesnoth.sides[i]
                    side.gold = side.gold * gfactor
                end
            >>
        [/lua]

        {CLEAR_VARIABLE destroyed_matrices,total_matrices}

        #
        # Set-up abyss demon spawning.
        #

        [set_variables]
            name=demon_spawning
            [literal]
                next_turn=3
                turns={DIFF 10 8 6}
                population_limit_percent={DIFF 0.40 0.75 0.90}
            [/literal]
        [/set_variables]

        [store_locations]
            terrain=Qxua
            variable=demon_spawning.locs
        [/store_locations]

        {LOG_IFTU_DBG ("S20 spawns: configured $demon_spawning.locs.length spawn locations")}

        [terrain]
            [and]
                terrain=Qxua
            [/and]
            terrain=Qxu
        [/terrain]

        #
        # Recall heroes
        #

        # wmllint: recognize Elynia
        {RECALL_ELYNIA}
        # wmllint: recognize Mal Keshar
        {RECALL_MAL_KESHAR}
        # wmllint: recognize Erathan
        {RECALL_ERATHAN}
        # wmllint: recognize Igor
        {RECALL_IGOR}

        [unit]
            side=2
            type=Dwarvish Pathfinder
            id=Molur
            name= _ "Molur"
            {IS_LOYAL}
            upkeep=free
            placement=leader
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            side=2
            type=Gryphon Rider
            id=Elegrild
            name= _ "Elegrild"
            {IS_LOYAL}
            upkeep=free
            placement=leader
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            side=2
            type=Dwarvish Thunderer
            id=Redbart
            name= _ "Redbart"
            {IS_LOYAL}
            upkeep=free
            placement=leader
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_HEALTHY}
            [/modifications]
        [/unit]

        [if]
            {VARIABLE_NUMERICAL_EQUALS s14_althurin_store.length 1}
            [then]
                [kill]
                    id=Althurin
                [/kill]

                [store_starting_location]
                    side=2
                [/store_starting_location]

                {VARIABLE s14_althurin_store.canrecruit yes}
                {VARIABLE s14_althurin_store.side         2}

                {CLEAR_VARIABLE s14_althurin_store.overlays,s14_althurin_store.ellipse}

                [unstore_unit]
                    variable=s14_althurin_store
                    x,y=$location.x,$location.y
                [/unstore_unit]

                {CLEAR_VARIABLE location,s14_althurin_store}
            [/then]
        [/if]

        {FACE_DIRECTION (side=1) sw}
        {FACE_DIRECTION (side=2) se}

        {FACE_UNIT id=Ilrymaea        id=Galas}
        {FACE_UNIT id=Limzer          id=Althurin}
        {FACE_UNIT id="General Erval" id=Galas}

        {OBJECTIVES (
            side=1

            {OBJECTIVE_VICTORY ( _ "Move Galas, Elynia, or Mal Keshar into the dark keep")}
            {OBJECTIVE_OR}
            {OBJECTIVE_VICTORY ( _ "Defeat all enemy leaders")}

            {OBJECTIVE_DEFEAT ( _ "Death of Galas")}
            {OBJECTIVE_DEFEAT ( _ "Death of Elynia")}
            {OBJECTIVE_DEFEAT ( _ "Death of Mal Keshar")}
            {OBJECTIVE_DEFEAT ( _ "Death of Erathan")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_CARRYOVER_NO_BONUS}
        )}

        {OBJECTIVES (
            side=2

            {OBJECTIVE_VICTORY ( _ "Distract the enemy while Galas, Elynia, or Mal Keshar enter the dark keep")}
            {OBJECTIVE_OR}
            {OBJECTIVE_VICTORY ( _ "Defeat all enemy leaders")}

            {OBJECTIVE_DEFEAT ( _ "Death of Althurin")}

            {TURNS_RUN_OUT}

            {OBJECTIVE_NO_CARRYOVER}
        )}
    [/event]

#ifdef CAMPAIGN_INVASION_FROM_THE_UNKNOWN_EPISODE_II
    {ALTHURIN_1ST_TIME_HELP}
#endif

    [event]
        name=start

        [message]
            speaker=Galas
            message= _ "There it is, the Heart of the Chaos Empire."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I figured the rumors weren’t too far from the truth, but this is ridiculous. How can these people afford such a ludicrous construction in the middle of the desert? Perhaps they only ever enlisted Uria’s demons in the first place as cheap work force..."
        [/message]

        [message]
            speaker=Galas
            message= _ "The dwarven scouts report that another large battalion departed for the northwest just a few hours ago. So... I believe the time has come."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Looking at it in hindsight, there really was no way our infiltration mission wouldn’t turn into a full-fledged assault on the enemy capital. Perhaps it’s better this way, after all. Now, Galas, will you do the honors?"
        [/message]

        [message]
            speaker=Galas
            message= _ "Eh..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "You know, ask us whether we are ready and then give us an overly dramatic discourse about the importance of this battle for the future of Irdya. It’s the kind of thing a good leader is expected to do."
        [/message]

        [message]
            speaker=Galas
            message= _ "Right. Are we all ready for the battle ahead?"
        [/message]

        [message]
            speaker=Igor
            message= _ "Yes! I’m ready, master Galas!"
        [/message]

        [message]
            speaker=Erathan
            message= _ "My bow obediently awaits your orders, Lord Galas."
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Let’s get this over with!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "(<i>nods</i>)"
        [/message]

        [message]
            speaker=Galas
            message= _ "Then the battle for Irdya begins now. <b>Charge!!!</b>"
        [/message]

        [message]
            speaker=Igor
            message= _ "Wait, and what about the dramatic discourse the lady mentioned?"
        [/message]

        [message]
            speaker=Althurin
            message= _ "It appears Lord Galas has just given the order, lads. Ye know what to do! Don’t hold back! Kill every single one of these fiends! Avenge our fallen brethren! For the King! For Herthgar! <b>Charge!!!</b>"
        [/message]

        {REPLACE_SCENARIO_MUSIC casualties_of_war.ogg}
        {APPEND_MUSIC           northerners.ogg}
        {APPEND_MUSIC           battle.ogg}
        {APPEND_MUSIC           siege_of_laurelmor.ogg}

        [message]
            speaker=Ilrymaea
            message= _ "The elf lord and his consorts approach from the northeast, sir!"
        [/message]

        [message]
            speaker=Limzer
            message= _ "Dwarves! Dwarves on the northwestern hills! We are under attack!"
        [/message]

        [message]
            speaker=General Erval
            message= _ "Oh, ha ha! Are they truly this naïve? Do they believe we were not prepared for this contingency? Prepare for battle! Crush all these vermin to the ground! For Yechnagoth! For the glory of Uria and the Chaos Empire!"
        [/message]

        {HIGHLIGHT_IMAGE $goal_loc.x $goal_loc.y items/gohere.png ()}

        {CLEAR_VARIABLE goal_loc}
    [/event]

    [event]
        name=side 1 turn 1 end

        [message]
            speaker=Elynia
            message= _ "(<i>bitterly</i>) And so my time has come again to serve as the elves’ living weapon. Even if I can hardly stand this much death and destruction..."
        [/message]

        [message]
            speaker=Galas
            message= _ "I hope you can forgive me for bringing you here."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Oh, Galas, don’t fret about it — by now this almost feels like daily routine. Besides, I told you before, I would have come on my own anyway."
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            race=dwarf
        [/filter]

        [message]
            speaker=unit
            message= _ "<b>For Herthgar!!!</b>"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            race=elf
        [/filter]

        [message]
            speaker=unit
            message= _ "For Lord Lédinor and our fallen comrades!"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Mal Keshar
        [/filter]

        [message]
            speaker=Mal Keshar
            message= _ "He, he, he, he... It’s about time this place got a do-over befitting of gods who relish in death and destruction, don’t you think?"
        [/message]
    [/event]

    [event]
        name=attack
        [filter]
            id=Galas
        [/filter]

        [message]
            speaker=Galas
            message= _ "For Anlindë!"
        [/message]
    [/event]

    [event]
        name=turn 2

        [message]
            speaker=General Erval
            message= _ "Let us show these non-believers the real might of the Empire!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "Galas, enemy troops are coming from behind!"
        [/message]

        [store_starting_location]
            side=6
        [/store_starting_location]

        [store_direction]
            from_x,from_y=$location.x,$location.y
            [to]
                [filter]
                    id=Galas
                [/filter]
            [/to]
        [/store_direction]

        [move_unit_fake]
            side=6
            type=Demon Warrior
            gender=female
            x="$($location.x - 1),$location.x"
            y="1,$location.y"
        [/move_unit_fake]

        [unit]
            canrecruit=yes
            side=6
            type=Demon Warrior
            id=Umlayla
            name= _ "Umlayla"
            gender=female
            level=4
            facing=$direction
            x,y=$location.x,$location.y
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
                {BOSS_BOOST 60% 3 1 2 1}
                [object]
                    silent=yes
                    [effect]
                        apply_to=new_ability
                        [abilities]
                            {ABILITY_LEADERSHIP}
                            {ABILITY_REGENERATES}
                        [/abilities]
                    [/effect]
                [/object]
            [/modifications]
        [/unit]

        [terrain]
            x,y=$location.x,$location.y
            radius=1
            terrain=Ce
        [/terrain]

        [terrain]
            x,y=$location.x,$location.y
            terrain=Ke
        [/terrain]

        [redraw][/redraw]

        [unit]
            animate=yes
            side=6
            type=Chaos Magus
            id=Ellerian
            name= _ "Ellerian"
            x,y=$location.x,$location.y
            facing=$direction
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_DEXTROUS}
            [/modifications]
        [/unit]

#ifndef EASY
        [unit]
            animate=yes
            side=6
            type=Chaos Lorekeeper
            id=Mal Cyriath
            name= _ "Mal Cyriath"
            x,y=$location.x,$location.y
            facing=$direction
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
#endif

        [modify_side]
            side=6
            hidden=no
        [/modify_side]

        {CLEAR_VARIABLE location,direction}

        [message]
            speaker=Umlayla
            message= _ "Surprise, Irdyan maggots!"
        [/message]

        [message]
            speaker=Igor
            message= _ "Uh-oh."
        [/message]
    [/event]

    [event]
        name=turn 7

        [message]
            speaker=Althurin
            message= _ "Brace yourselves, boys! The Long Dark is upon our heels and ready to liven up this hell of a battle!"
        [/message]
    [/event]

    [event]
        name=turn 11

        [message]
            speaker=Galas
            message= _ "Even though it’s taking us much longer than expected, the Chaos Emperor has yet to make an appearance. What if our information is incorrect and he is not even in the capital?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Nah, he’s probably in his chamber running in circles and flailing his arms like a lunatic while begging the goddesses for forgiveness! (<i>cackles</i>) He knows we’ve won this fight."
        [/message]

        [message]
            speaker=Elynia
            message= _ "Hm, yes. He is most certainly down there. He... and something else whose nature I cannot ascertain yet. Mal Keshar, you can feel it too, right?"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "I try not to worry too much about these things, girl. Besides, what power could possibly stop two walking legends like us?"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            [not]
                side=1,2
            [/not]
        [/filter]
        [filter_second]
            id=Galas
        [/filter_second]

        [message]
            speaker=Galas
            message= _ "Do you see how this dark fortress crumbles down already? Tell your goddess that <b>this</b> is the fate that awaits those who dare cross the peoples of Irdya!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            [not]
                side=1,2
            [/not]
        [/filter]
        [filter_second]
            id=Elynia
        [/filter_second]

        [message]
            speaker=Elynia
            message= _ "If you meet your demon gods on the other side, tell them I will not stop until I have erased the very last trace of their influence on Irdya! Begone, filth!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            canrecruit=yes
            [not]
                side=1,2
            [/not]
        [/filter]
        [filter_second]
            id=Mal Keshar
        [/filter_second]

        [message]
            speaker=unit
            message= _ "We’ve failed the Master... How can this be... No... no!"
        [/message]

        [message]
            speaker=Mal Keshar
            message= _ "Yes, <b>yes</b>, <b>YES! AhahahahahahahaHAHAHAHAHA!!!</b>"
        [/message]
    [/event]

    #
    # Periodic demon spawning logic
    #

    [event]
        name=side 9 turn end
        first_time_only=no
        [filter_condition]
            {VARIABLE_NUMERICAL_EQUALS turn_number $demon_spawning.next_turn}
        [/filter_condition]

        {VARIABLE demon_spawning.next_turn "$($turn_number + $demon_spawning.turns)"}

        {VARIABLE_ADD demon_spawning.turns {DIFF 4 3 2}}

        [count_units]
            [filter_wml]
                [variables]
                    is_auto_spawned=yes
                [/variables]
            [/filter_wml]
            variable=temp_spawn_count
        [/count_units]

        {VARIABLE temp_spawns_needed "$($demon_spawning.locs.length * $demon_spawning.population_limit_percent - $temp_spawn_count)"}

        # TODO: use [set_variable] round once I figure out how it works.
        [lua]
            code=<<
                wml.variables["temp_spawns_needed"] = mathx.round(tonumber(wml.variables["temp_spawns_needed"]))
            >>
        [/lua]

        {LOG_IFTU_DBG "S20 spawns: need to spawn $temp_spawns_needed/$demon_spawning.locs.length demons"}

        #
        # Randomize spawn locations table every time. The shuffled table is
        # written into $temp_spawn_locs.
        #
        [lua]
            code=<<
                -- Don't do anything here if there's no need to spawn anything.
                if wml.variables["temp_spawns_needed"] > 0 then
                    local function wml_array_len(array_id)
                        return wml.variables[("%s.length"):format(array_id)]
                    end

                    local function copy_wml_array_to(src_id, src_n, dst_id, dst_n)
                        wesnoth.wml_actions.set_variables {
                            name = ("%s[%d]"):format(dst_id, dst_n),
                            mode = "replace",
                            to_variable = ("%s[%d]"):format(src_id, src_n),
                        }
                    end

                    -- List of random 0-based subscripts to $demon_spawning.locs.
                    local locs_table = {}
                    local num_locs = wml.variables["demon_spawning.locs.length"]

                    assert(num_locs > 0)

                    for j = 1, num_locs do
                        locs_table[j] = j - 1
                    end

                    mathx.shuffle(locs_table)

                    for j, n in ipairs(locs_table) do
                        local m = j -1
                        copy_wml_array_to("demon_spawning.locs", n, "temp_spawn_locs", m)
                    end

                    assert(wml_array_len("temp_spawn_locs") == wml_array_len("demon_spawning.locs"))
                end
            >>
        [/lua]

        [while]
            {VARIABLE_NUMERICAL_GREATER_THAN temp_spawns_needed 0}
            [do]
                {VARIABLE_RANDOM temp_spawn_type "Shadow Minion,Ghost,Ghost,Demon Zephyr,Demon Zephyr,Demon Zephyr,Demon Zephyr,Demon Zephyr,Demon Zephyr,Demon Zephyr,Demon Zephyr,Demon Zephyr,Shaxthal Assault Drone"}

                {VARIABLE k "$($temp_spawn_locs.length - $temp_spawns_needed)"}

                [store_direction]
                    from_x,from_y=$temp_spawn_locs[$k].x,$temp_spawn_locs[$k].y
                    [to]
                        [filter]
                            id=Galas
                        [/filter]
                    [/to]
                [/store_direction]

                [unit]
                    side=9
                    type=$temp_spawn_type
                    facing=$direction
                    x,y=$temp_spawn_locs[$k].x,$temp_spawn_locs[$k].y
                    random_traits=yes
                    random_gender=yes
                    generate_name=yes
                    animate=yes
                    [variables]
                        is_auto_spawned=yes
                    [/variables]
                [/unit]

                {VARIABLE_DEC temp_spawns_needed}
            [/do]
        [/while]

        {CLEAR_VARIABLE temp_spawn_locs,temp_spawns_needed,temp_spawn_count,temp_spawn_type,k,direction}
    [/event]

    #
    # Keep proximity spawn logic.
    #

    [event]
        name=side 9 turn
        first_time_only=no
        [filter_condition]
            [have_unit]
                side=1
                [filter_location]
                    area=indoors
                    radius={DIFF 5 7 9}
                [/filter_location]
            [/have_unit]

            [not]
                [have_unit]
                    side=9
                    [filter_wml]
                        [variables]
                            is_proximity_spawn=yes
                        [/variables]
                    [/filter_wml]
                    [filter_location]
                        area=indoors
                        radius={DIFF 5 7 9}
                    [/filter_location]
                [/have_unit]
            [/not]
        [/filter_condition]

        {LOG_IFTU_DBG "S20 spawns: proximity spawn triggered!"}

        [store_starting_location]
            side=9
            variable=spawn_loc
        [/store_starting_location]

#ifndef EASY
        {VARIABLE_RANDOM spawn_type "Demon,Demon,Demon,Demon Grunt,Demon Warrior,Chaos Headhunter,Chaos Bowman,Chaos Invader,Chaos Invader,Doom Guard,Dark Knight,Chaos Magus,Chaos Invoker,Chaos Invoker"}
#else
        {VARIABLE_RANDOM spawn_type "Demon,Demon,Demon,Demon,Demon Grunt,Chaos Headhunter,Chaos Bowman,Chaos Invader,Chaos Invader,Chaos Invader,Chaos Invader,Doom Guard,Chaos Invoker,Chaos Invoker"}
#endif

        [unit]
            animate=yes
            side=9
            type=$spawn_type
            x,y=$spawn_loc.x,$spawn_loc.y
            generate_name=yes
            random_traits=yes
            random_gender=yes
            [variables]
                is_proximity_spawn=yes
            [/variables]
        [/unit]

        {CLEAR_VARIABLE spawn_loc,spawn_type}
    [/event]

    #
    # Victory events.
    #

    [event]
        name=moveto
        [filter]
            id=Galas,Elynia,Mal Keshar
            [filter_location]
                area=indoors
            [/filter_location]
        [/filter]

        [message]
            speaker=unit
            message= _ "Quickly! We have no time to waste."
        [/message]

        {ENDLEVEL_VICTORY no}
    [/event]

    # This should be an 'enemies defeated' event handler, by all means, but as
    # side 6 is set up as an undefeatable side without leader, it will prevent
    # the event from ever triggering.
    [event]
        name=die
        [filter]
            canrecruit=yes
            [not]
                side=1,2
            [/not]
        [/filter]
        [filter_condition]
            [not]
                [have_unit]
                    canrecruit=yes
                    [filter_side]
                        [enemy_of]
                            side=1
                        [/enemy_of]
                        [not]
                            side=6
                        [/not]
                    [/filter_side]
                    [not]
                        x,y=$x1,$y1
                    [/not]
                [/have_unit]
            [/not]
        [/filter_condition]

        {ENDLEVEL_VICTORY no}
    [/event]

    [event]
        name=victory

        [message]
            speaker=Elynia
            message= _ "You know, Galas... It’s very strange for somebody like me to say this but..."
        [/message]

        [message]
            speaker=Galas
            message= _ "What is it?"
        [/message]

        [message]
            speaker=Elynia
            message= _ "... Just stay close to me at all times. It would do us no good if the shadows took over your body again."
        [/message]

        [message]
            speaker=Galas
            message= _ "... Very well."
        [/message]

        [message]
            speaker=Althurin
            message= _ "Alas, if Galas and the Lady are to succeed in their mission we must stay here and fend off the enemy reinforcements. I can’t help but wonder what kind of foe awaits that courageous bunch in there..."
        [/message]

        {CLEAR_VARIABLE demon_spawning}
    [/event]

    [event]
        name=time over

        [message]
            speaker=Elynia
            message= _ "This is hopeless, Galas. We took too long, and now enemy reinforcements are approaching from all directions!"
        [/message]
    [/event]
[/scenario]

#undef TH_TOWER
#undef TH_DRONE_SPAWNER
#undef TH_ENEMY_AI_TARGETS

# kate: indent-mode normal; encoding utf-8; space-indent on;