Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
BehaviorTree.h File Reference

Data-driven behavior tree system for AI decision making. More...

#include "../ECS_Entity.h"
#include "../vector.h"
#include <vector>
#include <string>
#include <cstdint>
#include <map>
+ Include dependency graph for BehaviorTree.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BTNode
 Represents a single node in a behavior tree. More...
 
struct  BTValidationMessage
 Validation message for behavior tree structure checking. More...
 
struct  BehaviorTreeAsset
 
class  BehaviorTreeManager
 

Enumerations

enum class  BTNodeType : uint8_t {
  Selector = 0 , Sequence , Condition , Action ,
  Inverter , Repeater
}
 Behavior tree node types. More...
 
enum class  BTStatus : uint8_t {
  Idle = 0 , Running = 1 , Success = 2 , Failure = 3 ,
  Aborted = 4
}
 Behavior tree node execution status. More...
 
enum class  BTConditionType : uint8_t {
  TargetVisible = 0 , TargetInRange , HealthBelow , HasMoveGoal ,
  CanAttack , HeardNoise , IsWaitTimerExpired , HasNavigableDestination ,
  HasValidPath , HasReachedDestination , HasTarget = TargetVisible , IsTargetInAttackRange = TargetInRange
}
 Built-in condition types for behavior trees. More...
 
enum class  BTActionType : uint8_t {
  SetMoveGoalToLastKnownTargetPos = 0 , SetMoveGoalToTarget , SetMoveGoalToPatrolPoint , MoveToGoal ,
  AttackIfClose , PatrolPickNextPoint , ClearTarget , Idle ,
  WaitRandomTime , ChooseRandomNavigablePoint , RequestPathfinding , FollowPath ,
  MoveTo = MoveToGoal , AttackMelee = AttackIfClose
}
 Built-in action types for behavior trees. More...
 

Functions

BTStatus ExecuteBTNode (const BTNode &node, EntityID entity, AIBlackboard_data &blackboard, const BehaviorTreeAsset &tree)
 
BTStatus ExecuteBTCondition (BTConditionType condType, float param, EntityID entity, const AIBlackboard_data &blackboard)
 
BTStatus ExecuteBTAction (BTActionType actionType, float param1, float param2, EntityID entity, AIBlackboard_data &blackboard)
 

Detailed Description

Data-driven behavior tree system for AI decision making.

Author
Nicolas Chereau
Date
2025
Version
2.0

This file implements a behavior tree system for creating complex AI behaviors. Behavior trees are hierarchical structures that make decisions based on conditions and execute actions based on those decisions.

Key features:

Note
Behavior Tree purpose: Data-driven behavior tree system for AI decision making.

Definition in file BehaviorTree.h.

Enumeration Type Documentation

◆ BTActionType

Built-in action types for behavior trees.

Predefined actions that can be executed during tree execution.

Enumerator
SetMoveGoalToLastKnownTargetPos 

Move to last seen target position.

SetMoveGoalToTarget 

Move towards current target.

SetMoveGoalToPatrolPoint 

Move to next patrol waypoint.

MoveToGoal 

Execute movement to goal.

AttackIfClose 

Attack if in range.

PatrolPickNextPoint 

Select next patrol point.

ClearTarget 

Clear current target.

Idle 

Do nothing.

WaitRandomTime 

Initialize random timer (param1=min, param2=max)

ChooseRandomNavigablePoint 

Choose navigable point (param1=searchRadius, param2=maxAttempts)

RequestPathfinding 

Request pathfinding to moveGoal via MoveIntent.

FollowPath 

Follow the path (check progression)

MoveTo 

Alias for MoveTo action.

AttackMelee 

Alias for melee attack.

Examples
/home/runner/work/Olympe-Engine/Olympe-Engine/Source/AI/BehaviorTree.h.

Definition at line 106 of file BehaviorTree.h.

◆ BTConditionType

Built-in condition types for behavior trees.

Predefined conditions that can be checked during tree execution.

Enumerator
TargetVisible 

Can see target entity.

TargetInRange 

Target within specified range.

HealthBelow 

Health below threshold.

HasMoveGoal 

Movement goal is set.

CanAttack 

Attack is available.

HeardNoise 

Detected noise.

IsWaitTimerExpired 

Wait timer expired?

HasNavigableDestination 

Navigable destination chosen?

HasValidPath 

Valid path calculated?

HasReachedDestination 

Reached destination?

HasTarget 

Alias for HasTarget condition.

IsTargetInAttackRange 

Alias for range check.

Examples
/home/runner/work/Olympe-Engine/Olympe-Engine/Source/AI/BehaviorTree.h.

Definition at line 82 of file BehaviorTree.h.

◆ BTNodeType

Behavior tree node types.

Defines the different types of nodes that can exist in a behavior tree.

Enumerator
Selector 

OR node - succeeds if any child succeeds.

Sequence 

AND node - succeeds if all children succeed.

Condition 

Leaf node - checks a condition.

Action 

Leaf node - performs an action.

Inverter 

Decorator - inverts child result.

Repeater 

Decorator - repeats child N times.

Examples
/home/runner/work/Olympe-Engine/Olympe-Engine/Source/AI/BehaviorTree.h.

Definition at line 51 of file BehaviorTree.h.

◆ BTStatus

Behavior tree node execution status.

Represents the current state of a behavior tree node.

Enumerator
Idle 

Node waiting for execution (not yet started)

Running 

Node is currently executing.

Success 

Node completed successfully.

Failure 

Node failed.

Aborted 

Node execution interrupted (e.g., entity destroyed)

Examples
/home/runner/work/Olympe-Engine/Olympe-Engine/Source/AI/BehaviorTree.h.

Definition at line 67 of file BehaviorTree.h.

Function Documentation

◆ ExecuteBTAction()

BTStatus ExecuteBTAction ( BTActionType  actionType,
float  param1,
float  param2,
EntityID  entity,
AIBlackboard_data blackboard 
)

◆ ExecuteBTCondition()

BTStatus ExecuteBTCondition ( BTConditionType  condType,
float  param,
EntityID  entity,
const AIBlackboard_data blackboard 
)

◆ ExecuteBTNode()

BTStatus ExecuteBTNode ( const BTNode node,
EntityID  entity,
AIBlackboard_data blackboard,
const BehaviorTreeAsset tree 
)

Definition at line 398 of file BehaviorTree.cpp.

References Action, Condition, ExecuteBTAction(), ExecuteBTCondition(), ExecuteBTNode(), Failure, GetComponentTypeID_Static(), Inverter, Repeater, Running, Selector, Sequence, and Success.

Referenced by ExecuteBTNode(), and BehaviorTreeSystem::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: