Armies

Struct Armies 

Source
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

Source

pub fn new() -> Self

Creates a new empty Armies collection.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn fighter_count(&self) -> usize

Returns the total number of fighters in the collection.

Source

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
Source

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
Source

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.

Source

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§

Source§

impl Clone for Armies

Source§

fn clone(&self) -> Armies

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Armies

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Armies

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Armies

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Armies

Source§

fn eq(&self, other: &Armies) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Armies

Source§

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V