2022-09-18 16:02:13 +00:00
|
|
|
use crate::defines::LevelInt;
|
|
|
|
use crate::ffi::{ExternPointer, OwnedPtr};
|
|
|
|
use crate::static_data::{GrowthRate, LookupGrowthRate};
|
|
|
|
use std::ptr::drop_in_place;
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Instantiates a new lookup growth rate. The experience array should be the amount of experience
|
|
|
|
/// required per level, with the first element being the experience required for level 1 (generally 0).
|
2022-09-18 16:02:13 +00:00
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
unsafe extern "C" fn growth_rate_lookup_new(array: *const u32, length: usize) -> OwnedPtr<Box<dyn GrowthRate>> {
|
2022-09-18 16:02:13 +00:00
|
|
|
let array = std::slice::from_raw_parts(array, length);
|
2022-09-20 16:04:19 +00:00
|
|
|
Box::into_raw(Box::new(Box::new(LookupGrowthRate::new(array.to_vec()))))
|
2022-09-18 16:02:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Drops the growth rate.
|
2022-09-18 16:02:13 +00:00
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
unsafe extern "C" fn growth_rate_lookup_drop(ptr: OwnedPtr<Box<dyn GrowthRate>>) {
|
2022-09-18 16:02:13 +00:00
|
|
|
drop_in_place(ptr)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Calculate the level something with this growth rate would have at a certain experience.
|
2022-09-18 16:02:13 +00:00
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
extern "C" fn growth_rate_calculate_level(ptr: ExternPointer<Box<dyn GrowthRate>>, experience: u32) -> LevelInt {
|
2022-09-18 16:02:13 +00:00
|
|
|
ptr.as_ref().calculate_level(experience)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Calculate the experience something with this growth rate would have at a certain level.
|
2022-09-18 16:02:13 +00:00
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
extern "C" fn growth_rate_calculate_experience(ptr: ExternPointer<Box<dyn GrowthRate>>, level: LevelInt) -> u32 {
|
2022-09-18 16:02:13 +00:00
|
|
|
ptr.as_ref().calculate_experience(level)
|
|
|
|
}
|