Skip to main content

GameState

Struct GameState 

Source
pub struct GameState {
Show 31 fields pub references: BTreeMap<u32, String>, pub climate: u32, pub start_condition: u32, pub terrain: u32, pub seed: u32, pub size: i32, pub flags: u32, pub scenario: i32, pub random_index: u32, pub random_state: Vec<u32>, pub town_name: String, pub goal_done: bool, pub goal: Option<ObjId>, pub entity_time: i64, pub entities: Vec<Option<ObjId>>, pub buckets: Vec<Vec<Option<ObjId>>>, pub bucket_values: [[i32; 5]; 2], pub schedules: Vec<(i32, i32, i32, i64)>, pub version: u32, pub wide_strings: bool, pub persist_state: Vec<u8>, pub entity_manager_version: u32, pub achievements: Fields, pub animations: Vec<u8>, pub audio_scene: Vec<u8>, pub camera: Option<SceneCamera>, pub terrain_map: Option<MapComponent>, pub town: Fields, pub map: GameMap, pub managers: Fields, pub objects: BTreeMap<ObjId, Object>,
}
Expand description

The whole game state.

Fields§

§references: BTreeMap<u32, String>

The external reference table (ExternalFactory::SerializeReferenceTable).

§climate: u32

The climate.

§start_condition: u32

The start condition.

§terrain: u32

The terrain type.

§seed: u32

The map seed.

§size: i32

The map size.

§flags: u32

The game’s flags.

§scenario: i32

The scenario.

§random_index: u32

The index of the game’s Random (System::Random::Serialize).

§random_state: Vec<u32>

The 624 words of the game’s Random.

§town_name: String

The town’s name.

§goal_done: bool

The goal’s state.

§goal: Option<ObjId>

The goal, if any.

§entity_time: i64

The entity manager’s clock.

Original: FUN_1400c9970, FUN_140022500.

§entities: Vec<Option<ObjId>>

The entities.

§buckets: Vec<Vec<Option<ObjId>>>

The scheduler’s five bucket lists.

§bucket_values: [[i32; 5]; 2]

The scheduler’s two five-int arrays.

§schedules: Vec<(i32, i32, i32, i64)>

Each entity’s schedule (the low 24 bits; the time).

§version: u32

The game loop serializer’s version (3 in the samples).

§wide_strings: bool

The strings were written as UTF-16 (2015 builds) rather than 8-bit.

§persist_state: Vec<u8>

InternalFactory::ResetPersistState’s block, as written.

§entity_manager_version: u32

The entity manager block’s version.

§achievements: Fields

AchievementManager::Persist: the achievement instances.

§animations: Vec<u8>

The animations: a whole block (markers included) carried through undecoded. An empty one (a new game) is written as the engine’s empty state (empty_animations).

§audio_scene: Vec<u8>

The sound scene: a whole block carried through undecoded. An empty one is written as the engine’s empty state (empty_audio_scene).

§camera: Option<SceneCamera>

The game camera.

Original: FUN_14009dd90.

§terrain_map: Option<MapComponent>

The terrain.

Original: FUN_1400b59a0.

§town: Fields

The town manager.

Original: FUN_140094c30.

§map: GameMap

The gameplay map.

Original: FUN_1400a45d0.

§managers: Fields

The blocks after the map: jobs, tools, calendar, event_log, environment and minimap (see savegame_schema).

§objects: BTreeMap<ObjId, Object>

Every object in the stream, by number.

Implementations§

Source§

impl GameState

Source

pub fn new_object(&mut self, name: &'static str) -> Option<ObjId>

A new object of type name with default fields (crate::savegame_schema::default_fields) and the next free factory index. The tag (Internal, drawn on the factory’s own Random in the original) is the index here; returns its id.

Source

pub fn decode(state: &[u8]) -> Result<GameState>

Decode an expanded game-state stream (crate::save::Save::state).

Source

pub fn encode(&self) -> Result<Vec<u8>>

The writing side of GameState::decode: the same stream, with each object written inline where it is first referenced, in the order the decoder met them.

Trait Implementations§

Source§

impl Clone for GameState

Source§

fn clone(&self) -> GameState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GameState

Source§

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

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

impl Default for GameState

Source§

fn default() -> GameState

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

Auto Trait Implementations§

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.