#textdomain wesnoth-ei

#
# if the player is already struggling, this scenario is easy. With no recall list, you can win by just rushing Gweddry/Owaec/Dacyn acrosss
# and if you have a single castle of worthwhile recalls, it's still fairly easy to get across
#
# but a veteran player with a huge recall list will have difficulty getting everyone across the bridge safely, because of both the gold costs and the time limit
# this is designed to equalize things a little bit, and make it a little harder for a player's recall list to snowball out of control
#

#
# the extremely low turn limit is to discourage winning via killing enemy leaders.
# while killing enemy leaders is an option, it bypasses the ending cutscene and feels against the spirit of the scenario
# instead, players are encouraged to rush across the bridge as quickly as possible, which takes far fewer turns than direct combat
#
# low turn limit also discourages using the bridge chokepoint to farm excessive kills
#

#define SCENARIO_TURN_LIMIT
11 #enddef
#define TURNS_LOW_WARNING
9 #enddef

#define NOT_ACROSS_RIVER
    [not]
        x=0-4, 5-9
        y=0-99,0-13
    [/not]
#enddef

[scenario]
    id=12_Evacuation
    name= _ "Evacuation"
    map_file=12_Evacuation.map
    turns={SCENARIO_TURN_LIMIT}
    next_scenario=13_Spoils_of_War

    {WINTER_SCHEDULE}
    current_time=1 # midday

    {SCENARIO_MUSIC loyalists.ogg}

    [story]
        [part]
            story= _ "Gweddry and his men escaped from the orcish prisons and fled westward as swiftly as they could, closely pursued by the orcs and their drake vassals."
            music=silence.ogg
        [/part]
    [/story]

    {EI_TRACK {JOURNEY_12_NEW} }

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

    [side]
        color=white
        side=2
        type=Orcish Warlord
        id=Varrak-Klar
        #po: In S12, a leader with a high but not unbeatable amount of gold.
        #po: However, if Chief Dra-Nak survived S11 then S12's Varrak-Klar will be changed to an Orcish Sovereign and renamed to appear to be the Chief pursuing the escapees.
        name= _ "Varrak-Klar"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_STRONG}
        [/modifications]
        controller=ai
        recruit= # handle recruits via "LIMIT_CONTEMPORANEOUS_RECRUITS". Limit the total number to reduce screen clutter
        {GOLD    0 75 125} # Since this scenario is so short, the first couple rounds of recruits matter much more than the later rounds.
        {INCOME 23 73 123} # This distorts gold-based easy/normal scaling. Instead, balance via income.
        team_name=bad
        user_team_name=_"Clan Whitefang"
        {FLAG_VARIANT6 ragged}
        [ai]
            leader_value=0
        [/ai]
        {LOYAL_UNIT 2 (Direwolf Rider)     31 1} {GUARDIAN} {FACING sw} # don't vary with difficulty, since these guys are purely for defense,
        {LOYAL_UNIT 2 (Orcish Warrior)     30 6} {GUARDIAN} {FACING sw} # and we want to discourage killing enemy leaders even at low difficulties
        {LOYAL_UNIT 2 (Orcish Warrior)     30 3} {GUARDIAN} {FACING sw}
        {LOYAL_UNIT 2 (Orcish Crossbowman) 26 3} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT 2 (Goblin Pillager) 29 1} {FACING sw}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
        # plus a few units that attack right away
        {GENERIC_UNIT 2 (Wolf Rider)      30 1} {FACING sw}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 2 1}
    {STARTING_VILLAGES 2 5}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Wolf Rider"      1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Goblin Pillager" 4}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Goblin Knight"   4}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Direwolf Rider"  4} # includes the starting loyal
    [event]
        name=prestart
        [if]
            {VARIABLE_CONDITIONAL dra_nak_dead not_equals yes}
            [then]
                {MODIFY_UNIT id=Varrak-Klar name _"Chief Dra-Nak"}
                {ADVANCE_UNIT id=Varrak-Klar "Orcish Sovereign"}
                {MODIFY_UNIT id=Varrak-Klar profile portraits/orcs/ruler-2.webp}
            [/then]
        [/if]
    [/event]

    [side]
        color=orange
        side=3
        type=Drake Flameheart
        id=Mortic
        name= _ "Mortic"
        canrecruit=yes
        controller=ai
        experience=9 # since he probably got some XP from the fight in S09
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_STRONG}
        [/modifications]
        recruit= # handle recruits via "LIMIT_CONTEMPORANEOUS_RECRUITS". Limit the total number to reduce screen clutter
        {GOLD    0 45 75} # Since this scenario is so short, the first couple rounds of recruits matter much more than the later rounds.
        {INCOME 13 43 73} # This distorts gold-based easy/normal scaling. Instead, balance via income.
        team_name=bad
        user_team_name=_"Drakes"
        [ai]
            leader_value=0
        [/ai]
        {LOYAL_UNIT 3 (Drake Thrasher)  18 7} {GUARDIAN} {FACING se}
        {LOYAL_UNIT 3 (Drake Warden)    14 9} {GUARDIAN} {FACING se}
        {LOYAL_UNIT 3 (Hurricane Drake) 15 2} {GUARDIAN} {FACING se}
        {LOYAL_UNIT 3 (Hurricane Drake) 13 1} {GUARDIAN} {FACING sw}
        {LOYAL_UNIT 3 (Sky Drake)       12 2} {GUARDIAN} {FACING se}

        {NOTRAIT_UNIT 3 (Drake Arbiter) 15 6}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        {NOTRAIT_UNIT 3 (Drake Clasher) 14 6}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 3 1}
    {STARTING_VILLAGES_AREA 3 14-19 0-11 0}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Burner"   2} # if there's too many of these, chopping the bridge down seems meaningless
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Fighter"  2} # if there's too many of these, chopping the bridge down seems meaningless
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Clasher"  4}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Arbiter"  2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Thrasher" 2} # includes the starting loyal

    [side]
        color=white
        side=4
        type=Orcish Slurbow
        id=Rakkha
        #po: In S12, a leader with a high but not unbeatable amount of gold.
        name= _ "Rakkha"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_QUICK}
            {TRAIT_RESILIENT}
        [/modifications]
        controller=ai
        recruit= # handle recruits via "LIMIT_CONTEMPORANEOUS_RECRUITS". Limit the total number to reduce screen clutter
        {GOLD    0 45 75} # Since this scenario is so short, the first couple rounds of recruits matter much more than the later rounds.
        {INCOME 13 43 73} # This distorts gold-based easy/normal scaling. Instead, balance via income.
        team_name=bad
        user_team_name=_"Clan Whitefang"
        {FLAG_VARIANT6 ragged}
        [ai]
            leader_value=0
        [/ai]
        {LOYAL_UNIT 4 (Orcish Warrior)     22 21} {GUARDIAN} {FACING sw}
        {LOYAL_UNIT 4 (Orcish Crossbowman) 18 24} {GUARDIAN} {FACING sw}

        {GENERIC_UNIT 4 (Orcish Warrior) 25 24}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]

        {GENERIC_UNIT 4 (Orcish Archer)  29 22}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 4 1}
    {STARTING_VILLAGES_AREA 4 0-99 19-99 0}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Orcish Grunt"       2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Orcish Warrior"     3} # includes the starting loyal
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Orcish Archer"      2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Orcish Crossbowman" 4} # includes the starting loyal
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Orcish Assassin"    2}

    [event]
        name=side 1 turn end
        first_time_only=no
        {RESET_SIDE_AI 2,3,4 offensive 0.8 0.25}

        # drakes don't fly across the river
        {MODIFY_SIDE_AI (3) (
            [avoid]
                x,y=0-5,0-99
            [/avoid]
        )}

        {VARY_AI_BY_SCHEDULE_WINTER 2,3,4}
    [/event]

    [event]
        name=prestart

        {RECALL_XY Owaec 23 10}
        {RECALL_XY Dacyn 24 11} # he's slow, so put him near the bridge
        [modify_unit]
            [filter]
                id=Dacyn
            [/filter]
            [object]
                id=dacyn_no_halo
                [effect]
                    apply_to=remove_ability
                    [experimental_filter_ability]
                        tag_name=illuminates
                    [/experimental_filter_ability]
                [/effect]
            [/object]
        [/modify_unit]
        {RECALL_XY Addogin 24 9}
        {RECALL_XY (Hahid al-Ali) 24 9} # he drinks an elixir of haste. To make it more meaningful, put him on the furthest tile from the bridge
        {RECALL_XY Terraent 24 9}
        {RECALL_XY Dolburras 23 11} # he's slow, so put him near the bridge
        {RECALL_XY Grug 23 11}

        # on Easy, Dacyn starts with full hitpoints in the previous scenario, so it would be odd for him to be injured here
        {MODIFY_UNIT (id=Dacyn) hitpoints {ON_DIFFICULTY 47 34 21}}

        [objectives]
            side=1
            [objective]
                description= _ "Move Owaec to the end of the bridge"
                condition=win
            [/objective]
            {ALTERNATIVE_OBJECTIVE ( _ "Defeat all enemy leaders")}
            [objective]
                description= _ "Death of Gweddry, Dacyn, or Owaec"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]

            [note]
                description= _ "It is winter, daytime is shorter"
            [/note]
            [note]
                description= _ "<b>Every unit east of the bridge when it is destroyed will be lost (including non-recalled units)</b>"
            [/note]
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=Gweddry
            message= _ "Dacyn, are you feeling better? We must keep moving! The orcs have almost caught up to us."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "(cough) (cough) Yes, yes, I’m perfectly fine... (cough)"
        [/message]
        [message]
            speaker=Owaec
            message= _ "Such decrepitude is one ten-thousandth of what you deserve for wielding that evil amulet! But lo, a bridge in the distance! Hope is not yet lost."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "We must get across quickly before we are cut off and overwhelmed. But the men are exhausted! We cannot keep running for much longer."
        [/message]
        [message]
            speaker=Grug
            message= _ "(nodding) Gruuhhh... Grug tired. Leg hurt..."
        [/message]
        [message]
            speaker=Dolburras
            #po: "Yeah, don't forget! My legs aren't as long as you humans'!"
            message= _ "Aye, dinnae forget, my legs ain’t as long as ye human-folks’!"
        [/message]
        [message]
            speaker=Owaec
            message= _ "Tell the men they need not fear! I will cross last and destroy the bridge behind us so that the orcs cannot follow!"
        [/message]
        {HIGHLIGHT_IMAGE 4 15 items/gohere.png ()}
        [message]
            speaker=Hahid al-Ali
            message= _ "Well I intend to cross first! Gold’s no good if I die before I can spend it! I’m not about to sacrifice myself to save you bunch of barbarians."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Everyone, get moving! Anyone left behind on this side of the bridge will surely be killed!"
        [/message]
        [message]
            speaker=Addogin
            message= _ "I’m gettin’ too old for this life..."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "All units <b>(including non-recalled units!)</b> left behind will be lost."
        [/message]
        {REPLACE_SCENARIO_MUSIC cry_from_elensefar.ogg}
        {APPEND_MUSIC legends_of_the_north.ogg}
        {APPEND_MUSIC frantic.ogg}

        [store_gold] # store this now in case we spend it before the IF_GOLD event
            side=1
        [/store_gold]
    [/event]
    [event]
        name=recruit,recall,moveto,side 1 turn end # so it triggers very quickly
        [if]
            {VARIABLE_CONDITIONAL gold less_than_equal_to 0}
            [then]
                [message]
                    speaker=Dacyn
                    message= _ "It is unfortunate (cough) that we have not saved any gold to recruit or recall. Escape for our soldiers is impossible, yet if us few rush immediately across the bridge we may be able to (cough)(cough) reach the far shore before the orcs can attack."
                [/message]
            [/then]

            [else]
                [if]
                    {VARIABLE_CONDITIONAL gold less_than 100}
                    [then]
                        [message]
                            speaker=Dacyn
                            message= _ "It is unfortunate (cough) that we have saved little gold to recruit or recall. Escape for everyone is likely impossible, yet if the 3 of us rush immediately across the bridge we may be able to (cough)(cough) reach the far shore before the orcs can attack."
                        [/message]
                    [/then]

                    [else]
                        [if]
                            {VARIABLE_CONDITIONAL gold less_than 200}
                            [then]
                                [message]
                                    speaker=Dacyn
                                    message= _ "We have enough gold to put up a fight, but the orcs are numerous (cough) and strong. Escape for everyone is likely impossible, yet if the 3 of us rush immediately across the bridge we may be able to (cough)(cough) reach the far shore before the orcs can attack."
                                [/message]
                            [/then]

                            [else]
                                [message]
                                    speaker=Dacyn
                                    message= _ "We have gold for many soldiers, but the bridge (cough) is long and narrow. Escape for everyone is likely impossible, yet if the 3 of us rush immediately across the bridge we may be able to (cough)(cough) reach the far shore before the orcs can attack."
                                [/message]
                            [/else]
                        [/if]
                    [/else]
                [/if]
            [/else]
        [/if]
        [message]
            speaker=Owaec
            #po: Although Dacyn is a Mage of Light, he currently doesn't have a halo.
            #po: In the unlikely case that he was still L2 when he picked up the amulet, he's automatically advanced at that point in S10.
            message= _ "Small wonder your Light has abandoned you, if you would leave our companions to the mercy of the orcs! We should all cross together and leave none behind!"
        [/message]
        [message]
            speaker=Dacyn
            #po: After this message the halo flickers and then stays on.
            message= _ "(cough) My light? ...oh, oh yes, yes of course. Just one moment."
        [/message]
        [repeat]
            times=8
            [do]
                [delay]
                    time=100
                [/delay]
                [modify_unit]
                    [filter]
                        id=Dacyn
                    [/filter]
                    [object]
                        id=dacyn_no_halo
                        [effect]
                            apply_to=remove_ability
                            [experimental_filter_ability]
                                tag_name=illuminates
                            [/experimental_filter_ability]
                        [/effect]
                    [/object]
                [/modify_unit]
                [redraw]
                [/redraw]
                [delay]
                    time=50
                [/delay]
                [remove_object]
                    id=Dacyn
                    object_id=dacyn_no_halo
                [/remove_object]
                [redraw]
                [/redraw]
            [/do]
        [/repeat]
        [delay]
            time=750
        [/delay]
    [/event]

    # hahid drinks an elixir
    # not on turn 1, since there's already a big info dump there
    [event]
        name=side 1 turn 2
        [filter_condition]
            [have_unit]
                id=Hahid al-Ali
            [/have_unit]
        [/filter_condition]
        [message]
            speaker=Hahid al-Ali
            #po: He drinks an elixir between this message and the next one
            message= _ "Trapped among barbarians and pursued by orcs... how in the sands did I get here? Time to break out something I’ve been saving for a rainy day..."
        [/message]

        {STORE_UNIT_VAR (id=Hahid al-Ali) x hahid_x}
        {STORE_UNIT_VAR (id=Hahid al-Ali) y hahid_y}
        {DISPLAY_HASTE}
        {GIVE_HASTE $hahid_x $hahid_y ()}
        {CLEAR_VARIABLE hahid_x}
        {CLEAR_VARIABLE hahid_y}

        [message]
            speaker=Hahid al-Ali
            #po: He drank an elixir between the last message and this one
            message= _ "Nothing like some extra speed to help me get away!"
        [/message]
    [/event]

    [event]
        name=turn 5
        [message]
            speaker=Owaec
            #po: Addressed to Gweddry, but many of the heroes except Dacyn are together in this conversation, assuming the player managed to collect them.
            #po: It has to still make sense with only Gweddry and Owaec talking to each other.
            message= _ "Gweddry, you saw how Dacyn struggled to channel his Light. What do you think of this?"
        [/message]
        [message]
            speaker=Dolburras
            message= _ "Aye, and have ye noticed the man’s cough? He be trying to hide it."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "... it is a bad sign, to be sure. But Dacyn is determined to protect Wesnoth and destroy Mal-Ravanal, and I believe he is our only chance at doing so."
        [/message]
        [message]
            speaker=Grug
            message= _ "Magic man kind! Be good magic man be."
        [/message]
        [message]
            speaker=Owaec
            message= _ "I agree his intentions are good, but with each passing hour, that foul amulet’s darkness festers within him. What influence may it have?"
        [/message]
        [message]
            speaker=Terraent
            message= _ "I choose to place my faith in the holy Light, not the darkness! We will overcome Mal-Ravanal’s evil, and this dark amulet’s as well."
        [/message]
        [message]
            speaker=Hahid al-Ali
            #po: Last message in the "Gweddry, you saw how Dacyn struggled to channel his Light" conversation
            message= _ "Bah, magic! There’s a reason the civilized people of my world eschew magic — we would never have to deal with problems like this back in my homeland."
        [/message]
    [/event]

    # orcs announce their daytime retreat (and drakes complain about it)
    [event]
        name=turn 7

        [filter_condition]
            [have_unit]
                race=orc
                canrecruit=yes
            [/have_unit]
            [and]
                [have_unit]
                    id=Mortic
                [/have_unit]
            [/and]
        [/filter_condition]

        [message]
            race=orc
            canrecruit=yes
            #po: Speaker might be any of Chief Dra-Nak, Varrak-Klar or Rakkha; all three are male orcs.
            message= _ "(squinting) I can’t see anything in this searing sunlight. Fall back, wait for dusk!"
        [/message]
        [message]
            id=Mortic
            #po: to the male orc leader who's ordering the retreat
            message= _ "The sun strengthens my kin.
Daytime is our Domain.
We should press the attack."
        [/message]
        [message]
            race=orc
            canrecruit=yes
            #po: The messages in this event give the player a chance to react to the retreat.
            #po: By now they should know that enemies retreat during the day, but it's especially important to know now so they can evacuate.
            message= _ "You heard me, wyrm! Wait. For. Dusk."
        [/message]
    [/event]

#define DESTROY_BRIDGE X Y
    [sound]
        name=wose-die.ogg
    [/sound]
    {MODIFY_TERRAIN Wo {X} {Y}}
    [redraw][/redraw]
    [kill]
        x,y={X},{Y}

        [not]
            id=Owaec
        [/not]

        [not]
            type_adv_tree=Drake Fighter,Drake Burner,Drake Glider
        [/not]

        [not]
            variation=drake,falcon,gryphon,bat
        [/not]

        fire_event=yes
        animate=yes
    [/kill]
    [delay]
        time=400
    [/delay]
#enddef
    [event]
        name=moveto
        first_time_only=no
        [filter]
            x,y=4,15
            id=Owaec
        [/filter]
        [message]
            speaker=Owaec
            message= _ "Is everyone across? I’m ready to chop down the bridge."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Hmm..."
            [option]
                label= _ "Yes, destroy the bridge."
                [command]
                    [animate_unit]
                        flag=attack
                        [filter]
                            id=Owaec
                        [/filter]
                        [primary_attack]
                            name=greathammer
                        [/primary_attack]
                        hits=yes
                        [facing]
                            x,y=5,16
                        [/facing]
                    [/animate_unit]
                    {DESTROY_BRIDGE 4 15}
                    {DESTROY_BRIDGE 5 16}
                    {DESTROY_BRIDGE 6 16}
                    {DESTROY_BRIDGE 7 17}

                    #-----------------
                    # GWEDDRY/DACYN LEFT BEHIND
                    #-----------------
                    {FIND_NEARBY (
                        side=1
                        id=Gweddry,Dacyn # Owaec can't be left behind, since he's needed to chop down the bridge
                        {NOT_ACROSS_RIVER}
                    ) 24 10 99}
                    [if]
                        {VARIABLE_CONDITIONAL found_unit.id equals Dacyn}
                        [then]
                            [message]
                                speaker=Dacyn
                                #po: Owaec has just destroyed the bridge
                                message= _ "Owaec, you fool! I am trapped on the east bank! Without my help Wesnoth will surely fall to Mal-Ravanal..."
                            [/message]
                            [endlevel]
                                result=defeat
                            [/endlevel]
                            [return][/return]
                        [/then]
                    [/if]
                    [if]
                        {VARIABLE_CONDITIONAL found_unit.id equals Gweddry}
                        [then]
                            [message]
                                speaker=Dacyn
                                #po: Owaec has just destroyed the bridge
                                message= _ "Owaec, you fool! Gweddry is trapped on the east bank! Without his help Wesnoth will surely fall to Mal-Ravanal..."
                            [/message]
                            [endlevel]
                                result=defeat
                            [/endlevel]
                            [return][/return]
                        [/then]
                    [/if]
                    {CLEAR_VARIABLE found_unit}

                    #-----------------
                    # UNITS LEFT BEHIND
                    #-----------------
                    {PUT_TO_RECALL_LIST (
                        side=1
                        {NOT_ACROSS_RIVER}
                        [not]
                            variation=drake,falcon,gryphon,bat
                        [/not]
                    )}

                    # if we have a meaningful amount of leveled units, play a brief cutscene
                    {STORE_RECALLS (level=2-99) left_behind_units} # first just store the 2-99 level units, so we can check the count
                    {STORE_RECALLS (level=2-99) gweddrys_remnants} # save these units in a new variable, which we'll use for the bonus scenario S99 (the original variable gets modified)
                    [if]
                        {VARIABLE_CONDITIONAL left_behind_units.length greater_than_equal_to 2}
                        [then]
                            {STORE_RECALLS (level=0-1) left_behind_units} # add the 0-1 units in too
                            {STORE_RECALLS (level=0-1) gweddrys_remnants}
                            [store_locations]
                                x=24,25,24,23,  26,25,23,  23,21,23 # assorted tiles near your starting keep
                                y=10,11, 9,10,  10,13, 9,  11,10,12
                                variable=recall_locations
                            [/store_locations]
                            [foreach]
                                array=recall_locations
                                [do]
                                    [recall]
                                        find_in=left_behind_units[0]
                                        x,y=$this_item.x,$this_item.y
                                    [/recall]
                                    {CLEAR_VARIABLE left_behind_units[0]}
                                [/do]
                            [/foreach]

                            [message]
                                speaker=Owaec
                                #po: Several high-level units were left unrecalled. For a brief cutscene, 10 unrecalled units (high levels preferred) appear on the starting castle.
                                message= _ "Alas, what have I done? So many brave soldiers of Wesnoth, left behind in the wildlands..."
                            [/message]
                            [message]
                                side=1
                                x,y=21-26,9-13
                                level=2-99

                                [not]
                                    id=Hahid al-Ali
                                [/not]
                                [not]
                                    race=ogre
                                [/not]
                                #po: Said by any left-behind unit except ogres (they can't speak fluently) and Hahid al-Ali (it would be very out of character for him).
                                #po: TODO in 1.19: the "we" in this is a typo. It should be "you must ride ..."
                                message= _ "At least you three commanders are safe. From here, we must ride swift, ride strong, and ride to save all of Wesnoth!"
                            [/message]
                        [/then]

                        [else]
                            [message]
                                speaker=Owaec
                                #po: either got everyone across or left behind at most one L2 or L3 unit
                                message= _ "Huzzah, we have escaped the northerners! A true Clansman would never willingly leave his companions behind, and so have we clutched victory from the jaws of defeat!"
                            [/message]
                        [/else]
                    [/if]
                    {CLEAR_VARIABLE left_behind_units}

                    #-----------------
                    # ANNOUNCE OUR ESCAPE
                    #-----------------
                    [if]
                        [have_unit]
                            id=Mortic
                        [/have_unit]

                        [then]
                            [message]
                                speaker=Dacyn
                                message= _ "Yes, yes, (cough)(cough) that’s all well and good. With the bridge destroyed, the orcs cannot (cough) cross, but what of the drakes?"
                            [/message]
                        [/then]

                        [else]
                            [message]
                                speaker=Dacyn
                                message= _ "(cough) And with the drakes defeated, (cough)(cough) no enemies will be able to pursue us. Now, it is finally time for us to once again travel toward Weldyn."
                            [/message]
                        [/else]
                    [/if]

                    #-----------------
                    # MORTIC REBELS AGAINST ORCS
                    #-----------------
                    [if]
                        [have_unit]
                            id=Mortic
                        [/have_unit]

                        [then]
                            [message]
                                race=orc
                                canrecruit=yes
                                #po: Spoken to Mortic, but at this point it's possible that all the orc leaders are dead, in which case it doesn't get said.
                                message= _ "Useless pathetic ugly weakling wyrms! Fly across and chase after them, or we’ll sell you <i>all</i> to the necromancers!"
                            [/message]
                            [if]
                                {VARIABLE_CONDITIONAL dra_nak_dead equals yes}
                                [then]
                                    [message]
                                        speaker=Mortic
                                        #po: to his fellow drakes, and any surviving orcs
                                        message= _ "Dra-Nak is dead,
His armies weakened,
His prey fled."
                                    [/message]
                                [/then]

                                [else]
                                    [message]
                                        speaker=Mortic
                                        #po: to his fellow drakes, and any surviving orcs
                                        message= _ "Dra-Nak is feeble,
His armies weakened,
His prey fled."
                                    [/message]
                                [/else]
                            [/if]
                            [message]
                                speaker=Mortic
                                #po: to his fellow drakes, and any surviving orcs
                                message= _ "Long has our Honor been stained.
No longer shall it be.
Now we reclaim our Aerie,
And the strength of our Flight."
                            [/message]
                            {FIND_NEARBY (side=2,4) 14 7 99}
                            [if]
                                [not]
                                    [variable]
                                        name=found_unit.length
                                        greater_than=0
                                    [/variable]
                                [/not]

                                [then]
                                    {GENERIC_UNIT 2 (Orcish Warrior) 31 2}
                                    {GENERIC_UNIT 2 (Wolf Rider) 31 1}
                                    {GENERIC_UNIT 2 (Orcish Archer) 30 3}
                                    {FIND_NEARBY (side=2,4) 31 2 99}
                                [/then]
                            [/if]

                            {MOVE_UNIT id=Mortic $found_unit.x $found_unit.y}
                            [message]
                                speaker=$found_unit.id
                                #po: Speaker is an orc, and Mortic is flying towards them. "What? Hey!" *gets killed by Mortic*
                                message= _ "Wha- hey!"
                            [/message]
                            [animate_unit]
                                [filter]
                                    id=Mortic
                                [/filter]

                                flag=attack
                                [primary_attack]
                                    range=melee
                                [/primary_attack]
                                [facing]
                                    x,y=$found_unit.x,$found_unit.y
                                [/facing]
                                hits=yes
                            [/animate_unit]
                            {KILL id=$found_unit.id ANIMATE=yes}
                            [message]
                                speaker=Mortic
                                message= _ "The Hunt is called!
The orcs our prey!
Flight of Mortic, we fight!"
                            [/message]
                            {VARIABLE drakes_rebelling yes} # used for S13 intro text
                        [/then]
                    [/if]

                    [kill]
                        side=1
                        {NOT_ACROSS_RIVER}
                        [not]
                            variation=drake,falcon,gryphon,bat
                        [/not]
                    [/kill]

                    [endlevel]
                        result=victory
                        bonus=yes
                        {NEW_GOLD_CARRYOVER 40}
                    [/endlevel]
                [/command]
            [/option]

            [option]
                label= _ "No, not yet."
                [command]
                    [allow_undo][/allow_undo]
                [/command]
            [/option]
        [/message]
    [/event]

    [event]
        name=turn {TURNS_LOW_WARNING}
        [message]
            speaker=Gweddry
            message= _ "Hurry! If we cannot secure a position on the west bank, the drakes will surely fly behind and cut off our retreat!"
        [/message]
    [/event]
    [event]
        name=side 3 turn {SCENARIO_TURN_LIMIT}
        [message]
            speaker=Mortic
            message= _ "The sun arises.
Second and third Wings,
Capture the west bank."
        [/message]
        [if]
            [not]
                [have_unit]
                    id=Mortic
                [/have_unit]
            [/not]

            [then]
                [message]
                    side=2,4
                    canrecruit=yes
                    #po: spoken by the leader of either orc side. Lots of drakes appear immediately after this.
                    message= _ "We need help over here! Where are the rest of those lousy drakes? They should be in position by now!"
                [/message]
            [/then]
        [/if]
        {RESET_SIDE_AI 3 offensive 0.99 0.01} # remove the avoid

        # only spawn drakes that have a wing-flapping standing_anim. Gliders count, but only when in the water
        # and spawn a whole lot of them, so the player doesn't think "really? I’m supposed to be defeated by *that*?"
        {MOVE_UNIT x,y=12,2 4 7}
        {MOVE_UNIT x,y=13,1 5 5}
        {MOVE_UNIT x,y=15,2 4 5}

        {GENERIC_UNIT 3 (Drake Glider)     10 1} {ANIMATE}
        {GENERIC_UNIT 3 (Sky Drake)         9 1}
        {GENERIC_UNIT 3 (Hurricane Drake)   7 1} {ANIMATE}
        {GENERIC_UNIT 3 (Sky Drake)         5 1}
        {GENERIC_UNIT 3 (Hurricane Drake)   5 1} {ANIMATE}
        {GENERIC_UNIT 3 (Sky Drake)         5 1}
        {GENERIC_UNIT 3 (Hurricane Drake)   3 1} {ANIMATE}
        {GENERIC_UNIT 3 (Sky Drake)         3 1}
        {GENERIC_UNIT 3 (Sky Drake)         1 1} {ANIMATE}
        {GENERIC_UNIT 3 (Hurricane Drake)   1 1}

        {GENERIC_UNIT 3 (Drake Glider)      9 5} {ANIMATE}
        {GENERIC_UNIT 3 (Drake Glider)      8 7}
        {GENERIC_UNIT 3 (Drake Glider)      7 5} {ANIMATE}
        {GENERIC_UNIT 3 (Hurricane Drake)   1 5}
        {GENERIC_UNIT 3 (Sky Drake)         1 7} {ANIMATE}
        {NAMED_UNIT   3 (Sky Drake)         2 7 "bridgeburner" (_"Gel’ka") ()}
        {GENERIC_UNIT 3 (Sky Drake)         1 8} {ANIMATE}

        [message]
            speaker=Dacyn
            message= _ "We have not crossed the bridge in time. Now we will all be killed!"
        [/message]

        # don't actually end in defeat here; give them a chance to move and attack
        # they'll probably kill player units, but that's ok because the "turns over" event triggers immediately after
    [/event]

    [event]
        name=enemies defeated
        [message]
            speaker=Gweddry
            message= _ "I can hardly believe it! We didn’t need to destroy the bridge after all."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Huzzah, a glorious victory in the name of the Clans! Man will never flee from orc and drake; we have taught these northerners not to trifle with Wesnoth!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "(cough)(cough) Yes, yes, very well, well done. (cough) Now, it is finally time for us to see what has become of Wesnoth in our absence."
        [/message]

        [set_achievement]
            content_for=eastern_invasion
            id=ei_S12
        [/set_achievement]

        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Varrak-Klar
        [/filter]

        [if]
            {VARIABLE_CONDITIONAL dra_nak_dead equals yes}
            [then]
                [message]
                    speaker="Varrak-Klar"
                    message= _ "Graahh! Stupid humans..."
                [/message]
            [/then]
            [else]
                [message]
                    speaker="Varrak-Klar" # name is 'Chief Dra-Nak' here
                    message= _ "Curse you all! Why couldn’t you have just died as tribute like everyone else? Now my glorious golden Empire will never be..."
                [/message]
                {VARIABLE dra_nak_dead yes}
            [/else]
        [/if]
    [/event]
    [event]
        name=last breath

        [filter]
            id=Mortic
        [/filter]

        [message]
            speaker=Mortic
            #po: Aspirant is a drake military rank
            message= _ "I am Aspirant no more."
        [/message]
        {VARIABLE mortic_dead yes}
    [/event]
    [event]
        name=last breath

        [filter]
            id=Rakkha
        [/filter]

        [message]
            speaker=Rakkha
            message= _ "I hate you! Hate... hate... hate you..."
        [/message]
    [/event]

    {FOREIGN_DEFEAT}

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

#undef SCENARIO_TURN_LIMIT
#undef TURNS_LOW_WARNING
