#textdomain wesnoth-low
[scenario]
    id=02_Hostile_Mountains
    next_scenario=03_Kalian_under_Attack

    random_start_time=no
    allow_new_game=no
    force_lock_settings=yes

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

    {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 4}
    {STARTING_VILLAGES_DWARF 3}

    [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..."
        [/part]
    [/story]
    {LOW_TRACK {FLIGHT_STAGE2} }

    ### Kalenz's code ###
#define PLAYER_GOLD
#ifdef MULTIPLAYER
    {GOLD 120 100 80}
#else
    {GOLD 200 180 120}
#endif
    income=-2
    village_gold=1
#enddef

    # wmllint: validate-off
    [side]
        side=1
        {PLAYABLE}
        {KALENZ_YOUNG}
        {PLAYER_GOLD}
        disallow_shuffle=yes
#ifndef MULTIPLAYER
        [unit]
            {LANDAR_YOUNG}
            x=20
            y=4
        [/unit]
#endif
    [/side]
    # wmllint: validate-on
    [event]
        name=prestart
        [recall]
            id=Anduilas
            x=20
            y=6
        [/recall]
        [recall]
            id=Arkildur
            x=19
            y=5
        [/recall]
    [/event]
    ### /Kalenz's code ###

    # wmllint: skip-side
    {MP_SIDE 2 (
        x=20
        y=4
        save_id=Landar
        disallow_shuffle=yes
        {LANDAR_YOUNG}
        {PLAYABLE}
        {PLAYER_GOLD}
    )}

    ### 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

    # wmllint: validate-off
    [side]
        # wmllint: who OLURF is Olurf
        {OLURF}
        side=3
        allow_player=no
        controller=ai
        {GOLD 150 120 120}
        persistent=yes
        save_id=Olurf
#ifdef EASY
        team_name=player
        user_team_name= _ "Player"
#else
        team_name=player,trolls
        user_team_name= _ "Neutrals"
#endif
        [ai]
            {AI_SIMPLE_ALWAYS_ASPECT caution 0}
            {AI_SIMPLE_ALWAYS_ASPECT village_value 0}
            {AI_SIMPLE_ALWAYS_ASPECT leader_value 0}
        [/ai]
    [/side]
    # wmllint: validate-on

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

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

        [cancel_action]
        [/cancel_action]

        [if]
            [variable]
                name=offended_by_elves
                boolean_equals=yes
            [/variable]
            # the elves have stepped onto already
            [then]
                [modify_side]
                    side=3
                    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=3
                    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=enter_hex
        first_time_only=yes
        [filter]
            side=1,2
            {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]

        [cancel_action]
        [/cancel_action]

        [store_side]
            side=3
            variable=olurf_side
        [/store_side]
        [if]
            [variable]
                name=olurf_side.team_name
                equals=player
            [/variable]
            [then]
                [modify_side]
                    side=3
                    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=3
                    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_instructions always}
#enddef

#define ADD_AVOID_STAY_AT_OLURFS_LAND
    {MODIFY_AI_ADD_ASPECT 3 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,2
            [/criteria]
            value=1.5
        [/goal]
    )}
#enddef

#define ADD_GOAL_KILL_TROLLS SIDE
    {MODIFY_AI_ADD_GOAL {SIDE} (
        [goal]
            id=kill_trolls
            [criteria]
                side=4
            [/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=ai_default_rca::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 3}
        {MODIFY_AI_ADD_ASPECT 3 recruitment_instructions {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 3}
        {ADD_GOAL_KILL_ELVES 3}
        [message]
            id=Olurf
            message= _ "Up axes, and death to elves!"
        [/message]
    [/event]

    [event]
        name=dwarves_kill_trolls
        first_time_only=no
        {CLEAN_AI 3}
        {ADD_GOAL_KILL_TROLLS 3}
        [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 3}
        {ADD_GOAL_KILL_ELVES 3}
        {ADD_GOAL_KILL_TROLLS 3}
        [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 3}
        {ADD_AVOID_STAY_AT_OLURFS_LAND}
        {ADD_GOAL_KILL_TRESPASSERS 3}
        {ADD_STAGE_RETREAT_TO_OLURFS_LAND 3}
        [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=scenario_end
        {CLEAR_VARIABLE offended_by_elves}
    [/event]
    ### /Olurf's Code ###

    ### Enemy Side ###
    [side]
        side=4
        allow_player=no
        controller=ai
#ifdef EASY
        type=Troll Hero
#else
        type=Great Troll
#endif
        id=Grugl
        name=_ "Grugl"

        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]
            {AI_SIMPLE_ALWAYS_ASPECT recruitment_pattern "fighter, mixed fighter"}
            [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 4 "Troll Warrior" 2}
#endif

    ### /Enemy Side ###

    #### 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 wills 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

            [objective]
                description= _ "Kalenz or Landar must reach the signpost"
                condition=win
            [/objective]

            [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=40
            [/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=scenario_end
        {CLEAR_VARIABLE killed_by_elves}
    [/event]

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

        {ENDSPEECH unit}

        [endlevel]
            result=victory
#ifdef MULTIPLAYER
            bonus=0.5
#else
            bonus=yes
#endif
            {NEW_GOLD_CARRYOVER 40}
        [/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 second_unit}
#undef ENDSPEECH
        [endlevel]
            result=victory
#ifdef MULTIPLAYER
            bonus=0.5
#else
            bonus=yes
#endif
            {NEW_GOLD_CARRYOVER 40}
        [/endlevel]
    [/event]

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

#undef PLAYER_GOLD
#undef MULTIPLAYER_GOLD
