#textdomain wesnoth-ei

#define SCENARIO_TURN_LIMIT
15 #enddef
#define TURNS_LOW_WARNING
12 #enddef

[scenario]
    id=06b_Soradoc
    name= _ "Soradoc"
    map_file=06b_Soradoc.map
    turns={SCENARIO_TURN_LIMIT}
    next_scenario=07b_Ogre_Crossing
    victory_when_enemies_defeated=no

    {DEFAULT_SCHEDULE_SECOND_WATCH}

    {SCENARIO_MUSIC siege_of_laurelmor.ogg}
    {EXTRA_SCENARIO_MUSIC heavens-remix.ogg}
    {EXTRA_SCENARIO_MUSIC the_king_is_dead.ogg}

    [story]
        [part]
            story=_ "Established by the Crown and administered by the Horse Clans, Soradoc controlled the strategic confluence of the Great River and the River Weldyn. Since its founding in the early days of Wesnoth, it had grown into a prosperous and well-fortified border town. Gweddry and his band approached cautiously, hoping to reunite with Wesnoth’s armies."
            music=silence.ogg
            {EI_BIGMAP}
        [/part]
    [/story]
    {EI_TRACK {JOURNEY_06B_NEW} }

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

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

    #--------------------
    # YANNIC (retake the city)
    #--------------------
    [side]
        color=brown
        side=2
        controller=ai
        recruit=
        {GOLD 0 10 20} # have yannic die around the same time, regardless of the undead difficulty
        {INCOME 3 8 13}
        team_name=good
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}
        type=Lancer
        id=Yannic
        name= _ "Yannic"
        advances_to=Banneret
        canrecruit=yes
        facing=se
        [modifications]
            {TRAIT_LOYAL}
            {TRAIT_QUICK}
        [/modifications]
        [ai]
            {NO_SCOUTS}
            leader_aggression=-9
            aggression=-9
            caution=9
            leader_value=0
            grouping=no
        [/ai]
    [/side]
    {STARTING_VILLAGES 2 3}
    {SILENTLY_LIMIT_LEADER_MOVES 2 1}
    {LIMIT_RECRUITS_PER_TURN 2 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Heavy Infantryman)  3} # unit cap for Yannic
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Mage,Red Mage)      3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Spearman,Swordsman) 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Bowman,Longbowman)  2}
    [event]
        name=prestart
        {GENERIC_UNIT 2 (Bowman) 7 9}
        {GENERIC_UNIT 2 (Swordsman) 8 11}
        {GENERIC_UNIT 2 (Heavy Infantryman) 7 14}
        {GENERIC_UNIT 2 (Red Mage) 3 15}
    [/event]

    # vary Yannic's goals/avoids depending on our army size
#define OR_OUTSIDE_TOWN
    [or]
        x=1,   2,   2,    3,   3,    4,  4,    5,   5,    6,  6,    7,  7,    8,   8,    9,  9,    10, 10,   11, 11,   12, 12,   13,  13
        y=0-99,0-12,15-99,0-10,16-99,0-9,16-99,0-10,16-99,0-9,16-99,0-8,17-99,0-10,19-99,0-9,19-99,0-8,18-99,0-9,19-99,0-9,19-99,0-10,19-99
        [or]
            x=14,  14,   15,  15,   16, 16,   17,  17,   18,  18,   19
            y=0-10,18-99,0-10,18-99,0-9,18-99,0-10,18-99,0-11,17-99,0-99
        [/or]
    [/or]
#enddef
    [event]
        name=new turn
        first_time_only=no
        {RESET_SIDE_AI 2 no -9 9}
        {MODIFY_AI_DELETE_CANDIDATE_ACTION 2 main_loop leader_shares_keep}

        # inner villages
        [if]
            [have_unit]
                side=2
                count=0-6
            [/have_unit]
            [and]
                [lua]
                    code=<< return wesnoth.current.turn>1 >>
                [/lua]
            [/and]
            [then]
                # never do this on the first turn, or we retreat and look stupid
                {MODIFY_SIDE_AI (2) ( {GOAL_TERRAIN 15 (terrain=Kh,Ch,Chr,R*)} )}
                {MODIFY_SIDE_AI (2) ( {GOAL_LOCATION 15 (x=6, 3, 6, 3, 4
                y=12,12,10,14,14 )} )}
                {MODIFY_SIDE_AI (2) (
                    [avoid]
                        x=5,    6,    7-99
                        y=16-99,14-99,0-99
                        {OR_OUTSIDE_TOWN}
                    [/avoid]
                )}
            [/then]
        [/if]

        # medium walls and villages
        [if]
            [have_unit]
                side=2
                count=7-11
            [/have_unit]
            [or]
                [lua]
                    code=<< return wesnoth.current.turn==1 >>
                [/lua]
            [/or]
            [then]
                # always do this on the first turn, or we retreat and look stupid
                {MODIFY_SIDE_AI (2) ( {GOAL_TERRAIN 15 (terrain=Kh,Ch,Chr,R*)} )}
                {MODIFY_SIDE_AI (2) ( {GOAL_LOCATION 15 (x=9, 9, 7, 8, 4
                y=10,12,14,15,14)} )}
                {MODIFY_SIDE_AI (2) (
                    [avoid]
                        x=8,    9,    10-99
                        y=17-99,14-99, 0-99
                        {OR_OUTSIDE_TOWN}
                    [/avoid]
                )}
            [/then]
        [/if]

        # outer walls
        [if]
            [have_unit]
                side=2
                count=12-99
            [/have_unit]
            [then]
                {MODIFY_SIDE_AI (2) ( {GOAL_TERRAIN 15 (terrain=Kh,Ch,Chr,R*)} )}
                {MODIFY_SIDE_AI (2) ( {GOAL_LOCATION 15 (x=2, 4, 8, 8,  12,18,17,16, 7,10,12
                y=15,15,16,18, 18,16,11,13, 9,9, 10)} )}
                {MODIFY_SIDE_AI (2) (
                    [avoid]
                        x,y=0,0
                        {OR_OUTSIDE_TOWN}
                    [/avoid]
                )}
            [/then]
        [/if]
    [/event]

    #--------------------
    # GHAST (attack Yannic)
    #--------------------
    [side]
        side=3
        controller=ai
        recruit=Walking Corpse,Ghoul
        {GOLD 0 0 0}
        {INCOME 2 6 10}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Ghast
        id=ghast_leader
        canrecruit=yes
        facing=sw
    [/side]
    {STARTING_VILLAGES 3 4}
    {SILENTLY_LIMIT_LEADER_MOVES 3 1} # don't let him reach a village, or he's easy to block out of his keep

    [event]
        name=prestart
        {GENERIC_UNIT 3 (Walking Corpse) 13 13}
        {GENERIC_UNIT 3 (Walking Corpse) 12 14}

        {GENERIC_UNIT 3 (Soulless) 16 15}
        {GENERIC_UNIT 3 (Walking Corpse) 14 14}
        {GENERIC_UNIT 3 (Walking Corpse) 15 13}

        {GENERIC_UNIT 3 (Soulless) 20 12}
        {GENERIC_UNIT 3 (Walking Corpse) 20 12}
        {GENERIC_UNIT 3 (Soulless) 22 13}
        {GENERIC_UNIT 3 (Walking Corpse) 22 13}
        {GENERIC_UNIT 3 (Ghoul) 19 16}

        {LOYAL_UNIT 3 (Walking Corpse) 17 12} {GUARDIAN}
        {LOYAL_UNIT 3 (Ghoul) 16 17} {GUARDIAN} # makes it harder for owaec to solo-rush across the river
    [/event]
    {SILENTLY_LIMIT_MOVES 3 (side,x,y=3,16,17) 0} # so he doesn't move and let owaec sneak by

    [event]
        name=side 3 turn
        first_time_only=no
        {RESET_SIDE_AI 3 offensive 0.8 0.25}

        {MODIFY_SIDE_AI (3) ({GOAL_SEEK_SIDE 3 2 1})}
        {RETREAT_WHEN_WEAK 3 {ON_DIFFICULTY 0-3 0-4 0-5} (
            {GOAL_LOCATION 99 (x,y=12,14)}
            {GOAL_LOCATION 77 (x,y=14,13)}
            {GOAL_LOCATION 77 (x,y=14,14)}
        )}
    [/event]

    #--------------------
    # EAST NECROMANCER (attack player)
    #--------------------
    [side]
        side=4
        controller=ai
        recruit=Walking Corpse,Soulless,Ghoul,Dark Adept
        {GOLD 20 60 100}
        {INCOME 3 8 13}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Necromancer
        id=Mal-Talar
        name= _ "Mal-Talar"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_INTELLIGENT}
        [/modifications]
    [/side]
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 (Walking Corpse) 4}
    {SILENTLY_LIMIT_LEADER_MOVES 4 1}
    {STARTING_VILLAGES 4 5}

    [event]
        name=prestart
        {LOYAL_UNIT 4 {ON_DIFFICULTY "Walking Corpse" Ghoul       Necrophage} 22 8} {GUARDIAN}
        {LOYAL_UNIT 4 {ON_DIFFICULTY "Walking Corpse" Necrophage  Ghast     } 28 10} {GUARDIAN}
        {LOYAL_UNIT 4 {ON_DIFFICULTY "Walking Corpse" Skeleton    Revenant  } 26 7} {GUARDIAN}
    [/event]
    [event]
        name=side 4 turn
        first_time_only=no
        {RESET_SIDE_AI 4 offensive 0.8 0.25}

        {MODIFY_SIDE_AI (4) ({GOAL_SEEK_SIDE 5 1 1})}
        {RETREAT_WHEN_WEAK 4 {ON_DIFFICULTY 0-8 0-10 0-12} (
            {GOAL_LOCATION 66 (x,y=25,19)}
            {GOAL_LOCATION 66 (x,y=24,19)}
            {GOAL_LOCATION 66 (x,y=23,19)}
            {GOAL_LOCATION 55 (x,y=24,18)}

            {GOAL_LOCATION 99 (x,y=23,16)}
            {GOAL_LOCATION 88 (x,y=24,15)}
            {GOAL_LOCATION 77 (x,y=27,15)}

            {GOAL_LOCATION 77 (x,y=24,12)}
            {GOAL_LOCATION 77 (x,y=25,12)}
        )}
        {VARY_AI_BY_SCHEDULE_ENEMY 4 1,2}
    [/event]

    #--------------------
    # NORTH SORCERER (loiter)
    #--------------------
    [side]
        color=teal
        side=5
        controller=ai
        recruit=Vampire Bat,Blood Bat,Ghost
        {GOLD 15 45 75}
        {INCOME 5 12 19}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Dark Sorcerer
        id=Mal-Mana
        name= _ "Mal-Mana"
        gender=female
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_RESILIENT}
        [/modifications]
        [ai]
            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=1
            [/goal]
            leader_value=0
        [/ai]
        {LOYAL_UNIT 4 (Wraith) 16 1} {GUARDIAN}
    [/side]
    {STARTING_VILLAGES 5 7}
    {SILENTLY_LIMIT_LEADER_MOVES 5 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 5 (Vampire Bat) 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 5 (Blood Bat)   3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 5 (Ghost)       4}
    [event]
        name=prestart
        [micro_ai]
            side=5
            ai_type=hang_out
            action=add
            [filter]
                upkeep=full
            [/filter]
            [filter_location]
                x,y=18,5
            [/filter_location]
            [mobilize_condition]
                [not] # mobilize if side 4 leader dies
                    [have_unit]
                        side=4
                        canrecruit=yes
                    [/have_unit]
                [/not]
                [or] # mobilize on turn 6
                    [lua]
                        code = << return (wesnoth.current.turn>=6) >>
                    [/lua]
                [/or]
            [/mobilize_condition]
        [/micro_ai]
    [/event]
    [event]
        name=side 5 turn
        first_time_only=no
        {RESET_SIDE_AI 6 offensive 0.8 0.25}

        # no variation - these guys just run at the enemy no matter the situation
    [/event]

    #--------------------
    # SOUTH DEATH KNIGHT (loiter)
    #--------------------
    [side]
        color=brightorange
        side=6
        controller=ai
        recruit=Skeleton,Revenant,Skeleton Archer,Bone Shooter,Bone Knight
        {GOLD 20 60 100}
        {INCOME 13 28 43}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Death Knight
        id=Naken-alvak
        name= _ "Naken-alvak"
        canrecruit=yes
        facing=sw
    [/side]
    {STARTING_VILLAGES 6 7}
    {SILENTLY_LIMIT_LEADER_MOVES 6 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 6 "Revenant" 3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 6 "Bone Shooter" 3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 6 "Bone Knight" 1}
    [event]
        name=prestart
        {LOYAL_UNIT 6 (Chocobone) 9 28} {GUARDIAN}
        {LOYAL_UNIT 6 (Skeleton Archer) 12 24} {GUARDIAN} # makes it harder for owaec to solo-rush across the river
        {LOYAL_UNIT 6 (Skeleton) 5 24} {GUARDIAN}
        [micro_ai]
            side=6
            ai_type=hang_out
            action=add
            [filter]
                upkeep=full
            [/filter]
            [filter_location]
                x=5, 8
                y=31,26
            [/filter_location]
            [mobilize_condition]
                [lua] # mobilize just before Mal-Ravanal shows up
                    code = << return (wesnoth.current.turn>=4) >>
                [/lua]
                [or] # or mobilize if the player gets close
                    [have_unit]
                        side=1
                        x=0-12,13,  14,  15
                        y=0-99,0-29,0-28,0-27
                    [/have_unit]
                [/or]
            [/mobilize_condition]
        [/micro_ai]
    [/event]
    [event]
        name=side 6 turn
        first_time_only=no
        {RESET_SIDE_AI 6 offensive 0.8 0.25}

        {MODIFY_SIDE_AI (6) ({GOAL_SEEK_SIDE 1 2 1})}
        {RETREAT_WHEN_WEAK 6 {ON_DIFFICULTY 0-5 0-7 0-9} (
            {GOAL_LOCATION 99 (x,y=9,28)}
            {GOAL_LOCATION 88 (x,y=8,30)}
            {GOAL_LOCATION 77 (x,y=6,27)}
        )}
        [if] # don't retreat during the first day, or we're too vulnerable to being rushed
            [lua]
                code = << return (wesnoth.current.turn>=4) >>
            [/lua]
            [then]
                {VARY_AI_BY_SCHEDULE_ENEMY 6 1,2}
            [/then]
        [/if]
    [/event]

    {SET_LABEL 4 11 ( _"West Barracks" )}
    {SET_LABEL 24 11 ( _"East Barracks" )}
    {SET_LABEL 15 14 ( _"Citadel" )}
    {SET_LABEL 6 12 ( _"Temple" )}

    {PLACE_IMAGE scenery/rock1.png 30 27}
    {PLACE_IMAGE scenery/rock2.png 29 35}
    {PLACE_IMAGE scenery/well.png  11 23}

    {PLACE_IMAGE scenery/trash.png 9 9}
    {PLACE_IMAGE scenery/trash.png 28 16}
    {PLACE_IMAGE scenery/castle-ruins2.png 16 14}
    {PLACE_IMAGE scenery/castle-ruins2.png 7 18}

    {PLACE_IMAGE scenery/village-human-burned1.png 13 22}
    {PLACE_IMAGE scenery/village-human-burned2.png 27 12}
    {PLACE_IMAGE scenery/village-human-burned3.png 1 32}
    {PLACE_IMAGE scenery/village-human-burned4.png 12 3}
    {PLACE_IMAGE scenery/village-human-burned1.png 30 26}
    {PLACE_IMAGE scenery/village-human-burned2.png 11 11}

    {PLACE_IMAGE scenery/temple1.png 6 12}

    {PLACE_IMAGE scenery/gore-1.png 16 14}
    {PLACE_IMAGE scenery/gore-2.png 25 16}
    {PLACE_IMAGE scenery/gore-3.png 14 14}
    {PLACE_IMAGE scenery/gore-4.png 24 10}
    {PLACE_IMAGE scenery/blood-trail-2.png 18 12}
    {PLACE_IMAGE scenery/blood-1.png 13 15}
    {PLACE_IMAGE scenery/blood-2.png 12 22}
    {PLACE_IMAGE scenery/blood-3.png 23 10}

    [event]
        name=prestart
        {BRAZIER_ILLUMINATION_SECOND_WATCH 5 13}

        [if]
            {VARIABLE_CONDITIONAL talar_dead equals yes}
            [then]
                [modify_unit]
                    [filter]
                        id=Mal-Talar
                    [/filter]
                    #po: If Mal-Talar was killed in S01, use a different name.
                    name= _ "Mal-Bakral"
                [/modify_unit]
            [/then]
        [/if]

        [objectives]
            side=1
            [objective]
                description= _ "Move any unit to the northern path."
                condition=win
                show_turn_counter=yes
            [/objective]
            [objective]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Defeat as many enemy leaders as possible, and then move any unit to the northern path (easier next scenario)"
                condition=win
                [show_if]
                    [have_unit]
                        side=3,4,5,6
                        canrecruit=yes
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Move Owaec next to Yannic, and then protect Yannic until you move any unit to the northern path (bonus item next scenario)"
                condition=win
                [show_if]
                    [have_unit]
                        id=Yannic
                    [/have_unit]
                    [variable]
                        name=met_yannic
                        not_equals=yes
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Protect Yannic until you move any unit to the northern path (bonus item next scenario)"
                condition=win
                [show_if]
                    [have_unit]
                        id=Yannic
                    [/have_unit]
                    [variable]
                        name=met_yannic
                        equals=yes
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry, Dacyn, or Owaec"
                condition=lose
            [/objective]
            {TURNS_RUN_OUT}
            [gold_carryover]
                bonus=no
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]

        {RECALL_XY (Dacyn) 22 31}
        {RECALL_XY (Owaec) 23 31} # make it more difficult for him to rush across the river
        {RECALL_XY (Addogin) 23 30}
        {RECALL_XY (Terraent) 23 30}
        {RECALL_XY (Hahid al-Ali) 23 30}
    [/event]

    [event]
        name=start

        [message]
            speaker=Gweddry
            message= _ "The air is filled with smoke. I fear the town is already lost."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Madness! How can the city have fallen? The garrison is stout-hearted and loyal to a fault. I know many of them personally! They would hold the city to their dying breaths."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Were you expecting a victory parade? Soradoc will be the first of many if we cannot accomplish our goal."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Wait, look, the flag of Wesnoth still flies over the western barracks!"
        [/message]

        {SCROLL_TO 15 14}
        [delay]
            time=100
        [/delay]

        [message]
            speaker=Yannic
            message= _ "Are you our reinforcements? Weldyn promised us aid days ago! The undead already control most of the city. We’re hiding our wounded in the temple, but if we lose the western quarter as well, I fear that no one will escape."
        [/message]
        [message]
            speaker=Owaec
            message= _ "By the Clans, some of them yet live! We must move quickly if we are to rescue the garrison! If we can defeat this wave of undead, they may yet have time to evacuate."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "I agree, but... there are many powerful undead besieging the city. Do we have the strength to defeat them all?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Maybe, maybe not. Remember that our true goal lies far to the north. Nothing we do here today will more than inconvenience Mal-Ravanal."
        [/message]
        [message]
            speaker=Owaec
            message= _ "You still have yet to explain more about this goal."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "We should proceed north as quickly as we can. If we cannot save Soradoc, we can at least slip past the undead and escape, though they will certainly follow us."
        [/message]
        {HIGHLIGHT_IMAGE 27 1 items/gohere.png ()}
    [/event]

    [event]
        name=side 1 turn end
        [message]
            speaker=Naken-alvak
            message= _ "Intruders... living men... from the southeast..."
        [/message]
        [if]
            {VARIABLE_CONDITIONAL talar_dead not_equals yes}
            [then]
                [message]
                    speaker=Mal-Talar
                    message= _ "Ah, it’s the garrison that escaped me back at that border outpost. They won’t get lucky again this time!"
                [/message]
            [/then]
        [/if]

        [message]
            speaker=Mal-Mana
            #po: Mal-Mana dispatches a bat messenger to say she's spotted Dacyn.
            message= _ "And see who is among them! I shall inform Mal-Ravanal at once."
        [/message]
        [animate_unit]
            [filter]
                id=Mal-Mana
            [/filter]
            flag=attack
            hits=no
            [primary_attack]
                range=ranged
                type=cold
            [/primary_attack]
            [facing]
                [filter]
                    x,y=15,4
                [/filter]
            [/facing]
        [/animate_unit]

        [move_unit_fake]
            type=Vampire Bat
            side=4
            x=15,30
            y=4, 24
        [/move_unit_fake]
    [/event]

    # Mal-ravanal shows up and spawns spirits
    [event]
        name=side 1 turn 5

        {GENERIC_UNIT 4 (Skeleton Archer) 30 34} {MOVE_UNIT x,y=30,34 29 34}
        {GENERIC_UNIT 4 (Skeleton Archer) 30 34} {MOVE_UNIT x,y=30,34 28 35}
        {GENERIC_UNIT 4 (Skeleton)        30 34} {MOVE_UNIT x,y=30,34 30 32}

        {FIND_NEARBY (type=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Draug,Banebow,Chocobone) 29 34 8}
        {SPAWN_IF_UNFOUND 4 (Skeleton) 28 35}

        {RAVANAL_POSSESS 30 34 (x,y=$found_unit.x,$found_unit.y) (sw)}

        [delay]
            time=250
        [/delay]

        [if]
            [variable]
                name=fork_04c
                equals=yes
            [/variable]
            [then]
                [message]
                    speaker=Mal-Ravanal
                    message= _ "Dacyn, is that you again? So this is where you ran off to. I would recognize your nauseating aura anywhere."
                [/message]
                [message]
                    speaker=Mal-Ravanal
                    message= _ "I should put you out of your misery right now, but then again, I wanted you to see the results of all my long years of research. I guess it can wait a little longer."
                [/message]
            [/then]
            [else]
                [message]  # if you change this, also change 04c_Mal-Ravanals_Capital
                    speaker=Mal-Ravanal
                    message= _ "Wait a moment! That nauseating holier-than-thou aura..."
                [/message]
                [message]
                    speaker=Mal-Ravanal
                    message= _ "... ah, Dacyn, what an unexpected surprise! Last time we spoke, you blasted me before I could even finish telling you about my research."
                [/message]
                [message]
                    speaker=Dacyn
                    message= _ "If only it had ended back then. Stop this madness. Let this torment come to an end."
                [/message]
                [message]
                    speaker=Mal-Ravanal
                    message= _ "Torment? What torment? You’re the one who seems to be miserable. But don’t worry, if your goal was to become one of these mindless thralls, you came to the right place. You know what they say. No brain, no pain!"
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Mal-Ravanal
            message= _ "Well then, I know you’ll miss me, so here’s a little going-away present for you and your friends."
        [/message]

        {MODIFY_UNIT id=Mal-Ravanal facing sw}
#ifdef HARD
        {RAVANAL_ATTACK} {GENERIC_UNIT 4 (Spectre) $possessee.x $possessee.y} {ANIMATE}
        {RAVANAL_ATTACK} {GENERIC_UNIT 4 (Ghost)   $possessee.x $possessee.y} {ANIMATE}
#endif
#ifndef EASY
        {RAVANAL_ATTACK} {GENERIC_UNIT 4 (Shadow)  $possessee.x $possessee.y} {ANIMATE}
        {RAVANAL_ATTACK} {GENERIC_UNIT 4 (Shadow)  $possessee.x $possessee.y} {ANIMATE}
#endif

        {RAVANAL_ATTACK} {GENERIC_UNIT 4 (Spectre) $possessee.x $possessee.y} {ANIMATE}
        {RAVANAL_ATTACK} {GENERIC_UNIT 4 (Wraith)  $possessee.x $possessee.y} {ANIMATE}

        [delay]
            time=250
        [/delay]

        {RAVANAL_DEPOSSESS 30 34}
    [/event]

    #
    # Owaec meets up with Yannic
    #
    [event]
        name=moveto
        [filter]
            id=Owaec
        [/filter]
        [filter_condition] # if Owaec moves adjacent to Yannic
            [have_unit]
                id=Yannic
                [filter_adjacent]
                    id=Owaec
                [/filter_adjacent]
            [/have_unit]
        [/filter_condition]
        [fire_event]
            name=meet_yannic
        [/fire_event]
    [/event]

    # if 3/4 enemy leaders die, that counts as having saved Yannic too
    [event]
        name=die
        [filter]
            side=3,4,5,6 # for some reason 3-6 doesn't work
            canrecruit=yes
        [/filter]
        [filter_condition]
            [have_unit]
                side=3,4,5,6 # for some reason 3-6 doesn't work
                canrecruit=yes
                count=1
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Gweddry
            #po: there were originally 4 of them, and 3 are now defeated
            message= _ "That’s almost all the undead leaders defeated!"
        [/message]
        [fire_event]
            name=meet_yannic
        [/fire_event]
    [/event]

    [event]
        name=meet_yannic
        [filter_condition]
            [have_unit]
                id=Yannic
            [/have_unit]
        [/filter_condition]
        [message]
            speaker=Owaec
            message= _ "Who commands this garrison? Time is short. We must evacuate what’s left of your men before—"
        [/message]
        [message]
            speaker=Yannic
            message= _ "Owaec? Is that you?"
        [/message]
        [message]
            speaker=Owaec
            message= _ "Yannic?! Well met friend, I haven’t seen you in years!! Ha, you never could stay out of trouble! How’s your horse, Clansman?"
        [/message]
        [message]
            speaker=Yannic
            message= _ "Injured, along with those few of my men lucky enough to yet live. I am more than grateful for your timely arrival and help."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Speaking of help, we require yours. I, the King’s High Advisor, seek a powerful magic east of the Listra to destroy these undead. We will require your men and provisions for the journey."
        [/message]
        [message]
            speaker=Yannic
            message= _ "... I would gladly offer all for the friend of a fellow Clansman, but as you can see, myself and what remains of my garrison are in little condition to help anyone. Still, should I encounter any fresh reinforcements or objects of interest, I will send them your way."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Acceptable."
        [/message]
        [message]
            speaker=Owaec
            message= _ "Bah, we come to aid you, not to seek <i>your</i> aid! We shall do our utmost to ensure you and your men survive this dark time."
        [/message]
        {VARIABLE met_yannic yes}

        [show_objectives]
        [/show_objectives]
    [/event]

#define MESSAGE_IF_COUNT COUNT SPEAKER MESSAGE
    [if]
        [have_unit]
            side=3,4,5,6 # for some reason 3-6 doesn't work
            canrecruit=yes
            count={COUNT}
        [/have_unit]

        [then]
            [message]
                speaker={SPEAKER}
                message={MESSAGE}
            [/message]
        [/then]
    [/if]
#enddef
    # win when any unit reaches the north signpost
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x,y=27,1
        [/filter]
        {MESSAGE_IF_COUNT 4-3 unit _"I’ve broken through the undead lines. Follow me before we are overwhelmed!"}
        {MESSAGE_IF_COUNT 2-0 unit _"The northern path is clear! Follow me, let us cross the Great River."}
        [endlevel]
            result=victory
            bonus=no
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]
    [event]
        name=victory
        [if]
            [have_unit]
                side=3,4,5,6
                canrecruit=yes
                count=4
            [/have_unit]

            [then]
                [set_achievement]
                    content_for=eastern_invasion
                    id=ei_S06b
                [/set_achievement]
            [/then]
        [/if]

        #
        # Gweddry counts how many leaders you've killed
        #
        {MESSAGE_IF_COUNT 4 "Gweddry" _"We have failed to defeat even a single enemy leader! It galls me to flee, but this is a battle we cannot win."}
        {MESSAGE_IF_COUNT 3 "Gweddry" _"We have failed to defeat more than a single enemy leader! It galls me to flee, but this is a battle we cannot win."}
        {MESSAGE_IF_COUNT 2 "Gweddry" _"We have weakened the undead here, yet we cannot hope to defeat them all! It galls me to flee, but this is a battle we cannot win."}

        {MESSAGE_IF_COUNT 0 "Dacyn"
        _"We have done well to defeat the undead here. Their forces will be unable to pursue us; we shall have an uneventful river crossing."}
        {MESSAGE_IF_COUNT 1 "Dacyn"  _"We have done well to defeat the undead here. They may still pursue as we cross the river, but far fewer than would otherwise have come."}
        {MESSAGE_IF_COUNT 1 "Gweddry" _"It galls me to flee before vanquishing the final undead leader, but enemy reinforcements will doubtlessly soon arrive."}

        #
        # resolve Yannic's life/death/meeting
        #
        [if]
            [have_unit]
                id=Yannic
            [/have_unit]

            [then]
                [if]
                    {VARIABLE_CONDITIONAL met_yannic equals yes}
                    [then]
                        [message]
                            speaker=Yannic
                            message= _ "Farewell, and good luck! You have bought us enough time to evacuate, and for that I will be ever grateful! May our paths cross again someday."
                        [/message]
                        [message]
                            speaker=Owaec
                            message= _ "Farewell friend! May you find fairer fields unfouled by undead."
                        [/message]
                        [store_unit] # record yannic for future use; but only if we actually meet him (otherwise you can just rush the exit and still get yannic's rewards)
                            [filter]
                                id=Yannic
                            [/filter]

                            variable=Yannic
                        [/store_unit]
                    [/then]

                    [else]
                        [message]
                            speaker=Yannic
                            message= _ "No, wait, you can’t just leave us here!"
                        [/message]
                        [message]
                            speaker=Owaec
                            message= _ "We flee?! My Clan would banish me for half as much cowardice! I am ashamed to call myself a Clansman."
                        [/message]
                    [/else]
                [/if]
            [/then]

            [else]
                [message]
                    speaker=Owaec
                    message= _ "But alas, the garrison is slain. If only we had acted more swiftly, they might still have been saved."
                [/message]
            [/else]
        [/if]

        #
        # Dacyn explains the next scenario
        #
        {MESSAGE_IF_COUNT 4 "Dacyn"
        _"With all enemy leaders still alive, we are sure to be destroyed when we attempt to cross the river..."}
        {MESSAGE_IF_COUNT 3 "Dacyn"
        _"With three enemy leaders still alive, we are sure to be destroyed when we attempt to cross the river..."}
        {MESSAGE_IF_COUNT 2 "Dacyn"
        _"Several undead leaders yet remain, and they are sure to attack us while we attempt to cross the river."}

        #
        # end level
        #
        [store_unit]
            [filter]
                id=ghast_leader
            [/filter]

            variable=ghast_leader
        [/store_unit]
        [store_unit]
            [filter]
                id=Mal-Mana
            [/filter]

            variable=Mal_Mana
        [/store_unit]
        [store_unit]
            [filter]
                id=Mal-Talar
            [/filter]

            variable=Mal_Talar
        [/store_unit]
        [store_unit]
            [filter]
                id=Naken-alvak
            [/filter]

            variable=Naken_alvak
        [/store_unit]
        {CLEAR_VARIABLE met_yannic}
    [/event]

    #
    # time runs out
    #
    [event]
        name=turn {TURNS_LOW_WARNING}
        [message]
            speaker=Dacyn
            message= _ "We must not tarry here too long. Mal-Ravanal is fickle and may return to vanquish us all."
        [/message]
    [/event]

    [event] # once your turn is over, you can't win, so skip straight to time-over
        name=side 1 turn {SCENARIO_TURN_LIMIT} end
        [fire_event]
            name=time over
        [/fire_event]
    [/event]
    [event]
        name=time over

        {FIND_NEARBY (type=Skeleton,Skeleton Archer,Revenant,Bone Shooter,Draug,Banebow,Chocobone) 29 34 999}
        {SPAWN_IF_UNFOUND 4 (Skeleton) 28 35}

        {RAVANAL_POSSESS 30 34 (x,y=$found_unit.x,$found_unit.y) (sw)}
        {CLEANUP_SEARCH}
        [message]
            speaker=Mal-Ravanal
            message= _ "Look who’s still here! Dacyn, I thought you were wiser than this. I’ve changed my mind about letting you live. You know what they say, there’s no time like the present!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "We have tarried here too long. All is now lost!"
        [/message]

        {MODIFY_UNIT id=Mal-Ravanal facing ne}
        {RAVANAL_LIGHTNING}
        {COLOR_ADJUST -127 -191 -127}
        [delay]
            time=50
        [/delay]

        {MODIFY_UNIT id=Mal-Ravanal facing nw}
        {RAVANAL_LIGHTNING}
        {COLOR_ADJUST 127 64 127}
        [delay]
            time=50
        [/delay]

        {MODIFY_UNIT id=Mal-Ravanal facing se}
        {RAVANAL_LIGHTNING}
        {COLOR_ADJUST 127 64 127}
        [delay]
            time=50
        [/delay]

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

        [kill]
            side=1

            [not]
                id=Gweddry,Dacyn,Owaec
            [/not]

            animate=no
        [/kill]
        {KILL id=Dacyn ANIMATE=yes FIRE_EVENT=yes}

        [fire_event]
            name=defeat
        [/fire_event]
    [/event]

    {ENEMYDEATHS_SORADOC}
    {WESNOTH_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
    {HERODEATH_OWAEC}
    {HERODEATH_ADDOGIN}
    {HERODEATH_TERRAENT}
    {HERODEATH_GRUG}
    {HERODEATH_HAHID}

    {HERODEATH_YANNIC}
[/scenario]

#undef SCENARIO_TURN_LIMIT
#undef TURNS_LOW_WARNING
