#textdomain wesnoth-ei

#define SCENARIO_TURN_LIMIT
25 #enddef

[scenario]
    id=04a_An_Elven_Interlude
    name= _ "An Elven Interlude"
    map_file=04a_An_Elven_Interlude.map
    turns={SCENARIO_TURN_LIMIT}
    next_scenario=05_Northern_Outpost
    victory_when_enemies_defeated=no

    {DEFAULT_SCHEDULE}

    {SCENARIO_MUSIC       silvan_sanctuary.ogg}
    {EXTRA_SCENARIO_MUSIC traveling_minstrels.ogg}
    {EXTRA_SCENARIO_MUSIC elvish-theme.ogg}

    {AMBIENT_BIRDS 12 21}
    {AMBIENT_BIRDS 5  14}
    {AMBIENT_BIRDS 33 17}
    {AMBIENT_BIRDS 29 7 }
    {SET_LABEL 18 16 _"Singing Spring"}

    [story]
        [part]
            music=elf-land.ogg
            story=_ "Gweddry and Dacyn found but scant respite through the west pass. After weeks of slow and labored mountain marching, they stumbled upon a green valley and an unknown forest."
            {EI_BIGMAP}
        [/part]
    [/story]

    {EI_TRACK {JOURNEY_04A_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_AREA 1 29-99 13-99 0}
    # wmllint: validate-on

    #-----------------
    # ELVES
    #-----------------
    [side]
        side=2
        controller=ai
        recruit=Elvish Fighter,Elvish Archer,Elvish Shaman
        {GOLD 15 45 80}
        income=0
        team_name=good # start allied so 1) we don't give away the dialogue and 2) the player can see the elvish rangers
        user_team_name= _ "Elves"
        {FLAG_VARIANT wood-elvish}
        type=Elvish Lady
        id=Vaelya
        name= _ "Vaelya"
        canrecruit=yes
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_DEXTROUS}
        [/modifications]
#ifndef EASY
        {GENERIC_UNIT 2 ({ON_DIFFICULTY (none)          (Elvish Ranger) (Elvish Ranger) })  9 14} {GUARDIAN}
        {GENERIC_UNIT 2 ({ON_DIFFICULTY (none)          (Elvish Archer) (Elvish Ranger) }) 12 15} {GUARDIAN}
#endif
        {GENERIC_UNIT 2 ({ON_DIFFICULTY (Elvish Archer) (Elvish Ranger) (Elvish Ranger) }) 11 21} {GUARDIAN}
        {GENERIC_UNIT 2 ({ON_DIFFICULTY (Elvish Archer) (Elvish Archer) (Elvish Ranger) })  8 16} {GUARDIAN}
        {GENERIC_UNIT 2 ({ON_DIFFICULTY (Elvish Ranger) (Elvish Ranger) (Elvish Avenger)})  9 18} {GUARDIAN}
    [/side]
    {STARTING_VILLAGES_AREA 2 5-22 11-99 0}
    {SILENTLY_LIMIT_LEADER_MOVES 2 2}

    [event]
        name=side 1 turn end
        first_time_only=no
        {RESET_SIDE_AI 2 no -2 2}

        {MODIFY_SIDE_AI (2) ({GOAL_SEEK_SIDE 0.001 2 4})} # group up. Defensive grouping doesn't seem to do anything...

        {MODIFY_SIDE_AI (2) ({GOAL_LOCATION 9 (x,y,radius=13,18,1)})}
        {MODIFY_SIDE_AI (2) ({GOAL_LOCATION 9 (x,y,radius=10,14,1)})}

        {RETREAT_WHEN_WEAK 2 0-8 (
            {GOAL_LOCATION 99 (x,y=15,16)}
            {GOAL_LOCATION 99 (x,y=13,15)}
            {GOAL_LOCATION 99 (x,y=12,19)}
        )}

        # don't send scouts out of the forest
        {MODIFY_SIDE_AI (2) (villages_per_scout=0)}

        {VARY_AI_BY_SCHEDULE 2}
    [/event]

    #-----------------
    # MERCENARIES
    #-----------------
    [side]
        color=green
        side=3
        controller=ai
        recruit=Thug,Thief,Footpad,Orcish Grunt,Orcish Archer,Orcish Assassin
        {GOLD 0 50 120} # reduced scaling, because they start with free recruits
        {INCOME -2 5 15} # also because they have a lot of villages
        team_name=enemies
        user_team_name= _ "Mercenaries"
        {FLAG_VARIANT6 ragged}
        type=Outlaw
        id=Addogin
        name= _ "Addogin"
        canrecruit=yes
        [modifications]
            {TRAIT_RESILIENT}
        [/modifications]
        [ai]
            leader_value=0
        [/ai]

        # NOTE - I use these specific locations when I have the mercenaries retreat
        # reduced scaling, because you don't need to fight these guys if you don't want to
        {GENERIC_UNIT 3 (Thug) 3 1} {GUARDIAN}
        {GENERIC_UNIT 3 (Rogue) 2 1} {GUARDIAN}
        {GENERIC_UNIT 3 (Orcish Assassin) 1 3} {GUARDIAN}
#ifndef EASY
        {GENERIC_UNIT 3 (Orcish Archer) 5 1} {GUARDIAN}
#endif
#ifdef HARD
        {GENERIC_UNIT 3 (Orcish Grunt) 2 4} {GUARDIAN}
#endif
    [/side]
    {STARTING_VILLAGES 3 3}
    {SILENTLY_LIMIT_LEADER_MOVES 3 1}

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

        {RETREAT_WHEN_WEAK 3 {ON_DIFFICULTY 0-9 0-12 0-15} (
            #including {GUARDIAN} units!
            {GOAL_LOCATION 99 (x,y=18,4)}
            {GOAL_LOCATION 88 (x,y=20,3)}
            {GOAL_LOCATION 77 (x,y=16,3)}
        )}
        {VARY_AI_BY_SCHEDULE 3}
    [/event]

    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Move any unit to the signpost in the northwest"
                condition=win
            [/objective]
            [objective]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Kill Addogin (bonus reward)"
                condition=win
                [show_if]
                    [have_unit]
                        id=Addogin
                        side=3
                    [/have_unit]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry or Dacyn"
                condition=lose
            [/objective]
            {TURNS_RUN_OUT}
            [gold_carryover]
                bonus=yes
                carryover_percentage=40
            [/gold_carryover]
            [note]
                description= _ "Control 10 villages or kill Addogin to force the mercenaries to retreat."
                [show_if]
                    [have_unit]
                        id=Addogin
                        side=3
                    [/have_unit]
                [/show_if]
            [/note]
        [/objectives]

        {RECALL Dacyn}
    [/event]

    [event]
        name=start
        [message]
            speaker=Vaelya
            message= _ "Greetings, travelers! I hope you find our forest hospitable."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Indeed, and you have my thanks for allowing us entry."
        [/message]
        [message]
            speaker=Vaelya
            message= _ "What brings you to our lands? Long has it has been since men of Wesnoth presented themselves to us."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "I’m afraid Wesnoth has been invaded by fell undead, although I am glad to see they have not yet entered this forest. We have come here seeking refuge and passage to Wesnoth’s northern river outpost."
        [/message]
        [message]
            speaker=Vaelya
            #po: followed by a delay and then the elves switching from allies to enemies
            message= _ "I am sorry to hear of your misfortune. Our scouts had spotted undead in this area, but I am shocked to hear that they are attacking Wesnoth. And if they are hunting you, then..."
        [/message]

        [delay]
            time=2000
        [/delay]

        [modify_side]
            side=2
            team_name=enemies
        [/modify_side]
        [message]
            speaker=Vaelya
            message= _ "My heart aches with the weight of this decision, but if you are being pursued by undead I am afraid I cannot allow you entry. You are welcome to travel outside our lands, but I cannot risk bringing destruction to my people."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "So much for forest hospitality. Elf, you know full well that going around will take us days of forced march, time which we can hardly afford. We despise the undead just as much as you. Let us pass."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "Vaelya, surely you can find it in your heart to grant us passage?"
        [/message]
        [message]
            speaker=Vaelya
            message= _ "I wish I could, but I would spare my people the fate of undeath. I must take precautions to protect these lands."
        [/message]
        [message]
            speaker=Vaelya
            message= _ "In fact, I confess that since hearing of the undead I have stooped so low as to hire a mercenary company..."
        [/message]
        [message]
            speaker=Vaelya
            message= _ "... Addogin, please escort these Wesnothians away to the east."
        [/message]

        {GENERIC_UNIT 3 (Orcish Archer) 18 2} {ANIMATE}
        {GENERIC_UNIT 3 (Thief) 17 3} {ANIMATE}
        {GENERIC_UNIT 3 (Thug) 18 1} {ANIMATE}
        [message]
            speaker=Addogin
            message= _ "You heard the lady! Boys, it’s time to earn our keep!"
        [/message]
        [move_unit_fake]
            type={ON_DIFFICULTY (Orcish Slayer) (Orcish Nightblade) (Orcish Nightblade)}
            side=3
            x=18,18,18
            y=1,2,3
        [/move_unit_fake]
        [unit]
            type={ON_DIFFICULTY (Orcish Slayer) (Orcish Nightblade) (Orcish Nightblade)}
            id=Nafga
            name= _ "Nafga"
            side=3
            x,y=18,3
            [modifications]
                {TRAIT_DEXTROUS}
                {TRAIT_QUICK}
            [/modifications]
        [/unit]
        [message]
            speaker=Nafga
            #po: What are your orders for me to perform, Addogin?
            message= _ "And what about me?"
        [/message]
        [message]
            speaker=Addogin
            #po: "you" being a single male Orcish Slayer or Orcish Nightblade
            #po: later in the campaign, it's revealed that the necromancers are buying corpses, and a lot are being sold
            message= _ "Into the forest with you. If it comes to bloodshed, strike at them from behind. And don’t even think of running off with any corpses before I can collect our bounty!"
        [/message]
        [store_unit]
            [filter]
                id=Nafga
            [/filter]

            kill=yes
            variable=nafga_store
        [/store_unit]
        [move_unit_fake]
            type=$nafga_store.type
            side=3
            x=18,18,18,18
            y=3,4,5,6
        [/move_unit_fake]

        [message]
            speaker=Gweddry
            message= _ "There must be some way to resolve this without fighting..."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Finding another path westwards would cause great delay, which would cost Wesnoth many lives. We will fight our way through the mercenaries, through the elves and out the other side."
        [/message]
        {HIGHLIGHT_IMAGE 1 2 items/gohere.png ()}
        [message]
            speaker=Gweddry
            message= _ "... hmm, mercenaries are not known for their loyalty. If we can show we are gaining ground, they may turn and run. If we can defeat their leader, the outcome may be even better."
        [/message]
    [/event]

    # as soon as anyone dies, Nafga appears
    [event]
        name=die
        [event]
            name=side 3 turn
            {VARIABLE nafga_store.x 31}
            {VARIABLE nafga_store.y 18}
            [unstore_unit]
                variable=nafga_store
                find_vacant=yes
            [/unstore_unit]
            {CLEAR_VARIABLE nafga_store}
            {ZONE_GUARDIAN 3 "Nafga" 31 18  31 18 99} # zone guardian so he doesn't attempt to capture villages
            [message]
                speaker=Nafga
                message= _ "Bloodshed, hahaha! Nafga will kill the humans and keep the bounty all for himself!"
            [/message]
        [/event]
    [/event]

#define RETREAT_MERCENARIES
    [message]
        speaker=Addogin
        message= _ "No amount of money is worth dying for. Forget this, it’s time to bail!"
    [/message]
    {MOVE_UNIT (x,y=5,1) 1 2}  {KILL x,y=1,2}
    {MOVE_UNIT (x,y=3,1) 1 2}  {KILL x,y=1,2}
    {MOVE_UNIT (x,y=2,1) 1 2}  {KILL x,y=1,2}
    {MOVE_UNIT (x,y=1,3) 1 2}  {KILL x,y=1,2}
    {MOVE_UNIT (x,y=2,4) 1 2}  {KILL x,y=1,2}
    [kill]
        side=3

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

        [then]
            [message]
                speaker=Vaelya
                #po: to the remaining mercenaries, who are orcs and human outlaws
                message= _ "No, we need your help! Please come back!"
            [/message]
            [message]
                speaker=Addogin
                message= _ "Sorry lady, but coin’s no good if you’re not alive to spend it."
            [/message]
        [/then]
    [/if]
    {MOVE_UNIT id=Addogin 16 1}
#enddef

    # mercenaries scatter when Gweddry has 10 villages
    [event]
        name=capture
        [filter_condition]
            [have_location]
                owner_side=1
                count=10
            [/have_location]
            [and]
                [have_unit]
                    id=Addogin
                    side=3
                [/have_unit]
            [/and]
        [/filter_condition]

        {FIND_NEARBY (side=3) 20 20 99}
        [message]
            speaker=$found_unit.id
            #po: the mercenaries decide it's time to retreat
            message= _ "This ain’t lookin’ good. Those Wesnoth soldiers are <i>mean</i>."
        [/message]
        {CLEAR_VARIABLE found_unit}

        {RETREAT_MERCENARIES}
        {KILL id=Addogin}
    [/event]

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

        {RETREAT_MERCENARIES}

        {MOVE_UNIT id=$second_unit.id 15 1}
        [message]
            speaker=$second_unit.id
            #po: capturing Addogin, spoken by the unit fighting him
            message= _ "Oh no you don’t! You and your band of mercenaries have caused us enough trouble! How do we know you won’t rally your men and attack us again?"
        [/message]
        [message]
            speaker=Gweddry
            #po: capturing Addogin
            message= _ "I suppose we’ll have to bring him with us, at least for a time. Tie him up so he doesn’t run away."
        [/message]
        [message]
            speaker=Addogin
            message= _ "Help! I was only doing my job!"
        [/message]

        [sound]
            name=magicmissile.wav
        [/sound]
        [delay]
            time=300
        [/delay]
        [sound]
            name=magicmissile.wav
        [/sound]

        [modify_unit]
            [filter]
                id=Addogin
            [/filter]

            side=1
            canrecruit=no
            hitpoints=1
            {TRAIT_LOYAL}
            {TEAM_COLOR_OVERRIDE () green}
        [/modify_unit]
        {MODIFY_UNIT id=Addogin status.slowed yes}
        {MODIFY_UNIT id=Addogin attacks_left 0}
        [event]
            name=side 1 turn refresh
            first_time_only=no
            {MODIFY_UNIT id=Addogin status.slowed yes}
            {MODIFY_UNIT id=Addogin attacks_left 0}
        [/event]

        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "Addogin has joined your side, but will be <b><i>slowed</i></b> and <b><i>unable to attack</i></b> as long as he remains tied up."
        [/message]
        [message]
            speaker=Addogin
            message= _ "I’m gettin’ too old for this..."
        [/message]

        [show_objectives]
        [/show_objectives]

        {VARIABLE addogin_killed yes} # killed, not fled
        [if]
            [not]
                [have_unit]
                    id=Vaelya
                [/have_unit]
            [/not]

            [then]
                [set_achievement]
                    content_for=eastern_invasion
                    id=ei_S04a
                [/set_achievement]
            [/then]
        [/if]
    [/event]

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

        [message]
            speaker=Nafga
            #po: last breath
            message= _ "No! This is the first and last time I have failed a mission!"
        [/message]
    [/event]

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

        [message]
            speaker=Vaelya
            #po: last breath
            message= _ "I only wanted... to protect my people..."
        [/message]
        {KILL id=Vaelya}
        [if]
            {VARIABLE_CONDITIONAL addogin_killed equals yes}
            [then]
                [set_achievement]
                    content_for=eastern_invasion
                    id=ei_S04a
                [/set_achievement]
            [/then]
        [/if]

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

            [then]
                {RETREAT_MERCENARIES}
                {KILL id=Addogin}
            [/then]
        [/if]
    [/event]

    [event]
        name=moveto

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

        [message]
            speaker=unit
            #po: The valley of the River Weldyn, although there's also a city with the same name.
            message= _ "I’ve made it through the forest and I can see the valley Weldyn open on the other side!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Well done, we have crossed this forest without major delay. Now we must see what has become of Owaec and his garrison."
        [/message]

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

    [event]
        name=side 1 turn {SCENARIO_TURN_LIMIT} end
#define NO_INVISIBILITY
    [+unit]
        [modifications]
            [object]
                [effect]
                    apply_to=remove_ability
                    [abilities]
                        {ABILITY_AMBUSH}
                    [/abilities]
                [/effect]
            [/object]
        [/modifications]
    [/unit]
#enddef
        {GENERIC_UNIT 2 (Elder Wose)    9 14} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose)         18 13} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose)         21 21} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Elder Wose)   18 17} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose Sapling) 17 18} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose)          9  7} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose Sapling)  8  7} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose)          6 18} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose Sapling) 14 17} {NO_INVISIBILITY} {ANIMATE}
        {GENERIC_UNIT 2 (Wose Sapling) 14  9} {NO_INVISIBILITY} {ANIMATE}
        [message]
            speaker=Addogin
            message= _ "What the?! Are you seeing this? Trees aren’t supposed to move like that."
        [/message]
        [message]
            speaker=Vaelya
            message= _ "The forest itself has come to our aid! Not in a hundred years have I witnessed such a wonder."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "The fighting has awoken woses from the forest. Now they will surely deny us passage, and this delay will mean the end of Wesnoth..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {FOREIGN_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
[/scenario]

#undef SCENARIO_TURN_LIMIT
