pub struct EnemyController { /* private fields */ }Expand description
Constant-space controller. Identity supplies a deterministic strafe phase; no random global state, heap allocation, renderer, transport or damage access.
Implementations§
Source§impl EnemyController
impl EnemyController
pub fn new( config: EnemyConfig, identity: u64, ) -> Result<EnemyController, AiError>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clear target, reaction, recovery, movement history and inspection status. Restores the original identity’s strafe phase, as for a fresh controller. Death applies this same reset before returning a dead intention.
use ferravex_play::ai::{EnemyConfig, EnemyController};
let mut enemy = EnemyController::new(EnemyConfig::ranged(), 7).unwrap();
let initial = enemy.status();
enemy.reset();
assert_eq!(enemy.status(), initial);Sourcepub fn status(&self) -> EnemyStatus
pub fn status(&self) -> EnemyStatus
Inspect reaction windup and recovery without producing attack requests. The timers may overlap after a target change. A zero windup does not imply that firing is possible: inspect the phase and the returned tick intention.
use ferravex_play::ai::{EnemyAttackPhase, EnemyConfig, EnemyController, EnemyStatus};
let enemy = EnemyController::new(EnemyConfig::ranged(), 7).unwrap();
let status: EnemyStatus = enemy.status();
assert_eq!(status.phase, EnemyAttackPhase::Inactive);
assert_eq!(status.target, None);
assert_eq!(status.windup_remaining, 0.0);
assert_eq!(status.recovery_remaining, 0.0);
assert!(!status.target_visible);Sourcepub fn cancel_target(&mut self) -> Option<u64>
pub fn cancel_target(&mut self) -> Option<u64>
Forget the selected target and pending reaction, returning its identity. Recovery is preserved, so cancellation cannot bypass attack cadence. Movement/stall history is cleared; the deterministic strafe phase remains. The host must also remove invalid tracks from its memory/input, or a later tick can select that identity again and begin a new reaction.
use ferravex_math::Vec3;
use ferravex_play::ai::*;
let mut memory = Memory::new(MemorySettings::default()).unwrap();
memory.observe(Candidate { id: 9, position: Vec3::Z * 10.0, groups: 1 }, Sense::Sight).unwrap();
let mut enemy = EnemyController::new(EnemyConfig::ranged(), 7).unwrap();
enemy.tick(EnemyInput {
position: Vec3::ZERO, forward: Vec3::Z, up: Vec3::Y,
patrol_goal: Vec3::ZERO, target: memory.best(1).copied(),
health_fraction: 1.0, weapon_ready: true, alive: true,
}, 0.1).unwrap();
assert_eq!(enemy.cancel_target(), Some(9));
assert_eq!(enemy.status().lost_target, Some(9));
assert_eq!(enemy.status().phase, EnemyAttackPhase::Inactive);
assert_eq!(enemy.status().target, None);
memory.forget(9);Sourcepub fn tick(
&mut self,
input: EnemyInput,
dt: f32,
) -> Result<EnemyIntent, AiError>
pub fn tick( &mut self, input: EnemyInput, dt: f32, ) -> Result<EnemyIntent, AiError>
Apply a fixed simulation delta in 0..=1 seconds. Zero observes input
transitions but advances no timers and never requests attack or replanning.
Invalid input returns AiError::InvalidInput without changing state.