#textdomain wesnoth-low
[scenario]
    name= _ "Human Alliance"
    id=14_Human_Alliance

    random_start_time=no
    allow_new_game=no
    force_lock_settings=yes

    experience_modifier=100
    next_scenario=15_The_Treaty

    {LOW_MAP 14_Human_Alliance.map}

    #out of turns leads to victory
    {TURNS 18 20 22}
    victory_when_enemies_defeated=no

    {DEFAULT_SCHEDULE_AFTERNOON}

    #     #TODO split the villages instead of leaving them unassigned in MP?
#ifndef MULTIPLAYER
    {STARTING_VILLAGES_ELF   1}
#endif
    {STARTING_VILLAGES_HUMAN 2}
    {STARTING_VILLAGES_TROLL 3}

    {INTRO_AND_SCENARIO_MUSIC revelation.ogg loyalists.ogg}
    {EXTRA_SCENARIO_MUSIC the_city_falls.ogg}
    {EXTRA_SCENARIO_MUSIC knolls.ogg}
    {EXTRA_SCENARIO_MUSIC heroes_rite.ogg}
    {EXTRA_SCENARIO_MUSIC breaking_the_chains.ogg}
    {EXTRA_SCENARIO_MUSIC northerners.ogg}
    {EXTRA_SCENARIO_MUSIC siege_of_laurelmor.ogg}
    {EXTRA_SCENARIO_MUSIC elvish-theme.ogg}
    {EXTRA_SCENARIO_MUSIC casualties_of_war.ogg}

    [story]
#ifdef MULTIPLAYER
        [part]
            delay=4000
            title= _ "<i>The Legend of Wesmere</i>
Chapter Four"
        [/part]
#endif
        [part]
            title= _ "Chapter Four
<i>The Alliance</i>"
            #delay=4000
            #show_title=yes
        [/part]
        [part]
            story= _ "With the human-elf alliance revived, our heroes hurried to the battlefield..."
            delay=4000
            {LOW_BIGMAP}
            {TREASURY_COMPLETE}
            {BOOK_COMPLETE}
            {ALLIANCE_STAGE2}
        [/part]
    [/story]

#define PLAYER_GOLD
    {GOLD 550 470 400}
#enddef
#define MULTIPLAYER_GOLD
    {GOLD 160 140 120}
#enddef

    [side]
        side=1
        {PLAYABLE}
        save_id=Kalenz
        disallow_shuffle=yes

        {KALENZ}
        # wmllint: recognize Kalenz
        x=25
        y=11

#ifndef MULTIPLAYER
        {PLAYER_GOLD}
        [unit]
            {LANDAR}
            x=25
            y=13
        [/unit]
        [unit]
            {CLEODIL}
            x=27
            y=12
        [/unit]
        [unit]
            {OLURF}
            x=36
            y=10
        [/unit]
#else
        {MULTIPLAYER_GOLD}
#endif
    [/side]
    [event]
        name=prestart
        {RECALL_LOYALS}
    [/event]

    [side]
        side=2
        no_leader=yes
        {PLAYABLE}
        [unit]
            id=Aldar
            type=General
            name= _ "Aldar"
            profile="portraits/aldar.png"
            x=42
            y=27
            canrecruit=yes
            extra_recruit=Fencer, Heavy Infantryman,Dragoon,Longbowman,Duelist,Halberdier,Horseman,Cavalier,Cavalryman, Royal Guard, Mage, Swordsman, Bowman, White Mage, Red Mage, Spearman
        [/unit]
        disallow_shuffle=yes

#ifdef MULTIPLAYER
        {MULTIPLAYER_GOLD}
#else
        {PLAYER_GOLD}
#endif

        {LOYALIST_SETUP}
        {FLAG_VARIANT loyalist}
    [/side]

    [side]
        side=3
        allow_player=no
        team_name=orcs
        user_team_name= _ "Enemies"
        no_leader=yes
        {INCOME 220 280 360}
        {GOLD   520 630 800}

        [ai]
            {NO_SCOUTS}
            recruitment_pattern=scout,fighter,fighter,archer,mixed fighter
            {ATTACK_DEPTH 4 5 6}
        [/ai]
        [ai]
            time_of_day=dusk,first_watch,second_watch
            aggression=0.75
            caution=0.0
            grouping=no
        [/ai]

        [unit]
            type=Orcish Warlord
            id=Pirror
            name=_ "Pirror"
            canrecruit=yes
            x=10
            y=2
#ifdef EASY
            extra_recruit=Orcish Grunt, Orcish Assassin, Orcish Crossbowman, Goblin Pillager, Goblin Knight
#endif

#ifdef NORMAL
            extra_recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Orcish Slayer, Orcish Warrior, Goblin Spearman
#endif

#ifdef HARD
            extra_recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Knight, Goblin Pillager, Orcish Slayer, Goblin Spearman, Goblin Impaler, Goblin Rouser, Direwolf Rider
#endif
        [/unit]

        [unit]
            type=Orcish Warlord
            id=Tan-Grub
            name=_ "Tan-Grub"
            profile="portraits/orcs/warlord.png"
            canrecruit=yes
            x=10
            y=33
#ifdef EASY
            extra_recruit=Orcish Grunt, Orcish Assassin, Orcish Crossbowman, Goblin Pillager, Goblin Knight
#endif

#ifdef NORMAL
            extra_recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Goblin Pillager, Goblin Knight, Orcish Slayer, Orcish Warrior, Goblin Spearman
#endif

#ifdef HARD
            extra_recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Wolf Rider, Orcish Crossbowman, Orcish Warrior, Goblin Knight, Goblin Pillager, Orcish Slayer, Goblin Spearman, Goblin Impaler, Goblin Rouser, Direwolf Rider
#endif
        [/unit]

        [unit]
            x=46
            y=5
            type=Great Troll
            id=Grol
            name=_ "Grol"
            canrecruit=yes
            #TODO think about adding troll shamans
#ifdef EASY
            extra_recruit=Troll Whelp, Troll
#endif
#ifdef NORMAL
            extra_recruit=Troll Whelp, Troll, Troll Rocklobber
#endif
#ifdef HARD
            extra_recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Warrior
#endif
        [/unit]
    [/side]

    [side]
        side=4
        no_leader=yes
        {PLAYABLE}
        save_id=Galtrid
        disallow_shuffle=yes
        previous_save_id=Kalenz
#ifdef MULTIPLAYER
        {MULTIPLAYER_GOLD}
#else
        {PLAYER_GOLD}
#endif

        [unit]
            # wmllint: recognize Galtrid
            {GALTRID}
            x=15
            y=12
        [/unit]

#ifndef MULTIPLAYER
        [unit]
            # wmllint: recognize El_Isomithir
            {EL_ISOMITHIR}
            x=13
            y=15
        [/unit]

        [unit]
            # wmllint: recognize Eradion
            {ERADION}
            x=15
            y=15
        [/unit]
#endif
    [/side]

    [event]
        name=prestart

        [objectives]
            side=0
            [objective]
                description= _ "Last for the end of turns"
                condition=win
                show_turn_counter=yes
            [/objective]
            [objective]
                description= _ "Death of Kalenz"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Landar"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Olurf"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Cleodil"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Aldar"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Galtrid"
                condition=lose
            [/objective]

            [gold_carryover]
                bonus=no
                carryover_percentage=40
            [/gold_carryover]
        [/objectives]
    [/event]

    [event]
        name=side 1 turn 1
        [message]
            id=Kalenz
            message= _ "Tremble, orcs! The vengeance of the Elves is upon you!!"
        [/message]
        [message]
            id=Aldar
            message= _ "So it is true! The elves have come to our aid!"
        [/message]
        [message]
            id=Olurf
            message= _ "Hey! Do I look like an elf?"
        [/message]
        [message]
            id=Landar
            message= _ "I can scarce believe I am fighting besides these betrayers."
        [/message]
        [message]
            id=Cleodil
            message= _ "We cannot be choosy about our allies when our need is dire."
        [/message]
        [message]
            id=Kalenz
            message= _ "Indeed not. Save your anger for our enemies, Landar."
        [/message]
        [message]
            id=Landar
            message= _ "I shall. But when our need is not so dire, there must be a reckoning..."
        [/message]
        [message]
            id=Tan-Grub
            #canrecruit=yes
            #race=orc
            message= _ "An elven army to the north? And they have dwarves with them? We must defeat them in detail before they combine, which means attacking before our reinforcements arrive. Maybe we can beat the humans before the elves can intervene. Overrun city and castle!"
        [/message]

        [message]
            speaker=narrator
            message= _ "The brazen cry of a war-horn is heard in the distance."
            sound=horn-signals/horn-2.ogg
            image="portraits/goblins/rouser-2.png"
        [/message]

        [unit]
            id=Aldun
            name= _ "Aldun"
            type=Horseman
            random_traits=yes
            side=2
            x=33
            y=24
            facing=sw
        [/unit]
        {MOVE_UNIT id=Aldun 21 16}

        [message]
            id=Aldun
            message= _ "General Aldar has received your message. He asks that you engage the orcish reinforcements from the north, preventing them from joining with their fellows here. Those fresh troops must not be allowed to enter the battle! Our reinforcements should arrive in a few days."
        [/message]
        [message]
            id=Kalenz
            message= _ "Very well... But have you any word of the elvish troops marching to join us? We are too few to defeat the enemy without them."
        [/message]
        [message]
            id=Aldun
            message=_"We have no news from the Ka’lian."
        [/message]

        [message]
            id=Galtrid
            message= _ "Kalenz! We come to fight beside you!"
        [/message]
        [message]
            id=Kalenz
            message= _ "Where is the rest of the elvish army? They were promised and should be here!"
        [/message]
        [message]
            id=Eradion
            message= _ "The Great Council has decided it was too risky to send troops here. But some of us dissented and have come to fight beside you."
        [/message]
        [message]
            id=Landar
            message= _ "That is well! If the Ka’lian is too fearful or blind to see what is needed, we must do it ourselves."
        [/message]
        [message]
            id=Cleodil
            message= _ "It is not well that we have become so divided as this."
        [/message]
        [message]
            id=Kalenz
            message= _ "No, it is not. But if we do not defeat these orcs here and now our divisions will all be moot. I will take every sword-arm I can get and be glad of them."
        [/message]
    [/event]

    {MP_SIDE 5 (
        #Landar's side
        no_leader=yes
        {PLAYABLE}
        save_id=Landar
        disallow_shuffle=yes

        [unit]
            {LANDAR}
            x=27
            y=12
        [/unit]
        {MULTIPLAYER_GOLD}
    )}

    {MP_SIDE 6 (
        #Olurf's side
        no_leader=yes
        save_id=Olurf
        disallow_shuffle=yes

        [unit]
            {OLURF}
            x=36
            y=10
        [/unit]
        {PLAYABLE}

        {MULTIPLAYER_GOLD}
    )}

    {MP_SIDE 7 (
        #Cleodil's side
        {PLAYABLE}
        save_id=Cleodil
        disallow_shuffle=yes
        no_leader=yes
        [unit]
            {CLEODIL}
            x=25
            y=13
        [/unit]

        {MULTIPLAYER_GOLD}
    )}

    {MP_SIDE 8 (
        #El'Isomithir's side
        {PLAYABLE}
        no_leader=yes
        previous_save_id=Landar
        save_id=El_Isomithir
        disallow_shuffle=yes
        [unit]
            {EL_ISOMITHIR}
            x=13
            y=15
        [/unit]

        {MULTIPLAYER_GOLD}
    )}

    {MP_SIDE 9 (
        #Eradion's side
        {PLAYABLE}
        save_id=Eradion
        disallow_shuffle=yes
        previous_save_id=Cleodil
        no_leader=yes
        [unit]
            {ERADION}
            x=15
            y=15
        [/unit]

        {MULTIPLAYER_GOLD}
    )}

    #### reenforcements for the player ####

    [event]
        name=turn 9

        [foreach]
            array=l3_store_kalenz
            [do]
                [unstore_unit]
                    find_vacant=yes
                    variable=this_item
                    x=9
                    y=15
                [/unstore_unit]
                [role]
                    role=l3_store
                    id=$this_item.id
                [/role]
                {MODIFY_UNIT (id=$this_item.id) facing ne}
            [/do]
        [/foreach]

#ifdef MULTIPLAYER
        [foreach]
            array=l3_store_landar
            [do]
                [unstore_unit]
                    find_vacant=yes
                    variable=this_item
                    x=9
                    y=15
                [/unstore_unit]
                [role]
                    role=l3_store
                    id=$this_item.id
                [/role]
                {MODIFY_UNIT (id=$this_item.id) facing ne}
                {MODIFY_UNIT (id=$this_item.id) side 5}
            [/do]
        [/foreach]
#endif

        [if]
            [not]
                [variable]
                    name=l3_store_kalenz.length
                    numerical_equals=0
                [/variable]
            [/not]
#ifdef MULTIPLAYER
            [or]
                [not]
                    [variable]
                        name=l3_store_landar.length
                        numerical_equals=0
                    [/variable]
                [/not]
            [/or]
#endif
            [then]
                [message]
                    role=l3_store
                    message= _ "Kalenz! We come to fight beside you!"
                [/message]
                [message]
                    # The player already knows that the kalian refused to help, Galtrid said it on turn 1.
                    # Repeat Landar's comment from then, but not the rest of the conversation; if too much text is repeated the player may think a bug has triggered the event twice.
                    id=Landar
                    message= _ "That is well! If the Ka’lian is too fearful or blind to see what is needed, we must do it ourselves."
                [/message]
                [message]
                    # This text is from 04_The_Elvish_Treasury, reused unchanged because of the string freeze
                    id=Kalenz
                    message= _ "I accept your service gratefully, for I will need every sword and bow and spell with which to defeat these invaders. There will be time for talk later; now, we must fight."
                [/message]
            [/then]
        [/if]
        {CLEAR_VARIABLE l3_store_kalenz}
#ifdef MULTIPLAYER
        {CLEAR_VARIABLE l3_store_landar}
#endif
    [/event]

    [event]
        name=time over

        [unit]
            type=Paladin
            id=Kulrad
            name=_ "Kulrad"
            side=2
            x=38
            y=30
        [/unit]

        {GENERIC_UNIT 2 Knight 43 33}
        {GENERIC_UNIT 2 Knight 43 36}

        {GENERIC_UNIT 2 Horseman 38 34}
        {GENERIC_UNIT 2 Horseman 42 35}
        {GENERIC_UNIT 2 Horseman 39 34}
        {GENERIC_UNIT 2 Horseman 43 37}
        {GENERIC_UNIT 2 Horseman 41 37}
        {GENERIC_UNIT 2 Horseman 41 39}

        [message]
            id=Kulrad
            message= _ "I see foul orcs to be ridden down! Charge!"
        [/message]
        [message]
            race=orc
            canrecruit=yes
            message= _ "More of the cursed horse-pokers!! Run, let’s get out of here!"
        [/message]

        #TODO move the message in a macro
        [message]
            speaker=narrator
            message= _ "The not-at-all-brazen cry of a war-horn is heard in the distance."
            #TODO rethink about which signal to use here
            sound=horn-signals/horn-8.ogg
            image="portraits/goblins/rouser-2.png"
        [/message]

        [endlevel]
            result=victory
            bonus=no
            save=no
        [/endlevel]
    [/event]

    # [event]
    #     name=enemies defeated
    #     [message]
    #         id=Aldar
    #         message= _ "This is only a pause in their onslaught. Reform, men, and bind your wounds as you may. They’ll be back."
    #     [/message]
    #     #TODO CRAB
    #     #[modify_ai]
    #     #
    #     #[/modify_ai]
    # [/event]

    [event]
        name=victory
        [message]
            id=Kalenz
            message= _ "We have thwarted the Orcs once again!"
        [/message]
        [message]
            id=Cleodil
            message= _ "And we revived the alliance with the Humans, which is no small thing."
        [/message]
        [message]
            id=Kalenz
            message= _ "Indeed it is not. As always, Cleodil, you speak with the wisdom and care that befits a healer. That is a good reminder for those who must walk the path of steel and warfare, and touches my heart."
        [/message]
        [message]
            id=Olurf
            message= _ "A good fight against foul enemies. These orcs make a dwarf’s hackles rise; I might even fight them for free, next time."
        [/message]
        [message]
            id=Aldar
            message= _ "The King is here! Hail Haldric II, King of Wesnoth!"
        [/message]
        #TODO Landar is quiet?
        [kill]
            id=Aldun
        [/kill]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Aldar
        [/filter]
        [message]
            speaker=unit
            message= _ "Tath will fall! We have failed!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=last breath
        [filter]
            id=Grol
        [/filter]
        [message]
            speaker=unit
            message= _ "I die? Great Chief never said anything about fighting elves and dwarves!"
        [/message]
    [/event]

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

#undef PLAYER_GOLD
#undef MULTIPLAYER_GOLD
