#textdomain wesnoth-low

#TODO Add the ogre cage idea.
#TODO give a reward for saving some of the Kalian gold.
#TODO add the water sound effects.
#TODO try to tune the troll ai to not start a suicide run against the wood border.

{./07_Elves_Last_Stand_utils.cfg}

[scenario]
    random_start_time=no
    allow_new_game=no
    force_lock_settings=yes

    id=07_Elves_Last_Stand

    experience_modifier=100
    next_scenario=08_Council_of_Hard_Choices
    name= _ "Elves’ Last Stand"

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

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

    {DEFAULT_SCHEDULE_AFTERNOON}

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

    ### /Map Setup ###

#define PLAYER_GOLD
    {GOLD 600 500 400}
    income=-2
#enddef
#define MULTIPLAYER_GOLD
    {GOLD 200 166 133}
    income=-2
#enddef

    #### Kalenz ###
    [side]
        side=1
        {PLAYABLE}
        fog=no
        shroud=no
        no_leader=yes
        controller=human
        save_id=Kalenz

        [unit]
            {KALENZ}
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            x=46
            y=21
        [/unit]

#ifndef MULTIPLAYER
        {PLAYER_GOLD}
        [unit]
            {LANDAR}
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            x=45
            y=35
        [/unit]
        [unit]
            {CLEODIL}
            extra_recruit=Elvish Shaman, Elvish Scout, Wose
            x=47
            y=28
        [/unit]
#else
        {MULTIPLAYER_GOLD}
#endif
    [/side]

    #TODO enable the extended recruit list and give a hint to the player about it
    #        [event]
    #            name=prestart
    #            [allow_recruit]
    #                side=1
    #                type={ELVES}
    #            [/allow_recruit]
    #        [/event]

    [event]
        name=prestart
        # the usual suspects
        {RECALL_LOYALS}
    [/event]

    [side]
        side=2
        no_leader=yes
#ifdef MULTIPLAYER
        {PLAYABLE}
        save_id=Landar
        fog=no
        shroud=no
        {MULTIPLAYER_GOLD}

        [unit]
            {LANDAR}
            type=Elvish Ranger
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            x=45
            y=35
        [/unit]
#else
        hidden=yes
        allow_player=no
        controller=null
#endif
    [/side]

    [side]
        side=3
        no_leader=yes
#ifdef MULTIPLAYER
        {PLAYABLE}
        save_id=Cleodil
        allow_player=yes
        fog=no
        shroud=no
        {MULTIPLAYER_GOLD}

        [unit]
            {CLEODIL}
            type=Elvish Shyde
            extra_recruit=Elvish Shaman, Wose, Elvish Scout
            x=47
            y=28
        [/unit]
#else
        hidden=yes
        controller=null
        allow_player=no
#endif
    [/side]

    ### Allies ####
    [side]
        side=4
        {PLAYABLE}
        no_leader=yes
        allow_player=yes
        save_id=Galtrid
        persistent=yes
#ifndef MULTIPLAYER
        {GOLD 400 300 200}
        controller=human
#else
        {GOLD 133 100 65}
        controller=1
#endif

        [unit]
            # wmllint: recognize Galtrid
            {GALTRID}
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            x=33
            y=32
        [/unit]

#ifndef MULTIPLAYER
        [unit]
            # wmllint: recognize El_Isomithir
            {EL_ISOMITHIR}
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            x=29
            y=32
        [/unit]
        [unit]
            # wmllint: recognize Eradion
            {ERADION}
            extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
            x=7
            y=36
        [/unit]

#endif
    [/side]

    [side]
        side=5
#ifdef MULTIPLAYER
        {PLAYABLE}
        controller=2
        {EL_ISOMITHIR}
        save_id=El_Isomithir
        extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
        x=29
        y=32
        {GOLD 400 300 200}
#else
        hidden=yes
        controller=null
        no_leader=yes
#endif
    [/side]

    [side]
        side=6
#ifdef MULTIPLAYER
        {PLAYABLE}
        {ERADION}
        extra_recruit=Elvish Fighter, Elvish Archer, Elvish Scout
        x=7
        y=36
        {GOLD 400 300 200}
        controller=3
#else
        no_leader=yes
        hidden=yes
        controller=null
#endif
    [/side]

    [event]
        name=prestart
        [allow_recruit]
            side=2
            type=Elvish Fighter, Elvish Archer, Elvish Scout
        [/allow_recruit]
    [/event]

#ifndef MULTIPLAYER
    {STARTING_VILLAGES_ALL 4}
#endif
    ### /ALLIES ###

    ### ENEMIES ###
    [side]
        side=7
        no_leader=yes

        allow_player=no
        controller=ai
        team_name=orcs
        user_team_name= _ "Enemies"
        {ORC_SETUP}
        faction=Custom

        {GOLD 1200 1720 2260}
        {INCOME 50 80 120}

        [unit]
            type=Naga Myrmidon
            id=Mordrum
            name= _ "Mordrum"
            canrecruit=yes
            x=6
            y=4
#ifdef HARD
            extra_recruit=Naga Fighter, Naga Warrior, Naga Myrmidon, Water Serpent
#endif
#ifdef NORMAL
            extra_recruit=Naga Fighter, Naga Warrior, Naga Myrmidon, Water Serpent
#endif
#ifdef EASY
            extra_recruit=Naga Fighter, Naga Warrior
#endif
        [/unit]

        [unit]
            type=Orcish Warlord
            id=Urug-Pir
            name=_ "Urug-Pir"
            profile=portraits/orcs/transparent/grunt-2.png
            canrecruit=yes
            x=6
            y=23
#ifdef HARD
            extra_recruit=Orcish Archer, Orcish Crossbowman, Orcish Slurbow, Orcish Assassin, Orcish Slayer, Orcish Grunt, Orcish Warrior, Orcish Warlord, Goblin Spearman, Goblin Impaler, Goblin Rouser, Wolf Rider, Goblin Knight, Goblin Pillager, Direwolf Rider
#endif
#ifdef NORMAL
            extra_recruit=Orcish Archer, Orcish Crossbowman, Orcish Assassin, Orcish Slayer, Orcish Grunt, Orcish Warrior, Goblin Spearman, Goblin Impaler, Goblin Rouser, Wolf Rider, Goblin Knight, Goblin Pillager, Direwolf Rider
#endif
#ifdef EASY
            extra_recruit=Orcish Archer, Orcish Crossbowman, Orcish Assassin, Orcish Grunt, Orcish Warrior, Goblin Spearman, Wolf Rider, Goblin Knight, Goblin Pillager
#endif

            {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]
        [/unit]

        [unit]
            type=Great Troll
            id=Truugl
            name= _ "Truugl"
            canrecruit=yes
            x=26
            y=7
#ifdef EASY
            extra_recruit=Troll Whelp
#endif
#ifdef NORMAL
            extra_recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman
#endif
#ifdef HARD
            extra_recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Shaman, Troll Warrior, Troll Hero
#endif

            {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]
        [/unit]
    [/side]

    ### /ENEMIES ####

    #### Objectives and corresponding events ####
#define OBJECTIVES
    side=0
    [objective]
        #TODO reconsider the formulation
        #TODO format?
        description= _ "You must own the field and be capable of overwhelming your opponents. (Player(s) own more than 25 units while the foes’ numbers fell below 15)"
        condition=win
    [/objective]
    [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]

    {TURNS_RUN_OUT}

    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]

    #Let the orcs flee if their numbers go low and the elves go high
    [event]
        name=side 7 turn
        first_time_only=no

        [filter_condition]
            [variable]
                name=turn_number
                greater_than=1
            [/variable]
        [/filter_condition]

        [if]
            [have_unit]
                side=7
                count=1-15
            [/have_unit]
            [have_unit]
                side=1,2,3,4
                count=25-999
            [/have_unit]
            [then]
                [message]
                    canrecruit=yes
                    [and]
                        race=orc
                        [or]
                            race=troll
                        [/or]
                    [/and]
                    message= _ "Flee! They have broken us!"
                [/message]
                [message]
                    id=Landar
                    message= _ "Hunt them down and kill every single one of them!"
                [/message]
                [message]
                    id=Cleodil
                    message= _ "It is not wise to put a wounded foe in a desperate situation; they will but fight harder for it. Break their will and let them flee, so they will spread fear of us among their kind."
                [/message]
                [message]
                    id=Galtrid
                    message= _ "She is right. Don’t let them lure you away from the Ka’lian, preparations for when more of them arrive return must be made."
                [/message]
                [fire_event]
                    name=enemies defeated
                [/fire_event]
            [/then]
        [/if]
    [/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=Landar
            # wmllint: local spelling Elvenkind
            message= _ "Galtrid, speak not of defeat. Elvenkind shall rise! Our enemies shall perish in blood and fire!"
        [/message]
        [message]
            id=Cleodil
            message= _ "It is a dark day indeed when elves must steel themselves with dreams of slaughter."
        [/message]
        [message]
            id=Urug-Pir
            # wmllint: local spelling da
            message= _ "We’ll crush those weak elves and I’ll get da stone!"
        [/message]
        [message]
            id=El_Isomithir
            message= _ "These are hardened orc and troll veterans. Men, prepare for a long, difficult fight..."
        [/message]
    [/event]
    ### /INTRO ####

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

        [unit]
#ifndef MULTIPLAYER
            side=1
#else
            side=8
#endif
            {OLURF}
            canrecruit=yes
            x=$olurf_entry.x
            y=$olurf_entry.y
        [/unit]

#ifndef MULTIPLAYER
        {OLURF_PARTY 1}
#else
        {OLURF_PARTY 8}
#endif

        ####ifndef MULTIPLAYER
        ####        {MODIFY_UNIT (side=8) side 1}
        ####        {TRANSFER_VILLAGE_OWNERSHIP 8 1}
        ######endif
        {OLURF_SPEAK}
    [/event]

    [event]
        name=victory
        {VARIABLE olurf_entry.x 40}
        {VARIABLE olurf_entry.y 5}
        [fire_event]
            name=olurf
        [/fire_event]
    [/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]
        [message]
            id=Landar
            message= _ "Perhaps the gold will our word weight with the council."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            side_for=1
            message= _ "Kalenz" + _ " has left the recovered gold into the elvish treasury. You will start the next scenario with a preset amount."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            side_for=9
            message= _ "Landar" + _ " has left the recovered gold into the elvish treasury. You will start the next scenario with a preset amount."
        [/message]
    [/event]

    ###DEATH EVENTS###
    [event]
        name=last breath
        [filter]
            id=Truugl
        [/filter]
        [message]
            id=Truugl
            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=Urug-Pir
        [/filter]
        [message]
            speaker=unit
            message= _ "I die without getting da stone?"
        [/message]
    [/event]

    #Eradion death is split in two events.
    #The first part is spoken after deadly wounded but still speaking
    [event]
        name=last breath
        [filter]
            id="Eradion"
        [/filter]
        {INCIDENTAL_MUSIC sad.ogg}
        [message]
            speaker=second_unit
            message= _ "Be grateful, tree-shagger, for I have spared you the pain of seeing your precious citadel burned and razed."
        [/message]
        [message]
            speaker=unit
            message= _ "Galtrid, my friend. Do not let my death be in vain. Destroy these foul orcs, and sing for me in the green woods when we have won."
        [/message]
        [message]
            id=Galtrid
            message= _ "We shall avenge you tenfold!"
        [/message]
        [scroll_to_unit]
            id="Eradion"
        [/scroll_to_unit]
    [/event]
    [event]
        name=die
        [filter]
            id="Eradion"
        [/filter]
        [message]
            speaker=second_unit
            message= _ "Dead he is. Too quick. His screams were sweet."
        [/message]
        [message]
            side=4,5,6
            [not]
                id=Galtrid
            [/not]
            [not]
                id="Eradion"
            [/not]
            message= _ "Let us pursue the orc who murdered $unit.name|!"
        [/message]
        [message]
            id=Galtrid
            message= _ "No, don’t leave your formation. An elf was slain by beast. What does it matter which beast it was? We must kill them all."
        [/message]
    [/event]

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

#undef PLAYER_GOLD
#undef MULTIPLAYER_GOLD
