## ai_controller
#version 0.9
# wmllint: no translatables

#please use in a post prestart event (for example: start)
#define AI_LOCATION ID NAME_STRING RADIUS X Y
    [label]
        text={NAME_STRING}
        x,y={X},{Y}
    [/label]
    [set_variables]
        name=ai_controller.locations
        mode=append
        [value]
            x={X}
            y={Y}
            name={NAME_STRING}
            id={ID}
            range={RADIUS}
        [/value]
    [/set_variables]
#enddef

#define AI_CONTROLLER FRIEND_TEAM FRIEND_SIDES ENEMY_TEAM ENEMY_SIDES
    [event]
        name=prestart

        [set_menu_item]
            id=ai_controller_location
            description= "define ai location"	# wmllint: ignore
            [command]
                [message]
                    speaker=narrator
                    [text_input]
                        variable=ai_controller.location_input
                        label="Location name?"	# wmllint: ignore
                        max_chars=10 # ?hmmm
                        #text=""
                    [/text_input]
                    image=wesnoth-icon.png
                [/message]
                [message]
                    speaker=narrator
                    [text_input]
                        variable=ai_controller.location_range
                        label="Range in Hexfields?"	# wmllint: ignore
                        max_chars=3
                    [/text_input]
                    image=wesnoth-icon.png
                [/message]

                {AI_LOCATION selfdefined$ai_controller.location_input $ai_controller.location_input $ai_controller.location_range $x1 $y1}
                {CLEAR_VARIABLE ai_controller.location_range}
                {CLEAR_VARIABLE ai_controller.location_input}
            [/command]
        [/set_menu_item]

#        [set_menu_item]
#            id=ai_controller_enable
#            description= "enable ai_controller"	# wmllint: ignore no spellcheck
#            [show_if]
#                [not]
#                    [variable]
#                        name=ai_controller.in_command
#                        boolean_equals=true
#                    [/variable]
#                [/not]
#            [/show_if]
#            [command]
#                {VARIABLE ai_controller.in_command true}
#            [/command]
#        [/set_menu_item]

#        [set_menu_item]
#            id=ai_controller_disable
#            description= "disable ai_controller" # wmllint: ignore no spellcheck
#            [show_if]
#                [variable]
#                    name=ai_controller.in_command
#                    boolean_equals=true
#                [/variable]
#            [/show_if]
#            [command]
#                {VARIABLE ai_controller.in_command false}
#            [/command]
#        [/set_menu_item]

        [set_menu_item]
            id=ai_controller_orders
            description= "Give new orders"	# wmllint: ignore
            [show_if]
                [have_unit]
                    canrecruit=yes
                    side={FRIEND_SIDES}
                    x=$x1
                    y=$y1
                [/have_unit]
            [/show_if]
            [command]
                [store_unit]
                    [filter]
                        x=$x1
                        y=$y1
                    [/filter]
                    variable=ai_controller.selected_leader
                [/store_unit]

                [if]
                    [variable]
                        name=ai_controller.selected_leader.side
                        equals=$side_number
                    [/variable]
                    [then]
                        [store_unit]
                            [filter]
                                canrecruit=yes
                                side={FRIEND_SIDES}
                                #team={FRIEND_TEAM}
                            [/filter]
                            variable=ai_controller.friend_leaders
                        [/store_unit]
                        {FOREACH ai_controller.friend_leaders friend}
                            [if]
                                [variable]
                                    name=ai_controller.friend_leaders[$friend].side
                                    not_equals=$ai_controller.selected_leader.side
                                [/variable]

                                [then]
                                    [set_variables]
                                        name=ai_controller.options
                                        mode=append
                                        [value]
                                            message= "Command $ai_controller.friend_leaders[$friend].id"	# wmllint: ignore
                                            id="command_ally_$friend_leaders[$friend].id"
                                            [command]
                                                {VARIABLE_OP ai_controller.ai_side format $ai_controller.friend_leaders[$friend].side}

                                                [fire_event]
                                                    name=ai_controller
                                                [/fire_event]
                                            [/command]
                                        [/value]
                                    [/set_variables]
                                [/then]
                                #[if]
                                #	[variable]
                                #		name=selected_leader.id
                                #		not_equals=$friend_leaders[$friend].id
                                #	[/variable]
                                #	[then]
                                #	{VARIABLE options[$friend].message "Protect $friend_leaders[$friend].id|!"}
                                #	[/then]
                                #	[else]
                                #	{VARIABLE options[$friend].message "Your men shall protect yourself!"}
                                #	[/else]
                                #[/if]
                            [/if]
                        {NEXT friend}
                        {CLEAR_VARIABLE friend}

                        [message]
                            id=$ai_controller.selected_leader.id
                            message= "Which ally should i command?"	# wmllint: ignore
                            [insert_tag]
                                name=option
                                variable=ai_controller.options
                            [/insert_tag]
                        [/message]
                        {CLEAR_VARIABLE ai_controller.options}
                    [/then]
                    [else]
                        {VARIABLE_OP ai_controller.ai_side format $ai_controller.selected_leader.side}
                        [fire_event]
                            name=ai_controller
                        [/fire_event]
                    [/else]
                [/if]
            [/command]
        [/set_menu_item]
    [/event]

    [event]
        name=start

        #store all leaders
        [store_unit]
            [filter]
                canrecruit=yes
                #side={ENEMY_SIDES}
            [/filter]
            variable=ai_controller.all_leaders
        [/store_unit]

        # isn't working any more
        #       {FOREACH ai_controller.all_leaders leader}
        #       [set_variables]
        #           name=ai_controller.options
        #           mode=append
        #           [value]
        #                id="command_take_$all_leaders[$leader].id"
        #                message="Take the Keep of $all_leaders[$leader].id|!"	# wmllint: ignore
        #                [command]
        #		    [set_variables]
        #		    name=ai_controller.ai_lists.side$ai_controller.ai_side|
        #		    mode=append
        #                        [ai]
        #                            [leader_goal]
        #                                value=5
        #                                x=$ai_controller.all_leaders[$leader].x
        #                                y=$ai_controller.all_leaders[$leader].y
        #                            [/leader_goal]
        #                        [/ai]
        #		    [/set_variables]
        #                        [fire_event]
        #                            name=ai_controller
        #                        [/fire_event]
        #                [/command]
        #            [/value]
        #        [/set_variables]

        #        {NEXT leader}
        {CLEAR_VARIABLE ai_controller.all_leaders}
        {CLEAR_VARIABLE ai_controller.leaders}
    [/event]

    [event]
        name="ai_ask_value"
        first_time_only=no
        [message]
            message= "How important is this command?"	# wmllint: ignore
            id=$ai_controller.current_leader.id
            [option]
                id="ai_ask_very"
                message= "It is very important. (value 90)"	# wmllint: ignore
                [command]
                    {VARIABLE ai_controller.ai_value 90}
                [/command]
            [/option]
            [option]
                id="ai_ask_very"
                message= "It is important. (value 50)"	# wmllint: ignore
                [command]
                    {VARIABLE ai_controller.ai_value 50}
                [/command]
            [/option]
            [option]
                id="ai_ask_very"
                message= "It is not so important. (value 25)"	# wmllint: ignore
                [command]
                    {VARIABLE ai_controller.ai_value 25}
                [/command]
            [/option]
            [option]
                id="ai_ask_custom"
                message= "It has the importance ..."	# wmllint: ignore
                [command]
                    [message]
                        speaker=narrator
                        [text_input]
                            variable=ai_controller.ai_value
                            label="value: "	# wmllint: ignore
                            max_chars=2
                            text=20	# wmllint: ignore
                        [/text_input]
                        image=wesnoth-icon.png
                    [/message]
                [/command]
            [/option]
        [/message]
    [/event]

    [event]
        name=victory # when should i clear variables?
        {CLEAR_VARIABLE ai_controller}
    [/event]

    [event]
        name="ai_controller"
        first_time_only=no

        {CLEAR_VARIABLE ai_controller.options}

        #debug output
        #[message]
        #    message="ai trigered"	# wmllint: ignore
        #[/message]

        #store enemy leaders
        [store_unit]
            [filter]
                canrecruit=yes
                side={ENEMY_SIDES}
            [/filter]
            variable=ai_controller.enemy_leaders
        [/store_unit]

        #store friends
        [store_unit]
            [filter]
                canrecruit=yes
                side={FRIEND_SIDES}
                #team={FRIEND_TEAM}
            [/filter]
            variable=ai_controller.friend_leaders
        [/store_unit]

        #store the allied leader who is playing
        [store_unit]
            [filter]
                side=$ai_controller.ai_side
                canrecruit=yes
            [/filter]
            variable=ai_controller.current_leader
        [/store_unit]

        [set_variable]
            name=ai_controller.current_orders
            [join]
                variable=ai_controller.ai_desc.side$ai_controller.ai_side|
                key=description
                separator="
@"
            [/join]
        [/set_variable]

        [message]
            # wmllint: display on
            message= "Which kind of order do you want me to obey?	# wmllint: ignore
@$ai_controller.current_orders"
            id=$ai_controller.current_leader.id
            # wmllint: display off

            #[option]
            #    id=command_nothing
            #    message= "Stay with your current orders!"	# wmllint: ignore
            #[/option]

            [option]
                id=command_clear
                message= "#I revoke all your commands!"	# wmllint: ignore

		[command]
			{MODIFY_UNIT side=$ai_controller.ai_side goto_x "-999"}
	                {MODIFY_UNIT side=$ai_controller.ai_side goto_y "-999"}
			{CLEAR_VARIABLE ai_controller.ai_lists.side$ai_controller.ai_side|}
 			{CLEAR_VARIABLE ai_controller.ai_desc.side$ai_controller.ai_side|}
		#	{VARIABLE ai_controller.goto.}
			[fire_event]
                            name=ai_controller
                        [/fire_event]
		[/command]
	    [/option]

#            [option]
#                id=command_empty
#                message= "Forget your destination and listen to a new Command! (Move Commands must be cleaned)"	# wmllint: ignore

#                [command]
 #                   [modify_side]
  #                      side=$ai_controller.ai_side
   #                     [ai]
    #                        dummy=dummy # not sure if necessary
     #                   [/ai]
      #              [/modify_side]
       #         [/command]
        #        [command]
         #           {MODIFY_UNIT side=$ai_controller.ai_side goto_x "-999"}
          #      [/command]
           #     [command]
            #        {MODIFY_UNIT side=$ai_controller.ai_side goto_y "-999"}
             #   [/command]
#
#                [command]
#                    [message]
#                        message="Your orders are canceled!"	# wmllint: ignore
#                        id=$ai_controller.current_leader.id
#                    [/message]
#                
#                    [fire_event]
#                        name=ai_controller
#                    [/fire_event]
#                [/command]
#            [/option]

            [option]
                message= "Defeat an enemy Leader!"	# wmllint: ignore
                [command]
                    {FOREACH ai_controller.enemy_leaders enemy}

                    [set_variables]
                        name=ai_controller.options
                        mode=append
                        [value]
                            id="command_defeat_$ai_controller.enemy_leaders[$enemy].id"
                            message= "Defeat $ai_controller.enemy_leaders[$enemy].id|!"	# wmllint: ignore
                            [command]
                                [fire_event]
                                    name=ai_ask_value
                                [/fire_event]

                                [set_variables]
                                    name=ai_controller.ai_lists.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        [target]
                                            value=$ai_controller.ai_value
                                            [filter]
                                                id=$ai_controller.enemy_leaders[$enemy].id
                                            [/filter]
                                        [/target]
                                    [/value]
                                [/set_variables]

                                [set_variables]
                                    name=ai_controller.ai_desc.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        description= "I am already attacking $ai_controller.enemy_leaders[$enemy].id|!"	# wmllint: ignore
                                    [/value]
                                [/set_variables]

                                [fire_event]
                                    name=ai_controller
                                [/fire_event]
                            [/command]
                        [/value]
                    [/set_variables]
                    {NEXT enemy}
                    {CLEAR_VARIABLE enemy}

                    [message]
                        id=$ai_controller.current_leader.id
                        message= "Which enemy Leaders do you want me to defeat?"	# wmllint: ignore
                        [insert_tag]
                            name=option
                            variable=ai_controller.options
                        [/insert_tag]
                    [/message]
                [/command]
            [/option]

            [option]
                message= "Protect an allied leader!"	# wmllint: ignore
                [command]
                    {FOREACH ai_controller.friend_leaders friend}
                    [set_variables]
                        name=ai_controller.options
                        mode=append
                        [value]
                            message= "Protect $ai_controller.friend_leaders[$friend].id"	# wmllint: ignore
                            id="command_protect_$ai_controller.friend_leaders[$friend].id"
                            [command]
				[fire_event]
                                    name=ai_ask_value
                                [/fire_event]
                                [set_variables]
					name=ai_controller.ai_lists.side$ai_controller.ai_side|
					mode=append
					[value]
						[protect_unit]
							value=5
                                            		radius=10
                                            		[filter]
								id=$ai_controller.friend_leaders[$friend].id
                                            		[/filter]
                                        	[/protect_unit]                                  
					[/value]
                                [/set_variables]

				[set_variables]
                                    name=ai_controller.ai_desc.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        description= "I am already protecting $ai_controller.friend_leaders[$friend].id"	# wmllint: ignore
                                    [/value]
                                [/set_variables]
				
  				[fire_event]
                                    name=ai_controller
                                [/fire_event]
                            [/command]
                        [/value]
                    [/set_variables]
                    #[if]
                    #    [variable]
                    #        name=ai_controller.current_leader.id
                    #        not_equals=ai_controller.$friend_leaders[$friend].id
                    #    [/variable]
                    #    [then]
                    #        {VARIABLE ai_controller.options[$friend].message "Protect $friend_leaders[$friend].id|!"}
                    #    [/then]
                    #    [else]
                    #        {VARIABLE ai_controller.options[$friend].message "Your men shall protect yourself!"}
                    #    [/else]
                    #[/if]

                    {NEXT friend}
                    {CLEAR_VARIABLE friend}

                    [message]
                        message= "Which allied leader should i protect?"	# wmllint: ignore
                        id=$ai_controller.current_leader.id
                        [insert_tag]
                            name=option
                            variable=ai_controller.options
                        [/insert_tag]
                    [/message]
                [/command]
            [/option]

            [option]
                message="Defend a location!"	# wmllint: ignore
                [command]
                    {FOREACH ai_controller.locations location}
                    [set_variables]
                        name=ai_controller.options
                        mode=append
                        [value]
                            id="command_defend_$ai_controller.locations[$location].id"
                            message= "Defend the $ai_controller.locations[$location].name|!"	# wmllint: ignore
                            [command]
				[fire_event]
					name=ai_ask_value
				[/fire_event]

                                [set_variables]
				    name=ai_controller.ai_lists.side$ai_controller.ai_side|
				    mode=append
                                    [value]
                                        [protect_location]
                                            x=$ai_controller.locations[$location].x
                                            y=$ai_controller.locations[$location].y
                                            value=$|ai_controller.value
                                            radius=$ai_controller.locations[$location].radius
                                        [/protect_location]
                                    [/value]
                                [/set_variables]

				[set_variables]
                                    name=ai_controller.ai_desc.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        description= "I am already defending $ai_controller.locations[$location].name|!"	# wmllint: ignore
                                    [/value]
                                [/set_variables]


				[fire_event]
					name=ai_controller
				[/fire_event]

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

                    {NEXT location}
                    {CLEAR_VARIABLE location}

                    [message]
                        message= "Which location should i protect?"	# wmllint: ignore
                        id=$ai_controller.current_leader.id
                        [insert_tag]
                            name=option
                            variable=ai_controller.options
                        [/insert_tag]
                    [/message]
                [/command]
            [/option]

            [option]
                message= "Go to a location! (only the leader)"	# wmllint: ignore
                [command]
                    {FOREACH ai_controller.locations location}
                    [set_variables]
                        name=ai_controller.options
                        mode=append
                        [value]
                            id="command_goto_$ai_controller.locations[$location].id"
                            message="Goto the $ai_controller.locations[$location].name|!"	# wmllint: ignore
                            [command]
				[fire_event]
					name=ai_ask_value
				[/fire_event]
                                [set_variables]
				    name=$ai_controller.ai_lists.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        [leader_goal]
                                            x=$ai_controller.locations[$location].x
                                            y=$ai_controller.locations[$location].y
                                            value=$|ai_controller.value
                                        [/leader_goal]
                                    [/value]
                                [/set_variables]

				[set_variables]
                                    name=ai_controller.ai_desc.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        description= "I am already going to $ai_controller.locations[$location].name|!"	# wmllint: ignore
                                    [/value]
                                [/set_variables]

				[fire_event]
					name=ai_controller
				[/fire_event]
                            [/command]
                        [/value]
                    [/set_variables]
                    {NEXT location}
		    {CLEAR_VARIABLE location}

                    [message]
                        message= "To which location shall i move?"	# wmllint: ignore
                        id=$ai_controller.current_leader.id
                        [insert_tag]
                            name=option
                            variable=ai_controller.options
                        [/insert_tag]
                    [/message]
                [/command]
            [/option]

            [option]
                message= "Avoid a location!"	# wmllint: ignore
                [command]
                    {FOREACH ai_controller.locations location}
                    [set_variables]
                        name=ai_controller.options
                        mode=append
                        [value]
                            id="command_avoid_$ai_controller.locations[$location].id"
                            message= "Avoid the $ai_controller.locations[$location].name|!"	# wmllint: ignore
                            [command]
				[fire_event]
					name=ai_ask_value
				[/fire_event]
                                [set_variables]
				    name=ai_controller.ai_lists.side$ai_controller.ai_side|
				    mode=append
				    [value]                     
                                        [avoid]
                                            x=$ai_controller.locations[$location].x
                                            y=$ai_controller.locations[$location].y
                                            range=$ai_controller.locations[$location].range
                                            value=$|ai_controller.value
                                        [/avoid]
                                    [/value]
                                [/set_variables]
				[set_variables]
                                    name=ai_controller.ai_desc.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        description= "I am already ordered to avoid $ai_controller.locations[$location].name|!"	# wmllint: ignore
                                    [/value]
                                [/set_variables]
				[fire_event]
					name=ai_controller
				[/fire_event]
                            [/command]
                        [/value]
                    [/set_variables]
                    {NEXT location}
		    {CLEAR_VARIABLE location}

                    [message]
                        message= "Which location shall i avoid?"	# wmllint: ignore
                        id=$ai_controller.current_leader.id
                        [insert_tag]
                            name=option
                            variable=ai_controller.options
                        [/insert_tag]
                    [/message]
                [/command]
            [/option]

           # [option]
           #     message= "Take a keep!"	# wmllint: ignore
           #     [command]
           #         {FOREACH options option}
           #         {VARIABLE options[$option].command.modify_side.side $ai_side}
                    #[set_variables]
                    #    name=take_options
                    #    mode=append
                    #    [value]
                    #        id="command_take_$ai_locations[$location].id"
                    #        message="$ai_locations[$location].name|!"	# wmllint: ignore
                    #        [command]
                    #            [modify_side]
                    #                side=$ai_side
                    #                [ai]
                    #                    [avoid]
                    #			     x=$ai_locations[$location].x
                    #                        y=$ai_locations[$location].y
                    #    		     range=$ai_locations[$location].range
                    #                        value=5
                    #                    [/avoid]
                    #                 [/ai]
                    #            [/modify_side]
                    #        [/command]
                    #    [/value]
                    #[/set_variables]
           #         {NEXT option}

            #        [message]
             #           message= "Which keep shall i take?"	# wmllint: ignore
              #          id=$ai_controller.current_leader.id
               #         [insert_tag]
                #            name=option
                #            variable=ai_controller.take_options
                #        [/insert_tag]
            #        [/message]
            #    [/command]
           # [/option]

            #{FOREACH take_options option}
            #{VARIABLE take_options[$option].command.modify_side.side $ai_side}
            #[if]
            #    [variable]
            #        name=current_leader.id
            #        equals=$friend_leaders[$friend].id
            #    [/variable]
            #    [then]
            #        {VARIABLE protect_options[$friend].message "Protect $friend_leaders[$friend].id|!"}
            #    [/then]
            #    [else]
            #        {VARIABLE protect_options[$friend].message "Your men shall protect yourself!"}
            #    [/else]
            #[/if]
            #{NEXT option}
            #{CLEAR_VARIABLE option}


            [option]
                message= "Send your army to a location!"	# wmllint: ignore
                [command]
                    {FOREACH ai_controller.locations location}
                    [set_variables]
                        name=ai_controller.options
                        mode=append
                        [value]
                            id="command_send_$ai_controller.locations[$location].id"
                            message="Move to the $ai_controller.locations[$location].name|!"	# wmllint: ignore
                            [command]
                                [store_unit]
                                    [filter]
                                        side=$ai_controller.ai_side
                                    [/filter]
                                    variable=ai_controller.sidemembers
                                [/store_unit]
                                [set_variable]
                                    name=i
                                    value=0
                                [/set_variable]
                                [while]
                                    [variable]
                                        name=i
                                        less_than=$|ai_controller.sidemembers.length
                                    [/variable]
                                    [do]
                                        [set_variable]
                                            name=ai_controller.sidemembers[$|i].goto_x
                                            value=$ai_controller.locations[$location].x
                                        [/set_variable]
                                        [set_variable]
                                            name=ai_controller.sidemembers[$|i].goto_y
                                            value=$ai_controller.locations[$location].y
                                        [/set_variable]
                                        [unstore_unit]
                                            variable=ai_controller.sidemembers[$|i]
                                        [/unstore_unit]
                                        [set_variable]
                                            name=i
                                            add=1
                                        [/set_variable]

                                    [/do]
                                [/while]
                                [clear_variable]
                                    name=ai_controller.sidemembers
                                [/clear_variable]
				{CLEAR_VARIABLE i}
				[set_variables]
                                    name=ai_controller.ai_desc.side$ai_controller.ai_side|
                                    mode=append
                                    [value]
                                        description= "I am already ordered to send all men to $ai_controller.locations[$location].name|!"	# wmllint: ignore
                                    [/value]
                                [/set_variables]
                            [/command]
                        [/value]
                    [/set_variables]
                    {NEXT location}

                    [message]
                        message= "Which location shall i send my men to?"	# wmllint: ignore
                        id=$ai_controller.current_leader.id
                        [insert_tag]
                            name=option
                            variable=ai_controller.options
                        [/insert_tag]
                    [/message]
		    [fire_event]
			name=ai_controller
		    [/fire_event]
                [/command]
            [/option]



            [option]
                id=command_quit
                message= "@I don't want to be in command any more! Take care of yourselves! (Disables AI_CONTROLLER)"	# wmllint: ignore no spellcheck
            	[show_if]
		    [variable]
                        name=ai_controller.in_command
                        boolean_equals=true
                    [/variable]
                [/show_if]
                [command]
                    {VARIABLE ai_controller.in_command false}
                [/command]
            [/option]

            [option]
            	id=command_execute
            	message= "@Execute my orders!"	# wmllint: ignore
            	[command]
			[modify_side]
				side=$ai_controller.ai_side
            			[insert_tag]
					name=ai
                                	variable=$ai_controller.ai_lists.side$ai_controller.ai_side|
                           	[/insert_tag]
			[/modify_side]
            	[/command]
            [/option]

        [/message]

        #{CLEAR_VARIABLE ai_controller.current_leader}
        #{CLEAR_VARIABLE ai_controller.enemy_leaders}
        #{CLEAR_VARIABLE ai_controller.friend_leaders}
        #{CLEAR_VARIABLE ai_controller.defeat_options}
        #{CLEAR_VARIABLE ai_controller.protect_options}
        #{CLEAR_VARIABLE ai_controller.defend_options}
        #{CLEAR_VARIABLE ai_controller.goto_options}
        #{CLEAR_VARIABLE ai_controller.move_options}
        # take_options is static and will be cleared at level end

	{CLEAR_VARIABLE ai_controller.options}
        
    [/event]

    [event]
        name="ai turn"
        first_time_only=no

        [store_side]
            side=$side_number
            variable=ai_controller.current_side
        [/store_side]

        [if]
            [and]
                [variable]
                    name=ai_controller.current_side.team_name
                    equals={FRIEND_TEAM}
                [/variable]

                [variable]
                    name=ai_controller.in_command
                    boolean_equals=true
                [/variable]

		[have_unit]
		    side=$side_number	
		    canrecruit=yes
		[/have_unit]
            [/and]

            [then]
                {VARIABLE ai_controller.ai_side $side_number}

                [fire_event]
                    name=ai_controller
                [/fire_event]
            [/then]
        [/if]
    [/event]

    [event]
	name=victory
	{CLEAR_VARIABLE ai_controller}

	#TODO disable the ai_controller context menu entries	
        [set_menu_item]
            id=ai_controller_enable
	    [show_if] 
	    	      [not]
		      [/not] 
	    [/show_if]
        [/set_menu_item]

        [set_menu_item]
            id=ai_controller_disable
	    [show_if] 
	    	      [not]
		      [/not] 
	    [/show_if]
        [/set_menu_item]

	[set_menu_item]
            id=ai_controller_location
	    [show_if] 
	    	      [not]
		      [/not] 
	    [/show_if]
	[/set_menu_item]    

    [/event]
#enddef
