#textdomain wesnoth-ai

# This is AI test scenario which is not visible to casual player.
[test]
    id=ai_arena_small
    name= _ "AI Arena - small"
    description= _ "Small ai arena"
    map_data="{ai/maps/scenario-AI_Arena_small.map}"
    random_start_time="no"
    turns=unlimited

    {DEFAULT_SCHEDULE}
    {DEFAULT_MUSIC_PLAYLIST}

    {PLACE_IMAGE items/burial.png 15 13}
    {PLACE_IMAGE items/burial.png 26 16}
    {PLACE_IMAGE items/burial.png 4 9}

    [event]
        name=preload
        first_time_only=no
        [lua]
            code = <<
            local tests_table = {}
            function register_test(_name, _description)
            tests_table[_name] = _description
            end
            function get_tests_table()
            return tests_table
            end
            >>
        [/lua]
    [/event]

    [event]
        name=preload
        first_time_only=no
        [set_variable]
            name=test_path_to_ai
            value=ai/ais/ai_default_rca.cfg
        [/set_variable]
        [set_variable]
            name=test_path_to_idle_ai
            value=ai/ais/idle_ai.cfg
        [/set_variable]
        [set_variable]
            name=test_path_to_formula_ai
            value=ai/dev/formula_ai.cfg
        [/set_variable]
        [set_variable]
            name=test_path_to_ai_default_rca
            value=ai/ais/ai_default_rca.cfg
        [/set_variable]
        [set_variable]
            name=test_id
            value=0001-healing
        [/set_variable]

        [set_menu_item]
            id=repeat_test
            description= _ "Repeat last test"
            [command]
                [fire_event]
                    name="_clean_arena"
                [/fire_event]
                [fire_event]
                    name="_replace_ai_2"
                [/fire_event]
                [lua]
                    code= <<  wesnoth.wml_actions.fire_event {name=wml.variables["test_id"] } >>
                [/lua]
            [/command]
        [/set_menu_item]

        [set_menu_item]
            id=select_another_ai
            description= _ "Select another ai"
            [command]
                [fire_event]
                    name=_select_challenger_ai
                [/fire_event]
            [/command]
        [/set_menu_item]

        [set_menu_item]
            id=select_test
            description= _ "Select another test"
            [command]
                [fire_event]
                    name=_select_test
                [/fire_event]
            [/command]
        [/set_menu_item]
    [/event]

    {ai/scenarios/ai_arena_small/}

    [side]
        side=1
        name= _ "AI Developer"
        type=Nightgaunt
        canrecruit=yes
        controller=human
        suppress_end_turn_confirmation=yes
        team_name=master
        user_team_name= _ "team_name^AI Developer"
        fog=no
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_QUICK}
            {TRAIT_LOYAL}
        [/modifications]
    [/side]
    [side]
        side=2
        id=chall-ai
        name= _ "Challenger AI"
        type=White Mage
        canrecruit=yes
        controller=ai
        team_name=north
        user_team_name= _ "North"
        fog=yes
        recruit="Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer,Thief,Poacher,Footpad"
    [/side]
    [side]
        side=3
        id=champ-ai
        name= _ "Champion AI"
        type=Dark Adept
        canrecruit=yes
        controller=ai
        team_name=south
        user_team_name= _ "South"
        fog=yes
        recruit="Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer,Thief,Poacher,Footpad"
    [/side]

    [event]
        name=_select_test
        first_time_only=no
        [command]
            [fire_event]
                name="_clean_arena"
            [/fire_event]
        [/command]
        [lua]
            code= <<
            local opts = {}
            for k,v in pairs(get_tests_table()) do
            local cmd = { "command", {{ "set_variable", {name="test_id", value= k } } } }
            table.insert(opts, { "option", { label = v, cmd } } )
            end
            wesnoth.wml_actions.message { speaker="narrator", message="Which test do you wish to run, O Mighty AI Developer?", table.unpack(opts) }
            >>
        [/lua]
        [command]
            [fire_event]
                name="_replace_ai_2"
            [/fire_event]
        [/command]
        [lua]
            code= <<  wesnoth.wml_actions.fire_event {name=wml.variables["test_id"] } >>
        [/lua]
    [/event]

    [event]
        name=_select_challenger_ai
        first_time_only=no

        [message]
            speaker=narrator
            message= _ "Which AI do you wish to use, O Mighty AI Developer?"
            [option]
                label= _ "I am happy with the current AI of team 2, [$test_path_to_ai]" # wmllint: no spellcheck
            [/option]
            [option]
                label= _ "My AI is the RCA AI (the current default)." # wmllint: no spellcheck
                [command]
                    [set_variable]
                        name=test_path_to_ai
                        value=$test_path_to_ai_default_rca
                    [/set_variable]
                [/command]
            [/option]
            [option]
                label= _ "I am the king of FORMULA AI, and I will use its vast powers for world domination."
                [command]
                    [set_variable]
                        name=test_path_to_ai
                        value=$test_path_to_formula_ai
                    [/set_variable]
                [/command]
            [/option]
            [option]
                label= _ "I want to test formulaAI-based poisoning improvements" # wmllint: no spellcheck
                [command]
                    [set_variable]
                        name=test_path_to_ai
                        value=ai/dev/formula_ai_poisoning.cfg
                    [/set_variable]
                [/command]
            [/option]
            [option]
                label= _ "I've come with my own AI, and I am ready to test its strength"
                [command]
                    [message]
                        speaker=narrator
                        image=wesnoth-icon.png
                        message= _ "And where is it located (path follows the usual WML convention)"
                        [text_input]
                            label=_"AI Location:"
                            variable="test_path_to_ai"
                        [/text_input]
                    [/message]
                [/command]
            [/option]
        [/message]
        [command]
            [fire_event]
                name="_replace_ai_2"
            [/fire_event]
        [/command]
        [command]
            {TELEPORT_TILE 6 21 5 22}
        [/command]
    [/event]

    [event]
        name=_clean_arena
        first_time_only=no
        [kill]
            animate=no
            fire_event=no
            canrecruit=no
        [/kill]
        [capture_village]
            x,y=5,9
        [/capture_village]
        [capture_village]
            x,y=6,19
        [/capture_village]
        [capture_village]
            x,y=9,17
        [/capture_village]
        [capture_village]
            x,y=10,20
        [/capture_village]
        [capture_village]
            x,y=11,4
        [/capture_village]
        [capture_village]
            x,y=14,8
        [/capture_village]
        [capture_village]
            x,y=16,17
        [/capture_village]
        [capture_village]
            x,y=19,22
        [/capture_village]
        [capture_village]
            x,y=20,5
        [/capture_village]
        [capture_village]
            x,y=21,9
        [/capture_village]
        [capture_village]
            x,y=24,6
        [/capture_village]
        [capture_village]
            x,y=25,17
        [/capture_village]
        [label]
            x="9"
            y="17"
        [/label]
        [label]
            x="19"
            y="6"
        [/label]
        [label]
            x="25"
            y="19"
        [/label]
        [label]
            x="26"
            y="14"
        [/label]
        [modify_side]
            side=1
            gold=10000
        [/modify_side]
        [modify_side]
            side=2
            gold=10000
        [/modify_side]
        [modify_side]
            side=3
            gold=10000
        [/modify_side]
    [/event]

    [event]
        name=_replace_ai_2
        first_time_only=no
        [modify_side]
            side=2
            switch_ai=$test_path_to_ai
        [/modify_side]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "And so, the AI for team 2 was redeployed from file '$test_path_to_ai'"
        [/message]
    [/event]
[/test]
