#textdomain wesnoth-ei

#
# 2 options - west or east
#
# west is easier: flat terrain, and you can win before Mal-Kallat's forces catch up to you
#    but leads to the low-reward Elven Interlude
# east is harder: fighting bats/ghosts in difficult terrain, and Mal-Skraat's forces will catch up to you
#    but leads to the high-reward Bitter Swamp and Mal-Ravanal's Capital
#

#define SCENARIO_TURN_LIMIT
24 #enddef

[scenario]
    id=03_An_Unexpected_Appearance
    name= _ "An Unexpected Appearance"
    map_file=03_An_Unexpected_Appearance.map
    next_scenario=04a_An_Elven_Interlude
    turns={SCENARIO_TURN_LIMIT}

    {DEFAULT_SCHEDULE}

    [story]
        [part]
            story=_ "Daylight broke over the relieved faces of Gweddry and his men as they clambered out of the dingy cave. The lush Estmark hills filled the horizon in all directions."
            music=silence.ogg
            {EI_BIGMAP}
        [/part]
    [/story]
    {EI_TRACK {JOURNEY_03_NEW} }
    {SCENARIO_MUSIC knolls.ogg}

    {PLACE_IMAGE scenery/trapdoor-open.png 23 11}

    [side]
        side=1
        controller=human
        {GOLD 170 160 150}
        team_name=wesnothians
        user_team_name= _ "Wesnothians"
        {FLAG_VARIANT loyalist}
        {CHARACTER_STATS_GWEDDRY}
    [/side]

    [side]
        side=2
        controller=ai
        recruit=Walking Corpse,Soulless,Ghoul,Skeleton Rider
        {GOLD 20 60 100}
        {INCOME -2 0 4}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Dark Sorcerer
        id=Mal-Skraat
        #po: brother of Mal-Kallat
        name= _ "Mal-Skraat"
        canrecruit=yes
        facing=ne
        [modifications]
            {TEAM_COLOR_OVERRIDE () darkred}
            {TRAIT_INTELLIGENT}
            {TRAIT_STRONG}
        [/modifications]
        [ai]
            scout_village_targeting=0.8
            leader_value=0
        [/ai]
    [/side]
    {STARTING_VILLAGES 2 9}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Vampire Bat" 1}
    {RECRUIT_UNIT_VARIATIONS 2 "Walking Corpse" none,none,mounted,mounted}
    {RECRUIT_UNIT_VARIATIONS 2 "Soulless" none,none,mounted,mounted}
    {SILENTLY_LIMIT_LEADER_MOVES 2 1}

    [side]
        side=3
        controller=ai
        recruit=Walking Corpse
        {GOLD 0 0 8}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Dark Adept
        id=Mal-Tar
        name= _ "Mal-Tar"
        canrecruit=yes
        facing=sw
        experience=11
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_RESILIENT}
        [/modifications]
        [ai]
            aggression=1.0
            leader_aggression=1.0
            leader_value=0
        [/ai]
#ifndef EASY
        {GENERIC_UNIT 3 (Walking Corpse) 25 11}
#endif
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 3 1}
    {FORCE_CHANCE_TO_HIT id=Gweddry,Dacyn side=3 100 ()} # make sure you can't lose from bad luck

    [side]
        side=4
        controller=ai
        recruit={ON_DIFFICULTY (Vampire Bat) (Vampire Bat,Blood Bat,Ghost) (Vampire Bat,Blood Bat,Ghost)} # on easy, she might never recruit if she tries to save money
        {GOLD 13 35 60} # needs at least 13 gold to get her first vampire bat
        {INCOME 1 6 12}
        team_name=undead
        user_team_name= _ "Undead"
        {FLAG_VARIANT undead}
        type=Dark Sorcerer
        id=Mal-Kallat
        #po: sister of Mal-Skraat
        name= _ "Mal-Kallat"
        gender=female
        canrecruit=yes
        facing=sw
        [modifications]
            {TEAM_COLOR_OVERRIDE () darkred}
            {TRAIT_INTELLIGENT}
            {TRAIT_QUICK}
        [/modifications]
        [ai]
            leader_value=0
        [/ai]
    [/side]
    {LIMIT_CONTEMPORANEOUS_RECRUITS 4 (Vampire Bat) 2}
    # no starting villages for side 4. This delays the initial wave of bats/ghosts
    {SILENTLY_LIMIT_LEADER_MOVES 4 1}

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

        {RETREAT_WHEN_WEAK 2 {ON_DIFFICULTY 0-3 0-4 0-5} (
            {GOAL_LOCATION 99 (x,y=13,14)}
            {GOAL_LOCATION 88 (x,y=9,15)}
            {GOAL_LOCATION 77 (x,y=7,14)}
        )}
        {RETREAT_WHEN_WEAK 4 {ON_DIFFICULTY 0-3 0-4 0-5} (
            {GOAL_LOCATION 99 (x,y=43,13)}
            {GOAL_LOCATION 88 (x,y=49,19)}
            {GOAL_LOCATION 77 (x,y=47,9)}
        )}
        {VARY_AI_BY_SCHEDULE 2,4}
    [/event]

    [event]
        name=prestart

        [objectives]
            side=1
            [objective]
                description= _ "To travel northwest, defeat Mal-Skraat. <i>(easy)</i>"
                condition=win
            [/objective]
            [objective]
                {ALTERNATIVE_OBJECTIVE_CAPTION}
                description= _ "To travel east, defeat Mal-Kallat. <i>(normal)</i>"
                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_XY Dacyn 22 10}
        {MODIFY_UNIT id=Dacyn facing se}
        {MODIFY_UNIT id=Gweddry facing se}

        [if]
            {VARIABLE_CONDITIONAL undead_arrived_s02 equals yes}
            [then]
                {GENERIC_UNIT 4 Skeleton 23 11} {FACING nw}
            [/then]
        [/if]
    [/event]

    [event]
        name=start

        [if]
            {VARIABLE_CONDITIONAL  undead_arrived_s02 equals yes}
            [then]
                [delay]
                    time=250
                [/delay]

                {DACYN_ATTACK}
                {KILL x,y=23,11 ANIMATE=yes}
                [message]
                    speaker=Dacyn
                    message= _ "Quick, I must collapse the tunnels behind us."
                [/message]

                {DACYN_ATTACK}
                [sound]
                    name=cave-in.ogg
                [/sound]

                {PLACE_IMAGE scenery/castle-ruins.png 23 11}
                [delay]
                    time=500
                [/delay]

                {DACYN_ATTACK}
                {PLACE_IMAGE scenery/castle-ruins2.png 23 11}
                [delay]
                    time=500
                [/delay]

                {DACYN_ATTACK}
                {PLACE_IMAGE scenery/castle-ruins3.png 23 11}
                [delay]
                    time=1000
                [/delay]
            [/then]

            [else]
                [message]
                    speaker=Dacyn
                    message= _ "Excellent, we have swiftly escaped the tunnels, and there is no sign of pursuit."
                [/message]
            [/else]
        [/if]
        {CLEAR_VARIABLE undead_arrived_s02}

        [message]
            speaker=Gweddry
            message= _ "It’s a relief to once again breathe the fresh air. Where are we now?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "These are the Estmark hills, so we must be in a mountain pass leading both east and west. I am unsure which path leads us the swiftest towards Wesnoth, but we certainly cannot stay here."
        [/message]
        [message]
            speaker=Mal-Kallat
            #po: sister talking to younger brother
            message= _ "What are these soldiers doing here? The vanguard must not have done a thorough job of cleaning up..."
        [/message]
        [message]
            speaker=Mal-Skraat
            #po: brother talking to older sister
            message= _ "Don’t be scared, Kala. Look at how haggard they are! I bet the new recruit can handle them by himself."
        [/message]
        [message]
            speaker=Mal-Tar
            #po: Dacyn and Gweddry are going to do this during turn 1, before he even gets a chance to recruit
            message= _ "No!! They’ll kill me!"
        [/message]
        [message]
            speaker=Mal-Skraat
            #po: talking to Mal-Tar
            message= _ "We can always bring you back if you die."
        [/message]
    [/event]

    #TODO: at some point, I want to drop some journals somewhere in this scenario or in some other ones to hint at Mal-Skraat and Mal-Kallat's backstory.
    #Idea is for Kala to be a mage in training who had to abandon her studies when her parents died and she had to return to take care of her little brother
    #She couldn't really get by with regular magic doing much (they didn't teach practical things in Alduin at first), so she studied some dark magic to get by
    #Fearing being found out when Konrad II's current mage council (including Dacyn) began cracking down more on black magic, she fled with her little brother

    [event]
        name=turn 2
        [message]
            speaker=Dacyn
            message= _ "I believe this is the undead rearguard; we must have crossed under their armies while in the tunnel. We must kill either of the dark sorcerers and escape towards Wesnoth."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "This is a true invasion then? These necromancers mean to conquer Wesnoth itself?"
        [/message]
        [message]
            speaker=Dacyn
            #po: "their leader" being Mal-Ravanal, who's neither male nor female
            message= _ "Yes. I have history with their leader."
        [/message]
    [/event]

    [event]
        name=die

        [filter]
            id=Gweddry,Dacyn
        [/filter]

        [filter_second]
            side=3
        [/filter_second]

        [filter_condition]
            [have_unit]
                id=Mal-Tar
            [/have_unit]
        [/filter_condition]

        [message]
            speaker=Mal-Tar
            message= _ "I... I actually did it!"
        [/message]
        [message]
            speaker=Mal-Skraat
            message= _ "Well well, I’m impressed! Perhaps this apprenticeship has not been wasted on you after all."
        [/message]
        [message]
            speaker=Mal-Kallat
            #po: star wars reference
            message= _ "We will watch your career with great interest..."
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]
    [event]
        name=last breath
        [filter]
            id=Mal-Tar
        [/filter]

        [message]
            speaker=Mal-Tar
            message= _ "Wait, please, not like this!"
        [/message]

        # add in the herodeaths. Don't do these before, since we want special behavior for the achievement
        {HERODEATH_GWEDDRY}
        {HERODEATH_DACYN}
    [/event]
    [event]
        name=die
        [filter]
            id=Mal-Tar
        [/filter]

        [message]
            speaker=Mal-Skraat
            message= _ "I told him he should have studied harder."
        [/message]
        [message]
            speaker=Mal-Kallat
            message= _ "I wanted to avoid as much battle as I could, but it seems like we have no choice..."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Mal-Skraat
        [/filter]

        [message]
            speaker=Mal-Kallat
            message= _ "Skrai, no!! Cursed Wesnothians, he was my precious little brother..."
        [/message]

        {VARIABLE skraat_dead yes}
        {VARIABLE fork_04a yes}
        [endlevel]
            result=victory
            next_scenario=04a_An_Elven_Interlude
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=Mal-Kallat
        [/filter]

        [message]
            speaker=Mal-Skraat
            message= _ "Kala, no!! Curse you Wesnothians! You may have killed my sister, but I will chase you east and take my revenge!"
        [/message]

        {VARIABLE kallat_dead yes}
        {VARIABLE fork_04b yes}
        [endlevel]
            result=victory
            next_scenario=04b_Ill_Humors
            bonus=yes
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

    [event]
        name=victory

        [filter_condition]
            [have_unit]
                id=Mal-Tar
            [/have_unit]
        [/filter_condition]

        [set_achievement]
            content_for=eastern_invasion
            id=ei_S03
        [/set_achievement]

        {VARIABLE mal_tar_alive yes}
        [message]
            speaker=Mal-Tar
            message= _ "... wait, what just happened? Why am I still alive?"
        [/message]
    [/event]

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

        #TODO: make an actual time over cutscene
        {GENERIC_UNIT 3 (Spectre) 23 11} {ANIMATE}
        {GENERIC_UNIT 3 (Ghost)   21 10} {ANIMATE}
        {GENERIC_UNIT 3 (Wraith)  23 12} {ANIMATE}
        {GENERIC_UNIT 3 (Wraith)  23  9} {ANIMATE}
        {GENERIC_UNIT 3 (Ghost)   24 10} {ANIMATE}
        {GENERIC_UNIT 3 (Spectre) 23 13} {ANIMATE}
        {GENERIC_UNIT 3 (Ghost)   23 11} {ANIMATE}
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}

    {EARLY_DEFEAT}
[/scenario]

#undef SCENARIO_TURN_LIMIT
