#textdomain wesnoth-low

#TODO shorten the scenario by ledding the orcs flee if their number is low.
#TODO give the player a reward for saving el'isomithir
#TODO Add the oger cage idea.
#TODO give a reward for saving some of the Kalian gold.
#TODO make Cleodil say something
#TODO remove the village that was destroyed in scenario 3.
#TODO add the water sound effects.

{./07_Elves_last_stand_utils.cfg}

#ifdef MULTIPLAYER
[multiplayer]
    random_start_time=no
#ifndef DEBUG_MODE
    allow_new_game=no
#endif
#else
[scenario]    
#endif

    id=07_Elves_last_stand
    name= _ "Elves' Last Stand"
    next_scenario=08_Council_of_hard_choices

    ### Story ###
    [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]
            show_title=yes
            delay=4000
            {TO_ELVES_LAST_STAND}
        [/part]
    [/story]
    ### /Story ###

    ### Music playlist ###
    {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}
    {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}
    ### /Music playlist ###

    ### Map setup ###
    {TURNS 35 30 25}

    {DEFAULT_SCHEDULE}

    {LOW_MAP  Kalian.map}
    {LOW_MASK 07_Elves_last_stand.mask 1 1}
    {campaigns/Legend_of_Wesmere/maps/Kalian_map.cfg}

    {LOW_PRESTART}

    ### /Map Setup ###

#define PLAYER_GOLD
    {GOLD 600 500 400}
#enddef

    #### Kalenz ###
    #wmllint: validate-off
    [side]
        {KALENZ}
        {PLAYER_GOLD}
        fog=no
        # wmllint: recognize Kalenz
        x=42
        y=10
        team_name=player
        user_team_name= _ "Player"
        recruit={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid
#ifndef MULTIPLAYER
        [unit]
            {LANDAR}
            # wmllint: recognize Landar
            placement=leader
        [/unit]
#endif
        [unit]
            {CLEODIL}
            # wmllint: recognize Cleodil
            placement=leader
        [/unit]
    [/side]
    #TODO give a hint to the player about the changed recruit list
    [event]
        name=prestart
        [allow_recruit]
            side=1
            type={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid
        [/allow_recruit]
    [/event]
    [event]
        name=prestart
        # the usual suspects
        {RECALL_LOYALS}
    [/event]

    ### Allies ####
    [side]
        side=2
        allow_player=no
        controller=ai
        team_name=player
        user_team_name= _ "Player"
        recruit={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid, Elvish Lord
        {GALTRID}
        # wmllint: recognize Galtrid
        x=33
        y=26
        {GOLD 250 300 400}

        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT passive_leader_shares_keep yes}
            {AI_SIMPLE_ALWAYS_ASPECT villages_per_scout 20}
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.0}
            {AI_SIMPLE_ALWAYS_ASPECT caution 0.75}
            {AI_SIMPLE_ALWAYS_ASPECT grouping defensive}
        [/ai]
    [/side]
    [event]
        name=prestart
        [allow_recruit]
            side=2
            type={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid, Elvish Lord
        [/allow_recruit]
    [/event]




    #wmllint: validate-on
    {STARTING_VILLAGES_ALL 2}

    [side]
        side=3
        allow_player=no
        controller=ai
        team_name=player
        user_team_name= _ "Player"
        type=Elvish Marshal
        id="El'Isomithir"
        name= _ "El'Isomithir"
        canrecruit=yes
        #TODO Maybe define some fitting traits for him
        generate_traits=yes
        x=13
        y=35
        controller=ai
        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT villages_per_scout 20}
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.0}
            {AI_SIMPLE_ALWAYS_ASPECT caution 0.75}
            {AI_SIMPLE_ALWAYS_ASPECT grouping defensive}
        [/ai]
        {GOLD 280 320 400}
        recruit={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid
    [/side]
    {STARTING_VILLAGES_AREA 3 13 35 15}
    ### /ALLIES ###

    ### ENEMIES ###
    [side]
        side=4
        allow_player=no
        controller=ai
        team_name=orcs
        user_team_name= _ "Enemies"
        {FLAG_VARIANT undead}
        type=Orcish Warlord
        id=Mordrum
        name= _ "Mordrum"
        profile=portraits/orcs/transparent/grunt-2.png
        canrecruit=yes
        x=4
        y=12
        {RECRUIT_ORC}
        {GOLD 550 700 900}
        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_NO_SCOUTS}

            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_movement yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "scout,fighter,fighter,archer,mixed fighter"}
            {AI_SIMPLE_ALWAYS_ASPECT aggression 0.75}
            {AI_SIMPLE_ALWAYS_ASPECT caution 0.0}
            {AI_SIMPLE_ALWAYS_ASPECT attack_depth 5}
            {AI_SIMPLE_ALWAYS_ASPECT grouping offensive}

            {AI_SIMPLE_NIGHT_ASPECT aggression 0.75}
            {AI_SIMPLE_NIGHT_ASPECT caution 0.0}
            {AI_SIMPLE_NIGHT_ASPECT attack_depth 5}
            {AI_SIMPLE_NIGHT_ASPECT grouping offensive}
        [/ai]
        {INCOME 4 8 12}
    [/side]
    [side]
        side=5
        allow_player=no
        controller=ai
        {FLAG_VARIANT undead}
        type=Orcish Warlord
        id=Urug-Pir
        name=_ "Urug-Pir"
        profile=portraits/orcs/transparent/grunt-2.png
        canrecruit=yes
        x=6
        y=21
        {RECRUIT_ORC}
        {GOLD 300 500 730}
        {INCOME 4 8 12}
        team_name=orcs
        user_team_name= _ "Enemies"
        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_NO_SCOUTS}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_movement yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "scout,fighter,fighter,archer,mixed fighter"}
            {AI_SIMPLE_NIGHT_ASPECT aggression 0.75}
            {AI_SIMPLE_NIGHT_ASPECT caution 0.0}
            {AI_SIMPLE_NIGHT_ASPECT grouping no}
            {AI_SIMPLE_NIGHT_ASPECT attack_depth 5}
        [/ai]
    [/side]
    [side]
        side=6
        allow_player=no
        controller=ai
        team_name=orcs
        user_team_name= _ "Enemies"
        {FLAG_VARIANT undead}
        type=Great Troll
        id=Truugl
        name= _ "Truugl"
        canrecruit=yes
        x=26
        y=7
#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/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_NO_SCOUTS}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_movement yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_combat yes}
#ifdef EASY
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter"}
#else
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter, mixed fighter, fighter, mixed fighter, fighter"}
#endif
            {AI_SIMPLE_NIGHT_ASPECT aggression 0.75}
            {AI_SIMPLE_NIGHT_ASPECT caution 0.0}
            {AI_SIMPLE_NIGHT_ASPECT attack_depth 5}
            {AI_SIMPLE_NIGHT_ASPECT grouping offensive}
        [/ai]
    [/side]
    [side]
        side=7
        allow_player=no
        controller=ai
        team_name=orcs
        user_team_name= _ "Enemies"
        {FLAG_VARIANT undead}
        type=Orcish Warlord
        id=Grubr
        name= _ "Grubr"
        profile=portraits/orcs/transparent/grunt-3.png
        canrecruit=yes
        x=25
        y=42
        {RECRUIT_ORC}
        {GOLD 400 550 650}
        {INCOME 4 8 12}
        {ai/aliases/stable_singleplayer.cfg}
        [ai]
            {AI_NO_SCOUTS}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_ignore_bad_movement yes}
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "scout,fighter,fighter,archer,mixed fighter"}
            {AI_SIMPLE_NIGHT_ASPECT aggression 0.75}
            {AI_SIMPLE_NIGHT_ASPECT caution 0.0}
            {AI_SIMPLE_NIGHT_ASPECT attack_depth 5}
            {AI_SIMPLE_NIGHT_ASPECT grouping offensive}
        [/ai]
    [/side]
    ### /ENEMIES ####

    [side]
        side=8
        allow_player=no
        controller=null
        persistent=yes
        save_id=Olurf
        no_leader=yes
        hidden=yes
    [/side]

#ifdef MULTIPLAYER
    [side]
        side=9
        fog=no
        {PLAYER_GOLD}
        {LANDAR}
        recruit={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid
        x=39
        y=10
    [/side]
    [event]
        name=prestart
        [allow_recruit]
            side=9
            type={ELVES}, Elvish Captain, Elvish Hero, Elvish Sorceress, Elvish Marksman, Elvish Ranger, Elvish Druid
        [/allow_recruit]
    [/event]
#endif

    #### Objectives and corresponding events ####
#define OBJECTIVES
    side=0
    [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 Galtrid"
        condition=lose
    [/objective]
    [objective]
        description= _ "Turns run out"
        condition=lose
    [/objective]
    note={NO_GOLD_CARRYOVER_NOTE}
#enddef

    [event]
        name=prestart
        [objectives]
            {OBJECTIVES}
        [/objectives]
    [/event]

    [event]
        name=enemies defeated
        [endlevel]
            save=no
            result=victory
            bonus=no
            carryover_percentage=0
        [/endlevel]
    [/event]

    [event]
        name=time over
        [message]
            id=Kalenz
            message= _ "The orcs are not defeated, and our troops and supplies are exhausted. This is the end!"
        [/message]
    [/event]
    #### /Objectives and corresponding events ####

    #### INTRO ####
    [event]
        name=start

        [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]
        [message]
            id=Kalenz
            message= _ "These are hardened orc and troll veterans. Men, prepare for a long, hard fight..."
        [/message]
    [/event]
    ### INTRO ####

    ### AI_CONTROLLER ###

#ifdef MULTIPLAYER 
    {AI_CONTROLLER (kalenz) 1 2 ()}
    {AI_CONTROLLER (landar) 9 3 ()}
#else
    {AI_CONTROLLER (kalenz) 1 2,3 ()}
#endif
    [event]
        name=start
        [message]
            speaker=narrator
            message= _ "In this scenario, you may change the behavior of an allied side's AI using a context menu brought up by clicking on the allied side's leader."
            image=wesnoth-icon.png
        [/message]

        {AI_CONTROLLER_ALLOW_LEADER_CONTROL 1 2}
#ifdef MULTIPLAYER
        {AI_CONTROLLER_ALLOW_LEADER_CONTROL 9 3}
#else
        {AI_CONTROLLER_ALLOW_LEADER_CONTROL 1 3}
#endif
    [/event]
    [event]
        name=victory
        {AI_CONTROLLER (kalenz) () () ()}
#ifdef MULTIPLAYER
        {AI_CONTROLLER (landar) () () ()}
#endif
        #disable the ai controller
    [/event]

    ### /AI_CONTROLLER ###

    ### OLURF ###
    [event]
        name=olurf

        [unit]
            side=8
            {OLURF}
            #wmllint: recognize Olurf
            x=42
            y=2
        [/unit]

#ifndef MULTIPLAYER
        {MODIFY_UNIT (side=8) side 1}
#endif

        {OLURF_PARTY}
        {OLURF_SPEAK}

        [objectives]
            {OBJECTIVES}
#undef OBJECTIVES
            [objective]
                description= _ "Death of Olurf"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

#ifndef MULTIPLAYER
    [event]
        name=turn 12
        [fire_event]
            name=olurf
        [/fire_event]
    [/event]
#endif

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

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

        [unit]
            type=Orcish Warrior
            id=Pirorr
            name= _ "Pirorr"
            side=7
            x=1
            y=43
            facing=ne
            profile=portraits/orcs/transparent/grunt-2.png
        [/unit]
        {MOVE_UNIT id=Pirorr 1 41}

        [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
            animate=no
        [/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]
    [/event]

    ###DEATH EVENTS###
    [event]
        name=last breath
        [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}
    ###/DEATH EVENTS###

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

#undef PLAYER_GOLD
