Struct EnemyController

Source
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

Source

pub fn new( config: EnemyConfig, identity: u64, ) -> Result<EnemyController, AiError>

Source

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);
Source

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);
Source

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);
Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.