#textdomain wesnoth

#define AI_CONTROLLER_NOTE
    [note]
        description= _ "In this scenario, you may issue instructions to an allied side by right-clicking on a unit that belongs to it."
    [/note]
#enddef

#define AI_CONTROLLER AFFIX PLAYER_SIDES ALLY_SIDES VARIABLES_WML
    [event]
        name=prestart

        [set_variables]
            name=ai_controller_{AFFIX}

            # This block contains all the default settings and options.
            [literal]
                enabled=yes
                option_name= _ "Instruct ally"
                player_side={PLAYER_SIDES}
                ally_sides={ALLY_SIDES}
                disabled_for_sides=0

                [overview_message_has_instructions]
                    speaker=narrator
                    caption= _ "Instruct ally"
                    message= _ "$ally_leader.name (side $ally_side|) is carrying out the following instructions:"
                    image=wesnoth-icon.png
                [/overview_message_has_instructions]

                [overview_message_no_instructions]
                    speaker=narrator
                    caption= _ "Instruct ally"
                    message= _ "$ally_leader.name (side $ally_side|) has not been given any instructions and is acting normally."
                    image=wesnoth-icon.png
                [/overview_message_no_instructions]

                ################

                [aggression]
                    option_description= _ "Be more aggressive"
                    currently_doing_description= _ "aggressive."

                    [show_if]
                    [/show_if]

                    [actions_when_applied]
                        {MODIFY_AI_ADD_SIMPLE_ASPECT $ally_side aggression set_by_ai_controller "0.9"}
                        {MODIFY_AI_ADD_SIMPLE_ASPECT $ally_side caution set_by_ai_controller "0.1"}
                    [/actions_when_applied]

                    [message_when_applied]
                    [/message_when_applied]
                [/aggression]

                ################

                [caution]
                    option_description= _ "Be more defensive"
                    currently_doing_description= _ "defensive."

                    [actions_when_applied]
                        {MODIFY_AI_ADD_SIMPLE_ASPECT $ally_side aggression set_by_ai_controller "0.1"}
                        {MODIFY_AI_ADD_SIMPLE_ASPECT $ally_side caution set_by_ai_controller "1.0"}
                    [/actions_when_applied]
                [/caution]

                ################

                [focus_on_enemy]
                    option_description= _ "Focus on defeating..."
                    currently_doing_description= _ "focusing on defeating $ai_controller.side_$ally_side|_current_settings.focus_on_enemy.side_description|."

                    [actions_when_applied]
                        [set_variables]
                            name=focus_on_enemy_options_message

                            [insert_tag]
                                name=value
                                variable=ai_controller_{AFFIX}.main_menu_message
                            [/insert_tag]
                        [/set_variables]

                        {CLEAR_VARIABLE focus_on_enemy_options_message.option}

                        [store_side]
                            side=$ally_side
                            variable=stored_ally_side
                        [/store_side]

                        {VARIABLE temp_i 1}

                        [while]
                            [variable]
                                name=temp_i
                                less_than=10
                            [/variable]

                            [do]
                                [store_side]
                                    side=$temp_i
                                    variable=stored_other_side
                                [/store_side]

                                [if]
                                    [variable]
                                        name=stored_ally_side.team_name
                                        not_equals=$stored_other_side.team_name
                                    [/variable]

                                    [have_unit]
                                        side=$temp_i
                                    [/have_unit]

                                    [then]
                                        [if]
                                            [have_unit]
                                                side=$temp_i
                                                canrecruit=yes

                                                [filter_vision]
                                                    viewing_side=$side_number
                                                    visible=yes
                                                [/filter_vision]
                                            [/have_unit]

                                            [then]
                                                [store_unit]
                                                    [filter]
                                                        side=$temp_i
                                                        canrecruit=yes
                                                    [/filter]

                                                    kill=no
                                                    variable=side_i_leader
                                                [/store_unit]

                                                {VARIABLE this_enemy_txt_img_description "&$side_i_leader.image~TC($temp_i|,$side_i_leader.flag_rgb|)=$side_i_leader.name|="+_"(side $temp_i|)"}
                                            [/then]

                                            [else]
                                                {VARIABLE this_enemy_txt_img_description "&misc/blank-hex.png= ="+_"(side $temp_i|)"}
                                                {VARIABLE ai_controller.side_$ally_side|_current_settings.focus_on_enemy.side_description _"side $temp_i"}
                                            [/else]
                                        [/if]

                                        [set_variables]
                                            name=focus_on_enemy_options_message.option
                                            mode=append

                                            [value]
                                                message=$this_enemy_txt_img_description

                                                [command]
                                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.focus_on_enemy.side $temp_i}
                                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.focus_on_enemy.side_description _"$side_i_leader.name (side $temp_i|)"}

                                                    {MODIFY_AI_ADD_GOAL $ally_side (
                                                        [goal]
                                                            id=set_by_ai_controller
                                                            value=20
                                                            [criteria]
                                                                side=$temp_i
                                                            [/criteria]
                                                        [/goal]
                                                    )}
                                                [/command]
                                            [/value]
                                        [/set_variables]
                                    [/then]
                                [/if]

                                {VARIABLE_OP temp_i add 1}
                            [/do]
                        [/while]

                        [set_variables]
                            name=focus_on_enemy_options_message.option
                            mode=append

                            [value]
                                message= _ "Back"

                                [command]
                                [/command]
                            [/value]
                        [/set_variables]

                        [insert_tag]
                            name=message
                            variable=focus_on_enemy_options_message
                        [/insert_tag]

                        {CLEAR_VARIABLE stored_other_side,focus_on_enemy_options_message,side_i_leader,this_enemy_description}
                    [/actions_when_applied]
                [/focus_on_enemy]

                ################

                [protect]
                    option_description= _ "Focus on protecting..."
                    currently_doing_description= _ "focusing on protecting $ai_controller.side_$ally_side|_current_settings.protect.side_description|."

                    [actions_when_applied]
                        [set_variables]
                            name=protect_options_message

                            [insert_tag]
                                name=value
                                variable=ai_controller_{AFFIX}.main_menu_message
                            [/insert_tag]
                        [/set_variables]

                        {CLEAR_VARIABLE protect_options_message.option}

                        [store_side]
                            side=$ally_side
                            variable=stored_ally_side
                        [/store_side]

                        {VARIABLE temp_i 1}

                        [while]
                            [variable]
                                name=temp_i
                                less_than=10
                            [/variable]

                            [do]
                                [store_side]
                                    side=$temp_i
                                    variable=stored_other_side
                                [/store_side]

                                [if]
                                    [variable]
                                        name=ally_side
                                        not_equals=$temp_i
                                    [/variable]

                                    [variable]
                                        name=stored_ally_side.team_name
                                        equals=$stored_other_side.team_name
                                    [/variable]

                                    [have_unit]
                                        side=$temp_i
                                    [/have_unit]

                                    [then]
                                        [if]
                                            [have_unit]
                                                side=$temp_i
                                                canrecruit=yes
                                            [/have_unit]

                                            [then]
                                                [store_unit]
                                                    [filter]
                                                        side=$temp_i
                                                        canrecruit=yes

                                                        [filter_vision]
                                                            viewing_side=$side_number
                                                            visible=yes
                                                        [/filter_vision]
                                                    [/filter]

                                                    kill=no
                                                    variable=side_i_leader
                                                [/store_unit]

                                                {VARIABLE this_ally_txt_img_description "&$side_i_leader.image~TC($temp_i|,$side_i_leader.flag_rgb|)=$side_i_leader.name|="+_"(side $temp_i|)"}
                                            [/then]

                                            [else]
                                                {VARIABLE this_ally_txt_img_description "&misc/blank-hex.png= ="+_"(side $temp_i|)"}
                                                {VARIABLE ai_controller.side_$ally_side|_current_settings.protect.side_description _"side $temp_i"}
                                            [/else]
                                        [/if]

                                        [set_variables]
                                            name=protect_options_message.option
                                            mode=append

                                            [value]
                                                message=$this_ally_txt_img_description

                                                [command]
                                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.protect.side $temp_i}
                                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.protect.side_description _"$side_i_leader.name (side $temp_i|)"}

                                                    {MODIFY_AI_ADD_GOAL $ally_side (
                                                        [goal]
                                                            id=set_by_ai_controller
                                                            name=protect
                                                            value=20
                                                            [criteria]
                                                                [filter]
                                                                    side=$temp_i
                                                                [/filter]
                                                            [/criteria]
                                                        [/goal]
                                                    )}
                                                [/command]
                                            [/value]
                                        [/set_variables]
                                    [/then]
                                [/if]

                                {VARIABLE_OP temp_i add 1}
                            [/do]
                        [/while]

                        [set_variables]
                            name=protect_options_message.option
                            mode=append

                            [value]
                                message= _ "Back"

                                [command]
                                [/command]
                            [/value]
                        [/set_variables]

                        [insert_tag]
                            name=message
                            variable=protect_options_message
                        [/insert_tag]

                        {CLEAR_VARIABLE stored_other_side,side_i_leader,this_ally_description,protect_options_message}
                    [/actions_when_applied]
                [/protect]

                ################

#ifdef __UNUSED
                [defend_location]
                    type=objective

                    [ai]
                        [protect_location]
                            x=$ai_controller.side_$ally_side|_current_settings.defend_location.x
                            y=$ai_controller.side_$ally_side|_current_settings.defend_location.y
                            radius=6
                            value=20
                        [/protect_location]
                    [/ai]

                    [option]
                        message= _ "Defend a location..."

                        [show_if]
                            [variable]
                                name=ai_controller_{AFFIX}.defend_location.disabled
                                not_equals=yes
                            [/variable]
                        [/show_if]

                        [command]
                            {VARIABLE ai_controller_{AFFIX}.defend_location.picker_active yes}
                            {VARIABLE ai_controller_{AFFIX}.defend_location.original_controller_invokation_x $x1}
                            {VARIABLE ai_controller_{AFFIX}.defend_location.original_controller_invokation_y $y1}
                            {VARIABLE ai_controller_finished yes}

                            [print]
                                text= _ "Right-click to select a location to defend"
                                duration=100
                                {COLOR_WHITE}
                            [/print]

                            [set_menu_item]
                                id=ai_controller_defend_location_picker
                                description= _ "Defend this location"

                                [show_if]
                                    [variable]
                                        name=ai_controller_{AFFIX}.defend_location.picker_active
                                        boolean_equals=yes
                                    [/variable]
                                [/show_if]

                                [command]
                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.defend_location.x $x1}
                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.defend_location.y $y1}
                                    {VARIABLE ai_controller_{AFFIX}.defend_location.picker_active no}

                                    {VARIABLE order_type defend_location}

                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.current_objective defend_location}
                                    {VARIABLE ai_controller.side_$ally_side|_current_settings.currently_doing_objective_description _"focusing on defending the area around $x1|,$y1|."}

                                    {MODIFY_AI_ADD_GOAL $ally_side (
                                        [goal]
                                            id=set_by_ai_controller
                                            name=protect
                                            value=20
                                            [criteria]
                                                x,y=$x1,$y1
                                            [/criteria]
                                        [/goal]
                                    )}

                                    [print]
                                        text=" "    # wmllint: ignore
                                        duration=1
                                    [/print]

                                    [fire_event]
                                        name=menu item ai_controller

                                        [primary_unit]
                                            x=$ai_controller_{AFFIX}.defend_location.original_controller_invokation_x
                                            y=$ai_controller_{AFFIX}.defend_location.original_controller_invokation_y
                                        [/primary_unit]
                                    [/fire_event]
                                [/command]
                            [/set_menu_item]

                            [event]
                                name=select,recruit,recall,side turn,menu item ai_controller

                                [if]
                                    [variable]
                                        name=ai_controller_{AFFIX}.defend_location.picker_active
                                        boolean_equals=yes
                                    [/variable]

                                    [then]
                                        {VARIABLE ai_controller_{AFFIX}.defend_location.picker_active no}

                                        [print]
                                            text= _ "Location selection canceled"
                                            duration=100
                                            {COLOR_WHITE}
                                        [/print]
                                    [/then]
                                [/if]
                            [/event]
                        [/command]
                    [/option]
                [/defend_location]
#endif

                ################

                [revoke_objective_orders]
                    option_description= _ "Clear objective orders"

                    [actions_when_applied]
                        {MODIFY_AI_DELETE_GOAL $ally_side set_by_ai_controller}

                        {CLEAR_VARIABLE ai_controller.side_$ally_side|_current_settings.current_objective}
                    [/actions_when_applied]
                [/revoke_objective_orders]

                ################

                [revoke_behavior_orders]
                    option_description= _ "Clear behavior orders"

                    [actions_when_applied]
                        {MODIFY_AI_DELETE_ASPECT $ally_side aggression set_by_ai_controller}
                        {MODIFY_AI_DELETE_ASPECT $ally_side caution set_by_ai_controller}

                        {CLEAR_VARIABLE ai_controller.side_$ally_side|_current_settings.current_behavior}
                    [/actions_when_applied]
                [/revoke_behavior_orders]

                ################

                [revoke_all_orders]
                    option_description= _ "Clear all orders"

                    [actions_when_applied]
                        {MODIFY_AI_DELETE_GOAL $ally_side set_by_ai_controller}
                        {MODIFY_AI_DELETE_ASPECT $ally_side aggression set_by_ai_controller}
                        {MODIFY_AI_DELETE_ASPECT $ally_side caution set_by_ai_controller}

                        {CLEAR_VARIABLE ai_controller.side_$ally_side|_current_settings}
                    [/actions_when_applied]
                [/revoke_all_orders]
            [/literal]
        [/set_variables]

        [set_variables]
            name=ai_controller_{AFFIX}
            mode=merge

            [literal]
                {VARIABLES_WML}
            [/literal]
        [/set_variables]

        [set_menu_item]
            id=ai_controller_{AFFIX}
            description=$ai_controller_{AFFIX}.option_name

            [show_if]
                [have_unit]
                    side=$ai_controller_{AFFIX}.ally_sides
                    x,y=$x1,$y1

                    [not]
                        side=$ai_controller_{AFFIX}.disabled_for_sides
                    [/not]
                [/have_unit]

                [variable]
                    name=ai_controller_{AFFIX}.enabled
                    equals=yes
                [/variable]

                [variable]
                    name=ai_controller_{AFFIX}.player_side
                    contains=$side_number
                [/variable]

                [variable]
                    name=ai_controller_{AFFIX}.defend_location.picker_active
                    boolean_equals=no
                [/variable]
            [/show_if]

            [command]
                [store_unit]
                    [filter]
                        x,y=$x1,$y1
                    [/filter]

                    kill=no
                    variable=ally_unit
                [/store_unit]

                [store_unit]
                    [filter]
                        side=$ally_unit.side
                        canrecruit=yes
                    [/filter]

                    kill=no
                    variable=ally_leader
                [/store_unit]

                {VARIABLE ally_side $ally_leader.side}

                [if]
                    [variable]
                        name=ai_controller.side_$ally_side|_original_settings.side
                        equals=$empty
                    [/variable]

                    [then]
                        [store_side]
                            side=$ally_side
                            variable=ai_controller.side_$ally_side|_original_settings
                        [/store_side]

                        [set_variables]
                            name=ai_controller.side_$ally_side|_original_settings.ai_settings

                            [value]
                                side=$ally_side

                                [insert_tag]
                                    name=ai
                                    variable=ally_leader.ai
                                [/insert_tag]
                            [/value]
                        [/set_variables]
                    [/then]
                [/if]

                {CLEAR_VARIABLE ai_controller_finished}

                [while]
                    [variable]
                        name=ai_controller_finished
                        not_equals=yes
                    [/variable]

                    [do]
                        [if]
                            [variable]
                                name=ai_controller.side_$ally_side|_current_settings.current_objective
                                equals=$empty
                            [/variable]

                            [then]
                                {VARIABLE ai_controller.side_$ally_side|_current_settings.currently_doing_objective_description _"none set."}
                            [/then]
                        [/if]

                        [if]
                            [variable]
                                name=ai_controller.side_$ally_side|_current_settings.current_behavior
                                equals=$empty
                            [/variable]

                            [then]
                                {VARIABLE ai_controller.side_$ally_side|_current_settings.currently_doing_behavior_description _"none set."}
                            [/then]
                        [/if]

                        [if]
                            [variable]
                                name=ai_controller.side_$ally_side|_current_settings.current_objective
                                equals=$empty
                            [/variable]

                            [variable]
                                name=ai_controller.side_$ally_side|_current_settings.current_behavior
                                equals=$empty
                            [/variable]

                            [then]
                                [set_variables]
                                    name=ai_controller_{AFFIX}.main_menu_message

                                    [insert_tag]
                                        name=value
                                        variable=ai_controller_{AFFIX}.overview_message_no_instructions
                                    [/insert_tag]
                                [/set_variables]
                            [/then]

                            [else]
                                [set_variables]
                                    name=ai_controller_{AFFIX}.main_menu_message

                                    [insert_tag]
                                        name=value
                                        variable=ai_controller_{AFFIX}.overview_message_has_instructions
                                    [/insert_tag]
                                [/set_variables]
                            [/else]
                        [/if]

                        # wmllint: display on
                        {VARIABLE ai_controller_{AFFIX}.main_menu_message.message "$ai_controller_{AFFIX}.main_menu_message.message"+"
<span color='black'>-</span>"+"
"+_"Objective: $ai_controller.side_$ally_side|_current_settings.currently_doing_objective_description
Behavior: $ai_controller.side_$ally_side|_current_settings.currently_doing_behavior_description"+"
<span color='black'>-</span>"}
                        # wmllint: display off

                        [set_variables]
                            name=ai_controller_{AFFIX}.main_menu_message.option

                            [literal]
                                message= _ "Set objective..."

                                [command]
                                    [set_variables]
                                        name=set_objective_message

                                        [insert_tag]
                                            name=value
                                            variable=ai_controller_{AFFIX}.main_menu_message
                                        [/insert_tag]
                                    [/set_variables]

                                    {CLEAR_VARIABLE set_objective_message.option}

                                    [set_variables]
                                        name=set_objective_message.option

                                        [value]
                                            message=$ai_controller_{AFFIX}.focus_on_enemy.option_description

                                            [insert_tag]
                                                name=show_if
                                                variable=ai_controller_{AFFIX}.focus_on_enemy.show_if
                                            [/insert_tag]

                                            [command]
                                                {VARIABLE objective_picked focus_on_enemy}
                                            [/command]
                                        [/value]

                                        [value]
                                            message=$ai_controller_{AFFIX}.protect.option_description

                                            [insert_tag]
                                                name=show_if
                                                variable=ai_controller_{AFFIX}.protect.show_if
                                            [/insert_tag]

                                            [command]
                                                {VARIABLE objective_picked protect}
                                            [/command]
                                        [/value]

                                        [value]
                                            message=$ai_controller_{AFFIX}.revoke_objective_orders.option_description

                                            [insert_tag]
                                                name=show_if
                                                variable=ai_controller_{AFFIX}.revoke_objective_orders.show_if
                                            [/insert_tag]

                                            [command]
                                                {VARIABLE objective_picked revoke_objective_orders}
                                            [/command]
                                        [/value]

                                        [value]
                                            message=_"Back"

                                            [command]
                                            [/command]
                                        [/value]
                                    [/set_variables]

                                    [insert_tag]
                                        name=message
                                        variable=set_objective_message
                                    [/insert_tag]

                                    [if]
                                        [variable]
                                            name=objective_picked
                                            not_equals=$empty
                                        [/variable]

                                        [then]
                                            [insert_tag]
                                                name=command
                                                variable=ai_controller_{AFFIX}.$objective_picked|.actions_when_applied
                                            [/insert_tag]

                                            {VARIABLE ai_controller.side_$ally_side|_current_settings.current_objective $objective_picked}
                                            {VARIABLE ai_controller.side_$ally_side|_current_settings.currently_doing_objective_description $ai_controller_{AFFIX}.$objective_picked|.currently_doing_description|}
                                        [/then]
                                    [/if]

                                    {CLEAR_VARIABLE set_objective_message,objective_picked}
                                [/command]
                            [/literal]

                            [literal]
                                message= _ "Set behavior..."

                                [command]
                                    [set_variables]
                                        name=set_behavior_message

                                        [insert_tag]
                                            name=value
                                            variable=ai_controller_{AFFIX}.main_menu_message
                                        [/insert_tag]
                                    [/set_variables]

                                    {CLEAR_VARIABLE set_behavior_message.option}

                                    [set_variables]
                                        name=set_behavior_message.option

                                        [value]
                                            message=$ai_controller_{AFFIX}.aggression.option_description

                                            [insert_tag]
                                                name=show_if
                                                variable=ai_controller_{AFFIX}.aggression.show_if
                                            [/insert_tag]

                                            [command]
                                                {VARIABLE behavior_picked aggression}
                                            [/command]
                                        [/value]

                                        [value]
                                            message=$ai_controller_{AFFIX}.caution.option_description

                                            [insert_tag]
                                                name=show_if
                                                variable=ai_controller_{AFFIX}.caution.show_if
                                            [/insert_tag]

                                            [command]
                                                {VARIABLE behavior_picked caution}
                                            [/command]
                                        [/value]

                                        [value]
                                            message=$ai_controller_{AFFIX}.revoke_behavior_orders.option_description

                                            [insert_tag]
                                                name=show_if
                                                variable=ai_controller_{AFFIX}.revoke_behavior_orders.show_if
                                            [/insert_tag]

                                            [command]
                                                {VARIABLE behavior_picked revoke_behavior_orders}
                                            [/command]
                                        [/value]

                                        [value]
                                            message=_"Back"

                                            [command]
                                            [/command]
                                        [/value]
                                    [/set_variables]

                                    [insert_tag]
                                        name=message
                                        variable=set_behavior_message
                                    [/insert_tag]

                                    [if]
                                        [variable]
                                            name=behavior_picked
                                            not_equals=$empty
                                        [/variable]

                                        [then]
                                            [insert_tag]
                                                name=command
                                                variable=ai_controller_{AFFIX}.$behavior_picked|.actions_when_applied
                                            [/insert_tag]

                                            {VARIABLE ai_controller.side_$ally_side|_current_settings.current_behavior $behavior_picked}
                                            {VARIABLE ai_controller.side_$ally_side|_current_settings.currently_doing_behavior_description $ai_controller_{AFFIX}.$behavior_picked|.currently_doing_description|}
                                        [/then]
                                    [/if]

                                    {CLEAR_VARIABLE set_behavior_message,behavior_picked}
                                [/command]
                            [/literal]

                            [literal]
                                message=$ai_controller_{AFFIX}.revoke_all_orders.option_description

                                [insert_tag]
                                    name=show_if
                                    variable=ai_controller_{AFFIX}.revoke_all_orders.show_if
                                [/insert_tag]

                                [insert_tag]
                                    name=command
                                    variable=ai_controller_{AFFIX}.revoke_all_orders.actions_when_applied
                                [/insert_tag]
                            [/literal]

                            [literal]
                                message=_"Exit"

                                [command]
                                    {VARIABLE ai_controller_finished yes}

#ifndef MULTIPLAYER
                                    [allow_undo]
                                    [/allow_undo]
#endif
                                [/command]
                            [/literal]
                        [/set_variables]

                        [insert_tag]
                            name=message
                            variable=ai_controller_{AFFIX}.main_menu_message
                        [/insert_tag]
                    [/do]
                [/while]

                {CLEAR_VARIABLE ally_unit,ally_leader,ai_controller_{AFFIX}.main_menu_message}
            [/command]
        [/set_menu_item]
    [/event]

    [event]
        name=victory

        {CLEAR_VARIABLE ai_controller,ai_controller_{AFFIX}}
    [/event]
#enddef

#define DISABLE_AI_CONTROLLER AFFIX
    {VARIABLE ai_controller_{AFFIX}.enabled no}
#enddef

#define DISABLE_AI_CONTROLLER_FOR_SIDE AFFIX SIDE
    [if]
        [variable]
            name=ai_controller_{AFFIX}.disabled_for_sides
            equals=0
        [/variable]

        [not]
            [variable]
                name=ai_controller_{AFFIX}.disabled_for_sides
                contains={SIDE}
            [/variable]
        [/not]

        [then]
            {VARIABLE ai_controller_{AFFIX}.disabled_for_sides {SIDE}}
        [/then]

        [else]
            [if]
                [variable]
                    name=ai_controller_{AFFIX}.disabled_for_sides
                    contains={SIDE}
                [/variable]

                [else]
                    {VARIABLE ai_controller_{AFFIX}.disabled_for_sides $ai_controller_{AFFIX}.disabled_for_sides|,{SIDE}}
                [/else]
            [/if]
        [/else]
    [/if]
#enddef

#define ENABLE_AI_CONTROLLER_FOR_SIDE AFFIX SIDE
    [if]
        [variable]
            name=ai_controller_{AFFIX}.disabled_for_sides
            contains={SIDE}
        [/variable]

        [then]
            [set_variables]
                name=disabled_for_sides_array

                [split]
                    list=ai_controller_{AFFIX}.disabled_for_sides
                    key=side
                    separator=,
                [/split]
            [/set_variables]

            {FOREACH disabled_for_sides_array disabled_for_side_i}
                [if]
                    [variable]
                        name=disabled_for_sides_array[$disabled_for_side_i].side
                        equals={SIDE}
                    [/variable]

                    [then]
                        {CLEAR_VARIABLE disabled_for_sides_array[$disabled_for_side_i]}
                    [/then]
                [/if]
            {NEXT disabled_for_side_i}

            [set_variable]
                name=ai_controller_{AFFIX}.disabled_for_sides

                [join]
                    variable=disabled_for_sides_array
                    key=side
                    separator=,
                [/join]
            [/set_variable]

            {CLEAR_VARIABLE disabled_for_sides_array}
        [/then]

        [else]
            {VARIABLE ai_controller_{AFFIX}.ally_sides $ai_controller_{AFFIX}.ally_sides|,{SIDE}}
        [/else]
    [/if]
#enddef

# A stub for scenario 7 of LoW
#define AI_LOCATION AFFIX STRING RADIUS X Y
    {SET_LABEL {X} {Y} ({STRING})}
#enddef

#define AI_CONTROLLER_FUTURE_STRINGS
    # These will be used for the special orders menu and the order for telling
    # the ally leader to move someplace
    future_string_1= _ "Set special orders..."  #wmllint: ignore
    future_string_2= _ "Move leader to..."  #wmllint: ignore
    future_string_3= _ "Right-click to select a location to move leader to" #wmllint: ignore
    future_string_4= _ "Move leader here"   #wmllint: ignore
    future_string_5= _ "moving leader to $x1|,$y1|."    #wmllint: ignore
    future_string_6= _ "Clear special orders"   #wmllint: ignore
    future_string_7= _ "Special: $ai_controller.side_$ally_side|_current_settings.currently_doing_special_description"  #wmllint: ignore
#enddef
