Finished documenting all public interfaces.
continuous-integration/drone/push Build is passing Details

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

View File

@ -1,7 +1,7 @@
// The too many arguments is annoying, especially for when we create constructor, disable.
#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
#![allow(clippy::not_unsafe_ptr_arg_deref)]
#![warn(missing_docs)]
#![deny(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
#![feature(test)]
#![feature(bench_black_box)]

View File

@ -1,14 +1,19 @@
use crate::static_data::EffectParameter;
use crate::StringKey;
/// An ability is a passive effect in battle that is attached to a Pokemon.
#[derive(Debug)]
pub struct Ability {
/// The name of the ability.
name: StringKey,
/// The name of the script effect of the ability.
effect: StringKey,
/// The parameters for the script effect of the ability.
parameters: Vec<EffectParameter>,
}
impl Ability {
/// Instantiates a new ability.
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<EffectParameter>) -> Self {
Self {
name: name.clone(),
@ -17,12 +22,15 @@ impl Ability {
}
}
/// The name of the ability.
pub fn name(&self) -> &StringKey {
&self.name
}
/// The name of the script effect of the ability.
pub fn effect(&self) -> &StringKey {
&self.effect
}
/// The parameters for the script effect of the ability.
pub fn parameters(&self) -> &Vec<EffectParameter> {
&self.parameters
}

View File

@ -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)]
pub struct AbilityIndex {
/// Whether or not the ability we're referring to is a hidden ability.
pub hidden: bool,
/// The index of the ability.
pub index: u8,
}

View File

@ -1,8 +1,13 @@
// 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?
/// Gender is a Pokemon characteristic.
///
/// 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)]
pub enum Gender {
/// The Pokemon has no gender.
Genderless = 0,
/// The Pokemon is male.
Male = 1,
/// The Pokemon is female.
Female = 2,
}

View File

@ -1,19 +1,25 @@
use crate::defines::LevelInt;
use crate::StringKey;
use hashbrown::hash_map::Entry::{Occupied, Vacant};
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)]
pub struct LearnableMoves {
/// A map of the moves a Pokemon can learn per level.
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>,
}
impl LearnableMoves {
/// Instantiates a new Learnable Moves.
pub fn new() -> LearnableMoves {
LearnableMoves::default()
}
/// Adds a new level move the Pokemon can learn.
pub fn add_level_move(&mut self, level: LevelInt, m: &StringKey) {
match self.learned_by_level.entry(level) {
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>> {
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> {
&self.distinct_level_moves
}

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)
}

View File

@ -1,13 +1,20 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// Stats are numerical values on Pokemon that are used in battle.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Statistic {
/// Health Points determine how much damage a Pokemon can receive before fainting.
HP,
/// Attack determines how much damage a Pokemon deals when using a physical attack.
Attack,
/// Defense determines how much damage a Pokemon receives when it is hit by a physical attack.
Defense,
/// Special Attack determines how much damage a Pokemon deals when using a special attack.
SpecialAttack,
/// Special Defense determines how much damage a Pokemon receives when it is hit by a special attack.
SpecialDefense,
/// Speed determines the order that a Pokemon can act in battle.
Speed,
}