Micro AIs

From The Battle for Wesnoth Wiki
Revision as of 02:27, 3 September 2012 by Mattsc (talk | contribs) (The [micro_ai] Tag)

Important: This is a pre-release wiki page. The functionality described below has not actually been released yet.


The add-on AI Modification Demos contains a number of so-called Micro AIs (well, currently there's one, but the goal is to add more). Mirco AIs add specific functionalities to a side's AI and can be added to a scenario easily using only a few lines of WML code. Adding (or deleting) a Micro AI is done via the [micro_ai] tag, which also lets the campaign designer configure the AI behavior to the specific need of the scenario.

Note that the current Micro AIs are written for Wesnoth 1.10 in order to maximize the number of people that can give feedback on the AI behaviors. They should work in Wesnoth 1.11 as well (please report if you find that they don't), but they don't make use of the new features of the development version (yet).

Setting up a Micro AI

After installing the AI Modification Demos add-on, there are currently (for Wesnoth 1.10) three steps required to set up a Micro AI:

1. Making the Micro AIs and [micro_ai] tag available in your add-on

The following line needs to be added to your _main.cfg file, inside the #ifdef for your campaign:

{~add-ons/AI-demos/micro_ais/activate_micro_ais.cfg}

This loads the required AI files and sets up the [micro_ai] tag.

Note: If the Micro AIs were ever mainlined (in BfW 1.16 or so), this would not be needed any more, of course.

2. Setting up the Lua AI engine

Add the following line into the side definition (inside the [side] tag) of the side that should use the Micro AI:

    {MICRO_AI_ENGINE}

This does not yet activate any Micro AIs, but in Wesnoth 1.10 it is necessary to define the Lua AI engine inside the side definition, thus the need for this line. This requirement will go away for Wesnoth 1.11 making this step unnecessary. Note, however, that the current version of the add-on does not make use of this yet so as to be compatible with Wesnoth 1.10, so this line is currently required even if you are using Wesnoth 1.11.

3. Activating and configuring the Micro AI

Micro AIs are activated, deleted and configured using the [micro_ai] tag. This tag needs to be placed in ActionWML, that is, in an event, a menu option or the like. As an example, the following code activates the healer_support Micro AI in its default configuration for Side 2 from the beginning of the scenario:

    [event]
        name=prestart

        # Configure the healer support micro AI
        [micro_ai]
            side=2
            ai_type=healer_support
            action=add
        [/micro_ai]
    [/event]

For the full syntax of the [micro_ai] tag and the available Micro AIs, see the next sections.

The [micro_ai] Tag

The [micro_ai] tag activates, deletes and configures the Micro AIs for use in a scenario. It needs to be placed in ActionWML and must contain the following three required keys:

  • action (string): The action to take concerning the Micro AI. The following values are allowed:
    • add: Add a Micro AI to a side.
    • change: Change the configuration of an existing Micro AI. Note that this does not only change the specific parameters provided in the tag, but it replaces the entire existing Micro AI by a new version with the new (and only the new) configuration. It is therefore equivalent to using first the delete and then the add action.
    • delete: Delete an existing Micro AI from a side.
  • side: The side for which the Micro AI is to be added, changed or deleted
  • ai_type: The type of Micro AI to be added, changed or deleted. See the following sections for allowed values.

If no other keys are given, the Micro AI is set up in its default configuration when using the add and change actions. Additional keys allowed for each Micro AI are listed below. The add and change actions ignore all keys that do not apply to the respective Micro AI type. The delete action ignores all keys other than the three required ones listed above.

Healer Support Micro AI

The Healer Support Micro AI configures the healers of a side to stay behind the battle lines and heal injured and/or threatened units rather than participate in combat under all circumstances. You can set different levels of aggressiveness for the healers, from "never attack" to "only heal if you cannot attack" (not all implemented yet).

Use this Micro AI by setting:

ai_type=healer_support

in the [micro_ai] tag.

Healer Support specific keys (only one so far, more to be added):

  • never_attack=false: (boolean) If set to true, the AI will never let its healers participate in combat, otherwise it allows them to attack after all other units have attacked and if the healers cannot find any more units to support. The former behavior might be appropriate in scenarios with only one or few valuable healers, while the latter might work better in scenarios with many healers.


Important: This is a pre-release wiki page. The functionality described above has not actually been released yet.