Remove lifetime mess, replace a lot of code with Arc instead of borrows.
Some checks failed
continuous-integration/drone/push Build is failing
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:
@@ -84,34 +84,34 @@ impl HitData {
|
||||
|
||||
/// An executing move is the data of the move for while it is executing.
|
||||
#[derive(Debug)]
|
||||
pub struct ExecutingMove<'own, 'battle, 'library> {
|
||||
pub struct ExecutingMove {
|
||||
/// The number of hits this move has.
|
||||
number_of_hits: u8,
|
||||
/// A list of hits for this move. For multi target multi hit moves, this stores the hits linearly,
|
||||
/// for example: (target1, hit1), (target1, hit2), (target2, hit1), (target2, hit2), etc.
|
||||
hits: Vec<HitData>,
|
||||
/// The user of the move.
|
||||
user: Arc<Pokemon<'battle, 'library>>,
|
||||
user: Arc<Pokemon>,
|
||||
/// The move the user has actually chosen to do.
|
||||
chosen_move: Arc<LearnedMove<'library>>,
|
||||
chosen_move: Arc<LearnedMove>,
|
||||
/// The move that the user is actually going to do.
|
||||
use_move: &'own MoveData,
|
||||
use_move: Arc<MoveData>,
|
||||
/// The script of the move.
|
||||
script: ScriptContainer,
|
||||
/// The targets for this move.
|
||||
targets: &'own TargetList<'battle, 'library>,
|
||||
targets: TargetList,
|
||||
/// Data required for this to be a script source.
|
||||
script_source_data: RwLock<ScriptSourceData>,
|
||||
}
|
||||
|
||||
impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
impl ExecutingMove {
|
||||
/// Instantiates an executing move.
|
||||
pub fn new(
|
||||
targets: &'own TargetList<'battle, 'library>,
|
||||
targets: TargetList,
|
||||
number_of_hits: u8,
|
||||
user: Arc<Pokemon<'battle, 'library>>,
|
||||
chosen_move: Arc<LearnedMove<'library>>,
|
||||
use_move: &'own MoveData,
|
||||
user: Arc<Pokemon>,
|
||||
chosen_move: Arc<LearnedMove>,
|
||||
use_move: Arc<MoveData>,
|
||||
script: ScriptContainer,
|
||||
) -> Self {
|
||||
let total_hits = number_of_hits as usize * targets.len();
|
||||
@@ -140,16 +140,16 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
self.number_of_hits
|
||||
}
|
||||
/// The user of the move.
|
||||
pub fn user(&self) -> &Arc<Pokemon<'battle, 'library>> {
|
||||
pub fn user(&self) -> &Arc<Pokemon> {
|
||||
&self.user
|
||||
}
|
||||
/// The move the user has actually chosen to do.
|
||||
pub fn chosen_move(&self) -> &Arc<LearnedMove<'library>> {
|
||||
pub fn chosen_move(&self) -> &Arc<LearnedMove> {
|
||||
&self.chosen_move
|
||||
}
|
||||
/// The move that the user is actually going to do.
|
||||
pub fn use_move(&self) -> &'own MoveData {
|
||||
self.use_move
|
||||
pub fn use_move(&self) -> &Arc<MoveData> {
|
||||
&self.use_move
|
||||
}
|
||||
/// The script of the move.
|
||||
pub fn script(&self) -> &ScriptContainer {
|
||||
@@ -157,11 +157,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
}
|
||||
|
||||
/// Gets a hit data for a target, with a specific index.
|
||||
pub fn get_hit_data<'func>(
|
||||
&'func self,
|
||||
for_target: &'func Arc<Pokemon<'battle, 'library>>,
|
||||
hit: u8,
|
||||
) -> PkmnResult<&'func HitData> {
|
||||
pub fn get_hit_data<'func>(&'func self, for_target: &'func Arc<Pokemon>, hit: u8) -> PkmnResult<&'func HitData> {
|
||||
for (index, target) in self.targets.iter().enumerate() {
|
||||
if let Some(target) = target {
|
||||
if std::ptr::eq(target.deref().deref(), for_target.deref().deref()) {
|
||||
@@ -174,7 +170,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
}
|
||||
|
||||
/// Checks whether a Pokemon is a target for this move.
|
||||
pub fn is_pokemon_target(&self, pokemon: &Arc<Pokemon<'battle, 'library>>) -> bool {
|
||||
pub fn is_pokemon_target(&self, pokemon: &Arc<Pokemon>) -> bool {
|
||||
for target in self.targets.iter().flatten() {
|
||||
if std::ptr::eq(target.deref().deref(), pokemon.deref().deref()) {
|
||||
return true;
|
||||
@@ -184,7 +180,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
}
|
||||
|
||||
/// Gets the index of the hits in this move where the hits for a specific target start.
|
||||
pub(crate) fn get_index_of_target(&self, for_target: &Arc<Pokemon<'battle, 'library>>) -> PkmnResult<usize> {
|
||||
pub(crate) fn get_index_of_target(&self, for_target: &Arc<Pokemon>) -> PkmnResult<usize> {
|
||||
for (index, target) in self.targets.iter().enumerate() {
|
||||
if let Some(target) = target {
|
||||
if std::ptr::eq(target.deref().deref(), for_target.deref().deref()) {
|
||||
@@ -202,7 +198,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'own, 'battle, 'library> ScriptSource<'own> for ExecutingMove<'own, 'battle, 'library> {
|
||||
impl ScriptSource for ExecutingMove {
|
||||
fn get_script_count(&self) -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user