find_path_to_entity starts an asynchronous pathfinder and when a valid path is found, declares that it's ready with the path as its think output this path is often passed as an argument to a subsequent follow_path activity). it's performing a step in a compound action). Each action can then (often asynchronously) decide when it is ready to run, and provide "think output" that can be used as input to later steps if this action is performing a part of a sequence (i.e. When the AI component wants to perform an activity, it asks all the actions that implement that activity to start thinking. Making plans - Deciding whether an action is ready to run. This is an implementation detail, and there's only one TaskAction class, so it can mostly be ignored.Ĭharacter behavior is generally configured by the set of actions that they "know", specified through "AI packs", described in more detail later in this guide. Task action - An action which runs each task instance in a task group.farming_task_group involves tilling ( stonehearth:till_entire_field), planting ( stonehearth:plant_crop), or harvesting ( stonehearth:harvest_field), and specifies how these three activities compete against each other in terms of utility (see "comparing plans" below). This is the only place where different activities compete with each other, so the task group declaration allows you to remap their utility values or ranges. Systems outside the AI control which of these tasks are active at a given time, and task groups allow these systems to ask multiple characters to perform some action. Task group action - An action that runs one of a list of declared tasks (activities).heal_self_action consists of (1) getting a healing item (a stonehearth:goto_item_made_of activity with a material argument set to "healing_item"), (2) reserving that item so other characters don't grab it (a stonehearth:reserve_entity activity with the item selected in the previous step passed as an argument), and finally (3) self-healing with that item (a stonehearth:heal_entity_adjacent activity with the entity itself as the target and the item reserved in the previous step as the item to apply). Executing a compound action involves finding a valid action that performs each step's activity and executing all these actions in order. Compound action - An action that is composed of a list of steps, each of which is an activity with optional argument bindings.A Lua file that has a run() method that executes the action's logic. Leaf action - The simplest type of action.
#Stonehearth mods 2017 how to#
Ready to be executed and what relevant state it expects to change if executed, (3) and how to "run" it, i.e. how good it is, (2) how to "think" it, i.e. An action is responsible for telling the AI system (1) its "utility", i.e.
#Stonehearth mods 2017 code#
In the code we express this by saying that the action "does" the given activity string. At its core, all the AI component does is to continuously try to perform the stonehearth:top activity.Īction - A specific implementation of an activity. the stonehearth:find_path_to_entity activity takes the entity to path to as an argument. A not-necessarily-up-to-date list of activities can be found in stonehearth/ai/a. Activities are represented as strings, conventionally in the form mod_name:verb, e.g. For example, if "get food" is an activity, "get food from stockpile", "get food from backpack", and "hunt wild animal" may all be implementations of the "get food" activity. Intelligent entities include hearthlings, enemy mobs, pets, critters, and even turrets, although the rest of this page uses "character" to refer to any of these entities.Īctivity - A behavior that can have multiple implementations. This component runs a Lua thread (a coroutine managed by the thread class), which continuously evaluates a tree of plans and executes a branch of it. Intelligent entity - An entity that has a stonehearth:ai component. Let's unpack that formal definition and map it to the terms used in the implementation: Many potential plans are typically being considered at a time, most of which are not ready to execute, or are suboptimal, and the AI constantly selects the one best plan to execute at any given time. Intelligent entities in Stonehearth run a hierarchical task network to perform activities by making, comparing, and executing plans made up of actions. They're still mostly valid, and might help you understand how the AI works with a practical/visual example. There's also the old notes about AI in this other PDF. You can find all the information from this page in this PDF.