FFI for Turn Choices

This commit is contained in:
2022-10-22 12:08:58 +02:00
parent ddfb00d36b
commit 1b627378f6
3 changed files with 120 additions and 0 deletions

View File

@@ -7,10 +7,13 @@ use crate::dynamic_data::Pokemon;
use crate::dynamic_data::ScriptContainer;
use crate::dynamic_data::{LearnedMove, ScriptWrapper};
use crate::dynamic_data::{ScriptSource, ScriptSourceData};
use crate::{ValueIdentifiable, ValueIdentifier};
/// The data on a turn choice that should be contained in every turn choice, regardless of type.
#[derive(Debug)]
struct CommonChoiceData {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// The user of the turn choice
user: Arc<Pokemon>,
/// The speed of the user at the beginning of the turn.
@@ -185,6 +188,7 @@ impl MoveChoice {
script: Default::default(),
priority: 0,
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
random_value: 0,
@@ -256,6 +260,7 @@ impl ItemChoice {
pub fn new(user: Arc<Pokemon>) -> Self {
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
random_value: 0,
@@ -294,6 +299,7 @@ impl SwitchChoice {
pub fn new(user: Arc<Pokemon>) -> Self {
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
random_value: 0,
@@ -332,6 +338,7 @@ impl FleeChoice {
pub fn new(user: Arc<Pokemon>) -> Self {
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
random_value: 0,
@@ -370,6 +377,7 @@ impl PassChoice {
pub fn new(user: Arc<Pokemon>) -> Self {
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
random_value: 0,
@@ -470,3 +478,9 @@ impl Ord for TurnChoice {
}
}
}
impl ValueIdentifiable for TurnChoice {
fn value_identifier(&self) -> ValueIdentifier {
self.choice_data().identifier
}
}