Warning: Undefined array key 1 in /customers/3/5/3/eej.dk/httpd.www/community/authentication.php on line 29 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/5/3/eej.dk/httpd.www/community/authentication.php:29) in /customers/3/5/3/eej.dk/httpd.www/community/include.php on line 67 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/5/3/eej.dk/httpd.www/community/authentication.php:29) in /customers/3/5/3/eej.dk/httpd.www/community/include.php on line 68 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/5/3/eej.dk/httpd.www/community/authentication.php:29) in /customers/3/5/3/eej.dk/httpd.www/community/include.php on line 69 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/5/3/eej.dk/httpd.www/community/authentication.php:29) in /customers/3/5/3/eej.dk/httpd.www/community/include.php on line 70 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/5/3/eej.dk/httpd.www/community/authentication.php:29) in /customers/3/5/3/eej.dk/httpd.www/community/include.php on line 71 Warning: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent in /customers/3/5/3/eej.dk/httpd.www/community/authentication.php on line 50 Warning: session_start(): Session cannot be started after headers have already been sent in /customers/3/5/3/eej.dk/httpd.www/community/authentication.php on line 51 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/5/3/eej.dk/httpd.www/community/authentication.php:29) in /customers/3/5/3/eej.dk/httpd.www/community/index.php on line 51 Patterns -

Abstraction

While the goal of Behave keeps it at a highly abstract level of operation, there are many simple to implement, yet powerful patterns of use.

A common pattern is that your agent class is also the one ticking its behaviour tree instance(s) at a frame rate. Through the Behave tree designer UI, a designer can link a different frame rate to each tree. This has no direct practical implication at runtime though. Its purpose is merely to communicate a desire from designer to implementer.

Not being limited to frame rate execution, ticks could just as well occur in response to an event – be that a game / simulation event or even an action handler invocation from another tree. Again, note that any agent can have multiple trees associated with it.

Embedding

An example of such non-frame-rate ticks could be for use in intelligent items. These are items with embedded behaviour trees – ticked by item consumers when needed. In a game, such an item might be a weapon.

The agent would have a reference to its currently equipped weapon and in response to action ticks from its main tree, tick relevant trees referenced by the weapon and return the result as the action result.

Aside from the obvious “attack” action / embedded tree combination, these could also be availability and range checks.

Selection

A more simple case would be the agent implementation of a dynamic or “lookup” selector. In some cases, branch selection is not simple enough that is can be expressed in simple control nodes – more state awareness is required.

In such a case, an agent might hold a collection of trees in addition to its main tree. On tick / init or reset of certain actions, the agent would then pick an appropriate tree from the collection (based on agent state) and invoke the appropriate handler on that.

This can be particularly useful if, like with embedding, the agent needs to be able to receive certain behaviour for execution at runtime, relevant in only a specific scenario or section of simulation duration.

In the case of a game, such behaviour could be related to dynamic quest or story systems or crowd simulations where characters are dynamically moved between low-cost milling behaviour and more costly, interactive behaviours.

Delegation

Action forwards allow for events from multiple actions to be handled by the same handler which could be implemented by the same agent or an entirely different class.

One use case for this could be a squad system which uses agents based on the selection pattern to assign task trees to agents in a squad. Trees which upon task completion need to inform the squad system at certain points in task execution – such as start and end.

By using action forwards on the task trees, the squad system can ensure low complexity agent class while preserving the ability to do extensive special casing of task events.

Inheritance

An added advantage of the low level interface of the Behave runtime is the availability of powerful language constructs such as class inheritance.

Since agents are classes and action handlers are methods, virtual from an agent blueprint or dynamically mapped via introspection, deep agent specialization can be achieved from one base agent class using the same main tree.

Say for instance you have a base soldier agent class which creates and stores an instance of a base soldier tree for use as its main tree – ticked at a specific frame-rate and with default handlers for all actions.

Such a tree would probably contain a standard structure for a rudimentary sustain, attack, investigate behaviour.

You implement the basic soldier agent to perform these tasks to the letter and that is all groovy. However, later you discover a need for a more advanced soldier, say a commando, and you would really prefer not to have to duplicate all of that work.

Luckily your actions are described in quite abstract terms, so in stead of duplicating, you make sure that the action handlers on your base soldier agent class are marked as virtual – after which you create a new commando agent class – deriving from the soldier agent class.

In this new agent class, you can then override the action handlers which need specialization and implement alternative behaviour for them. Perhaps such behaviour could even be ticking an entirely different tree.