#textdomain wesnoth-ai

[test]
    id=bottleneck_defense
    name= _ "Bottleneck Defense"
    next_scenario=micro_ai_test

    map_data="{ai/micro_ais/maps/bottleneck_defense.map}"

    {DEFAULT_SCHEDULE}
    turns=unlimited
    victory_when_enemies_defeated=no

    [side]
        side=1
        controller=ai
        id=LuaAI
        type=Lieutenant
        defeat_condition=no_units_left
        persistent=no

        canrecruit=yes
        recruit=Spearman,Bowman
        gold=125

        [unit]
            type=White Mage
            x,y=23,6
        [/unit]
    [/side]

    [side]
        side=2
        controller=ai
        suppress_end_turn_confirmation=yes
        type=Orcish Leader
        id=Big Bad Orc
        name= _ "Big Bad Orc"
        persistent=no

        canrecruit=yes
        recruit=Orcish Archer,Orcish Grunt
        gold=400

        [ai]
            aggression=1.0
        [/ai]
    [/side]

    [side]  # This side is only here because we need one persistent side for the game to go on
        side=3
        controller=null
        persistent=yes
        save_id=Grnk
        hidden=yes
    [/side]

    [event]
        name=prestart

        {VARIABLE scenario_name bottleneck_defense}

        # Set up the Bottleneck Defense Micro AI
        [micro_ai]
            side=1
            ai_type=bottleneck_defense
            action=add

            x=14,14,14
            y= 7, 9, 8
            enemy_x=13,13
            enemy_y= 8, 9

            healer_x=14,14,15,15
            healer_y= 7, 9, 8, 9
            leadership_x=14,14,15,15
            leadership_y= 7, 9, 9 ,8
            active_side_leader=yes
        [/micro_ai]
    [/event]

    [event]
        name=start

        [message]
            speaker=LuaAI
            message= _ "All right, chaps. Those orcs need to be stopped."
        [/message]
        {STORE_UNIT_VAR (id=Big Bad Orc) profile profile}
        [message]
            speaker=Big Bad Orc
            image=$profile~FL()~RIGHT()
            message= _ "They there!  We them get!"
        [/message]
        {CLEAR_VARIABLE profile}
        # wmllint: unbalanced-on
        [message]
            speaker=LuaAI
            message= _ "We need to hold that pass for as long as we can. Let's put our strongest fighters on the front line and bring injured units to the back for healing. If we're careful enough, we might even win this battle. I'll join you as soon as I'm done recruiting and do my share of the fighting.

Note: The Bottleneck Defense AI is coded as a Micro AI. A Micro AI can be added and adapted to the need of a scenario easily using only WML and the [micro_ai] tag. Check out the <span color='#00A000'>Micro AI wiki page</span> at https://wiki.wesnoth.org/Micro_AIs for more information."
        [/message]
        # wmllint: unbalanced-off
        # wmllint: local spellings AIs RCA

        [message]
            speaker=narrator
            caption= _ "Question for the Player"
            image=wesnoth-icon.png
            message= _ "In this scenario, the AI playing the humans in the east is instructed to form a defensive line at the pass and hold off the orcs for as long as possible. Do you want to play the orc side or let the default (RCA) AI do that?"
            [option]
                label= _ "<span font='16'>I'll watch the two AIs fight it out.</span>"
            [/option]
            [option]
                label= _ "<span font='16'>I'll play the orcs.</span>"
                [command]
                    [modify_side]
                        side=2
                        controller=human
                    [/modify_side]
                [/command]
            [/option]
        [/message]

        [objectives]
            summary= _ "Take the pass"
            [objective]
                description= _ "Defeat all humans"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Big Bad Orc"
                condition=lose
            [/objective]
            [objective]
                description= _ "Only one orc remains"
                condition=lose
            [/objective]
        [/objectives]
    [/event]

    # White Mage has to hang out at keep for one turn
    [event]
        name=side 1 turn 1 refresh

        {MODIFY_UNIT (type=White Mage) moves 0}
    [/event]

    # When leader dies: message, then keep fighting
    [event]
        name=last_breath
        [filter]
            id=LuaAI
        [/filter]

        [if]
            [have_unit]
                side=1
            [/have_unit]
            [then]
        [message]
            speaker=LuaAI
            message= _ "I may have fallen, but we will continue to defend the pass to the last man!"
        [/message]
            [/then]
        [/if]
    [/event]

    # When the last unit on one side dies, end the scenario
    [event]
        name=die
        first_time_only=no

        [if]
            [not]  # If all pass defenders have died
                [have_unit]
                    side=1
                [/have_unit]
            [/not]
            [or]  # or if all orcs (except their leader) have died
                [have_unit]
                    side=2
                    count=1
                [/have_unit]
            [/or]
            [then]
                [kill]
                    id=$unit.id
                [/kill]

                # So that game goes on to next scenario
                [modify_side]
                    side=3
                    controller=human
                [/modify_side]

                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Well, that was that."
                [/message]

                [endlevel]
                    result=victory
                    bonus=no
                    carryover_percentage=0
                    carryover_report=no
                    linger_mode=no
                [/endlevel]
            [/then]
        [/if]
    [/event]

    # Spearmen only advance to Javelineers
    [event]
        name=recruit
        first_time_only=no
        [filter]
            type=Spearman
        [/filter]

        {MODIFY_UNIT id=$unit.id advances_to Javelineer}
    [/event]
[/test]
