A lot more work on a bunch of different parts of the system.
This commit is contained in:
@@ -1,36 +1,40 @@
|
||||
use self::super::form::Form;
|
||||
use crate::static_data::species_data::gender::Gender;
|
||||
use crate::utils::random::Random;
|
||||
use crate::StringKey;
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Species<'a> {
|
||||
id: u16,
|
||||
name: String,
|
||||
name: StringKey,
|
||||
gender_rate: f32,
|
||||
growth_rate: String,
|
||||
growth_rate: StringKey,
|
||||
capture_rate: u8,
|
||||
forms: HashMap<String, Form<'a>>,
|
||||
flags: HashSet<String>,
|
||||
forms: HashMap<StringKey, Form<'a>>,
|
||||
flags: HashSet<StringKey>,
|
||||
}
|
||||
lazy_static::lazy_static! {
|
||||
static ref DEFAULT_KEY: StringKey = StringKey::new("default");
|
||||
}
|
||||
|
||||
impl<'a> Species<'a> {
|
||||
pub fn new(
|
||||
id: u16,
|
||||
name: &str,
|
||||
name: &StringKey,
|
||||
gender_rate: f32,
|
||||
growth_rate: &str,
|
||||
growth_rate: &StringKey,
|
||||
capture_rate: u8,
|
||||
default_form: Form<'a>,
|
||||
flags: HashSet<String>,
|
||||
flags: HashSet<StringKey>,
|
||||
) -> Species<'a> {
|
||||
let mut forms = HashMap::with_capacity(1);
|
||||
forms.insert("default".to_string(), default_form);
|
||||
forms.insert_unique_unchecked(DEFAULT_KEY.clone(), default_form);
|
||||
Species {
|
||||
id,
|
||||
name: name.to_string(),
|
||||
name: name.clone(),
|
||||
gender_rate,
|
||||
growth_rate: growth_rate.to_string(),
|
||||
growth_rate: growth_rate.clone(),
|
||||
capture_rate,
|
||||
forms,
|
||||
flags,
|
||||
@@ -39,33 +43,37 @@ impl<'a> Species<'a> {
|
||||
pub fn id(&self) -> u16 {
|
||||
self.id
|
||||
}
|
||||
pub fn name(&self) -> &str {
|
||||
pub fn name(&self) -> &StringKey {
|
||||
&self.name
|
||||
}
|
||||
pub fn gender_rate(&self) -> f32 {
|
||||
self.gender_rate
|
||||
}
|
||||
pub fn growth_rate(&self) -> &str {
|
||||
pub fn growth_rate(&self) -> &StringKey {
|
||||
&self.growth_rate
|
||||
}
|
||||
pub fn capture_rate(&self) -> u8 {
|
||||
self.capture_rate
|
||||
}
|
||||
pub fn forms(&self) -> &HashMap<String, Form<'a>> {
|
||||
pub fn forms(&self) -> &HashMap<StringKey, Form<'a>> {
|
||||
&self.forms
|
||||
}
|
||||
pub fn flags(&self) -> &HashSet<String> {
|
||||
pub fn flags(&self) -> &HashSet<StringKey> {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
pub fn add_form(&mut self, id: String, form: Form<'a>) {
|
||||
pub fn add_form(&mut self, id: StringKey, form: Form<'a>) {
|
||||
self.forms.insert(id, form);
|
||||
}
|
||||
|
||||
pub fn get_form(&self, id: &str) -> Option<&Form> {
|
||||
pub fn get_form(&self, id: &StringKey) -> Option<&Form> {
|
||||
self.forms.get(id)
|
||||
}
|
||||
|
||||
pub fn get_default_form(&self) -> &Form {
|
||||
self.forms.get(&DEFAULT_KEY).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_random_gender(&self, rand: &mut Random) -> Gender {
|
||||
if self.gender_rate < 0.0 {
|
||||
Gender::Genderless
|
||||
@@ -76,7 +84,7 @@ impl<'a> Species<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_flag(&self, key: &str) -> bool {
|
||||
pub fn has_flag(&self, key: &StringKey) -> bool {
|
||||
self.flags.contains(key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user