A strong implementation of a BehaviorTree system in pure Lua, useful for implementing Artificial Intelligence in many domains (robotic, games, etc...), and with support of XML language.
You just need to clone or download this project as zip to get the source files. Once you have these sources somewhere in your project, import the /LuaBehaviorTree/src/BehaviorTree.lua file, or just the /LuaBehaviorTree/src directory (only if you have ?/init.lua in your search path.) where you want to use the library.
local BehaviorTree = require "LuaBehaviorTree.src.BehaviorTree";TODO
This BehaviorTree implementation comes with a predefined set of nodes, which are largely sufficient to build any custom nodes.
Node: The base implementation of every nodes.Action: The base implementation of every leaf nodes (actions).BranchNode: The base implementation of every branch nodes.DecoratorNode: The base implementation of every decorator nodes.
EmitEvent: A node used to emit a specific event giving its name. Returnssuccesswhen the event is emitted, andfailureotherwise.Return: A node used to return a value (success,failure, orrunning) directly in the behavior tree.
Fallback: A node which executes sequentially all of its children until one of then return asuccessstate. Returnssuccessif one of its children returnssuccess, returnsfailureif all children has returnedfailure, returnsrunningif the current executing child returnsrunning.Random: A node which pick randomly only one of its children and execute it. Returns the same result as the executing child.ReactiveFallback: A node which executes each child nodes sequentially until one node returnssuccess, then, itself returnssuccess. If every child nodes returnsfailure, theReactiveFallbacknode returnsfailure. If a node returnsrunning, the whole sequence is restarted to the first child.ReactiveSequence: A node which executes each child nodes sequentially until one node returnsfailure, or all nodes returnssuccess. If every child nodes returnssuccess, theReactiveSequencenode returnssuccesstoo, otherwisefailure. If a node returnsrunning, the whole sequence is restarted to the first child.Sequence: A node which executes each child nodes sequentially until one node returnsfailure, or all nodes returnssuccess. If every child nodes returnssuccess, theSequencenode returnssuccesstoo, otherwise returnsfailure.SequenceStar: ASequencenode used when you don't want to tick children again that already returnedsuccess.
ForceFailureNode: A node which will always returnfailurewhatever its child node returns.ForceSuccessNode: A node which will always returnsuccesswhatever its child node returns.InvertorNode: A node which will returnsuccesswhen its child returnsfailure, andfailurewhen its child returnsuccess. This node will returnrunningif its child returnsrunning.RepeatNode: A node which will repeat the execution of its child for a given number of times. Returnssuccesswhen it reach the given amount of iterations, andrunningif its child returnsrunningduring an iteration.RepeatUntilFailureNode: A node which will repeat for a maximum number of times the execution of its child until this last one returnsfailure. If the child node returnfailurebefore the maximum iteration count is reached, theRepeatUntilFailureNodereturnssuccess, otherwise returnsfailure.RepeatUntilSuccessNode: A node which will repeat for a maximum number of times the execution of its child until this last one returnssuccess. If the child node returnsuccessbefore the maximum iteration count is reached, theRepeatUntilSuccessNodereturnssuccess, otherwise returnsfailure.
StateMachine: TheStateMachinenode is a composite node allowed to have one or more children. The children of aStateMachinenode must all beStatenodes. Only oneStatenode is allowed to run at a time and the first one defined (the first child node) is the first one to run. The current status of aStateMachinenode is the same as the child that is currently selected to run.State: TheStatenode is the basic block of aStateMachinenode. EachStatenode must have aBehaviorTreenode and may also have aTransitionsblock. AStatenode runs the content of itsBehaviorTreenode and can transit to another state (or itself) as specified in theTransitionsblock. If aStatenode transits into itself while running, it will first be terminated, re-initialized, and then updated again.Transition: TheTransitionnode is used in theStatenode to define the set of transitions from/to other states in the same parentStateMachinenode.
BehaviorTree: The topmost node of each behavior tree created using this library. Can only have one root node, and may content a set of properties, events, and subtrees.Events(XML only): A node having a set ofEventnodes.Event(XML only): A node used to create a behavior tree event.Properties(XML only): A node having a set ofPropertynodes.Property(XML only): A node used to create a behavior tree property.Root(XML only): A node used to define the root node of the behavior tree. Can only have one child.SubTrees(XML only): A node having a set ofSubTreenodes.SubTree: A node used to create a behavior tree subtree. Since this node can be used outside of an XML context, it's mostly useful (and also makes sense) in XML to create a composite node using other nodes.