Skip to content

Commit

Permalink
Some tree views for examples (#354)
Browse files Browse the repository at this point in the history
* added treeview example to selector page

* added sequence example treeview

* added simple parallel example treeview

* fixed inconsistency in simple parallel

* links in example trees now lead to top of the page

* added examples treeviews for inverter and untilfail

* improved untilfail decorator example
  • Loading branch information
suhankins authored Sep 18, 2024
1 parent f7b90cf commit b89ed98
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 3 deletions.
45 changes: 45 additions & 0 deletions docs/assets/icons/until_fail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 114 additions & 1 deletion docs/manual/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,69 @@ A `Succeeder` node will always return a `SUCCESS` status code, no matter the out
## Inverter
An `Inverter` node reverses the outcome of its child node. It returns `FAILURE` if its child returns a `SUCCESS` status code, and `SUCCESS` if its child returns a `FAILURE` status code. This is useful when you want to negate a condition or invert the result of an action.

**Example:** An NPC is patrolling an area and should change its path if it *doesn't* detect an enemy.
**Example:** Instead of creating separate conditions like "guards sees an enemy" and "guard doesn't see an enemy", you could create just 1, and then invert it.

<ul style="list-style: none;">
<li>
<img src="assets/icons/tree.svg" width="18px"/>
BeehaveTree
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/selector?id=selector-node"><img src="assets/icons/selector.svg" width="18px"/></a>
SelectorComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/decorators?id=inverter"><img src="assets/icons/inverter.svg" width="18px"/></a>
InverterDecorator
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
SeesEnemy
</li>
</ul>
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
Patrol
</li>
</ul>
</li>
</ul>
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite2
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
SeesEnemy
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
Attack
</li>
</ul>
</li>
</ul>
</li>
</li>
</ul>

## Limiter
The `Limiter` node executes its `RUNNING` child a specified number of times (x). When the maximum number of ticks is reached, it returns a `FAILURE` status code. The limiter resets its counter after its child returns either `SUCCESS` or `FAILURE`.
Expand Down Expand Up @@ -45,3 +107,54 @@ The `Cooldown` node executes its child until it either returns `SUCCESS` or `FAI
The `UntilFail` node executes its child and returns `RUNNING` as long as it returns either `RUNNING` or `SUCCESS`. If its child returns `FAILURE`, it will instead return `SUCCESS`.

**Example:** A turret fires upon any NPC in range until it does not detect any more NPCs.

<ul style="list-style: none;">
<li>
<img src="assets/icons/tree.svg" width="18px"/>
BeehaveTree
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/decorators?id=untilfail"><img src="assets/icons/until_fail.svg" width="18px"/></a>
UntilFailDecorator
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
DetectsNPCs
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
Shoot
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
NoOneLeftToShootSequence
</li>
<li>
<ul style="list-style: none;">
<li>...</li>
</ul>
</li>
</li>
</ul>
</li>
</ul>
77 changes: 77 additions & 0 deletions docs/manual/selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,83 @@ Imagine an enemy character that should decide between different actions based on

The enemy will choose the first successful option, and the Selector node will return `SUCCESS`. If none of the conditions are met, the Selector node will return `FAILURE`.

<ul style="list-style: none;">
<li>
<img src="assets/icons/tree.svg" width="18px"/>
BeehaveTree
</li>
<ul style="list-style: none;">
<li>
<a href="#/manual/selector?id=selector-node"><img src="assets/icons/selector.svg" width="18px"/></a>
SelectorComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
IsPlayerFarAway
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
PatrolTheArea
</li>
</ul>
</li>
</ul>
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite2
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
IsPlayerClose
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
AttackPlayer
</li>
</ul>
</li>
</ul>
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite3
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
IsPlayerClose
</li>
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
IsHPLow
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
Retreat
</li>
</ul>
</li>
</ul>
</li>
</ul>
</ul>

### Example 2: NPC Reactions
An NPC in your game should react differently based on the player's reputation. You can use a Selector node with the following child nodes:

Expand Down
38 changes: 38 additions & 0 deletions docs/manual/sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,44 @@ Imagine you want a guard character to follow a patrol route. You can use a Seque

The guard will follow this sequence, and if all actions are successful, the Sequence node will return `SUCCESS`.

<ul style="list-style: none;">
<li>
<img src="assets/icons/tree.svg" width="18px"/>
BeehaveTree
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
MoveToPointA
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
WaitFor2Seconds
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
MoveToPointB
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
WaitFor2Seconds2
</li>
</ul>
</li>
</ul>
</li>
</ul>

Instead of creating a custom action for waiting, you could use <a href="#/manual/decorators?id=delayer">Delayer</a> decorator.


### Example 2: NPC Conversation
An NPC in your game should have a conversation with the player when they approach. You can use a Sequence node with the following child nodes:

Expand Down
43 changes: 41 additions & 2 deletions docs/manual/simple_parallel.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,50 @@ Here are some example scenarios to help you understand the Sequence node better:
### Example: While attacking the enemy, move toward the enemy
Imagine you want a ranged enemy character trying to shoot you whenever he can while to move towards you. You can use a Simple Parallel node with the following child nodes architecture:

1. Move to point A near player
1. Move to player
2. Sequence Node
1. Check if enemy can shoot
2. Shoot

The enemy will move to a location near player and try to shoot at same time, and if move action is successful or failure, the Simple Parallel node will termitate the child sequence node for shooting attempt, then return `SUCCESS` or `FAILURE` according to move action result.
The enemy will move to a player and try to shoot at same time, and if move action is successful or failure, the Simple Parallel node will termitate the child sequence node for shooting attempt, then return `SUCCESS` or `FAILURE` according to move action result.

<ul style="list-style: none;">
<li>
<img src="assets/icons/tree.svg" width="18px"/>
BeehaveTree
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/simple_parallel"><img src="/beehave/assets/icons/simple_parallel.svg" width="18px"/></a>
SimpleParallel
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
MoveToPlayer
</li>
<li>
<a href="#/manual/sequence?id=sequence-node"><img src="assets/icons/sequence.svg" width="18px"/></a>
SequenceComposite
</li>
<li>
<ul style="list-style: none;">
<li>
<a href="#/manual/condition_leaf?id=condition-leaf"><img src="assets/icons/condition.svg" width="18px"/></a>
CanShoot
</li>
<li>
<a href="#/manual/action_leaf?id=action-leaf-node"><img src="assets/icons/action.svg" width="18px"/></a>
Shoot
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

Simple Parallel can be nested to create complex behaviors while it's not suggested, because too much nesting would make it hard to maintain your behavior tree.

0 comments on commit b89ed98

Please sign in to comment.