Add function to get random nature, add shiny rate to library settings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -5,8 +5,8 @@ use std::ptr::drop_in_place;
|
||||
/// Creates a new generation 7 damage library. `has_randomness` defines whether a random damage
|
||||
/// modifier (0.85x - 1.00x) is applied to the calculated damage.
|
||||
#[no_mangle]
|
||||
extern "C" fn gen_7_damage_library_new(randomness: u8) -> IdentifiablePointer<Box<dyn DamageLibrary>> {
|
||||
let v: Box<dyn DamageLibrary> = Box::new(Gen7DamageLibrary::new(randomness == 1));
|
||||
extern "C" fn gen_7_damage_library_new(has_randomness: u8) -> IdentifiablePointer<Box<dyn DamageLibrary>> {
|
||||
let v: Box<dyn DamageLibrary> = Box::new(Gen7DamageLibrary::new(has_randomness == 1));
|
||||
let id = v.value_identifier();
|
||||
let ptr = Box::into_raw(Box::new(v));
|
||||
IdentifiablePointer::new(ptr, id)
|
||||
|
||||
@@ -4,9 +4,16 @@ use crate::static_data::{LibrarySettings, LibrarySettingsImpl};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Creates a new settings library.
|
||||
/// - `maximum_level` is the highest level a Pokemon can be.
|
||||
/// - `shiny_rate` is the chance of a Pokemon being shiny, as the denominator of a fraction, where
|
||||
/// the nominator is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is
|
||||
/// 1/1000.
|
||||
#[no_mangle]
|
||||
extern "C" fn library_settings_new(max_level: LevelInt) -> IdentifiablePointer<Box<dyn LibrarySettings>> {
|
||||
let b: Box<dyn LibrarySettings> = Box::new(LibrarySettingsImpl::new(max_level));
|
||||
extern "C" fn library_settings_new(
|
||||
max_level: LevelInt,
|
||||
shiny_rate: u32,
|
||||
) -> IdentifiablePointer<Box<dyn LibrarySettings>> {
|
||||
let b: Box<dyn LibrarySettings> = Box::new(LibrarySettingsImpl::new(max_level, shiny_rate));
|
||||
b.into()
|
||||
}
|
||||
|
||||
@@ -21,3 +28,10 @@ unsafe extern "C" fn library_settings_drop(ptr: OwnedPtr<Box<dyn LibrarySettings
|
||||
extern "C" fn library_settings_maximum_level(ptr: ExternPointer<Box<dyn LibrarySettings>>) -> LevelInt {
|
||||
ptr.as_ref().maximum_level()
|
||||
}
|
||||
|
||||
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
||||
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
||||
#[no_mangle]
|
||||
extern "C" fn library_settings_shiny_rate(ptr: ExternPointer<Box<dyn LibrarySettings>>) -> u32 {
|
||||
ptr.as_ref().shiny_rate()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::ffi::{BorrowedPtr, ExternPointer, IdentifiablePointer, OwnedPtr};
|
||||
use crate::static_data::{Nature, NatureLibrary, NatureLibraryImpl};
|
||||
use crate::Random;
|
||||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
@@ -41,6 +42,16 @@ unsafe extern "C" fn nature_library_get_nature(
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a random nature.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_library_get_random_nature(
|
||||
ptr: ExternPointer<Box<dyn NatureLibrary>>,
|
||||
seed: u64,
|
||||
) -> IdentifiablePointer<Arc<dyn Nature>> {
|
||||
let mut rand = Random::new(seed as u128);
|
||||
ptr.as_ref().get_random_nature(&mut rand).into()
|
||||
}
|
||||
|
||||
/// Finds a nature name by nature.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_library_get_nature_name(
|
||||
|
||||
Reference in New Issue
Block a user