pub struct SpawnTable { /* private fields */ }Expand description
A weighted spawn table.
Usage:
let mut table = SpawnTable::new();
table.add(SpawnEntry::new("goblin", "Goblin", SpawnTier::Common));
table.add(SpawnEntry::new("orc", "Orc", SpawnTier::Uncommon).with_depth(3, u32::MAX));
let result = table.roll(&mut rng, 5);Implementations§
Source§impl SpawnTable
impl SpawnTable
pub fn new() -> Self
pub fn add(&mut self, entry: SpawnEntry) -> &mut Self
Sourcepub fn add_many(&mut self, entries: Vec<SpawnEntry>) -> &mut Self
pub fn add_many(&mut self, entries: Vec<SpawnEntry>) -> &mut Self
Add multiple entries from a slice.
Sourcepub fn roll_one(
&self,
rng: &mut Rng,
depth: u32,
tag: Option<&str>,
) -> Option<&SpawnEntry>
pub fn roll_one( &self, rng: &mut Rng, depth: u32, tag: Option<&str>, ) -> Option<&SpawnEntry>
Roll for a single spawn at depth, optionally filtered by tag.
Sourcepub fn roll(&self, rng: &mut Rng, n: usize, depth: u32) -> Vec<SpawnResult>
pub fn roll(&self, rng: &mut Rng, n: usize, depth: u32) -> Vec<SpawnResult>
Roll for n spawns at depth. May return fewer if table is small.
Sourcepub fn roll_guaranteed(
&self,
rng: &mut Rng,
depth: u32,
tiers: &[SpawnTier],
) -> Vec<SpawnResult>
pub fn roll_guaranteed( &self, rng: &mut Rng, depth: u32, tiers: &[SpawnTier], ) -> Vec<SpawnResult>
Roll guaranteeing at least one entry from each tier in tiers.
Sourcepub fn by_tag(&self, tag: &str) -> Vec<&SpawnEntry>
pub fn by_tag(&self, tag: &str) -> Vec<&SpawnEntry>
Get all entries with a given tag.
Sourcepub fn available_at_depth(&self, depth: u32) -> Vec<&SpawnEntry>
pub fn available_at_depth(&self, depth: u32) -> Vec<&SpawnEntry>
Get entries valid for depth, sorted by weight descending.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Clone for SpawnTable
impl Clone for SpawnTable
Source§fn clone(&self) -> SpawnTable
fn clone(&self) -> SpawnTable
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpawnTable
impl Debug for SpawnTable
Source§impl Default for SpawnTable
impl Default for SpawnTable
Source§fn default() -> SpawnTable
fn default() -> SpawnTable
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SpawnTable
impl RefUnwindSafe for SpawnTable
impl Send for SpawnTable
impl Sync for SpawnTable
impl Unpin for SpawnTable
impl UnsafeUnpin for SpawnTable
impl UnwindSafe for SpawnTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.