#textdomain wesnoth-ei

#
# This is intended to be a difficult mission, moreso than the next few.
# I think high difficulty is necessary to establish the undead (and particularly Mal-Ravanal) as a credible threat.
#
# At first, this scenario is pretty easy. The enemies have low gold and low income.
# But once Mal-Ravanal shows up, things get dangerous:
#    1) this (hopefully) makes the player fear Mal-Ravanal right off the bat
#    2) this establishes the undead invasion as a credible threat.
#
# In my expeience, the best strategy is to push forward and gather XP in the first half,
# then give ground after Mal-Ravanal shows up, during the second night.
# You need to have enough units/hp to push forward during the third day.
#

[scenario]
    id=01_Eastern_Invasion
    name= _ "Eastern Invasion"
    map_file=01_Eastern_Invasion.map
    next_scenario=02_The_Escape_Tunnel
    turns=11
    victory_when_enemies_defeated=no

    {DEFAULT_SCHEDULE_DUSK}

    {SETUP_CAMPFIRES}

    {INTRO_AND_SCENARIO_MUSIC main_menu.ogg loyalists.ogg}
    {LET_INTRO_MUSIC_FINISH}
    [story]
        [part]
            title= _ "Warning!"
            story= _ "Content note: this campaign has minor depictions of blood and gore."
        [/part]
        [part]
            #po: It is 625 YW. Konrad II is king, having reigned since 612.
            story= _ "It was the thirteenth year of Konrad II’s reign when the strange occurrences in the Estmark Hills on the eastern border of Wesnoth began."
            {EI_BIGMAP}
        [/part]
        [part]
            story= _ "Cattle and beasts of burden were found dead in the fields and villagers vanished from their houses with nary a clue nor sign of struggle. At first, the settlers suspected raiders from the great desert, but when they sent scouts east they found nothing but a small mountain range and miles of swamp."
            {EI_BIGMAP}
        [/part]
        [part]
            story= _ "The disappearances did not stop and every day the terror grew greater. Eventually, the people living in the eastern villages sent a messenger to the king, asking for help. The messenger rode hard for many days and nights, and finally reached the city of Weldyn."
            {EI_BIGMAP}
        [/part]
        [part]
            story= _ "When the king received news of the problem, his advisor Dacyn had much to say. Apparently, these attacks bore much similarity to ones that had previously occurred on the far southern border where undead had been the eventual culprit. Dacyn outlined a plan to combat these intrusions."
            {EI_BIGMAP}
        [/part]
        [part]
            #po: The River Guard posts had been built in 470 YW; they were abandoned in 544 YW.
            #po: The wave of colonization had begun around 530 YW.
            #po: This intro starts in 625 YW; the king's forces arrive at the outposts in 626 YW.
            story= _ "In the days of King Garard I, two strong points had been built along the near bank of the River Weldyn, south of Soradoc, to stop bandits and orcish raiders out of the Estmarks from entering Wesnoth. In later years, the river guard posts had been abandoned as colonists spread into the Estmarks and the orcs were driven in retreat north of the Great River."
            {EI_BIGMAP}
        [/part]
        [part]
            story= _ "With unknown enemies pressing Wesnoth from the East, Dacyn pressed Konrad II to re-man the outposts, and use them to keep the Crown’s eye and hand firmly on the lower River Weldyn. He sent two of the most promising young officers to them. To the northern outpost he sent Owaec, a Clan noble. To the southern outpost, he sent Sergeant Gweddry, who would be accompanied by Dacyn the mage."
            {EI_BIGMAP}
        [/part]
        [part]
            story= _ "All went well once the king’s forces arrived. There were no attacks for several weeks, and Gweddry’s men started to grow incautious. Then, one evening, Gweddry and his men were roused by the startled cries of the night watchmen..."
            {EI_BIGMAP}
            show_title=yes
        [/part]
    [/story]

    {EI_TRACK {JOURNEY_01_NEW} }

    [side]
        side=1
        controller=human
        {GOLD 130 120 110}
        team_name=wesnothians
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}

        # wmlint: recognize Gweddry
        {CHARACTER_STATS_GWEDDRY}
        facing=se

        [unit]
            x,y=10,14
            facing=se
            # wmllint: recognize Dacyn
            {CHARACTER_STATS_DACYN}
        [/unit]
    [/side]
    {STARTING_VILLAGES 1 10}

    [side]
        side=2
        controller=ai
        recruit=Skeleton,Skeleton Archer
        gold=0
        {INCOME -2 3 8}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Death Knight
        id=Nakeg-alvan # this guy reappears in S16 even if you kill him in S01. (maybe death knights can get re-animated)
        name= _ "Nakeg-alvan"
        canrecruit=yes
        facing=sw
        [ai]
            leader_value=0
        [/ai]
        # initial spawns so there's less dead-time where nobody is fighting
        {GENERIC_UNIT 2 (Skeleton Archer) 28 5}
#ifndef EASY
        {GENERIC_UNIT 2 (Skeleton Archer) 28 4}
        {GENERIC_UNIT 2 (Skeleton) 27 6}
#endif
#ifdef HARD
        {GENERIC_UNIT 2 (Skeleton) 29 6}
#endif

        {NOTRAIT_UNIT 2 (Vampire Bat) 17 1} {FACING nw} # so they don't waste time capturing those villages
        [+unit]
            [modifications]
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 2 1}

    [side]
        side=3
        controller=ai
        recruit=Vampire Bat,Walking Corpse,Soulless
        gold=0
        {INCOME -2 3 8}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Dark Sorcerer
        id=Mal-Talar
        #po: A male necromancer, reappears in S06b and can pursue the player to S07b.
        #po: In case a leader gets killed, there's some alias use between necromancers:
        #po: if Mel Guthrak dies in S01, the pursuer in S02 is renamed Mal-Talar
        #po: if Mal-Talar dies in S01, S02 can and S06b does rename to "Mal-Bakral"
        name= _ "Mal-Talar"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_INTELLIGENT}
        [/modifications]
        [ai]
            scout_village_targeting=0.9 # Most combat-oriented side. Don't go for villages as much
            leader_value=0
        [/ai]
        # initial spawns so there's less dead-time where nobody is fighting
        {GENERIC_UNIT 3 (Walking Corpse) 34 14}
        {GENERIC_UNIT 3 (Walking Corpse) 36 14}
#ifndef EASY
        {GENERIC_UNIT 3 (Soulless) 36 15}
        {GENERIC_UNIT 3 (Soulless) 34 15}
#endif
#ifdef HARD
        {GENERIC_UNIT 3 (Walking Corpse) 37 15}
        {GENERIC_UNIT 3 (Soulless) 35 14}
#endif
        {LOYAL_UNIT 3 (Ghoul) 38 13} {GUARDIAN} {FACING sw}
    [/side]
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 (Vampire Bat) 1}
    {SILENTLY_LIMIT_LEADER_MOVES 3 1}

    [side]
        side=4
        controller=ai
#ifdef EASY
        recruit=Skeleton,Skeleton Archer
#else
        recruit=Skeleton,Revenant,Skeleton Archer,Bone Shooter
#endif
        gold=0
        {INCOME 3 8 13}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Necromancer
        id=Mel Guthrak
        #po: See comments for Mal-Talar about which necromancer appears in S02.
        #po: This guy reappears no matter what in S16 (reanimated as a lich).
        name= _ "Mel Guthrak"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
        [ai]
            grouping=no
            leader_value=0
        [/ai]
        # initial spawns so there's less dead-time where nobody is fighting
        # reduced scaling because this section is easy on all difficulties, and fewer enemies means less XP for when Mal-Ravanal arrives
        {GENERIC_UNIT 4 (Bone Shooter) 25 28}
#ifndef EASY
        {GENERIC_UNIT 4 (Revenant) 26 26}
        {GENERIC_UNIT 4 (Skeleton) 26 28}
#endif
#ifdef HARD
        {GENERIC_UNIT 4 (Bone Shooter) 26 27}
#endif
        # Comments about Gaennell are in S13
        {NAMED_LOYAL_UNIT 4 (Dark Adept) 30 27 "Gaennell" (_"Gaennell")} {GUARDIAN} {FACING nw}
        [+unit]
            profile=portraits/gaennell-adept.webp
            gender=female
        [/unit]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 4 1}

    # some cowardly peasants/woodsmen, for flavor
    [side]
        side=5
        controller=ai
        hidden=yes
        team_name=wesnothians
        user_team_name= _ "Wesnothians"
        no_leader=yes
        {NOTRAIT_UNIT       5 (Peasant) 16 11} {FACING ne}
        [+unit]
            [modifications]
                {TRAIT_INTELLIGENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        {NAMED_NOTRAIT_UNIT 5 (Peasant) 21 17 "Vugreddyr" (_"Vugreddyr")} {FACING se}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        {NOTRAIT_UNIT       5 (Woodsman) 17 26} {FACING se}
        [+unit]
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
    [/side]
    # peasants escape when they get to the west edge
    [event]
        name=moveto
        first_time_only=no

        [filter]
            side=5
            x=1
        [/filter]

        {KILL id=$unit.id}
    [/event]

    [event]
        name=prestart

        # give the undead nearby villages, so they don't waste their tiny starting army capturing them
        {CAPTURE_VILLAGES 2 29 5  5}
        {CAPTURE_VILLAGES 2 17 1  1} # this one has a vampire bat on it
        {CAPTURE_VILLAGES 3 35 15 3}
        {CAPTURE_VILLAGES 4 30 25 7}

        # need to set recruits per-unit (instead of per-side) so we don't mess up the plague staff
        [set_extra_recruit]
            id=Gweddry
            extra_recruit={EARLY_RECRUIT_LIST}
        [/set_extra_recruit]

        {PLACE_IMAGE scenery/trapdoor-closed.png 10 15}

        [micro_ai]
            ai_type=coward
            action=add
            side=5
            [filter]
                side=5
            [/filter]
            distance=99
            seek_x,seek_y=1,6
            attack_if_trapped=yes
        [/micro_ai]

        [objectives]
            side=1
            [objective]
                description= _ "Survive until turns run out"
                condition=win
                [show_if]
                    [variable]
                        name=trapdoor_open
                        not_equals=yes
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Move any unit to the trapdoor just outside your keep (10,15)"
                condition=win
                [show_if]
                    [variable]
                        name=trapdoor_open
                        equals=yes
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry or Dacyn"
                condition=lose
            [/objective]
            [gold_carryover]
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=Gweddry
            #po: Probably only two or three watchmen
            message= _ "Watchmen, report. What’s going on?"
        [/message]
        [message]
            speaker=Vugreddyr
            message= _ "Help! Run for your lives!"
        [/message]
        [message]
            speaker=Dacyn
            #po: Speaking to Gweddry
            message= _ "See for yourself. Undead approach from the east."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Soldiers, to arms!"
        [/message]
    [/event]

    # necromancers inform Mal-Ravanal of the "resistance"
    # this is similar to the bat-messenger used in S06b
    [event]
        name=side 3 turn 2
        [message]
            speaker=Gaennell
            message= _ "Look! The old outpost is newly manned."
        [/message]
        [message]
            speaker=Mel Guthrak
            #po: Mal-Talar is a male dark sorcerer, he'll dispatch a messenger bat
            message= _ "Interesting... you, Talar, send news of this development."
        [/message]
        [animate_unit]
            [filter]
                id=Mal-Talar
            [/filter]
            flag=attack
            hits=no
            [primary_attack]
                range=ranged
                type=cold
            [/primary_attack]
            [facing]
                [filter]
                    x,y=36,15
                [/filter]
            [/facing]
        [/animate_unit]

        [move_unit_fake]
            type=Vampire Bat
            side=3
            x=36,39
            y=15,16
        [/move_unit_fake]
    [/event]

    #--------------------
    # SECOND DAY, REGROUP AI
    #--------------------
    # modify AI
    [event]
        name=side 1 turn end
        first_time_only=no
        {RESET_SIDE_AI 2,3,4 no 0.8 0.25}

        # only care about the 2nd day, not the 1st or 3rd
        [if]
            [lua]
                code=<< return (wesnoth.current.turn>3 and wesnoth.current.turn<10) >>
            [/lua]

            [then]
                {MODIFY_SIDE_AI (2,3,4) ({GOAL_LOCATION 1 (x,y=11,16)})}
                {VARY_AI_BY_SCHEDULE 2,3,4}
            [/then]
        [/if]
    [/event]

    # alert the player
    [event]
        name=prestart
        {VARIABLE deaths 0}
    [/event]
    [event]
        name=die
        first_time_only=no
        {VARIABLE_OP deaths add 1}
    [/event]
    [event]
        name=side 2 turn 5 end
        {FIND_NEARBY (side=1) 39 21 99}
        [if] {VARIABLE_CONDITIONAL deaths greater_than_equal_to 3}
            [then]
                # don't show this message if there hasn't been meaningful combat
                [message]
                    speaker=$found_unit.id
                    message= _ "Sun’s up! They’re falling back!"
                [/message]
            [/then]
        [/if]
    [/event]

    # Dacyn's disappearance and Mal-Ravanal's appearance
    # (turn refresh to be nice and let Dacyn heal everyone first)
    [event]
        name=side 1 turn 7 refresh

        {REPLACE_SCENARIO_MUSIC silence.ogg}
        [message]
            speaker=Dacyn
            message= _ "I sense a great power... no, it cannot be... I must not be seen."
        [/message]
        {LIGHT_SHIELD_EFFECT_OBJECT_ID Dacyn}
        [animate_unit]
            [filter]
                id=Dacyn
            [/filter]

            flag=disappear
        [/animate_unit]
        [store_unit]
            [filter]
                id=Dacyn
            [/filter]

            kill=yes
            variable=stored_Dacyn
        [/store_unit]

        # prefer to possess an existing skeleton if one is nearby
        # only look for units near the east edge of the map, to reduce RNG
        {FIND_NEARBY (type=Skeleton,Skeleton Archer,Revenant,Bone Shooter) 32 4 5}
        [if]
            {VARIABLE_CONDITIONAL found_unit.length equals 0}
            [then]
                {FIND_NEARBY (type=Skeleton,Skeleton Archer,Revenant,Bone Shooter) 28 30 5}
            [/then]
        [/if]
        [if]
            {VARIABLE_CONDITIONAL found_unit.length equals 0}
            [then]
                {FIND_NEARBY (type=Skeleton,Skeleton Archer,Revenant,Bone Shooter) 34  7 7}
            [/then]
        [/if]
        {SPAWN_IF_UNFOUND 3 (Skeleton) 32 16}
        {RAVANAL_POSSESS 39 $found_unit.y (x,y=$found_unit.x,$found_unit.y) (sw)}
        {CLEANUP_SEARCH}

        [delay]
            time=100
        [/delay]

        [message]
            speaker=Mal-Ravanal
            message= _ "This is the resistance you spoke of, an untrained commander and a few fresh recruits?"
        [/message]
        [message]
            speaker=Mal-Talar
            #po: Mal-Ravanal is neither male nor female, so avoid structures using direct addresses or pronouns when possible
            #po: Gender neutral pronouns or plural pronouns implying multiple entities are preferred, but you can use language default if that is not possible
            message= _ "My deepest apologies! Please, forgive us. There will be no more delays."
        [/message]
        [message]
            speaker=Mal-Ravanal
            message= _ "So you say."
        [/message]

        {REPLACE_SCENARIO_MUSIC the_dangerous_symphony.ogg}
        {APPEND_MUSIC heavens-remix.ogg}

#ifndef EASY
        {RAVANAL_ATTACK} {GENERIC_UNIT 3 (Ghost) $possessee.x $possessee.y} {ANIMATE}
        {RAVANAL_ATTACK} {GENERIC_UNIT 3 (Wraith) $possessee.x $possessee.y} {ANIMATE}
#endif
#ifdef HARD
        {RAVANAL_ATTACK} {GENERIC_UNIT 3 (Ghost) $possessee.x $possessee.y} {ANIMATE}
        {RAVANAL_ATTACK} {GENERIC_UNIT 3 (Ghost) $possessee.x $possessee.y} {ANIMATE}
#endif

        {MODIFY_UNIT id=Mal-Ravanal facing ne}
        {RAVANAL_ATTACK}
        {GENERIC_UNIT 2 (Skeleton) 27 6} {ANIMATE}
#ifndef EASY
        {GENERIC_UNIT 2 (Skeleton Archer) 29 5} {ANIMATE}
        {GENERIC_UNIT 2 (Skeleton) 29 5} {ANIMATE}
#endif
#ifdef HARD
        {GENERIC_UNIT 2 (Skeleton Archer) 29 5} {ANIMATE}
#endif

        {RAVANAL_ATTACK}
        {GENERIC_UNIT 3 (Soulless) 35 15} {ANIMATE}
#ifndef EASY
        {GENERIC_UNIT 3 (Soulless) 35 15} {ANIMATE}
#endif
#ifdef HARD
        {GENERIC_UNIT 3 (Walking Corpse) 35 15} {ANIMATE}
        {GENERIC_UNIT 3 (Soulless) 35 15} {ANIMATE}
#endif

        {RAVANAL_ATTACK}
        {GENERIC_UNIT 4 (Revenant) 28 27} {ANIMATE}
#ifndef EASY
        {GENERIC_UNIT 4 (Bone Shooter) 26 27} {ANIMATE}
        {GENERIC_UNIT 4 (Skeleton Archer) 30 27} {ANIMATE}
#endif
#ifdef HARD
        {GENERIC_UNIT 4 (Revenant) 26 26} {ANIMATE}
#endif

        [message]
            speaker=Mal-Ravanal
            #po: Mal-Ravanal has just animated 10 (more or less depending on difficulty) undead
            message= _ "That is how you raise thralls, apprentice. Carry on."
        [/message]
        [message]
            speaker=Mal-Talar
            message= _ "We shall ensure their destruction!"
        [/message]
        [delay]
            time=100
        [/delay]

        {RAVANAL_DEPOSSESS 39 $possessee.y}

        [message]
            speaker=Gweddry
            message= _ "Blast it, they’ve been reinforced! And why did Dacyn leave? We’ll have to hold back the undead until he returns."
        [/message]
    [/event]

    # to emphasize that the undead are unstoppable, give them extra gold as the scenario nears completion
    [event]
        name=turn 8
        [gold]
            side=2,3,4
            amount={ON_DIFFICULTY 0 10 20}
        [/gold]
    [/event]
    [event]
        name=turn 9
        [gold]
            side=2,3,4
            amount=50 # units recruited now won't be able to reach the player before the player wins, so here-on-out is just for show
        [/gold]
        [allow_recruit]
            side=2
            type=Bone Shooter,Revenant
        [/allow_recruit]
        [allow_recruit]
            side=3
            type=Ghoul
        [/allow_recruit]
    [/event]
    [event]
        name=turn 10
        [gold]
            side=2,3,4
            amount=100
        [/gold]
        [allow_recruit]
            side=3
            type=Necrophage
        [/allow_recruit]
        [allow_recruit]
            side=4
            type=Draug,Banebow
        [/allow_recruit]
    [/event]
    [event]
        name=turn 11
        [gold]
            side=2,3,4
            amount=150
        [/gold]
    [/event]
    [event]
        name=turn 12
        [gold]
            side=2,3,4
            amount=200
        [/gold]
    [/event]
    [event]
        name=turn 13
        [gold]
            side=2,3,4
            amount=250
        [/gold]
    [/event]

    [event]
        name=enemies defeated
        [fire_event]
            name=time over
        [/fire_event]
    [/event]
    [event]
        name=time over
        [modify_turns]
            value=-1
        [/modify_turns]

        # spawn a bunch of undead at the west edge, so we can say we've been flanked
        {GENERIC_UNIT 2 (Wraith) 6 1} {ANIMATE}
        {GENERIC_UNIT 2 (Dread Bat) 5 1} {ANIMATE}

        {GENERIC_UNIT 4 (Bone Shooter) 12 30} {ANIMATE}
        {GENERIC_UNIT 4 (Draug) 12 29} {ANIMATE}

        {GENERIC_UNIT 4 (Banebow) 1 22} {ANIMATE}
        {GENERIC_UNIT 4 (Revenant) 2 22} {ANIMATE}

        {GENERIC_UNIT 3 (Vampire Bat) 1 13} {ANIMATE}
        {GENERIC_UNIT 3 (Wraith)      1 14} {ANIMATE}
        {GENERIC_UNIT 3 (Blood Bat)   1 15} {ANIMATE}

        {GENERIC_UNIT 3 (Dark Sorcerer)  1 5 } {ANIMATE}
        {GENERIC_UNIT 3 (Dark Adept)     1 6 } {ANIMATE}
        {GENERIC_UNIT 3 (Ghoul)          2 5 } {ANIMATE}
        {GENERIC_UNIT 3 (Walking Corpse) 3 4} {ANIMATE}
        {GENERIC_UNIT 3 (Walking Corpse) 1 7} {ANIMATE}
        {GENERIC_UNIT 3 (Walking Corpse) 3 7} {ANIMATE}

        # keep spawning them each turn
        [event]
            name=side 4 turn end
            first_time_only=no

            {GENERIC_UNIT 2 (Ghost) 6 1} {ANIMATE}
            {GENERIC_UNIT 2 (Blood Bat) 5 1} {ANIMATE}

            {GENERIC_UNIT 4 (Revenant) 12 30} {ANIMATE}

            {GENERIC_UNIT 4 (Bone Shooter) 1 22} {ANIMATE}

            {GENERIC_UNIT 3 (Vampire Bat) 1 13} {ANIMATE}
            {GENERIC_UNIT 3 (Ghost)      1 14} {ANIMATE}

            {GENERIC_UNIT 3 (Soulless) 1 5} {ANIMATE}
            {GENERIC_UNIT 3 (Walking Corpse) 1 6} {ANIMATE}
            {GENERIC_UNIT 3 (Walking Corpse) 2 5} {ANIMATE}
        [/event]

        [message]
            speaker=Gweddry
            #po: a huge number of undead are spawning
            message= _ "Wha- How did so many of them flank us? We’re cut off from Wesnoth!"
        [/message]

        # Dacyn reappears and gives message about trapdoor.
        {SCROLL_TO 10 15}
        {VARIABLE stored_Dacyn.resting no}

        [if]
            [have_unit]
                id=Dacyn
            [/have_unit]

            [then] #if we somehow already have Dacyn (probably because of debug mode), don't do anything
            [/then]
            [else]
                {STORE_UNIT_VAR id=Gweddry x gweddry_x}
                {STORE_UNIT_VAR id=Gweddry y gweddry_y}
                [unstore_unit]
                    variable=stored_Dacyn
                    x,y=$gweddry_x,$gweddry_y
                    find_vacant=yes
                [/unstore_unit]
                {CLEAR_VARIABLE gweddry_x,gweddry_y}
            [/else]
        [/if]
        {CLEAR_VARIABLE stored_Dacyn}
        [animate_unit]
            [filter]
                id=Dacyn
            [/filter]

            flag=reappear
        [/animate_unit]
        [message]
            speaker=Dacyn
            #po: Dacyn doesn't really express much and doesn't like to explain himself
            message= _ "Gweddry? Ah, you survive."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Dacyn, why did you flee the battle? Our situation has become rather desperate."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Now is not the time for a lengthy report. Unless you intend to die, I suggest you escape through this trapdoor."
        [/message]

        [if]
            [have_unit]
                x,y=10,15
                [not]
                    side=1
                [/not]
            [/have_unit]

            [then]
                {DACYN_FAKEATTACK}
                {KILL x,y=10,15 ANIMATE=yes}
            [/then]
        [/if]
        [store_unit] # hide any unit on 10,15 so it's easier to see where the trapdoor is
            [filter]
                x,y=10,15
            [/filter]

            variable=trapdoor_unit
            kill=yes
        [/store_unit]

        {HIGHLIGHT_IMAGE 10 15 items/gohere-empty.png scenery/trapdoor-open.png}

        [if]
            {VARIABLE_CONDITIONAL trapdoor_unit.length greater_than 0}
            [then]
                [unstore_unit]
                    variable=trapdoor_unit
                    animate=no
                [/unstore_unit]
                {CLEAR_VARIABLE trapdoor_unit}
            [/then]
        [/if]

        [message]
            speaker=Gweddry
            message= _ "But we have orders to hold this outpost!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "You have not yet seen even one-hundredth of the undead armies. This outpost is already lost. Your death — as heroic as I am sure it would be — will benefit no one. Now come, there is little time to spare."
        [/message]
        [modify_turns]
            value=-1
        [/modify_turns]
        {VARIABLE trapdoor_open yes}
        [show_objectives]
        [/show_objectives]

#define VICTORY_CHOICE
    [message]
        side=1
        x,y=10,15
        message= _ "I’m at the trapdoor! Follow me!"
        [option]
            label= _ "Escape"
            [command]
                [hide_unit]
                    id=$unit.id
                [/hide_unit]
                [redraw][/redraw]
                [endlevel]
                    result=victory
                    bonus=no
                    {NEW_GOLD_CARRYOVER 40}
                [/endlevel]
            [/command]
        [/option]
        [option]
            label= _ "Wait"
        [/option]
    [/message]
#enddef
        # in case you already have a unit on the trapdoor
        [if]
            [have_unit]
                side=1
                x,y=10,15
            [/have_unit]

            [then]
                {VICTORY_CHOICE}
            [/then]
        [/if]

        # you win when you move to the trapdoor
        [event]
            name=moveto
            first_time_only=no

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

            {VICTORY_CHOICE}
        [/event]
    [/event]

    # You are urged to hurry
    [event]
        name=turn 14
        [message]
            speaker=Dacyn
            message= _ "If you wish to die, there will be plenty of time for that later."
        [/message]
    [/event]

    #------------------
    # LAST BREATH EVENTS
    #------------------
    [event]
        name=last breath

        [filter]
            id=Nakeg-alvan
        [/filter]

        [message]
            speaker=Nakeg-alvan
            message= _ "..."
        [/message]
        [modify_side]
            side=2,3,4
            gold=50
        [/modify_side]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Mal-Talar
        [/filter]

        [message]
            speaker=Mal-Talar
            message= _ "No! I was promised I could rule this province!"
        [/message]
        [modify_side]
            side=2,3,4
            gold=50
        [/modify_side]
        {VARIABLE talar_dead yes}
    [/event]

#define GAENNELL_RUN
    [message]
        speaker=Gaennell
        #po: Gaennell gets to run away instead of dying
        message= _ "Get me out of here!"
    [/message]
    {MOVE_UNIT id=Gaennell 32 30}
    {KILL id=Gaennell}
#enddef
    [event]
        name=last breath

        [filter]
            id=Mel Guthrak
        [/filter]

        [message]
            speaker=Mel Guthrak
            message= _ "You may defeat me now, but I will return!"
        [/message]
        [modify_side]
            side=2,3,4
            gold=50
        [/modify_side]
        {VARIABLE guthrak_dead yes}
        {GAENNELL_RUN}
    [/event]
    [event]
        name=last breath

        [filter]
            id=Gaennell
        [/filter]

        {GAENNELL_RUN}
    [/event]

    # sometimes, Gaennell plays her recruit anim alongside Mel Guthrak
    [event]
        name=prerecruit
        first_time_only=no

        [filter]
            side=4
        [/filter]

        {RANDOM yes,no}
        [if]
            {VARIABLE_CONDITIONAL random equals yes}
            [then]
                [animate_unit]
                    [filter]
                        id=Gaennell
                    [/filter]

                    flag=attack # can't get recruiting anim to work, so using attack anim instead
                    hits=no
                    [primary_attack]
                        range=ranged
                        type=cold
                    [/primary_attack]
                [/animate_unit]
            [/then]
        [/if]
    [/event]

    [event]
        name=victory
        [if]
            [have_unit]
                side=1
                count=10-99
            [/have_unit]

            [then]
                [set_achievement]
                    content_for=eastern_invasion
                    id=ei_S01
                [/set_achievement]
            [/then]
        [/if]
        {CLEAR_VARIABLE trapdoor_open,deaths}
    [/event]

    {EARLY_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
[/scenario]
