Finished documenting all public interfaces.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3c8d633be7
commit
717fcdefda
|
@ -1,7 +1,7 @@
|
||||||
// The too many arguments is annoying, especially for when we create constructor, disable.
|
// The too many arguments is annoying, especially for when we create constructor, disable.
|
||||||
#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
|
#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
|
||||||
#![allow(clippy::not_unsafe_ptr_arg_deref)]
|
#![allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||||
#![warn(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![warn(clippy::missing_docs_in_private_items)]
|
#![warn(clippy::missing_docs_in_private_items)]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
#![feature(bench_black_box)]
|
#![feature(bench_black_box)]
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
use crate::static_data::EffectParameter;
|
use crate::static_data::EffectParameter;
|
||||||
use crate::StringKey;
|
use crate::StringKey;
|
||||||
|
|
||||||
|
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Ability {
|
pub struct Ability {
|
||||||
|
/// The name of the ability.
|
||||||
name: StringKey,
|
name: StringKey,
|
||||||
|
/// The name of the script effect of the ability.
|
||||||
effect: StringKey,
|
effect: StringKey,
|
||||||
|
/// The parameters for the script effect of the ability.
|
||||||
parameters: Vec<EffectParameter>,
|
parameters: Vec<EffectParameter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ability {
|
impl Ability {
|
||||||
|
/// Instantiates a new ability.
|
||||||
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<EffectParameter>) -> Self {
|
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<EffectParameter>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
|
@ -17,12 +22,15 @@ impl Ability {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The name of the ability.
|
||||||
pub fn name(&self) -> &StringKey {
|
pub fn name(&self) -> &StringKey {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
/// The name of the script effect of the ability.
|
||||||
pub fn effect(&self) -> &StringKey {
|
pub fn effect(&self) -> &StringKey {
|
||||||
&self.effect
|
&self.effect
|
||||||
}
|
}
|
||||||
|
/// The parameters for the script effect of the ability.
|
||||||
pub fn parameters(&self) -> &Vec<EffectParameter> {
|
pub fn parameters(&self) -> &Vec<EffectParameter> {
|
||||||
&self.parameters
|
&self.parameters
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
/// An ability index allows us to find an ability on a form. It combines a bool for whether the
|
||||||
|
/// ability is hidden or not, and then an index of the ability.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct AbilityIndex {
|
pub struct AbilityIndex {
|
||||||
|
/// Whether or not the ability we're referring to is a hidden ability.
|
||||||
pub hidden: bool,
|
pub hidden: bool,
|
||||||
|
/// The index of the ability.
|
||||||
pub index: u8,
|
pub index: u8,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
// Required for standard pokemon functions, but somewhat controversial nowadays. Consider adding a feature
|
/// Gender is a Pokemon characteristic.
|
||||||
// that allows for a more progressive gender system for those that want it?
|
///
|
||||||
|
/// Required for standard pokemon functions, but somewhat controversial nowadays. Consider adding a feature
|
||||||
|
/// that allows for a more progressive gender system for those that want it?
|
||||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||||
pub enum Gender {
|
pub enum Gender {
|
||||||
|
/// The Pokemon has no gender.
|
||||||
Genderless = 0,
|
Genderless = 0,
|
||||||
|
/// The Pokemon is male.
|
||||||
Male = 1,
|
Male = 1,
|
||||||
|
/// The Pokemon is female.
|
||||||
Female = 2,
|
Female = 2,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
use crate::defines::LevelInt;
|
|
||||||
use crate::StringKey;
|
|
||||||
use hashbrown::hash_map::Entry::{Occupied, Vacant};
|
use hashbrown::hash_map::Entry::{Occupied, Vacant};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
|
use crate::defines::LevelInt;
|
||||||
|
use crate::StringKey;
|
||||||
|
|
||||||
|
/// This allows for storage of the moves a Pokemon can learn.
|
||||||
#[derive(Default, PartialEq, Eq, Debug)]
|
#[derive(Default, PartialEq, Eq, Debug)]
|
||||||
pub struct LearnableMoves {
|
pub struct LearnableMoves {
|
||||||
|
/// A map of the moves a Pokemon can learn per level.
|
||||||
learned_by_level: HashMap<LevelInt, Vec<StringKey>>,
|
learned_by_level: HashMap<LevelInt, Vec<StringKey>>,
|
||||||
|
/// A list of the distinct moves a Pokemon can learn through leveling up.
|
||||||
distinct_level_moves: Vec<StringKey>,
|
distinct_level_moves: Vec<StringKey>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LearnableMoves {
|
impl LearnableMoves {
|
||||||
|
/// Instantiates a new Learnable Moves.
|
||||||
pub fn new() -> LearnableMoves {
|
pub fn new() -> LearnableMoves {
|
||||||
LearnableMoves::default()
|
LearnableMoves::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds a new level move the Pokemon can learn.
|
||||||
pub fn add_level_move(&mut self, level: LevelInt, m: &StringKey) {
|
pub fn add_level_move(&mut self, level: LevelInt, m: &StringKey) {
|
||||||
match self.learned_by_level.entry(level) {
|
match self.learned_by_level.entry(level) {
|
||||||
Occupied(x) => {
|
Occupied(x) => {
|
||||||
|
@ -28,10 +34,12 @@ impl LearnableMoves {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets all moves a Pokemon can learn when leveling up to a specific level.
|
||||||
pub fn get_learned_by_level(&self, level: LevelInt) -> Option<&Vec<StringKey>> {
|
pub fn get_learned_by_level(&self, level: LevelInt) -> Option<&Vec<StringKey>> {
|
||||||
self.learned_by_level.get(&level)
|
self.learned_by_level.get(&level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the distinct moves a Pokemon can learn through leveling up.
|
||||||
pub fn get_distinct_level_moves(&self) -> &Vec<StringKey> {
|
pub fn get_distinct_level_moves(&self) -> &Vec<StringKey> {
|
||||||
&self.distinct_level_moves
|
&self.distinct_level_moves
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,37 @@
|
||||||
|
use std::lazy::SyncLazy;
|
||||||
|
|
||||||
|
use hashbrown::{HashMap, HashSet};
|
||||||
|
|
||||||
use crate::static_data::Form;
|
use crate::static_data::Form;
|
||||||
use crate::static_data::Gender;
|
use crate::static_data::Gender;
|
||||||
use crate::Random;
|
use crate::Random;
|
||||||
use crate::StringKey;
|
use crate::StringKey;
|
||||||
use hashbrown::{HashMap, HashSet};
|
|
||||||
use std::lazy::SyncLazy;
|
|
||||||
|
|
||||||
|
/// The data belonging to a Pokemon with certain characteristics.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Species {
|
pub struct Species {
|
||||||
|
/// The national dex identifier of the Pokemon.
|
||||||
id: u16,
|
id: u16,
|
||||||
|
/// The name of the Pokemon.
|
||||||
name: StringKey,
|
name: StringKey,
|
||||||
|
/// The chance between 0.0 and 1.0 that a Pokemon is female.
|
||||||
gender_rate: f32,
|
gender_rate: f32,
|
||||||
|
/// How much experience is required for a level.
|
||||||
growth_rate: StringKey,
|
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,
|
capture_rate: u8,
|
||||||
|
/// The forms that belong to this Pokemon.
|
||||||
forms: HashMap<StringKey, Form>,
|
forms: HashMap<StringKey, Form>,
|
||||||
|
/// The arbitrary flags that can be set on a Pokemon for script use.
|
||||||
flags: HashSet<StringKey>,
|
flags: HashSet<StringKey>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A cached String Key to get the default form.
|
||||||
static DEFAULT_KEY: SyncLazy<StringKey> = SyncLazy::new(|| StringKey::new("default"));
|
static DEFAULT_KEY: SyncLazy<StringKey> = SyncLazy::new(|| StringKey::new("default"));
|
||||||
|
|
||||||
impl Species {
|
impl Species {
|
||||||
|
/// Creates a new species.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: u16,
|
id: u16,
|
||||||
name: &StringKey,
|
name: &StringKey,
|
||||||
|
@ -40,40 +53,53 @@ impl Species {
|
||||||
flags,
|
flags,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The national dex identifier of the Pokemon.
|
||||||
pub fn id(&self) -> u16 {
|
pub fn id(&self) -> u16 {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
/// The name of the Pokemon.
|
||||||
pub fn name(&self) -> &StringKey {
|
pub fn name(&self) -> &StringKey {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
/// The chance between 0.0 and 1.0 that a Pokemon is female.
|
||||||
pub fn gender_rate(&self) -> f32 {
|
pub fn gender_rate(&self) -> f32 {
|
||||||
self.gender_rate
|
self.gender_rate
|
||||||
}
|
}
|
||||||
|
/// How much experience is required for a level.
|
||||||
pub fn growth_rate(&self) -> &StringKey {
|
pub fn growth_rate(&self) -> &StringKey {
|
||||||
&self.growth_rate
|
&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 {
|
pub fn capture_rate(&self) -> u8 {
|
||||||
self.capture_rate
|
self.capture_rate
|
||||||
}
|
}
|
||||||
|
/// The forms that belong to this Pokemon.
|
||||||
pub fn forms(&self) -> &HashMap<StringKey, Form> {
|
pub fn forms(&self) -> &HashMap<StringKey, Form> {
|
||||||
&self.forms
|
&self.forms
|
||||||
}
|
}
|
||||||
|
/// The arbitrary flags that can be set on a Pokemon for script use.
|
||||||
pub fn flags(&self) -> &HashSet<StringKey> {
|
pub fn flags(&self) -> &HashSet<StringKey> {
|
||||||
&self.flags
|
&self.flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds a new form to the species.
|
||||||
pub fn add_form(&mut self, id: StringKey, form: Form) {
|
pub fn add_form(&mut self, id: StringKey, form: Form) {
|
||||||
self.forms.insert(id, form);
|
self.forms.insert(id, form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets a form by name.
|
||||||
pub fn get_form(&self, id: &StringKey) -> Option<&Form> {
|
pub fn get_form(&self, id: &StringKey) -> Option<&Form> {
|
||||||
self.forms.get(id)
|
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 {
|
pub fn get_default_form(&self) -> &Form {
|
||||||
self.forms.get(&DEFAULT_KEY).unwrap()
|
self.forms.get(&DEFAULT_KEY).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets a random gender.
|
||||||
pub fn get_random_gender(&self, rand: &mut Random) -> Gender {
|
pub fn get_random_gender(&self, rand: &mut Random) -> Gender {
|
||||||
if self.gender_rate < 0.0 {
|
if self.gender_rate < 0.0 {
|
||||||
Gender::Genderless
|
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 {
|
pub fn has_flag(&self, key: &StringKey) -> bool {
|
||||||
self.flags.contains(key)
|
self.flags.contains(key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Stats are numerical values on Pokemon that are used in battle.
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum Statistic {
|
pub enum Statistic {
|
||||||
|
/// Health Points determine how much damage a Pokemon can receive before fainting.
|
||||||
HP,
|
HP,
|
||||||
|
/// Attack determines how much damage a Pokemon deals when using a physical attack.
|
||||||
Attack,
|
Attack,
|
||||||
|
/// Defense determines how much damage a Pokemon receives when it is hit by a physical attack.
|
||||||
Defense,
|
Defense,
|
||||||
|
/// Special Attack determines how much damage a Pokemon deals when using a special attack.
|
||||||
SpecialAttack,
|
SpecialAttack,
|
||||||
|
/// Special Defense determines how much damage a Pokemon receives when it is hit by a special attack.
|
||||||
SpecialDefense,
|
SpecialDefense,
|
||||||
|
/// Speed determines the order that a Pokemon can act in battle.
|
||||||
Speed,
|
Speed,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue