9#include "../system/system_utils.h"
15 : m_maxDepth(0), m_executedNodes(0)
31 SYSTEM_LOG <<
"[BehaviorTreeExecutor] Tree has no root node\n";
32 outTracer.RecordError(-1,
"",
"Tree has no root node",
"Critical");
33 outTracer.RecordExecutionCompleted(
false,
"No root node");
37 SYSTEM_LOG <<
"[BehaviorTreeExecutor] Starting execution of tree: " <<
btAsset.name <<
"\n";
43 outTracer.RecordExecutionCompleted(success,
44 success ?
"Tree executed successfully" :
"Tree execution failed");
46 SYSTEM_LOG <<
"[BehaviorTreeExecutor] Tree execution completed: "
58 SYSTEM_LOG <<
"[BehaviorTreeExecutor] Recursion limit exceeded (cycle detected?)\n";
67 SYSTEM_LOG <<
"[BehaviorTreeExecutor] Node " << nodeId <<
" not found in tree\n";
116 if (!
node->childIds.empty())
159 "Selector child " + std::to_string(childIndex),
160 static_cast<int32_t>(childId));
185 "Sequence failed at child " + std::to_string(childIndex),
186 static_cast<int32_t>(childId));
208 switch (
node.conditionType)
229 "Parameter: " + std::to_string(
node.conditionParam));
240 switch (
node.actionType)
259 "Params: " + std::to_string(
node.actionParam1) +
260 ", " + std::to_string(
node.actionParam2));
268 if (
node.decoratorChildId == 0)
283 for (
int i = 1;
i <
node.repeatCount; ++
i)
297 if (
node.subgraphPath.empty())
299 std::string
error =
"SubGraph node '" +
node.name +
"' has no path specified";
308 std::string
error =
"Circular reference detected: " +
node.subgraphPath;
324 SYSTEM_LOG <<
"[BehaviorTreeExecutor] Executing SubGraph: " <<
node.subgraphPath
325 <<
" (depth=" <<
m_callStack.GetDepth() + 1 <<
")\n";
338 std::string
error =
"Failed to load SubGraph: '" +
node.subgraphPath +
"'";
349 std::string
error =
"SubGraph loaded but not found in manager: '" +
node.subgraphPath +
"'";
370 SYSTEM_LOG <<
"[BehaviorTreeExecutor] SubGraph execution completed with status: "
399 default:
return "Unknown";
Native BehaviorTree execution for simulation and tracing.
@ SetMoveGoalToTarget
Move towards current target.
@ SetMoveGoalToLastKnownTargetPos
Move to last seen target position.
@ WaitRandomTime
Initialize random timer (param1=min, param2=max)
@ MoveToGoal
Execute movement to goal.
@ ClearTarget
Clear current target.
@ SendMessage
Emit event to EventQueue (param1=EventType enum)
@ PatrolPickNextPoint
Select next patrol point.
@ ChooseRandomNavigablePoint
Choose navigable point (param1=searchRadius, param2=maxAttempts)
@ AttackIfClose
Attack if in range.
@ SetMoveGoalToPatrolPoint
Move to next patrol waypoint.
@ RequestPathfinding
Request pathfinding to moveGoal via MoveIntent.
@ FollowPath
Follow the path (check progression)
BTStatus
Behavior tree node execution status.
@ Success
Node completed successfully.
@ Running
Node is currently executing.
@ Aborted
Node execution interrupted (e.g., entity destroyed)
@ Idle
Node waiting for execution (not yet started)
@ Action
Leaf node - performs an action.
@ Selector
OR node - succeeds if any child succeeds.
@ OnEvent
Phase 38b: OnEvent root - event-driven entry point (orange, event-triggered)
@ Sequence
AND node - succeeds if all children succeed.
@ SubGraph
Phase 39: SubGraph - external graph reference (recursive BT or ATS)
@ Inverter
Decorator - inverts child result.
@ Condition
Leaf node - checks a condition.
@ Repeater
Decorator - repeats child N times.
@ Root
Phase 38b: Root node - entry point of behavior tree (green, fixed position)
@ HasValidPath
Valid path calculated?
@ CanAttack
Attack is available.
@ IsWaitTimerExpired
Wait timer expired?
@ HeardNoise
Detected noise.
@ TargetVisible
Can see target entity.
@ HasMoveGoal
Movement goal is set.
@ HasNavigableDestination
Navigable destination chosen?
@ HealthBelow
Health below threshold.
@ HasReachedDestination
Reached destination?
@ TargetInRange
Target within specified range.
ComponentTypeID GetComponentTypeID_Static()
bool LoadTreeFromFile(const std::string &filepath, uint32_t treeId)
static BehaviorTreeManager & Get()
const BehaviorTreeAsset * GetTreeByAnyId(uint32_t treeId) const
BTStatus ExecuteSelector(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a Selector (OR) composite node.
static const char * StatusToString(BTStatus status)
Convert BTStatus to string for logging.
SubGraphCallStack m_callStack
Phase 39: Call stack for SubGraph recursion tracking.
BTStatus ExecuteCondition(const BTNode &node, GraphExecutionTracer &outTracer)
Execute a Condition leaf node.
BTStatus ExecuteTree(const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a BehaviorTree and collect trace information.
int m_executedNodes
Count of executed nodes.
BTStatus ExecuteNode(uint32_t nodeId, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Recursively execute a single BehaviorTree node.
BTStatus ExecuteAction(const BTNode &node, GraphExecutionTracer &outTracer)
Execute an Action leaf node.
int m_maxDepth
Track recursion depth to detect cycles.
BTStatus ExecuteSubGraph(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Phase 39: Execute a SubGraph reference node.
BTStatus ExecuteSequence(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a Sequence (AND) composite node.
BTStatus ExecuteDecorator(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Apply a Decorator (Inverter, Repeater) to a child node result.
Records execution trace during graph simulation.
< Provides AssetID and INVALID_ASSET_ID
Represents a single node in a behavior tree.
bool Contains(const std::string &path) const
void Push(const std::string &path)
static const int MAX_DEPTH
Maximum recursion depth limit.