Skip to main content

wowlab_engine_domain/targeting/support/
algebra.rs

1use crate::targeting::TargetSelector;
2
3const TARGET_OPERATION_SLOTS: usize = 2;
4
5/// The independent selector axis responsible for a support gap.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7#[non_exhaustive]
8pub enum TargetPlanAxis {
9    Object,
10    Reference,
11    Algorithm,
12    Check,
13    Direction,
14    EffectFallback,
15}
16
17/// One precise unsupported axis in a compiled program.
18#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
19#[error("target selector {selector:?} has unsupported {axis:?} value {value}")]
20pub struct TargetPlanGap {
21    pub selector: Option<i32>,
22    pub axis: TargetPlanAxis,
23    pub value: &'static str,
24}
25
26/// Runtime-supported origin for a location or actor selection.
27#[derive(Clone, Copy, Debug, Eq, PartialEq)]
28// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
29pub enum ExecutableTargetReference {
30    Caster,
31    ExplicitTarget,
32    Source,
33    Destination,
34}
35
36/// Runtime candidate universe produced by object and relationship composition.
37#[derive(Clone, Copy, Debug, Eq, PartialEq)]
38// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
39pub enum ExecutableCandidateDomain {
40    EnemyUnits,
41}
42
43/// Runtime-supported spatial selection algorithm.
44#[derive(Clone, Copy, Debug, Eq, PartialEq)]
45// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
46pub enum ExecutableTargetAlgorithm {
47    Single,
48    ChannelTarget,
49    Radius,
50    Cone,
51    Line,
52}
53
54/// Runtime-supported algorithm for assigning a positional source or destination.
55#[derive(Clone, Copy, Debug, Eq, PartialEq)]
56// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
57pub enum ExecutableLocationAlgorithm {
58    Reference,
59    ChannelTarget,
60}
61
62/// Runtime-supported positional direction component.
63#[derive(Clone, Copy, Debug, Eq, PartialEq)]
64// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
65pub enum ExecutableTargetDirection {
66    None,
67    Front,
68    Back,
69    Right,
70    Left,
71    FrontRight,
72    BackRight,
73    BackLeft,
74    FrontLeft,
75    Random,
76}
77
78/// An executable location assignment, already lowered independently by semantic axis.
79#[derive(Clone, Copy, Debug, Eq, PartialEq)]
80pub struct ExecutableLocation {
81    pub reference: ExecutableTargetReference,
82    pub algorithm: ExecutableLocationAlgorithm,
83    pub direction: ExecutableTargetDirection,
84}
85
86/// An executable actor selection, assembled from independently lowered components.
87#[derive(Clone, Copy, Debug, Eq, PartialEq)]
88pub struct ExecutableSelection {
89    pub candidates: ExecutableCandidateDomain,
90    pub reference: ExecutableTargetReference,
91    pub algorithm: ExecutableTargetAlgorithm,
92    pub direction: ExecutableTargetDirection,
93    pub selector: TargetSelector,
94}
95
96/// One executable target-program operation.
97#[derive(Clone, Copy, Debug, Eq, PartialEq)]
98// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
99pub enum ExecutableTargetOperation {
100    AssignSource(ExecutableLocation),
101    AssignDestination(ExecutableLocation),
102    Select(ExecutableSelection),
103    SelectAndAssignDestination(ExecutableSelection),
104}
105
106/// Executable TargetA/TargetB operations in authored order.
107#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
108pub struct ExecutableTargetOperations {
109    first: Option<ExecutableTargetOperation>,
110    second: Option<ExecutableTargetOperation>,
111}
112
113impl ExecutableTargetOperations {
114    /// Creates an empty executable target-operation sequence.
115    #[must_use]
116    pub const fn new() -> Self {
117        Self {
118            first: None,
119            second: None,
120        }
121    }
122
123    /// Return both fixed DBC operation slots in authored order.
124    #[must_use]
125    pub const fn into_array(self) -> [Option<ExecutableTargetOperation>; TARGET_OPERATION_SLOTS] {
126        [self.first, self.second]
127    }
128
129    pub(super) fn push(&mut self, operation: ExecutableTargetOperation) {
130        if self.first.is_none() {
131            self.first = Some(operation);
132        } else {
133            self.second = Some(operation);
134        }
135    }
136}
137
138/// Runtime behavior when an effect has no implicit target operations.
139#[derive(Clone, Copy, Debug, Eq, PartialEq)]
140// #t(rust_non_exhaustive_on_public) the lowered runtime algebra is intentionally exhaustive
141pub enum ExecutableTargetFallback {
142    ExplicitUnit,
143    NoSelection,
144    ExplicitDestination,
145}
146
147/// Fully lowered target program consumed unchanged by combat and Forge conformance.
148#[derive(Clone, Copy, Debug, Eq, PartialEq)]
149pub struct ExecutableTargetPlan {
150    pub operations: ExecutableTargetOperations,
151    pub fallback: ExecutableTargetFallback,
152}