Struct SquadBoard

Source
pub struct SquadBoard<const C: usize> { /* private fields */ }

Implementations§

Source§

impl<const C: usize> SquadBoard<C>

Source

pub fn new(cover: [Vec3; C]) -> Result<SquadBoard<C>, AiError>

Source

pub fn report(&mut self, candidate: Candidate) -> Result<(), AiError>

Call only for a validated fresh observation, never for a radio echo.

Source

pub fn contact(&self) -> Option<RadioContact>

Source

pub fn forget(&mut self)

Source

pub fn advance(&mut self, dt: f32) -> Result<(), AiError>

Age contacts and leases by supplied simulation seconds.

Call once per actual fixed tick, including while a local menu is open if authoritative simulation continues. Leases expire when their remaining time reaches zero; contacts expire at three seconds. Inspection and retention do not advance time. Nonfinite dt or values outside 0..=60 return AiError::InvalidInput without changing the board.

Source

pub fn reservations(&self) -> impl Iterator<Item = CoverReservation>

Inspect active cover leases in the original cover-array order.

Visits at most C slots without allocation, queries or timer changes. An owner has at most one lease, and duplicate cover points appear at most once. Use find to inspect a particular member’s lease.

use ferravex_math::Vec3;
use ferravex_play::ai::{CoverReservation, SquadBoard, VisibilityQuery, WorkBudget};
struct Wall;
impl VisibilityQuery for Wall {
    fn clear(&mut self, _: Vec3, _: Vec3) -> bool { false }
}
let mut board = SquadBoard::new([Vec3::X]).unwrap();
board.reserve(7, Vec3::ZERO, Vec3::Z,
    &mut WorkBudget::new(1, 1, 0), &mut Wall, |_| true).unwrap();
board.advance(0.5).unwrap();
let lease: CoverReservation = board.reservations().find(|r| r.owner == 7).unwrap();
assert_eq!(lease.position, Vec3::X);
assert_eq!(lease.remaining_seconds, 1.0);
board.advance(1.0).unwrap();
assert!(board.reservations().next().is_none());
Source

pub fn retain_reservations( &mut self, keep: impl FnMut(CoverReservation) -> bool, ) -> usize

Immediately release leases for which keep returns false, returning the number released. For example, remove members that left the squad or whose reserved cover is no longer reachable.

Calls keep once per active lease in original cover-array order, at most C times. This scan allocates nothing and performs no visibility queries; the host controls any work in keep. Retained leases keep their remaining lifetime, and radio contacts are unchanged. This does not replace calling Self::advance each simulation tick. Call before new reservations when departed members’ cover should be immediately available to their peers.

use ferravex_math::Vec3;
use ferravex_play::ai::{SquadBoard, VisibilityQuery, WorkBudget};
struct Wall;
impl VisibilityQuery for Wall {
    fn clear(&mut self, _: Vec3, _: Vec3) -> bool { false }
}
let mut board = SquadBoard::new([Vec3::X, Vec3::Z]).unwrap();
for owner in [7, 8] {
    board.reserve(owner, Vec3::ZERO, Vec3::Y,
        &mut WorkBudget::new(2, 2, 0), &mut Wall, |_| true).unwrap();
}
let active_members = [8]; // Member 7 departed without explicitly releasing.
assert_eq!(board.retain_reservations(|r| active_members.contains(&r.owner)), 1);
assert_eq!(board.reserve(9, Vec3::ZERO, Vec3::Y,
    &mut WorkBudget::new(2, 2, 0), &mut Wall, |_| true).unwrap(), Some(Vec3::X));
Source

pub fn release(&mut self, owner: u64)

Source

pub fn reserve( &mut self, owner: u64, from: Vec3, threat: Vec3, budget: &mut WorkBudget, query: &mut impl VisibilityQuery, eligible: impl FnMut(Vec3) -> bool, ) -> Result<Option<Vec3>, AiError>

Tests at most C candidates and one occlusion query per eligible point. eligible performs cheap host checks; a successful path is still required. Equal distances prefer the first cover-array entry; duplicate points are considered only at their first entry. Success replaces the owner’s old lease with a 1.5-second lease. Failure leaves any existing lease unchanged, including its remaining lifetime.

Trait Implementations§

Source§

impl<const C: usize> Clone for SquadBoard<C>

Source§

fn clone(&self) -> SquadBoard<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const C: usize> Debug for SquadBoard<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const C: usize> Freeze for SquadBoard<C>

§

impl<const C: usize> RefUnwindSafe for SquadBoard<C>

§

impl<const C: usize> Send for SquadBoard<C>

§

impl<const C: usize> Sync for SquadBoard<C>

§

impl<const C: usize> Unpin for SquadBoard<C>

§

impl<const C: usize> UnwindSafe for SquadBoard<C>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.