State

Struct State 

Source
pub struct State {
    pub side_one: Side,
    pub side_two: Side,
    pub weather: StateWeather,
    pub terrain: StateTerrain,
    pub trick_room: StateTrickRoom,
    pub team_preview: bool,
    pub use_last_used_move: bool,
    pub use_damage_dealt: bool,
}

Fields§

§side_one: Side§side_two: Side§weather: StateWeather§terrain: StateTerrain§trick_room: StateTrickRoom§team_preview: bool§use_last_used_move: bool§use_damage_dealt: bool

Implementations§

Source§

impl State

Source

pub fn root_get_all_options(&self) -> (Vec<MoveChoice>, Vec<MoveChoice>)

Source

pub fn get_all_options(&self) -> (Vec<MoveChoice>, Vec<MoveChoice>)

Source

pub fn reset_toxic_count( &mut self, side_ref: &SideReference, vec_to_add_to: &mut Vec<Instruction>, )

Source

pub fn remove_volatile_statuses_on_switch( &mut self, side_ref: &SideReference, instructions: &mut Vec<Instruction>, baton_passing: bool, shed_tailing: bool, )

Source

pub fn terrain_is_active(&self, terrain: &Terrain) -> bool

Source

pub fn get_terrain(&self) -> Terrain

Source

pub fn weather_is_active(&self, weather: &Weather) -> bool

Source

pub fn set_damage_dealt_flag(&mut self)

Source

pub fn set_last_used_move_flag(&mut self)

Source

pub fn set_conditional_mechanics(&mut self)

Source§

impl State

Source

pub fn battle_is_over(&self) -> f32

Source

pub fn get_side(&mut self, side_ref: &SideReference) -> &mut Side

Source

pub fn get_side_immutable(&self, side_ref: &SideReference) -> &Side

Source

pub fn get_both_sides( &mut self, side_ref: &SideReference, ) -> (&mut Side, &mut Side)

Source

pub fn get_both_sides_immutable( &self, side_ref: &SideReference, ) -> (&Side, &Side)

Source

pub fn reset_boosts( &mut self, side_ref: &SideReference, vec_to_add_to: &mut Vec<Instruction>, )

Source

pub fn re_enable_disabled_moves( &mut self, side_ref: &SideReference, vec_to_add_to: &mut Vec<Instruction>, )

Source

pub fn apply_instructions(&mut self, instructions: &Vec<Instruction>)

Source

pub fn apply_one_instruction(&mut self, instruction: &Instruction)

Source

pub fn reverse_instructions(&mut self, instructions: &Vec<Instruction>)

Source

pub fn reverse_one_instruction(&mut self, instruction: &Instruction)

Source§

impl State

Source

pub fn pprint(&self) -> String

Source

pub fn serialize(&self) -> String

Source

pub fn deserialize(serialized: &str) -> State


/*
This doctest does its best to show the format of the serialized state.

Roughly, the format for a state is:
    side1/side2/weather/terrain/trick_room/team_preview

Where the format for a side is:
    p0=p1=p2=p3=p4=p5=active_index=side_conditions=wish0=wish1=force_switch=switch_out_move_second_saved_move=baton_passing=shed_tailing=force_trapped=last_used_move=slow_uturn_move

And the format for a pokemon is:
   id,level,type1,type2,hp,maxhp,ability,item,attack,defense,special_attack,special_defense,speed,attack_boost,defense_boost,special_attack_boost,special_defense_boost,speed_boost,accuracy_boost,evasion_boost,status,substitute_health,rest_turns,weight_kg,volatile_statuses,m0,m1,m2,m3

There's more to it, follow the code below to see a full example of a serialized state.
*/

if cfg!(feature = "gen2") {
   return;
}

use poke_engine::engine::abilities::Abilities;
use poke_engine::engine::items::Items;
use poke_engine::pokemon::PokemonName;
use poke_engine::state::State;

let serialized_state = concat!(

// SIDE 1

// POKEMON 1

// name
"alakazam,",

// level
"100,",

// type1
"Psychic,",

// type2
"Typeless,",

// base_types 1 and 2. These are needed to revert to the correct type when switching out after being typechanged
"Psychic,",
"Typeless,",

// hp
"251,",

// maxhp
"251,",

// ability
"NONE,",

// base ability. This is needed to revert to the correct ability when switching out after having the ability changed
"NONE,",

// item
"LIFEORB,",

// nature
"SERIOUS,",

// EVs split by `;`. Leave blank for default EVs (85 in all)
"252;0;252;0;4;0,",
// ",", left blank for default EVs

// attack,defense,special attack,special defense,speed
// note these are final stats, not base stats
"121,148,353,206,365,",

// status
"None,",

// rest_turns
"0,",

// sleep_turns
"0,",

// weight_kg
"25.5,",

// moves 1 through 4 (move_id;disabled;pp)
"PSYCHIC;false;16,GRASSKNOT;false;32,SHADOWBALL;false;24,HIDDENPOWERFIRE70;false;24,",

// terastallized
"false,",

// tera_type
"Normal=",

// all remaining Pokémon shown in 1 line for brevity
"skarmory,100,Steel,Flying,Steel,Flying,271,271,STURDY,STURDY,CUSTAPBERRY,SERIOUS,,259,316,104,177,262,None,0,0,25.5,STEALTHROCK;false;32,SPIKES;false;32,BRAVEBIRD;false;24,THIEF;false;40,false,Normal=",
"tyranitar,100,Rock,Dark,Rock,Dark,404,404,SANDSTREAM,SANDSTREAM,CHOPLEBERRY,SERIOUS,,305,256,203,327,159,None,0,0,25.5,CRUNCH;false;24,SUPERPOWER;false;8,THUNDERWAVE;false;32,PURSUIT;false;32,false,Normal=",
"mamoswine,100,Ice,Ground,Ice,Ground,362,362,THICKFAT,THICKFAT,NEVERMELTICE,SERIOUS,,392,196,158,176,241,None,0,0,25.5,ICESHARD;false;48,EARTHQUAKE;false;16,SUPERPOWER;false;8,ICICLECRASH;false;16,false,Normal=",
"jellicent,100,Water,Ghost,Water,Ghost,404,404,WATERABSORB,WATERABSORB,AIRBALLOON,SERIOUS,,140,237,206,246,180,None,0,0,25.5,TAUNT;false;32,NIGHTSHADE;false;24,WILLOWISP;false;24,RECOVER;false;16,false,Normal=",
"excadrill,100,Ground,Steel,Ground,Steel,362,362,SANDFORCE,SANDFORCE,CHOICESCARF,SERIOUS,,367,156,122,168,302,None,0,0,25.5,EARTHQUAKE;false;16,IRONHEAD;false;24,ROCKSLIDE;false;16,RAPIDSPIN;false;64,false,Normal=",

// active-index. This is the index of the active Pokémon in the side's Pokémon array
"0=",

// side conditions are integers
"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;=",

// volatile_statuses (delimited by ":")
"=",

// some volatile statuses have durations associated with them, delimited by ;
"0;0;0;0;0;0=",

// substitute_health
"0=",

// For the active pokemon:
// attack_boost,defense_boost,special attack_boost,special defense_boost,speed_boost,accuracy_boost,evasion_boost
"0=0=0=0=0=0=0=",

// wish condition is represented by 2 integers, the first is how many wish turns remaining, the second is the amount of HP to heal
"0=",
"0=",

// future sight is represented by the PokemonIndex of the pokemon that used futuresight, and the number of turns remaining until it hits
"0=",
"0=",

// a boolean representing if the side is forced to switch
"false=",

// a 'saved moved' that a pokemon may be waiting to use after the opponent finished their uturn/volt switch/etc.
"NONE=",

// a boolean representing if the side is baton passing
"false=",

// a boolean representing if the side is shed tailing
"false=",

// a boolean representing if the side is force trapped. This is only ever externally provided and never changed by the engine
"false=",

// last used move is a string that can be either "move:move_name" or "switch:pokemon_index"
"switch:0=",

// a boolean representing if the side is slow uturning.
// This is only ever set externally. It is used to know if the opposing side has a stored move to use after uturn.
"false/",

// SIDE 2, all in one line for brevity
"terrakion,100,Rock,Fighting,Rock,Fighting,323,323,NONE,NONE,FOCUSSASH,SERIOUS,,357,216,163,217,346,None,0,0,25.5,CLOSECOMBAT;false;8,STONEEDGE;false;8,STEALTHROCK;false;32,TAUNT;false;32,false,Normal=lucario,100,Fighting,Steel,Fighting,Steel,281,281,NONE,NONE,LIFEORB,SERIOUS,,350,176,241,177,279,None,0,0,25.5,CLOSECOMBAT;false;8,EXTREMESPEED;false;8,SWORDSDANCE;false;32,CRUNCH;false;24,false,Normal=breloom,100,Grass,Fighting,Grass,Fighting,262,262,TECHNICIAN,TECHNICIAN,LIFEORB,SERIOUS,,394,196,141,156,239,None,0,0,25.5,MACHPUNCH;false;48,BULLETSEED;false;48,SWORDSDANCE;false;32,LOWSWEEP;false;32,false,Normal=keldeo,100,Water,Fighting,Water,Fighting,323,323,NONE,NONE,LEFTOVERS,SERIOUS,,163,216,357,217,346,None,0,0,25.5,SECRETSWORD;false;16,HYDROPUMP;false;8,SCALD;false;24,SURF;false;24,false,Normal=conkeldurr,100,Fighting,Typeless,Fighting,Typeless,414,414,GUTS,GUTS,LEFTOVERS,SERIOUS,,416,226,132,167,126,None,0,0,25.5,MACHPUNCH;false;48,DRAINPUNCH;false;16,ICEPUNCH;false;24,THUNDERPUNCH;false;24,false,Normal=toxicroak,100,Poison,Fighting,Poison,Fighting,307,307,DRYSKIN,DRYSKIN,LIFEORB,SERIOUS,,311,166,189,167,295,None,0,0,25.5,DRAINPUNCH;false;16,SUCKERPUNCH;false;8,SWORDSDANCE;false;32,ICEPUNCH;false;24,false,Normal=0=0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;==0;0;0;0;0;0=0=0=0=0=0=0=0=0=0=0=0=0=false=NONE=false=false=false=switch:0=false/",

// weather is a string representing the weather type and the number of turns remaining
"none;5/",

// terrain is a string representing the terrain type and the number of turns remaining
"none;5/",

// trick room is a boolean representing if trick room is active and the number of turns remaining
"false;5/",

// team preview is a boolean representing if the team preview is active
"false"

);

let state = State::deserialize(serialized_state);

assert_eq!(state.side_one.get_active_immutable().id, PokemonName::ALAKAZAM);
assert_eq!(state.side_one.get_active_immutable().weight_kg, 25.5);
assert_eq!(state.side_one.substitute_health, 0);
assert_eq!(state.side_two.get_active_immutable().id, PokemonName::TERRAKION);
assert_eq!(state.trick_room.active, false);
assert_eq!(state.team_preview, false);


// the same state, but all in one line
let serialized_state = "alakazam,100,Psychic,Typeless,Psychic,Typeless,251,251,NONE,NONE,LIFEORB,SERIOUS,252;0;252;0;4;0,121,148,353,206,365,None,0,0,25.5,PSYCHIC;false;16,GRASSKNOT;false;32,SHADOWBALL;false;24,HIDDENPOWERFIRE70;false;24,false,Normal=skarmory,100,Steel,Flying,Steel,Flying,271,271,STURDY,STURDY,CUSTAPBERRY,SERIOUS,,259,316,104,177,262,None,0,0,25.5,STEALTHROCK;false;32,SPIKES;false;32,BRAVEBIRD;false;24,THIEF;false;40,false,Normal=tyranitar,100,Rock,Dark,Rock,Dark,404,404,SANDSTREAM,SANDSTREAM,CHOPLEBERRY,SERIOUS,,305,256,203,327,159,None,0,0,25.5,CRUNCH;false;24,SUPERPOWER;false;8,THUNDERWAVE;false;32,PURSUIT;false;32,false,Normal=mamoswine,100,Ice,Ground,Ice,Ground,362,362,THICKFAT,THICKFAT,NEVERMELTICE,SERIOUS,,392,196,158,176,241,None,0,0,25.5,ICESHARD;false;48,EARTHQUAKE;false;16,SUPERPOWER;false;8,ICICLECRASH;false;16,false,Normal=jellicent,100,Water,Ghost,Water,Ghost,404,404,WATERABSORB,WATERABSORB,AIRBALLOON,SERIOUS,,140,237,206,246,180,None,0,0,25.5,TAUNT;false;32,NIGHTSHADE;false;24,WILLOWISP;false;24,RECOVER;false;16,false,Normal=excadrill,100,Ground,Steel,Ground,Steel,362,362,SANDFORCE,SANDFORCE,CHOICESCARF,SERIOUS,,367,156,122,168,302,None,0,0,25.5,EARTHQUAKE;false;16,IRONHEAD;false;24,ROCKSLIDE;false;16,RAPIDSPIN;false;64,false,Normal=0=0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;==0;0;0;0;0;0=0=0=0=0=0=0=0=0=0=0=0=0=false=NONE=false=false=false=switch:0=false/terrakion,100,Rock,Fighting,Rock,Fighting,323,323,NONE,NONE,FOCUSSASH,SERIOUS,,357,216,163,217,346,None,0,0,25.5,CLOSECOMBAT;false;8,STONEEDGE;false;8,STEALTHROCK;false;32,TAUNT;false;32,false,Normal=lucario,100,Fighting,Steel,Fighting,Steel,281,281,NONE,NONE,LIFEORB,SERIOUS,,350,176,241,177,279,None,0,0,25.5,CLOSECOMBAT;false;8,EXTREMESPEED;false;8,SWORDSDANCE;false;32,CRUNCH;false;24,false,Normal=breloom,100,Grass,Fighting,Grass,Fighting,262,262,TECHNICIAN,TECHNICIAN,LIFEORB,SERIOUS,,394,196,141,156,239,None,0,0,25.5,MACHPUNCH;false;48,BULLETSEED;false;48,SWORDSDANCE;false;32,LOWSWEEP;false;32,false,Normal=keldeo,100,Water,Fighting,Water,Fighting,323,323,NONE,NONE,LEFTOVERS,SERIOUS,,163,216,357,217,346,None,0,0,25.5,SECRETSWORD;false;16,HYDROPUMP;false;8,SCALD;false;24,SURF;false;24,false,Normal=conkeldurr,100,Fighting,Typeless,Fighting,Typeless,414,414,GUTS,GUTS,LEFTOVERS,SERIOUS,,416,226,132,167,126,None,0,0,25.5,MACHPUNCH;false;48,DRAINPUNCH;false;16,ICEPUNCH;false;24,THUNDERPUNCH;false;24,false,Normal=toxicroak,100,Poison,Fighting,Poison,Fighting,307,307,DRYSKIN,DRYSKIN,LIFEORB,SERIOUS,,311,166,189,167,295,None,0,0,25.5,DRAINPUNCH;false;16,SUCKERPUNCH;false;8,SWORDSDANCE;false;32,ICEPUNCH;false;24,false,Normal=0=0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;==0;0;0;0;0;0=0=0=0=0=0=0=0=0=0=0=0=0=false=NONE=false=false=false=switch:0=false/none;5/none;5/false;5/false";
let state2 = State::deserialize(serialized_state);
assert_eq!(state.serialize(), state2.serialize());

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for State

Source§

fn default() -> State

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V