pub struct SquadBoard<const C: usize> { /* private fields */ }Implementations§
Source§impl<const C: usize> SquadBoard<C>
impl<const C: usize> SquadBoard<C>
pub fn new(cover: [Vec3; C]) -> Result<SquadBoard<C>, AiError>
Sourcepub fn report(&mut self, candidate: Candidate) -> Result<(), AiError>
pub fn report(&mut self, candidate: Candidate) -> Result<(), AiError>
Call only for a validated fresh observation, never for a radio echo.
pub fn contact(&self) -> Option<RadioContact>
pub fn forget(&mut self)
Sourcepub fn advance(&mut self, dt: f32) -> Result<(), AiError>
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.
Sourcepub fn reservations(&self) -> impl Iterator<Item = CoverReservation>
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());Sourcepub fn retain_reservations(
&mut self,
keep: impl FnMut(CoverReservation) -> bool,
) -> usize
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));pub fn release(&mut self, owner: u64)
Sourcepub 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>
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>
impl<const C: usize> Clone for SquadBoard<C>
Source§fn clone(&self) -> SquadBoard<C>
fn clone(&self) -> SquadBoard<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more