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: boolImplementations§
Source§impl State
impl State
pub fn root_get_all_options(&self) -> (Vec<MoveChoice>, Vec<MoveChoice>)
pub fn get_all_options(&self) -> (Vec<MoveChoice>, Vec<MoveChoice>)
pub fn reset_toxic_count( &mut self, side_ref: &SideReference, vec_to_add_to: &mut Vec<Instruction>, )
pub fn remove_volatile_statuses_on_switch( &mut self, side_ref: &SideReference, instructions: &mut Vec<Instruction>, baton_passing: bool, shed_tailing: bool, )
pub fn terrain_is_active(&self, terrain: &Terrain) -> bool
pub fn get_terrain(&self) -> Terrain
pub fn weather_is_active(&self, weather: &Weather) -> bool
pub fn set_damage_dealt_flag(&mut self)
pub fn set_last_used_move_flag(&mut self)
pub fn set_conditional_mechanics(&mut self)
Source§impl State
impl State
pub fn battle_is_over(&self) -> f32
pub fn get_side(&mut self, side_ref: &SideReference) -> &mut Side
pub fn get_side_immutable(&self, side_ref: &SideReference) -> &Side
pub fn get_both_sides( &mut self, side_ref: &SideReference, ) -> (&mut Side, &mut Side)
pub fn get_both_sides_immutable( &self, side_ref: &SideReference, ) -> (&Side, &Side)
pub fn reset_boosts( &mut self, side_ref: &SideReference, vec_to_add_to: &mut Vec<Instruction>, )
pub fn re_enable_disabled_moves( &mut self, side_ref: &SideReference, vec_to_add_to: &mut Vec<Instruction>, )
pub fn apply_instructions(&mut self, instructions: &Vec<Instruction>)
pub fn apply_one_instruction(&mut self, instruction: &Instruction)
pub fn reverse_instructions(&mut self, instructions: &Vec<Instruction>)
pub fn reverse_one_instruction(&mut self, instruction: &Instruction)
Source§impl State
impl State
pub fn pprint(&self) -> String
pub fn serialize(&self) -> String
Sourcepub fn deserialize(serialized: &str) -> State
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more