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 <algorithm>
#include <set>
+ 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
 
struct  SubGraphCallStack
 
class  BehaviorTreeManager
 

Enumerations

enum class  BTNodeType : uint8_t {
  Selector = 0 , Sequence , Condition , Action ,
  Inverter , Repeater , Root , OnEvent ,
  SubGraph = 8
}
 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 ,
  SendMessage , 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)
 
void TickEventRoots (class EventQueue &eventQueue, const BehaviorTreeAsset &tree, 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)

SendMessage 

Emit event to EventQueue (param1=EventType enum)

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 111 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 87 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.

Root 

Phase 38b: Root node - entry point of behavior tree (green, fixed position)

OnEvent 

Phase 38b: OnEvent root - event-driven entry point (orange, event-triggered)

SubGraph 

Phase 39: SubGraph - external graph reference (recursive BT or ATS)

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

Definition at line 53 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 72 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 450 of file BehaviorTree.cpp.

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

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

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

◆ TickEventRoots()

void TickEventRoots ( class EventQueue eventQueue,
const BehaviorTreeAsset tree,
EntityID  entity,
AIBlackboard_data blackboard 
)

Definition at line 1575 of file BehaviorTree.cpp.

References ExecuteBTNode(), GetComponentTypeID_Static(), Olympe_EventType_AI_DamageDealt, Olympe_EventType_AI_Explosion, Olympe_EventType_AI_Noise, Olympe_EventType_Object_Create, and Olympe_EventType_Object_Destroy.

Referenced by BehaviorTreeSystem::Process().

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