67 lines
2.3 KiB
Rust
67 lines
2.3 KiB
Rust
use crate::dynamic_data::{LearnedMove, MoveLearnMethod};
|
|
use crate::ffi::{ExternPointer, IdentifiablePointer, NativeResult, OwnedPtr};
|
|
use crate::static_data::MoveData;
|
|
use std::ptr::drop_in_place;
|
|
use std::sync::Arc;
|
|
|
|
/// Instantiate a new learned move.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_new(
|
|
move_data: ExternPointer<Arc<dyn MoveData>>,
|
|
learn_method: MoveLearnMethod,
|
|
) -> IdentifiablePointer<Arc<LearnedMove>> {
|
|
Arc::new(LearnedMove::new(move_data.as_ref().clone(), learn_method)).into()
|
|
}
|
|
|
|
/// Drops a learned move.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_drop(learned_move: OwnedPtr<Arc<LearnedMove>>) {
|
|
unsafe { drop_in_place(learned_move) }
|
|
}
|
|
|
|
/// The immutable move information of the move.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_move_data(
|
|
learned_move: ExternPointer<Arc<LearnedMove>>,
|
|
) -> IdentifiablePointer<Arc<dyn MoveData>> {
|
|
learned_move.as_ref().move_data().clone().into()
|
|
}
|
|
|
|
/// The maximal power points for this move.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_max_pp(learned_move: ExternPointer<Arc<LearnedMove>>) -> u8 {
|
|
learned_move.as_ref().max_pp()
|
|
}
|
|
|
|
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_remaining_pp(learned_move: ExternPointer<Arc<LearnedMove>>) -> u8 {
|
|
learned_move.as_ref().remaining_pp()
|
|
}
|
|
|
|
/// The way the move was learned.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_learn_method(learned_move: ExternPointer<Arc<LearnedMove>>) -> MoveLearnMethod {
|
|
learned_move.as_ref().learn_method()
|
|
}
|
|
|
|
/// Try and reduce the PP by a certain amount. If the amount is higher than the current uses,
|
|
/// return 0. Otherwise, reduce the PP, and return 1.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_try_use(learned_move: ExternPointer<Arc<LearnedMove>>, amount: u8) -> u8 {
|
|
u8::from(learned_move.as_ref().try_use(amount))
|
|
}
|
|
|
|
/// Set the remaining PP to the max amount of PP.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_restore_all_uses(learned_move: ExternPointer<Arc<LearnedMove>>) {
|
|
learned_move.as_ref().restore_all_uses();
|
|
}
|
|
|
|
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
|
#[no_mangle]
|
|
extern "C" fn learned_move_restore_uses(learned_move: ExternPointer<Arc<LearnedMove>>, amount: u8) -> NativeResult<()> {
|
|
learned_move.as_ref().restore_uses(amount);
|
|
NativeResult::ok(())
|
|
}
|