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

#else
    [scenario]
#endif
        id=02_Hostile_Mountains
        next_scenario=03_Kalian_under_Attack

        experience_modifier=100
        name= _ "Hostile Mountains"
        {LOW_MAP 02_Hostile_Mountains.map}
        {TURNS 32 28 24}

        {INTRO_AND_SCENARIO_MUSIC sad.ogg northern_mountains.ogg}
        {EXTRA_SCENARIO_MUSIC knolls.ogg}
        {EXTRA_SCENARIO_MUSIC traveling_minstrels.ogg}
        {EXTRA_SCENARIO_MUSIC legends_of_the_north.ogg}
        {EXTRA_SCENARIO_MUSIC knalgan_theme.ogg}

        {DEFAULT_SCHEDULE_AFTERNOON}

        {STARTING_VILLAGES_ALL 3}
        {STARTING_VILLAGES_DWARF 2}

        #        {LOW_PRESTART}

        [story]
            [part]
                story= _ "Kalenz and his band broke out of the orcish encirclement, only to discover that the country on the direct route to the Ka’lian was already swarming with orcs. The raid on Kalenz’s home, it seemed, had been but one small part of a great migration south. There was no choice but to make a detour through territory the elves would rather have avoided..."
                delay=8000
            [/part]
            [part]
                delay=4000
                {TO_HOSTILE_MOUNTAINS}
                show_title=yes
            [/part]
        [/story]

        ### Kalenz's code ###
#define PLAYER_GOLD
    {GOLD 200 180 100}
#enddef
#define MULTIPLAYER_GOLD
    {GOLD 100 90 50}
#enddef

        [side]
            {KALENZ}
            # wmllint: recognize Kalenz
            controller=human
            fog=no
            extra_recruit=Elvish Fighter, Elvish Archer
#ifndef MULTIPLAYER
            {PLAYER_GOLD}
            [unit]
                {LANDAR}
                # wmllint: recognize Landar
                extra_recruit=Elvish Fighter, Elvish Archer
                x=20
                y=4
            [/unit]
#else
            {MULTIPLAYER_GOLD}
#endif
        [/side]
        [event]
            name=prestart
            {RECALL_LOYALS}
        [/event]
        ### /Kalenz's code ###

        ### Olurf's Code ###
#define OLURFS_LAND
    x=20-24,19-30,17-30,16-30,14-30,12-30,11-30,10-30,7-30,8-30,10-30,13-30,15-30,18-30,19-30,20-30,22-30,23-30,24-30,23-30,22-30
    y=10,11,12,13-15,16-17,18-19,20,21,22,23,24,25,26,27,28-29,30,31-32 ,33-36,37,38-39,40
#enddef

        [side]
            # wmllint: recognize Olurf
            {OLURF}
            side=2
            allow_player=no
            controller=ai
            canrecruit=yes
            {GOLD 150 120 120}
            persistent=yes
            save_id=Olurf
            recruit={DWARVES_NO_ULFS}
#ifdef EASY
            team_name=player
            user_team_name= _ "Player"
#else
            team_name=player,trolls
            user_team_name= _ "Neutrals"
#endif
            {ai/aliases/stable_singleplayer.cfg}  #note that this MUST be given OUTSIDE the 'ai' tag
            [ai]
                {AI_SIMPLE_ALWAYS_ASPECT caution 0}
                {AI_SIMPLE_ALWAYS_ASPECT village_value 0}
                {AI_SIMPLE_ALWAYS_ASPECT leader_value 0}
            [/ai]
        [/side]

        # Trolls have stepped on Olurf's land.
        [event]
            name=moveto
            first_time_only=yes
            [filter]
                side=3
                {OLURFS_LAND}
            [/filter]

            [message]
                id=Olurf
                message= _ "Those stinking trolls ha’ stepped on <i>our</i> land!"
            [/message]

            [if]
                [variable]
                    name=offended_by_elves
                    boolean_equals=yes
                [/variable]
                # the elves have stepped onto already
                [then]
                    [modify_side]
                        side=2
                        team_name=dwarves
                        user_team_name= _ "Enemies"
                    [/modify_side]
#ifdef EASY
                    [fire_event]
                        name=dwarves_defend_their_territory
                    [/fire_event]
#endif
#ifdef NORMAL
                    [fire_event]
                        name=dwarves_defend_their_territory
                    [/fire_event]
#endif
#ifdef HARD
                    [fire_event]
                        name=dwarves_kill_elves_and_trolls
                    [/fire_event]
#endif
                [/then]
                [else]
                    [modify_side]
                        side=2
                        team_name=player
                        user_team_name= _ "Player"
                    [/modify_side]
#ifdef EASY
                    [fire_event]
                        name=dwarves_kill_trolls
                    [/fire_event]
#endif
#ifdef NORMAL
                    [fire_event]
                        name=dwarves_kill_trolls
                    [/fire_event]
#endif
#ifdef HARD
                    [fire_event]
                        name=dwarves_kill_trolls
                    [/fire_event]
#endif
                [/else]
            [/if]
        [/event]

        # Elves have stepped on Olurf's land.
        [event]
            name=moveto
            first_time_only=yes
            [filter]
                side=1,4
                {OLURFS_LAND}
            [/filter]

            [message]
                id=Olurf
                message= _ "Those lying elves have stepped on <i>our</i> land!"
            [/message]
            [message]
                id=Kalenz
                message= _ "Fight to subdue, and do not kill unless you must. We have foes enough as it is without making blood enemies of these dwarves."
            [/message]

            #TODO CRAB why do we store this side? There is nothing done with the variable?
            [store_side]
                side=2
                variable=olurf_side
            [/store_side]

            [if]
                [variable]
                    name=olurf_side.team_name
                    equals=player
                [/variable]
                [then]
                    [modify_side]
                        side=2
                        team_name=dwarves
                        user_team_name= _ "Enemies"
                    [/modify_side]
#ifdef EASY
                    [fire_event]
                        name=dwarves_defend_their_territory
                    [/fire_event]
#endif
#ifdef NORMAL
                    [fire_event]
                        #TODO think about making it like HARD
                        name=dwarves_defend_their_territory
                    [/fire_event]
#endif
#ifdef HARD
                    [fire_event]
                        name=dwarves_kill_elves_and_trolls
                    [/fire_event]
#endif
                [/then]
                [else]
                    [modify_side]
                        side=2
                        team_name=trolls
                        user_team_name= _ "Enemies"
                    [/modify_side]
#ifdef EASY
                    [fire_event]
                        name=dwarves_defend_their_territory
                    [/fire_event]
#endif
#ifdef NORMAL
                    [fire_event]
                        name=dwarves_kill_elves
                    [/fire_event]
#endif
#ifdef HARD
                    [fire_event]
                        name=dwarves_kill_elves
                    [/fire_event]
#endif
                [/else]
            [/if]
            {CLEAR_VARIABLE olurf_side}
            {VARIABLE offended_by_elves yes}
        [/event]

        # start dwarven ai code

#define CLEAN_AI SIDE
    {MODIFY_AI_DELETE_GOAL {SIDE} *}
    {MODIFY_AI_TRY_DELETE_STAGE {SIDE} retreat_to_olurfs_land}
    {MODIFY_AI_TRY_DELETE_ASPECT {SIDE} avoid stay_in_own_land}
    {MODIFY_AI_TRY_DELETE_ASPECT {SIDE} recruitment always}
#enddef

#define ADD_AVOID_STAY_AT_OLURFS_LAND
    {MODIFY_AI_ADD_ASPECT 2 avoid (
        [facet]
            id="stay_in_own_land"
            [value]
                [not]
                    {OLURFS_LAND}
                [/not]
            [/value]
        [/facet]
    )}
#enddef

#define ADD_GOAL_KILL_ELVES SIDE
    {MODIFY_AI_ADD_GOAL {SIDE} (
        [goal]
            id=kill_elves
            [criteria]
                side=1
            [/criteria]
            value=1.5
        [/goal]
    )}
#enddef

#define ADD_GOAL_KILL_TROLLS SIDE
    {MODIFY_AI_ADD_GOAL {SIDE} (
        [goal]
            id=kill_trolls
            [criteria]
                side=3
            [/criteria]
            value=1.5
        [/goal]
    )}
#enddef

#define ADD_GOAL_KILL_TRESPASSERS SIDE
    {MODIFY_AI_ADD_GOAL {SIDE} (
        [goal]
            id=kill_trespassers
            [criteria]
                [not]
                    side={SIDE}
                [/not]
                #limiting is handled by 'avoid' aspect
            [/criteria]
            value=1.5
        [/goal]
    )}
#enddef

#define ADD_STAGE_RETREAT_TO_OLURFS_LAND SIDE
    [modify_ai]
        side={SIDE}
        action=add
        path=stage[0]
        [stage]
            id=retreat_to_olurfs_land
            name=testing_ai_default::candidate_action_evaluation_loop
            #TODO: add [candidate_action]s to make the retreat work
        [/stage]
    [/modify_ai]
#enddef

        [event]
            name=dwarves_watch_the_show
            first_time_only=no
            {CLEAN_AI 2}
            {MODIFY_AI_ADD_ASPECT 2 recruitment {AI_NO_RECRUITMENT} }
            {ADD_AVOID_STAY_AT_OLURFS_LAND}
            [message]
                id=Olurf
                message= _ "It should be rare sport to watch this... Just be sure not to trespass on our land."
            [/message]
        [/event]

        [event]
            name=dwarves_kill_elves
            first_time_only=no
            {CLEAN_AI 2}
            {MODIFY_AI_ADD_ASPECT 2 recruitment {AI_FORMULA_AI_EXPERIMENTAL_RECRUITMENT} }
            {ADD_GOAL_KILL_ELVES 2}
            [message]
                id=Olurf
                message= _ "Up axes, and death to elves!"
            [/message]
        [/event]

        [event]
            name=dwarves_kill_trolls
            first_time_only=no
            {CLEAN_AI 2}
            {MODIFY_AI_ADD_ASPECT 2 recruitment {AI_FORMULA_AI_EXPERIMENTAL_RECRUITMENT} }
            {ADD_GOAL_KILL_TROLLS 2}
            [message]
                id=Olurf
                message= _ "Up axes, and death to trolls!"
            [/message]
        [/event]

        [event]
            name=dwarves_kill_elves_and_trolls
            first_time_only=no
            {CLEAN_AI 2}
            {MODIFY_AI_ADD_ASPECT 2 recruitment {AI_FORMULA_AI_EXPERIMENTAL_RECRUITMENT} }
            {ADD_GOAL_KILL_ELVES 2}
            {ADD_GOAL_KILL_TROLLS 2}
            [message]
                id=Olurf
                message= _ "Up axes, and kill all the interlopers!"
            [/message]
        [/event]

        [event]
            name=dwarves_defend_their_territory
            first_time_only=no
            {CLEAN_AI 2}
            {MODIFY_AI_ADD_ASPECT 2 recruitment {AI_FORMULA_AI_EXPERIMENTAL_RECRUITMENT} }
            {ADD_AVOID_STAY_AT_OLURFS_LAND}
            {ADD_GOAL_KILL_TRESPASSERS 2}
            {ADD_STAGE_RETREAT_TO_OLURFS_LAND 2}
            [message]
                id=Olurf
                message= _ "Defend our bounds! Slay all who trespass them!"
            [/message]
        [/event]

#undef CLEAN_AI
#undef ADD_AVOID_STAY_AT_OLURFS_LAND
#undef ADD_STAGE_RETREAT_TO_OLURFS_LAND
#undef ADD_GOAL_KILL_ELVES
#undef ADD_GOAL_KILL_TROLLS
#undef ADD_GOAL_KILL_TRESPASSERS

        # end dwarven ai code

        [event]
            name=victory
            {CLEAR_VARIABLE offended_by_elves}
        [/event]
        ### /Olurf's Code ###

        ### Enemy Side ###
        [side]
            allow_player=no
            controller=ai
#ifdef EASY
            type=Troll Hero
#else
            type=Great Troll
#endif
            id=Grugl
            name=_ "Grugl"
            side=3
            team_name=trolls
            user_team_name= _ "Enemies"
            {TROLL_SETUP}
            canrecruit=yes
#ifdef EASY
            recruit=Troll Whelp
#endif
#ifdef NORMAL
            recruit=Troll Whelp, Troll, Troll Rocklobber
#endif
#ifdef HARD
            recruit=Troll Whelp, Troll, Troll Rocklobber, Troll Warrior
#endif
            {GOLD 170 240 270}

            {ai/aliases/stable_singleplayer.cfg}
            [ai]
                #TODO enable after the bug with the AI_SIMPLE_FORMULA_AI_EXPERIMENTAL_RECRUITMENT macro is fixed.
                ##ifdef EASY
                {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter"}
                ##else
                #         {AI_SIMPLE_FORMULA_AI_EXPERIMENTAL_RECRUITMENT}
                ##endif
                [goal]
                    [criteria]
                        race=elf
                    [/criteria]
                    value=1.5
                [/goal]

                {AI_SIMPLE_ALWAYS_ASPECT aggression 0.75}
                {AI_SIMPLE_NIGHT_ASPECT caution 0}
                {AI_SIMPLE_NIGHT_ASPECT grouping no}
            [/ai]
            {INCOME 4 8 12}
        [/side]
#undef OLURFS_LAND
#ifdef HARD
        #{LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Troll Warrior" 2}
#endif

        ### /Enemy Side ###

#ifdef MULTIPLAYER
        [side]
            side=4
            x=20
            y=4
            save_id=Landar
            {LANDAR}
            {MULTIPLAYER_GOLD}
            fog=no
            # wmllint: recognize Landar
            extra_recruit=Elvish Fighter, Elvish Archer
        [/side]
#endif

        #### Objectives and corresponding events ####
        [event]
            name=start
            [message]
                id=Kalenz
                message= _ "I had hoped to avoid these paths... The eastern way is through dwarvish territory and is shorter. I pray the dwarves will grant us safe passage, since the other path is through troll territory..."
            [/message]
            [message]
                id=Olurf
                message= _ "Not even in yer dreams, elf. These are dwarvish lands, and troubles we want no part of nip at yer heels. Get out and stay out!"
            [/message]
            [message]
                id=Landar
                message= _ "Our troubles will be yours, too, whether either of us will it or not. The orcs have come down from the north like a flood; if we squabble among ourselves they will feast on our discord."
            [/message]
            [message]
                id=Olurf
                message= _ "Bah. More smooth words and trickery, by my beard. We know yer kind... and who needs yer help anyway, weaklings? Leave now, or feel my axe! That same kiss of steel will greet all intruders. Anyone who sets foot on the eastern bank o’ this river will rue the day he was born!"
            [/message]
            [message]
                id=Landar
                message= _ "I cannot see how trolls could be any less friendly."
            [/message]
            [message]
                id=Kalenz
                message= _ "Hmm... Perhaps the dwarves’ intransigence can serve our purpose. Onwards, and no matter what you do, do <i>not</i> step on the eastern bank of the river!"
            [/message]

            {HIGHLIGHT_IMAGE 18 37 scenery/signpost.png ()}

            [fire_event]
                name=dwarves_watch_the_show
            [/fire_event]
        [/event]

        [event]
            name=prestart
            [objectives]
                side=0
#ifdef MULTIPLAYER
                [objective]
                    description= _ "Kalenz or Landar must reach the signpost"
                    condition=win
                [/objective]
#else
                [objective]
                    description= _ "Kalenz must reach the signpost"
                    condition=win
                [/objective]
#endif
                [objective]
                    {ALTERNATIVE_OBJECTIVE_CAPTION}
                    description= _ "Defeat Grugl"
                    condition=win
                [/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]

                {TURNS_RUN_OUT}

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

#define ENDSPEECH SPEAKER_NAME
    [message]
        speaker={SPEAKER_NAME}
        message= _ "We made it. Onwards to Wesmere!"
    [/message]

    [if]
        [variable]
            name=killed_by_elves
            greater_than=3
        [/variable]
        [then]
            [message]
                id=Olurf
                message= _ "Crazy elves! But at least they felled a few trolls before they left."
            [/message]
        [/then]
        [else]
            [message]
                id=Olurf
                message= _ "Crazy elves!"
            [/message]
        [/else]
    [/if]
#enddef

        [event]
            name=prestart
            {VARIABLE killed_by_elves 0}
        [/event]

        [event]
            name=die
            first_time_only="no"
            [filter]
                race=troll
            [/filter]
            [filter_second]
                race=elf
            [/filter_second]
            #TODO does this need the variable to exist?
            [set_variable]
                name=killed_by_elves
                add=1
            [/set_variable]
        [/event]

        [event]
            name=victory
            {CLEAR_VARIABLE killed_by_elves}
        [/event]

        [event]
            name=moveto
            [filter]
                x=18
                y=37
                [and]
                    id=Kalenz
#ifdef MULTIPLAYER
                    [or]
                        id=Landar
                    [/or]
#endif
                [/and]
            [/filter]

            {ENDSPEECH unit}

            [endlevel]
                #TODO reduce the carry over
                result=victory
                bonus=yes
            [/endlevel]
        [/event]

        [event]
            name=last breath
            [filter]
                id=Grugl
            [/filter]
            [filter_second]
                race=dwarf
            [/filter_second]
            [message]
                id=Grugl
                # wmllint: local spelling Urgh
                message= _ "Urgh! Grugl tried to eat dwarves, but choked on their sharp nasty axes."
            [/message]

            {ENDSPEECH "Kalenz"}
        [/event]

        [event]
            name=last breath
            [filter]
                id=Grugl
            [/filter]
            [filter_second]
                race=elf
            [/filter_second]
            [message]
                id=Grugl
                message= _ "Urgh! Grugl wanted tasty elf-meat, but choked on their nasty pointy spears!"
            [/message]

            {ENDSPEECH secondary_unit}
#undef ENDSPEECH
            [endlevel]
                #TODO reduce carry over
                result=victory
                bonus=yes
            [/endlevel]
        [/event]

        {campaigns/Legend_of_Wesmere/utils/deaths.cfg}

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

#undef PLAYER_GOLD
#undef MULTIPLAYER_GOLD
