Prevent overflows using saturating types for several script functions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-06-30 16:53:28 +02:00
parent 653de5c919
commit ddaa2dab31
9 changed files with 570 additions and 517 deletions

View File

@@ -8,6 +8,8 @@ use alloc::rc::Rc;
use alloc::vec::Vec;
use core::any::Any;
use core::fmt::{Debug, Display, Formatter};
use core::num::Saturating;
type Result<T> = crate::result::PkmnResult<T>;
pub trait Script {
@@ -45,7 +47,7 @@ pub trait Script {
/// This function allows you to modify the effective speed of the Pokemon. This is ran before
/// turn ordering, so overriding here will allow you to put certain Pokemon before others.
fn change_speed(&self, _choice: TurnChoice, _speed: &mut u32) -> Result<()> {
fn change_speed(&self, _choice: TurnChoice, _speed: &mut Saturating<u32>) -> Result<()> {
Ok(())
}
/// This function allows you to modify the effective priority of the Pokemon. This is ran before
@@ -63,7 +65,11 @@ pub trait Script {
/// This function allows you to change a move into a multi-hit move. The number of hits set here
/// gets used as the number of hits. If set to 0, this will behave as if the move missed on its
/// first hit.
fn change_number_of_hits(&self, _choice: TurnChoice, _number_of_hits: &mut u8) -> Result<()> {
fn change_number_of_hits(
&self,
_choice: TurnChoice,
_number_of_hits: &mut Saturating<u8>,
) -> Result<()> {
Ok(())
}
@@ -157,7 +163,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_accuracy: &mut u8,
_accuracy: &mut Saturating<u8>,
) -> Result<()> {
Ok(())
}
@@ -168,7 +174,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_stage: &mut u8,
_stage: &mut Saturating<u8>,
) -> Result<()> {
Ok(())
}
@@ -201,7 +207,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_base_power: &mut u8,
_base_power: &mut Saturating<u8>,
) -> Result<()> {
Ok(())
}
@@ -231,7 +237,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_amount: &mut u32,
_amount: &mut Saturating<u32>,
) -> Result<()> {
Ok(())
}
@@ -241,7 +247,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_amount: &mut u32,
_amount: &mut Saturating<u32>,
) -> Result<()> {
Ok(())
}
@@ -273,7 +279,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_damage: &mut u32,
_damage: &mut Saturating<u32>,
) -> Result<()> {
Ok(())
}
@@ -283,7 +289,7 @@ pub trait Script {
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
_damage: &mut u32,
_damage: &mut Saturating<u32>,
) -> Result<()> {
Ok(())
}
@@ -428,7 +434,7 @@ pub trait Script {
&self,
_fainted_mon: Pokemon,
_winning_mon: Pokemon,
_amount: &mut u32,
_amount: &mut Saturating<u32>,
) -> Result<()> {
Ok(())
}
@@ -454,7 +460,7 @@ pub trait Script {
&self,
_target: Pokemon,
_pokeball: Item,
_modifier: &mut u8,
_modifier: &mut Saturating<u8>,
) -> Result<()> {
Ok(())
}

File diff suppressed because it is too large Load Diff