pub fn run(&mut self) -> BattleExecution
	{
		if (self.command != 0 && !self.effects.effects_empty()) || self.retreat
		{
			if self.retreat
			{
				// TODO: This feels hacky.
				let party;
				let active;
				if let Effect::Retreat(ref retreat) = self.effect_current
				{
					party = retreat.party;
					active = retreat.active;
				}
				else
				{
					unreachable!();
				}
				self.apply_effect_retreat(party, active)
			}
			else
			{
				let effect = self.effects.effect_take();
				let execution = self.apply_effect(&effect);
				self.effect_current = effect;
				execution
			}
		}
		else if self.sides_alive.len() <= 1
		{
			// TODO: Handle ties.
			BattleExecution::Finished(*self.sides_alive.keys().next().unwrap())
		}
		else if self.command < self.replay.command_count()
		{
			self.effects.effects_clear();
			self.sub_command = 0;
			
			// TODO: Refactor to use a match here.
			if let CommandType::Turn = *self.replay.command(self.command)
			{
				for x in 0..self.state.parties().len()
				{
					let party = &mut self.state.parties_mut()[x];
					party.active_purge();
				}
				self.effects.effect_add(Effect::None(NoneReason::Turn));
				for lingering_index in 0..self.state.lingering().len()
				{
					// TODO: Wait for non-lexical lifetimes.
					let changed =
					{
						let effect = &mut self.state.lingering_mut()[lingering_index];
						effect.after_turn() && effect.state_change()
					};
					if changed
					{
						let lingering_change = LingeringChange
						{
							index: lingering_index
						};
						self.effects.effect_add(Effect::LingeringChange(lingering_change));
					}
				}
				self.turn += 1;
			}
			else
			{
				let hit = if let CommandType::Attack(ref attack_command) = *self.replay.command(self.command)
				{
					let hit =
					{
						self.state.parties()[attack_command.target_party].active_member_alive(attack_command.target_member).is_some()
					};

					let party = &mut self.state.parties_mut()[attack_command.party];
					party.active_member_attack_limit_take(attack_command.member,
						attack_command.attack_index);

					hit
				}
				else
				{
					true
				};

				if hit
				{
					self.replay.command(self.command).effects(&mut self.effects, &self.state, &mut self.rng);
				}
				else
				{
					self.effects.effect_add(Effect::None(NoneReason::Miss));
				}
			}
			self.command += 1;
			BattleExecution::Command
		}
		else
		{
			BattleExecution::Ready
		}
		// Check battle finished with winner.
		// Increment command counter.
	}
/// Executes the next consecutive command effect. Returns the result of the command.
///
/// Execution goes as follows:
/// - For the current command, all effects are applied.
/// - Checks are done to see if there is a winner yet.
/// - The next command is lined up for execution.
///
Executes the next consecutive command effect. Returns the result of the command.
Execution goes as follows:
For the current command, all effects are applied.
Checks are done to see if there is a winner yet.
The next command is lined up for execution.
Executes the next consecutive command effect . Returns the result of the command . Execution goes as follows : For the current command all effects are applied . Checks are done to see if there is a winner yet . The next command is lined up for execution .
pub fn run(&mut self) -> BattleExecution
	{
		if (self.command != 0 && !self.effects.effects_empty()) || self.retreat
		{
			if self.retreat
			{
				// TODO: This feels hacky.
				let party;
				let active;
				if let Effect::Retreat(ref retreat) = self.effect_current
				{
					party = retreat.party;
					active = retreat.active;
				}
				else
				{
					unreachable!();
				}
				self.apply_effect_retreat(party, active)
			}
			else
			{
				let effect = self.effects.effect_take();
				let execution = self.apply_effect(&effect);
				self.effect_current = effect;
				execution
			}
		}
		else if self.sides_alive.len() <= 1
		{
			// TODO: Handle ties.
			BattleExecution::Finished(*self.sides_alive.keys().next().unwrap())
		}
		else if self.command < self.replay.command_count()
		{
			self.effects.effects_clear();
			self.sub_command = 0;
			// TODO: Refactor to use a match here.
			if let CommandType::Turn = *self.replay.command(self.command)
			{
				for x in 0..self.state.parties().len()
				{
					let party = &mut self.state.parties_mut()[x];
					party.active_purge();
				}
				self.effects.effect_add(Effect::None(NoneReason::Turn));
				for lingering_index in 0..self.state.lingering().len()
				{
					// TODO: Wait for non-lexical lifetimes.
					let changed =
					{
						let effect = &mut self.state.lingering_mut()[lingering_index];
						effect.after_turn() && effect.state_change()
					};
					if changed
					{
						let lingering_change = LingeringChange
						{
							index: lingering_index
						};
						self.effects.effect_add(Effect::LingeringChange(lingering_change));
					}
				}
				self.turn += 1;
			}
			else
			{
				let hit = if let CommandType::Attack(ref attack_command) = *self.replay.command(self.command)
				{
					let hit =
					{
						self.state.parties()[attack_command.target_party].active_member_alive(attack_command.target_member).is_some()
					};
					let party = &mut self.state.parties_mut()[attack_command.party];
					party.active_member_attack_limit_take(attack_command.member,
						attack_command.attack_index);
					hit
				}
				else
				{
					true
				};
				if hit
				{
					self.replay.command(self.command).effects(&mut self.effects, &self.state, &mut self.rng);
				}
				else
				{
					self.effects.effect_add(Effect::None(NoneReason::Miss));
				}
			}
			self.command += 1;
			BattleExecution::Command
		}
		else
		{
			BattleExecution::Ready
		}
		// Check battle finished with winner.
		// Increment command counter.
	}
pub fn run ( & mut self ) -> BattleExecution { if ( self . command != 0 && ! self . effects . effects_empty ( ) ) || self . retreat { if self . retreat { // TODO: This feels hacky. let party ; let active ; if let Effect :: Retreat ( ref retreat ) = self . effect_current { party = retreat . party ; active = retreat . active ; } else { unreachable ! ( ) ; } self . apply_effect_retreat ( party , active ) } else { let effect = self . effects . effect_take ( ) ; let execution = self . apply_effect ( & effect ) ; self . effect_current = effect ; execution } } else if self . sides_alive . len ( ) <= 1 { // TODO: Handle ties. BattleExecution :: Finished ( * self . sides_alive . keys ( ) . next ( ) . unwrap ( ) ) } else if self . command < self . replay . command_count ( ) { self . effects . effects_clear ( ) ; self . sub_command = 0 ; // TODO: Refactor to use a match here. if let CommandType :: Turn = * self . replay . command ( self . command ) { for x in 0 .. self . state . parties ( ) . len ( ) { let party = & mut self . state . parties_mut ( ) [ x ] ; party . active_purge ( ) ; } self . effects . effect_add ( Effect :: None ( NoneReason :: Turn ) ) ; for lingering_index in 0 .. self . state . lingering ( ) . len ( ) { // TODO: Wait for non-lexical lifetimes. let changed = { let effect = & mut self . state . lingering_mut ( ) [ lingering_index ] ; effect . after_turn ( ) && effect . state_change ( ) } ; if changed { let lingering_change = LingeringChange { index : lingering_index } ; self . effects . effect_add ( Effect :: LingeringChange ( lingering_change ) ) ; } } self . turn += 1 ; } else { let hit = if let CommandType :: Attack ( ref attack_command ) = * self . replay . command ( self . command ) { let hit = { self . state . parties ( ) [ attack_command . target_party ] . active_member_alive ( attack_command . target_member ) . is_some ( ) } ; let party = & mut self . state . parties_mut ( ) [ attack_command . party ] ; party . active_member_attack_limit_take ( attack_command . member , attack_command . attack_index ) ; hit } else { true } ; if hit { self . replay . command ( self . command ) . effects ( & mut self . effects , & self . state , & mut self . rng ) ; } else { self . effects . effect_add ( Effect :: None ( NoneReason :: Miss ) ) ; } } self . command += 1 ; BattleExecution :: Command } else { BattleExecution :: Ready } // Check battle finished with winner. // Increment command counter. }
Executes the next consecutive command effect.
Executes the next consecutive command effect .
&mut self
&mut self