Finished documenting all public interfaces.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-07-01 17:52:00 +02:00
parent 3c8d633be7
commit 717fcdefda
7 changed files with 66 additions and 7 deletions

View File

@@ -1,24 +1,37 @@
use std::lazy::SyncLazy;
use hashbrown::{HashMap, HashSet};
use crate::static_data::Form;
use crate::static_data::Gender;
use crate::Random;
use crate::StringKey;
use hashbrown::{HashMap, HashSet};
use std::lazy::SyncLazy;
/// The data belonging to a Pokemon with certain characteristics.
#[derive(Debug)]
pub struct Species {
/// The national dex identifier of the Pokemon.
id: u16,
/// The name of the Pokemon.
name: StringKey,
/// The chance between 0.0 and 1.0 that a Pokemon is female.
gender_rate: f32,
/// How much experience is required for a level.
growth_rate: StringKey,
/// How hard it is to capture a Pokemon. 255 means this will be always caught, 0 means this is
/// uncatchable.
capture_rate: u8,
/// The forms that belong to this Pokemon.
forms: HashMap<StringKey, Form>,
/// The arbitrary flags that can be set on a Pokemon for script use.
flags: HashSet<StringKey>,
}
/// A cached String Key to get the default form.
static DEFAULT_KEY: SyncLazy<StringKey> = SyncLazy::new(|| StringKey::new("default"));
impl Species {
/// Creates a new species.
pub fn new(
id: u16,
name: &StringKey,
@@ -40,40 +53,53 @@ impl Species {
flags,
}
}
/// The national dex identifier of the Pokemon.
pub fn id(&self) -> u16 {
self.id
}
/// The name of the Pokemon.
pub fn name(&self) -> &StringKey {
&self.name
}
/// The chance between 0.0 and 1.0 that a Pokemon is female.
pub fn gender_rate(&self) -> f32 {
self.gender_rate
}
/// How much experience is required for a level.
pub fn growth_rate(&self) -> &StringKey {
&self.growth_rate
}
/// How hard it is to capture a Pokemon. 255 means this will be always caught, 0 means this is
/// uncatchable.
pub fn capture_rate(&self) -> u8 {
self.capture_rate
}
/// The forms that belong to this Pokemon.
pub fn forms(&self) -> &HashMap<StringKey, Form> {
&self.forms
}
/// The arbitrary flags that can be set on a Pokemon for script use.
pub fn flags(&self) -> &HashSet<StringKey> {
&self.flags
}
/// Adds a new form to the species.
pub fn add_form(&mut self, id: StringKey, form: Form) {
self.forms.insert(id, form);
}
/// Gets a form by name.
pub fn get_form(&self, id: &StringKey) -> Option<&Form> {
self.forms.get(id)
}
/// Gets the form the Pokemon will have by default, if no other form is specified.
pub fn get_default_form(&self) -> &Form {
self.forms.get(&DEFAULT_KEY).unwrap()
}
/// Gets a random gender.
pub fn get_random_gender(&self, rand: &mut Random) -> Gender {
if self.gender_rate < 0.0 {
Gender::Genderless
@@ -84,6 +110,7 @@ impl Species {
}
}
/// Check whether the Pokemon has a specific flag set.
pub fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}