Loads more work on battling, initial stretch to run a turn done.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -13,22 +13,22 @@ use std::ops::Deref;
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BattleSide<'a> {
|
||||
pub struct BattleSide<'own, 'library> {
|
||||
index: u8,
|
||||
pokemon_per_side: u8,
|
||||
pokemon: Vec<Option<Arc<RwLock<Pokemon<'a>>>>>,
|
||||
choices: Vec<Option<Arc<TurnChoice<'a>>>>,
|
||||
pokemon: Vec<Option<Arc<RwLock<Pokemon<'own, 'library>>>>>,
|
||||
choices: Vec<Option<Arc<RwLock<TurnChoice<'own, 'library>>>>>,
|
||||
fillable_slots: Vec<bool>,
|
||||
choices_set: u8,
|
||||
battle: Weak<RwLock<Battle<'a>>>,
|
||||
battle: Weak<RwLock<Battle<'own, 'library>>>,
|
||||
has_fled_battle: bool,
|
||||
volatile_scripts: Arc<RwLock<ScriptSet>>,
|
||||
|
||||
script_source_data: RwLock<ScriptSourceData>,
|
||||
}
|
||||
|
||||
impl<'a> BattleSide<'a> {
|
||||
pub fn new(index: u8, battle: Weak<RwLock<Battle<'a>>>, pokemon_per_side: u8) -> Self {
|
||||
impl<'own, 'library> BattleSide<'own, 'library> {
|
||||
pub fn new(index: u8, battle: Weak<RwLock<Battle<'own, 'library>>>, pokemon_per_side: u8) -> Self {
|
||||
let mut pokemon = Vec::with_capacity(pokemon_per_side as usize);
|
||||
let mut choices = Vec::with_capacity(pokemon_per_side as usize);
|
||||
let mut fillable_slots = Vec::with_capacity(pokemon_per_side as usize);
|
||||
@@ -58,19 +58,23 @@ impl<'a> BattleSide<'a> {
|
||||
pub fn pokemon_per_side(&self) -> u8 {
|
||||
self.pokemon_per_side
|
||||
}
|
||||
pub fn pokemon(&self) -> &Vec<Option<Arc<RwLock<Pokemon<'a>>>>> {
|
||||
pub fn pokemon(&self) -> &Vec<Option<Arc<RwLock<Pokemon<'own, 'library>>>>> {
|
||||
&self.pokemon
|
||||
}
|
||||
pub fn choices(&self) -> &Vec<Option<Arc<TurnChoice<'a>>>> {
|
||||
pub fn choices(&self) -> &Vec<Option<Arc<RwLock<TurnChoice<'own, 'library>>>>> {
|
||||
&self.choices
|
||||
}
|
||||
pub fn choices_mut(&mut self) -> &mut Vec<Option<Arc<RwLock<TurnChoice<'own, 'library>>>>> {
|
||||
&mut self.choices
|
||||
}
|
||||
|
||||
pub fn fillable_slots(&self) -> &Vec<bool> {
|
||||
&self.fillable_slots
|
||||
}
|
||||
pub fn choices_set(&self) -> u8 {
|
||||
self.choices_set
|
||||
}
|
||||
pub fn battle(&self) -> &Weak<RwLock<Battle<'a>>> {
|
||||
pub fn battle(&self) -> &Weak<RwLock<Battle<'own, 'library>>> {
|
||||
&self.battle
|
||||
}
|
||||
pub fn has_fled_battle(&self) -> bool {
|
||||
@@ -103,11 +107,11 @@ impl<'a> BattleSide<'a> {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn set_choice(&mut self, choice: TurnChoice<'a>) {
|
||||
pub fn set_choice(&mut self, choice: TurnChoice<'own, 'library>) {
|
||||
for (index, pokemon_slot) in self.pokemon.iter().enumerate() {
|
||||
if let Some(pokemon) = pokemon_slot {
|
||||
if pokemon.read().unique_identifier() == choice.user().unique_identifier() {
|
||||
self.choices[index] = Some(Arc::new(choice));
|
||||
if std::ptr::eq(pokemon.data_ptr(), choice.user().data_ptr()) {
|
||||
self.choices[index] = Some(Arc::new(RwLock::new(choice)));
|
||||
self.choices_set += 1;
|
||||
return;
|
||||
}
|
||||
@@ -115,11 +119,17 @@ impl<'a> BattleSide<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_choices(&mut self) {
|
||||
for i in 0..self.choices.len() {
|
||||
self.choices[i] = None;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn force_clear_pokemon(&mut self, index: u8) {
|
||||
self.pokemon[index as usize] = None;
|
||||
}
|
||||
|
||||
pub fn set_pokemon(&mut self, index: u8, pokemon: Option<Arc<RwLock<Pokemon<'a>>>>) {
|
||||
pub fn set_pokemon(&mut self, index: u8, pokemon: Option<Arc<RwLock<Pokemon<'own, 'library>>>>) {
|
||||
let old = &mut self.pokemon[index as usize];
|
||||
if let Some(old_pokemon) = old {
|
||||
let mut p = old_pokemon.write();
|
||||
@@ -163,7 +173,7 @@ impl<'a> BattleSide<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_pokemon_on_side(&self, pokemon: Arc<Pokemon<'a>>) -> bool {
|
||||
pub fn is_pokemon_on_side(&self, pokemon: Arc<Pokemon<'own, 'library>>) -> bool {
|
||||
for p in self.pokemon.iter().flatten() {
|
||||
if p.read().unique_identifier() == pokemon.unique_identifier() {
|
||||
return true;
|
||||
@@ -172,7 +182,7 @@ impl<'a> BattleSide<'a> {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn mark_slot_as_unfillable(&mut self, pokemon: &Pokemon<'a>) {
|
||||
pub fn mark_slot_as_unfillable(&mut self, pokemon: &Pokemon<'own, 'library>) {
|
||||
for (i, slot) in self.pokemon.iter().enumerate() {
|
||||
if let Some(p) = slot {
|
||||
if p.read().deref() as *const Pokemon == pokemon as *const Pokemon {
|
||||
@@ -183,7 +193,7 @@ impl<'a> BattleSide<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_slot_unfillable(&self, pokemon: Arc<Pokemon<'a>>) -> bool {
|
||||
pub fn is_slot_unfillable(&self, pokemon: Arc<Pokemon<'own, 'library>>) -> bool {
|
||||
for (i, slot) in self.pokemon.iter().enumerate() {
|
||||
if let Some(p) = slot {
|
||||
if p.read().unique_identifier() == pokemon.unique_identifier() {
|
||||
@@ -263,7 +273,7 @@ impl<'a> BattleSide<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VolatileScripts<'a> for BattleSide<'a> {
|
||||
impl<'own, 'library> VolatileScripts<'own> for BattleSide<'own, 'library> {
|
||||
fn volatile_scripts(&self) -> &Arc<RwLock<ScriptSet>> {
|
||||
&self.volatile_scripts
|
||||
}
|
||||
@@ -278,7 +288,7 @@ impl<'a> VolatileScripts<'a> for BattleSide<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ScriptSource<'a> for BattleSide<'a> {
|
||||
impl<'own, 'library> ScriptSource<'own> for BattleSide<'own, 'library> {
|
||||
fn get_script_count(&self) -> usize {
|
||||
self.battle.upgrade().unwrap().read().get_script_count() + 1
|
||||
}
|
||||
@@ -293,10 +303,6 @@ impl<'a> ScriptSource<'a> for BattleSide<'a> {
|
||||
|
||||
fn collect_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {
|
||||
self.get_own_scripts(scripts);
|
||||
self.battle
|
||||
.upgrade()
|
||||
.unwrap()
|
||||
.read()
|
||||
.collect_scripts(scripts);
|
||||
self.battle.upgrade().unwrap().read().collect_scripts(scripts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user