pub struct Armies { /* private fields */ }Expand description
Manages all fighters across all teams in the game.
The Armies struct provides a centralized collection of all fighters,
indexed by their unique u64 ID. It supports adding, removing, and querying
fighters regardless of which team they belong to.
§Example
use liquidwar7core::{Armies, Fighter};
let mut armies = Armies::new();
let team_id = 0x1234567890abcdef_u64;
// Fighter::new(team_id, x, y, z, gradient_index, health)
let fighter = Fighter::new(team_id, 5.0, 5.0, 0.5, 0, 1.0);
let fighter_id = armies.add_fighter(fighter);
assert_eq!(armies.fighter_count(), 1);
assert!(armies.get_fighter(&fighter_id).is_some());Implementations§
Source§impl Armies
impl Armies
Sourcepub fn add_fighter(&mut self, fighter: Fighter) -> u64
pub fn add_fighter(&mut self, fighter: Fighter) -> u64
Adds a fighter to the collection and returns its unique ID.
A new random u64 ID is generated, with collision checking.
Sourcepub fn set_fighter(&mut self, id: u64, fighter: Fighter)
pub fn set_fighter(&mut self, id: u64, fighter: Fighter)
Inserts or updates a fighter with a specific ID.
Used for network sync where fighter IDs must match across server and clients.
Sourcepub fn remove_fighter(&mut self, id: &u64) -> Option<Fighter>
pub fn remove_fighter(&mut self, id: &u64) -> Option<Fighter>
Removes a fighter from the collection by its ID.
Returns the removed fighter if it existed, or None if not found.
Sourcepub fn get_fighter(&self, id: &u64) -> Option<&Fighter>
pub fn get_fighter(&self, id: &u64) -> Option<&Fighter>
Returns a reference to the fighter with the given ID.
Returns None if no fighter with that ID exists.
Sourcepub fn get_fighter_mut(&mut self, id: &u64) -> Option<&mut Fighter>
pub fn get_fighter_mut(&mut self, id: &u64) -> Option<&mut Fighter>
Returns a mutable reference to the fighter with the given ID.
Returns None if no fighter with that ID exists.
Sourcepub fn fighter_count(&self) -> usize
pub fn fighter_count(&self) -> usize
Returns the total number of fighters in the collection.
Sourcepub fn iter(&self, odd_even: bool) -> impl Iterator<Item = (&u64, &Fighter)>
pub fn iter(&self, odd_even: bool) -> impl Iterator<Item = (&u64, &Fighter)>
Returns an iterator over all fighters and their IDs, sorted by ID.
The sorting ensures deterministic iteration order across different program instances processing similar data.
§Arguments
odd_even- If true, reverses the sort order to avoid systematic bias
Sourcepub fn iter_mut(
&mut self,
odd_even: bool,
) -> impl Iterator<Item = (&u64, &mut Fighter)>
pub fn iter_mut( &mut self, odd_even: bool, ) -> impl Iterator<Item = (&u64, &mut Fighter)>
Returns a mutable iterator over all fighters and their IDs, sorted by ID.
The sorting ensures deterministic iteration order across different program instances processing similar data.
§Arguments
odd_even- If true, reverses the sort order to avoid systematic bias
Sourcepub fn unsorted_iter(&self) -> impl Iterator<Item = &Fighter>
pub fn unsorted_iter(&self) -> impl Iterator<Item = &Fighter>
Returns an unsorted iterator over all fighters (values only).
Use this when order doesn’t matter and you only need fighter data.
This is faster than iter() which sorts by ID.
Sourcepub fn unsorted_iter_with_ids(&self) -> impl Iterator<Item = (&u64, &Fighter)>
pub fn unsorted_iter_with_ids(&self) -> impl Iterator<Item = (&u64, &Fighter)>
Returns an unsorted iterator over all fighters with their IDs.
Use this when order doesn’t matter but you need both IDs and fighter data.
This is faster than iter() which sorts by ID.
Trait Implementations§
impl Eq for Armies
impl StructuralPartialEq for Armies
Auto Trait Implementations§
impl Freeze for Armies
impl RefUnwindSafe for Armies
impl Send for Armies
impl Sync for Armies
impl Unpin for Armies
impl UnwindSafe for Armies
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)