#textdomain wesnoth-After_the_Storm

[scenario]
    id=08D_Destiny_part_2
    name= _ "Destiny — Part 2"
    {MAP 08D_Destiny_part_2.map}
    {TURNS 48 46 44}
    next_scenario=09_Dark_Depths
    victory_when_enemies_defeated=no

    {J_DEATHS}

    {SCENARIO_MUSIC "silence.ogg"}

    {STORYTXT_DESTINY_PART_2}

    {ENDLESS_NIGHT}

    {SHAXTHAL_SET_SURFACE_VARIATIONS_FLAG}

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

        {GOLD 440 430 420}

        # wmllint: recognize Anya
        {CHARACTER_STATS_ANYA}
        canrecruit=yes
        type=Guardian of Darkness Anya
        # clobber IS_HERO from the stats macro
        {NO_OVERLAYS_NO_ELLIPSE}
    [/side]

    [side]
        side=2
        controller=human
        save_id=Durvan
        team_name=good
        user_team_name= _ "team_name^Durvan"
        {ALLIANCE_FLAG}

        {GOLD 350 340 330}

        # wmllint: recognize Durvan
        {CHARACTER_STATS_DURVAN}
        canrecruit=yes
        # clobber IS_HERO from the stats macro
        {NO_OVERLAYS_NO_ELLIPSE}
    [/side]
    # wmllint: validate-on

#define INT_NO_DEMOLITION_ABILITY
    [+unit]
        [+modifications]
            [object]
                silent=yes
                [effect]
                    apply_to=remove_ability
                    [abilities]
                        {ABILITY_DEMOLITION_TEXT_ONLY}
                    [/abilities]
                [/effect]
            [/object]
        [/modifications]
    [/unit]
#enddef

    [side]
        side=3
        team_name=evil
        user_team_name= _ "team_name^Iron Council"
        {CHAOS_FLAG}

        {GOLD 60 70 80}
        recruit=Demon,Chaos Invader,Chaos Raider,Chaos Invoker

        canrecruit=yes
        type=Ancient Lich
        id="Mal Ba'arth"
        name= _ "Mal Ba’arth"
        facing=sw
        [modifications]
            {TRAIT_UNDEAD}
            {TRAIT_RESILIENT}
        [/modifications]

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader yes}
        [/ai]

        {GENERIC_UNIT () (Demon Warrior) 45 19} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Demon Warrior) 47 20} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING nw}

        {GENERIC_UNIT () (Shaxthal Stormblade) 47 18} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Shaxthal Stormblade) 50 20} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Shaxthal Stormblade) 51 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Shaxthal Stormblade) 53 19} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT () (Shaxthal Stormblade) 37 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING s}
        {GENERIC_UNIT () (Shaxthal Stormblade) 45 30} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT () (Lumeril Guard) 46 28} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Lumeril Guard) 48 29} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        # These four are placed in order to discourage units flying across the river.
        {GENERIC_UNIT () (Shaxthal War Drone) 14 14} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Shaxthal War Drone)  6  2} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Shaxthal War Drone) 23 20} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Shaxthal War Drone) 37 20} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING  s}

        {GENERIC_UNIT () (Shaxthal Turret) 46 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 36 18} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 40 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 40 13} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 47 22} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 49 22} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 54 21} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 56 22} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 56 15} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 60 16} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 62 18} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 58 18} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}
        {GENERIC_UNIT () (Shaxthal Turret) 60 20} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN}

        # Not guardians

        {GENERIC_UNIT () (Serpent Messenger) 51 38} {NO_UPKEEP_NO_OVERLAY} {FACING sw} {GUARDIAN}
        {GENERIC_UNIT () (Serpent Messenger) 55 38} {NO_UPKEEP_NO_OVERLAY} {FACING sw} {GUARDIAN}
        {GENERIC_UNIT () (Serpent Messenger) 49 25} {NO_UPKEEP_NO_OVERLAY} {FACING sw} {GUARDIAN}

        {GENERIC_UNIT () (Armageddon Imp) 55 20} {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {GENERIC_UNIT () (Armageddon Imp) 45 14} {NO_UPKEEP_NO_OVERLAY} {FACING se}

        [unit]
            id=Vrylla
            name= _ "Vrylla"
            type=Demon Slashing Gale
            x,y=57,31
            gender=female
            upkeep=free
            facing=sw
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        [unit]
            id=Grylla
            name= _ "Grylla"
            type=Demon Slashing Gale
            x,y=62,30
            gender=female
            upkeep=free
            facing=sw
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [unit]
            id=Aethengrya
            name= _ "Aethengrya"
            type=Demon Slashing Gale
            x,y=63,32
            gender=female
            upkeep=free
            facing=sw
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        {GENERIC_UNIT () (Shaxthal War Drone) 61 23} {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {GENERIC_UNIT () (Shaxthal War Drone) 59 19} {NO_UPKEEP_NO_OVERLAY} {FACING sw}

        {GENERIC_UNIT () (Shaxthal Assault Drone) 62 23} {NO_UPKEEP_NO_OVERLAY} {FACING sw}
        {GENERIC_UNIT () (Shaxthal Assault Drone) 60 18} {NO_UPKEEP_NO_OVERLAY} {FACING se}
        {GENERIC_UNIT () (Shaxthal Assault Drone) 59 23} {NO_UPKEEP_NO_OVERLAY} {FACING sw}

        {GENERIC_UNIT () (Shaxthal Enforcer Drone) 14  3} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Enforcer Drone) 20 11} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Enforcer Drone) 27  4} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}

        {GENERIC_UNIT () (Shaxthal Sentry Drone) 28  4} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Sentry Drone) 16  7} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Sentry Drone) 21  3} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Sentry Drone) 21 10} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}

        {GENERIC_UNIT () (Shaxthal Enforcer Drone) 52 52} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Enforcer Drone) 55 49} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Enforcer Drone) 62 56} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}

        {GENERIC_UNIT () (Shaxthal Sentry Drone) 57 50} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Sentry Drone) 61 54} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Sentry Drone) 64 49} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}
        {GENERIC_UNIT () (Shaxthal Sentry Drone) 65 53} {NO_UPKEEP_NO_OVERLAY} {VARIATION surface}

        {GENERIC_UNIT () (Shaxthal Assault Drone)  1 10} {NO_UPKEEP_NO_OVERLAY} {FACING se}
        {GENERIC_UNIT () (Shaxthal Assault Drone)  3 15} {NO_UPKEEP_NO_OVERLAY} {FACING se}
    [/side]

    [side]
        side=4
        team_name=evil
        user_team_name= _ "team_name^Kalari"
        {CHAOS_FLAG}

        {GOLD 65 80 95}
        recruit=Chaos Invader,Chaos Bowman,Chaos Headhunter

        canrecruit=yes
        type=Hell Guardian
        id=Tremor
        name= _ "Tremor"
        [modifications]
            {TRAIT_SLOW}
            {TRAIT_INTELLIGENT}
        [/modifications]
    [/side]

    [side]
        side=5
        team_name=evil
        user_team_name= _ "team_name^Kalari"
        {CHAOS_FLAG}

        {GOLD 100 110 120}
        recruit=Ghoul,Skeleton Archer,Demon,Shaxthal Razorbird

        canrecruit=yes
        type=Chaos Lorekeeper
        id=Mal Wufnen
        name= _ "Mal Wufnen"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_INTELLIGENT}
        [/modifications]
    [/side]

    [side]
        side=6
        team_name=evil
        user_team_name= _ "team_name^Kalari"
        {CHAOS_FLAG}

        {GOLD 90 100 110}
        recruit=Chaos Hound,Chaos Bowman,Shaxthal Runner Drone,Chaos Headhunter

        canrecruit=yes
        type=Demon Spelldancer
        id=Zhanethes
        name= _ "Zhanethes"
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    [side]
        side=7
        team_name=evil
        user_team_name= _ "team_name^Kalari"
        {CHAOS_FLAG}

        {GOLD 80 90 100}
        recruit=Imp,Vampire Bat,Ghost,Demon,Skeleton Archer

        canrecruit=yes
        type=Ancient Lich
        id=Mal Unroth
        name= _ "Mal Unroth"
        [modifications]
            {TRAIT_UNDEAD}
            {TRAIT_STRONG}
        [/modifications]

        {GENERIC_UNIT () (Ixthala Fire Dancer) 33 17} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Ixthala Fire Dancer) 55 17} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Ixthala Fire Dancer) 48 34} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Ixthala Fire Dancer) 40 28} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Ixthala Fire Dancer) 40 11} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Ixthala Fire Dancer) 45 17} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
    [/side]

    [side]
        side=8
        team_name=evil
        user_team_name= _ "team_name^Kalari"
        {CHAOS_FLAG}

        {GOLD 110 120 130}
        recruit=Chaos Raider,Chaos Gunner,Chaos Invader,Chaos Invoker

        canrecruit=yes
        type=Chaos Razerman
        id=General Penthein
        name= _ "General Penthein"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]
    [/side]

    [side]
        side=9
        team_name=evil
        user_team_name= _ "team_name^Kalari"
        {CHAOS_FLAG}

        {GOLD 100 110 120}
        recruit=Chaos Headhunter,Imp,Skeleton Archer,Skeleton

        canrecruit=yes
        type=Death Knight
        id=General Mylean
        name= _ "General Mylean"
        [modifications]
            {TRAIT_UNDEAD}
            {TRAIT_RESILIENT}
        [/modifications]

        {GENERIC_UNIT () (Chocobone) 42 30} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Chocobone) 42 32} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT () (Chocobone) 38 26} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}

        {GENERIC_UNIT () (Chocobone) 34 31} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Chocobone) 35 40} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Chocobone) 35 33} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT () (Chocobone)  8 21} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Chocobone) 33 41} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT () (Banebow) 39 18} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}

        {GENERIC_UNIT () (Banebow) 49 37} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING nw}

        {GENERIC_UNIT () (Banebow) 20 21} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING se}
        {GENERIC_UNIT () (Draug)   17 20} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
        {GENERIC_UNIT () (Draug)   21 23} {NO_UPKEEP_NO_OVERLAY} {GUARDIAN} {FACING sw}
    [/side]

    [side]
        side=10
        team_name=evil
        user_team_name= _ "team_name^Shaxthals"
        {CHAOS_FLAG}
        color=brightgreen

        {NO_ECONOMY}
        no_leader=yes
        hidden=yes

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

            [goal]
                name=protect_location
                value=100
                protect_radius=6
                [criteria]
                    x,y=50,18 # The citadel keep
                [/criteria]
            [/goal]
        [/ai]
    [/side]

    {STARTING_VILLAGES_ALL 3}

    {STARTING_VILLAGES 4 4}
    {STARTING_VILLAGES 5 4}
    {STARTING_VILLAGES 6 4}
    {STARTING_VILLAGES 7 8}
    {STARTING_VILLAGES 8 5}
    {STARTING_VILLAGES 9 3}

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 39 33}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 40 34}

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 45 29}
    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 47 30}

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 39 17}
    {PLACE_IMAGE scenery/banner-uria-standing.png    35 17}

    {PLACE_IMAGE scenery/banner-uria-standing.png    38 24}
    {PLACE_IMAGE scenery/banner-uria-standing.png    37 26}

    {PLACE_IMAGE scenery/banner-uria-standing-sw.png 51 18}

    {PLACE_IMAGE scenery/rock3.png 63 54}
    {PLACE_IMAGE scenery/rock2.png 57 51}

    {PLACE_IMAGE items/scarecrow.png 25 29}
    {PLACE_IMAGE items/scarecrow.png  9 25}

    {PLACE_IMAGE items/grain-sheaf.png 23 29}

    {PLACE_IMAGE items/bones.png             55 54}
    {PLACE_IMAGE "items/bones.png~FL(horiz)" 16 16}
    {PLACE_IMAGE items/bones.png             10  9}

#define INT_PLAYER_HELPER _WML
    [unit]
        {_WML}
        upkeep=free
        {IS_LOYAL}
        [+modifications]
            {TRAIT_LOYAL}
        [/modifications]
    [/unit]
#enddef

#define INT_PILLAGER _X _Y
    {INT_PLAYER_HELPER (
        side=2
        x={_X}
        y={_Y}
        random_traits=yes
        generate_name=yes
        facing=ne
        type=Goblin Pillager
    )}
#enddef

#define INT_FORCE_OBJECTIVES_REFRESH
    [fire_event]
        name=force objectives refresh
    [/fire_event]
#enddef

    [event]
        name=force objectives refresh
        first_time_only=no

        #
        # HACK:
        #
        # Works around AtS issue #66 in Wesnoth 1.14.x by forcing objectives to
        # be fully refreshed each time instead of relying on [show_if]'s
        # advertised semantics to work properly past turn save loads.
        #
        # Previously we'd use [objectives] in prestart and [show_objectives] in
        # the middle of the scenario.
        #

        {OBJECTIVES (
            side=1,2
            victory_string= _ "Current Objectives:"
            {OBJECTIVE_VICTORY ( _ "Destroy Mal Ba’arth, the last Iron Council member, and move Anya to the citadel")}
            {OBJECTIVE_SHOW_IF ({VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_council no})}
            {OBJECTIVE_VICTORY ( _ "Defeat the Storm Sisters (Vrylla, Grylla, and Aethengrya)")}
            {OBJECTIVE_SHOW_IF ({VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_sisters no})}
            {OBJECTIVE_VICTORY ( _ "Move Anya to the citadel")}
            {OBJECTIVE_SHOW_IF (
                {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_council yes}
                {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_sisters yes}
                {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.seize_citadel  no }
            )}
            {OBJECTIVE_VICTORY_END_OF_TURNS}
            {OBJECTIVE_SHOW_IF ({VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.seize_citadel yes})}

            {OBJECTIVE_DEFEAT  ( _ "Death of Anya")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Durvan")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Irylean")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Ergea")}
            {OBJECTIVE_DEFEAT  ( _ "Death of Cron")}
            {TURNS_RUN_OUT}
            {OBJECTIVE_SHOW_IF ({VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.seize_citadel no})}

            {OBJECTIVE_FULL_CARRYOVER}

            {OBJECTIVE_NOTE ( _ "The citadel comprises the starting location for Mal Ba’arth and the immediately adjacent keep (not castle) hexes at (50, 18)")}
            {OBJECTIVE_NOTE ( _ "It could prove advantageous to defeat other enemy leaders and move Anya or Ergea to their keeps before destroying Mal Ba’arth")}
            {OBJECTIVE_NOTE ( _ "Avoid stationing units on the Shaxthal hives nearby")}
            {OBJECTIVE_NOTE ( _ "Do not waste your Goblin Pillagers")}
        )}
    [/event]

    [event]
        name=prestart

        [set_variables]
            name=e3s8d_objectives_status
            mode=replace
            [literal]
                defeat_council=no
                seize_citadel=no
                defeat_sisters=no
                defeat_other_enemy_leaders=no
            [/literal]
        [/set_variables]

        # Daeira should have been returned to the recall list at the end of the
        # boss fight sequence in E3S8B. This is here just in case that didn't
        # happen (debug mode?).

        [if]
            {VARIABLE_NUMERICAL_NOT_EQUALS daeira_store.length 0}
            [then]
                [unstore_unit]
                    variable=daeira_store
                    x,y=recall,recall
                [/unstore_unit]

                {CLEAR_VARIABLE daeira_store}
            [/then]
        [/if]

        [capture_village]
            side=1
            x=14,19,18,18
            y=37,40,43,46
        [/capture_village]

        [capture_village]
            side=2
            x=12, 6, 2, 6, 5
            y=47,47,45,43,55
        [/capture_village]

        [kill]
            id=Anya
        [/kill]

        [unit]
            # wmllint: recognize Anya
            {CHARACTER_STATS_ANYA}
            canrecruit=yes
            type=Guardian of Darkness Anya
            facing=ne
            side=1
            placement=leader
            # clobber IS_HERO from the stats macro
            {NO_OVERLAYS_NO_ELLIPSE}
        [/unit]

        # wmllint: recognize Irylean
        {RECALL_IRYLEAN_AT_LOCATION 14 42}
        # wmllint: recognize Ergea
        {RECALL_ERGEA_AT_LOCATION   13 42}
        # wmllint: recognize Cron
        {RECALL_CRON_AT_LOCATION    12 41}
        # wmllint: recognize Igor
        {RECALL_IGOR_AT_LOCATION     4 43}
        # wmllint: recognize Daeira
        {RECALL_DAEIRA_AT_LOCATION   9 39}

        #
        # Workaround for recall issues in E3S8B (FIXME)
        #

        [modify_unit]
            [filter]
                id=Cron,Irylean,Igor
            [/filter]
            moves=$this_unit.max_moves
        [/modify_unit]

        {RECALL_SIDE_LOYALS 2 ()}

        {RECALL_SIDE_UNITS_AT 1 (race=merman) 6 36}

        {INT_PLAYER_HELPER (
            side=1
            type=Faerie Dryad
            id=Meeryn
            name= _ "Meeryn"
            x,y=12,39
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=1
            type=Faerie Dryad
            id=Anelith
            name= _ "Anelith"
            x,y=9,46
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        )}

        [if]
            [have_unit]
                id=Daeira
            [/have_unit]
            [then]
                {LIGHT_OF_XIAEL:APPLY_TO_SINGULAR_UNIT id=Anelith,Meeryn}
            [/then]
        [/if]

        {INT_PLAYER_HELPER (
            side=1
            type=Saurian Soothsayer
            id=Sharazkas
            name= _ "Sharazkas"
            facing=ne
            x,y=21,44
            [modifications]
                {TRAIT_STRONG}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=1
            type=Saurian Soothsayer
            id=Eressin
            name= _ "Eressin"
            facing=ne
            x,y=19,38
            [modifications]
                {TRAIT_STRONG}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=1
            type=Demon Spelldancer
            id=Domegi
            name= _ "Domegi"
            facing=ne
            x,y=8,39
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=1
            type=Saurian Flanker
            id=Issylias
            name= _ "Issylias"
            facing=ne
            x,y=6,45
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=2
            type=Orcish Warlord
            id=Nortrang
            name= _ "Nortrang"
            x,y=7,41
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=2
            type=Direwolf Rider
            id=Fernol
            name= _ "Fernol"
            x,y=10,47
            [modifications]
                {TRAIT_STRONG}
            [/modifications]
        )}

        {INT_PLAYER_HELPER (
            side=2
            type=Orcish Slayer
            id=Acengrez
            name= _ "Acengrez"
            x,y=16,41
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        )}

        {INT_PILLAGER  3 39}
        {INT_PILLAGER  4 40}
        {INT_PILLAGER  2 40}
        {INT_PILLAGER  4 41}

        {INT_PILLAGER  7 54}
        {INT_PILLAGER  8 55}
        {INT_PILLAGER  6 56}
        {INT_PILLAGER  3 55}

        {INT_PILLAGER  2 48}
        {INT_PILLAGER  4 49}

        {INT_PILLAGER 18 48}
        {INT_PILLAGER 16 48}

        {INT_PILLAGER 13 52}
        {INT_PILLAGER 12 53}

        {INT_PLAYER_HELPER (
            side=2
            type=Orcish Slurbow
            id=Bogar
            name= _ "Bogar"
            x,y=6,52
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        )}

        {FACE_DIRECTION side=1,2 ne}

        {INT_FORCE_OBJECTIVES_REFRESH}
    [/event]

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

    [event]
        name=start

        {INCIDENTAL_MUSIC "battle-epic.ogg"}

        [message]
            speaker=Anya
            message= _ "For the last time, Durvan, I am <b>not</b> a goddess! This is ridiculous!"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Well... there’s not much you can do about it at this point, anyway. Everyone saw the darkness stuff you did with the remaining monsters, and rumors spread like—"
        [/message]

        [message]
            speaker=Anya
            message= _ "A disease! I do not even know what I actually did! I only want to leave this dreadful place and rest!"
        [/message]

        [message]
            speaker=Ergea
            message= _ "This is the most auspicious moment to storm the citadel if that is what you want to do. And if you play the part you may be able to obtain support from Uria’s converts. Once they realize that the Fist and the Iron Council have been lying to them, the Chaos Empire’s social structure shall shatter. But we ought to plant the seed of distrust now, while Elynia and the Fire prepare to vanquish the usurper."
        [/message]

        [message]
            speaker=Anya
            message= _ "... Assuming they are even alive."
        [/message]

        [message]
            speaker=Ergea
            message= _ "Is that what you want?"
        [/message]

        [message]
            speaker=Anya
            message= _ "... Yes."
        [/message]

        {INT_ANYA_THOUGHTS ( _ "I want to see her once again. I want to smile with her, talk with her. She promised...")}

        [message]
            speaker=Ergea
            message= _ "Then, please, help us. Help us storm the citadel. Help us uproot Uria’s evil influence on Irdya, and advance the long path that lies ahead for you as the Guardian of Darkness."
        [/message]

        {REPLACE_SCENARIO_MUSIC "casualties_of_war.ogg"}
        {APPEND_MUSIC           "legends_of_the_north.ogg"}
        {APPEND_MUSIC           "battle.ogg"}
        {APPEND_MUSIC           "siege_of_laurelmor.ogg"}
        # Yes, only play this one once, right now. It's even more upbeat
        # than legends_of_the_north.ogg and that's not a good thing in
        # this case.
        {INCIDENTAL_MUSIC       "northern_mountains.ogg"}
    [/event]

    [event]
        name=side 1 turn 1 end

        [message]
            speaker=Anya
            message= _ "I guess I should be thankful you are not calling me Merthiaal or anything like that."
        [/message]

        [message]
            speaker=Ergea
            message= _ "The names of the guardians you know were the names they chose for themselves in the First Cycle. We may not call you by the name of the original Guardian of Darkness unless you choose to adopt her name instead of your own."
        [/message]

        [message]
            speaker=Anya
            message= _ "Is that how it really works? I prefer to keep my current name, then."
        [/message]
    [/event]

    [event]
        name=side 2 turn 1 end

        [message]
            speaker=Irylean
            message= _ "Hey, Durvan, did you ever think you would fight at the side of two faerie goddesses against an endless horde of demons, imps, and devout worshipers of an evil demoness?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "No. Well, now that you mention it... this will be quite the story to tell the folks in the Heart Forest. Nobody will ever believe me."
        [/message]

        [message]
            speaker=Igor
            message= _ "Same..."
        [/message]
    [/event]

    [event]
        name=side 1 turn 3 end
        [filter_condition]
            [have_unit]
                id=Igor
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Anya
            message= _ "On the bright side, dying and returning to the physical realm as a Guardian is a surprisingly easy way to get rid of all the sweat and filth on me."
        [/message]
    [/event]

    [event]
        name=side 2 turn 4
        [filter_condition]
            [have_unit]
                id=Igor
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Durvan
            message= _ "Igor?"
        [/message]

        [message]
            speaker=Igor
            message= _ "Hm?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Have you ever felt like... no matter how hard you try, you can’t even hope to measure up to someone whose company you enjoy?"
        [/message]

        [message]
            speaker=Igor
            message= _ "Uh, sometimes."
        [/message]
    [/event]

    [event]
        name=side 2 turn 4 end
        [filter_condition]
            [have_unit]
                id=Igor
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Igor
            message= _ "But you end up realizing that friends don’t expect you to magically become something you’re not! Lady Elynia and the scary lich always were way more than me with all those magic powers I don’t understand, but that never stopped them from seeing me as a friend!"
        [/message]

        [message]
            speaker=Durvan
            message= _ "Right. <i>(sighs)</i> I guess I’ve just got to accept it..."
        [/message]
    [/event]

    #
    # It goes without saying that this event only triggers if Daeira exists.
    #
    [event]
        name=moveto
        [filter]
            id=Anya
            [filter_adjacent]
                id=Daeira
            [/filter_adjacent]
            [or]
                id=Daeira
                [filter_adjacent]
                    id=Anya
                [/filter_adjacent]
            [/or]
        [/filter]

        [message]
            speaker=Anya
            message= _ "Oh, hello again!"
        [/message]

        [message]
            speaker=Daeira
            message= _ "Greetings."
        [/message]

        [message]
            speaker=Anya
            message= _ "I thought something bad may have happened to you back there... You were with us and then disappeared? Why?"
        [/message]

        [message]
            speaker=Daeira
            message= _ "You need not worry about my wellbeing, Anya. I can easily escape from certain danger thanks to my intimate connection to the Aspect of Water. There is a large amount of it around these parts, after all."
        [/message]

        [message]
            speaker=Anya
            message= _ "Please don’t tell me now that you are the Guardian of Water or some nonsense like that... I cannot take more of this right now."
        [/message]

        [message]
            speaker=Daeira
            message= _ "It would be a sin beyond measure for someone such as I to pretend to be a god in front of one. With that said, all faeriekind creatures are connected to one or two Aspects to some degree. For example, you are connected to both Darkness and Earth as the daughter of a forest faerie."
        [/message]

        {VARIABLE_DEFAULT anya_wants_to_see_the_manager no}

        [if]
            {VARIABLE_BOOLEAN_EQUALS anya_wants_to_see_the_manager yes}
            [then]
                [message]
                    speaker=Anya
                    message= _ "Right, which reminds me I still don’t know how the story of my parents ends. Then again... perhaps I don’t want to know."
                [/message]
            [/then]
        [/if]

        [message]
            speaker=Anya
            message= _ "Did you know I was meant to become the Guardian of Darkness, though?"
        [/message]

        [message]
            speaker=Daeira
            message= _ "Yes, I did. And I apologize for not revealing that to you — if I had, there is a good chance that you would have made all the wrong decisions."
        [/message]

        [if]
            {VARIABLE_NUMERICAL_LESS_THAN turn_number 4}
            [then]
                [message]
                    speaker=Anya
                    message= _ "Meanwhile, Ergea hasn’t apologized for keeping information from me... Which reminds me, we still have a battle to fight. I hope I can count on your help."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Anya
                    message= _ "Meanwhile, Ergea hasn’t apologized for keeping information from me... Well, it doesn’t matter for now. We need to get back to the fight."
                [/message]
            [/else]
        [/if]

        [message]
            speaker=Daeira
            message= _ "Certainly."
        [/message]
    [/event]

    [event]
        name=prestart

        #
        # Setup the rebel location events.
        #
        # The rebel_villages container (which we try to make sure is empty at first
        # is used to keep track of the villages that have already been configured
        # (using SLF find_in), so we don't need to keep it around once we are done.
        #

        {CLEAR_VARIABLE rebel_villages}

        [while]
            {VARIABLE_NUMERICAL_LESS_THAN rebel_villages.length 12}
            [do]
                [store_locations]
                    terrain=*^V*
                    [not]
                        owner_side=1
                    [/not]
                    [not]
                        owner_side=2
                    [/not]
                    [not]
                        find_in=rebel_villages
                    [/not]
                    variable=locs
                [/store_locations]

                # FIXME: interacts poorly with pseudoinfinite loops.
                #{BUG_ON ({VARIABLE_NUMERICAL_EQUALS locs.length 0})
                #("Could not store more villages! ($rebel_villages.length|)")}

                {VARIABLE_RANDOM n "0..$($locs.length - 1)"}

                [set_variables]
                    name=rebel_villages
                    mode=append
                    to_variable="locs[$n]"
                [/set_variables]

                # The unit type chosen for each rebel is determined here so that the player
                # can't save-reload before every village capture in an attempt to obtain the
                # rarer types. The repetition of some ids is intended to help with adjusting
                # probabilities.

                {VARIABLE_RANDOM rebel_type "Demon,Demon,Demon Zephyr,Chaos Invader,Chaos Invader,Chaos Invader,Chaos Invader,Chaos Invader,Chaos Bowman,Chaos Bowman,Chaos Gunner,Chaos Raider,Chaos Headhunter"}

                [unit]
                    side=1 # This is changed by events depending on who captured the village.
                    type=$rebel_type
                    {IS_LOYAL}
                    upkeep=free
                    random_gender=yes
                    random_traits=yes
                    generate_name=yes
                    to_variable=rebel_wml
                    [modifications]
                        {TRAIT_LOYAL}
                        # Second trait slot gets a random trait.
                    [/modifications]
                [/unit]

                [event]
                    name=moveto
                    delayed_variable_substitution=no
                    [filter]
                        x,y=$locs[$n].x,$locs[$n].y
                        [and]
                            side=1
                            [or]
                                side=2
                            [/or]
                        [/and]
                    [/filter]

                    [set_variables]
                        name=rebel_spawn
                        mode=replace
                        # Substitute rebel_wml on handler generation, not
                        # later.
                        [insert_tag]
                            name=literal
                            variable="rebel_wml"
                        [/insert_tag]
                    [/set_variables]

                    # Override spawn side with the primary unit's side
                    # when running the event handler.

                    {VARIABLE rebel_spawn.side $|unit.side}

                    [unstore_unit]
                        variable=rebel_spawn
                        x,y="$|x1","$|y1"
                        find_vacant=yes
                        check_passability=no
                    [/unstore_unit]

                    {CLEAR_VARIABLE rebel_spawn}

                    [fire_event]
                        name=rebel_speech
                        [primary_unit]
                            # This we can substitute on handler generation.
                            # It is supposed to be the engine's automatically
                            # generated default unit id.
                            id=$rebel_wml.id
                        [/primary_unit]
                    [/fire_event]
                [/event]

                {CLEAR_VARIABLE n,locs,rebel_wml,rebel_type}
            [/do]
        [/while]

        # Done now, so we can dispose of the SLF state.
        {CLEAR_VARIABLE rebel_villages}
    [/event]

#define INT_SPEECH _MSG
    [value]
        message={_MSG}
    [/value]
#enddef

    [event]
        name=prestart

        [set_variables]
            name=rebel_speeches
            mode=replace

            {INT_SPEECH ( _ "The prophecies were correct! The Dark Lady was reborn, and she has finally come to vanquish the usurper and set us free from his grasp!")}

            {INT_SPEECH ( _ "Rise up, brethren! We are slaves of the Fist no more!")}

            {INT_SPEECH ( _ "May the Dark Lady guide us to victory over the false god!")}

            {INT_SPEECH ( _ "Can it be? Rebelling against Uria could be highly disastrous for everyone! But... What else do we have left anymore?")}
        [/set_variables]

        [set_variables]
            name=funpack_speeches
            mode=replace

            {INT_SPEECH ( _ "We have long awaited this night. Together, we shall forge a new empire from the blood of the usurper and the fakes who dare to adore him!")}

            {INT_SPEECH ( _ "Uria’s time is almost over. I can feel it. Death to the usurper!")}

            {INT_SPEECH ( _ "Behold, the Guardian of Darkness in all her godly glory!")}

            {INT_SPEECH ( _ "Let us cleanse this land and restore the true cult of Yechnagoth!")}
        [/set_variables]
    [/event]

#define INT_RANDOM_ONE_TIME_SPEECH_EVENT _SPEECHES_ARRAY
    [filter_condition]
        {VARIABLE_NUMERICAL_GREATER_THAN {_SPEECHES_ARRAY}+".length" 0}
    [/filter_condition]
    #
    # Select a random speech and never use it again.
    #

    {VARIABLE_RANDOM r "0..$($"+{_SPEECHES_ARRAY}+".length - 1)"}

    [message]
        speaker=unit
        message="$"+{_SPEECHES_ARRAY}+"[$r].message"
    [/message]

    {CLEAR_VARIABLE {_SPEECHES_ARRAY}+"[$r]"}
    {CLEAR_VARIABLE r}
#enddef

    [event]
        name=rebel speech
        first_time_only=no

        {INT_RANDOM_ONE_TIME_SPEECH_EVENT rebel_speeches}
    [/event]

    [event]
        name=funpack speech
        first_time_only=no

        {INT_RANDOM_ONE_TIME_SPEECH_EVENT funpack_speeches}
    [/event]

    [event]
        name=funpack event
        first_time_only=no

        [unit]
            side=1
            type=Chaos Invoker
            generate_name=yes
            random_gender=yes
            random_traits=yes
            upkeep=free
            {IS_LOYAL}
            x,y=$x1,$y1
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        {RANDOM "Demon,Demon,Demon,Demon,Demon Zephyr,Imp,Imp,Imp,Valdemon Basher"}

        [unit]
            side=1
            type=$random
            generate_name=yes
            random_gender=yes
            random_traits=yes
            upkeep=free
            {IS_LOYAL}
            x,y=$x1,$y1
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        {RANDOM "Shaxthal Drone,Shaxthal Drone,Shaxthal Runner Drone,Shaxthal Runner Drone,Shaxthal Runner Drone,Shaxthal Razorbird"}

        [unit]
            side=1
            type=$random
            generate_name=yes
            random_gender=yes
            random_traits=yes
            upkeep=free
            variation=surface
            {IS_LOYAL}
            x,y=$x1,$y1
            [modifications]
                {TRAIT_LOYAL}
            [/modifications]
        [/unit]

        {CLEAR_VARIABLE random}

        [fire_event]
            name=funpack speech
            [primary_unit]
                type=Chaos Invoker
                [filter_location]
                    x,y=$x1,$y1
                    # should be an adequate radius in case there are units obstructing the spawn location
                    radius=3
                [/filter_location]
            [/primary_unit]
        [/fire_event]

        {VARIABLE temp_gold_retrieval_amount ({DIFF 150 130 110})}

        [message]
            speaker=narrator
            sound=gold.ogg
            image="items/gold-coins-medium.png"
            message= _ "Both playing teams retrieve $temp_gold_retrieval_amount pieces of gold."
        [/message]

        [gold]
            side=1,2
            amount=$temp_gold_retrieval_amount
        [/gold]

        {CLEAR_VARIABLE temp_gold_retrieval_amount}
    [/event]

#define INT_FUNPACK_LOCATION_EVENT _DECEASED_LEADER_SIDE _X _Y
    [event]
        name=moveto
        delayed_variable_substitution=no
        [filter]
            x={_X}
            y={_Y}
            [and]
                id=Anya
                [or]
                    id=Ergea
                [/or]
            [/and]
        [/filter]
        [filter_condition]
            [not]
                [have_unit]
                    canrecruit=yes
                    side={_DECEASED_LEADER_SIDE}
                [/have_unit]
            [/not]
        [/filter_condition]

        [fire_event]
            name=funpack event
            [primary_unit]
                # delay substitution
                x,y=$|x1,$|y1
            [/primary_unit]
        [/fire_event]
    [/event]
#enddef

    #
    # Setup funpack locations.
    #
    [event]
        name=prestart

        [for]
            variable=n
            start,end=4,9
            [do]
                [store_starting_location]
                    side=$n
                [/store_starting_location]

                {INT_FUNPACK_LOCATION_EVENT $n $location.x $location.y}
            [/do]
        [/for]

        {CLEAR_VARIABLE location}
    [/event]

    [event]
        name=victory
        {CLEAR_VARIABLE rebel_speeches,funpack_speeches}
    [/event]

#define INT_OBJECTIVE_COMPLETE _OBJECTIVE_ID
    {VARIABLE "e3s8d_objectives_status."+{_OBJECTIVE_ID} yes}

    [fire_event]
        name=objectives controller
    [/fire_event]
#enddef

    #
    # Defeating Mal What's-His-Name.
    #
    [event]
        name=last breath
        [filter]
            id="Mal Ba'arth"
        [/filter]

        [message]
            speaker="Mal Ba'arth"
            message= _ "... It is true, then. The Dark Lady has finally arisen and come to reclaim this doomed world... But it is all in vain... all in vain..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id="Mal Ba'arth"
        [/filter]

        {INT_OBJECTIVE_COMPLETE defeat_council}
    [/event]

    #
    # Defeating the Storm Sisters.
    #
    [event]
        name=die
        [filter]
            id=Vrylla
            [or]
                id=Grylla
            [/or]
            [or]
                id=Aethengrya
            [/or]
        [/filter]
        [filter_condition]
            [not]
                [have_unit]
                    [not]
                        x,y=$x1,$y1
                    [/not]
                    [and]
                        id=Vrylla
                        [or]
                            id=Grylla
                        [/or]
                        [or]
                            id=Aethengrya
                        [/or]
                    [/and]
                [/have_unit]
            [/not]
        [/filter_condition]

        {INT_OBJECTIVE_COMPLETE defeat_sisters}
    [/event]

    #
    # Defeating supporting enemy leaders.
    #
    # They are handled on an individual basis (for granting the player bonus
    # units) in a different handler. We only do objectives tracking in this one.
    #
    [event]
        name=die
        [filter]
            canrecruit=yes
            [not]
                side=1
            [/not]
            [not]
                side=2
            [/not]
            [not]
                side=3
            [/not]
        [/filter]
        [filter_condition]
            [not]
                [have_unit]
                    canrecruit=yes
                    [not]
                        x,y=$x1,$y1
                    [/not]
                    [not]
                        side=1
                    [/not]
                    [not]
                        side=2
                    [/not]
                    [not]
                        side=3
                    [/not]
                [/have_unit]
            [/not]
        [/filter_condition]

        {INT_OBJECTIVE_COMPLETE defeat_other_enemy_leaders}
    [/event]

    [event]
        name=die
        first_time_only=no
        [filter]
            canrecruit=yes
            [and]
                [not]
                    side=1
                    [or]
                        side=2
                    [/or]
                [/not]
            [/and]
        [/filter]

        [fire_event]
            name=check citadel capture status
        [/fire_event]
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            id=Anya
        [/filter]

        [allow_undo][/allow_undo]

        [fire_event]
            name=check citadel capture status
        [/fire_event]
    [/event]

    #
    # Seizing the citadel after completing the minimum objectives.
    #
    [event]
        name=check citadel capture status
        [filter_condition]
            [have_unit]
                id=Anya
                x=49-51,50
                y=18-19,17
            [/have_unit]

            {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_council yes}
            {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_sisters yes}
        [/filter_condition]

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

        {PLACE_IMAGE scenery/banner-yechnagoth-standing-sw.png 51 18}

        [message]
            speaker=Anya
            message= _ "The citadel is ours! Now we should be able to find Elynia and—"
        [/message]

        {REPLACE_SCENARIO_MUSIC "the_city_falls.ogg"}
        {APPEND_MUSIC           "casualties_of_war.ogg"}
        {APPEND_MUSIC           "siege_of_laurelmor.ogg"}

        {INCIDENTAL_MUSIC       "northerners.ogg"}

        [message]
            speaker=Irylean
            message= _ "I fear that we will have to put that plan on hold, Anya. There are reports of more of those creatures coming from the hives around the citadel. People say they will be here in a matter of minutes."
        [/message]

        [message]
            speaker=Anya
            message= _ "But we have only just won! Are they going to storm their own capital now?"
        [/message]

        [message]
            speaker=Durvan
            message= _ "I would not put it past them to attempt to destroy the citadel in an attempt to ensure we cannot find Elynia... assuming she is even alive at this point."
        [/message]

        [message]
            speaker=Anya
            message= _ "Do <b>not</b> say that! Let’s repel those awful creatures, then!"
        [/message]

        [message]
            speaker=Irylean
            message= _ "Easier said than done..."
        [/message]

        [message]
            speaker=Igor
            message= _ "Battle goblin, ready to crush those bugs!"
        [/message]

        [fire_event]
            name=enter survival mode
        [/fire_event]

        {INT_OBJECTIVE_COMPLETE seize_citadel}
    [/event]

    [event]
        name=objective announce iron council left
        [message]
            speaker=Ergea
            message= _ "The Storm Sisters are now our prisoners, but we must destroy the last member of the Iron Council if we intend to seize the citadel."
        [/message]
    [/event]

    [event]
        name=objective announce storm sisters left
        [message]
            speaker=Ergea
            message= _ "The last member of the Iron Council is no more, but as long as any of the Storm Sisters still roam about, there shall be no end to our struggles."
        [/message]
    [/event]

    [event]
        name=objectives controller
        first_time_only=no

        [if]
            {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_council no}
            {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_sisters yes}
            [then]
                [fire_event]
                    name=objective announce iron council left
                [/fire_event]
            [/then]
        [/if]

        # Didn't want to go deeper with indentation here.

        [if]
            {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_council yes}
            {VARIABLE_BOOLEAN_EQUALS e3s8d_objectives_status.defeat_sisters no}
            [then]
                [fire_event]
                    name=objective announce storm sisters left
                [/fire_event]
            [/then]
        [/if]

        {INT_FORCE_OBJECTIVES_REFRESH}
    [/event]

    [event]
        name=enter survival mode

        # This is it, the end of the scenario. First increase turn limit and
        # configure the upcoming Shaxthal enemy waves. They take place every
        # four turns on any difficulty mode.

        {VARIABLE w ({DIFF 1 1 2})} # Number of survival waves
        {VARIABLE d 1} # Initial delay before the first wave
        {VARIABLE r 5} # Enemy waves rate (in turns)

        [modify_turns]
            value="$($turn_number + $d + $r * $w)"
        [/modify_turns]

        [for]
            variable=k
            start,end=1,$w
            [do]
                [event]
                    delayed_variable_substitution=no
                    name="turn $($turn_number + $r * ($k - 1) + $d)"

                    [fire_event]
                        name=create survival wave
                    [/fire_event]
                [/event]
            [/do]
        [/for]

        {CLEAR_VARIABLE w,d,r}

        #
        # Setup end-of-turns handler so victory is achieved by surviving until
        # the end of turns.
        #
        [event]
            name=time over

            {ENDLEVEL_QUIET}
        [/event]

        # The event which invoked us will take care of signaling the handler to
        # refresh the player objectives.
    [/event]

#define INT_SLF_SOUTHEAST_HIVE
    x=50-65
    y=47-56
#enddef

#define INT_SLF_NORTHWEST_HIVE
    x=4-15,16-22,23-33
    y=1-6 , 1-12, 1-10
#enddef

#define INT_GENERATE_WAVE _SLF_BASE
    [store_locations]
        terrain=C*
        {_SLF_BASE}
        variable=locs
    [/store_locations]

    [foreach]
        array=locs
        variable=loc
        [do]
            {VARIABLE_RANDOM type "Shaxthal Custodian Drone,Shaxthal War Drone,Shaxthal Enforcer Drone,Shaxthal Enforcer Drone"}
            {GENERIC_UNIT 10 $type $loc.x $loc.y} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {VARIATION surface}
        [/do]
    [/foreach]

    [store_locations]
        terrain=*^Xp
        {_SLF_BASE}
        variable=locs
    [/store_locations]

    [foreach]
        array=locs
        variable=loc
        [do]
            {VARIABLE_RANDOM type "Shaxthal Drone,Shaxthal Drone,Shaxthal Runner Drone,Shaxthal Runner Drone,Shaxthal Drone,Shaxthal Razorbird,Shaxthal Thunderbird,Shaxthal Assault Drone,Shaxthal Sentry Drone,Shaxthal Assault Drone,Shaxthal Drone"}
            {GENERIC_UNIT 10 $type $loc.x $loc.y} {NO_UPKEEP_NO_OVERLAY} {FACING nw} {VARIATION surface}
        [/do]
    [/foreach]
#enddef

    [event]
        name=create survival wave
        first_time_only=no

        #
        # Southeast
        #
        {INT_GENERATE_WAVE ({INT_SLF_SOUTHEAST_HIVE})}

        #
        # Northwest
        #
        {INT_GENERATE_WAVE ({INT_SLF_NORTHWEST_HIVE})}

        {CLEAR_VARIABLE type,locs}
    [/event]

    [event]
        name=victory

        {LOCK_VIEW}

        [hide_unit][/hide_unit]

        {FADE_TO_BLACK}

        {BLACK_SCREEN}

        [fade_out_music][/fade_out_music]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=narrator
            sound=rumble.ogg
            image=wesnoth-icon.png
            message= _ "The earth rumbles..."
        [/message]

        [delay]
            time=1500
        [/delay]

        {UNLOCK_VIEW}

        {CLEAR_VARIABLE e3s8d_objectives_status}
    [/event]

#undef INT_NO_DEMOLITION_ABILITY
#undef INT_OBJECTIVE_COMPLETE
#undef INT_FUNPACK_LOCATION_EVENT
#undef INT_GENERATE_WAVE
#undef INT_ANYA_THOUGHTS
#undef INT_RANDOM_ONE_TIME_SPEECH_EVENT
#undef INT_SPEECH
#undef INT_PLAYER_HELPER
#undef INT_PILLAGER
#undef INT_SLF_NORTHWEST_HIVE
#undef INT_SLF_SOUTHEAST_HIVE
#undef INT_FORCE_OBJECTIVES_REFRESH
[/scenario]

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