#textdomain wesnoth-ei

#
# Simple and easy, especially compared to S01.
#
# This is beatable without any combat or recruiting - just run straight through the dwarvish tunnels, and wade through the river.
# More ambitious players can take the north path and raid the troll trezzur hole for some gold and a powerful item
# REALLY ambitous players can fight their way through the troll leader for extra XP.
#

# undead arrival + 5
#define SCENARIO_TURN_LIMIT
{ON_DIFFICULTY 17 15 13} #enddef

[scenario]
    id=02_The_Escape_Tunnel
    name= _ "The Escape Tunnel"
    map_file=02_The_Escape_Tunnel.map
    turns={SCENARIO_TURN_LIMIT}
    next_scenario=03_An_Unexpected_Appearance
    victory_when_enemies_defeated=no

    {UNDERGROUND}

    [story]
        [part]
            story=_ "Screams and shouts echoed across the surface as Gweddry rushed his remaining men into the roughly hewn tunnel. A foul stench wafted up from below..."
            music=silence.ogg
        [/part]
    [/story]
    {EI_TRACK {JOURNEY_02_NEW} }
    {SCENARIO_MUSIC the_deep_path.ogg}

    # wmllint: validate-off
    [side]
        side=1
        controller=human
        {GOLD 130 120 110}
        team_name=wesnothians
        user_team_name=_"Wesnothians"
        {FLAG_VARIANT loyalist}
        {CHARACTER_STATS_GWEDDRY}
        shroud=yes
        fog=yes
    [/side]
    # wmllint: validate-on

    [side]
        side=2
        controller=ai
        recruit=Dwarvish Miner
        gold=50
        income=0 # dwarves get ~5 free village
        team_name=wesnothians
        user_team_name=_"Dwarves"
        {FLAG_VARIANT knalgan}
        type=Dwarvish Steelclad
        canrecruit=yes
        id=Knutan
        name=_"Knutan"
        fog=yes
        shroud=yes
        share_vision=none
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_HEALTHY}
        [/modifications]
        [ai]
            grouping=defensive
            leader_value=0
            [avoid]
                x=24-99,27-99 # prefer fighting where the player can see
                y= 0-8,  0-11
            [/avoid]
        [/ai]
        {NAMED_NOTRAIT_UNIT 2 (Dwarvish Miner) 14 12 "Pelmaithodor" (_"Pelmaithodor")} {GUARDIAN} {FACING sw}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_HEALTHY}
            [/modifications]
        [/unit]
    [/side]
    [event]
        name=prestart
        {NAMED_NOTRAIT_UNIT 3 (Dwarvish Scout) 35 11 "Duduril" (_"Duduril")} {GUARDIAN} {FACING sw} # start him on side 3 so he doesn't give vision
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

        {MODIFY_AI_DELETE_CANDIDATE_ACTION 3 main_loop leader_shares_keep}
    [/event]
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Dwarvish Miner"    4} # including the farm guardian
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Dwarvish Fighter"   1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Dwarvish Thunderer" 1}
    {SILENTLY_LIMIT_LEADER_MOVES 2 3}
    {SILENTLY_LIMIT_MOVES 2 (id=Pelmaithodor) 2} # so he doesn't charge in unless the dwarves are losing
    {STARTING_VILLAGES_AREA 2 26 9 0}

    [side]
        side=3
        controller=ai
        recruit=Troll Whelp
        gold=30
        income=3 # scaling comes from the {GUARDIAN} units, which are worth 13 + 13 + 25 gold
        team_name=trolls
        user_team_name=_"Trolls"
        type=Troll
        canrecruit=yes
        id=Kabak
        name=_"Kabak"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_FEARLESS}
        [/modifications]
        [ai]
            aggression=1.0
            grouping=defensive
            leader_value=0
            [avoid]
                x,y=24-99,8-99 # prefer fighting where the player can see
            [/avoid]
        [/ai]
#ifndef EASY
        {NAMED_NOTRAIT_UNIT 3 (Troll Whelp) 30 2 "Nag" (_"Nag")} {GUARDIAN}
        [+unit]
            [modifications]
                {TRAIT_FEARLESS}
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        {NAMED_NOTRAIT_UNIT 3 (Troll Whelp) 23 8 "Hur" (_"Hur")} {GUARDIAN}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]

#endif
#ifdef HARD
        {NAMED_NOTRAIT_UNIT 3 (Troll Rocklobber) 23 8 "Hur" (_"Hur")} {GUARDIAN}
        [+unit]
            [modifications]
                {TRAIT_QUICK}
                {TRAIT_FEARLESS}
            [/modifications]
        [/unit]

#endif
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 3 1}
    {SILENTLY_LIMIT_MOVES 3 (id=Nag) 2} # so he doesn't leave the treasure room
    {SILENTLY_LIMIT_MOVES 3 (id=Hur) 2} # so he doesn't attack unless the trolls are losing
    {STARTING_VILLAGES_AREA 3 29 6 0} # so he doesn't waste a unit capturing the far-off village
    {STARTING_VILLAGES_AREA 3 23 8 0} # a guardian starts on this village, so it needs to start captured

    [side]
        side=4
        controller=ai
        hidden=yes
        type=Necromancer
        id=Mel Guthrak
        name=_"Mel Guthrak"
        [modifications]
            {TRAIT_STRONG}
            {TRAIT_QUICK}
        [/modifications]
        gold=500
        income=98
        team_name=undead
        user_team_name=_"Undead"
        {FLAG_VARIANT undead}
        [ai]
            recruitment_pattern=fighter,scout
            aggression=0.7
            leader_value=0
            {NO_SCOUTS}
        [/ai]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 4 0}
    # only recruit these units, and only in these quantities
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Soulless" 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Draug" 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Banebow" 1}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Vampire Bat" 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Ghost" 3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Blood Bat" 3}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Shadow" 2}

    [event]
        name=prestart

        [time_area]
            x=0-3,4-7,  38-99,36-99
            y=0-4,0-3,   5-12, 7-12
            {DEFAULT_SCHEDULE_AFTERNOON}
        [/time_area]

        [if]
            {VARIABLE_CONDITIONAL guthrak_dead equals yes}
            [then]
                [if] {VARIABLE_CONDITIONAL talar_dead equals yes}
                    [then]
                        {MODIFY_UNIT (id=Mel Guthrak) name (_"Mal-Bakral")}
                    [/then]

                    [else]
                        {MODIFY_UNIT (id=Mel Guthrak) name (_"Mal-Talar") }
                    [/else]
                [/if]
            [/then]
        [/if]

        [objectives]
            side=1
            [objective]
                description= _ "Move any unit to the tunnel exit"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Gweddry or Dacyn"
                condition=lose
            [/objective]
            {TURNS_RUN_OUT}
            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]

        {RECALL Dacyn}
    [/event]

    [event]
        name=start

        [message]
            speaker=Gweddry
            message= _ "Where are we? I can hardly see my own nose."
        [/message]
        [message]
            speaker=Dacyn
            #po: "We" is not just Gweddry and Dacyn, but also all survivors from S01
            message= _ "We are in a tunnel under the outpost. Smugglers originally dug it to sneak behind Wesnoth’s patrols. I believe it to be currently inhabited by trolls."
        [/message]

        # Path leading through the troll cave
        {SCROLL_TO 16 6}
        [remove_shroud]
            side=1
            x,y=16,6
            radius=1
        [/remove_shroud]
        [delay]
            time=500
        [/delay]

        {SCROLL_TO 22 5}
        [remove_shroud]
            side=1
            x,y=22,5
            radius=1
        [/remove_shroud]
        [delay]
            time=500
        [/delay]

        {SCROLL_TO 28 5}
        [remove_shroud]
            side=1
            x,y=28,5
            radius=1
        [/remove_shroud]
        [delay]
            time=500
        [/delay]

        {SCROLL_TO 32 7}
        [remove_shroud]
            side=1
            x,y=32,7
            radius=1
        [/remove_shroud]
        [delay]
            time=500
        [/delay]

        {SCROLL_TO 39 8}
        [remove_shroud]
            side=1
            x=37-99, 36-99, 37
            y= 5-11,  7-11, 12
        [/remove_shroud]
        [delay]
            time=500
        [/delay]

        [message]
            speaker=Dacyn
            message= _ "We must make haste to escape before the undead catch us."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Wait, before we go anywhere — who were those necromancers?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Is this really the time for questions? Suffice to say they represent an army much too powerful for us; perhaps too powerful for all of Wesnoth. We must flee while I consider how to defeat them."
        [/message]
    [/event]

    # Find the dwarves
    [event]
        name=sighted,moveto

        [filter]
            side=2
        [/filter]

        [filter_second]
            side=1
        [/filter_second]

        [message]
            speaker=unit
            #po: speaker is a dwarf
            message= _ "Who goes there?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "We are soldiers of the King of Wesnoth. Make way, or help us get past these trolls."
        [/message]
        [modify_side]
            side=2
            share_view=yes
        [/modify_side]
        [message]
            speaker=Knutan
            #po: in plain English, "Yes, we'll help anyone quarreling with the trolls. But what are you doing down here?"
            message= _ "Aye, we’ll help anyone quarrelin’ wi’ them trolls. But what be ye doing down here?"
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Undead are pursuing us, purging the land of all that lives. You should join us and flee!"
        [/message]
        [message]
            speaker=Knutan
            #po: "My clan has lived in these caves for nearly a century. We'll not be scattered now by some sacks of bones"
            message= _ "My clan ha’ lived in these caves fer near a century. We’ll no’ be scattered now by some sacks o’ bones."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Yes, I’m sure that will end well. Gweddry, we may be able to avoid the bulk of the trolls by going through the dwarves’ tunnel. I doubt they will need it much longer."
        [/message]
    [/event]

    {PLACE_IMAGE items/bones.png 11 3}

    # little easter egg for discovering the river path
    [event]
        name=sighted

        [filter]
            id=Duduril
        [/filter]

        {MODIFY_UNIT id=Duduril side 2} # start him on side 3 so he doesn't give vision
        [message]
            speaker=Duduril
            #po: speaker is a dwarf, currently alone
            message= _ "Humans! What be ye doin’ in our caves?"
        [/message]
        [message]
            speaker=second_unit
            #po: "you" meaning a single dwarf
            message= _ "A horde of undead is pursuing us! You should come with us and escape."
        [/message]
        [message]
            speaker=Duduril
            message= _ "Thursagan’s beard! I’ve got to go help the others!"
        [/message]
        {MOVE_UNIT id=Duduril 27 12}
        {MODIFY_UNIT id=Duduril status.guardian no}
    [/event]

    #------------------
    # TROLL TREZZUR HOLE
    #------------------
    {PLACE_IMAGE items/chest.png 31 2}
    {PLACE_IMAGE scenery/signpost.png 28 5}
    [event]
        name=moveto

        [filter]
            side=1
            x,y=28,5
        [/filter]

        [message]
            speaker=unit
            image=scenery/signpost.png
            #po: "troll treasure hole, keep out"
            message= _ "TROL TREZZUR HOL: KEIP OWT" # wmllint: no spellcheck
        [/message]
        [allow_undo][/allow_undo]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x,y=31,2
        [/filter]

        [sound]
            name=gold.ogg
        [/sound]

        [message]
            speaker=unit
            message= _ "It seems these trolls were hiding some gold. I count fifty gold pieces!"
        [/message]
        [gold]
            side=1
            amount=50
        [/gold]
        [remove_item]
            x,y=$x1,$y1
        [/remove_item]
    [/event]

    [event]
        name=moveto

        [filter]
            side=1
            x,y=32,2
        [/filter]

        [message]
            speaker=Dacyn
            message= _ "I recognize the enchantment on that quiver. How did trolls come to possess such an artifact?"
        [/message]
    [/event]
    {PLACE_ITEM_CRYSTAL_QUIVER 32 2}
    {PLACE_IMAGE terrain/misc/detritus/detritusC-1.png 30 2}
    {PLACE_IMAGE terrain/misc/detritus/detritusC-2.png 29 2}
    {PLACE_IMAGE terrain/misc/detritus/detritusC-3.png 30 1}
    {PLACE_IMAGE terrain/misc/detritus/detritusC-4.png 32 1}
    {PLACE_IMAGE terrain/misc/detritus/detritusC-5.png 31 4}
    {PLACE_IMAGE terrain/misc/detritus/detritusC-6.png 32 3}

    #------------------
    # UNDEAD FIND CAVES
    #------------------
    [event]
        name=turn {ON_DIFFICULTY 12 10 8} # careful: if you lower this, the associated achievement might become unachievable on Hard

        {VARIABLE undead_arrived_s02 yes}
        {MODIFY_TERRAIN Gs 3 4}
        {MODIFY_TERRAIN Gs 4 3}
        {SCROLL_TO 1 1}
        [redraw][/redraw]

        [remove_shroud]
            side=1
            x,y=3,2
            radius=1
        [/remove_shroud]
        [lift_fog]
            x,y=3,2
            radius=2
        [/lift_fog]
        [remove_shroud]
            side=1
            x,y=3,3
            radius=1
        [/remove_shroud]
        [lift_fog]
            x,y=3,3
            radius=1
        [/lift_fog]
        {REPLACE_SCENARIO_MUSIC frantic.ogg}

        [message]
            speaker=Mel Guthrak
            message= _ "I have found your hiding spot, fleshbag! Prepare to die!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "He sounds awfully smug for finding an open trapdoor. Gweddry, we must escape through this tunnel’s eastern exit. It is unfortunate that it will take us into the Estmark hills, beyond the borders of Wesnoth. But it is the only option."
        [/message]

        [objectives]
            side=1
            silent=yes
            [objective]
                description= _ "Move any unit to the tunnel exit"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Gweddry or Dacyn"
                condition=lose
            [/objective]

            {TURNS_RUN_OUT}

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

    # victory
    [event]
        name=enter hex
        [filter]
            side=1
            x=38,  36
            y=5, 8-12
        [/filter]
        [message]
            speaker=unit
            message= _ "I see daylight! Follow me!"
        [/message]
        [if]
            {VARIABLE_CONDITIONAL undead_arrived_s02 not_equals yes}
            [then]
                [set_achievement]
                    content_for=eastern_invasion
                    id=ei_S02
                [/set_achievement]
            [/then]
        [/if]
        [endlevel]
            result=victory
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Knutan
        [/filter]

        [message]
            speaker=Knutan
            message= _ "Maybe I ain’t been the wisest leader..."
        [/message]
    [/event]
    [event]
        name=last breath
        [filter]
            id=Kabak
        [/filter]

        [message]
            speaker=Kabak
            message= _ "From stone I come... now stone I return..."
        [/message]
    [/event]
    [event]
        name=last breath
        [filter]
            id=Mel Guthrak
        [/filter]

        [message]
            speaker=Mel Guthrak
            message= _ "I die? But how?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "A small victory. He will be replaced soon enough; we must still flee."
        [/message]
    [/event]
    [event]
        name=die
        [filter]
            id=Mel Guthrak
        [/filter]

        [fire_event]
            name=spawn_undead
        [/fire_event]
        [event]
            name=side 4 turn
            first_time_only=no
            [fire_event]
                name=spawn_undead
            [/fire_event]
        [/event]
    [/event]
    [event]
        name=spawn_undead
        first_time_only=no
        {GENERIC_UNIT 4 Nightgaunt 1 1} {ANIMATE}
        {GENERIC_UNIT 4 Shadow     1 1} {ANIMATE}
        {GENERIC_UNIT 4 Shadow     1 1} {ANIMATE}
        {GENERIC_UNIT 4 Wraith     1 1} {ANIMATE}
        {GENERIC_UNIT 4 Nightgaunt 1 1} {ANIMATE}
        {GENERIC_UNIT 4 Spectre    1 1} {ANIMATE}
        {GENERIC_UNIT 4 Shadow     1 1} {ANIMATE}
        {GENERIC_UNIT 4 Wraith     1 1} {ANIMATE}
    [/event]

    [event]
        name=side 1 turn {SCENARIO_TURN_LIMIT} end

        [remove_shroud]
            side=1
            x,y=39,8
            radius=3
        [/remove_shroud]
        [lift_fog]
            x,y=39,8
            radius=3
        [/lift_fog]
        {NAMED_UNIT 4 (Dark Adept) 39 8 "Mal-Tar" (_"Mal-Tar") ()} {ANIMATE}
        {GENERIC_UNIT 4 (Soulless)       39  7} {ANIMATE}
        {GENERIC_UNIT 4 (Walking Corpse) 38  7} {ANIMATE}
        {GENERIC_UNIT 4 (Soulless)       39  9} {ANIMATE}
        {GENERIC_UNIT 4 (Walking Corpse) 38 10} {ANIMATE}
        {GENERIC_UNIT 4 (Walking Corpse) 38  5} {ANIMATE}
        [message]
            speaker=Mal-Tar
            message= _ "Hello? My masters said I should see what was making all the noise down in this old cave..."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "We are discovered and surrounded. Now Wesnoth is doomed..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {EARLY_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
[/scenario]

#undef SCENARIO_TURN_LIMIT
