2022-10-14 11:59:04 +00:00
|
|
|
use crate::defines::LevelInt;
|
|
|
|
use crate::dynamic_data::{Battle, DamageSource, DynamicLibrary, LearnedMove, MoveLearnMethod, Pokemon};
|
|
|
|
use crate::ffi::{ffi_arc_getter, ffi_vec_value_getters, ExternPointer, IdentifiablePointer, OwnedPtr};
|
|
|
|
use crate::static_data::{
|
|
|
|
Ability, AbilityIndex, Form, Gender, Item, Nature, Species, Statistic, StatisticSet, TypeIdentifier,
|
|
|
|
};
|
|
|
|
use std::ffi::{c_char, CStr, CString};
|
|
|
|
use std::ptr::drop_in_place;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Instantiates a new Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_new(
|
|
|
|
library: ExternPointer<Arc<DynamicLibrary>>,
|
|
|
|
species: ExternPointer<Arc<Species>>,
|
|
|
|
form: ExternPointer<Arc<Form>>,
|
|
|
|
hidden_ability: bool,
|
|
|
|
ability_index: u8,
|
|
|
|
level: LevelInt,
|
|
|
|
unique_identifier: u32,
|
|
|
|
gender: Gender,
|
|
|
|
coloring: u8,
|
|
|
|
nature: *const c_char,
|
|
|
|
) -> IdentifiablePointer<Arc<Pokemon>> {
|
|
|
|
let nature = unsafe { CStr::from_ptr(nature) }.into();
|
|
|
|
Arc::new(Pokemon::new(
|
|
|
|
library.as_ref().clone(),
|
|
|
|
species.as_ref().clone(),
|
|
|
|
form.as_ref(),
|
|
|
|
AbilityIndex {
|
|
|
|
hidden: hidden_ability,
|
|
|
|
index: ability_index,
|
|
|
|
},
|
|
|
|
level,
|
|
|
|
unique_identifier,
|
|
|
|
gender,
|
|
|
|
coloring,
|
|
|
|
&nature,
|
|
|
|
))
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Drops an Arc reference held by the FFI.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
unsafe extern "C" fn pokemon_drop(ptr: OwnedPtr<Arc<Pokemon>>) {
|
|
|
|
drop_in_place(ptr);
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The library data of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_library(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<DynamicLibrary>> {
|
|
|
|
ptr.as_ref().library().clone().into()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The species of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_species(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<Species>> {
|
2022-10-14 14:53:30 +00:00
|
|
|
ptr.as_ref().species().into()
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The form of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_form(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<Form>> {
|
2022-10-14 14:53:30 +00:00
|
|
|
ptr.as_ref().form().into()
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_display_species(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<Species>> {
|
2022-10-14 14:53:30 +00:00
|
|
|
ptr.as_ref().display_species().into()
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_display_form(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<Form>> {
|
2022-10-14 14:53:30 +00:00
|
|
|
ptr.as_ref().display_form().into()
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ffi_arc_getter!(Pokemon, level, LevelInt);
|
|
|
|
ffi_arc_getter!(Pokemon, experience, u32);
|
|
|
|
ffi_arc_getter!(Pokemon, unique_identifier, u32);
|
|
|
|
ffi_arc_getter!(Pokemon, gender, Gender);
|
|
|
|
ffi_arc_getter!(Pokemon, coloring, u8);
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Gets the held item of a Pokemon
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
2022-11-27 16:29:29 +00:00
|
|
|
extern "C" fn pokemon_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Item>> {
|
2022-10-14 11:59:04 +00:00
|
|
|
if let Some(v) = ptr.as_ref().held_item().read().as_ref() {
|
|
|
|
v.clone().into()
|
|
|
|
} else {
|
|
|
|
IdentifiablePointer::none()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Checks whether the Pokemon is holding a specific item.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_has_held_item(ptr: ExternPointer<Arc<Pokemon>>, name: *const c_char) -> u8 {
|
|
|
|
let name = unsafe { CStr::from_ptr(name) }.into();
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().has_held_item(&name))
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Changes the held item of the Pokemon. Returns the previously held item.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_set_held_item(
|
|
|
|
ptr: ExternPointer<Arc<Pokemon>>,
|
2022-11-27 16:29:29 +00:00
|
|
|
item: ExternPointer<Arc<dyn Item>>,
|
|
|
|
) -> IdentifiablePointer<Arc<dyn Item>> {
|
2022-10-14 11:59:04 +00:00
|
|
|
if let Some(v) = ptr.as_ref().set_held_item(item.as_ref()) {
|
2022-10-14 14:53:30 +00:00
|
|
|
v.into()
|
2022-10-14 11:59:04 +00:00
|
|
|
} else {
|
|
|
|
IdentifiablePointer::none()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Removes the held item from the Pokemon. Returns the previously held item.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
2022-11-27 16:29:29 +00:00
|
|
|
extern "C" fn pokemon_remove_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Item>> {
|
2022-10-14 11:59:04 +00:00
|
|
|
if let Some(v) = ptr.as_ref().remove_held_item() {
|
2022-10-14 14:53:30 +00:00
|
|
|
v.into()
|
2022-10-14 11:59:04 +00:00
|
|
|
} else {
|
|
|
|
IdentifiablePointer::none()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Makes the Pokemon uses its held item.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_consume_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().consume_held_item())
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ffi_arc_getter!(Pokemon, current_health, u32);
|
|
|
|
ffi_arc_getter!(Pokemon, max_health, u32);
|
|
|
|
ffi_arc_getter!(Pokemon, weight, f32);
|
|
|
|
ffi_arc_getter!(Pokemon, height, f32);
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// An optional nickname of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_nickname(ptr: ExternPointer<Arc<Pokemon>>) -> *mut c_char {
|
|
|
|
let name = ptr.as_ref().nickname();
|
|
|
|
if let Some(v) = name {
|
|
|
|
CString::new(v.as_str()).unwrap().into_raw()
|
|
|
|
} else {
|
|
|
|
std::ptr::null_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Whether the actual ability on the form is a hidden ability.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_real_ability_is_hidden(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().real_ability().hidden)
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The index of the actual ability on the form.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_real_ability_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
|
|
|
ptr.as_ref().real_ability().index
|
|
|
|
}
|
|
|
|
|
|
|
|
ffi_vec_value_getters!(Pokemon, types, TypeIdentifier);
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Gets a learned move of the Pokemon. Index should generally be below [`MAX_MOVES`], you will get
|
|
|
|
/// a null pointer otherwise.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_learned_move_get(
|
|
|
|
ptr: ExternPointer<Arc<Pokemon>>,
|
|
|
|
index: usize,
|
|
|
|
) -> IdentifiablePointer<Arc<LearnedMove>> {
|
|
|
|
if let Some(Some(v)) = ptr.as_ref().learned_moves().read().get(index) {
|
|
|
|
v.clone().into()
|
|
|
|
} else {
|
|
|
|
IdentifiablePointer::none()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The stats of the Pokemon when disregarding any stat boosts.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_flat_stats(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<StatisticSet<u32>> {
|
|
|
|
(ptr.as_ref().flat_stats() as *const StatisticSet<u32>).into()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The stats of the Pokemon including the stat boosts.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_boosted_stats(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<StatisticSet<u32>> {
|
|
|
|
(ptr.as_ref().boosted_stats() as *const StatisticSet<u32>).into()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Get the stat boosts for a specific stat.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_get_stat_boost(ptr: ExternPointer<Arc<Pokemon>>, statistic: Statistic) -> i8 {
|
|
|
|
ptr.as_ref().stat_boost(statistic)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Change a boosted stat by a certain amount.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_change_stat_boost(
|
|
|
|
ptr: ExternPointer<Arc<Pokemon>>,
|
|
|
|
stat: Statistic,
|
|
|
|
diff_amount: i8,
|
|
|
|
self_inflicted: u8,
|
|
|
|
) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().change_stat_boost(stat, diff_amount, self_inflicted == 1))
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Gets a [individual value](https://bulbapedia.bulbagarden.net/wiki/Individual_values) of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_get_individual_value(ptr: ExternPointer<Arc<Pokemon>>, stat: Statistic) -> u8 {
|
|
|
|
ptr.as_ref().individual_values().get_stat(stat)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Modifies a [individual value](https://bulbapedia.bulbagarden.net/wiki/Individual_values) of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_set_individual_value(ptr: ExternPointer<Arc<Pokemon>>, stat: Statistic, value: u8) {
|
|
|
|
ptr.as_ref().individual_values().set_stat(stat, value);
|
|
|
|
ptr.as_ref().recalculate_flat_stats();
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Gets a [effort value](https://bulbapedia.bulbagarden.net/wiki/Effort_values) of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_get_effort_value(ptr: ExternPointer<Arc<Pokemon>>, stat: Statistic) -> u8 {
|
|
|
|
ptr.as_ref().effort_values().get_stat(stat)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Modifies a [effort value](https://bulbapedia.bulbagarden.net/wiki/Effort_values) of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_set_effort_value(ptr: ExternPointer<Arc<Pokemon>>, stat: Statistic, value: u8) {
|
|
|
|
ptr.as_ref().effort_values().set_stat(stat, value);
|
|
|
|
ptr.as_ref().recalculate_flat_stats();
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Gets the data for the battle the Pokemon is currently in. If the Pokemon is not in a battle, this
|
|
|
|
/// returns null.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_get_battle(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Battle> {
|
|
|
|
if let Some(v) = ptr.as_ref().get_battle() {
|
|
|
|
(v as *const Battle).into()
|
|
|
|
} else {
|
|
|
|
IdentifiablePointer::none()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Get the index of the side of the battle the Pokemon is in. If the Pokemon
|
|
|
|
/// is not on the battlefield, this always returns 0.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_get_battle_side_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
|
|
|
ptr.as_ref().get_battle_side_index().unwrap_or_default()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Get the index of the slot on the side of the battle the Pokemon is in. If the Pokemon
|
|
|
|
// is not on the battlefield, this always returns 0.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_get_battle_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
|
|
|
ptr.as_ref().get_battle_index().unwrap_or_default()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Returns whether something overrides the ability.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_is_ability_overriden(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().is_ability_overriden())
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Returns the currently active ability.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_active_ability(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Ability> {
|
|
|
|
(ptr.as_ref().active_ability() as *const Ability).into()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Whether or not the Pokemon is allowed to gain experience.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_allowed_experience_gain(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().allowed_experience_gain())
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// The [nature](https://bulbapedia.bulbagarden.net/wiki/Nature) of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
2022-11-27 16:36:42 +00:00
|
|
|
extern "C" fn pokemon_nature(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Nature>> {
|
2022-10-14 11:59:04 +00:00
|
|
|
ptr.as_ref().nature().clone().into()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Calculates the flat stats on the Pokemon. This should be called when for example the base
|
|
|
|
/// stats, level, nature, IV, or EV changes. This has a side effect of recalculating the boosted
|
|
|
|
/// stats, as those depend on the flat stats.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_recalculate_flat_stats(ptr: ExternPointer<Arc<Pokemon>>) {
|
|
|
|
ptr.as_ref().recalculate_flat_stats()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Calculates the boosted stats on the Pokemon. This should be called when a stat boost changes.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_recalculate_boosted_stats(ptr: ExternPointer<Arc<Pokemon>>) {
|
|
|
|
ptr.as_ref().recalculate_boosted_stats()
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Change the species of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_change_species(
|
|
|
|
ptr: ExternPointer<Arc<Pokemon>>,
|
|
|
|
species: ExternPointer<Arc<Species>>,
|
|
|
|
form: ExternPointer<Arc<Form>>,
|
|
|
|
) {
|
|
|
|
ptr.as_ref()
|
|
|
|
.change_species(species.as_ref().clone(), form.as_ref().clone())
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Change the form of the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_change_form(ptr: ExternPointer<Arc<Pokemon>>, form: ExternPointer<Arc<Form>>) {
|
|
|
|
ptr.as_ref().change_form(form.as_ref())
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Whether or not the Pokemon is useable in a battle.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_is_usable(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().is_usable())
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Returns whether the Pokemon is fainted.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_is_fainted(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().is_fainted())
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Whether or not the Pokemon is on the battlefield.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_is_on_battlefield(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
2022-10-14 14:53:30 +00:00
|
|
|
u8::from(ptr.as_ref().is_on_battlefield())
|
2022-10-14 11:59:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Damages the Pokemon by a certain amount of damage, from a damage source.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_damage(ptr: ExternPointer<Arc<Pokemon>>, damage: u32, source: DamageSource) {
|
|
|
|
ptr.as_ref().damage(damage, source)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Heals the Pokemon by a specific amount. Unless allow_revive is set to true, this will not
|
|
|
|
/// heal if the Pokemon has 0 health. If the amount healed is 0, this will return false.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_heal(ptr: ExternPointer<Arc<Pokemon>>, amount: u32, allow_revive: u8) -> bool {
|
|
|
|
ptr.as_ref().heal(amount, allow_revive == 1)
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Learn a move.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_learn_move(
|
|
|
|
ptr: ExternPointer<Arc<Pokemon>>,
|
|
|
|
move_name: *const c_char,
|
|
|
|
learn_method: MoveLearnMethod,
|
|
|
|
) {
|
|
|
|
unsafe { ptr.as_ref().learn_move(&CStr::from_ptr(move_name).into(), learn_method) }
|
|
|
|
}
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Removes the current non-volatile status from the Pokemon.
|
2022-10-14 11:59:04 +00:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn pokemon_clear_status(ptr: ExternPointer<Arc<Pokemon>>) {
|
|
|
|
ptr.as_ref().clear_status()
|
|
|
|
}
|