A lot more work on a bunch of different parts of the system.
This commit is contained in:
@@ -1,39 +1,42 @@
|
||||
use self::super::learnable_moves::LearnableMoves;
|
||||
use crate::static_data::species_data::ability::Ability;
|
||||
use crate::static_data::species_data::ability_index::AbilityIndex;
|
||||
use crate::static_data::statistic_set::StatisticSet;
|
||||
use crate::static_data::statistics::Statistic;
|
||||
use crate::utils::random::Random;
|
||||
use crate::StringKey;
|
||||
use hashbrown::HashSet;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Form<'a> {
|
||||
name: String,
|
||||
name: StringKey,
|
||||
height: f32,
|
||||
weight: f32,
|
||||
base_experience: u32,
|
||||
types: Vec<u8>,
|
||||
base_stats: StatisticSet<u16>,
|
||||
abilities: Vec<String>,
|
||||
hidden_abilities: Vec<String>,
|
||||
abilities: Vec<&'a Ability>,
|
||||
hidden_abilities: Vec<&'a Ability>,
|
||||
moves: LearnableMoves<'a>,
|
||||
flags: HashSet<String>,
|
||||
flags: HashSet<StringKey>,
|
||||
}
|
||||
|
||||
impl<'a> Form<'a> {
|
||||
pub fn new(
|
||||
name: &str,
|
||||
name: &StringKey,
|
||||
height: f32,
|
||||
weight: f32,
|
||||
base_experience: u32,
|
||||
types: Vec<u8>,
|
||||
base_stats: StatisticSet<u16>,
|
||||
abilities: Vec<String>,
|
||||
hidden_abilities: Vec<String>,
|
||||
abilities: Vec<&'a Ability>,
|
||||
hidden_abilities: Vec<&'a Ability>,
|
||||
moves: LearnableMoves<'a>,
|
||||
flags: HashSet<String>,
|
||||
flags: HashSet<StringKey>,
|
||||
) -> Form<'a> {
|
||||
Form {
|
||||
name: name.to_string(),
|
||||
name: name.clone(),
|
||||
height,
|
||||
weight,
|
||||
base_experience,
|
||||
@@ -46,7 +49,7 @@ impl<'a> Form<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
pub fn name(&self) -> &StringKey {
|
||||
&self.name
|
||||
}
|
||||
pub fn height(&self) -> f32 {
|
||||
@@ -64,16 +67,16 @@ impl<'a> Form<'a> {
|
||||
pub fn base_stats(&self) -> StatisticSet<u16> {
|
||||
self.base_stats
|
||||
}
|
||||
pub fn abilities(&self) -> &Vec<String> {
|
||||
pub fn abilities(&self) -> &Vec<&'a Ability> {
|
||||
&self.abilities
|
||||
}
|
||||
pub fn hidden_abilities(&self) -> &Vec<String> {
|
||||
pub fn hidden_abilities(&self) -> &Vec<&'a Ability> {
|
||||
&self.hidden_abilities
|
||||
}
|
||||
pub fn moves(&self) -> &LearnableMoves<'a> {
|
||||
&self.moves
|
||||
}
|
||||
pub fn flags(&self) -> &HashSet<String> {
|
||||
pub fn flags(&self) -> &HashSet<StringKey> {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
@@ -85,9 +88,9 @@ impl<'a> Form<'a> {
|
||||
self.base_stats.get_stat(stat)
|
||||
}
|
||||
|
||||
pub fn find_ability_index(&self, ability: &str) -> Option<AbilityIndex> {
|
||||
pub fn find_ability_index(&self, ability: &Ability) -> Option<AbilityIndex> {
|
||||
for (index, a) in self.abilities.iter().enumerate() {
|
||||
if a == ability {
|
||||
if std::ptr::eq(a.deref(), ability as *const Ability) {
|
||||
return Some(AbilityIndex {
|
||||
hidden: false,
|
||||
index: index as u8,
|
||||
@@ -95,7 +98,7 @@ impl<'a> Form<'a> {
|
||||
}
|
||||
}
|
||||
for (index, a) in self.hidden_abilities.iter().enumerate() {
|
||||
if a == ability {
|
||||
if std::ptr::eq(a.deref(), ability as *const Ability) {
|
||||
return Some(AbilityIndex {
|
||||
hidden: true,
|
||||
index: index as u8,
|
||||
@@ -105,15 +108,23 @@ impl<'a> Form<'a> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_random_ability(&self, rand: &mut Random) -> &String {
|
||||
&self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize]
|
||||
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_hidden_ability(&self, rand: &mut Random) -> &String {
|
||||
&self.hidden_abilities
|
||||
|
||||
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: &str) -> bool {
|
||||
pub fn has_flag(&self, key: &StringKey) -> bool {
|
||||
self.flags.contains(key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user