#textdomain wesnoth-ei
[scenario]
    id=10_Dark_Sanctuary
    name= _ "Dark Sanctuary"
    map_file=10_Dark_Sanctuary.map
    victory_when_enemies_defeated=no
    turns=unlimited # see notes in S09_Castle_In_The_Ice

    {UNDERGROUND}

    next_scenario=11_Captured

    {SCENARIO_MUSIC underground.ogg}
    {EXTRA_SCENARIO_MUSIC suspense.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    [story]
        [part]
            story=_ "Sequestered away under ice and stone, the dark places of the world quietly count the long years, biding their time until once more disturbed."
            music=silence.ogg
        [/part]
    [/story]
    {EI_TRACK {JOURNEY_10_NEW} }

    victory_when_enemies_defeated=no

    [side]
        side=1
        canrecruit=yes
        controller=human
        team_name=good
        user_team_name=_"Wesnothians"
        shroud=yes
        gold=0 # see notes in S09_Castle_In_The_Ice
        {FLAG_VARIANT loyalist}

        {CHARACTER_STATS_GWEDDRY}
    [/side]
    {STARTING_VILLAGES_AREA 1 30 20 4}

    [side]
        color=white
        no_leader=yes
        side=2
        team_name=orcs_and_firespirits_and_jinn
        user_team_name=_"Clan Whitefang"
        hidden=yes
        [ai]
            aggression=0.9
            grouping=no
            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=99
            [/goal]
            retreat_factor=0
            [avoid] # keep the jinn out of the ant nest
                x,y=45-99,0-19
            [/avoid]
        [/ai]
    [/side]

    [side]
        no_leader=yes
        side=3
        team_name=monsters
        user_team_name=_"Monsters"
        hidden=yes
        [ai]
            aggression=0.9
            caution=0.1
            grouping=no
            # monsters avoid the west wing, and avoid the undead study
            [avoid]
                x= 0-22, 29-31
                y=13-24,  0-9
            [/avoid]
            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=99
            [/goal]
            retreat_factor=0
        [/ai]
    [/side]

    [side]
        no_leader=yes
        side=4
        team_name=undead
        user_team_name=_"Undead"
        {INCOME 2 15 30}
        recruit=Skeleton,Skeleton Archer
        hidden=yes
        [ai]
            aggression=0.9
            caution=0.1
            grouping=no
            # study ghosts avoid the vaults
            [avoid]
                x=35-99
                y=11-15
            [/avoid]
            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=99
            [/goal]
            retreat_factor=0
        [/ai]
    [/side]
#ifdef HARD
    # This macro automatically adds the unit type to the side's recruitment
    # list, on other difficulties side 4 can't even recruit Revenants.
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 (Revenant) 1}
#endif

    [side]
        no_leader=yes
        side=5
        team_name=goblins
        user_team_name=_"Goblins"
        hidden=yes
        [ai]
            [goal] # prefer staying in their initial rooms
                name=target_location
                [criteria]
                    x,y=14,14
                    radius=2
                [/criteria]
                value=0.1
            [/goal]
            [goal]
                name=target_location
                [criteria]
                    x,y=24,18
                    radius=2
                [/criteria]
                value=0.1
            [/goal]
            grouping="defensive"
            aggression=0.9
            caution=0.1
        [/ai]
    [/side]

    [event]
        name=prestart
        {INCIDENTAL_MUSIC heroes_rite.ogg}

        # normally we don't scale anything except enemy count,
        # but I heard a couple comments that this scenario was too hard even on Easy,
        # so make both defense and economy easier on lower difficulties
#ifdef EASY
        {MODIFY_TERRAIN Uu^Vud 40 18}
        {MODIFY_TERRAIN Rb^Vo 40 25}
#endif
#ifndef HARD
        {MODIFY_TERRAIN Uu^Vud 35 20}
        {MODIFY_TERRAIN Ha^Voa 48 21}
#endif
        [time_area]
            x=30,31,   32,   33,   34,   35,   36,   37,   38,   39,   40,   41,   42,   43,   44,   45,   46,   47,   48,   49,   50,   51,   52,   53,   54,   55,   56,   57
            y=30,30-31,29-31,29-31,28-31,27-31,27-31,26-31,24-31,25-31,24-31,24-31,23-31,23-31,22-31,22-31,21-31,21-31,20-31,21-31,20-31,20-31,19-31,19-31,18-31,18-31,18-31,18-31
            {WINTER_SCHEDULE}
        [/time_area]

        #---------------------------
        # MAIN HALL SCENERY
        #---------------------------
        {PLACE_IMAGE scenery/signpost.png 31 12}
        {PLACE_IMAGE scenery/signpost.png 25 14}
        {PLACE_IMAGE items/gold-coins-medium.png 27 11}

        {PLACE_IMAGE scenery/rune_line_glow.png 20 10}
        {PLACE_IMAGE scenery/rune_line_glow.png 21 10}
        {PLACE_IMAGE scenery/rune_line_glow.png 22 9}

        #---------------------------
        # EAST HALL SCENERY
        #---------------------------
        {PLACE_IMAGE scenery/rune6-glow.png 33 10}
        {PLACE_IMAGE scenery/rune6-glow.png 38 12}

        {PLACE_IMAGE "items/lamp-genie.png" 42 11}
        {PLACE_IMAGE items/cloak-green.png 38 10}
        {PLACE_IMAGE "items/chest.png~FL(horiz)" 42 9}
        {PLACE_IMAGE "items/chest.png~FL(horiz)" 43 10}
        {PLACE_ITEM_HOLY_AMULET {ID_HOLY_AMULET_2} 39 10}
        {PLACE_ITEM_BANEBLADE 41 10}

        {PLACE_IMAGE "items/dragonstatue.png~FL(horiz)" 33 4}
        {PLACE_IMAGE "items/dragonstatue.png~FL(horiz)" 28 1}
        {PLACE_IMAGE "items/dragonstatue.png~FL(horiz)" 33 4}
        {PLACE_IMAGE "scenery/bookshelf.png~FL(horiz)" 31 3}
        {PLACE_IMAGE "scenery/bookshelf-full.png~FL(horiz)" 30 2}
        {PLACE_IMAGE items/ball-blue.png 30 5}
        {PLACE_IMAGE items/ball-green.png 31 5}
        {PLACE_IMAGE items/ball-magenta.png 32 4}
        {PLACE_IMAGE items/book5.png 28 5}
        {PLACE_IMAGE items/book2.png 27 7}
        {PLACE_IMAGE items/book1.png 30 3}
        {PLACE_IMAGE items/book4.png 29 4}
        {PLACE_IMAGE items/box.png 25 3}
        {PLACE_IMAGE items/barrel.png 26 2}
        {PLACE_IMAGE items/box.png 26 3}
        {PLACE_IMAGE items/gohere-empty.png 28 2}
        {PLACE_IMAGE items/key.png 28 2}

        #---------------------------
        # WEST HALL SCENERY
        #---------------------------
        {PLACE_IMAGE items/dragonstatue.png 13 19}
        {PLACE_IMAGE items/dragonstatue.png 16 20}
        {PLACE_IMAGE scenery/rubble.png 19 22}

        {PLACE_IMAGE items/altar-evil.png 12 13}
        {PLACE_IMAGE items/altar-evil.png 13 13}
        {PLACE_IMAGE items/potion-blue.png 10 14}
        {PLACE_IMAGE items/potion-grey.png 17 13}
        {PLACE_IMAGE items/potion-yellow.png 15 12}
        {PLACE_IMAGE items/potion-poison.png 14 14}
        {PLACE_ITEM_BARKSKIN 15 13}

        {PLACE_IMAGE scenery/rune4-glow.png 24 22}
        {PLACE_IMAGE "items/bones.png~FL(horiz)" 23 23}
        {PLACE_IMAGE items/orcish-flag.png 21 19}
        {PLACE_IMAGE items/orcish-flag.png 26 19}
        {PLACE_IMAGE scenery/leanto.png 20 18}
        {PLACE_IMAGE items/gohere-empty.png 25 18}
        {PLACE_IMAGE items/key.png 25 18}

        #---------------------------
        # SANCTUM SCENERY
        #---------------------------
        {PLACE_IMAGE "items/bones.png~FL(horiz)" 13 1}
        {PLACE_IMAGE items/bones.png 16 2}
        {PLACE_IMAGE items/bones.png 8 6}

        {PLACE_IMAGE items/altar-evil-amulet.png 13 5}

        #---------------------------
        # INITIAL HUMANS
        #---------------------------
        {RECALL_XY Dacyn 37 19}
        {RECALL_XY Owaec 38 20}
        {RECALL_XY Addogin 42 20}
        {RECALL_XY (Hahid al-Ali) 42 20}
        {RECALL_XY Terraent 42 20}
        {RECALL_XY Dolburras 43 21}
        {RECALL_XY Grug 43 21}

        #---------------------------
        # WYVERN
        #---------------------------
        {GENERIC_UNIT 3 (Giant Rat) 31 16} {GUARDIAN}
        {GENERIC_UNIT 3 (Wild Wyvern) 27 11} {GUARDIAN} # sitting on a pile of gold
        [object]
            [filter]
                type=Wild Wyvern
            [/filter]

            [effect]
                apply_to=movement
                set=3
            [/effect]

            [effect]
                apply_to=hitpoints
                heal_full=yes
                increase_total={ON_DIFFICULTY -40 -10 0}
            [/effect]

            [effect]
                apply_to=alignment
                set={ON_DIFFICULTY lawful neutral chaotic}
            [/effect]
        [/object]

        #---------------------------
        # ANT COLONY
        #---------------------------
        [event]
            name=moveto

            [filter]
                side=1
                [filter_location]
                    x,y=49-99,11-18
                [/filter_location]
            [/filter]

            [message]
                speaker=unit
                #po: a significant hint, exploring would take a long time with no reward
                message= _ "Ugh, more ants. I doubt there’s anything of value in here, just more of that lousy ambrosia."
            [/message]
        [/event]

        {GENERIC_UNIT 3 (Ant Queen) 49 8} {GUARDIAN} {FACING se}
        [modify_unit]
            [filter]
                type=Ant Queen
            [/filter]

            [object]
                [effect]
                    apply_to=overlay
                    add=misc/leader-crown.png
                [/effect]
            [/object]
        [/modify_unit]
        [event]
            name=sighted

            [filter]
                type=Ant Queen
            [/filter]

            [remove_shroud]
                side=1
                x,y=49,8
                radius=3
            [/remove_shroud]
        [/event]
        [event]
            name=die
            [filter]
                type=Ant Queen
            [/filter]

            [kill]
                type=Egg Sac,Giant Ant,Soldier Ant,Fire Ant,Firebane Ant,Firebomb Ant
                animate=yes
                fire_event=yes
            [/kill]
        [/event]

        # these items are bad; they're mostly here so the player doesn't think there's a good item somewhere in the ant colony
        {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia01  47 12} {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia02  47 18} {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia03  46 17}
        {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia04  52 16} {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia05  52 14} {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia06  53 16}
        {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia07  55 9}

        {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia11  48 8}  {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia12  49 7}  {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia13  50 7}
        {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia14  52 4}  {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia15  53 5}  {PLACE_ITEM_ANTAMBROSIA  ant_ambrosia16  49 8}

        # eggs hatch
        {GENERIC_UNIT 3 (Egg Sac) 48 6}  {GENERIC_UNIT 3 (Egg Sac) 47 7}  {GENERIC_UNIT 3 (Egg Sac) 48 7}
        {GENERIC_UNIT 3 (Egg Sac) 47 9}  {GENERIC_UNIT 3 (Egg Sac) 48 9}
        {GENERIC_UNIT 3 (Egg Sac) 50 9}
        {GENERIC_UNIT 3 (Egg Sac) 51 7}  {GENERIC_UNIT 3 (Egg Sac) 52 7}  {GENERIC_UNIT 3 (Egg Sac) 52 8}

        {GENERIC_UNIT 3 (Egg Sac) 50 4}  {GENERIC_UNIT 3 (Egg Sac) 51 4}  {GENERIC_UNIT 3 (Egg Sac) 53 4}
        {GENERIC_UNIT 3 (Egg Sac) 55 13} {GENERIC_UNIT 3 (Egg Sac) 56 13} {GENERIC_UNIT 3 (Egg Sac) 54 8}
        {GENERIC_UNIT 3 (Egg Sac) 48 11} {GENERIC_UNIT 3 (Egg Sac) 49 12}
        {GENERIC_UNIT 3 (Egg Sac) 48 16} {GENERIC_UNIT 3 (Egg Sac) 53 15}
#define HATCH
    [store_unit]
        [filter]
            type=Egg Sac
        [/filter]

        variable=eggs
    [/store_unit]
    [foreach]
        array=eggs
        variable=egg
        [do]
            [if]
                [have_unit]
                    side=1
                    [filter_location]
                        x,y=$egg.x,$egg.y
                        radius=1
                    [/filter_location]
                [/have_unit]

                [or]
                    [have_unit]
                        type=Ant Queen
                        formula=(self.hitpoints < self.max_hitpoints) # if queen is injured, all eggs pop immediately
                    [/have_unit]
                [/or]
                [then]
                    {KILL id=$egg.id ANIMATE=yes FIRE_EVENT=yes}
                    [sound]
                        name=hiss-die.wav
                    [/sound]

                    {RANDOM "Soldier Ant","Fire Ant"}
                    {GENERIC_UNIT 3 ($random) $egg.x $egg.y} {ANIMATE}
                [/then]
            [/if]
        [/do]
    [/foreach]
    {CLEAR_VARIABLE eggs}
#enddef
        [event]
            name=last breath
            [filter]
                type=Egg Sac
            [/filter]

            first_time_only=no
            {PLACE_IMAGE "units/ant/egg-sac-remains.png~CS(30,22,12)" $unit.x $unit.y}
        [/event]
        [event]
            name=side 3 turn
            first_time_only=no
            {HATCH}
        [/event]
        [event]
            name=attack end
            first_time_only=no # in case all attacks miss or something

            [filter]
                type=Ant Queen
            [/filter]

            {HATCH}
        [/event]
        [event]
            name=attack end
            first_time_only=no # in case all attacks miss or something

            [filter_second]
                type=Ant Queen
            [/filter_second]

            {HATCH}
        [/event]

        # worker ants flee
        {GENERIC_UNIT 3 (Giant Ant) 47 15}
        {GENERIC_UNIT 3 (Giant Ant) 51 15}
        {GENERIC_UNIT 3 (Giant Ant) 55 12}
        {GENERIC_UNIT 3 (Giant Ant) 54 9}
        {GENERIC_UNIT 3 (Giant Ant) 50 6}
        [micro_ai]
            side=3
            ai_type=coward
            action=add
            [filter]
                side=3
                type=Giant Ant
            [/filter]
            distance=5
            attack_if_trapped=yes
            seek_x=56
            distance=5
        [/micro_ai]
        [event] # escape
            name=moveto
            first_time_only=no
            [filter]
                side=3
                type=Giant Ant
                x=56
            [/filter]
            {KILL id=$unit.id}
        [/event]

        # front area ants
#ifndef EASY
        {NAMED_UNIT 3 (Fire Ant)    47 13 "frontguard1" "" ()}
        {NAMED_UNIT 3 (Soldier Ant) 47 13 "frontguard2" "" ()} #endif
#ifdef HARD
        {NAMED_UNIT 3 (Soldier Ant) 47 13 "frontguard3" "" ()} #endif
        [micro_ai]
            side=3
            ai_type=zone_guardian
            action=add

            [filter]
                id=frontguard1,frontguard2,frontguard3
            [/filter]

            [filter_location]
                x,y=47,13
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=47,13
                radius=4
            [/filter_location_enemy]
        [/micro_ai]

        # chasm ants
        {GENERIC_UNIT 3 {ON_DIFFICULTY (Fire Ant) (Firebomb Ant) (Firebomb Ant)} 46 17} {GUARDIAN}
        {GENERIC_UNIT 3 {ON_DIFFICULTY (Fire Ant) (Firebomb Ant) (Firebomb Ant)} 53 16} {GUARDIAN}

        # middle area ants
#ifndef EASY
        {NAMED_UNIT 3 (Soldier Ant) 54 10 "middleguard1" "" ()} #endif
#ifdef HARD
        {NAMED_UNIT 3 (Firebane Ant) 54 10 "middleguard2" "" ()}
        {NAMED_UNIT 3 (Firebane Ant) 54 10 "middleguard3" "" ()} #endif
        [micro_ai]
            side=3
            ai_type=zone_guardian
            action=add

            [filter]
                id=middleguard1,middleguard2,middleguard3
            [/filter]

            [filter_location]
                x,y=54,10
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=54,10
                radius=4
            [/filter_location_enemy]
        [/micro_ai]

        # queen guard ants
#ifndef EASY
        {NAMED_UNIT 3 (Firebane Ant) 52 5 "queenguard1" "" ()} #endif
#ifdef HARD
        {NAMED_UNIT 3 (Firebane Ant) 52 5 "queenguard2" "" ()}  #endif
        [micro_ai]
            side=3
            ai_type=zone_guardian
            action=add

            [filter]
                id=queenguard1,queenguard2
            [/filter]

            [filter_location]
                x,y=52,5
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=52,5
                radius=4
            [/filter_location_enemy]
        [/micro_ai]

        #---------------------------
        # INITIAL UNDEAD
        #---------------------------
        {NAMED_UNIT 4 ({ON_DIFFICULTY Skeleton Deathblade Draug}) 28 6 "Study Guard" (_"Study Guard") ()}
        [+unit]
            max_moves=0
        [/unit]

#ifndef EASY
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Soulless)       (Soulless)      }) 16 8} {VARIATION spider}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Walking Corpse) (Walking Corpse)}) 17 8} {VARIATION rat}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Walking Corpse) (Walking Corpse)}) 18 7} {VARIATION rat}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Walking Corpse) (Soulless)      }) 19 7} {VARIATION spider}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Soulless)       (Soulless)      }) 15 8} {VARIATION spider}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Walking Corpse) (Walking Corpse)}) 16 7} {VARIATION rat}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Soulless)       (Soulless)      }) 17 7} {VARIATION spider}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY (n/a) (Walking Corpse) (Soulless)      }) 18 6} {VARIATION spider}
#endif

        # these guys' job is to poison goblins, making them easier for the player to kill
        # but don't kill too many goblins or we deprive the player of xp
        # or if the player really wants, they can kill all the goblins first, then release the ghouls for even more xp
        {GENERIC_UNIT 4 ({ON_DIFFICULTY Ghoul      Ghoul      Ghoul     }) 24 15} {GUARDIAN}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY Ghoul      Ghoul      Ghoul     }) 25 16} {GUARDIAN}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY Ghoul      Ghoul      Ghoul     }) 27 17} {GUARDIAN}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY Ghoul      Necrophage Necrophage}) 28 17} {GUARDIAN}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY Ghoul      Ghoul      Ghoul     }) 30 18} {GUARDIAN}
        {GENERIC_UNIT 4 ({ON_DIFFICULTY Ghoul      Ghoul      Necrophage}) 31 19} {GUARDIAN}

        #---------------------------
        # INITIAL GOBLINS
        #---------------------------
        {NAMED_UNIT 5 (Goblin Spearman) 16 16 "Cowardly Goblin" (_"Cowardly Goblin") ()}
        [+unit]
            max_moves=0
        [/unit]
        {FACING se}

        # Potion Room goblins
        {NAMED_UNIT 5 (Goblin Spearman) 15 15 "Thirsty Goblin" (_"Thirsty Goblin") ()}
        [+unit]
            max_moves=0
        [/unit]
        {FACING nw}
        {NAMED_UNIT   5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Rouser) (Goblin Impaler)}) 13 16 "Thirsty_Goblin_Trigger" (_"Dushab") ()}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Rouser) (Goblin Impaler)}) 16 12}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Rouser) (Goblin Rouser) }) 15 13}
        [+unit]
            max_moves=0
        [/unit]

#ifndef EASY
        {GENERIC_UNIT 5 ({ON_DIFFICULTY (n/a) (Goblin Spearman) (Goblin Rouser) }) 12 14}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 (Goblin Spearman) 11 14}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 (Goblin Spearman) 12 15}
        [+unit]
            max_moves=0
        [/unit]

#endif

        # Ghoul Room goblins
        # reduced difficulty scaling here, since they mostly die fighting the ghouls (who also have reduced variation)
        {NAMED_UNIT 5 ({ON_DIFFICULTY (Wolf Rider) (Goblin Knight) (Direwolf Rider)}) 25 19 "Goblin Leader" (_"Goblin Leader") ()}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Spearman) (Goblin Rouser)}) 24 19}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 (Goblin Spearman) 26 20}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Rouser) (Goblin Impaler)}) 25 21}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 (Goblin Spearman) 28 19}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Spearman) (Goblin Rouser)}) 21 17}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Impaler) (Goblin Impaler)}) 21 18}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Rouser) (Goblin Impaler)}) 22 18}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 (Goblin Spearman) 23 18}
        [+unit]
            max_moves=0
        [/unit]

        {GENERIC_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Spearman) (Goblin Impaler)}) 19 18}
        [+unit]
            max_moves=0
        [/unit]

        {VARIABLE experiment_goblins_frozen yes}

        #---------------------------
        # START GAME
        #---------------------------
        [objectives]
            side=1
            [objective]
                description= _ "Move Dacyn, Gweddry, and reinforcements into the gate"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL antechamber_ready equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Find both gate keys"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL looking_for_keys equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Move Dacyn, Gweddry, and reinforcements into the inner gate"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL sanctum_antechamber_open equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Defeat the sanctum guard"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL inside_inner_sanctum equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Retrieve the amulet"
                condition=win
            [/objective]

            [objective]
                description= _ "Survive the orcish assault"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL orcs_attacking equals yes}
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry, Dacyn, or Owaec"
                condition=lose
            [/objective]

            [gold_carryover]
                bonus=no
                carryover_percentage=100
            [/gold_carryover]

            [note]
                #po: TODO in 1.19 add "... and end your turn"
                description= _ "To enter the castle, move Dacyn into the gated area."
                [show_if]
                    {VARIABLE_CONDITIONAL antechamber_ready not_equals yes}
                [/show_if]
            [/note]
            [note]
                description= _ "Dacyn has been here before and will have better outcomes when stepping on runes."
            [/note]
            [note]
                description= _ "It is winter, daytime is shorter"
            [/note]
        [/objectives]

        [remove_shroud]
            side=1
            x=30-38, 39-44,44,   45,   46,   47,   48,   49,   50,   51,   52,   53,   54-99
            y=20-99, 16-99,19-99,18-99,18-99,19-99,18-99,18-99,17-99,18-99,17-99,17-99,16-99
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x=30-38,39-58
            y=20-32,16-32
            multiturn=yes
        [/lift_fog]
    [/event]

    [event]
        name=start

        [message]
            speaker=Dacyn
            #po: Iliah-Malal was the male lich antagonist of Delfador's Memoirs, around 160 years ago
            message= _ "We have arrived. This is a long-abandoned sanctum that you may know as the lair of the mage Iliah-Malal."
        [/message]
        [message]
            speaker=Dacyn
            #po: once again Dacyn is an unreliable narrator and does not speak absolute truth, he only says what he knows
            #po: in fact the Amulet by itself can't do what he says it does, that's just his assumption
            message= _ "It is here that I seek Iliah-Malal’s Amulet of the Veil, an artifact possessing the power to open gates between the land of the living and that of the dead.

I once thought such a power too dangerous to use; I am no longer so naive."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Iliah-Malal? I know that name from the legends..."
        [/message]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Owaec
            message= _ "All this time... all this time I thought we were questing towards a noble goal. Searching for a legendary sword, an ancient tome, a holy relic."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Instead, our quest brings us to the lair of one of the most evil beings that ever lived. How can you possibly mean to make use of anything ever possessed by such an evil? As soldiers of Wesnoth we are honor-bound to fight for the Light, not the darkness!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Do not be so shortsighted. With the power to open portals to the Land of the Dead, I can pull Mal-Ravanal’s spirit out of this world. Then, the spells granting false life to the dead will fail, and their fearsome armies will collapse into piles of bones. I am wielding this power for the good of Irdya, not for your honor’s sake."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Dacyn, I am uneasy about this course of action. I know little of the Land of the Dead, but everything I have heard suggests-"
        [/message]
        [message]
            speaker=Owaec
            message= _ "You would violate the dead’s eternal peace to fight a war, yet you call me shortsighted?! And while our homeland bleeds, you have the gall to speak of the good of all life?! Madness! As a mage of the Light, you should know better!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "I have had enough of your second-guessing. You, fool of a horse boy, know nothing of the mystic arts, yet you mask your ignorance by cowering behind a pretend morality. If that is what you insist on doing, then by all means return to Wesnoth and add your corpses to Mal-Ravanal’s ever-growing hordes."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Unlike you, I have the knowledge and power to defeat the undead, and I intend to use it to destroy Mal-Ravanal. Will you wallow in your shortsightedness, or do you intend to help me safeguard all that lives?"
        [/message]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Gweddry
            message= _ "I will help you. We have come this far, and it seems a waste to turn back now."
        [/message]
        [message]
            speaker=Owaec
            message= _ "By the Clans, I will not!! Would that I had perished in battle against the undead! Better that than living to see Wesnoth’s high mage succumb to the temptation of darkness."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Gweddry, if you truly wish to aid this madman, I will guard the outer gates for you. But I will not enter that evil stronghold. I would sooner perish than travel one step closer towards Dacyn’s foul amulet."
        [/message]
    [/event]

    [event]
        name=side 1 turn 2

        [message]
            speaker=Dacyn
            message= _ "Ah, I still remember this place quite clearly. Now that I think of it, Ravan had always been very interested in the magic of darkness. Apparently, the balance between light and dark would be crucial to the safety of Irdya in the future, at least according to Ravan’s theory. In hindsight, that was all nonsense."
        [/message]
        [message]
            speaker=Owaec
            message= _ "The irony seems lost on you."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Back then this place was full of traps and undead, and it will no doubt be worse now that the wild beasts have had a chance to move in."
        [/message]

        {MOVE_UNIT id=Dacyn 36 18}
        {MODIFY_UNIT id=Dacyn facing nw}
        [delay]
            time=500
        [/delay]

        [message]
            speaker=Dacyn
            message= _ "Ravan sealed this place before our last meeting. I need a moment to remember the incantation."
        [/message]
        [delay]
            time=1500
        [/delay]
        {DACYN_FAKEATTACK}
        [message]
            speaker=Dacyn
            #po: the "red star" refers to the Ruby of Fire, and the "red stone" refers to the Amulet of the Veil FYI but these are not to be explicitly mentioned
            #po: the "black pool" would be located near or under Weldyn, but again not to be explicitly mentioned
            message= _ "The red star blazes,
The red stone bleeds.
The black pool swallows all voices,
The darkness between worlds opens its maw."
        [/message]
        [delay]
            time=500
        [/delay]
        [sound]
            name=gate-fall.ogg
        [/sound]

        {MODIFY_TERRAIN Urc^Pr/ 31 17}
        {MODIFY_TERRAIN Urc^Pr/ 32 16}
        {MODIFY_TERRAIN Urc^Pr/ 33 16}
        {MODIFY_TERRAIN Urc^Pr/ 34 15}
        {MODIFY_TERRAIN Urc^Pr/o 34 18} {MOVE_UNIT (x,y=34,18) 34 19}
        {MODIFY_TERRAIN Urc^Pr/o 35 18} {MOVE_UNIT (x,y=35,18) 35 19}
        {MODIFY_TERRAIN Urc^Pr/o 36 17} {MOVE_UNIT (x,y=36,17) 36 18}
        {MODIFY_TERRAIN Urc^Pr/o 37 17} {MOVE_UNIT (x,y=37,17) 37 18}
        [redraw]
            clear_shroud=yes
            side=1
        [/redraw]

        [message]
            speaker=Hahid al-Ali
            message= _ "Ugh, spellcasting always gives me the shivers. There’s a reason the more civilized people of my homeland don’t trifle with magic!"
        [/message]
        [message]
            speaker=Terraent
            message= _ "For a mage of the Light, the words you speak are dark indeed."
        [/message]
        [message]
            speaker=Addogin
            message= _ "I’m a simple man. I use simple tools and weapons. This magic stuff is givin’ me the creeps."
        [/message]

        [delay]
            time=500
        [/delay]

        {MODIFY_UNIT (id=Dacyn) facing se}
        [message]
            speaker=Dacyn
            message= _ "This antechamber only has room for eight. I must go to retrieve the artifact, and Gweddry has agreed to accompany me, so that leaves room for six more."
        [/message]
        {VARIABLE antechamber_ready yes}
        [show_objectives]
        [/show_objectives]
    [/event]

    # hint that Dacyn needs to enter
    [event]
        name=side 1 turn 5
        [if]
            [variable]
                name=antechamber_ready
                equals=yes
            [/variable]
            [then]
                [message]
                    speaker=Dacyn
                    #po: the player needs to choose 6 troops
                    message= _ "Gweddry, are you still choosing your troops? I must end my turn in the antechamber to cycle the gate and enter the sanctuary."
                [/message]
            [/then]
        [/if]
    [/event]

    # Owaec refuses to enter the outer lock
    [event]
        name=enter hex
        first_time_only=no
        [filter]
            id=Owaec
            x=34,35,36,37
            y=18,18,17,17
        [/filter]
        [cancel_action]
        [/cancel_action]
        [message]
            speaker=Owaec
            message= _ "I will not aid in this evil quest."
        [/message]
        # prevent blocking Owaec to force him into the sanctuary
        [if]
            [have_unit]
                x,y=$x2,$y2
            [/have_unit]
            [then]
                [store_unit]
                    [filter]
                        x,y=$x2,$y2
                    [/filter]
                    variable=stored_forcepush
                    kill=yes
                [/store_unit]
                {MOVE_UNIT (id=Owaec) $x2 $y2}
                [unstore_unit]
                    variable=stored_forcepush
                    find_vacant=yes
                [/unstore_unit]
                {CLEAR_VARIABLE stored_forcepush}
            [/then]
            [else]
                {MOVE_UNIT (id=Owaec) $x2 $y2}
            [/else]
        [/if]
    [/event]

    # Dacyn cycles the outer lock
    [event]
        name=side 1 turn
        first_time_only=no
        [if]
            [have_unit]
                id=Dacyn
                x=32,33,33,34,34,35,35,36
                y=17,17,18,16,17,16,17,16
            [/have_unit]
            [variable]
                name=antechamber_ready
                equals=yes
            [/variable]

            [then]
                [if]
                    [have_unit]
                        id=Gweddry
                        x=32,33,33,34,34,35,35,36
                        y=17,17,18,16,17,16,17,16
                    [/have_unit]
                    [then]
                        [message]
                            speaker=Dacyn
                            #po: somewhat like an airlock
                            message= _ "I am ready to cycle the gates. Gweddry, shall we proceed?"
                            [option]
                                #po: 6 soldiers
                                label= _ "Yes, these are the soldiers I want."
                                [command]
                                    [fire_event]
                                        name=enter_dungeon
                                    [/fire_event]
                                [/command]
                            [/option]
                            [option]
                                label= _ "No, not yet."
                                [command]
                                [/command]
                            [/option]
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=Dacyn
                            message= _ "Gweddry, you agreed to accompany me. We must both enter this antechamber before I cycle the gates."
                        [/message]
                    [/else]
                [/if]
            [/then]
        [/if]
    [/event]

    [event]
        name=enter_dungeon
        {INCIDENTAL_MUSIC into_the_shadows.ogg}
        {SCROLL_TO 34 18}
        {DACYN_FAKEATTACK}
        [delay]
            time=1
        [/delay]

        [sound]
            name="gate-fall.ogg"
        [/sound]

        {MODIFY_TERRAIN Urc^Pr/ 34 18} {MOVE_UNIT x,y=34,18 35 19}
        {MODIFY_TERRAIN Urc^Pr/ 35 18} {MOVE_UNIT x,y=35,18 36 18}
        {MODIFY_TERRAIN Urc^Pr/ 36 17} {MOVE_UNIT x,y=36,17 37 18}
        {MODIFY_TERRAIN Urc^Pr/ 37 17} {MOVE_UNIT x,y=37,17 38 17}
        [redraw]
            clear_shroud=yes
            side=1
        [/redraw]
        [delay]
            time=200
        [/delay]

        [sound]
            name="gate-fall.ogg"
        [/sound]

        {MODIFY_TERRAIN Urc^Pr/o 31 17}
        {MODIFY_TERRAIN Urc^Pr/o 32 16}
        {MODIFY_TERRAIN Urc^Pr/o 33 16}
        {MODIFY_TERRAIN Urc^Pr/o 34 15}
        [redraw]
            clear_shroud=yes
            side=1
        [/redraw]
        [delay]
            time=500
        [/delay]

        {CLEAR_VARIABLE antechamber_ready}

        [if]
            [have_unit]
                id=Grug
                x=32,33,33,34,34,35,35,36
                y=17,17,18,16,17,16,17,16
            [/have_unit]
            [then]
                [message]
                    speaker=Grug
                    message= _ "Cave scary! Grug no like!"
                [/message]
            [/then]
        [/if]

        [message]
            speaker=Gweddry
            #po: the torches were already burning before any of Gweddry's party entered the castle
            message= _ "The torches are lit..."
        [/message]

        [if]
            [have_unit]
                id=Dolburras
                x=32,33,33,34,34,35,35,36
                y=17,17,18,16,17,16,17,16
            [/have_unit]
            [then]
                [message]
                    speaker=Dolburras
                    #po: "I have seen my fair share of dark caves, but something about this place is making me shake."
                    message= _ "I ha’ seen my fair share o’ dark caves, but summat ’bout this place be givin’ me the shakes."
                [/message]
            [/then]
        [/if]
        [if]
            [have_unit]
                id=Terraent
                x=32,33,33,34,34,35,35,36
                y=17,17,18,16,17,16,17,16
            [/have_unit]
            [then]
                [message]
                    speaker=Terraent
                    #po: at the moment he's seeing the inside of a castle, the lit torches, and a wild wyvern
                    #po: there's nothing particularly unholy to focus on
                    message= _ "May this unholy place be cleansed by the Light!"
                [/message]
            [/then]
        [/if]
    [/event]

    # have the leader INSIDE the sanctum say something
    # no longer needed, since Gweddry is now forced inside and Owaec is forced outside
#define INSIDE_LEADER_MESSAGE MESSAGE
    [if]
        [have_unit]
            id=Gweddry
            x=0-32,33-99
            y=0-99,0-16
        [/have_unit]
        [then]
            [message]
                speaker=Gweddry
                message={MESSAGE}
            [/message]
        [/then]
        [else]
            [if]
                [have_unit]
                    id=Owaec
                    x=0-32,33-99
                    y=0-99,0-16
                [/have_unit]
                [then]
                    [message]
                        speaker=Owaec
                        message={MESSAGE}
                    [/message]
                [/then]
                [else]
                    {FIND_NEARBY (
                        side=1
                        [not]
                            id=Dacyn
                        [/not]
                    ) 1 1 99}
                    [message]
                        speaker=$found_unit.id
                        message={MESSAGE}
                    [/message]
                [/else]
            [/if]
        [/else]
    [/if]
#enddef

    # have the leader OUTSIDE the sanctum say something
#define OUTSIDE_LEADER_MESSAGE MESSAGE
    [if]
        [have_unit]
            id=Gweddry
            x=0-32,33-99
            y=0-99,0-16
        [/have_unit]
        [then]
            [message]
                speaker=Owaec
                message={MESSAGE}
            [/message]
        [/then]
        [else]
            [message]
                speaker=Gweddry
                message={MESSAGE}
            [/message]
        [/else]
    [/if]
#enddef

    #---------------------------
    # MAIN HALL EVENTS
    #---------------------------
    [event]
        name=attacker hits,attacker misses,defender hits,defender misses
        [filter_second]
            type="Wild Wyvern"
        [/filter_second]
        [message]
            speaker=second_unit
            message= _ "Hissssss..."
        [/message]
    [/event]
    [event]
        name=moveto

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

        {VARIABLE gold {ON_DIFFICULTY 200 160 130}}
        [message]
            speaker=unit
            #po: 200, 160, or 130 gold
            message= _ "This wyvern was rich! I count $gold gold in its hoard."
            sound=gold.ogg
        [/message]
        [message]
            speaker=Hahid al-Ali
            message= _ "Ho ho, northerners’ gold, now that begins to make this all worth it!"
        [/message]
        [gold]
            side=1
            amount=$gold
        [/gold]
        {REMOVE_IMAGE 27 11}
    [/event]

    [event]
        name=moveto

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

        [message]
            speaker=narrator
            #po: a signpost. "Study" as in a room with a reading desk and small library
            message= _ "East: Study and Vaults"
            image=scenery/signpost.png
        [/message]
        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=moveto

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

        [message]
            speaker=narrator
            #po: a signpost
            message= _ "West: Laboratory and Experiment Testing"
            image=scenery/signpost.png
        [/message]
        [allow_undo]
        [/allow_undo]
    [/event]

    # lava trap
    [event]
        name=enter_hex
        [filter]
            x=20,21,22
            y=10,10,9
        [/filter]

        [cancel_action]
        [/cancel_action]
        {SCROLL_TO 21 10}
        [sound]
            name=magic-dark-big-miss.ogg
        [/sound]

        {COLOR_ADJUST 127 64 127}
        [delay]
            time=100
        [/delay]

        {COLOR_ADJUST -127 -191 -127}
        [delay]
            time=100
        [/delay]

        {COLOR_ADJUST 127 64 127}
        [delay]
            time=100
        [/delay]

        {COLOR_ADJUST 0 0 0}

        {REMOVE_IMAGE 20 10}
        {REMOVE_IMAGE 21 10}
        {REMOVE_IMAGE 22 9}
        {PLACE_IMAGE scenery/rune_line.png 20 10}
        {PLACE_IMAGE scenery/rune_line.png 21 10}
        {PLACE_IMAGE scenery/rune_line.png 22 9}

        [if]
            {VARIABLE_CONDITIONAL unit.id equals Dacyn}
            [then]
                [message]
                    speaker=Dacyn
                    message= _ "I have triggered a trap. As long as I stay on this rune I will be safe, but once I step away, fire spirits will rise from the lava."
                [/message]
            [/then]

            [else]
                [if]
                    {VARIABLE_CONDITIONAL unit.side equals 1}
                    [then]
                        [message]
                            speaker=unit
                            #po: the feeling that they've triggered a trap
                            message= _ "Uh oh..."
                        [/message]
                        [delay]
                            time=2000
                        [/delay]

                        [message]
                            speaker=unit
                            #po: no obvious effect yet, it triggers when that unit moves again
                            message= _ "Oh, nothing happened."
                        [/message]
                    [/then]

                    [else]
                        [message]
                            speaker=Dacyn
                            #po: a walking corpse of a rat or spider
                            message= _ "That corpse has triggered a trap. When next it moves, fire spirits will rise from the lava."
                        [/message]
                    [/else]
                [/if]
            [/else]
        [/if]

        # move away event
        [event]
            name=enter_hex
            [filter]
                x=20,21,22,23,19,20,21,22
                y=11,11,10,10,10, 9, 9, 8
                id=$unit.id
            [/filter]
            delayed_variable_substitution=no

            [cancel_action]
            [/cancel_action]
            [sound]
                name="melee-fire.ogg"
            [/sound]

            # spawn wraiths on side 2 (orcs), because they need to be hostile to everyone else inside the sanctuary
            {GENERIC_UNIT 2 ({ON_DIFFICULTY "Fire Guardian" "Fire Guardian" "Fire Wraith"}) 22 7}
            {GENERIC_UNIT 2 ({ON_DIFFICULTY "Fire Guardian" "Fire Guardian" "Fire Wraith"}) 16 10}
#ifndef EASY
            {GENERIC_UNIT 2 ({ON_DIFFICULTY "n/a"           "Fire Guardian" "Fire Wraith"}) 24 8}
            {GENERIC_UNIT 2 ({ON_DIFFICULTY "n/a"           "Fire Guardian" "Fire Wraith"}) 18 11}

            {GENERIC_UNIT 2 ({ON_DIFFICULTY "n/a"           "Fire Guardian" "Fire Wraith"}) 21 12} # these 2 prevent fleeing, unless you're a skirmisher
            {GENERIC_UNIT 2 ({ON_DIFFICULTY "n/a"           "Fire Guardian" "Fire Wraith"}) 24 10}
#endif
        [/event]
    [/event]

    #---------------------------
    # EAST HALL, SOUTH EVENTS
    #---------------------------
    # vault door traps
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            id=Dacyn
            x=33,38
            y=10,12
        [/filter]
        [message]
            speaker=Dacyn
            #po: the rune is on the floor in front of the door (using one of the terrains that make the rune occupy most of the hex)
            message= _ "This gate is locked, and I recognize the petrification trap concealed within its guardian rune. I should avoid trying to open it."
        [/message]
    [/event]

#define PETRIFY
    [if]
        {VARIABLE_CONDITIONAL unit.side equals 1}
        [then]
            [message]
                speaker=unit
                #po: the rune is on the floor in front of the door (using one of the terrains that make the rune occupy most of the hex)
                message= _ "Looks like this gate is locked. I wonder if this rune opens it?"
            [/message]
        [/then]
    [/if]
    [sound]
        name=lightning.ogg
    [/sound]

    {COLOR_ADJUST 127 127 127}

    {VARIABLE damage $unit.hitpoints}
    {VARIABLE_OP damage multiply 0.5} # 50% of current health
    [harm_unit]
        [filter]
            id=$unit.id
        [/filter]
        amount=$damage
        animate=yes
        kill=no
    [/harm_unit]
    {CLEAR_VARIABLE damage}

    {REMOVE_IMAGE $unit.x $unit.y}
    {PLACE_IMAGE scenery/rune6.png $unit.x $unit.y}
    [delay]
        time=100
    [/delay]

    {COLOR_ADJUST 0 0 0}
    [delay]
        time=1000
    [/delay]

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

    {MODIFY_UNIT (id=$unit.id) status.petrified yes}
    [delay]
        time=1000
    [/delay]

    [if]
        {VARIABLE_CONDITIONAL unit.side equals 1}
        [then]
            [message]
                speaker=Dacyn
                message= _ "That was a petrification rune. It should wear off in a few moments."
            [/message]
        [/then]

        [else]
            [message]
                speaker=Dacyn
                message= _ "We are fortunate, that enemy has triggered a petrification rune. Be warned though, it will only last a few moments."
            [/message]
        [/else]
    [/if]
#enddef
    [event]
        name=moveto

        [filter]
            x,y=33,10
            [not]
                id=Dacyn
            [/not]
        [/filter]

        {PETRIFY}
    [/event]
    [event]
        name=moveto

        [filter]
            x,y=38,12
            [not]
                id=Dacyn
            [/not]
        [/filter]

        {PETRIFY}
    [/event]

    # un-petrify anyone who got petrified
    [event]
        name=side 1 turn refresh
        first_time_only=no
        {MODIFY_UNIT side=2,3,4,5,6,7,8,9 status.petrified no}
    [/event]
    [event]
        name=side 1 turn end
        first_time_only=no
        {MODIFY_UNIT (side=1) status.petrified no}
    [/event]

    # spawn vault defender
    [event]
        name=enter_hex
        [filter]
            side=1
            x,y=43,12
        [/filter]
        [cancel_action]
        [/cancel_action]
        [message]
            speaker=unit
            #po: the unit triggers the trap immediately
            message= _ "Hmm, looks like a magic lamp. I’ve heard stories that these can grant wishes. Today must be my lucky day!"
        [/message]

        {QUAKE cave-in.ogg}
        [delay]
            time=1500
        [/delay]

        [sound]
            name=melee-fire.ogg
        [/sound]

        # the petrification traps are pretty good against this guy, if you can lure him onto them
        {NAMED_UNIT 2 (Jinn) 42 11 "Jinn" "" ()} {FACING se} {ANIMATE}
        [object]
            [filter]
                type=Jinn
            [/filter]

            [effect]
                apply_to=hitpoints
                heal_full=yes
                increase_total={ON_DIFFICULTY -28 -8 12}
            [/effect]

            [effect]
                apply_to=alignment
                set={ON_DIFFICULTY lawful neutral chaotic}
            [/effect]
        [/object]

        [delay]
            time=500
        [/delay]

        [message]
            speaker=Jinn
            message= _ "WHO DARES DISTURB MY SLUMBER?"
        [/message]
    [/event]

    # worthless green cloak
    [event]
        name=moveto
        [filter]
            side=1
            x,y=38,10
        [/filter]
        [message]
            speaker=unit
            #po: an item on a display rack, ready to be worn
            message= _ "This fine silken cloak would be priceless back in Wesnoth, but is useless to us here."
        [/message]
    [/event]

    # open vault chests
    [event]
        name=moveto

        [filter]
            side=1
            x,y=43,10
        [/filter]

        {REMOVE_IMAGE 43 10}
        {PLACE_IMAGE "items/chest-open.png~FL(horiz)" 43 10}
        {VARIABLE gold {ON_DIFFICULTY 70 55 45}}
        [message]
            speaker=unit
            sound=gold.ogg
            #po: 70, 55, or 45 gold
            message= _ "This chest contains $gold gold!"
        [/message]
        [gold]
            side=1
            amount=$gold
        [/gold]
    [/event]
    [event]
        name=moveto

        [filter]
            side=1
            x,y=42,9
        [/filter]

        {REMOVE_IMAGE 42 9}
        {PLACE_IMAGE "items/chest-open.png~FL(horiz)" 42 9}
        [message]
            speaker=unit
            #po: there was a closed chest on this hex, and it's been opened
            message= _ "It’s full of... toilet paper?!?"
        [/message]
    [/event]

    # unlock treasure room
    [event]
        name=moveto
        [filter]
            side=1
            x=39,40
            y=11,11
        [/filter]
        [message]
            speaker=unit
            #po: and the unit immediately does that, changing a closed-gate terrain to open-gate
            message= _ "I can unlock this gate from the inside."
        [/message]
        {MODIFY_TERRAIN Ias^Pr\o 39 12}
    [/event]

    #---------------------------
    # EAST HALL, NORTH EVENTS
    #---------------------------
    # study guard
    [event]
        name=enter_hex
        [filter]
            side=1
            x,y=29,7
        [/filter]

        [cancel_action]
        [/cancel_action]
        [message]
            speaker=Study Guard
            #po: the Study Guard is a Deathblade (or Draug on hard difficulty) that's stood immobile in the doorway
            message= _ "Who. Comes?"
        [/message]
        [message]
            speaker=unit
            message= _ "Err... don’t mind me, I’m just taking a look around."
        [/message]
        [message]
            speaker=Study Guard
            message= _ "Master. Is away. Intruders. Must die."
        [/message]
        {MODIFY_UNIT (id=Study Guard) max_moves 5}

#ifndef EASY
        {GENERIC_UNIT 4 (Ghost) 29 2} {ANIMATE}
        {GENERIC_UNIT 4 (Ghost) 26 2} {ANIMATE}
        {GENERIC_UNIT 4 (Ghost) 32 3} {ANIMATE}
#endif
#ifdef HARD
        {GENERIC_UNIT 4 (Wraith) 30 2} {ANIMATE}
        {GENERIC_UNIT 4 (Ghost) 28 3} {ANIMATE}
        {GENERIC_UNIT 4 (Ghost) 25 7} {ANIMATE}
#endif
    [/event]

    # necromancy book in study
    [event]
        name=moveto
        [filter]
            side=1
            x,y=28,5
            [not]
                id=Dacyn
            [/not]
        [/filter]

        [filter_condition]
            {VARIABLE_CONDITIONAL book_found not_equals yes}
        [/filter_condition]

        [message]
            speaker=unit
            #po: a quote from the journal written in SotA, also quoted in DiD
            message= _ "What’s this? Looks like a book on necromancy? <i>‘To become a lich, one must first-</i>"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Drop that at once! That journal is dangerous!"
        [/message]
        {VARIABLE book_found yes}
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x,y=28,5
            id=Dacyn
        [/filter]

        [if]
            {VARIABLE_CONDITIONAL book_count equals yes}
            [then]
                [message]
                    speaker=Dacyn
                    #po: a book on necromancy
                    message= _ "I recognize this volume. Such a thing could be dangerous in the wrong hands. Perhaps I should hold on to it... for safekeeping."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Dacyn
                    message= _ "... I recognize this volume. It is fortunate that I found it first; such a thing could be dangerous in the wrong hands. Perhaps I should hold on to it... for safekeeping."
                [/message]
            [/else]
        [/if]
        {REMOVE_IMAGE 28 5}
        {VARIABLE book_found yes}
    [/event]

    # east study flavor books
    [event]
        name=moveto

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

        [message]
            speaker=unit
            message= _ "There are a few loose pages on the ground here..."
        [/message]
        [message]
            speaker=unit
            message= _ "<i>Journal of Ravan - 13 Blackfire, 588 YW.

This expedition is proving a greater success than I had anticipated. While Dacyn disarms the traps littered around this place, I have been able to conduct extensive research into the other plane beyond the Maw. There is a realm of souls that can be reached from our very own world, one that Iliah-Malal doubtlessly made contact with using the Amulet of the Veil. From time to time, I hear spirits whispering from the other side, but their voices are faint as of yet. I suspect that if I can somehow reach them, they will be able to answer some of the questions I have been pondering. However, there seems to be a piece of the puzzle still missing.</i>"
        [/message]
        [message]
            speaker=unit
            message= _ "<i>Journal of Ravan - 21 Whitefire, 589 YW.

I had a dream tonight. Was it a dream? It seemed much more like a vision. I saw a scorching light from twin orbs in the sky, radiating searing brightness over a land teeming with aberrations of constantly shifting flesh. I saw a jewel, no, a key, alight with fire bridging the vast nothingness of the Maw. I saw darkness, merged with light and transfigured, rending the indestructible core of those without form. I hear voices recounting these muddled dreams, yet their words are disjointed, incomprehensible. What are they trying to tell me?</i>"
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            side=1
            x,y=29,4
        [/filter]
        [message]
            speaker=unit
            message= _ "This volume has something to do with a dwarf named Tharga... Thursag-something? The text is very faded."
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            side=1
            x,y=30,3
        [/filter]
        [message]
            speaker=unit
            message= _ "<i>Journal of Ravan - 5 Bleeding Moon, 597 YW.

Nothing is going well. My research has come to a dead end and even the spirits from the other plane no longer speak to me. I can no longer rely on Dacyn either. That stupid man! He decided that playing politics would be a better use of his abilities than helping me decipher this crucial puzzle. As if he could do any good, being the advisor to that half-decrepit old King Haldric. Then again, maybe that is the game Dacyn wants to play. What a shame. I had held him in higher regard than that.</i>"
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            side=1
            x,y=30,2
        [/filter]
        [message]
            speaker=unit
            #po: just flavortext, could be any books that are irrelevant to the story
            message= _ "This shelf appears to be full of accounting ledgers detailing the movement of funds and goods hundreds of years ago."
        [/message]
    [/event]

    # east study flavor boxes
    [event]
        name=moveto
        [filter]
            side=1
            x,y=26,3
        [/filter]
        [message]
            speaker=unit
            #po: a wooden crate, using the items/box.png image
            message= _ "This box is empty."
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            side=1
            x,y=25,3
        [/filter]
        [message]
            speaker=unit
            #po: a wooden crate, using the items/box.png image
            message= _ "Yuck, this box is full of pickled fingers!"
        [/message]
    [/event]
    [event]
        name=moveto
        [filter]
            side=1
            x,y=26,2
        [/filter]
        [message]
            speaker=unit
            #po: a barrel, using items/barrel.png
            message= _ "This cask of wine is from nearly 200 years ago! If only I was allowed to drink while on duty."
        [/message]
    [/event]

    # east study flavor orbs
    [event]
        name=moveto
        [filter]
            side=1
            x=30,31,32
            y=5,5,4
        [/filter]
        [message]
            speaker=unit
            message= _ "These three orbs must be ancient, but still pulse with some kind of dark energy. Just standing near them gives me a splitting headache."
        [/message]
    [/event]

    # east key
    [event]
        name=moveto
        [filter]
            side=1
            x,y=28,2
        [/filter]
        [message]
            speaker=unit
            message= _ "I’ve found a key! It must be magical; it started glowing as soon as I touched it."
        [/message]

        {VARIABLE east_key yes}
        {REMOVE_IMAGE 28 2}
        [if]
            [variable]
                name=west_key
                equals=yes
            [/variable]
            [then]
                [fire_event]
                    name=unlock_sanctum
                [/fire_event]
            [/then]
        [/if]
    [/event]

    #---------------------------
    # WEST HALL EVENTS
    #---------------------------
    # cowardly goblin
    [event]
        name=sighted

        [filter]
            id=Cowardly Goblin
        [/filter]

        {SCROLL_TO 19 15}
        [message]
            speaker=Cowardly Goblin
            #po: Cowardly Goblin is male, and appears in just two events. This one, and the end-of-level event.
            message= _ "Aaah, humans! Run away!"
        [/message]
        {MOVE_UNIT (id=Cowardly Goblin) 19 22}
        {KILL (id=Cowardly Goblin)}

        [message]
            speaker=second_unit
            message= _ "I guess there are goblins living here. Well, that explains the lit torches."
        [/message]
    [/event]

    # thirsty goblin
    [event]
        name=sighted
        [filter]
            id=Thirsty_Goblin_Trigger
        [/filter]

        {SCROLL_TO 14 14}
        [message]
            speaker=Thirsty Goblin
            #po: the goblin has moved to a hex with a green potion bottle. After this he drinks it, gets poisoned, and then turns into a walking corpse.
            message= _ "Hey, this looks tasty!"
        [/message]
        {MOVE_UNIT (id=Thirsty Goblin) 14 14}
        [sound]
            name=potion.ogg
        [/sound]

        {REMOVE_IMAGE 14 14}
        [delay]
            time=3000
        [/delay]

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

        {MODIFY_UNIT (id=Thirsty Goblin) status.poisoned yes}
        [delay]
            time=300
        [/delay]

        {KILL (id=Thirsty Goblin) ANIMATE=yes}
        [delay]
            time=500
        [/delay]

        {NAMED_UNIT 3 (Walking Corpse) 14 14 "Thirsty Goblin" (_"Thirsty Goblin") ()} {VARIATION goblin}
        [sound]
            name=zombie-attack.wav
        [/sound]

        # un-freeze the laboratory goblins
        {MODIFY_UNIT (x,side=1-16,5) max_moves 5}
    [/event]

    # blue potion
    [event]
        name=moveto
        [filter]
            side=1
            x,y=10,14
        [/filter]
        [sound]
            name=potion.ogg
        [/sound]

        {REMOVE_IMAGE 10 14}
        [delay]
            time=3000
        [/delay]

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

        {MODIFY_UNIT (id=$unit.id) status.slowed yes}
        [message]
            speaker=unit
            #po: the player's unit has moved to a hex with a blue potion, drunk it, and become slowed
            message= _ "Ugh, my head hurts. Was this room always spinning?"
        [/message]
    [/event]

    # yellow potion
    [event]
        name=moveto
        [filter]
            side=1
            x,y=15,12
        [/filter]
        [sound]
            name=potion.ogg
        [/sound]

        {REMOVE_IMAGE 15 12}
        [delay]
            time=3000
        [/delay]

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

        {MODIFY_UNIT (id=$unit.id) status.poisoned yes}
        [message]
            speaker=unit
            #po: the player's unit has moved to a hex with a yellow potion, drunk it, and become poisoned
            message= _ "Blech, this tastes awful! Whatever used to be in here, it went bad long ago."
        [/message]
    [/event]

    # grey potion
    [event]
        name=moveto
        [filter]
            side=1
            x,y=17,13
        [/filter]
        [sound]
            name=potion.ogg
        [/sound]

        {REMOVE_IMAGE 17 13}
        [delay]
            time=3000
        [/delay]

        [message]
            speaker=unit
            #po: the player's unit has moved to a hex with a grey potion, drunk it, and ...
            message= _ "ACK! I’M DYING!"
        [/message]
        [delay]
            time=500
        [/delay]

        [message]
            speaker=unit
            #po: the grey potion
            message= _ "Hah, just messing with you, it’s only water."
        [/message]
    [/event]

    # reveal ghouls in cages
    [event]
        name=sighted

        [filter]
            id=Goblin Leader
        [/filter]

        [remove_shroud]
            side=1
            x=19,20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31
            y=18,17-18,17-20,16-20,16-20,15-20,16-21,16-21,17-21,17-20,18-20,18-19,19
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x=19,20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31
            y=18,17-18,17-20,16-20,16-20,15-20,16-21,16-21,17-21,17-20,18-20,18-19,19
        [/lift_fog]

        {SCROLL_TO 25 18}
        [message]
            speaker=second_unit
            #po: the player's unit is outside the room with all of this in
            message= _ "Look, a key! But it’s guarded by all those goblins... and there are ghasts in cages!"
        [/message]
        [message]
            speaker=second_unit
            #po: the player's unit is outside the room with ghasts and goblins in, and there are a lot of campfires in there too
            message= _ "The goblins’ eyes must be blinded by their fires. I still haven’t been spotted."
        [/message]
    [/event]

    # release ghouls in cages
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=24,22

            [not]
                id=Dacyn
            [/not]
        [/filter]

        [filter_condition]
            {VARIABLE_CONDITIONAL ghouls_released not_equals yes}
        [/filter_condition]

        [message]
            speaker=unit
            #po: rune on the floor that will open floor-to-ceiling gates
            message= _ "Hmm, it looks like this rune is connected to those cages. I’ll bet I could get one of them open..."
            [option]
                label= _ "Yes, release some ghouls."
                [command]
                    [lift_fog]
                        [filter_side]
                            side=1
                        [/filter_side]
                        x=19,20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31
                        y=18,17-18,17-20,16-20,16-20,15-20,16-21,17-21,17-21,17-20,18-20,18-19,19
                    [/lift_fog]
                    {SCROLL_TO 25 18}
                    {MODIFY_TERRAIN Uu^Pr\o 26 17}
                    [sound]
                        name="gate-fall.ogg"
                    [/sound]

                    [redraw]
                    [/redraw]
                    [delay]
                        time=300
                    [/delay]

                    {VARIABLE ghouls_released yes}
                    [message]
                        speaker=Goblin Leader
                        message= _ "Aaahh!! The monsters have escaped!"
                    [/message]
                    # un-freeze the experiment goblins
                    {MODIFY_UNIT (x,side=19-29,5) max_moves 5}
                    {CLEAR_VARIABLE experiment_goblins_frozen}

                    {REMOVE_IMAGE 24 22}
                    {PLACE_IMAGE scenery/rune4.png 24 22}
                [/command]
            [/option]
            [option]
                label= _ "No, keep them locked up."
                [command]
                    # do nothing
                [/command]
            [/option]
        [/message]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=24,22
            id=Dacyn
        [/filter]

        [filter_condition]
            {VARIABLE_CONDITIONAL ghouls_released not_equals yes}
        [/filter_condition]

        [message]
            speaker=Dacyn
            #po: rune on the floor that will open floor-to-ceiling gates
            message= _ "Ah, this is the control for the experiment testing cages. Should I open them?"
            [option]
                label= _ "Yes, release all the ghouls."
                [command]
                    [lift_fog]
                        [filter_side]
                            side=1
                        [/filter_side]
                        x=19,20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31
                        y=18,17-18,17-20,16-20,16-20,15-20,16-21,17-21,17-21,17-20,18-20,18-19,19
                    [/lift_fog]
                    {SCROLL_TO 25 18}
                    {MODIFY_TERRAIN Uu^Pr\o 23 16}
                    [sound]
                        name="gate-fall.ogg"
                    [/sound]

                    [redraw]
                    [/redraw]
                    [delay]
                        time=300
                    [/delay]

                    {MODIFY_TERRAIN Uu^Pr\o 26 17}
                    [sound]
                        name="gate-fall.ogg"
                    [/sound]

                    [redraw]
                    [/redraw]
                    [delay]
                        time=300
                    [/delay]

                    {MODIFY_TERRAIN Uu^Pr\o 30 19}
                    [sound]
                        name="gate-fall.ogg"
                    [/sound]

                    [redraw]
                    [/redraw]
                    [delay]
                        time=300
                    [/delay]

                    {VARIABLE ghouls_released yes}
                    [message]
                        speaker=Goblin Leader
                        message= _ "Aaahh!! The monsters have escaped!"
                    [/message]
                    # un-freeze the experiment goblins
                    {MODIFY_UNIT (x,side=19-29,5) max_moves 5}
                    {CLEAR_VARIABLE experiment_goblins_frozen}

                    {REMOVE_IMAGE 24 22}
                    {PLACE_IMAGE scenery/rune4.png 24 22}
                [/command]
            [/option]
            [option]
                label= _ "No, keep them locked up."
                [command]
                    # do nothing
                [/command]
            [/option]
        [/message]
    [/event]

    # un-freeze the experiment goblins
    [event]
        name=enter_hex
        [filter]
            side=1
            x=21,22,23
            y=19,19,20
        [/filter]

        [cancel_action]
        [/cancel_action]
        [if]
            [variable]
                name=experiment_goblins_frozen
                equals=yes
            [/variable]
            [then]
                [message]
                    speaker=Goblin Leader
                    message= _ "Humans! Get them!"
                [/message]
                {CLEAR_VARIABLE experiment_goblins_frozen}
                {MODIFY_UNIT (x,side=19-29,5) max_moves 5}
            [/then]
        [/if]
    [/event]

    # goblin leader dies
    [event]
        name=die

        [filter]
            id=Goblin Leader
        [/filter]

        {KILL (id=Goblin Leader)}
        {NAMED_UNIT 5 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Rouser) (Goblin Rouser)}) $unit.x $unit.y "Goblin Leader" _"Goblin Leader" ()} {ANIMATE}
        [message]
            speaker=Goblin Leader
            #po: death of a wolf rider's mount
            message= _ "Noooo, wolfieeee!!!"
        [/message]
    [/event]

    # west key
    [event]
        name=moveto

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

        [message]
            speaker=unit
            message= _ "Look what I found! This key started glowing as soon as I touched it."
        [/message]

        {VARIABLE west_key yes}
        {REMOVE_IMAGE 25 18}
        [if]
            [variable]
                name=east_key
                equals=yes
            [/variable]
            [then]
                [fire_event]
                    name=unlock_sanctum
                [/fire_event]
            [/then]
        [/if]
    [/event]

    # secret room
    {PLACE_IMAGE scenery/summoning-center.png 12 25}
    {PLACE_IMAGE items/secret-item.png 12 25}

    {PLACE_IMAGE scenery/summoning-circle1.png 11 25}
    {PLACE_IMAGE scenery/summoning-circle2.png 13 25}
    {PLACE_IMAGE scenery/summoning-circle3.png 11 26}
    {PLACE_IMAGE scenery/summoning-circle4.png 13 26}
    [event]
        name=moveto
        [filter]
            side=1
            x,y=12,25
        [/filter]
        [sound]
            name=zombie-hit-1.ogg
        [/sound]

        [message]
            speaker=unit
            #po: although there's no filter on this event, the location is only reachable by a flying unit, presumably a walking corpse bat or walking corpse drake
            message= _ "Ruuuh... Brains..."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            #po: This is an easter egg, and the details don't matter because there's no way to get the staff out of the room.
            message= _ "This legendary magical staff has the power to reshape reality at will! Unfortunately, this zombie is not intelligent enough to understand the significance of what it has found, and merely perceives a lifeless room."
        [/message]
        [set_achievement]
            content_for=eastern_invasion
            id=ei_S10
        [/set_achievement]
    [/event]

    #---------------------------
    # SANCTUM EVENTS
    #---------------------------
    # lock sanctum
    [event]
        name=enter hex
        [filter]
            side=1
            x=25,26,27,28,29,30,31
            y=14,13,13,12,12,11,11
        [/filter]
        [if]
            [variable]
                name=sanctum_antechamber_open
                equals=yes
            [/variable]
            [then]
            [/then]
            [else]
                [remove_shroud]
                    side=1
                    x,y=21,10
                    radius=3
                [/remove_shroud]
                [lift_fog]
                    [filter_side]
                        side=1
                    [/filter_side]
                    x,y=21,10
                    radius=3
                [/lift_fog]
                {SCROLL_TO 19 9}
                [message]
                    speaker=Dacyn
                    message= _ "The Amulet should be just beyond that gate, within the inner sanctum. We will have to find a pair of magical keys to open the door."
                    scroll=no
                [/message]
                {VARIABLE looking_for_keys yes}
                [show_objectives]
                [/show_objectives]
            [/else]
        [/if]
    [/event]

    # unlock sanctum antechamber
    [event]
        name=unlock_sanctum
        [message]
            speaker=Dacyn
            message= _ "Both keys are found! We can now enter the inner sanctum and retrieve the Amulet."
        [/message]
        {CLEAR_VARIABLE looking_for_keys}
        {CLEAR_VARIABLE west_key}
        {CLEAR_VARIABLE east_key}

        {SCROLL_TO 18 7}
        [delay]
            time=500
        [/delay]

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

        {MODIFY_TERRAIN Urc^Pr/o 17 9}
        {MODIFY_TERRAIN Urc^Pr/o 18 8}
        {MODIFY_TERRAIN Urc^Pr/o 19 8}
        {MODIFY_TERRAIN Urc^Pr/o 20 7}
        {MODIFY_TERRAIN Urc^Pr/ 14 7}
        {MODIFY_TERRAIN Urc^Pr/ 15 7}
        {MODIFY_TERRAIN Urc^Pr/ 16 6}
        {MODIFY_TERRAIN Urc^Pr/ 17 6}
        [redraw]
            clear_shroud=yes
            side=1
        [/redraw]

        [message]
            speaker=Gweddry
            #po: by this time Owaec is probably fighting orcs
            message= _ "I hope Owaec hasn’t gotten into any trouble outside..."
        [/message]

        {VARIABLE sanctum_antechamber_open yes}
        [show_objectives]
        [/show_objectives]
    [/event]

    # cycle sanctum antechamber
    [event]
        name=side 1 turn
        first_time_only=no
        [if]
            [have_unit]
                id=Dacyn
                x=15,16,17,18, 16,17,18,19
                y= 8, 7, 7, 6,  8, 8, 7, 7
            [/have_unit]
            [variable]
                name=sanctum_antechamber_open
                equals=yes
            [/variable]

            [then]
                [message]
                    speaker=Dacyn
                    message= _ "Are we ready to enter the inner sanctum?"
                    [option]
                        label= _ "Yes, I’m ready."
                        [command]
                            # spawn a few undead defenders
                            {GENERIC_UNIT 4 ({ON_DIFFICULTY (Skeleton Archer) (Bone Shooter) (Bone Shooter)}) 5 5}
                            {GENERIC_UNIT 4 ({ON_DIFFICULTY Skeleton Revenant Draug}) 11 8}
                            {GENERIC_UNIT 4 ({ON_DIFFICULTY Skeleton Skeleton Revenant}) 19 4}

                            {NAMED_UNIT 4 ("Death Knight") 9 3 "Sanctum Guard" (_"Sanctum Guard") ()}
                            [+unit]
                                max_moves=0
                            [/unit]

                            {MODIFY_UNIT id="Sanctum Guard" canrecruit yes}

                            # open the gates
                            {SCROLL_TO 17 9}
                            [sound]
                                name=gate-fall.ogg
                            [/sound]

                            {MODIFY_TERRAIN Urc^Pr/ 17 9} {MOVE_UNIT (x,y=17,9) 18 9}
                            {MODIFY_TERRAIN Urc^Pr/ 18 8} {MOVE_UNIT (x,y=18,8) 19 9}
                            {MODIFY_TERRAIN Urc^Pr/ 19 8} {MOVE_UNIT (x,y=19,8) 20 8}
                            {MODIFY_TERRAIN Urc^Pr/ 20 7} {MOVE_UNIT (x,y=20,7) 21 8}
                            {MODIFY_TERRAIN Urc^Pr/o 14 7}
                            {MODIFY_TERRAIN Urc^Pr/o 15 7}
                            {MODIFY_TERRAIN Urc^Pr/o 16 6}
                            {MODIFY_TERRAIN Urc^Pr/o 17 6}
                            [redraw]
                                clear_shroud=yes
                                side=1
                            [/redraw]
                            {REPLACE_SCENARIO_MUSIC silence.ogg}

                            # warning taunt
                            {SCROLL_TO 13 5}
                            [delay]
                                time=2000
                            [/delay]

                            [message]
                                speaker=Gweddry
                                #po: looking at it from about 3 indoor hexes away
                                message= _ "Is that... the Amulet?"
                            [/message]
                            [message]
                                speaker="Dacyn"
                                message= _ "Yes. We now look upon one of the most powerful artifacts ever to taint Irdya. But first, we must clear out this room."
                            [/message]
                            [message]
                                speaker="Sanctum Guard"
                                message= _ "TRESSPASSERS!"
                            [/message]
                            [message]
                                speaker=Gweddry
                                message= _ "Prepare for incoming undead!"
                            [/message]
                            [modify_side]
                                side=4
                                gold={ON_DIFFICULTY 20 60 100}
                            [/modify_side]

                            {REPLACE_SCENARIO_MUSIC vengeful.ogg}

                            {CLEAR_VARIABLE sanctum_antechamber_open}
                            {VARIABLE inside_inner_sanctum yes}
                            [show_objectives]
                            [/show_objectives]
                        [/command]
                    [/option]
                    [option]
                        label= _ "No, not yet."
                        [command]
                            # do nothing
                        [/command]
                    [/option]
                [/message]
            [/then]
        [/if]
    [/event]

    #---------------------------
    # ORCISH ATTACKS
    #---------------------------
    [event]
        name=turn 9
        {REPLACE_SCENARIO_MUSIC northerners.ogg}

        {NAMED_UNIT 2 (Orcish Sovereign) 50 30 "Chief Dra-Nak" (_"Chief Dra-Nak") ()}
        [+unit]
            profile=portraits/orcs/ruler-2.webp
            canrecruit=yes
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
        {SCROLL_TO 50 30}

        [message]
            speaker="Chief Dra-Nak"
            #po: the wyrms being the drakes in S09
            #po: Talking about Owaec, who's waiting outside the sanctum, probably on a keep.
            #po: Owaec probably hasn't recruited, but the entire recall list is available to him so they're presumably "here".
            message= _ "What do we have here? This is what those wyrms were groveling about?"
        [/message]
        [message]
            speaker="Chief Dra-Nak"
            #po: he's a chief from the Whitefangs because he's not the only one, just a particularly powerful one
            message= _ "I’m Dra-Nak, Chief from the Whitefang clan. What’re you doing so far away from home, human?"
        [/message]
        [message]
            speaker=Owaec
            message= _ "I am a lord of the Horse Clans, and we are here on Wesnoth business. You would do well not to bother us."
        [/message]
        [message]
            speaker="Chief Dra-Nak"
            message= _ "Wesnoth business, huh. ...you’re not the first group of deserters I’ve caught fleeing the undead."
        [/message]
        [message]
            speaker="Chief Dra-Nak"
            message= _ "I’ll tell you what. I’m a fair orc, I won’t take advantage of your situation. Maybe I can help you. Let’s make a deal."
        [/message]
        [message]
            speaker="Chief Dra-Nak"
            message= _ "Those necromancers down south are paying me good coin to keep them supplied with corpses. Hand over, let’s say, eight of your soldiers as tribute, and you’re free to go about your business. I’ll even give you a cut of the profit!"
        [/message]
        [message]
            speaker=Owaec
            message= _ "Today I have been called shortsighted, then a coward, and now a deserter?! My honor will stand no more insult! Begone, fetid orc, lest I mount your head on a pike! I don’t fear the dead and I don’t fear you."
        [/message]
        [message]
            speaker="Chief Dra-Nak"
            #po: This is the start of the second night, and around 4 orcs will enter the map this turn, and 3 more next turn.
            message= _ "(grinning) I was hoping you’d say that!"
        [/message]
        {KILL id="Chief Dra-Nak"}
        {MOVE_UNIT id=Owaec 42 19} # hint that Owaec can recruit, if the player isn't already aware.

        {VARIABLE orcs_attacking yes}
        [show_objectives]
        [/show_objectives]

        # ensure the player is aware that Owaec can recruit. He's been able to since you first got him back in S05, but this is the first scenario where it's important.
        # the scenario is both unfun and extremely difficult without this knowledge.
        [event]
            name=side 5 turn end
            id=owaec_can_recruit_reminder
            [message]
                speaker=Owaec
                #po: this is a reminder to the player that Owaec is a leader and can recruit.
                message= _ "Gweddry may command the whole of our party, but do not forget that I too can recruit and recall! I will need soldiers to hold the line against these orcs."
            [/message]
        [/event]
        [event]
            name=recruit,recall
            [filter_second]
                id=Owaec
            [/filter_second]
            [remove_event]
                id=owaec_can_recruit_reminder
            [/remove_event]
        [/event]
    [/event]

#define REINFORCE_AFTER_NOATTACK TURN SIDE TYPE SPAWN_X SPAWN_Y
    [if]
        [variable]
            name=turn_number
            greater_than_equal_to={TURN}
        [/variable]
        [then]
            {GENERIC_UNIT {SIDE} ({TYPE}) {SPAWN_X} {SPAWN_Y}}
            [+unit]
                attacks_left=0
            [/unit]
        [/then]
    [/if]
#enddef

    # continually spawn ever-increasing orcish attack waves
    # trigger every night, after the orc ultimatum
    [event]
        name=side 2 turn refresh
        first_time_only=no
        [filter_condition]
            [lua]
                code = << return (wesnoth.current.turn%12==9) >>
            [/lua]
            [or]
                [lua]
                    code = << return (wesnoth.current.turn>50 and wesnoth.current.turn%6==3) >>
                [/lua]
            [/or]
        [/filter_condition]

        {SCROLL_TO 50 30}
        {REINFORCE_AFTER_NOATTACK 60 2 ({ON_DIFFICULTY (Orcish Grunt)    (Orcish Warrior)      (Orcish Warrior)     }) 50 30}
        {REINFORCE_AFTER_NOATTACK 60 2 ({ON_DIFFICULTY (Goblin Spearman) (Orcish Grunt)        (Orcish Warlord)     }) 50 30}

        {REINFORCE_AFTER_NOATTACK 24 2 ({ON_DIFFICULTY (Orcish Archer)   (Orcish Crossbowman)  (Orcish Crossbowman) }) 50 30}

        {REINFORCE_AFTER_NOATTACK 12 2 ({ON_DIFFICULTY (Goblin Spearman) (Orcish Grunt)        (Orcish Warrior)     }) 50 30}
        {REINFORCE_AFTER_NOATTACK 12 2 ({ON_DIFFICULTY (Goblin Spearman) (Orcish Grunt)        (Orcish Warrior)     }) 50 30}

        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Orcish Archer)    (Orcish Archer)       (Orcish Crossbowman) }) 50 30}
        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Goblin Spearman)  (Goblin Spearman)     (Orcish Warrior)     }) 50 30}
        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Orcish Grunt)     (Orcish Grunt)        (Orcish Grunt)       }) 50 30}
        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Goblin Spearman)  (Orcish Archer)       (Orcish Archer)      }) 50 30}

        [if]
            [lua]
                code=<< return wesnoth.current.turn==21 >>
            [/lua]

            [then]
                [message]
                    x,y=50,30
                    #po: Turn 21 (start of the fourth night) the second wave of orcs arrive and announce their plans.
                    #po: Around 6 orcs have just arrived, with 5 more next turn.
                    #po: There were 7 orcs in the first wave on turns 9 and 10, but the player has probably already handled them.
                    message= _ "Time to chop some human heads!"
                [/message]
            [/then]
        [/if]
        [if]
            [lua]
                code=<< return wesnoth.current.turn==33 >>
            [/lua]

            [then]
                [message]
                    x,y=50,30
                    #po: Turn 33 (start of the sixth night) the next wave of orcs arrive.
                    #po: The latest group is 7 orcs, with more a turn behind them.
                    message= _ "Keep attacking, hit ’em while the sun’s down!"
                [/message]
            [/then]
        [/if]
        [if]
            [lua]
                code=<< return wesnoth.current.turn==45 >>
            [/lua]

            [then]
                [message]
                    x,y=50,30
                    #po: Turn 45 (start of the eigth night) the next wave of orcs arrive.
                    #po: The latest group is 7 orcs, with more a turn behind them.
                    message= _ "Chief’s orders, let’s get them!"
                [/message]
            [/then]
        [/if]
        [if]
            [lua]
                code=<< return wesnoth.current.turn==51 >>
            [/lua]

            [then]
                [message]
                    x,y=50,30
                    #po: Turn 51 (start of the ninth night), and from here on they're arriving every night rather than one night in two.
                    message= _ "Burn and pillage!"
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=side 2 turn refresh
        first_time_only=no
        [filter_condition]
            [lua]
                code = << return (wesnoth.current.turn%12==10) >>
            [/lua]
            [or]
                [lua]
                    code = << return (wesnoth.current.turn>50 and wesnoth.current.turn%6==4) >>
                [/lua]
            [/or]
        [/filter_condition]
#ifndef EASY
        {REINFORCE_AFTER_NOATTACK 72 2 ({ON_DIFFICULTY (Orcish Slurbow)  (Orcish Slurbow)  (Orcish Slurbow)     }) 50 30}
        {REINFORCE_AFTER_NOATTACK 72 2 ({ON_DIFFICULTY (Orcish Warlord)  (Orcish Warlord)  (Orcish Warlord)     }) 50 30}

        {REINFORCE_AFTER_NOATTACK 66 2 ({ON_DIFFICULTY (Orcish Slurbow)  (Orcish Slurbow)  (Orcish Slurbow)     }) 50 30}
        {REINFORCE_AFTER_NOATTACK 66 2 ({ON_DIFFICULTY (Orcish Assassin) (Orcish Assassin) (Orcish Slayer)      }) 50 30}
#endif
#ifdef HARD
        {REINFORCE_AFTER_NOATTACK 24 2 ({ON_DIFFICULTY (Orcish Assassin) (Orcish Assassin) (Orcish Slayer)      }) 50 30}
        {REINFORCE_AFTER_NOATTACK 12 2 ({ON_DIFFICULTY (Orcish Assassin) (Orcish Assassin) (Orcish Assassin)    }) 50 30}
        {REINFORCE_AFTER_NOATTACK 12 2 ({ON_DIFFICULTY (Goblin Spearman) (Goblin Spearman) (Goblin Impaler)     }) 50 30}

        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Goblin Spearman)  (Goblin Spearman) (Goblin Impaler)     }) 50 30}
        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Orcish Assassin)  (Orcish Assassin) (Orcish Slayer)      }) 50 30}
        {REINFORCE_AFTER_NOATTACK 0 2 ({ON_DIFFICULTY (Orcish Archer)    (Orcish Archer)   (Orcish Crossbowman) }) 50 30}
#endif
    [/event]

    [event]
        name=side 2 turn refresh
        first_time_only=no
        [filter_condition]
            [lua]
                code = << return (wesnoth.current.turn%12==11) >>
            [/lua]
            [or]
                [lua]
                    code = << return (wesnoth.current.turn>50 and wesnoth.current.turn%6==5) >>
                [/lua]
            [/or]
        [/filter_condition]
#ifndef EASY
        {REINFORCE_AFTER_NOATTACK 84 2 ({ON_DIFFICULTY (Direwolf Rider)  (Direwolf Rider)   (Direwolf Rider)  }) 50 30}
        {REINFORCE_AFTER_NOATTACK 84 2 ({ON_DIFFICULTY (Goblin Knight)   (Goblin Knight)    (Goblin Knight)   }) 50 30}

        {REINFORCE_AFTER_NOATTACK 78 2 ({ON_DIFFICULTY (Goblin Pillager) (Goblin Pillager)  (Goblin Pillager) }) 50 30}
        {REINFORCE_AFTER_NOATTACK 78 2 ({ON_DIFFICULTY (Direwolf Rider)  (Direwolf Rider)   (Direwolf Rider)  }) 50 30}
#endif
#ifdef HARD
        {REINFORCE_AFTER_NOATTACK 54 2 ({ON_DIFFICULTY (Wolf Rider)      (Wolf Rider)       (Goblin Knight)   }) 50 30}
        {REINFORCE_AFTER_NOATTACK 54 2 ({ON_DIFFICULTY (Wolf Rider)      (Goblin Knight)    (Direwolf Rider)  }) 50 30}

        {REINFORCE_AFTER_NOATTACK 48 2 ({ON_DIFFICULTY (Wolf Rider)      (Wolf Rider)       (Goblin Pillager) }) 50 30}
        {REINFORCE_AFTER_NOATTACK 48 2 ({ON_DIFFICULTY (Goblin Knight)   (Goblin Knight)    (Goblin Knight)   }) 50 30}

        {REINFORCE_AFTER_NOATTACK 36 2 ({ON_DIFFICULTY (Wolf Rider)      (Wolf Rider)       (Wolf Rider)      }) 50 30}
        {REINFORCE_AFTER_NOATTACK 36 2 ({ON_DIFFICULTY (Wolf Rider)      (Goblin Pillager)  (Goblin Pillager) }) 50 30}
#endif
    [/event]

    # victory
    [event]
        name=die

        [filter]
            id=Sanctum Guard
        [/filter]

        {KILL (id=Sanctum Guard)}
        [kill]
            side=4
            [filter_location]
                x,y=12,4
                radius=7
            [/filter_location]
            animate=yes
        [/kill]

        {REPLACE_SCENARIO_MUSIC silence.ogg}
        [message]
            speaker="Dacyn"
            message= _ "Excellent. Now..."
        [/message]
        {MOVE_UNIT (id="Dacyn") 13 5}

        [message]
            speaker=Gweddry
            #po: before he picks up the amulet
            message= _ "Wait, Dacyn, before you pick that up... are you sure this is the right decision? Even if you can wield it safely, something this evil will doubtlessly corrupt anyone who possesses it."
        [/message]
        [message]
            speaker="Dacyn"
            message= _ "Why, I’m incredibly touched by your deep show of affection. I’m sure that will be of great comfort when thousands are massacred after Wesnoth loses its greatest war in living memory."
        [/message]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker="Dacyn"
            #po: there's a short pause between the "deep show of affection" message and this one
            message= _ "No, Gweddry, I am not sure. But I know of no other way to defeat Mal-Ravanal. I have tried once before. Even as a mage, Ravan’s powers near outmatched my own. As the lich Mal-Ravanal, perhaps only Delfador the Great could have stood a chance."
        [/message]
        [message]
            speaker="Dacyn"
            message= _ "This Amulet will give us the edge that I need. With it, I can open a gate to the Land of the Dead and pull Mal-Ravanal’s unholy spells out of this world."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "But if what you said is true, the very same could be said of Ravan. How do you know you will not fall down the same path as well?"
        [/message]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker="Dacyn"
            message= _ "You are right, Gweddry. I cannot know. But I must try. If I do not, Wesnoth — nay, all of Irdya — will surely fall to ruin. As long as I try, there is still a chance. Sacrificing myself means nothing for the greater good."
        [/message]
        [message]
            speaker="Dacyn"
            message= _ "(picks up the amulet)"
        [/message]

        {REMOVE_IMAGE 13 5}
        {PLACE_IMAGE items/altar-evil.png 13 5}
        [if]
            [have_unit]
                id=Dacyn
                type=White Mage
            [/have_unit]

            [then]
                {ADVANCE_UNIT id=Dacyn (Mage of Light)} # Dacyn needs the illuminates aura for future stuff to make sense. This seems as good a place to do it as any
            [/then]
        [/if]
        [sound]
            name=magic-dark-big-miss.ogg
        [/sound]

        {COLOR_ADJUST 265 0 0}
        [delay]
            time=100
        [/delay]

        {COLOR_ADJUST 265 265 265}
        [delay]
            time=100
        [/delay]

        {COLOR_ADJUST 265 0 0}
        [delay]
            time=100
        [/delay]

        {COLOR_ADJUST 0 0 0}

        [sound]
            name=human-old-die-1.ogg
        [/sound]

        {MODIFY_UNIT id=Dacyn hitpoints 1}
        {MODIFY_UNIT id=Dacyn experience 0}
        # experience because 1: showing that the amulet interferes with his MoL-ing, and
        # experience because 2: preventing the player from deliberately AMLA-ing Dacyn in the next scenario (partially a difficulty issue, but mostly it's bad to punish blind playthroughs / reward foreknowledge)
        {MODIFY_UNIT id=Dacyn status.slowed yes}
        [message]
            speaker="Dacyn"
            #po: on putting on the amulet, he's been dropped to 1 hp
            message= _ "AAAAHHHH!"
        [/message]
        [sound]
            name=lich-hit-1.ogg
        [/sound]

        # TODO: would like to extend this sequence adding some unknown spirit voices, same as the ones that appear later and that Ravan hinted at whispering from another dimension
        [message]
            caption= _ "Unknown"
            image=units/unknown-unit1.png
            message= _ "<span size='small' font-style='italic'>AAAAHHHH!</span>"
        [/message]
        [message]
            speaker=Gweddry
            #po: "everyone" being 6 units, or less
            message= _ "Dacyn! Everyone stand back, give him some air."
        [/message]
        [message]
            speaker="Dacyn"
            message= _ "... do not fear, I am unharmed. I just... need a moment to catch my breath."
        [/message]

        [delay]
            time=500
        [/delay]

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

        [delay]
            time=1000
        [/delay]

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

        {COLOR_ADJUST 265 265 265}
        {REPLACE_SCENARIO_MUSIC knalgan_theme.ogg}

        {MODIFY_TERRAIN Uh^Dr 8 7}
        {MODIFY_TERRAIN Uh^Dr 9 7}
        {MODIFY_TERRAIN Ur^Dr 10 7}
        {MODIFY_TERRAIN Ur^Dr 10 8}
        [redraw]
            clear_shroud=yes
            side=1
        [/redraw]

        {NAMED_UNIT 2 (Orcish Sovereign) 9 7 "Chief Dra-Nak" (_"Chief Dra-Nak") ()} {FACING ne}
        [+unit]
            profile=portraits/orcs/ruler-2.webp
            canrecruit=yes
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
        {NAMED_UNIT 5 (Goblin Spearman) 10 7 "Cowardly Goblin" (_"Cowardly Goblin") ()} {FACING ne}
        {GENERIC_UNIT 2 (Orcish Warrior) 9 8}
        {GENERIC_UNIT 2 (Orcish Warrior) 12 7}
        {GENERIC_UNIT 2 (Orcish Warlord) 10 9}
        {GENERIC_UNIT 2 (Orcish Slurbow) 10 8}
        {GENERIC_UNIT 2 (Orcish Crossbowman) 9 9}
        {GENERIC_UNIT 2 (Orcish Crossbowman) 7 10}
        {GENERIC_UNIT 2 (Goblin Knight) 7 8}
        {GENERIC_UNIT 2 (Goblin Pillager) 6 9}

        {GENERIC_UNIT 2 (Orcish Warrior) 12 3}
        {GENERIC_UNIT 2 (Orcish Crossbowman) 14 6}
        {GENERIC_UNIT 2 (Orcish Slurbow) 14 5}
        {GENERIC_UNIT 2 (Orcish Warlord) 10 5}

        [delay]
            time=300
        [/delay]

        {COLOR_ADJUST 0 0 0}

        [message]
            speaker="Chief Dra-Nak"
            #po: A wall of the inner sanctum (where the amulet was) has just exploded, revealing a cave that extends off the west edge of the map.
            #po: Introduction implying that Whitefang has other chiefs, but that Dra-Nak is particularly powerful.
            message= _ "Hah, did you think you were safe hiding back in here? Nobody can escape from Dra-Nak, greatest chief east of the Listra."
        [/message]
        [message]
            speaker="Cowardly Goblin"
            #po: male speaker
            message= _ "See see! I told you there were humans in here! And I showed you the secret passage! Reward reward?"
        [/message]
        [message]
            speaker="Chief Dra-Nak"
            #po: gives the Cowardly Goblin some gold
            message= _ "Sure, here you go. You did well."
        [/message]
        [sound]
            name=gold.ogg
        [/sound]

        {MOVE_UNIT (id="Cowardly Goblin") 1 13}

        [message]
            speaker="Chief Dra-Nak"
            #po: presumably still 8 humans, unless the player has lost some
            message= _ "As for you humans, you might as well convince your friends outside to surrender. Otherwise, we’ll slaughter you all starting with that injured old man. I gave you a chance to do things fairly before, but now we’re doing things my way."
        [/message]
        [message]
            speaker="Gweddry"
            message= _ "<span size='small'><i>I don’t know what these orcs want with us, but we can’t hope to escape with Dacyn so badly hurt.</i></span>"
        [/message]
        [message]
            speaker="Gweddry"
            message= _ "Very well, orc, we will surrender."
        [/message]

        {CLEAR_VARIABLE bow_dropper,book_found,orcs_attacking,inside_inner_sanctum,ghouls_released}
        [endlevel]
            result=victory
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]

    {FOREIGN_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
    {HERODEATH_OWAEC}
    {HERODEATH_ADDOGIN}
    {HERODEATH_HAHID}
    {HERODEATH_TERRAENT}
    {HERODEATH_GRUG}
    {HERODEATH_DOLBURRAS}
[/scenario]
