#textdomain wesnoth-After_the_Storm

[scenario]
    id=07A_Dark_Fire_part_1
    name= _ "Dark Fire"
    {SEGMENTED_SCENARIO}
    turns=-1
    next_scenario=07A_Dark_Fire_part_2
    victory_when_enemies_defeated=no
    disallow_recall=yes

    #
    # TODO: main chamber difficulty is too high, units get killed too easily (?)
    # TODO: mobilize guardians when entering the main chamber (?)
    #

    {F_DEATHS}

    {ADD_SEGMENT "{LE /maps/07A_Dark_Fire_part_1_01.map}"
    ({INDOORS} {SCHEDULE_LIGHTING -10 -20 0}) ()}

    {ADD_SEGMENT "{LE /maps/07A_Dark_Fire_part_1_02.map}"
    ({INDOORS} {SCHEDULE_LIGHTING -30 -40 -20}) ()}

    {SCENARIO_MUSIC "the_deep_path.ogg"}

    {STORYTXT_DARK_FIRE_1}

    # Wesnoth 1.11.8 doesn't handle ToD-less states gracefully, so we need a
    # default ToD for it.
    [time][/time]

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

        {NO_ECONOMY} # No minimum starting gold.

        shroud=yes

        # wmllint: recognize Elynia
        {CHARACTER_STATS_ELYNIA}
    [/side]
    # wmllint: validate-on

    # Catacomb guards
    [side]
        side=2
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    # Triad guards
    [side]
        side=3
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        recruit=Imp,Psy Crawler,Chaos Headhunter,Walking Corpse

        {NO_ECONOMY}
    [/side]

    # Entrance guards (NE)
    [side]
        side=4
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        recruit=Chaos Invader,Chaos Bowman,Demon,Chaos Headhunter

        {NO_ECONOMY}
    [/side]

    # Entrance guards (S)
    [side]
        side=5
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    # Entrance guards (central)
    [side]
        side=6
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    # Indoors guards
    [side]
        side=7
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        recruit=Automaton,Chaos Invoker,Demon

        {NO_ECONOMY}
    [/side]

    # Shaxthal drones, turrets
    [side]
        side=8
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        recruit=Shaxthal Drone,Shaxthal Rayblade,Psy Crawler

        {NO_ECONOMY}
    [/side]

    # Doors
    [side]
        side=9
        team_name=evil
        user_team_name= _ "team_name^Uria"
        {CHAOS_FLAG}
        controller=null

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    # Access guards
    [side]
        side=10
        team_name=evil
        user_team_name= _ "team_name^Uria"
        color=blue
        {CHAOS_FLAG}
        controller=null

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    # Stage boss units
    [side]
        side=11
        team_name=evil
        user_team_name= _ "team_name^Uria"
        color=gold
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    # Other creatures
    [side]
        side=12
        team_name=evil
        user_team_name= _ "team_name^Uria"
        color=black
        {CHAOS_FLAG}

        hidden=yes
        no_leader=yes

        {NO_ECONOMY}
    [/side]

    #
    # SUF for matching player units on map, including Elynia.
    #
#define FINALE_A_SUF_PLAYER_UNITS_ON_MAP
    side=1
    [filter_location][/filter_location]
#enddef

    #
    # SUF for matching player units on map other than Elynia.
    #
#define FINALE_A_SUF_PLAYER_ALLIES_ON_MAP
    {FINALE_A_SUF_PLAYER_UNITS_ON_MAP}
    [not]
        id=Elynia
    [/not]
#enddef

    #
    # SUF for selecting a player unit to speak who isn't Elynia
    # whenever possible, or Elynia in the worst case.
    #
#define FINALE_A_SUF_PLAYER_UNIT_OR_ELYNIA
    side=1
    [not]
        id=Elynia
    [/not]
    [or]
        id=Elynia
    [/or]
#enddef

    # This sound source is shared between floor 1 and 2 and never removed,
    # hence no custom id.
    {CAVE_NOISE_SOUND_SOURCE}

    [event]
        name=prestart

        # BEGIN: finale sequence configuration

        #
        # Make it possible to skip previous scenarios, but it shouldn't
        # be possible to come back here from another finale scenario.
        #

        # wmlindent: start ignoring
        {BUG_ON ({VARIABLE_NUMERICAL_NOT_EQUALS finale_status.length 0})
                ("E3S7A.1 must be started from a non-finale scenario")}
        # wmlindent: stop ignoring

        {VARIABLE finale_status.in_finale yes}

        #
        # Store all regular units for E3S7B.
        #

        [store_unit]
            [filter]
                side=1
                [not]
                    id=Elynia
                [/not]
            [/filter]
            variable=finale_status.side_1_units
            kill=yes
        [/store_unit]

        [store_gold]
            side=1
            variable=finale_status.side_1_gold
        [/store_gold]

        # END: finale sequence configuration

        [store_unit]
            [filter]
                id=Elynia
            [/filter]
            variable=elynia_glamour_store
            kill=yes
        [/store_unit]

        [unit]
            side=1
            canrecruit=yes
            id=Vyrelyam
            name= _ "Vyrelyam"
            type=Demon Messenger
            x,y=$elynia_glamour_store.x,$elynia_glamour_store.y
            facing=se
            [modifications]
                # Just a hint for attentive players.
                {TRAIT_RESILIENT}
                {TRAIT_DEXTROUS}
            [/modifications]
        [/unit]

        # Reset or change player information

        [modify_side]
            side=1
            gold=100
            team_name=evil
            user_team_name= _ "team_name^Uria"
            recruit=Demon,Saurian Augur,Saurian Skirmisher,Troll Whelp
        [/modify_side]

        # Configure the first segment now.

        {SWITCH_FLOOR 1}

        {CLEAR_CAVE_SHROUD (
            x=0-14,10-18
            y= 0-8, 9-12
            [or]
                x,y=21,13
                radius=6
                [filter_radius]
                    [not]
                        terrain=X*,*^X*,*^Z*,*^P*
                    [/not]
                [/filter_radius]
            [/or]
        )}

        [teleport]
            [filter]
                id=Vyrelyam
            [/filter]
            x,y=8,5
        [/teleport]

        #
        # The bodyguards.
        #

        {NAMED_UNIT 1 "Troll" 21 13 Krul  ( _ "Krul") (
            facing=se
            overlays="misc/loyal-icon.png"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        )}

        {NAMED_UNIT 1 "Troll Rocklobber" 19 14 Krago ( _ "Krago") (
            facing=se
            overlays="misc/loyal-icon.png"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_FEARLESS}
                {TRAIT_RESILIENT}
            [/modifications]
        )}

        {NAMED_UNIT 1 "Saurian Soothsayer" 20 13 Sesserin ( _ "Sesserin") (
            facing=se
            overlays="misc/loyal-icon.png"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        )}

        {NAMED_UNIT 1 "Demon Zephyr" 18 13 Grythal ( _ "Grythal") (
            facing=se
            gender=male
            overlays="misc/loyal-icon.png"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        )}

        {NAMED_UNIT 1 "Demon Grunt"  20 12 Nymeren ( _ "Nymeren") (
            facing=se
            gender=female
            overlays="misc/loyal-icon.png"
            [modifications]
                {TRAIT_LOYAL}
                {TRAIT_DEXTROUS}
                {TRAIT_STRONG}
            [/modifications]
        )}

        [hide_unit]
            side=1
            [not]
                id=Vyrelyam
            [/not]
        [/hide_unit]

        {DISALLOW_END_TURN}
    [/event]

    [event]
        name=restore elynia
        first_time_only=yes
        [filter_condition]
            [not]
                [have_unit]
                    side=1
                    id=Elynia
                [/have_unit]
            [/not]
        [/filter_condition]

        [store_unit]
            [filter]
                id=Vyrelyam
            [/filter]
            kill=yes
            variable=vyrelyam_store
        [/store_unit]

        [set_variables]
            name=elynia_glamour_store
            mode=merge
            [value]
                x,y=$vyrelyam_store.x,$vyrelyam_store.y
                facing=$vyrelyam_store.facing
            [/value]
        [/set_variables]

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

        {CLEAR_VARIABLE elynia_glamour_store,vyrelyam_store}
    [/event]

    #
    # Safeguard in case we skip this level while Elynia is using Glamour.
    # We need to restore her to her regular form.
    #

    [event]
        name=victory
        [filter_condition]
            [have_unit]
                side=1
                id=Vyrelyam
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=restore elynia
        [/fire_event]
    [/event]

    #
    # Preserve turn number for the next scenario.
    #

    [event]
        name=victory
        {VARIABLE dark_fire_turn_number $turn_number}
    [/event]

    #
    # During some events the player is given an advantage.
    #

    [event]
        name=prestart
        {VARIABLE finale_a_player_cth no}
    [/event]

    {FORCE_CHANCE_TO_HIT (side=1) () 100 ({VARIABLE_BOOLEAN_EQUALS finale_a_player_cth yes})}

    [event]
        name=victory
        {CLEAR_VARIABLE finale_a_player_cth}
    [/event]

#define FINALE_A_GUARDIAN _SIDE _TYPE _X _Y
    {GENERIC_UNIT ({_SIDE}) ({_TYPE}) ({_X}) ({_Y})} {GUARDIAN} {NO_UPKEEP_NO_OVERLAY}
#enddef

    # NOTE: currently doubles as SUF.
#define FINALE_A_TRANSPORTER_ROOM_SLF
    x=70,68-72,69-71
    y=50,   51,   52
#enddef

    ############################################################################
    #                                                                          #
    #                                FIRST FLOOR                               #
    #                                                                          #
    ############################################################################

    [event]
        name=setup floor 1
        #first_time_only=no

        # Dummy access guards; not actually playing since their
        # side isn't AI-controlled.

        {FINALE_A_GUARDIAN 10 (Doom Guard)  9  4} {FACING sw}
        {FINALE_A_GUARDIAN 10 (Doom Guard)  9  2} {FACING sw}
        {FINALE_A_GUARDIAN 10 (Doom Guard)  5  6} {FACING nw}
        {FINALE_A_GUARDIAN 10 (Doom Guard)  3  7} {FACING nw}
        {FINALE_A_GUARDIAN 10 (Doom Guard)  1  8} {FACING nw}

        {FINALE_A_GUARDIAN 10 (Doom Guard) 11  6} {FACING sw}

        {NAMED_LOYAL_UNIT 4 "Demon Grunt" 25  8 Ana ( _ "Ana")} {FACING se} {GENDER female} {GUARDIAN}

        {NAMED_LOYAL_UNIT 4 "Demon Spelldancer"  22  2 Litharen ( _ "Litharen")} {FACING sw} {GUARDIAN}

        #{FINALE_A_GUARDIAN 4 (Demon Warrior) 25  8} {FACING se}
        #{FINALE_A_GUARDIAN 4 (Demon Zephyr)  22  2} {FACING sw}

        [store_starting_location]
            side=4
        [/store_starting_location]

        [unit]
            side=4
            canrecruit=yes
            x,y=$location.x,$location.y
            type=Hell Guardian
            id=Romeldan
            name= _ "Romeldan"
            facing=s
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [store_starting_location]
            side=5
        [/store_starting_location]

        [unit]
            side=5
            canrecruit=yes
            x,y=$location.x,$location.y
            type=Chaos Razerman
            id=Captain Verathorn
            name= _ "Captain Verathorn"
            facing=sw
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        [unit]
            side=6
            x,y=20,10
            facing=sw
            type=Chaos Hound
            upkeep=loyal
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            side=6
            x,y=25,15
            facing=nw
            type=Demon Grunt
            id=Teremor
            name= _ "Teremor"
            gender=male
            upkeep=loyal
            [modifications]
                {TRAIT_SLOW}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [unit]
            side=6
            x,y=23,16
            facing=nw
            type=Demon Grunt
            id=Ryghel
            name= _ "Ryghel"
            gender=male
            upkeep=loyal
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_DEXTROUS}
            [/modifications]
        [/unit]

        [unit]
            side=6
            x,y=22,11
            facing=sw
            type=Chaos Invader
            id=Uron
            name= _ "Uron"
            gender=male
            upkeep=loyal
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [unit]
            side=6
            x,y=18,15
            facing=ne
            type=Chaos Invader
            id=Therlan
            name= _ "Therlan"
            gender=male
            upkeep=loyal
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        {FINALE_A_GUARDIAN 6 (Chaos Magus) 11 19} {FACING ne}

        {FINALE_A_GUARDIAN 6 (Chaos Bowman) 25 13} {FACING sw}
        {FINALE_A_GUARDIAN 6 (Chaos Gunner) 15 13} {FACING se}

        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 26 51}
        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 29 56}
        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 31 55}

        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 63 44}

        {FINALE_A_GUARDIAN 8 (Shaxthal Enforcer Drone) 68 50} {FACING nw}
        {PALETTE shaxthal_drone_base shaxthal_drone_purple}

        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 42 33}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 38 36}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 46 31}

        {FINALE_A_GUARDIAN 8 (Shaxthal Sentry Drone) 51 47} {FACING sw}
        {FINALE_A_GUARDIAN 8 (Shaxthal Rayblade) 47 49} {FACING se}

        {FINALE_A_GUARDIAN 8 (Shaxthal Sentry Drone) 52 22} {FACING nw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Sentry Drone) 54 21} {FACING se}

        {FINALE_A_GUARDIAN 7 (Chaos Gunner) 37 24} {FACING nw}
        {FINALE_A_GUARDIAN 7 (Chaos Gunner) 42 21} {FACING sw}

        {FINALE_A_GUARDIAN 7 (Automaton) 46 16} {FACING sw}
        {FINALE_A_GUARDIAN 7 (Automaton) 48 18} {FACING nw}

#ifdef HARD
        {FINALE_A_GUARDIAN 7 (Hellhound) 42 27} {FACING ne}
#endif

        {FINALE_A_GUARDIAN 7 (Chaos Magus) 43 29} {FACING nw}

#ifndef EASY
        {FINALE_A_GUARDIAN 7 (Iron Golem) 45 33} {FACING nw}
#endif

        {FINALE_A_GUARDIAN 7 (Chaos Invader) 32 18} {FACING nw}
        {FINALE_A_GUARDIAN 7 (Chaos Invader) 30 19} {FACING nw}

        {FINALE_A_GUARDIAN 7 (Chaos Crossbowman) 41 30} {FACING ne}

        {FINALE_A_GUARDIAN 7 (Automaton) 41 40} {FACING se}
        {FINALE_A_GUARDIAN 7 (Automaton) 41 42} {FACING ne}

        {FINALE_A_GUARDIAN 7 (Chaos Invader) 31 37} {FACING se}
        {FINALE_A_GUARDIAN 7 (Chaos Invader) 33 36} {FACING se}
        {FINALE_A_GUARDIAN 7 (Chaos Invader) 35 37} {FACING se}

#ifndef EASY
        {FINALE_A_GUARDIAN 7 (Iron Golem) 30 39} {FACING ne}
#endif

        {NAMED_LOYAL_UNIT 7 "Demon Shapeshifter" 18 44 Loru ( _ "Loru")} {FACING se} {GENDER male} {GUARDIAN}
        {NAMED_LOYAL_UNIT 7 "Demon Shapeshifter" 19 48 Urapur ( _ "Urapur")} {FACING ne} {GENDER male} {GUARDIAN}

        {FINALE_A_GUARDIAN 7 (Demon) 24 47} {FACING nw} {GENDER male}

#ifndef EASY
        {NAMED_LOYAL_UNIT 7 "Demon Shapeshifter" 40 55 Alia ( _ "Alia")} {FACING ne} {GENDER female} {GUARDIAN} {VARIATION gendered}
        {NAMED_LOYAL_UNIT 7 "Demon Shapeshifter" 42 56 Rothelan ( _ "Rothelan")} {FACING nw} {GENDER male} {GUARDIAN} {VARIATION gendered}
#else
        {FINALE_A_GUARDIAN 7 (Demon) 40 55} {FACING sw} {GENDER male}
        {FINALE_A_GUARDIAN 7 (Demon) 42 56} {FACING nw} {GENDER male}
#endif

        {FINALE_A_GUARDIAN 7 (Chaos Magus) 57 42} {FACING sw}

#ifndef EASY
        {FINALE_A_GUARDIAN 7 (Demonic Hound) 63 48} {FACING n}
#endif

        {FINALE_A_GUARDIAN 7 (Chaos Invoker) 41 35} {FACING ne}
        {FINALE_A_GUARDIAN 7 (Chaos Headhunter) 49 31} {FACING sw}

        {FINALE_A_GUARDIAN 7 (Chaos Marauder) 45 40} {FACING n}

        {FINALE_A_GUARDIAN 7 (Chaos Headhunter) 22 44} {FACING ne}

        {FINALE_A_GUARDIAN 7 (Doom Guard) 63 45} {FACING nw}

#ifndef EASY
        {FINALE_A_GUARDIAN 7 (Chaos Invader) 54 42} {FACING sw}
        {FINALE_A_GUARDIAN 7 (Chaos Invader) 56 43} {FACING sw}
#endif

        {FINALE_A_GUARDIAN 12 (Giant Rat) 39  9} {FACING nw}
        {FINALE_A_GUARDIAN 12 (Giant Rat) 33 11} {FACING n}
        {FINALE_A_GUARDIAN 12 (Giant Rat) 26  1} {FACING se}

        {FINALE_A_GUARDIAN 12 (Blood Bat) 54 19} {FACING sw}

        {CLEAR_VARIABLE location}

        {PLACE_IMAGE ("items/bones.png") 54 19}

        {PLACE_IMAGE ("items/bones.png~FL(horiz)") 52 46}

        {PLACE_IMAGE ("items/barrel.png")  8 23}
        {PLACE_IMAGE ("items/barrel.png") 11 24}

        {PLACE_IMAGE ("items/barrel.png") 17 22}
        {PLACE_IMAGE ("items/barrel.png") 18 20}
        {PLACE_IMAGE ("items/barrel.png") 17 20}

        {PLACE_IMAGE ("items/barrel.png")  8 15}

        {PLACE_IMAGE ("items/box.png")    39  8}
        {PLACE_IMAGE ("items/box.png")    38  9}

        {PLACE_IMAGE ("items/box.png")    34  9}

        {PLACE_IMAGE ("items/box.png")    26  1}

        {PLACE_IMAGE ("items/box.png")    13 28}
        {PLACE_IMAGE ("items/box.png")    14 26}
        {PLACE_IMAGE ("items/box.png")    15 29}

        {PLACE_IMAGE ("items/box.png")     7 20}

        {PLACE_IMAGE ("items/box.png")    14 18}

        {PLACE_IMAGE ("items/burial.png")  4  4}
        {PLACE_IMAGE ("items/burial.png")  4  2}
        {PLACE_IMAGE ("items/burial.png")  7  4}
        {PLACE_IMAGE ("items/burial.png")  1  3}
        {PLACE_IMAGE ("items/burial.png")  1  1}

        {PLACE_IMAGE ("items/bonestack.png") 62 43}

        {PLACE_IMAGE ("items/gohere.png") 70 51}

        {PLACE_IMAGE ("items/gold-coins-medium.png") 48 29}
        {PLACE_IMAGE ("items/gold-coins-small.png") 49 30}

        {PLACE_IMAGE ("items/chest-plain-open.png") 48 30}

        {PLACE_IMAGE ("items/gold-coins-small.png") 42 35}

        {PLACE_IMAGE ("items/potion-blue.png") 41 36}

        {PLACE_IMAGE ("items/potion-red.png")  8 17}
        {PLACE_IMAGE ("items/potion-red.png") 33 10}
        {PLACE_IMAGE ("items/potion-red.png") 18 21}
        {PLACE_IMAGE ("items/potion-red.png") 47 30}
        {PLACE_IMAGE ("items/potion-poison.png") 16 21}

        {PLACE_IMAGE ("scenery/trash.png") 41 34}
        {PLACE_IMAGE ("scenery/trash.png") 22 43}
        {PLACE_IMAGE ("scenery/trash.png") 31 17}

        {PLACE_IMAGE ("items/axe.png")  7 16}

        {ITEM_CRYSTAL_GLYPH_MESSAGE 63 35}

        {ITEM_CRYSTAL_GLYPH_GATE 21  3}

        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 16 13}
        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 21 11}
        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 26 13}
        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 21 16}

        {PLACE_IMAGE scenery/banner-uria-standing.png 26 54}

        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 66 48}
        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 65 48}
        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 67 49}

        {PLACE_IMAGE scenery/banner-uria-standing.png 30  5}

        # NOTE: the following objects must be removed manually on setup floor 2

        {SET_LABEL 61 44 _"Transport Access"}

        {SET_LABEL 14 15 _"Storerooms"}

        {SET_LABEL 25  9 _"Guard Post"}

        {SET_LABEL 17 12 _"Entrance"}

        [time_area]
            id=outdoors
            x=0-9,0-7,0-5,0-3,0-1
            y=0-4,  5,  6,  7,  8
            {LONGDARK2}
        [/time_area]

        {CAVE_WATER_SOUND_SOURCE 51 20}
        [+sound_source]
            id=floor_1_water_sound_source_1
        [/sound_source]

        {CAVE_WATER_SOUND_SOURCE 51 48}
        [+sound_source]
            id=floor_1_water_sound_source_2
        [/sound_source]
    [/event]

#define FINALE_A_ACTIVATE_SIDE _SIDE
    [modify_side]
        side={_SIDE}
        {GOLD 80 90 100}
        {INCOME 2 3 4}
        hidden=no
    [/modify_side]
#enddef

#define FINALE_A_RECRUITMENT_MECHANICS_NOTE
    {OBJECTIVE_NOTE ( _ "All recruits are free of cost and require zero upkeep")}
    {OBJECTIVE_NOTE ( _ "You can only have up to eight allies on the map simultaneously")}
#enddef

    #
    # Initial events.
    #

    [event]
        name=start

        {LOCK_VIEW}

        {MOVE_UNIT id=Vyrelyam 12,12,21 7,9,14}

        [unhide_unit]
            side=1
        [/unhide_unit]

        [redraw]
            side=1 # Refresh shroud
        [/redraw]

        {MOVE_UNIT id=Teremor 24 14}

        [message]
            speaker=Teremor
            message= _ "What brings you here?"
        [/message]

        [message]
            speaker=Vyrelyam
            # po: "The Fire of Uria" refers to Elyssa.
            message= _ "A message from the Demon Lord of the Storms, for the Fire of Uria."
        [/message]

        [message]
            speaker=Ryghel
            message= _ "The captain said we are not supposed to let anyone in for now! You’ll have to wait until he comes back from his inspection."
        [/message]

        [message]
            speaker=Vyrelyam
            message= _ "Time is of the essence. Do you really wish to anger your masters by making them wait more than is absolutely necessary?"
        [/message]

        [message]
            speaker=Teremor
            message= _ "Look, wench, our masters can go to hell for all I care. You can either deliver your damn message to the captain and convince him to let you pass, or just forget about it. Unless you would prefer to entertain us for a while in exchange for letting you pass, heh heh."
        [/message]

        [message]
            speaker=Vyrelyam
            message= _ "I want to speak to your captain. Where is he?"
        [/message]

        {MOVE_UNIT id=Teremor 25 15}

        {FACE_DIRECTION id=Teremor nw}

        [message]
            speaker=Ryghel
            message= _ "He’s probably in the storerooms right now. Go to your right and turn at the last passage down the corridor."
        [/message]

        #
        # Prevent side 1 units from wandering outside.
        #

        [terrain]
            terrain=Xv^Xo
            layer=overlay
            x=15,16,17
            y=12,11,11
        [/terrain]

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Talk to the guard captain")}

            {UNLIMITED_PLAYER_MOVES_NOTE}
            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        {UNLOCK_VIEW}
    [/event]

    {UNLIMITED_PLAYER_MOVES}

    [event]
        name=moveto
        [filter]
            id=Vyrelyam
            x=11-21,12,18
            y=26-30,25,25
        [/filter]

        {CLEAR_CAVE_SHROUD (
            x,y=18,27
            radius=7
        )}

        [redraw]
            side=1
        [/redraw]

        [message]
            speaker=Captain Verathorn
            message= _ "Who goes there?"
        [/message]

        [if]
            {VARIABLE_NUMERICAL_LESS_THAN x1 15}
            [then]
                {MOVE_UNIT id=Vyrelyam 15 28}
            [/then]
        [/if]

        [message]
            speaker=Vyrelyam
            message= _ "Sir, I have been sent by the Demon Lord of the Storms to bring a message to—"
        [/message]

        [message]
            speaker=Captain Verathorn
            message= _ "Is it anything you aren’t allowed to pass on to me?"
        [/message]

        [message]
            speaker=Vyrelyam
            message= _ "... Yes, quite so. I would prefer to talk to the Fire in pe—" # wmllint: no spellcheck
        [/message]

        [message]
            speaker=Captain Verathorn
            message= _ "The Fire does not want to see anyone right now in her chamber, or anywhere else for that matter. She said so herself: “I don’t want anyone coming into this fortress tonight”. Maybe those deaf sluggards at the main gate need a lesson or two...?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Captain Verathorn
            message= _ "What’s your name, girl?"
        [/message]

        [message]
            speaker=Vyrelyam
            message= _ "Vyrelyam, sir."
        [/message]

        [message]
            speaker=Captain Verathorn
            message= _ "I hadn’t seen your face around before. But there’s something oddly familiar about it..."
        [/message]

        [message]
            speaker=Vyrelyam
            message= _ "Is that so? ... Perhaps you may also recall torturing an elf or two..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Captain Verathorn
            message= _ "YOU—"
        [/message]

        {THUNDER ()}

        [kill]
            id=Captain Verathorn
            animate=yes
        [/kill]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Vyrelyam
            message= _ "Well... that didn’t work as planned. We must find a way to open that gate by ourselves."
        [/message]

        {NAMED_LOYAL_UNIT 4 "Chaos Magus" 28 13 Melor ( _ "Melor")} {FACING sw} {GUARDIAN}
        {NAMED_LOYAL_UNIT 4 "Chaos Bowman" 24 11 Irumia ( _ "Irumia")} {FACING se} {GUARDIAN}
        {NAMED_LOYAL_UNIT 4 "Blood Imp" 23 13 Harakas ( _ "Harakas")} {FACING sw} {GUARDIAN}

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Move your leader back to the entrance chamber")}

            {UNLIMITED_PLAYER_MOVES_NOTE}
            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        [event]
            name=moveto
            [filter]
                id=Vyrelyam
                x=14-28,17-26
                y= 8-14,15-16
            [/filter]

            [fire_event]
                name=reveal elynia
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=reveal elynia

        {LOCK_VIEW}

        [message]
            speaker=Irumia
            message= _ "There she is!"
        [/message]

        [message]
            speaker=Melor
            message= _ "Your illusions can’t deceive me, faerie witch!"
        [/message]

        [scroll_to_unit]
            id=Vyrelyam
        [/scroll_to_unit]

        {THUNDER (
            [fire_event]
                name=restore elynia
            [/fire_event]
        )}

        {REPLACE_SCENARIO_MUSIC ("the_city_falls.ogg")}

        {PLAY_LEVELIN_ANIM id=Elynia}

        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        [modify_side]
            side=1
            team_name=good
            user_team_name= _ "team_name^Elynia"
        [/modify_side]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Teremor
            message= _ "Seize her, quickly!"
        [/message]

        [message]
            speaker=Elynia
            message= _ "There goes our infiltration plan. To arms!"
        [/message]

        #
        # Everyone's locked in now.
        #

        [terrain]
            terrain=Xv^Zz/
            layer=overlay
            x=15,16,17
            y=12,11,11
        [/terrain]

        [redraw][/redraw]

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

        [delay]
            time=250
        [/delay]

        {REMOVE_EVENT_BARRIER ("*^Zz\,*^Zz/,*^Zz|") 24 10}

        {FINALE_A_ACTIVATE_SIDE 4}

        {DISABLE_UNLIMITED_PLAYER_MOVES}

        {ALLOW_END_TURN}

        [modify_turns]
            {QUANTITY add 80 88 86}
        [/modify_turns]

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Find a way to open the main access gate")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {TURNS_RUN_OUT}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        {UNLOCK_VIEW}

        #
        # Make player hits always land for the first two turns.
        #

        {VARIABLE finale_a_player_cth yes}

        [event]
            delayed_variable_substitution=no
            name="turn $($turn_number + 2)"

            {VARIABLE finale_a_player_cth no}
        [/event]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=21,3
        [/filter]
        {ON_FLOOR 1}

        {GATE_GLYPH_ACTIONS 25 16}

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Proceed through the main access gate")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {TURNS_RUN_OUT}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}
    [/event]

#define FINALE_A_ELYNIA_THOUGHTS _MESSAGE
    [message]
        speaker=narrator
        caption= _ "Elynia"
        image= # wmllint: ignore
        message="<i>"+{_MESSAGE}+"</i>" # wmllint: ignore
    [/message]
#enddef

    [event]
        name=moveto
        [filter]
            id=Elynia
            x=24-46,26
            y=16-28,15
        [/filter]
        {ON_FLOOR 1}

        {REPLACE_SCENARIO_MUSIC "siege_of_laurelmor.ogg"}
        {APPEND_MUSIC           "knalgan_theme.ogg"}
        {APPEND_MUSIC           "suspense.ogg"}
        {APPEND_MUSIC           "the_city_falls.ogg"}

        {FINALE_A_ELYNIA_THOUGHTS ( _ "And thus I descend into the darkness of Uria’s key stronghold on Irdya...")}

        {FINALE_A_ELYNIA_THOUGHTS ( _ "Ergea’s words were clear: we do not have a chance to win this war and purge the corrupted goddess’ influence from this earth; not without the power hidden beneath Kalari.")}

        {FINALE_A_ELYNIA_THOUGHTS ( _ "I do not intend to stand watching while she turns our ruined world into breeding grounds for her invasion army. Neither could I bear to live knowing that it is in her plans to tear another world apart and threaten our very reality to quench her dreadful thirst for power. I have to do something to prevent that.")}

        {FINALE_A_ELYNIA_THOUGHTS ( _ "No matter the cost.")}
    [/event]

    #
    # Shaxthal Stormblade miniboss event.
    #

    [event]
        name=moveto
        [filter]
            side=1
            x=18-29
            y=42-49
        [/filter]
        {ON_FLOOR 1}

        {LOCK_VIEW}

        [unit]
            side=11
            id=Espreon
            # NOTE: this unit has no visible in-game name. This is deliberate.
            type=Shaxthal Stormblade
            level=4
            x,y=28,53
            facing=ne
            #{IS_BOSS}
            max_hitpoints=79
            generate_name=no
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_ARMORED}
                {TEAM_COLOR_OVERRIDE () teal}
            [/modifications]
        [/unit]

        {CLEAR_CAVE_SHROUD (
            x,y=25,48
            radius=10
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=28,53
        [/scroll_to]

        {HIGHLIGHT_GOAL x,y=28,53}

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

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [filter_location]
                [filter_adjacent_location]
                    terrain=*^Xo
                [/filter_adjacent_location]
            [/filter_location]
        [/filter]
        [filter_condition]
            [have_unit]
                id=Elynia
            [/have_unit]
        [/filter_condition]
        {ON_FLOOR 1}

        [allow_undo][/allow_undo]

        [if]
            [have_unit]
                id=Elynia
                x,y=$x1,$y1
            [/have_unit]
            [then]
                [message]
                    speaker=unit
                    message= _ "elynia^This is not the right corridor. We must find a way leading to the transport room."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "elynia^That is not the right corridor. We must find a way leading to the transport room."
                [/message]
            [/else]
        [/if]
    [/event]

    #
    # Gold coins.
    #

    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            x=48,49,42
            y=29,30,35
        [/filter]
        {ON_FLOOR 1}

        [allow_undo][/allow_undo]

        [message]
            speaker=unit
            message= _ "Just a bunch of gold coins. Too bad that they are rather weighty and we have no use for them at this time."
        [/message]
    [/event]

    #
    # Empty chest.
    #

    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            x,y=48,30
        [/filter]
        {ON_FLOOR 1}

        [allow_undo][/allow_undo]

        [message]
            speaker=unit
            message= _ "There’s nothing in this chest."
        [/message]
    [/event]

    #
    # Potion of Life.
    #

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=41,36
            [not]
                id=Elynia
            [/not]
        [/filter]
        [filter_condition]
            [not]
                [have_unit]
                    id=Elynia
                    [filter_wml]
                        [variables]
                            have_full_heal_potion=yes
                        [/variables]
                    [/filter_wml]
                [/have_unit]
            [/not]
        [/filter_condition]
        {ON_FLOOR 1}

        [allow_undo][/allow_undo]

        [message]
            speaker=unit
            message= _ "This potion flask seems important. Let the Lady of Light come to examine it."
        [/message]
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=41,36
            id=Elynia
            [not]
                [filter_wml]
                    [variables]
                        have_full_heal_potion=yes
                    [/variables]
                [/filter_wml]
            [/not]
        [/filter]
        {ON_FLOOR 1}

        {VARIABLE unit.variables.have_full_heal_potion yes}

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

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

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

        [delay]
            time=250
        [/delay]

        [heal_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            amount="full"
            animate=yes
            restore_statuses=yes
        [/heal_unit]

        [sound]
            name=heal.wav
        [/sound]

        [object]
            id=potion_of_life
            [filter]
                x,y=$x1,$y1
            [/filter]
            image=icons/potion-cyan-4.png
            name= _ "Potion of Life"
            description= _ "This potion grants the Regenerates ability, allowing the unit to heal itself 8 HP per turn or remove the poison effect."
            [effect]
                apply_to=new_ability
                [abilities]
                    {ABILITY_REGENERATES}
                [/abilities]
            [/effect]
        [/object]

        [message]
            speaker=Elynia
            message= _ "Hm, this might prove useful later."
        [/message]
    [/event]

    #
    # Potion of yummy.
    #

    [event]
        name=potion of yummy
        first_time_only=no

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

        [heal_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            animate=no
            amount=1
        [/heal_unit]

        [transient_message]
            caption= _ "Potion of Magnificent Taste"
            image=icons/potion_red_medium.png
            sound=potion.ogg
            message= _ "The potion’s stupendous and reinvigorating taste heals the unit by 1 HP."
        [/transient_message]
    [/event]

#define FINALE_A_POTION_OF_YUMMY _FLOOR _X _Y
    [event]
        name=moveto
        [filter]
            side=1
            x={_X}
            y={_Y}
        [/filter]
        {ON_FLOOR {_FLOOR} }

        [fire_event]
            name=potion of yummy
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]
#enddef

    {FINALE_A_POTION_OF_YUMMY 1 18 21}

    {FINALE_A_POTION_OF_YUMMY 1  8 17}

    {FINALE_A_POTION_OF_YUMMY 1 33 10}

    {FINALE_A_POTION_OF_YUMMY 1 47 30}

    #
    # Excalibur
    #

    {PLACE_IMAGE items/sword.png 40 34}

    [event]
        name=moveto
        [filter]
            side=1
            x,y=40,34
        [/filter]
        {ON_FLOOR 1}

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

        [transient_message]
            caption= _ "Legendary Sword"
            image=attacks/sword-orcish.png
            message= _ "This sword, forgotten by time, once belonged to a legendary hero who presumably died in a glorious and dignified fashion like real heroes are wont to do. Unfortunately, since then it has rusted beyond use, and as the unit picks it up it snaps in half. The sword is now only marginally better than a small rock in combat — not that Elynia has any units that are trained in sword-fighting anyway."
        [/transient_message]
    [/event]

    #
    # Pickup-able items implementation code.
    #
    # This is somewhat reminiscent of the PICKUPPABLE_ITEM macro in mainline,
    # but not identical. The macro in question is simply incompatible with
    # segmented scenarios.
    #

#define FINALE_A_ITEM_EVENT _ID _FLOOR _X _Y _ELIGIBLE_SUF _ICON _ELIGIBLE_MESSAGE _INELIGIBLE_MESSAGE _OBJECT
    [event]
        name=prestart
        {VARIABLE ("picked_up_"+{_ID}) no}
    [/event]

    [event]
        name=victory
        {CLEAR_VARIABLE ("picked_up_"+{_ID})}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x={_X}
            y={_Y}
        [/filter]
        [filter_condition]
            {VARIABLE_BOOLEAN_EQUALS ("picked_up_"+{_ID}) no}
        [/filter_condition]
        {ON_FLOOR {_FLOOR} }

        [if]
            [have_unit]
                x,y=$x1,$y1
                {_ELIGIBLE_SUF}
            [/have_unit]
            [then]
                [message]
                    speaker=narrator
                    image={_ICON}
                    message={_ELIGIBLE_MESSAGE}+"

"+_"Should this unit take it?"
                    [option]
                        label= _ "Take it."
                        [command]
                            {_OBJECT}

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

                            {VARIABLE ("picked_up_"+{_ID}) yes}
                        [/command]
                    [/option]
                    [option]
                        label= _ "Leave it."
                        [command]
                            [allow_undo][/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]
            [else]
                [message]
                    speaker=narrator
                    image={_ICON}
                    message={_INELIGIBLE_MESSAGE}
                [/message]

                [allow_undo][/allow_undo]
            [/else]
        [/if]
    [/event]
#enddef

    #
    # Axe.
    #

    {FINALE_A_ITEM_EVENT throwing_axe
    1  7 16
    (type="Demon Grunt,Demon Warrior")
    ("attacks/axe-crude.png")
    ( _ "This small axe is not particularly suitable for combat at close quarters, but it may come in handy as a throwable weapon.")
    ( _ "This small axe could be useful in the hands of a trained man or demon fighter.")
    (
        [object]
            id=throwing_axe
            image="attacks/axe-crude.png"
            name= _ "Small Axe"
            description= _ "The unit wielding this weapon may use it for long range combat to inflict some considerable blade damage."

            duration=forever
            [filter]
                x,y=$x1,$y1
            [/filter]

            [effect]
                apply_to="new_attack"
                name=throwing axe
                description= _ "throwing axe"
                icon="attacks/axe-crude.png"
                type=blade
                range=ranged
                damage=10
                number=2
            [/effect]

            [effect]
                apply_to="new_animation"
                [attack_anim]
                    [filter_attack]
                        name=throwing axe
                    [/filter_attack]
                    start_time=-450
                    {MISSILE_FRAME_HATCHET}
                    [frame]
                        duration=400
                    [/frame]
                    [if]
                        hits=yes
                        [frame]
                            duration=100
                            sound=hatchet.wav
                        [/frame]
                    [/if]
                    [else]
                        hits=no
                        [frame]
                            duration=100
                            sound=hatchet-miss.wav
                        [/frame]
                    [/else]
                    [frame]
                        duration=100
                    [/frame]
                [/attack_anim]
            [/effect]
        [/object]
    )}

    #
    # Potion of poison.
    #

    {FINALE_A_ITEM_EVENT poison_jar
    1 16 21
    (type="Demon,Demon Zephyr,Demon Grunt,Demon Warrior,Saurian Augur,Saurian Oracle,Saurian Soothsayer,Saurian Skirmisher,Saurian Ambusher,Saurian Flanker")
    ("icons/potion-green-1.png")
    ( _ "The poison in the jar could be poured on claws or weapons and used against living opponents in melee combat to increase attack efficiency through its devastating effects on their health.")
    ( _ "This large jar contains poison that could be poured on claws or weapons and used against living opponents by a trained melee fighter or a staff-wielding magic user.")
    (
        [object]
            id=poison_jar
            image="icons/potion-green-1.png"
            name= _ "Poison Jar"
            description= _ "The unit employing this foul-smelling death catalyst can poison living opponents by dealing damage with its melee attacks."

            duration=forever
            [filter]
                x,y=$x1,$y1
            [/filter]

            [effect]
                apply_to="attack"
                range=melee
                [set_specials]
                    mode=append
                    {WEAPON_SPECIAL_POISON}
                [/set_specials]
            [/effect]
        [/object]
    )}

    #
    # Message glyphs.
    #

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=63,35
        [/filter]
        {ON_FLOOR 1}

        [allow_undo][/allow_undo]

        {MSG_GLYPH ( _ "On the day of the Longest Night, the New Guardian of Darkness shall rise from beyond to claim her rightful place amongst the Guardians of the Second Cycle.")}

        {MSG_GLYPH ( _ "On that day, the New Guardian of Life shall rise again, more powerful than before.")}

        {MSG_GLYPH ( _ "That is the day we have lived for.")}

        {MSG_GLYPH ( _ "The day that shall bring upon our doomed existence the promise of a new beginning.")}
    [/event]

    ############################################################################
    #                                                                          #
    #                                  ELEVATOR                                #
    #                                                                          #
    ############################################################################

    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            {FINALE_A_TRANSPORTER_ROOM_SLF}
        [/filter]
        [filter_condition]
            [have_unit]
                side=1
                [filter_location]
                    [not]
                        {FINALE_A_TRANSPORTER_ROOM_SLF}
                    [/not]
                [/filter_location]
            [/have_unit]
        [/filter_condition]
        {ON_FLOOR 1}

        [message]
            speaker=Elynia
            message= _ "We must all enter the transport room together — nobody should be left behind."
        [/message]

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Gather all your on-map units in the transport room")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {TURNS_RUN_OUT}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        #
        # NOTE: if the player's only remaining unit is Elynia, then
        # this event never triggers and she's instantly taken to the
        # next segment by the next event handler. Hence there's no
        # need to clarify the victory objectives above.
        #
    [/event]

    [event]
        name=moveto
        first_time_only=yes
        [filter]
            side=1
            {FINALE_A_TRANSPORTER_ROOM_SLF}
        [/filter]
        [filter_condition]
            [not]
                [have_unit]
                    side=1
                    [filter_location]
                        [not]
                            {FINALE_A_TRANSPORTER_ROOM_SLF}
                        [/not]
                    [/filter_location]
                [/have_unit]
            [/not]
        [/filter_condition]
        {ON_FLOOR 1}

        # Onwards to floor 2.

        {SWITCH_FLOOR 2}
    [/event]

    ############################################################################
    #                                                                          #
    #                               SECOND FLOOR                               #
    #                                                                          #
    ############################################################################

#define FINALE_A_ELEVATOR_RUMBLE
    #
    # TODO: SFX
    #
    [scroll]
        x=5
        y=0
    [/scroll]
    [scroll]
        x=-10
        y=0
    [/scroll]
    [scroll]
        x=5
        y=5
    [/scroll]
    [scroll]
        x=0
        y=-10
    [/scroll]
    [scroll]
        x=0
        y=5
    [/scroll]
#enddef

    [event]
        name=leave floor 1

        [remove_item]
            x,y=70,51
        [/remove_item]

        [kill]
            x,y=68,50
            animate=yes
            fire_event=yes
        [/kill]

        [terrain]
            x,y=68,50
            terrain=Xu
        [/terrain]

        [place_shroud]
            side=1
            [not]
                {FINALE_A_TRANSPORTER_ROOM_SLF}
            [/not]
        [/place_shroud]

        [redraw]
            side=1
        [/redraw]

        [store_unit]
            [filter]
                {FINALE_A_SUF_PLAYER_UNITS_ON_MAP}
            [/filter]
            variable=player_units_store
            kill=no
        [/store_unit]

        [foreach]
            array=player_units_store
            variable=player_unit
            [do]
                {VARIABLE player_unit.facing       nw}
                {VARIABLE player_unit.attacks_left $player_unit.max_attacks}
                {VARIABLE player_unit.moves        $player_unit.max_moves}

                [unstore_unit]
                    variable=player_unit
                    find_vacant=no
                [/unstore_unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE player_units_store}

        #
        # TODO: SFX
        #

        [delay]
            time=750
        [/delay]

        [message]
            {FINALE_A_SUF_PLAYER_UNIT_OR_ELYNIA}
            message= _ "Now what?"
        [/message]

        [delay]
            time=750
        [/delay]

        # The setup event may extend the delay further
        # while actions are processed.
    [/event]

    [event]
        name=setup floor 2
        #first_time_only=no

        [modify_turns]
            {QUANTITY add 80 88 86}
        [/modify_turns]

        # Post-floor 1 cleanup

        {SET_LABEL 61 44 ""}

        {SET_LABEL 14 15 ""}

        {SET_LABEL 25  9 ""}

        {SET_LABEL 17 12 ""}

        [time_area]
            id=outdoors
            remove=yes
        [/time_area]

        # Setup objects

        [time_area]
            id=hive
            {INDOORS_HIVE}

            #
            # The final area.
            #

            x=20-60,61-68,25-58,30-52,32,41   ,47,53-58,53-57,53-55,53
            y= 0-34, 0-24,35-42,43-47,48,48-50,48,40-42,43   ,44   ,45
            [not]
                x,y=30,47
            [/not]

            #
            # Satellite hive portions near the main
            # council room.
            #

            [or]
                x=55,56,57-58,59-60,61   ,62   ,63,59
                y=56,55,55-59,56-60,58-61,59-61,59,61
            [/or]

            [or]
                x= 0-18,19-30,31-33,21-25,25,26,27
                y=49-68,51-61,54-60,62-64,65,63,64
            [/or]

            [or]
                x=40-46
                y=63-68
            [/or]
        [/time_area]

        [store_starting_location]
            side=7
        [/store_starting_location]

        [unit]
            side=7
            canrecruit=yes
            x,y=$location.x,$location.y
            type=Lumeril Guard
            id=Agathylas
            name= _ "Agathylas"
            facing=s
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        {FINALE_A_ACTIVATE_SIDE 7}

        [capture_village]
            side=7
            x,y=$location.x,$location.y
            radius=4
        [/capture_village]

        # Side 3 and 8 leader and gold set up in later moveto events.

        {CLEAR_VARIABLE location}

        {FINALE_A_GUARDIAN 7 (Doom Guard) 72 43} {FACING s}
        {FINALE_A_GUARDIAN 7 (Doom Guard) 70 39} {FACING se}
        {FINALE_A_GUARDIAN 7 (Doom Guard) 75 41} {FACING sw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 51 62}
        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 56 64}
        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 34 62}
        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 27 48}

        {FINALE_A_GUARDIAN 8 (Shaxthal Turret) 48 42}

        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 41 43}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 42 44}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 43 42}

        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 40 46}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 58 56}

        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 37 26}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 44 29}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 42 30}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 48 29}
        {FINALE_A_GUARDIAN 8 (Verlissh Matrix Flow System) 31 26}

        {FINALE_A_GUARDIAN 8 (Psy Crawler) 42 39} {FACING sw}
        {FINALE_A_GUARDIAN 8 (Psy Crawler) 40 41} {FACING se}
        {FINALE_A_GUARDIAN 8 (Psy Crawler) 49 42} {FACING sw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Rayblade) 46 60} {FACING se}
        {FINALE_A_GUARDIAN 8 (Shaxthal Rayblade) 50 59} {FACING sw}
        {FINALE_A_GUARDIAN 8 (Shaxthal Rayblade) 44 56} {FACING sw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Worm) 35 40} {FACING se} {PALETTE shaxthal_drone_base shaxthal_drone_brown}
        {FINALE_A_GUARDIAN 8 (Shaxthal Worm) 34 41} {FACING se} {PALETTE shaxthal_drone_base shaxthal_drone_purple}
        {FINALE_A_GUARDIAN 8 (Shaxthal Worm) 32 42} {FACING se} {PALETTE shaxthal_drone_base shaxthal_drone_brown}
        {FINALE_A_GUARDIAN 8 (Shaxthal Worm) 39 43} {FACING sw} {PALETTE shaxthal_drone_base shaxthal_drone_cyan}
        {FINALE_A_GUARDIAN 8 (Shaxthal Worm) 41 47} {FACING sw} {PALETTE shaxthal_drone_base shaxthal_drone_brown}
        {FINALE_A_GUARDIAN 8 (Shaxthal Worm) 51 41} {FACING sw} {PALETTE shaxthal_drone_base shaxthal_drone_brown}

        {FINALE_A_GUARDIAN 8 (Shaxthal Sentry Drone) 75 38} {FACING sw}
        {FINALE_A_GUARDIAN 8 (Shaxthal Sentry Drone) 77 41} {FACING sw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 60 56} {FACING sw}
        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 61 60} {FACING nw}
        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 56 55} {FACING sw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 41 63} {FACING n}
        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 33 57} {FACING se}

        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 44 40} {FACING sw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Runner Drone) 48 45} {FACING nw}

        {FINALE_A_GUARDIAN 8 (Shaxthal Drone) 53 43} {FACING nw}

        {FINALE_A_GUARDIAN 3 (Lumeril Guard) 38 53} {FACING se}

        {FINALE_A_GUARDIAN 3 (Imp) 37 55} {FACING se}
        {FINALE_A_GUARDIAN 3 (Imp) 40 53} {FACING se}

        {FINALE_A_GUARDIAN 3 (Imp) 54 63} {FACING se}

        {FINALE_A_GUARDIAN 3 (Chaos Invader) 39 57} {FACING se}
        {FINALE_A_GUARDIAN 3 (Chaos Invader) 43 60} {FACING se}
        {FINALE_A_GUARDIAN 3 (Chaos Gunner)  45 58} {FACING sw}
        {FINALE_A_GUARDIAN 3 (Chaos Gunner)  48 60} {FACING se}

        {FINALE_A_GUARDIAN 3 (Chaos Magus) 24 46} {FACING se}

        {FINALE_A_GUARDIAN 3 (Dark Knight) 67 59} {FACING ne}

        {FINALE_A_GUARDIAN 3 (Chaos Crossbowman) 59 65} {FACING se}
        {FINALE_A_GUARDIAN 3 (Chaos Crossbowman) 57 66} {FACING se}

        {NAMED_LOYAL_UNIT 3 (Chaos Lorekeeper) 39 60 "Mal Boras"    ( _ "Mal Boras")   } {FACING ne} {GUARDIAN}

        [unit]
            side=3
            x,y=46,55
            type=Lich
            id=Mal Gulgolet
            name= _ "Mal Gulgolet"
            facing=se
            [modifications]
                {TRAIT_UNDEAD}
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]
        {NO_UPKEEP} {GUARDIAN}

        {FINALE_A_GUARDIAN  3 (Chaos Headhunter) 65 56} {FACING nw}
        {FINALE_A_GUARDIAN  3 (Chaos Headhunter) 71 61} {FACING sw}

        {FINALE_A_GUARDIAN  2 (Abomination) 55 29} {FACING sw}
        {FINALE_A_GUARDIAN  2 (Abomination) 52 31} {FACING ne}

        {FINALE_A_GUARDIAN  2 (Ghoul) 53 26} {FACING s}

        {FINALE_A_GUARDIAN 12 (Blood Bat) 30 19} {FACING s}
        {FINALE_A_GUARDIAN 12 (Vampire Bat) 27 24} {FACING se}
        {FINALE_A_GUARDIAN 12 (Vampire Bat) 30 24} {FACING se}

        {FINALE_A_GUARDIAN 12 (Walking Corpse) 29 21} {FACING s}  {VARIATION saurian}
        {FINALE_A_GUARDIAN 12 (Walking Corpse) 30 27} {FACING ne} {VARIATION bat}
        {FINALE_A_GUARDIAN 12 (Walking Corpse) 32 25} {FACING ne} {VARIATION saurian}

        {FINALE_A_GUARDIAN  2 (Demon Zephyr) 54 46} {FACING se}

        {FINALE_A_GUARDIAN 12 (Tentacle of the Deep) 36  8}
        {FINALE_A_GUARDIAN 12 (Tentacle of the Deep) 35 10}
        {FINALE_A_GUARDIAN 12 (Tentacle of the Deep) 38  7}

        {FINALE_A_GUARDIAN 12 (Giant Rat) 41  5} {FACING sw}
        {FINALE_A_GUARDIAN 12 (Giant Rat) 35  5} {FACING se}
        {FINALE_A_GUARDIAN 12 (Giant Rat) 31 11} {FACING ne}

        {FINALE_A_GUARDIAN 12 (Giant Rat) 33 18} {FACING se}

        {FINALE_A_GUARDIAN 12 (Leech) 38 28}
        {FINALE_A_GUARDIAN 12 (Leech) 42 24}
        {FINALE_A_GUARDIAN 12 (Leech) 45 27}
        {FINALE_A_GUARDIAN 12 (Leech) 50 28}
        {FINALE_A_GUARDIAN 12 (Leech) 28 22}

        {FINALE_A_GUARDIAN 7 (Demon Zephyr) 62 65} {FACING se}

        {PLACE_IMAGE scenery/trash.png 44  9}
        {PLACE_IMAGE scenery/trash.png 57 20}
        {PLACE_IMAGE scenery/trash.png 31 27}
        {PLACE_IMAGE scenery/trash.png 61 61}

        {PLACE_IMAGE "items/bones.png~FL(horiz)" 44 25}
        {PLACE_IMAGE "items/bones.png"           46 32}
        {PLACE_IMAGE "items/bones.png~FL(horiz)" 52 32}

        {PLACE_IMAGE "items/box.png" 62 49}

        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 39 57}
        {PLACE_IMAGE scenery/banner-uria-standing-sw.png 44 59}

        {PLACE_IMAGE scenery/banner-uria-standing.png 41 53}
        {PLACE_IMAGE scenery/banner-uria-standing.png 40 53}
        {PLACE_IMAGE scenery/banner-uria-standing.png 39 54}
        {PLACE_IMAGE scenery/banner-uria-standing.png 38 54}

        {PLACE_IMAGE scenery/banner-uria-standing.png 51 58}
        {PLACE_IMAGE scenery/banner-uria-standing.png 50 58}
        {PLACE_IMAGE scenery/banner-uria-standing.png 49 59}
        {PLACE_IMAGE scenery/banner-uria-standing.png 48 59}

        # The abandoned iron council room glyphs are handled by
        # a separate handler further below.

        {SET_LABEL 49 60 _"Council Chamber"}
        {SET_LABEL 45 13 _"Abandoned Council Chamber"}

        {ITEM_CRYSTAL_GLYPH         29  9}

        {REMOVE_SOUND_SOURCE floor_1_water_sound_source_1,floor_1_water_sound_source_2}

        {CAVE_WATER_SOUND_SOURCE 14 42}
        [+sound_source]
            id=floor_2_water_sound_source_1
        [/sound_source]

        {CAVE_WATER_SOUND_SOURCE 46 45}
        [+sound_source]
            id=floor_2_water_sound_source_2
        [/sound_source]

        {CAVE_WATER_SOUND_SOURCE 37  8}
        [+sound_source]
            id=floor_2_water_sound_source_3
        [/sound_source]
    [/event]

    [event]
        name=enter floor 2

        # Coming back from that lengthy delay...

        [repeat]
            times=24
            [do]
                {FINALE_A_ELEVATOR_RUMBLE}
            [/do]
        [/repeat]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "The transporter abruptly stops."
        [/message]

        [delay]
            time=750
        [/delay]

        [terrain]
            x,y=68,50
            terrain=Rr
        [/terrain]

        #
        # TODO: SFX
        #

        [redraw]
            side=1
        [/redraw]

        [delay]
            time=750
        [/delay]

        {MOVE_UNIT id=Elynia 67 50}

        [redraw]
            side=1
        [/redraw]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I recognize this corridor. Onwards!"
        [/message]

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Proceed further underground")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {TURNS_RUN_OUT}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}
    [/event]

    #
    # Entering the Iron Triad Council Chamber.
    #

    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                x,y=42,57
                radius=9
            [/filter_location]
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        [store_starting_location]
            side=8
        [/store_starting_location]

        [unit]
            side=8
            canrecruit=yes
            x,y=$location.x,$location.y
            type=Shaxthal Protector Drone
            facing=nw
            [modifications]
                {TRAIT_BIOMECHANICAL}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        {CLEAR_VARIABLE location}

        {FINALE_A_ACTIVATE_SIDE 8}

        {CLEAR_CAVE_SHROUD (
            x,y=44,56
            radius=7
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=44,56
        [/scroll_to]

        [delay]
            time=750
        [/delay]

        [if]
            [have_unit]
                {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
            [/have_unit]
            [then]
                [message]
                    speaker=Mal Gulgolet
                    message= _ "The Lady of Light and her foolish new cohorts, eh? We should have known that Ergea and her kind couldn’t be trusted. Hopefully you enjoy their company, for we intend to send you all to the abyss together, and not precisely to die..."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Mal Gulgolet
                    message= _ "The Lady of Light, eh? We should have known that Ergea and her kind couldn’t be trusted. Too bad that your cohorts didn’t make it; we wanted to send you all to the abyss together, and not precisely to die..."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Elynia
            # po: 'Master' here in feminine, referring to Elyssa (the 'Fire').
            message= _ "Save your boasting for later — it will not help you win the battle on the surface and we are well accustomed to it at this point. Where is your master?"
        [/message]

        [message]
            speaker=Mal Gulgolet
            message= _ "Our <i>masters</i> are busy with their own inscrutable plans, and the fortress defenses are already disposing of your pathetic allies above. But it is not <i>your</i> place to ask questions here. Now..."
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Mal Gulgolet
            message= _ "Would you prefer to go down fighting, or surrender and let us take you to the Fire?"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "I’ll let you have a guess."
        [/message]

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Mal Gulgolet
        [/filter]
        {ON_FLOOR 2}

        [message]
            speaker=Mal Gulgolet
            message= _ "... heh. The Fire was right... about you..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Mal Gulgolet
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        [unit]
            side=2
            type=Demon Spelldancer
            id=Talia
            name= _ "Talia"
            facing=se
            x,y=18,43
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_DEXTROUS}
            [/modifications]
        [/unit]

        [unit]
            side=2
            type=Iron Golem
            x,y=15,43
            facing=Se
            [modifications]
                {TRAIT_MECHANICAL}
            [/modifications]
        [/unit]

        [unit]
            side=2
            type=Iron Golem
            x,y=17,42
            facing=Se
            [modifications]
                {TRAIT_MECHANICAL}
            [/modifications]
        [/unit]

        {CLEAR_CAVE_SHROUD (
            x,y=18,43
            radius=6
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=18,43
        [/scroll_to]

        {HIGHLIGHT_GOAL x,y="18,17,15","43,42,43"}

        {CLEAR_CAVE_SHROUD (
            x,y=34,51
            radius=2
        )}

        [redraw]
            side=1
        [/redraw]

        {REMOVE_EVENT_BARRIER ("*^Zz\,*^Zz/,*^Zz|") 34 51}

        [scroll_to]
            x,y=$x2,$y2
        [/scroll_to]

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=die
        [filter]
            id=Talia
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        [store_starting_location]
            side=3
        [/store_starting_location]

        [unit]
            side=3
            canrecruit=yes
            x,y=$location.x,$location.y
            type=Chaos Lorekeeper
            id=Mal Arachgeas
            name= _ "Mal Arachgeas"
            facing=sw
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        {CLEAR_VARIABLE location}

        {FINALE_A_ACTIVATE_SIDE 3}

        [unit]
            side=9
            type=Door
            x,y=52,44
        [/unit]

        [unit]
            side=9
            type=Door
            x,y=54,43
        [/unit]

        [unit]
            side=9
            type=Door
            x,y=56,42
        [/unit]

        #
        # Yes, the facing specifications don't make sense if
        # Elynia isn't in the same corridor or the chamber nearby
        # at that time. No, I don't think that's terribly likely
        # or important for anything.
        #

        [store_direction]
            from_x,from_y=32,50
            [to]
                [filter]
                    id=Elynia
                [/filter]
            [/to]
        [/store_direction]

        [unit]
            side=11
            id=cutscene_fire_guardian
            type=Fire Wraith
            x,y=32,50
            facing=$direction
            animate=yes
        [/unit]

        #
        # Clear the cutscene region a bit in case the player didn't
        # clear shroud there yet (unlikely!)
        #

        {CLEAR_CAVE_SHROUD (
            x,y=32,50
            radius=4
            # Also the passage regions.
            [or]
                x,y=32,47
                radius=1
            [/or]
            [or]
                x,y=41,49
                radius=1
            [/or]
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=32,50
        [/scroll_to]

        [delay]
            time=250
        [/delay]

        [invert_direction][/invert_direction]

        {MODIFY_UNIT id=Elynia facing $direction}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            scroll=no
            message= _ "Is that..."
        [/message]

        [delay]
            time=750
        [/delay]

        #
        # Remove invisible barriers leading to the next area.
        #

        [remove_terrain_overlays]
            x=32,41
            y=47,49
        [/remove_terrain_overlays]

        [redraw]
            side=1
        [/redraw]

        [store_unit]
            [filter]
                id=cutscene_fire_guardian
            [/filter]
            kill=yes
            variable=cutscene_fire_guardian_store
        [/store_unit]

        [move_unit_fake]
            type=$cutscene_fire_guardian_store.type
            side=$cutscene_fire_guardian_store.side
            x=$cutscene_fire_guardian_store.x,32,40
            y=$cutscene_fire_guardian_store.y,46,42
        [/move_unit_fake]

        [redraw]
            side=1
        [/redraw]

        {HIGHLIGHT_GOAL x,y="32,41","47,49"}

        [message]
            speaker=Elynia
            message= _ "Those passages appear to lead somewhere."
        [/message]

        [scroll_to]
            x,y=$x2,$y2
        [/scroll_to]

        {CLEAR_VARIABLE cutscene_fire_guardian_store,direction}

        {UNLOCK_VIEW}
    [/event]

    #
    # Opening the doors leading to the corridor behind the throne
    # reveals a Fire Wraith providing a hint for the player to
    # follow.
    #

    [event]
        name=die
        [filter]
            type=Door
            x=52,54,56
            y=44,43,42
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        {CLEAR_CAVE_SHROUD (
            x,y=60,43
            radius=5
        )}

        [redraw]
            side=1
        [/redraw]

        [move_unit_fake]
            side=11
            type=Fire Wraith
            x=57,60,60,63
            y=45,43,39,38
        [/move_unit_fake]

        [scroll_to]
            x,y=$x2,$y2
        [/scroll_to]

        {UNLOCK_VIEW}
    [/event]

    #
    # Provide a hint about the secret passage.
    #

    [event]
        name=moveto
        [filter]
            side=1
            x=61-66
            y=28-40
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        {CLEAR_CAVE_SHROUD (
            x,y=63,34
            radius=6
        )}

        [redraw]
            side=1
        [/redraw]

        [terrain]
            terrain=Xv^Uov
            x=59-60
            y=33
            layer=overlay
        [/terrain]

        [move_unit_fake]
            side=11
            type=Fire Wraith
            x=63,63,61,56
            y=36,35,34,31
        [/move_unit_fake]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "A secret passage. Not particularly ingenious. Although... it might lead to the cave Ergea mentioned."
        [/message]

        {UNLOCK_VIEW}
    [/event]

    #
    # Soulless Mal Kendria miniboss event.
    #

    [event]
        name=moveto
        [filter]
            side=1
            x=37-55
            y=22-34
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        [message]
            speaker=Elynia
            message= _ "Wait. There’s someone else in here..."
        [/message]

        [delay]
            time=750
        [/delay]

        # Deliberate portraitless non-standard definition of Mal Kendria

        [unit]
            side=11
            id=Mal Kendria
            name= _ "Mal Kendria"
            type=Necromancer
            profile="unit_image"
            gender=female
            level=4
            x,y=41,27
            facing=se
            #{IS_BOSS}
            max_hitpoints=81
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
                {UNIT_PALETTE_SWITCH () necro_skin_base necro_skin_devoid}
                {MOD_LOYAL_HERO}
            [/modifications]
        [/unit]

        [unit]
            side=11
            x,y=41,29
            facing=se
            type=Soulless
            variation=troll
            upkeep=free
            [modifications]
                {TRAIT_UNDEAD}
            [/modifications]
        [/unit]

        [unit]
            side=11
            x,y=39,28
            facing=se
            type=Soulless
            variation=troll
            upkeep=free
            [modifications]
                {TRAIT_UNDEAD}
            [/modifications]
        [/unit]

#ifndef EASY
        [unit]
            side=11
            x,y=43,28
            facing=se
            type=Ghast
            upkeep=free
            [modifications]
                {TRAIT_UNDEAD}
            [/modifications]
        [/unit]
#endif

        {CLEAR_CAVE_SHROUD (
            x,y=41,27
            radius=8
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=41,27
        [/scroll_to]

        {HIGHLIGHT_GOAL x,y=41,27}

        [if]
            [have_unit]
                {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
            [/have_unit]
            [then]
                [message]
                    speaker=Elynia
                    message= _ "It’s the other necromancer, member of the Iron Triad. Perhaps, if we take her down... we might be able to force her to give us some directions."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "It’s the other necromancer, member of the Iron Triad. Perhaps, if I take her down... I might be able to force her to give me some directions."
                [/message]
            [/else]
        [/if]

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

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Defeat Mal Kendria")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {TURNS_RUN_OUT}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=last breath
        [filter]
            id=Mal Kendria
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        [message]
            speaker=Elynia
            message= _ "You are the other necromancer from the Iron Triad, aren’t you? Where is your master hiding? Where is the Ruby of Fire?"
        [/message]

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

        [delay]
            time=750
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(<i>silence</i>)"
        [/message]

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Are you going to answer?"
        [/message]

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

        [delay]
            time=750
        [/delay]

        [message]
            {FINALE_A_SUF_PLAYER_UNIT_OR_ELYNIA}
            message= _ "There is something wrong about her eyes..."
        [/message]

        [message]
            speaker=Elynia
            message= _ "I don’t have time for this."
        [/message]

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

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=die
        [filter]
            id=Mal Kendria
        [/filter]
        {ON_FLOOR 2}

        {LOCK_VIEW}

        [delay]
            time=750
        [/delay]

        [message]
            speaker=Elynia
            message= _ "Devoid of her own will... and turned into a living puppet... Suddenly, defeating her does not seem to be much of an achievement. I don’t think I saw anything like this the last time I was here. Why would they do this to her, though?"
        [/message]

        [if]
            [have_unit]
                {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
            [/have_unit]
            [then]
                [message]
                    {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
                    message= _ "My lady, we should proceed onwards, quickly. We don’t have much more time, and the Fire of Uria will not take kindly to all these casualties."
                [/message]

                [message]
                    speaker=Elynia
                    message= _ "Indeed, let us continue down this passage. If Ergea’s instructions are correct, there is a large stone chamber ahead."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "I should just continue down this passage. If Ergea’s instructions are correct, there is a large stone chamber ahead."
                [/message]
            [/else]
        [/if]

        [unit]
            side=9
            type=Door
            x,y=31,19
        [/unit]

        [unit]
            side=9
            type=Door
            x,y=32,19
        [/unit]

        {CLEAR_CAVE_SHROUD (
            x,y=30,20
            radius=2
        )}

        [redraw]
            side=1
        [/redraw]

        [scroll_to]
            x,y=31,19
        [/scroll_to]

        {HIGHLIGHT_GOAL x,y=31-32,19}

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

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Move Elynia into the chamber")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}
            {TURNS_RUN_OUT}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        {UNLOCK_VIEW}
    [/event]

    #
    # Entering the old council chamber
    #

    [event]
        name=moveto
        [filter]
            x=1-100,43-49,43-50
            y=1-15 ,16   ,17
            id=Elynia
        [/filter]
        {ON_FLOOR 2}

        [fire_event]
            name=entering old council chamber
            [primary_unit]
                x,y=$x1,$y1
            [/primary_unit]
        [/fire_event]
    [/event]

    # NOTE: doubles as SLF
#define FINALE_A_SUF_PLAYER_UNITS_ON_FINAL_CHAMBER
    x=1-100,33-35,49-65
    y=1-18 ,19   ,19-22
#enddef

    [event]
        name=entering old council chamber
        {ON_FLOOR 2}

        {LOCK_VIEW}

        {CLEAR_CAVE_SHROUD (
            x,y=45,14
            radius=6
        )}

        [store_direction]
            from_x,from_y=$x1,$y1
            to_x,to_y=31,19
        [/store_direction]

        {MODIFY_UNIT id=Elynia facing $direction}

        [redraw]
            side=1
        [/redraw]

        {REPLACE_SCENARIO_MUSIC "silence.ogg"}

        [scroll_to]
            x,y=31,19
            {WARP}
        [/scroll_to]

        [sound]
            name=explosion-big.ogg
        [/sound]

        # Kill everyone not in the chamber.
        [kill]
            [filter_location]
                [not]
                    {FINALE_A_SUF_PLAYER_UNITS_ON_FINAL_CHAMBER}
                [/not]
            [/filter_location]
            # x,y=31-32,19 -- this is included by the SLF
            animate=no
            fire_event=no
        [/kill]

        [place_shroud]
            side=1
            [not]
                {FINALE_A_SUF_PLAYER_UNITS_ON_FINAL_CHAMBER}
            [/not]
            [not]
                x,y=31-32,19
            [/not]
        [/place_shroud]

        [terrain]
            x,y=31-32,19
            terrain=Xu
        [/terrain]

        [redraw]
            side=1
        [/redraw]

        {QUAKE ("dragonstick.ogg")}

        [delay]
            time=500
        [/delay]

        {REPLACE_SCENARIO_MUSIC "everlasting_night.ogg"}

        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        [delay]
            time=500
        [/delay]

        [invert_direction][/invert_direction]

        {MODIFY_UNIT id=Elynia facing $direction}

        [redraw][/redraw]

        [delay]
            time=750
        [/delay]

        {VARIABLE_EVAL_CONDITIONAL have_more_units (
            [have_unit]
                {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
            [/have_unit]
        )}

        [if]
            {VARIABLE_BOOLEAN_EQUALS have_more_units yes}
            [then]
                [message]
                    speaker=Elynia
                    message= _ "We are trapped in this chamber..."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "I am trapped in this chamber..."
                [/message]
            [/else]
        [/if]

        {CLEAR_CAVE_SHROUD (
            x=50-52,53
            y=12-13,13
        )}

        [scroll_to]
            x,y=52,12
        [/scroll_to]

        {HIGHLIGHT_GOAL (
            x=51-52,53
            y=12   ,13
        )}

        [if]
            {VARIABLE_BOOLEAN_EQUALS have_more_units yes}
            [then]
                [message]
                    speaker=Elynia
                    message= _ "(<i>chuckles</i>) That’s were you want us to go. Isn’t that correct... Elyssa?"
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Elynia
                    message= _ "(<i>chuckles</i>) That’s were you want me to go. Isn’t that correct... Elyssa?"
                [/message]
            [/else]
        [/if]

        {CLEAR_VARIABLE have_more_units}

        [delay]
            time=250
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(<i>silence</i>)"
        [/message]

        [delay]
            time=250
        [/delay]

        [message]
            speaker=Elynia
            message= _ "You could have opened the gate for me, at the very least."
        [/message]

        [modify_turns]
            value=-1
        [/modify_turns]

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Find a way to open the chamber exit gate to proceed")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        {CLEAR_VARIABLE direction}

        {UNLOCK_VIEW}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            #
            # Only trigger this message-only event when an ally steps on the
            # glyph's hex, or when Elynia herself does _after_ getting the spell.
            #
            [not]
                id=Elynia
                [not]
                    [filter_wml]
                        [variables]
                            have_great_chamber_glyph_spell=yes
                        [/variables]
                    [/filter_wml]
                [/not]
            [/not]
            x,y=29,9
        [/filter]
        {ON_FLOOR 2}

        [allow_undo][/allow_undo]

        #
        # Different messages depending on whether Elynia has the spell
        # already or not.
        #
        [if]
            [have_unit]
                id=Elynia
                [filter_wml]
                    [variables]
                        have_great_chamber_glyph_spell=yes
                    [/variables]
                [/filter_wml]
            [/have_unit]
            [then]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Elynia already has the glyph’s spell. Move her next to the chamber exit to open it."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Elynia should be the one to investigate this glyph."
                [/message]
            [/else]
        [/if]
    [/event]

    [event]
        name=moveto
        [filter]
            id=Elynia
            x,y=29,9
        [/filter]
        {ON_FLOOR 2}

        [transient_message]
            caption= _ "Barrier Spell"
            image=items/crystal-glyph.png
            sound=magic-3.ogg
            message= _ "This spell allows the unit to open any barriers that were originally sealed with the same spell."
        [/transient_message]

        {VARIABLE unit.variables.have_great_chamber_glyph_spell yes}

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

        {OBJECTIVES (
            side=1
            victory_string= _ "Current Objective:"
            {OBJECTIVE_VICTORY ( _ "Move Elynia next to the chamber exit gate to proceed")}

            {OBJECTIVE_DEFEAT  ( _ "Death of Elynia")}

            {FINALE_A_RECRUITMENT_MECHANICS_NOTE}
            {OBJECTIVE_NO_CARRYOVER}
        )}

        #
        # Victory trigger event.
        #

        [event]
            name=moveto
            [filter]
                id=Elynia
                x=50,51-52
                y=12,13
            [/filter]

            {LOCK_VIEW}

            #
            # TODO: animate Elynia, perhaps using the default
            # 'selected' animation.
            #

            [remove_terrain_overlays]
                x=51-52,53
                y=12   ,13
            [/remove_terrain_overlays]

            {CLEAR_CAVE_SHROUD (
                x,y=54,11
                radius=2
            )}

            [redraw]
                side=1
            [/redraw]

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

            [delay]
                time=750
            [/delay]

            {MOVE_UNIT id=Elynia 54 11}

            {QUAKE ("rumble.ogg")}

            {FACE_LOCATION id=Elynia x,y=52,12}

            #
            # Remove any items that may have haloes so they don't glitch
            # through shroud.
            #

            [remove_item][/remove_item]

            [redraw]
                side=1
            [/redraw]

            [kill]
                {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
                fire_event=no
                animate=no
            [/kill]

            [terrain]
                x=51-52,53
                y=12   ,13
                terrain=Xu
            [/terrain]

            [place_shroud]
                side=1
                [not]
                    x,y=54,11
                    radius=2
                [/not]
            [/place_shroud]

            [redraw]
                side=1
            [/redraw]

            {QUAKE ("dragonstick.ogg")}

            [delay]
                time=1750
            [/delay]

            [message]
                speaker=Elynia
                message= _ "... So you want me to proceed alone. Very well, then."
            [/message]

            {FACE_DIRECTION id=Elynia ne}

            [delay]
                time=750
            [/delay]

            {MOVE_UNIT id=Elynia 62 7}

            [hide_unit]
                id=Elynia
            [/hide_unit]

            {UNLOCK_VIEW}

            {ENDLEVEL_QUIET} {NO_START_OF_SCENARIO_SAVE}
        [/event]

        #
        # Clear temporary unit-bound variables on victory.
        #

        [event]
            name=victory

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

            {CLEAR_VARIABLE elynia_store.variables.have_great_chamber_glyph_spell}

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

#define FINALE_A_CHAMBER_GLYPH _X _Y _ACTIONS
    [event]
        name=setup floor 2
        {ITEM_CRYSTAL_GLYPH_MESSAGE ({_X}) ({_Y})}
    [/event]
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x={_X}
            y={_Y}
        [/filter]
        {ON_FLOOR 2}

        [allow_undo][/allow_undo]

        {_ACTIONS}
    [/event]
#enddef

#define FINALE_A_CHAMBER_GLYPH_SIMPLE _X _Y _MSG
    {FINALE_A_CHAMBER_GLYPH ({_X}) ({_Y}) ({MSG_GLYPH ({_MSG})})}
#enddef

    #
    # NW message glyphs
    #

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 40  2 ( _ "<b>Urvatha</b>

Originally a peaceful world not predestined to harbor civilization, Urvatha was chosen by Iluvia as one of the destinations for the survivors of the First Cycle.

Over time, the lack of a guardian who could guide them resulted in devastating and long-lasting wars over increasingly scarce resources — thus earning it a new name for outsiders and natives alike: ‘Inferno’.

While Urvatha continues to be largely heterogeneous, its most inhospitable regions are much better known in Irdyan lore than the rest.

Despite originally lacking a guardian and a seed, Urvatha has become the domain of the New Guardian of Life.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 34  3 ( _ "<b>Silida</b>

Originally a barren world not predestined to harbor civilization, Silida was chosen by Iluvia as one of the destinations for the survivors of the First Cycle.

It is said that before being erased from existence, the Guardians of Life and Existence adapted this lifeless world as a new home for their peoples. However, their task was left unfinished, and the new inhabitants of the world died out after a few generations. Only many eons later would Silida be populated again by faerie creatures.

Despite originally lacking a guardian and a seed, Silida has become the domain of the New Guardian of Earth.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 29  5 ( _ "The First Gods created us and the reality we live in with the intent that our own Original Ten would protect and rule over their creation, and eventually replace their forefathers entirely. Little did they know of the many trials they would face during the First Cycle, and the betrayal that would result in the abrupt end of their own existence.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 30 12 ( _ "Little did they know that the same corruptive force that ravaged their universe would manipulate the order of events to ensure an entryway through the Tree of Life itself.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 36 11 ( _ "It would ensure that the souls of our ten demon gods would be connected directly to the Tree through their very hearts. And then it would corrupt the Tree, and its Protector.")}

    #
    # SE message glyphs
    #

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 55 15 ( _ "The First Gods no longer exist, and now the Tree is completely unguarded. Our universe and our guardians will fail to accomplish their intended mission. Not even Delethia could see this until the First Cycle was over. The songs of our own Ten will never be uttered within the boundaries of our existence, and the wound on the Tree will never be healed.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 62 17 ( _ "Even at the last moment, Delethia could not fully control the final outcome; however, her greatly increased foresight and power after defeating Yarae did allow her to alter it to a limited extent.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 56 21 ( _ "Our lives were carefully arranged before she sacrificed her own to create the Gatekeepers. She entrusted Uria and Xia’el with the devices necessary to put her secret plan into motion. The Second Cycle began.")}

    {FINALE_A_CHAMBER_GLYPH_SIMPLE 64 22 ( _ "At the end, only Four will prevail.")}

    #
    # TODO: remove in production
    #

    [event]
        name=debug skip

        [fire_event]
            name=restore elynia
        [/fire_event]

        [store_unit]
            [filter]
                {FINALE_A_SUF_PLAYER_UNITS_ON_MAP}
            [/filter]
            variable=debug_store
            kill=yes
        [/store_unit]

        [foreach]
            array=debug_store
            [do]
                {VARIABLE this_item.x 70}
                {VARIABLE this_item.y 51}

                [unstore_unit]
                    variable=this_item
                    find_vacant=yes
                    check_passability=no
                [/unstore_unit]
            [/do]
        [/foreach]

        {CLEAR_VARIABLE debug_store}

        [redraw]
            side=1
        [/redraw]

        [scroll_to_unit]
            id=Elynia
        [/scroll_to_unit]

        {SWITCH_FLOOR 2}
    [/event]

    ############################################################################
    #                                                                          #
    #                           PLAYER ECONOMYTRON 9000                        #
    #                            IT DICES! IT SLICES!                          #
    #                                                                          #
    ############################################################################

    [event]
        name=prerecruit
        first_time_only=no
        [filter]
            side=1
        [/filter]

        #
        # Emulate free recruits until there's a recruit_cost_factor
        # attribute for side declarations or something.
        #

        [gold]
            side=1
            amount=$unit.cost
        [/gold]

        #
        # We either kill the recruit or make it loyal depending
        # on the current ally count.
        #

        [count_units]
            {FINALE_A_SUF_PLAYER_ALLIES_ON_MAP}
            [not]
                id=Vyrelyam
            [/not]
        [/count_units]

        [if]
            {VARIABLE_NUMERICAL_LESS_THAN_OR_EQUAL unit_count 8}
            [then]
                [fire_event]
                    name=handle player recruit
                    [primary_unit]
                        x,y=$x1,$y1
                    [/primary_unit]
                [/fire_event]
            [/then]
            [else]
                [fire_event]
                    name=undo player recruit
                    [primary_unit]
                        x,y=$x1,$y1
                    [/primary_unit]
                [/fire_event]
            [/else]
        [/if]

        {CLEAR_VARIABLE unit_count}
    [/event]

    [event]
        name=undo player recruit
        first_time_only=no

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

        [transient_message]
            message= _ "You have eight allies on the map already. You cannot recruit additional units at this time!"
        [/transient_message]
    [/event]

    [event]
        name=handle player recruit
        first_time_only=no

        #
        # We need the TRAIT_LOYAL macro contents in a temporary.
        # They include the [trait] opening and closing tags, and
        # we don't want those below, hence this approach.
        #

        [set_variables]
            name="temp_trait_loyal_wml"
            mode=replace
            [literal]
                {TRAIT_LOYAL}
            [/literal]
        [/set_variables]

        [set_variables]
            name="unit"
            mode=merge
            [literal]
                upkeep=free
                {IS_LOYAL}
            [/literal]
        [/set_variables]

        [if]
            [not]
                [have_unit]
                    side=1
                    id=Elynia
                [/have_unit]
            [/not]
            [then]
                # When playing as Vyrelyam we have unlimited per-turn moves,
                # so reset the recruit's moves to maximum then.

                [set_variables]
                    name="unit"
                    mode=merge
                    [value]
                        attacks_left=$unit.max_attacks
                        moves=$unit.max_moves
                    [/value]
                [/set_variables]
            [/then]
        [/if]

        [set_variables]
            name="unit.modifications.trait[0]"
            mode=insert
            to_variable="temp_trait_loyal_wml.trait"
        [/set_variables]

        [unstore_unit]
            variable="unit"
            find_vacant=no
        [/unstore_unit]

        {CLEAR_VARIABLE temp_trait_loyal_wml}
    [/event]
[/scenario]

#undef FINALE_A_SUF_PLAYER_UNITS_ON_MAP
#undef FINALE_A_SUF_PLAYER_ALLIES_ON_MAP
#undef FINALE_A_SUF_PLAYER_UNIT_OR_ELYNIA
#undef FINALE_A_SUF_PLAYER_UNITS_ON_FINAL_CHAMBER
#undef FINALE_A_TRANSPORTER_ROOM_SLF
#undef FINALE_A_ITEM_EVENT
#undef FINALE_A_POTION_OF_YUMMY
#undef FINALE_A_ELYNIA_THOUGHTS
#undef FINALE_A_ELEVATOR_RUMBLE
#undef FINALE_A_CHAMBER_GLYPH
#undef FINALE_A_CHAMBER_GLYPH_SIMPLE
#undef FINALE_A_GUARDIAN
#undef FINALE_A_ACTIVATE_SIDE
#undef FINALE_A_RECRUITMENT_MECHANICS_NOTE

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