#textdomain wesnoth-low
[scenario]
    name= _ "Northern Battle"
    id=22_Northern_Battle
    next_scenario=23_End_of_War
    experience_modifier=100

    random_start_time=no
    allow_new_game=no

    {LOW_MAP  North_Elves.map}
    {LOW_MASK 22_Northern_Battle.mask 1 1}

    {NORTH_ELVES_VILLAGES}

    {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
            {LOW_BIGMAP}
            {CIVILWAR_STAGE2}
        [/part]
    [/story]

    [side]
        side=1

        {PLAYABLE}
        save_id=Kalenz
        disallow_shuffle=yes
        {GOLD 250 225 200}

        {KALENZ}
        x=46
        y=39

#ifndef MULTIPLAYER
        [unit]
            {CLEODIL}
            #TODO place on her keep
            placement=leader
        [/unit]
#endif
    [/side]

    [event]
        name=prestart

        # modify 2/3 of the non-loyal, non-shaman-line units to join Landar
        # TODO: This this still needed in mp?
        {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]
            array=steal_wearer
            [do]
                {RANDOM (2,1,2)}
                [if]
                    [variable]
                        name=random
                        numerical_equals=1
                    [/variable]
                    [then]
                        {VARIABLE this_item.side 2}
                        {VARIABLE this_item.role kalenz_loyal}
                        [unstore_unit]
                            variable=this_item
                            x,y=recall,recall
                        [/unstore_unit]
                    [/then]
                    [else]
                        {VARIABLE this_item.side 3}
                        {VARIABLE this_item.role landar_loyal}
                        [unstore_unit]
                            variable=this_item
                            x,y=recall,recall
                        [/unstore_unit]
                    [/else]
                [/if]
            [/do]
        [/foreach]
        {CLEAR_VARIABLE steal_wearer}

        # recall our loyals
        {RECALL_LOYALS}

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

    # wmllint: recognize Uradredia
    [event]
        name=scenario_end
        [filter_condition]
            [proceed_to_next_scenario]
            [/proceed_to_next_scenario]
        [/filter_condition]
        {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]
        side=2

        no_leader=yes
        [unit]
            {URADREDIA}
            x=24
            y=7
        [/unit]

        persistent=yes
        save_id=Uradredia

        allow_player=no
        {PLAYER_TEAM}
        recruit=Elvish Fighter, Elvish Archer, Elvish Shaman, Elvish Hero, Elvish Marksman, Elvish Ranger, Elvish Druid, Elvish Sorceress
        [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
        {GOLD 400 500 600}
#else
        {GOLD 250 275 300}
        {PLAYABLE}
#endif
        no_leader=yes
        team_name=landar
        persistent=yes
        save_id=Landar
        disallow_shuffle=yes
        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
        [ai]
            passive_leader=yes
            {NO_SCOUTS}
#ifndef HARD
            recruitment_pattern=archer, fighter
#else
            recruitment_pattern=archer, fighter, mixed fighter
#endif
        [/ai]
        {INCOME 4 8 12}
    [/side]

    [event]
        name=prestart
        # TODO: shouldn't Landar already be able to recuit?
        {MODIFY_UNIT id=Landar canrecruit yes}
    [/event]

    [side]
        side=4
        allow_player=no
        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}
#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]
#ifndef MULTIPLAYER
            [objective]
                description= _ "Death of Cleodil"
                condition=lose
            [/objective]
#endif
            [objective]
                description= _ "Death of Uradredia"
                condition=lose
            [/objective]

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

        [objectives]
            side=3
            [objective]
                description= _ "Death of Kalenz"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Landar"
                condition=lose
            [/objective]
            [objective]
                description= _ "Kalenz survives for six days"
                condition=lose
                show_turn_counter=yes
            [/objective]

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

            [note]
                description= _ "If you lose you still have a chance to defeat Kalenz in the next scenario."
            [/note]
        [/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
            [result]
                side = 3
                result = "defeat"
                {NEW_GOLD_CARRYOVER 40}
            [/result]
            {NEW_GOLD_CARRYOVER 40}
        [/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
            [result]
                side = 3
                result = "defeat"
                {NEW_GOLD_CARRYOVER 40}
            [/result]
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

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