use crate::static_data::Ability; use crate::static_data::AbilityIndex; use crate::static_data::LearnableMoves; use crate::static_data::Statistic; use crate::static_data::StatisticSet; use crate::Random; use crate::StringKey; use hashbrown::HashSet; use std::ops::Deref; #[derive(Debug)] pub struct Form<'a> { name: StringKey, height: f32, weight: f32, base_experience: u32, types: Vec, base_stats: StatisticSet, abilities: Vec<&'a Ability>, hidden_abilities: Vec<&'a Ability>, moves: LearnableMoves<'a>, flags: HashSet, } impl<'a> Form<'a> { pub fn new( name: &StringKey, height: f32, weight: f32, base_experience: u32, types: Vec, base_stats: StatisticSet, abilities: Vec<&'a Ability>, hidden_abilities: Vec<&'a Ability>, moves: LearnableMoves<'a>, flags: HashSet, ) -> Form<'a> { Form { name: name.clone(), height, weight, base_experience, types, base_stats, abilities, hidden_abilities, moves, flags, } } pub fn name(&self) -> &StringKey { &self.name } pub fn height(&self) -> f32 { self.height } pub fn weight(&self) -> f32 { self.weight } pub fn base_experience(&self) -> u32 { self.base_experience } pub fn types(&self) -> &Vec { &self.types } pub fn base_stats(&self) -> StatisticSet { self.base_stats } pub fn abilities(&self) -> &Vec<&'a Ability> { &self.abilities } pub fn hidden_abilities(&self) -> &Vec<&'a Ability> { &self.hidden_abilities } pub fn moves(&self) -> &LearnableMoves<'a> { &self.moves } pub fn flags(&self) -> &HashSet { &self.flags } pub fn get_type(&self, index: usize) -> u8 { self.types[index] } pub fn get_base_stat(&self, stat: Statistic) -> u16 { self.base_stats.get_stat(stat) } pub fn find_ability_index(&self, ability: &Ability) -> Option { for (index, a) in self.abilities.iter().enumerate() { if std::ptr::eq(a.deref(), ability as *const Ability) { return Some(AbilityIndex { hidden: false, index: index as u8, }); } } for (index, a) in self.hidden_abilities.iter().enumerate() { if std::ptr::eq(a.deref(), ability as *const Ability) { return Some(AbilityIndex { hidden: true, index: index as u8, }); } } None } pub fn get_ability(&self, index: AbilityIndex) -> &Ability { if index.hidden { self.hidden_abilities[index.index as usize] } else { self.abilities[index.index as usize] } } pub fn get_random_ability(&self, rand: &mut Random) -> &Ability { self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize] } pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &Ability { self.hidden_abilities[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize] } pub fn has_flag(&self, key: &StringKey) -> bool { self.flags.contains(key) } }