Remove lifetime mess, replace a lot of code with Arc instead of borrows.
Some checks failed
continuous-integration/drone/push Build is failing

This cleans up the codebase massively, and allows me to maintain some semblance of sanity.
This commit is contained in:
2022-08-20 13:17:20 +02:00
parent 2d4253e155
commit 55cc0906c9
34 changed files with 320 additions and 366 deletions

View File

@@ -12,7 +12,7 @@ use crate::dynamic_data::Pokemon;
use crate::static_data::{DataLibrary, MoveCategory};
use crate::{run_scripts, script_hook, PkmnResult};
impl<'own, 'library> Battle<'own, 'library> {
impl Battle {
/// Execute the entire turn after the choices are all set.
pub(crate) fn run_turn(&self) -> PkmnResult<()> {
let choice_queue = self.current_turn_queue();
@@ -62,7 +62,7 @@ impl<'own, 'library> Battle<'own, 'library> {
}
/// Executes a single choice.
fn execute_choice(&self, choice: &TurnChoice<'own, 'library>) -> PkmnResult<()> {
fn execute_choice(&self, choice: &TurnChoice) -> PkmnResult<()> {
// A pass turn choice means the user does not intend to do anything. As such, return.
if let TurnChoice::Pass(..) = choice {
return Ok(());
@@ -91,7 +91,7 @@ impl<'own, 'library> Battle<'own, 'library> {
}
/// Executes a move choice.
fn execute_move_choice<'func>(&'func self, choice: &'func TurnChoice<'own, 'library>) -> PkmnResult<()> {
fn execute_move_choice<'func>(&'func self, choice: &'func TurnChoice) -> PkmnResult<()> {
let choice = choice.get_move_turn_data();
let used_move = choice.used_move();
let move_data = {
@@ -111,11 +111,11 @@ impl<'own, 'library> Battle<'own, 'library> {
return Ok(());
}
let mut executing_move = ExecutingMove::new(
&targets,
targets.clone(),
number_of_hits,
choice.user().clone(),
used_move.clone(),
move_data,
move_data.clone(),
choice.script().clone(),
);
let mut prevented = false;
@@ -148,11 +148,7 @@ impl<'own, 'library> Battle<'own, 'library> {
}
/// Executes a move turn choice on a single target.
fn handle_move_for_target(
&self,
executing_move: &mut ExecutingMove<'_, 'own, 'library>,
target: &Arc<Pokemon<'own, 'library>>,
) -> PkmnResult<()> {
fn handle_move_for_target(&self, executing_move: &mut ExecutingMove, target: &Arc<Pokemon>) -> PkmnResult<()> {
{
let mut fail = false;
script_hook!(fail_incoming_move, target, executing_move, target, &mut fail);