#textdomain wesnoth-ai

[test]
    id=swarm
    name= _ "Swarm"
    next_scenario=micro_ai_test

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

    {DEFAULT_SCHEDULE}
    turns=unlimited
    victory_when_enemies_defeated=no

    [side]
        side=1
        controller=human
        suppress_end_turn_confirmation=yes
        hidden=no
        name= _ "Kraa"
        id=Kraa
        type=Gryphon
        max_moves=99
        side=1
        persistent=no

        team_name=gryphons
        user_team_name= _ "Gryphons"

        canrecruit=yes
        recruit=Ruffian,Footpad,Thug,Poacher
        gold=0
    [/side]

    [side]
        side=2
        controller=ai
        no_leader=yes
        persistent=no

        team_name=bats
        user_team_name= _ "Bats"

        gold=0
        income=-2
    [/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]

    # Put all the units and markers out there
    [event]
        name=prestart

        {VARIABLE scenario_name swarm}

        {REPEAT 12 {GENERIC_UNIT 2 "Vampire Bat" 37 26}}

        # The right-click menu items
        [set_menu_item]
            id=m01_end_swarm
            description= _ "End Scenario"
            image=items/ring-red.png~CROP(26,26,20,20)
            [show_if]
                {VARIABLE_CONDITIONAL scenario_name equals swarm}
            [/show_if]
            [command]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Well, that was that."
                [/message]

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

                [endlevel]
                    result=victory
                    bonus=no
                    carryover_percentage=0
                    carryover_report=no
                    linger_mode=no
                [/endlevel]
            [/command]
        [/set_menu_item]
        [set_menu_item]
            id=m02_new_gryphon
            description= _ "Place Side 1 Gryphon"
            image=units/monsters/gryphon.png~CROP(38,36,24,24)
            [show_if]
                {VARIABLE_CONDITIONAL scenario_name equals swarm}
            [/show_if]
            [command]
                {UNIT 1 Gryphon $x1 $y1 (max_moves=99)}
            [/command]
        [/set_menu_item]
        [set_menu_item]
            id=m03_new_bat
            description= _ "Place Side 2 Bat"
            image=units/undead/bat-se-4.png~CROP(24,16,24,24)
            [show_if]
                {VARIABLE_CONDITIONAL scenario_name equals swarm}
            [/show_if]
            [command]
                {GENERIC_UNIT 2 (Vampire Bat) $x1 $y1}
            [/command]
        [/set_menu_item]
        [set_menu_item]
            id=m05_kill_unit
            description= _ "Kill Unit under Cursor"
            image=items/potion-poison.png~CROP(24,29,24,24)
            [show_if]
                {VARIABLE_CONDITIONAL scenario_name equals swarm}
            [/show_if]
            [command]
                [kill]
                    x,y=$x1,$y1
                [/kill]
            [/command]
        [/set_menu_item]

        # Set up the swarm micro AI
        [micro_ai]
            side=2
            ai_type=swarm
            action=add
        [/micro_ai]
    [/event]

    [event]
        name=start

        # wmllint: unbalanced-on
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "This scenario features bats moving around in a swarm. Without adjacent enemies, they simply try to stay together and at a certain distance from enemies. However, if an enemy unit is close to any bat, the swarm scatters. This is particular fun to watch when one places an enemy unit in the middle of the swarm. After being scattered, the swarm members slowly rejoin, but not in a very organized way. Sub-swarms or individual bats might roam around for quite some time before they find their way back. It is also possible that individual bats (or small groups) split off from the larger swarm at times.

The player controls a side of gryphons, each of which is given 99 moves so that the reaction of the swarm to enemies can be tested easily. There are also several right-click options, for example for adding bats or gryphons or for taking units off the map.

Note: The Swarm 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

        [objectives]
            side=1
            summary= _ "Watch the bats move around and fight them if you want"
            [objective]
                description= _ "Defeat all bats"
                condition=win
            [/objective]
            [objective]
                description= _ "Use right-click option"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of all gryphons"
                condition=lose
            [/objective]
            [note]
                description= _ "Check out the right-click menu options for additional actions"
            [/note]
        [/objectives]
    [/event]

    # Stop if this was the last death on this side
    [event]
        name=die
        first_time_only=no

        [if]
            [not]
                [have_unit]
                    side=$unit.side
                [/have_unit]
            [/not]
            [then]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Well, that was that."
                [/message]

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

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