#textdomain wesnoth-low
#ifdef MULTIPLAYER
[multiplayer]
    random_start_time=no
#ifndef DEBUG_MODE
    allow_new_game=no
#endif
#else
    [scenario]
#endif

        name= _ "Northern Battle"
        id=22_Northern_Battle
        next_scenario=23_End_of_War
        experience_modifier=100

        {LOW_MAP  North_Elves.map}
        {LOW_MASK 22_Northern_Battle.mask 1 1}
        {campaigns/Legend_of_Wesmere/scenarios/North_elves_utils.cfg}

        ############## {../North_elves_utils.cfg} ###############

        {TURNS 40 36 32}
        {DEFAULT_SCHEDULE}

        {INTRO_AND_SCENARIO_MUSIC elf-land.ogg breaking_the_chains.ogg}
        {EXTRA_SCENARIO_MUSIC legends_of_the_north.ogg}
        {EXTRA_SCENARIO_MUSIC elvish-theme.ogg}
        {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}
        {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}
        {EXTRA_SCENARIO_MUSIC silvan_sanctuary.ogg}
        {EXTRA_SCENARIO_MUSIC weight_of_revenge.ogg}
        {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}

        [story]
            [part]
                story= _ "It was clear to Kalenz and Cleodil that there would be no sanctuary for them while Landar lived. But during their years in seclusion the fame of their deeds had only grown. Many healers and sorceresses responded to Cleodil’s call, and Kalenz found that recruits came to him as readily as if he were still High Lord in name."
            [/part]
            [part]
                story= _ "Kalenz’s veterans joined the host of the Northern Elves under Uradredia. Very soon, Landar’s army appeared..."
                delay=4000
                {TO_NORTHERN_BATTLE}
            [/part]
        [/story]

        [side]
            {KALENZ}
            {PLAYABLE}
            # wmllint: recognize Kalenz
            team_name=player
            user_team_name= _ "Player"
            controller=human
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            {GOLD 100 100 100}
            x=46
            y=39
#ifndef MULTIPLAYER
            [unit]
                {CLEODIL}
                extra_recruit=Elvish Shaman, Elvish Scout, Wose
                #TODO place on her keep
                placement=leader
                #wmllint: recognize Cleodil
            [/unit]
#endif
        [/side]

        [event]
            name=prestart

            # modify 2/3 of the non-loyal, non-shaman-line units to join Landar
            {MODIFY_UNIT (id=Landar) side 3}
            [store_unit]
                #TODO spellcheck
                variable=steal_wearer
                kill=yes
                [filter]
                    side=1
                    x,y=recall,recall
                    [not]
                        id=Kalenz
                    [/not]
                    [not]
                        # wmllint: recognize Anduilas
                        id=Anduilas
                    [/not]
                    [not]
                        {FILTER_LOYALS}
                    [/not]
                    [not]
                        type={ELVES_NON_STEEL}
                    [/not]
                [/filter]
            [/store_unit]
            {FOREACH steal_wearer u}
                {RANDOM (2,1,2)}
                [if]
                    [variable]
                        name=random
                        numerical_equals=1
                    [/variable]
                    [then]
                        {VARIABLE steal_wearer[$u].side 2}
                        {VARIABLE steal_wearer[$u].role kalenz_loyal}
                        [unstore_unit]
                            variable=steal_wearer[$u]
                            x,y=recall,recall
                        [/unstore_unit]
                    [/then]
                    [else]
                        {VARIABLE steal_wearer[$u].side 3}
                        {VARIABLE steal_wearer[$u].role landar_loyal}
                        [unstore_unit]
                            variable=steal_wearer[$u]
                            x,y=recall,recall
                        [/unstore_unit]
                    [/else]
                [/if]
            {NEXT u}
            {CLEAR_VARIABLE steal_wearer}

            # recall our loyals
            {RECALL_LOYALS}

            [recall]
                id=Landar
                x=15
                y=38
            [/recall]
        [/event]

        # wmllint: recognize Uradredia
        [event]
            name=victory
            {MODIFY_UNIT (side=2
            [not]
                id=Uradredia
            [/not]) side 1}
            {AI_CONTROLLER (kalenz) () () ()}
        [/event]

        [event]
            name=start
            [message]
                speaker=narrator
                message= _ "Kalenz can only recall shamans and their advancements from his former army; the rest of his men joined Uradredia before he arrived."
                image=wesnoth-icon.png
            [/message]
        [/event]

        [side]
            {URADREDIA}
            #wmllint: recognize Uradredia
            persistent=yes
            save_id=Uradredia
            side=2
            team_name=player
            user_team_name= _ "Player"
            recruit=Elvish Fighter, Elvish Archer, Elvish Shaman, Elvish Hero, Elvish Marksman, Elvish Ranger, Elvish Druid, Elvish Sorceress
            x=24
            y=7
            {ai/aliases/stable_singleplayer.cfg}
            [ai]
                {AI_SIMPLE_ALWAYS_ASPECT passive_leader_shares_keep yes}
                {AI_SIMPLE_ALWAYS_ASPECT villages_per_scout 0}
                {AI_SIMPLE_ALWAYS_ASPECT aggression 0.0}
                {AI_SIMPLE_ALWAYS_ASPECT caution 0.75}
                {AI_SIMPLE_ALWAYS_ASPECT grouping defensive}
            [/ai]
        [/side]

        {AI_CONTROLLER (kalenz) 1 2 ()}
        [event]
            name=start
            {AI_CONTROLLER_ALLOW_LEADER_CONTROL 1 2}
        [/event]

        [side]
            side=3
#ifndef MULTIPLAYER
            controller=ai
            allow_player=no
#else
            {PLAYABLE}
#endif
            no_leader=yes
            team_name=landar
            persistent=yes
            save_id=Landar
            user_team_name= _ "Enemies"
#ifdef EASY
            recruit=Elvish Archer, Elvish Fighter
#endif
#ifdef NORMAL
            recruit=Elvish Archer, Elvish Fighter, Elvish Hero
#endif
#ifdef HARD
            recruit=Elvish Archer, Elvish Fighter, Elvish Hero, Elvish Ranger
#endif
            {GOLD 400 600 750}
            [ai]
                passive_leader=yes
                {NO_SCOUTS}
                recruitment_ignore_bad_movement=yes
#ifndef HARD
                recruitment_pattern=archer, fighter
#else
                recruitment_pattern=archer, fighter, mixed fighter
#endif
            [/ai]
            {INCOME 4 8 12}
        [/side]

        [event]
            name=prestart
            {MODIFY_UNIT id=Landar canrecruit yes}
        [/event]

        [side]
            side=4
            persistent=yes
            save_id=Crintil
            team_name=landar
            user_team_name= _ "Enemies"
            type=Elvish Marshal
            id=Crintil
            name=_ "Crintil"
            canrecruit=yes
            x=41
            y=29
#ifdef EASY
            recruit=Elvish Archer, Elvish Fighter
#endif
#ifdef NORMAL
            recruit=Elvish Archer, Elvish Fighter, Elvish Hero
#endif
#ifdef HARD
            recruit=Elvish Archer, Elvish Fighter, Elvish Hero, Elvish Ranger
#endif

            {GOLD 180 220 260}
            [ai]
                {NO_SCOUTS}
                recruitment_ignore_bad_movement=yes
#ifndef HARD
                recruitment_pattern=archer, fighter
#else
                recruitment_pattern=archer, fighter, mixed fighter
#endif
            [/ai]
        [/side]
        [event]
            name=prestart
            [allow_recruit]
                side=4
#ifdef EASY
                type=Elvish Archer, Elvish Fighter
#endif
#ifdef NORMAL
                type=Elvish Archer, Elvish Fighter, Elvish Hero
#endif
#ifdef HARD
                type=Elvish Archer, Elvish Fighter, Elvish Hero, Elvish Ranger
#endif
            [/allow_recruit]
        [/event]

        [event]
            name=prestart

            [objectives]
                side=1
                [objective]
                    description= _ "Defeat all enemy leaders"
                    condition=win
                [/objective]
                [objective]
                    description= _ "Survive for six days"
                    condition=win
                    show_turn_counter=yes
                [/objective]
                [objective]
                    description= _ "Death of Kalenz"
                    condition=lose
                [/objective]
                [objective]
                    description= _ "Death of Cleodil"
                    condition=lose
                [/objective]
                [objective]
                    description= _ "Death of Uradredia"
                    condition=lose
                [/objective]

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

        [event]
            name=start
            [message]
                id=Kalenz
                message= _ "Landar, listen to me! It does not have to come to this. I know about the potion. Let us help!"
            [/message]
            [message]
                id=Landar
                message= _ "Here is Kalenz. There can be no talk with traitors! Leave none of them alive!"
            [/message]
        [/event]

        [event]
            name=moveto

            [filter]
                side=1,2
                [filter_adjacent]
                    id=Landar
                [/filter_adjacent]
            [/filter]

            [message]
                id=Landar
                message= _ "Things are not going well! Retreat! We will meet again, traitors!"
            [/message]
            [endlevel]
                result=victory
            [/endlevel]
        [/event]

        [event]
            name=time over

            [message]
                id=Landar
                message= _ "We have yet to break their defenses! While we are getting weaker, the enemy is getting stronger! Retreat!"
            [/message]
            [message]
                id=Kalenz
                message= _ "We won!"
            [/message]

            [endlevel]
                result=victory
            [/endlevel]
        [/event]

        {campaigns/Legend_of_Wesmere/utils/deaths.cfg}

#ifndef MULTIPLAYER
    [/scenario]
#else
[/multiplayer]
#endif
