#textdomain wesnoth-ei

#define SCENARIO_TURN_LIMIT
20 #enddef

[scenario]
    id=05_Northern_Outpost
    name= _ "Northern Outpost"
    map_file=05_Northern_Outpost.map
    turns={SCENARIO_TURN_LIMIT}
    next_scenario=06a_Undead_Crossing
    victory_when_enemies_defeated=no

    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC traveling_minstrels.ogg}

    [story]
        [if]
            [variable]
                name=fork_04a
                equals=yes
            [/variable]
            [then]
                [part]
                    story=_ "With the elven forest open for passage, Gweddry and his men resumed their journey through the northern Estmarks. After many days of mountainous travel, they were greatly relieved to see the walls of the northern outpost silhouetted against the horizon..."
                    music=silence.ogg
                    {EI_BIGMAP}
                [/part]
            [/then]
            [else]
                [if]
                    [variable]
                        name=fork_04c
                        equals=no
                    [/variable]
                    [then]
                        [part]
                            story=_ "Gweddry and his men made good time skirting the eastern Estmarks. After several weeks of marching, they were greatly relieved to see the walls of the northern outpost silhouetted against the horizon..."
                            music=silence.ogg
                            {EI_BIGMAP}
                        [/part]
                    [/then]
                    [else]
                        [part]
                            #po: only shown if the previous scenario was S04c (Mal-Ravanal’s Capital)
                            story=_ "Leaving the Bitter Swamp far behind, Gweddry and his men fled northwest as if their heels were winged. After weeks of frantic marching, they were greatly relieved to see the walls of the northern outpost silhouetted against the horizon..."
                            music=silence.ogg
                            {EI_BIGMAP}
                        [/part]
                    [/else]
                [/if]
            [/else]
        [/if]
    [/story]
    {EI_TRACK {JOURNEY_05_NEW} }

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        {GOLD 120 110 100}
        team_name=good
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}

        # wmllint: recognize Gweddry
        {CHARACTER_STATS_GWEDDRY}
    [/side]

    #--------------------
    # OWAEC
    #--------------------
    [side]
        side=2
        controller=ai
        recruit=Cavalryman,Peasant # no woodsmen, because Gweddry could level them into bandit-line units.
        gold=35                    # no horsemen, because they're expensive and AI can't use them properly
        income=-2                  # enough gold for 1 cav and 2 peasants
        team_name=good
        user_team_name= _ "Wesnothians"

        # wmllint: recognize Owaec
        {CHARACTER_STATS_OWAEC}
        canrecruit=yes # manual canrecruit flag here is deliberate
        facing=sw
        [ai]
            advancements=Knight # avoid advancing to Lancers
            {NO_SCOUTS}
        [/ai]
    [/side]
    {LIMIT_RECRUITS 2 "Cavalryman" 1} # only ever recruit 1 cav, and if it dies no recruiting more
    {SILENTLY_LIMIT_LEADER_MOVES 2 0}
    {SILENTLY_LIMIT_MOVES 2 id=Raraery 5} # so he takes 2 turns to get to his castle (the zone guardian MAI replaces this once he arrives)
    {SILENTLY_LIMIT_MOVES 2 type=Cavalryman 6} # so the recruited cav doesn't run ahead of with the peasants
    [event]
        name=side 2 turn refresh # script these first moves manually, instead of letting them move normally
        {MODIFY_UNIT id=Raraery moves 0}
        {MODIFY_UNIT id=Raetharvan moves 0}
    [/event]
    [event]
        name=side 2 turn end  # do this at the end to delay Owaec's initial recruit, to make the achievement possible
        # this also makes Owaec fight at night, which lets us give him more gold while still keeping his army weak
        {MOVE_UNIT id=Raraery    18 20}
        {MOVE_UNIT id=Raetharvan 18 21} # manually move peasant near Owaec's keep, so he doesn't run ahead and die early
        {MOVE_UNIT id=Owaec      17 21} # manually move Owaec to the keep, since he's limited to only
        {ZONE_GUARDIAN 2 Raraery 12 17 12 17 0} # sit on the forward river castle, and don't move
    [/event]
    [event]
        name=side 2 turn
        first_time_only=no
        {RESET_SIDE_AI 2 offensive 0.8 0.25}

        {MODIFY_SIDE_AI (2) (
            [avoid] # avoid everywhere except the road to the dark adept
                x=1-14,15-17,18-99,   0-99
                y= 0-5, 0-15, 0-99,  23-99
            [/avoid]
        )}
        {VARY_AI_BY_SCHEDULE_ENEMY_NIGHTTIME 2 3,4}
    [/event]
    # wmllint: validate-on

    #--------------------
    # DARK ADEPT
    #--------------------
    [side]
        side=3
        controller=ai
        recruit=Walking Corpse,Soulless,Skeleton Rider
        {GOLD 25 75 125}
        {INCOME 1 7 13}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Dark Adept
        id=Rilaka
        name= _ "Rilaka"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_QUICK}
        [/modifications]
    [/side]
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Skeleton Rider" 3}
    {SILENTLY_LIMIT_LEADER_MOVES 3 1}
    [event]
        name=side 3 turn
        first_time_only=no
        {RESET_SIDE_AI 3 offensive 0.8 0.25}

        {MODIFY_SIDE_AI (3) (
            [avoid] # avoid the eastern bandit area
                x=13-19,20-32
                y= 0-6,  0-99
            [/avoid]
        )}
        {VARY_AI_BY_SCHEDULE_ENEMY 3 1,2}
    [/event]

    #--------------------
    # BANDITS
    #--------------------
    [side]
        side=4
        no_leader=yes
        team_name=bad
        hidden=yes
        [ai]
            grouping=no
            aggression=0.7
            leader_aggression=0.7
            grouping=offensive
        [/ai]
    [/side]

    {PLACE_IMAGE scenery/rock1.png 15 28}
    {PLACE_IMAGE scenery/rock2.png 8 5}

    {PLACE_IMAGE scenery/trash.png 12 19}
    {PLACE_IMAGE scenery/trash.png 19 24}
    {PLACE_IMAGE scenery/castle-ruins2.png 18 20}

    {PLACE_IMAGE scenery/gore-1.png 6 21}
    {PLACE_IMAGE scenery/blood-trail-1.png 4 5}
    {PLACE_IMAGE scenery/blood-trail-2.png 12 9}
    {PLACE_IMAGE scenery/blood-2.png 13 20}

    {PLACE_IMAGE "scenery/temple-cracked2.png~FL(horiz)" 8 30}
    {PLACE_IMAGE scenery/gore-3.png 6 31}
    {PLACE_IMAGE items/bones.png 6 31}
    {PLACE_IMAGE scenery/blood-1.png 7 31}

    {PLACE_ITEM_HOLY_AMULET {ID_HOLY_AMULET_1} 7 31}
    [event]
        name=moveto
        [filter]
            x,y=7,31
        [/filter]
        [message]
            speaker=Owaec
            #po: "here lies the dead body of". An amulet was visible on this hex, a unit has moved to pick it up, which triggers this explanation why it's there.
            message= _ "There lies Anwyan, our local priestess. She insisted on hiding the others first and was one of those who didn’t make it to the cellars in time."
        [/message]
    [/event]

    {PLACE_IMAGE scenery/village-human-burned1.png 6 22}
    {PLACE_IMAGE scenery/village-human-burned2.png 3 5}
    {PLACE_IMAGE scenery/village-human-burned3.png 14 22}
    {PLACE_IMAGE scenery/village-human-burned4.png 14 19}
    {PLACE_IMAGE scenery/village-human-burned1.png 23 31}
    {PLACE_IMAGE scenery/village-human-burned2.png 13 9}

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description= _ "Find the outlaw leader"
                condition=win
                [show_if]
                    {VARIABLE_CONDITIONAL boss_found not_equals yes}
                [/show_if]
            [/objective]
            [objective]
                #po: Shodrano is a male Rogue or Assassin
                description= _ "Kill Shodrano"
                condition=win
                [show_if]
                    [have_unit]
                        side=4
                        id=Shodrano
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                #po: Rilaka is a male Dark Adept
                description= _ "Defeat Rilaka"
                condition=win
                [show_if]
                    [have_unit]
                        side=3
                        canrecruit=yes
                    [/have_unit]
                [/show_if]
            [/objective]
            [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= _ "Owaec is a leader and can recruit units when standing on a keep."
                [show_if]
                    [have_unit]
                        id=Owaec
                        side=1
                    [/have_unit]
                [/show_if]
            [/note]
        [/objectives]

        {VARIABLE shodrano_killed no}

        [store_villages]
            x,y=14-99,1-13
        [/store_villages]
        [spread_bandit_villages]
            x,y=14-99,1-13
            count=$($location.length / 2)
            types={ON_DIFFICULTY
            (Ruffian,Woodsman)
            (Footpad,Poacher,Thug,Thief)
            (Poacher,Poacher,Thug,Thug,Thief,Thief,Rogue,Bandit,Outlaw)
            }
        [/spread_bandit_villages]
        {CLEAR_VARIABLE location}

        {RECALL Dacyn}
        {RECALL Terraent}
        {RECALL (Hahid al-Ali)}
        {RECALL Addogin}
        {MODIFY_UNIT id=Addogin status.slowed yes}
    [/event]

    [event]
        name=start
        [store_unit]
            [filter]
                id=Rilaka
            [/filter]

            kill=yes
            variable=saved_Rilaka
        [/store_unit]

        [store_unit]
            [filter]
                id=Owaec
            [/filter]

            kill=yes
            variable=saved_Owaec
        [/store_unit]

        [message]
            speaker=Gweddry
            message= _ "Alas! The northern outpost has been destroyed..."
        [/message]

        [message]
            speaker=Dacyn
            #po: Did you expect to find the northern outpost still standing?
            message= _ "Did you expect anything else? Owaec has either fled or perished and the undead hordes now march toward the River Weldyn. They must seek to overrun Wesnoth before the king can muster his armies."
        [/message]

        {FAKE_UNIT_MOVE 21 20 18 19 2 (Mounted Fighter) ()}
        [unstore_unit]
            variable=saved_Owaec
            x,y=20,19
        [/unstore_unit]
        {CLEAR_VARIABLE saved_Owaec}

        {FAKE_UNIT_MOVE 21 21 18 19 2 (Horseman) ()}
        {NAMED_NOTRAIT_UNIT 2 (Horseman) 21 19 "Raraery" (_"Raraery")}
        [+unit]
            [modifications]
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]
        # don't want to use Loyal, since 1) it's disproportionately strong in the wildlands scenarios,
        [+unit]                       # and 2) all other loyal units are auto-recalled (Terraent, Hahid, Grug, Dolburras, Gaennell)
            experience=31 # so he's somewhat valuable, and worth defending.
        [/unit]

        {FAKE_UNIT_MOVE 21 20 18 18 2 (Peasant) ()}
        {NAMED_NOTRAIT_UNIT 2 (Peasant) 20 18 "Raetharvan" (_"Raetharvan")}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [+unit]
            [modifications]
                {TRAIT_SLOW}
            [/modifications]
        [/unit]
        # make the achievement easier

        [message]
            speaker=Owaec
            message= _ "Hail, Gweddry!"
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Hail, Owaec! I am stunned and relieved to see that you are still well. How did you escape the undead?"
        [/message]
        [message]
            speaker=Owaec
            message= _ "Many of these farmers dug deep cellars connected to a network of caves. I hid as many villagers as I could once our scouts spotted the undead. They must have thought the villages abandoned, for they moved on swiftly westward, and yet..."
        [/message]
        [message]
            speaker=Owaec
            message= _ "... I was not able to save everyone. Gweddry, their deaths weigh heavy on my heart."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "I am surprised you managed to save even yourself, much less anyone else. But compared to the havoc these undead seek to unleash on all Wesnoth, the deaths of a few peasants are hardly worth mourning."
        [/message]
        [message]
            speaker=Owaec
            message= _ "How can you say-"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "For now, I must study and consider how these undead can be defeated, and then we should leave before more arrive. Will you join us?"
        [/message]
        [message]
            speaker=Owaec
            message= _ "..."
        [/message]
        [message]
            speaker=Owaec
            message= _ "No. I failed these villagers once. I will not do so again. They have survived the undead, but a gang of bandits exploits our weakness and now terrorizes these people. I cannot seem to find a way to defeat the outlaws; they hide in the village cellars whenever I send in my horsemen."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "I fear that until the undead are defeated, these villagers will never be truly safe. But if we can drive these bandits out, will you join us? From what Dacyn tells me, Wesnoth will need all of its soldiers if it is to survive what has come."
        [/message]
        [message]
            speaker=Owaec
            message= _ "If the situation is so dire, I am honor-bound to join you... but I know of no way to remove these bandits."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "You forget that I have many skills as the advisor to the Crown. I can reveal the bandits when our soldiers enter a village. However, this magic will require my full attention. I will not be able to battle them directly."
        [/message]
        [if]
            [have_unit]
                id=Addogin
            [/have_unit]

            [then]
                [message]
                    speaker=Addogin
                    message= _ "Naw, wizard, you go help fight. We don’t need no fancy magic for this. I’ve dealt with plenty o’ thugs before. Maybe if you <i>untie me</i> I’ll help you find ’em, eh?"
                [/message]
                [message]
                    speaker=Gweddry
                    message= _ "Do you promise you won’t simply flee if we set you free? This is a battle for all of Wesnoth. If we fail, it will spell doom not just for us, but also for you and your little mercenary band."
                [/message]
                [message]
                    speaker=Addogin
                    message= _ "Eh, there’s always a necromancer or warlord o’ some kind one way or another. Me and my boys woulda been fine."
                [/message]
                [message]
                    speaker=Addogin
                    message= _ "But yeah, sure, I ain’t runnin’. Just sayin’, as soon as this invasion business is done, I’m outta here."
                [/message]
                [message]
                    speaker=Gweddry
                    message= _ "Very well, untie him! Owaec, we will aid you in driving out these bandits."
                [/message]
                [sound]
                    name=magicmissile.wav
                [/sound]
                [delay]
                    time=300
                [/delay]
                [sound]
                    name=magicmissile.wav
                [/sound]

                {MODIFY_UNIT id=Addogin status.slowed no}
            [/then]

            [else]
                [message]
                    speaker=Gweddry
                    message= _ "Very well. Owaec, we will aid you in driving out these bandits. Dacyn, cast your spell!"
                [/message]
                {MOVE_UNIT id=Dacyn 23 27}
                {MOVE_UNIT id=Dacyn 20 25}
                {MOVE_UNIT id=Dacyn 21 25}
                {DACYN_CASTING_SPELL_ANIMATION_OBJECT}
                {MODIFY_UNIT id=Dacyn variables.casting_the_spell yes}
            [/else]
        [/if]
    [/event]

    # Dacyn remains busy until the bandits are defeated
    [event]
        name=side 1 turn refresh
        first_time_only=no

        [filter_condition]
            [have_unit]
                id=Dacyn
                [filter_wml]
                    [variables]
                        casting_the_spell="yes"
                    [/variables]
                [/filter_wml]
            [/have_unit]
        [/filter_condition]

        {MODIFY_UNIT id=Dacyn moves 0}
        {MODIFY_UNIT id=Dacyn attacks_left 0}
    [/event]

    [event]
        name=capture
        first_time_only=no

        [filter]
            side=1
        [/filter]

        [filter_condition]
            [not]
                [have_unit]
                    id=Shodrano
                [/have_unit]
            [/not]
            [and]
                {VARIABLE_CONDITIONAL shodrano_killed not_equals yes}
            [/and]
        [/filter_condition]

        [bandit_village_capture]
            x,y=$x1,$y1
            unit=$unit
        [/bandit_village_capture]
    [/event]
    [event]
        name=addogin_advice # fired by bandits.lua

        [filter]
            [not]
                id=Addogin
            [/not]
        [/filter]

        [filter_condition]
            [have_unit]
                id=Addogin
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=unit
            message= _ "No outlaws in this village."
        [/message]
        [message]
            speaker=Addogin
            message= _ "Pull aside that old rug, will ya? I think I see somethin’..."
        [/message]
        [event]
            name=addogin_advice

            [filter]
                [not]
                    id=Addogin
                [/not]
            [/filter]

            [message]
                speaker=unit
                message= _ "No outlaws in this village."
            [/message]
            [message]
                speaker=Addogin
                message= _ "Check under the floorboards! There’s always somethin’ there."
            [/message]
            [event]
                name=addogin_advice

                [filter]
                    [not]
                        id=Addogin
                    [/not]
                [/filter]

                [message]
                    speaker=unit
                    message= _ "No outlaws in this village."
                [/message]
                [message]
                    speaker=Addogin
                    message= _ "Shh! Do ya hear that?"
                [/message]
                [event]
                    name=addogin_advice

                    [filter]
                        [not]
                            id=Addogin
                        [/not]
                    [/filter]

                    [message]
                        speaker=unit
                        message= _ "No outlaws in this village."
                    [/message]
                    [message]
                        speaker=Addogin
                        message= _ "Lemme take a closer look..."
                    [/message]
                [/event]
            [/event]
        [/event]
    [/event]

    # tell the player about the outlaw leader
    [event]
        name=capture

        [filter]
            side=1
        [/filter]

        [if]
            [have_unit]
                id=Addogin
            [/have_unit]

            [then]
                [message]
                    speaker=Addogin
                    message= _ "Every outlaw posse got a leader. Tear up enough cellars and he’ll turn up, then take him out and the rest’ll run for the hills."
                [/message]
                [message]
                    speaker=Dacyn
                    #po: They retreated when their leader was captured in the previous scenario, which was "many days of mountainous travel" ago.
                    message= _ "Like your mercenary band did?"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Owaec
                    message= _ "I believe there is a leader behind these outlaws. Kill him and we will face no further resistance."
                [/message]
            [/else]
        [/if]
    [/event]

    [event]
        name=boss_found
        [move_unit_fake]
            x=$x1,$x2
            y=$y1,$y2
            type={ON_DIFFICULTY "Rogue" "Assassin" "Assassin"}
            side=4
        [/move_unit_fake]
        [unit]
            x,y=$x2,$y2
            type={ON_DIFFICULTY "Rogue" "Assassin" "Assassin"}
            side=4
            id=Shodrano
            name= _ "Shodrano"
            canrecruit=yes
            [modifications]
                {TRAIT_STRONG}
                {TRAIT_INTELLIGENT}
            [/modifications]
        [/unit]
        {INCIDENTAL_MUSIC battle-epic.ogg}
        [message]
            speaker=Shodrano
            message= _ "Gah, I’ve been found!"
        [/message]
        [message]
            speaker=Owaec
            message= _ "That’s the bandit leader! Kill him!"
        [/message]
        [show_objectives][/show_objectives]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Shodrano
        [/filter]

        [message]
            speaker=Shodrano
            message= _ "This is how it ends..."
        [/message]
    [/event]

    [event]
        name=die

        [filter]
            id=Shodrano
        [/filter]

        {VARIABLE shodrano_killed yes}
        {MODIFY_UNIT id=Dacyn variables.casting_the_spell no}
        [if]
            [have_unit]
                side=2
                id=Owaec
            [/have_unit]

            [then]
                [message]
                    speaker=Owaec
                    message= _ "Huzzah!! At last, these villagers are liberated! Gweddry, thank you for your aid. I place my Clansmen and myself at your service."
                [/message]
                [capture_village]
                    owner_side=2
                    side=1
                [/capture_village]
                [modify_unit]
                    [filter]
                        side=2
                    [/filter]

                    side=1
                    moves=$($this_unit.max_moves)
                    attacks_left=1
                    {TEAM_COLOR_OVERRIDE () blue}
                [/modify_unit]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "(You may now recruit Horsemen and Cavalrymen!)"
                [/message]
                [set_extra_recruit] # need to set recruits per-unit (instead of per-side) so we don't mess up the plague staff
                    id=Gweddry
                    extra_recruit={REGULAR_RECRUIT_LIST}
                [/set_extra_recruit]
                [set_extra_recruit]
                    id=Owaec
                    extra_recruit={REGULAR_RECRUIT_LIST}
                [/set_extra_recruit]

                [if]
                    [not]
                        [have_unit]
                            id=Addogin
                        [/have_unit]
                    [/not]

                    [then]
                        [message]
                            speaker=Dacyn
                            message= _ "There is no more need for me to concentrate on this spell. However, we still need to deal with the adept."
                        [/message]
                    [/then]
                [/if]
                [show_objectives][/show_objectives]
            [/then]
            [else]
                [fire_event]
                    name=victory_cutscene
                [/fire_event]
            [/else]
        [/if]
    [/event]

    # Undead dark adept arrives
    [event]
        name=side 2 turn 1

        [move_unit_fake]
            x=1,3,6
            y=5,6,4
            side=3
            type=Dark Adept
        [/move_unit_fake]

        [unstore_unit]
            variable=saved_Rilaka
            x,y=6,4
        [/unstore_unit]
        {CLEAR_VARIABLE saved_Rilaka}

        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Ker 6 4}
        [redraw]
        [/redraw]
        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Cer 6 3}
        [redraw]
        [/redraw]
        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Cer 7 4}
        [redraw]
        [/redraw]
        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Cer 7 5}
        [redraw]
        [/redraw]
        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Cer 6 5}
        [redraw]
        [/redraw]
        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Cer 5 5}
        [redraw]
        [/redraw]
        [delay]
            time=150
        [/delay]
        {MODIFY_TERRAIN Cer 5 4}
        [redraw]
        [/redraw]

        [message]
            speaker=Rilaka
            #po: a male Dark Adept has just arrived, there's been an animation of him creating a camp, but he hasn't recruited yet
            #po: his recruit list will be entirely L0 and L1 undead, no living units
            message= _ "Ah ha! I knew this outpost wasn’t really abandoned! Too bad nobody else believed me. Maybe once I defeat you I’ll finally get the respect I deserve?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Defeat us, hmm? I have a better idea."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Once again, undead threaten these villagers! In the name of the Clans, I will strike you down!"
        [/message]

        [show_objectives][/show_objectives]
    [/event]

    [event]
        name=last breath

        [filter]
            id=Rilaka
        [/filter]

        [message]
            speaker=Rilaka
            message= _ "No! I deserve better than this!"
        [/message]
    [/event]

    [event]
        name=die

        [filter]
            id=Rilaka
        [/filter]

        [if]
            [have_unit]
                side=2
                id=Owaec
            [/have_unit]

            [then]
                [message]
                    speaker=Owaec
                    message= _ "Huzzah!! May these be the first of many undead to fall before our hooves! Gweddry, thank you for your aid. I place my Clansmen and myself at your service."
                [/message]
                [capture_village]
                    owner_side=2
                    side=1
                [/capture_village]
                [modify_unit]
                    [filter]
                        side=2
                    [/filter]

                    side=1
                    moves=$($this_unit.max_moves)
                    attacks_left=1
                    {TEAM_COLOR_OVERRIDE () blue}
                [/modify_unit]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "(You may now recruit Horsemen and Cavalrymen!)"
                [/message]
                [set_extra_recruit] # need to set recruits per-unit (instead of per-side) so we don't mess up the plague staff
                    id=Gweddry
                    extra_recruit={REGULAR_RECRUIT_LIST}
                [/set_extra_recruit]
                [set_extra_recruit]
                    id=Owaec
                    extra_recruit={REGULAR_RECRUIT_LIST}
                [/set_extra_recruit]
                [message]
                    speaker=Owaec
                    message= _ "Now let us free these villagers from the outlaws terrorizing them!"
                [/message]
                [show_objectives][/show_objectives]
            [/then]
            [else]
                [fire_event]
                    name=victory_cutscene
                [/fire_event]
            [/else]
        [/if]
    [/event]

    [event]
        name=die

        [filter]
            side=2
            type=Peasant
        [/filter]

        [remove_event]
            id=s05_no_peasants_died
        [/remove_event]
    [/event]
    [event]
        name=victory
        id=s05_no_peasants_died
        [set_achievement]
            content_for=eastern_invasion
            id=ei_S05
        [/set_achievement]
    [/event]

    [event]
        name=victory_cutscene

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Gweddry
            message= _ "Now that both the outlaws and undead are defeated, we finally have some time to rest."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Good. Now leave me in peace while I consider how to combat this invasion."
        [/message]

        {SCROLL_TO 17 25}
        {MOVE_UNIT (id=Dacyn) 16 21}
        [hide_unit] # if we put units to the recall list, they don't get XP for the game-winning kill
        [/hide_unit]

        {INCIDENTAL_MUSIC silence.ogg}

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Some time later..."
        [/message]
        [delay]
            time=1000
        [/delay]

        #----------------------
        # DACYN'S BACKSTORY
        #----------------------
        {FULL_HEAL id=Gweddry,Owaec,Dacyn}
        {TELEPORT_UNIT id=Owaec 14 22}
        {TELEPORT_UNIT id=Gweddry 15 23}
        {MODIFY_UNIT id=Owaec,Gweddry facing ne}
        [unhide_unit]
            id=Owaec,Gweddry
        [/unhide_unit]
        [message]
            speaker=Owaec
            #po: to Dacyn
            message= _ "Mage, pull your nose out of your books for a moment, would you? Gweddry and I have some questions about this invasion you speak of."
        [/message]
        [if]
            {VARIABLE_CONDITIONAL fork_04c equals yes}
            [then]
                [message]
                    speaker=Gweddry
                    message= _ "Back at the undead capital, the lich Mal-Ravanal referred to you as an old friend. What history is there between you?"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Gweddry
                    message= _ "What do you know of the dread lich they called Mal-Ravanal? Back at the southern outpost, you purposely hid yourself to avoid being seen."
                [/message]
            [/else]
        [/if]
        {TELEPORT_UNIT id=Dacyn 16 21}
        {MODIFY_UNIT id=Dacyn facing sw}
        [unhide_unit]
            id=Dacyn
        [/unhide_unit]
        [message]
            speaker=Dacyn
            message= _ "..."
        [/message]
        {INCIDENTAL_MUSIC revelations.ogg}
        [message]
            speaker=Dacyn
            #po: "you" being Owaec and Gweddry, they're both questioning him
            message= _ "I suppose you have a right to know of the adversary we face. I will tell you about Mal-Ravanal."
        [/message]
        {FADE_TO_BLACK}
        [message]
            speaker=Dacyn
            #po: Dacyn is an unreliable narrator, he only tells events the way he interprets them but not necessarily as an absolute truth
            #po: and because Gweddry and Owaec only hear Dacyn's side of the story, they are prone to misinterpretation of motives and events as well
            #po: TODO in 1.19 change this text to "Early in the reign ..." (issue #8387)
            #po: Happened by 589 YW at the latest, Haldric VII reigned 585-612 YW, and it's now 626 YW.
            message= _ "Late in the reign of Haldric VII, a Sylph of Lintanir forest came to Weldyn and spoke of the emergence of a power that threatened to corrupt Wesnoth’s greatest mages and eventually bring ruin to the entire kingdom. She offered only a small piece of cryptic advice, that avoiding this calamity would require a peerless wisdom to harness the use of tremendous power."
        [/message]
        [message]
            speaker=Dacyn
            #po: Ravan is also of an unspecified gender, and not assumed to be only human
            #po: Same as Mal-Ravanal, translations can prefer plural pronouns or language default pronoun if the former is not possible
            #po: Happened in 589 YW, it's now 626 YW.
            message= _ "Thus, the King decided to seek this peerless savant. In all the land, there were two magi that clearly stood out from the rest. Myself, and my good friend Ravan, a mage from the east. The King, wishing to choose the best advisor, sent us both before Galdren. Then he conversed with the seer privately. None know what was said, but when he came out he announced that the seer was dead, and he had... chosen... me as his new advisor."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Ravan took this quietly enough, or so I had thought, but it must have been more of a blow than I had realized. We drifted apart for a long while, and several years passed without my seeing my once close friend."
        [/message]

        [delay]
            time=2000
        [/delay]

        [message]
            speaker=Dacyn
            #po: Happened in 593 YW, it's now 626 YW. The Listra is a river.
            message= _ "One day, I received a message. Ravan was calling me north across the Great River and past the Listra, to an ancient sanctuary that we had once explored together in our younger years. At that time, I had still thought Ravan was my friend and a respected mage of the Light, so I obliged. It sounds foolish now, in hindsight, but I made the long journey north in the darkness of winter to the sanctuary and its hidden chambers."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Even now, that dreadful scene is burned into my memory. At a mere glance, I could already sense the taint of black magic on that cloaked form. Ravan’s once bright aura was enshrouded by an impenetrable darkness, thick and potent and filled with terror. Before I could gather myself, hoarse and frightful voices sprang to life around me, a stream of foul incantations whose cacophonous sound clawed and tore at my body and soul. At that moment, I knew I was obliged to do whatever was necessary to excise this evil from the world."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Before the incantation could finish, I summoned the utmost of my power and rended Ravan’s physical body. Yet even as I witnessed flesh and blood burn away into soot, a dark shadow arose from the ashen bones and dispersed throughout the sanctum. I knew then that death would be but a mere inconvenience to one so skilled in the mystic arts, and that Ravan’s spirit would return one day..."
        [/message]
        {FADE_IN}
        [delay]
            time=3000
        [/delay]

        #----------------------
        # THE AMULET PLAN
        #----------------------
        {INCIDENTAL_MUSIC wanderer.ogg}
        [message]
            speaker=Gweddry
            #po: "it" means the spirit of Mal-Ravanal; the Sylph prophesied about it sometime between 36 and 42 years ago.
            message= _ "As it has now, to finally fulfill the prophecy that the Sylph spoke of all those years ago."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Yes. But hope is not yet lost. After pondering the matter once more, I have come to a conclusion. I do not have the power to defeat Mal-Ravanal as I am now. We must travel north, away from Wesnoth, back to the sanctuary where I had defeated Ravan once before."
        [/message]
        [message]
            speaker=Owaec
            message= _ "And leave our countrymen to fend for themselves in a time of war? This does not sit right with me."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "If we fail to defeat Mal-Ravanal, no effort of ours will be sufficient to withstand the endless armies of the dead. Our blood is limited and the more it is spilled, the more their strength grows. Only by using the power from the sanctuary to destroy the Lich can we find salvation."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Far though this journey may take us, if it is necessary to defeating this great evil, we have no choice but to make it."
        [/message]

        [delay]
            time=1000
        [/delay]

        [message]
            speaker=Owaec
            message= _ "Very well. The Great River can be crossed near Soradoc. We could reach the garrison there, contact the Crown, and gather supplies for our journey."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "The entire undead army is between us and Soradoc. They even may have already taken the city itself. We should avoid that battle and cross the Great River further east, behind the undead lines."
        [/message]
        [message]
            speaker=Owaec
            message= _ "If undead are attacking Soradoc, that is all the more reason to travel west! I will not stand by and let my comrades die while I cravenly flee the battle."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Peace, friends. You both speak wisely. Allow me to cast the deciding vote."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "My decision is..."
            [option]
                label= _ "Cross the Great River to the east, behind enemy lines. <i>(normal)</i>"
                [command]
                    [message]
                        speaker=Gweddry
                        message= _ "We are not strong enough to fight the undead head-on. Let us cross the Great River to the east."
                    [/message]
                    {VARIABLE fork_06a yes}
                    [endlevel]
                        result=victory
                        next_scenario=06a_Undead_Crossing
                        bonus=yes
                        {NEW_GOLD_CARRYOVER 40}
                    [/endlevel]
                [/command]
            [/option]
            [option]
                label= _ "Cross the Great River west in Wesnoth, near Soradoc. <i>(challenging)</i>"
                [command]
                    [message]
                        speaker=Gweddry
                        message= _ "It is our duty to aid the king’s army at Soradoc and cross the river there."
                    [/message]
                    {VARIABLE fork_06b yes}
                    [endlevel]
                        result=victory
                        next_scenario=06b_Soradoc
                        bonus=yes
                        {NEW_GOLD_CARRYOVER 40}
                    [/endlevel]
                [/command]
            [/option]
        [/message]

        {CLEAR_VARIABLE stored_Owaec,bandit_villages,bandit_types,villages_visited,boss_found,shodrano_killed,x1,x2,y1,y2}
    [/event]

    [event]
        name=side 1 turn {SCENARIO_TURN_LIMIT} end
        [if]
            [have_unit]
                id=Rilaka
            [/have_unit]

            [then]
                [message]
                    speaker=Rilaka
                    message= _ "I’m not so sure I can win this fight, but maybe I don’t need to defeat you myself to be respected... maybe I only need to tell the others to come destroy you!"
                [/message]
                {MOVE_UNIT id=Rilaka 1 5}
                {KILL id=Rilaka}
                [message]
                    speaker=Gweddry
                    message= _ "He’s run off to summon reinforcements! If only we had acted sooner..."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Dacyn
                    message= _ "Enough of this. We cannot afford to waste time with petty bandits while Mal-Ravanal ravages Wesnoth. Owaec, come with us or stay here and die, I care not either way."
                [/message]
                [message]
                    speaker=Owaec
                    message= _ "Since we have failed to root out the bandit leader, I am honor-bound to stay and defend these villagers! If you wish to go, then go, but I shall not aid you."
                [/message]
                [message]
                    speaker=Gweddry
                    message= _ "I would that I had acted with more haste..."
                [/message]
            [/else]
        [/if]

        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {FOREIGN_DEFEAT}

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

#undef SCENARIO_TURN_LIMIT
