#textdomain wesnoth-did
[scenario]
    id=Saving_Parthyn
    next_scenario=Peaceful_Valley

    name=_ "Saving Parthyn"
    map_data="{campaigns/Descent_Into_Darkness/maps/Saving_Parthyn.map}"
    turns=15

    victory_when_enemies_defeated=no

    {STORY_SAVING_HALAL}

    {DEFAULT_SCHEDULE}

    [side]
        side=1
        controller=human
        team_name=town guard
        type=Apprentice Mage
        description=Malin Keshar
        user_description=_ "Malin Keshar"
        profile=portraits/malyoung.png
        unrenamable=yes
        canrecruit=yes
        recruit=Walking Corpse
        fog=no
        experience=0
        gold=70
    [/side]

    [side]
        side=2
        controller=ai
        team_name=orcs
        type=Orcish Warrior
        description="Kreg'a'shar Trr"
        user_description=_ "Kreg'a'shar Trr"
        canrecruit=yes
        recruit=Orcish Grunt,Orcish Archer,Wolf Rider,Orcish Crossbowman
        {GOLD 100 140 160}
        {INCOME 17 22 24}
        [ai]
            aggression=0.8
            leader_value=3
            grouping=offensive
            caution=0.1
            recruitment_pattern=fighter,archer,scout
        [/ai]
    [/side]

    [side]
        side=3
        controller=ai
        team_name=town guard
        type=Sergeant
        description=Drogan
        user_description=_ "Drogan"
        unrenamable=yes
        {GOLD 50 25 25}
        canrecruit=yes
        recruit=Peasant,Woodsman,Spearman
        [ai]
            village_value=0
            [protect_unit]
                description=Malin Keshar
                value=4
            [/protect_unit]
            caution=0.5
            #don't block Malins keep
            [avoid]
                x=30
                y=12
            [/avoid]
        [/ai]
    [/side]

    {STARTING_VILLAGES 3 10}

    [event]
        name=prestart

        [music]
            name=northerners.ogg
        [/music]
        [music]
            name=main_menu_new.ogg
            append=yes
            ms_before=1000
        [/music]

        # FIXME: Merge this map with the one for Return To Parthyn.
        # Scattering random trees on here would be a bad idea,
        # since we visit it twice.

        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Defend the river fort for two nights"
            [/objective]
            [objective]
                condition=lose
                description=_ "Orcs break through the river fort defenses"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Malin Keshar"
            [/objective]
            [objective]
                condition=lose
                description=_ "Death of Drogan"
            [/objective]
        [/objectives]

        # Place signpost to mark area defended
        {PLACE_IMAGE scenery/signpost.png 27 13}
        {PLACE_IMAGE scenery/signpost.png 23 20}

        # Place starting units for Drogan and Malin
        {LOYAL_UNIT 1 (Spearman) 30 11 (Kerith) ( _ "Kerith")}
        {LOYAL_UNIT 1 (Bowman) 31 12 (Owain) ( _ "Owain")}
        {LOYAL_UNIT 1 (Spearman) 31 13 (Aethun) ( _ "Aethun")}

        {LOYAL_UNIT 3 (Spearman) 5 17 (Yran) ( _ "Yran")}
        {LOYAL_UNIT 3 (Swordsman) 6 17 (Luddry) ( _ "Luddy")}
        {LOYAL_UNIT 3 (Spearman) 6 18 (Gwilam) ( _ "Gwilam")}

        {VARIABLE malin_used_necromancy 0}
    [/event]

    [event]
        name=start
        {DIALOGUE_SH_START}
    [/event]

    # In-scenario Events
    [event]
        name=recruit
        first_time_only=yes
        [filter]
            type=Walking Corpse
        [/filter]
        {DIALOGUE_SH_CORPSE}
        {VARIABLE malin_used_necromancy 1}
    [/event]

    [event]
        name=moveto
        [filter]
            side=1
            x,y=27,13
        [/filter]
        [message]
            speaker=narrator
            message=_ "Welcome to Parthyn"
            image=scenery/signpost.png
        [/message]

        [allow_undo][/allow_undo]
    [/event]

    {EVENT_SH_EE}

    # Defeat Conditions
    [event]
        name=moveto
        [filter]
            side=2
            x=0-27
            y=13-20
        [/filter]
        [message]
            speaker=Drogan
            message=_ "The orcs have broken through our line. Parthyn is open to attack!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {MALIN_DEATH}

    [event]
        name=die
        [filter]
            speaker=Drogan
        [/filter]
        [message]
            speaker=unit
            message=_ "Who will be left to defend Parthyn?"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

#define VICTORY
    [kill]
        side=2
        animate=no
        event_fire=no
    [/kill]
    [if]
        [variable]
            name=malin_used_necromancy
            numerical_equals=1
        [/variable]
        [then]
            {DIALOGUE_SH_EXILE}
        [/then]
        [else]
            {DIALOGUE_SH_PURSUE}
        [/else]
    [/if]
    [kill]
        side=1
        race=human
        [not]
            description=Malin Keshar
        [/not]
        animate=no
        fire_event=no
    [/kill]
    [endlevel]
        result=victory
    [/endlevel]
#enddef

    # Victory Conditions
    [event]
        name=time over
        {DIALOGUE_SH_TIME_OVER}
        {VICTORY}
    [/event]

    # This is very unlikely, but just in case...
    [event]
        name=enemies defeated
        {DIALOGUE_SH_ENEMIES_DEFEATED}
        {VICTORY}
    [/event]

    {@campaigns/Descent_Into_Darkness/utils/global-events.cfg}
[/scenario]
