#textdomain wesnoth-low
{./07_Elves_last_stand_utils.cfg}
[scenario]
    id=07_Elves_last_stand
    name= _ "Elves' Last Stand"
    {LOW_MAP  Kalian.map}
    {LOW_MASK 07_Elves_last_stand.mask}

    {TURNS 35 30 25}
    {DEFAULT_SCHEDULE}

    {INTRO_AND_SCENARIO_MUSIC elf-land.ogg elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}
    {EXTRA_SCENARIO_MUSIC elf-land.ogg}
    {EXTRA_SCENARIO_MUSIC wanderer.ogg}
    {EXTRA_SCENARIO_MUSIC siege_of_laurelmor.ogg}
    {EXTRA_SCENARIO_MUSIC suspense.ogg}
    {EXTRA_SCENARIO_MUSIC heroes_rite.ogg}

    #{DEFAULT_MUSIC_PLAYLIST}


    next_scenario=08_Council_of_hard_choices
    [story]
        [part]
            story= _ "The journey back to Wesmere was surprisingly uneventful, the orcs having apparently withdrawn to regroup after their defeats. Kalenz and his band returned just in time..."
            delay=4000
        [/part]
        [part]
            delay=4000
            {TO_ELVES_LAST_STAND}
        [/part]
    [/story]

    #Kalenz
    #wmllint: validate-off
    [side]
        side=1
        no_leader=yes
        controller=human
        team_name=kalenz
        save_id=Kalenz
        recruit={ELVES}
    [/side]
    [event]
        name=prestart

        [recall]
            id=Kalenz
            x=42
            y=10
        [/recall]
        # wmllint: recognize Kalenz

        # the usual suspects
        {RECALL_LOYALS}

        {CHECK_LANDAR}
        # wmllint: recognize Landar
        {CHECK_CLEODIL}
        # wmllint: recognize Cleodil

        {CHECK_OLURF_STORE ({IS_HERO})}
    [/event]

    [side]
        side=2
        no_leader=yes
        team_name=kalenz
        recruit={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid, Elvish Lord
        [unit]
            {GALTRID}
            x=33
            y=26
        [/unit]
        # wmllint: recognize Galtrid

        {GOLD 250 300 400}

        [ai]
            passive_leader=yes
            villages_per_scout=20
            aggression=0.0
            caution=0.75
            grouping=defensive
        [/ai]
    [/side]
    #wmllint: validate-on
    {STARTING_VILLAGES_ALL 2}

    [side]
        side=3
        no_leader=yes
        team_name=kalenz
        [unit]
            type=Elvish Marshal
            id="El'Isomithir"
            name=_ "El'Isomithir"
            canrecruit=yes
            x=13
            y=35
        [/unit]
        controller=ai
        [ai]
            villages_per_scout=20
            aggression=0.0
            caution=0.75
            grouping=defensive
        [/ai]
        {GOLD 280 300 400}
        recruit={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid
    [/side]
    {STARTING_VILLAGES_AREA 3 13 35 15}

    #enemies
    [side]
        side=4
        team_name=orcs
        no_leader=yes
        [unit]
            type=Orcish Warlord
            id=Mordrum
            name=_ "Mordrum"
            profile=portraits/orcs/warlord4.png
            canrecruit=yes
            x=4
            y=12
        [/unit]

        {RECRUIT_ORC}
        {GOLD 550 700 900}

        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_pattern=scout,fighter,fighter,archer,mixed fighter
            aggression=0.75
            caution=0.0
            attack_depth=5
            grouping=offensive
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            attack_depth=5
            grouping=offensive
        [/ai]
        {INCOME 4 8 12}
    [/side]
    [side]
        side=5
        no_leader=yes
        [unit]
            type=Orcish Warlord
            id=Urug-Pir
            name=_ "Urug-Pir"
            profile=portraits/orcs/warlord3.png
            canrecruit=yes
            x=6
            y=21
        [/unit]

        {RECRUIT_ORC}

        {GOLD 300 500 730}
        team_name=orcs
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_pattern=scout,fighter,fighter,archer,mixed fighter
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
            attack_depth=5
        [/ai]
        {INCOME 4 8 12}
    [/side]
    [side]
        side=6
        no_leader=yes
        team_name=orcs
        [unit]
            type=Great Troll
            id=Truugl
            name= _ "Truugl"
            canrecruit=yes
            x=26
            y=7
        [/unit]
#ifdef EASY
        recruit=Troll Whelp
#endif
#ifdef NORMAL
        recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman
#endif
#ifdef HARD
        recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman, Troll Warrior
#endif

        {GOLD 350 520 630}
        {INCOME 4 8 12}
        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_ignore_bad_combat=yes
#ifdef EASY
            recruitment_pattern=fighter
#else
            recruitment_pattern=fighter, mixed fighter, fighter, mixed fighter, fighter
#endif
        [/ai]
        [ai]
            recruitment_ignore_bad_movement=yes
            recruitment_ignore_bad_combat=yes
#ifdef EASY
            recruitment_pattern=fighter
#else
            recruitment_pattern=fighter, mixed fighter, fighter, mixed fighter, fighter
#endif
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            attack_depth=5
            grouping=offensive
        [/ai]
    [/side]
    [side]
        side=7
        team_name=orcs
        no_leader=yes
        [unit]
            type=Orcish Warlord
            id=Grubr
            name= _ "Grubr"
            profile=portraits/orcs/warlord5.png
            canrecruit=yes
            x=25
            y=42
        [/unit]

        {RECRUIT_ORC}
        {GOLD 400 550 650}
        {INCOME 4 8 12}

        [ai]
            {NO_SCOUTS}
            recruitment_ignore_bad_movement=yes
            recruitment_pattern=scout,fighter,fighter,archer,mixed fighter
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            attack_depth=5
            grouping=offensive
        [/ai]
    [/side]

    #### Objectives and corresponding events ####
    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat all enemy leaders"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Landar"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Cleodil"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Olurf"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Galtrid"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    [event]
        name=enemies defeated
        [endlevel]
            result=victory
            bonus=no
            carryover_percentage=100
        [/endlevel]
    [/event]
    #### /Objectives and corresponding events ####

    [event]
        name=start

        {SET_LABEL 12 2 (_ "River Telfar")}

        #Set locations known to the ai_controller.
        #Call protocol is AI_LOCATION AFFIX STRING RADIUS X Y
        {AI_LOCATION kkalenz     _"Keep of Kalenz"                1 42 11}
        {AI_LOCATION ktrugl      _"Keep of Truugl"                2 26  8}
        {AI_LOCATION kmordrum    _"Keep of Mordrum"               2 4  13}
        {AI_LOCATION kurugpir    _"Keep of Urug-Pir"              2 6  23}
        {AI_LOCATION kelithsomir _"Keep of El'Ithsomir"           1 13 36}
        {AI_LOCATION kgrubr      _"Keep of Grubr"                 1 25 43}
        {AI_LOCATION nshallows   _"Northern Shallows"             2 14  9}
        {AI_LOCATION falyas      _"Ford of Alyas"                 3 23 19}
        {AI_LOCATION ftifranur   _"Ford of Tifranur"              2 38 31}
        {AI_LOCATION tnorth      _"North Tower"                   1 31 24}
        {AI_LOCATION tsouth      _"South Tower"                   1 33 26}
        {AI_LOCATION sgate       _"South Bastion"                 1 31 31}
        {AI_LOCATION telgreen    _"Telfar Green"                  2 12 14}
        {AI_LOCATION dancegreen  _"Dancer's Green"                5 18  4}
        {AI_LOCATION karmarth    _"Karmarth Hills"                5 39  4}
        {AI_LOCATION nbridge     _"North Bridge"                  1 31 20}
        {AI_LOCATION gtree       _"Great Tree"                    1 30 25}
        {AI_LOCATION brightleaf  _"Brightleaf Wood"               5 19 30}
        {AI_LOCATION westwind    _"Westwind Wood"                 5 42 20}
        {AI_LOCATION southwind   _"Southwind Wood"                5 40 38}
        {AI_LOCATION telionath   _"Telionath"                     1 27 34}
        {AI_LOCATION arthen      _"Arthen"                        1 15 20}
        {AI_LOCATION arryn       _"Arryn"                         1 41 26}
        {AI_LOCATION illissa     _"Illissa"                       1 17 25}
        {AI_LOCATION viricon     _"Viricon"                       1 21 39}
        {AI_LOCATION tireas      _"Tireas"                        1 33 16}
        {AI_LOCATION essarn      _"Essarn"                        1 4  30}
        {AI_LOCATION valcathra   _"Valcathra"                     1 7  37}
        {AI_LOCATION aelion      _"Aelion"                        1 33 39}
        {AI_LOCATION elendor     _"Elendor"                       1 27 17}
        {AI_LOCATION erethean    _"Erethean"                      1 28 53}
        [message]
            id=Kalenz
            message= _ "The orcs have pushed us back to the Ka'lian. There is no way out. We must win here!"
        [/message]
        [message]
            id=Galtrid
            message= _ "This is our final stand. If they take the Ka'lian, all is lost!"
        [/message]
        [message]
            id=Grubr
            # wmllint: local spelling da
            message= _ "We'll crush those weak elves and I'll get da stone!"
        [/message]
        ### disabled till after the stringfreeze, don't remove ####
        #        [message]
        #            id=Kalenz
        #
        #            [option]
        #                message= _ "These are hardened orc and troll veterans. Men, prepare for a long, hard fight..."
        #            [/option]
        #
        #            [option]
        #                message= _ "I see the orcish army is big but consists mostly of inexperienced fighters. This should not take too long...."
        ### but gave orcs some more troops..

        ### do AI changes here for lower attack depth
        #                [command]
        #                    [modify_side]
        #                        side=4                       # Mordrun

        #                        {GOLD 580 730 880}
        ## give them +30 gold to offset more stupid AI

        #                        [ai]
        #                            {NO_SCOUTS}
        #                            recruitment_ignore_bad_movement=yes
        #                            recruitment_pattern=scout,fighter,fighter,archer
        #                        [/ai]
        #                        [ai]
        #                            time_of_day=dusk,first_watch,second_watch
        #                            aggression=0.75
        #                            caution=0.0
        #                            attack_depth=1
        #                            grouping=no
        #                        [/ai]
        #                    [/modify_side]
        #                [/command]

        #                [command]
        #                    [modify_side]
        #                        side=5

        #                        {GOLD 350 730 930}
        #                        ## give them +30 gold to offset more stupid AI

        #                        [ai]
        #                            {NO_SCOUTS}
        #                            recruitment_ignore_bad_movement=yes
        #                            recruitment_pattern=scout,fighter,fighter,archer
        #                        [/ai]
        #                        [ai]
        #                            time_of_day=dusk,first_watch,second_watch
        #                            aggression=0.75
        #                            caution=0.0
        #                            attack_depth=1
        #                            grouping=no
        #                        [/ai]
        #                    [/modify_side]
        #                [/command]

        #                [command]
        #                    [modify_side]
        #                        side=6

        #                        {GOLD 340 490 540}
        #                        {INCOME 4 8 12}
        #                        [ai]
        #                            {NO_SCOUTS}
        ##ifdef EASY
        #                            recruitment_pattern=fighter
        ##else
        #                            recruitment_pattern=fighter, mixed fighter, fighter, mixed fighter, fighter
        ##endif
        #                            recruitment_ignore_bad_movement=yes
        #                            recruitment_ignore_bad_combat=yes
        #                        [/ai]
        #                        [ai]
        #                            time_of_day=dusk,first_watch,second_watch
        #                            recruitment_ignore_bad_combat=yes
        #                            recruitment_ignore_bad_movement=yes
        ##ifdef EASY
        #                            recruitment_pattern=fighter
        ##else
        #                            recruitment_pattern=fighter, mixed fighter, fighter, mixed fighter, fighter
        ##endif
        #                            aggression=0.75
        #                            caution=0.0
        #                            attack_depth=1
        #                            grouping=no
        #                        [/ai]
        #                    [/modify_side]
        #                [/command]

        #                [command]
        #                    [modify_side]
        #                        side=7

        #                        {GOLD 430 580 630}
        #                        ## give them +30 gold to offset more stupid AI
        #
        #                        [ai]
        #                            {NO_SCOUTS}
        #                            recruitment_ignore_bad_movement=yes
        #                            recruitment_pattern=scout,fighter,fighter,archer
        #                        [/ai]
        #                        [ai]
        #                            time_of_day=dusk,first_watch,second_watch
        #                            aggression=0.75
        #                            caution=0.0
        #                            attack_depth=1
        #                            grouping=no
        #                        [/ai]
        #                    [/modify_side]
        #                [/command]
        #            [/option]
        #        [/message]
    [/event]

    ### AI_CONTROLLER ID PLAYER_SIDE ALLY_SIDES VARIABLES
    {AI_CONTROLLER () 1 2,3 ()}

    [event]
        name=olurf

        {FOREACH olurf_party dwarf}
            {VARIABLE olurf_party[$dwarf].side 1}

            [if]
                [variable]
                    name=olurf_party[$dwarf].id
                    equals="Olurf"
                [/variable]
                [then]
                    {VARIABLE olurf_party[$dwarf].canrecruit no}
                [/then]
            [/if]

            [unstore_unit]
                variable=olurf_party[$dwarf]
                find_vacant=yes
                x=42
                y=2
            [/unstore_unit]
            {NEXT dwarf}
        {CLEAR_VARIABLE olurf_party}
  
        {MAKE_HERO Olurf}

        #wmllint: recognize Olurf
        {OLURF_PARTY}
        {OLURF_SPEAK}
    [/event]

    [event]
        name=turn 14
        [fire_event]
            name=olurf
        [/fire_event]
    [/event]

    [event]
        name=time over
        [message]
            id=Kalenz
            message= _ "We still haven't defeated the orcs, and our troops and supplies are exhausted. This is the end!"
        [/message]
    [/event]

    [event]
        name=victory
        [message]
            id=Galtrid
            message= _ "At last! The orcs are defeated."
        [/message]

        [move_unit_fake]
            type=Orcish Warrior
            x=1,1,1
            y=43,42,41
        [/move_unit_fake]
        [unit]
            type=Orcish Warrior
            id=Pirorr
            name=_ "Pirorr"
            side=7
            x=1
            y=41
            facing=sw
        [/unit]

        [message]
            id=Pirorr
            message= _ "The elves have beaten us and they did not use da stone. Maybe they don't have it? Great Chief will not like bad news!"
        [/message]
        [kill]
            id=Pirorr
        [/kill]

        [message]
            id=Galtrid
            message= _ "Kalenz, we are again in your debt. You returned just in time."
        [/message]

        [message]
            id=Kalenz
            message= _ "And we have what's left of the elvish treasury with us!"
        [/message]

        # This is explained in the next (story-only) scenario
        [modify_side]
            side=1
            gold=287
        [/modify_side]

        [if]
            [not]
                [have_unit]
                    id=Olurf
                [/have_unit]
            [/not]
            [then]
                [fire_event]
                    name=olurf
                [/fire_event]
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        [filter]
            id=Truugl
        [/filter]
        [message]
            id=unit
            message= _ "Aargh! I should have stayed in the mountains instead of joining the orcs!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Mordrum
        [/filter]
        [message]
            id=Kalenz
            message= _ "Orcs, death is all you will find in this forest!"
        [/message]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Grubr
        [/filter]
        [message]
            speaker=unit
            message= _ "I die without getting da stone?"
        [/message]
    [/event]

    {@campaigns/Legend_of_Wesmere/utils/deaths.cfg}
[/scenario]
