Skip to main content

proof_engine/behavior/
mod.rs

1//! AI Behavior subsystem — Behavior Trees, built-in nodes, and GOAP planner.
2//!
3//! # Modules
4//!
5//! | Module | Contents |
6//! |--------|----------|
7//! | [`tree`]    | Core BT engine: `BehaviorNode`, `NodeStatus`, `Blackboard`, `BehaviorTree`, `TreeBuilder`, `SubtreeRegistry` |
8//! | [`nodes`]   | Ready-to-use leaf/decorator constructors: Wait, MoveTo, LookAt, PlayAnimation, CheckDistance, CheckHealth, CheckLineOfSight, SetBlackboard, RandomSelector, WeightedSelector, and more |
9//! | [`planner`] | GOAP planner: `WorldState`, `Action`, `GoalStack`, `GoapPlanner`, `PlanExecutor`, `GoapAgent`, `ActionLibrary` |
10//!
11//! # Quick start
12//!
13//! ```ignore
14//! use proof_engine::behavior::prelude::*;
15//!
16//! // Build a simple patrol-and-attack behavior tree.
17//! let root = TreeBuilder::selector("root")
18//!     .sequence_child("attack_sequence")
19//!         .node(check_in_range("in_range", "agent_pos", "enemy_pos", 5.0))
20//!         .node(fire_at_target("fire", "can_fire", "ammo", "fire_request"))
21//!     .end()
22//!     .node(patrol_set_target(
23//!         "patrol",
24//!         vec![Vec3::ZERO, Vec3::new(10.0, 0.0, 0.0)],
25//!         "wp_idx", "agent_pos", "patrol_target", 0.5,
26//!     ))
27//!     .build();
28//!
29//! let mut tree = BehaviorTree::new("enemy_ai", root);
30//! tree.blackboard_mut().set("agent_pos", Vec3::ZERO);
31//!
32//! loop {
33//!     let status = tree.tick(0.016);
34//!     // status is Running / Success / Failure
35//!     # break;
36//! }
37//! ```
38
39pub mod tree;
40pub mod nodes;
41pub mod planner;
42
43// ── Re-exports ────────────────────────────────────────────────────────────────
44
45// Core tree types
46pub use tree::{
47    BehaviorNode,
48    BehaviorTree,
49    Blackboard,
50    BlackboardValue,
51    DecoratorKind,
52    DecoratorState,
53    NodeStatus,
54    ParallelPolicy,
55    SubtreeRegistry,
56    TreeBuilder,
57    // Convenience constructors
58    cooldown,
59    invert,
60    leaf,
61    parallel,
62    repeat,
63    selector,
64    sequence,
65    timeout,
66};
67
68// Built-in node constructors
69pub use nodes::{
70    CompareOp,
71    // Actions
72    check_distance,
73    check_health,
74    check_health_low,
75    check_health_ok,
76    check_in_range,
77    check_out_of_range,
78    check_line_of_sight,
79    check_blackboard_bool,
80    check_blackboard_float,
81    check_blackboard_exists,
82    clear_blackboard,
83    copy_blackboard,
84    cooldown_node,
85    debug_log,
86    debug_log_blackboard,
87    face_direction,
88    fail_always,
89    fire_at_target,
90    flee,
91    idle,
92    invert_node,
93    look_at,
94    melee_attack,
95    move_to,
96    move_to_2d,
97    patrol_set_target,
98    play_animation,
99    random_selector,
100    repeat_forever,
101    repeat_node,
102    set_blackboard,
103    succeed_always,
104    timeout_node,
105    wait,
106    weighted_selector,
107    blackboard_guard,
108};
109
110// GOAP planner types
111pub use planner::{
112    Action,
113    ActionEffects,
114    ActionLibrary,
115    ExecutorState,
116    GoapAgent,
117    GoapPlanner,
118    Goal,
119    GoalStack,
120    PlanError,
121    PlanExecutor,
122    PlanStep,
123    PlanStepStatus,
124    Preconditions,
125    WorldState,
126};
127
128// ── Prelude ───────────────────────────────────────────────────────────────────
129
130/// Convenience glob import: `use proof_engine::behavior::prelude::*;`
131pub mod prelude {
132    pub use super::{
133        // Tree types
134        BehaviorNode, BehaviorTree, Blackboard, BlackboardValue,
135        DecoratorKind, NodeStatus, ParallelPolicy, SubtreeRegistry, TreeBuilder,
136        // Tree constructors
137        cooldown, invert, leaf, parallel, repeat, selector, sequence, timeout,
138        // Node constructors
139        CompareOp,
140        check_distance, check_health, check_health_low, check_health_ok,
141        check_in_range, check_out_of_range, check_line_of_sight,
142        check_blackboard_bool, check_blackboard_float, check_blackboard_exists,
143        clear_blackboard, copy_blackboard, cooldown_node,
144        debug_log, debug_log_blackboard,
145        face_direction, fail_always, fire_at_target, flee, idle,
146        invert_node, look_at, melee_attack, move_to, move_to_2d,
147        patrol_set_target, play_animation,
148        random_selector, repeat_forever, repeat_node,
149        set_blackboard, succeed_always, timeout_node, wait, weighted_selector,
150        blackboard_guard,
151        // GOAP
152        Action, ActionEffects, ActionLibrary,
153        ExecutorState, GoapAgent, GoapPlanner, Goal, GoalStack,
154        PlanError, PlanExecutor, PlanStep, PlanStepStatus,
155        Preconditions, WorldState,
156    };
157    pub use glam::{Vec2, Vec3};
158}