Skip to main content

euv_core/game/algorithms/ai/
enum.rs

1use super::*;
2
3/// Execution status returned by every `BehaviorTree` node on tick.
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
5pub enum BtStatus {
6    /// Node is still executing and will resume on the next tick.
7    Running,
8    /// Node completed its task successfully.
9    #[default]
10    Success,
11    /// Node failed its condition or action.
12    Failure,
13}
14
15/// Typed value stored inside a `BehaviorTree` `Blackboard`.
16#[derive(Clone, Debug, PartialEq)]
17pub enum BtValue {
18    /// Boolean flag value.
19    Bool(bool),
20    /// Signed 64-bit integer value.
21    Int(i64),
22    /// 32-bit floating-point scalar value.
23    Float(f32),
24    /// 2D spatial vector value.
25    Vec2(Vec2),
26    /// 3D spatial vector value.
27    Vec3(Vec3),
28    /// Owned UTF-8 text value.
29    Text(String),
30}
31
32/// Completion policy for `BehaviorTree` parallel composite nodes.
33#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
34pub enum BtParallelPolicy {
35    /// Succeeds when all children succeed; fails as soon as any child fails.
36    #[default]
37    RequireAll,
38    /// Succeeds as soon as any child succeeds; fails only when all children fail.
39    RequireOne,
40    /// Succeeds once at least `usize` children succeed; fails if remaining cannot reach threshold.
41    Threshold(usize),
42}
43
44/// Decorator operation wrapping a single child node in a `BehaviorTree`.
45#[derive(Clone, Debug, PartialEq)]
46pub enum BtDecoratorKind {
47    /// Flips `Success <-> Failure` while preserving `Running`.
48    Inverter,
49    /// Repeats child up to `usize` times (`0` repeats indefinitely until failure).
50    Repeater(usize),
51    /// Enforces a cooldown duration in seconds before allowing child re-entry after completion.
52    Cooldown(f32),
53    /// Requires blackboard boolean `key == expected` before ticking child, returning `Failure` otherwise.
54    Guard {
55        /// Blackboard key name checked before executing child.
56        key: String,
57        /// Required boolean value for the guard to pass.
58        expected: bool,
59    },
60}
61
62/// Structural node variant inside an arena-indexed `BehaviorTree`.
63#[derive(Clone, Debug, PartialEq)]
64pub enum BtNodeKind {
65    /// Executes children in order until one fails or runs.
66    Sequence(Vec<usize>),
67    /// Executes children in order until one succeeds or runs.
68    Selector(Vec<usize>),
69    /// Executes all children concurrently under `policy`.
70    Parallel {
71        /// Child node indices ticked together.
72        children: Vec<usize>,
73        /// Success/failure aggregation policy.
74        policy: BtParallelPolicy,
75    },
76    /// Wraps a single child node with `kind`.
77    Decorator {
78        /// Decorator behavior specification.
79        kind: BtDecoratorKind,
80        /// Child node index.
81        child: usize,
82    },
83    /// Evaluates user condition callback `condition_id` returning `Success` or `Failure`.
84    Condition(u32),
85    /// Executes user action callback `action_id` returning `BtStatus`.
86    Action(u32),
87}
88
89/// Lifecycle notification emitted by `HierarchicalFsm` during transitions and updates.
90#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
91pub enum HfsmLifecycleEvent {
92    /// State `u32` was entered top-down.
93    Enter(u32),
94    /// State `u32` was ticked during `update`.
95    Update(u32),
96    /// State `u32` was exited bottom-up.
97    Exit(u32),
98}
99
100/// Mathematical response curve shaping normalized `[0.0, 1.0]` consideration inputs in `UtilityAiBrain`.
101#[derive(Clone, Copy, Debug, PartialEq)]
102pub enum UtilityCurveKind {
103    /// Clamped affine ramp `(slope * x + intercept).clamp(0, 1)`.
104    Linear {
105        /// Ramp slope.
106        slope: f32,
107        /// Vertical intercept.
108        intercept: f32,
109    },
110    /// Power curve `x^exponent` (or `1 - x^exponent` when `invert` is true).
111    Quadratic {
112        /// Positive polynomial exponent.
113        exponent: f32,
114        /// Whether to invert output as `1.0 - x^exponent`.
115        invert: bool,
116    },
117    /// S-shaped logistic sigmoid `1 / (1 + exp(-steepness * (x - midpoint)))`.
118    Logistic {
119        /// Transition slope around `midpoint`.
120        steepness: f32,
121        /// Inflection midpoint in `[0.0, 1.0]`.
122        midpoint: f32,
123    },
124    /// Normalized exponential growth `(exp(base_power * x) - 1) / (exp(base_power) - 1)`.
125    Exponential {
126        /// Curvature rate (positive = convex rise, negative = concave rise).
127        base_power: f32,
128    },
129}