The Battle for Wesnoth  1.15.0-dev
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
saved_game Class Reference

#include <saved_game.hpp>

Public Member Functions

 saved_game ()
 
 saved_game (const saved_game &state)
 
 saved_game (config cfg)
 
 ~saved_game ()
 
saved_gameoperator= (const saved_game &other)=delete
 
saved_gameoperator= (saved_game &&other)
 
void swap (saved_game &other)
 
void set_data (config &cfg)
 destroys the passed config. More...
 
void clear ()
 
void write_config (config_writer &out) const
 writes the config information into a stream (file) More...
 
void write_general_info (config_writer &out) const
 
void write_carryover (config_writer &out) const
 
void write_starting_point (config_writer &out) const
 
config to_config () const
 
game_classificationclassification ()
 
const game_classificationclassification () const
 
mp_game_settingsmp_settings ()
 Multiplayer parameters for this game. More...
 
const mp_game_settingsmp_settings () const
 
void set_carryover_sides_start (config carryover_sides_start)
 
void expand_scenario ()
 copies the content of a [scenario] with the correct id attribute from the game config into this object. More...
 
void expand_carryover ()
 merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [carryover_sides_start] afterwards More...
 
void expand_mp_events ()
 adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because variables are persitent anyway to we don't need it should be called after expand_scenario() but before expand_carryover() More...
 
void load_mod (const std::string &type, const std::string &id)
 helper for expand_mp_events(); More...
 
void expand_mp_options ()
 adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next level. More...
 
void expand_random_scenario ()
 takes care of generate_map=, generate_scenario=, map= attributes This should be called before expanding carryover or mp_events because this might completely replace starting_point_. More...
 
void check_require_scenario ()
 Add addon_id information if needed. More...
 
bool valid () const
 
configset_snapshot (config snapshot)
 
void set_scenario (config scenario)
 
void remove_snapshot ()
 
bool is_mid_game_save () const
 
void convert_to_start_save ()
 converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next scenaio, The saved_game must contain a [snapshot] made during the linger mode of the last scenaio. More...
 
void set_random_seed ()
 sets the random seed if that didn't already happen. More...
 
const configget_replay_starting_point ()
 
std::string get_scenario_id ()
 
configget_starting_point ()
 
const configget_starting_point () const
 
configreplay_start ()
 
const configreplay_start () const
 
bool not_corrupt () const
 
void update_label ()
 sets classification().label to the correct value. More...
 
void cancel_orders ()
 
void unify_controllers ()
 
void set_defaults ()
 does some post loading stuff must be used before passing the data to connect_engine More...
 
replay_recorder_baseget_replay ()
 
const replay_recorder_baseget_replay () const
 

Static Public Member Functions

static void post_scenario_generation (const config &old_scenario, config &generated_scenario)
 copies attributes & tags from the 'outer' [scenario] to the scenario that is generated by scenario_generation= More...
 

Private Types

enum  STARTING_POINT_TYPE { STARTING_POINT_NONE, STARTING_POINT_SNAPSHOT, STARTING_POINT_SCENARIO, STARTING_POINT_INVALID }
 

Private Attributes

bool has_carryover_expanded_
 
config carryover_
 depends on has_carryover_expanded_: if true: The carryover information for all sides from the previous scenario that aren't used in this scenario (to be carried over to the next scenario). More...
 
config replay_start_
 snapshot made before the start event. More...
 
game_classification classification_
 some general information of the game that doesn't change during the game More...
 
mp_game_settings mp_settings_
 
STARTING_POINT_TYPE starting_point_type_
 
config starting_point_
 The starting pos where the (non replay) game will be started from. More...
 
replay_recorder_base replay_data_
 

Detailed Description

Definition at line 24 of file saved_game.hpp.

Member Enumeration Documentation

◆ STARTING_POINT_TYPE

Enumerator
STARTING_POINT_NONE 

There is no scenario stating pos data (start-of-scenario).

STARTING_POINT_SNAPSHOT 

We have a [snapshot] (mid-game-savefile).

STARTING_POINT_SCENARIO 

We have a [scenario] (start-of-scenario) savefile.

STARTING_POINT_INVALID 

We failed to get a starting pos in expand_scenario.

Definition at line 26 of file saved_game.hpp.

Constructor & Destructor Documentation

◆ saved_game() [1/3]

saved_game::saved_game ( )

Definition at line 87 of file saved_game.cpp.

◆ saved_game() [2/3]

saved_game::saved_game ( const saved_game state)

Definition at line 113 of file saved_game.cpp.

◆ saved_game() [3/3]

saved_game::saved_game ( config  cfg)
explicit

Definition at line 99 of file saved_game.cpp.

References set_data().

◆ ~saved_game()

saved_game::~saved_game ( )
inline

Member Function Documentation

◆ cancel_orders()

void saved_game::cancel_orders ( )

◆ check_require_scenario()

void saved_game::check_require_scenario ( )

◆ classification() [1/2]

game_classification& saved_game::classification ( )
inline

Definition at line 55 of file saved_game.hpp.

References classification_.

Referenced by mp::add_multiplayer_classification(), savegame::loadgame::check_version_compatibility(), ng::connect_engine::connect_engine(), ng::create_engine::create_engine(), savegame::ingame_savegame::create_initial_filename(), savegame::replay_savegame::create_initial_filename(), savegame::autosave_savegame::create_initial_filename(), savegame::scenariostart_savegame::create_initial_filename(), sp::enter_create_mode(), expand_mp_options(), expand_scenario(), gui2::dialogs::mp_join_game::fetch_game_config(), ng::configure_engine::fog_game_default(), ng::configure_engine::force_lock_settings(), play_controller::get_classification(), ng::create_engine::init_all_levels(), ng::create_engine::init_extras(), game_launcher::launch_game(), mp::level_to_gamestate(), game_launcher::load_game(), savegame::loadgame::load_game(), game_launcher::new_campaign(), play_controller::play_controller(), campaign_controller::play_game(), game_launcher::play_multiplayer(), game_launcher::play_multiplayer_commandline(), game_launcher::play_render_image_mode(), playsingle_controller::play_scenario_init(), game_launcher::play_test(), gui2::dialogs::mp_create_game::post_show(), ng::create_engine::prepare_for_campaign(), ng::create_engine::prepare_for_era_and_mods(), ng::create_engine::prepare_for_saved_game(), ng::create_engine::prepare_for_scenario(), ng::create_engine::set_current_level(), set_defaults(), ng::configure_engine::set_oos_debug(), game_launcher::set_test(), game_launcher::set_tutorial(), campaign_controller::show_carryover_message(), ng::side_engine::side_engine(), mp::start_client(), mp::start_local_game_commandline(), ng::create_engine::toggle_mod(), game_launcher::unit_test(), gui2::dialogs::mp_create_game::update_details(), update_label(), and ng::configure_engine::village_gold_default().

◆ classification() [2/2]

const game_classification& saved_game::classification ( ) const
inline

Definition at line 56 of file saved_game.hpp.

References classification_.

◆ clear()

void saved_game::clear ( )

◆ convert_to_start_save()

void saved_game::convert_to_start_save ( )

converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next scenaio, The saved_game must contain a [snapshot] made during the linger mode of the last scenaio.

Definition at line 551 of file saved_game.cpp.

References carryover_, config::clear(), has_carryover_expanded_, carryover_info::merge_old_carryover(), remove_snapshot(), replay_data_, replay_start_, carryover_info::rng(), randomness::mt_rng::rotate_random(), starting_point_, STARTING_POINT_SNAPSHOT, starting_point_type_, and carryover_info::to_config().

Referenced by is_mid_game_save(), and campaign_controller::play_game().

◆ expand_carryover()

void saved_game::expand_carryover ( )

merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [carryover_sides_start] afterwards

Definition at line 482 of file saved_game.cpp.

References carryover_, expand_scenario(), get_starting_point(), has_carryover_expanded_, STARTING_POINT_SCENARIO, starting_point_type_, carryover_info::to_config(), carryover_info::transfer_all_to(), and carryover_info::transfer_to().

Referenced by get_replay_starting_point(), mp_settings(), and campaign_controller::play_game().

◆ expand_mp_events()

void saved_game::expand_mp_events ( )

adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because variables are persitent anyway to we don't need it should be called after expand_scenario() but before expand_carryover()

Definition at line 343 of file saved_game.cpp.

References mp_game_settings::active_mods, game_classification::campaign, config::child_range(), classification_, config::clear_children(), expand_scenario(), load_mod(), mp_game_settings::mp_era, mp_settings_, starting_point_, STARTING_POINT_SCENARIO, and starting_point_type_.

Referenced by mp::initial_level_config(), mp_settings(), campaign_controller::play_game(), and mp::start_local_game_commandline().

◆ expand_mp_options()

void saved_game::expand_mp_options ( )

adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next level.

Note that since [variabels] are persistent we only use this once at the beginning of a campaign but calling it multiple times is no harm eigher

Definition at line 387 of file saved_game.cpp.

References mp_game_settings::active_mods, carryover_, config::child_or_add(), config::child_range(), classification(), ERR_NG, config::find_child(), get_scenario_id(), has_carryover_expanded_, LOG_NG, mp_game_settings::mp_era, mp_settings(), mp_settings_, preferences::options(), STARTING_POINT_SCENARIO, and starting_point_type_.

Referenced by mp::initial_level_config(), mp_settings(), campaign_controller::play_game(), and mp::start_local_game_commandline().

◆ expand_random_scenario()

void saved_game::expand_random_scenario ( )

takes care of generate_map=, generate_scenario=, map= attributes This should be called before expanding carryover or mp_events because this might completely replace starting_point_.

Definition at line 418 of file saved_game.cpp.

References config::child(), expand_scenario(), LOG_NG, post_scenario_generation(), random_generate_map(), random_generate_scenario(), filesystem::read_map(), set_defaults(), starting_point_, STARTING_POINT_SCENARIO, starting_point_type_, update_label(), and cursor::WAIT.

Referenced by mp::initial_level_config(), mp_settings(), campaign_controller::play_game(), ng::create_engine::prepare_for_new_level(), and mp::start_local_game_commandline().

◆ expand_scenario()

void saved_game::expand_scenario ( )

◆ get_replay() [1/2]

replay_recorder_base& saved_game::get_replay ( )
inline

◆ get_replay() [2/2]

const replay_recorder_base& saved_game::get_replay ( ) const
inline

Definition at line 122 of file saved_game.hpp.

References replay_data_.

◆ get_replay_starting_point()

const config & saved_game::get_replay_starting_point ( )
Returns
the starting pos for replays. Usually this is [replay_start] but it can also be a [scenario] if no [replay_start] is present

Definition at line 532 of file saved_game.cpp.

References config::child(), config::empty(), expand_carryover(), expand_scenario(), has_carryover_expanded_, replay_start_, starting_point_, STARTING_POINT_SCENARIO, and starting_point_type_.

Referenced by is_mid_game_save(), and campaign_controller::playsingle_scenario().

◆ get_scenario_id()

std::string saved_game::get_scenario_id ( )
Returns
the id of the currently played scenario or the id of the next scenario if this is a between-scenaios-save (also called start-of-scenario-save).

Definition at line 593 of file saved_game.cpp.

References carryover_, has_carryover_expanded_, starting_point_, STARTING_POINT_SCENARIO, STARTING_POINT_SNAPSHOT, and starting_point_type_.

Referenced by mp::add_multiplayer_classification(), sp::enter_create_mode(), expand_mp_options(), is_mid_game_save(), and campaign_controller::play_game().

◆ get_starting_point() [1/2]

config & saved_game::get_starting_point ( )

◆ get_starting_point() [2/2]

const config& saved_game::get_starting_point ( ) const
inline

Definition at line 108 of file saved_game.hpp.

References starting_point_.

◆ is_mid_game_save()

bool saved_game::is_mid_game_save ( ) const
inline

◆ load_mod()

void saved_game::load_mod ( const std::string &  type,
const std::string &  id 
)

◆ mp_settings() [1/2]

mp_game_settings& saved_game::mp_settings ( )
inline

◆ mp_settings() [2/2]

const mp_game_settings& saved_game::mp_settings ( ) const
inline

◆ not_corrupt()

bool saved_game::not_corrupt ( ) const

Definition at line 609 of file saved_game.cpp.

Referenced by replay_start(), and write_carryover().

◆ operator=() [1/2]

saved_game& saved_game::operator= ( const saved_game other)
delete

Referenced by ~saved_game().

◆ operator=() [2/2]

saved_game & saved_game::operator= ( saved_game &&  other)

Definition at line 655 of file saved_game.cpp.

References swap().

◆ post_scenario_generation()

void saved_game::post_scenario_generation ( const config old_scenario,
config generated_scenario 
)
static

copies attributes & tags from the 'outer' [scenario] to the scenario that is generated by scenario_generation=

Definition at line 455 of file saved_game.cpp.

References config::add_child(), and config::child_range().

Referenced by expand_random_scenario(), ng::create_engine::init_generated_level_data(), and mp_settings().

◆ remove_snapshot()

void saved_game::remove_snapshot ( )

◆ replay_start() [1/2]

config& saved_game::replay_start ( )
inline

◆ replay_start() [2/2]

const config& saved_game::replay_start ( ) const
inline

◆ set_carryover_sides_start()

void saved_game::set_carryover_sides_start ( config  carryover_sides_start)

◆ set_data()

void saved_game::set_data ( config cfg)

◆ set_defaults()

void saved_game::set_defaults ( )

◆ set_random_seed()

void saved_game::set_random_seed ( )

sets the random seed if that didn't already happen.

Definition at line 131 of file saved_game.cpp.

References carryover_, randomness::generator, randomness::rng::get_random_int(), and has_carryover_expanded_.

Referenced by mp::initial_level_config(), and is_mid_game_save().

◆ set_scenario()

void saved_game::set_scenario ( config  scenario)

◆ set_snapshot()

config & saved_game::set_snapshot ( config  snapshot)

◆ swap()

void saved_game::swap ( saved_game other)

◆ to_config()

config saved_game::to_config ( ) const

◆ unify_controllers()

void saved_game::unify_controllers ( )

Definition at line 640 of file saved_game.cpp.

References config::child_range(), and starting_point_.

Referenced by game_launcher::load_game(), and replay_start().

◆ update_label()

void saved_game::update_label ( )

◆ valid()

bool saved_game::valid ( ) const

◆ write_carryover()

void saved_game::write_carryover ( config_writer out) const

◆ write_config()

void saved_game::write_config ( config_writer out) const

◆ write_general_info()

void saved_game::write_general_info ( config_writer out) const

◆ write_starting_point()

void saved_game::write_starting_point ( config_writer out) const

Member Data Documentation

◆ carryover_

config saved_game::carryover_
private

depends on has_carryover_expanded_: if true: The carryover information for all sides from the previous scenario that aren't used in this scenario (to be carried over to the next scenario).

if false: The carryover information for all sides from the previous scenario.

Definition at line 131 of file saved_game.hpp.

Referenced by clear(), convert_to_start_save(), expand_carryover(), expand_mp_options(), expand_scenario(), get_scenario_id(), load_mod(), set_carryover_sides_start(), set_data(), set_random_seed(), swap(), to_config(), and write_carryover().

◆ classification_

game_classification saved_game::classification_
private

some general information of the game that doesn't change during the game

Definition at line 135 of file saved_game.hpp.

Referenced by classification(), clear(), expand_mp_events(), set_data(), swap(), to_config(), and write_general_info().

◆ has_carryover_expanded_

bool saved_game::has_carryover_expanded_
private

◆ mp_settings_

mp_game_settings saved_game::mp_settings_
private

◆ replay_data_

replay_recorder_base saved_game::replay_data_
private

◆ replay_start_

config saved_game::replay_start_
private

snapshot made before the start event.

To be used as a starting pos for replays

Definition at line 133 of file saved_game.hpp.

Referenced by clear(), convert_to_start_save(), get_replay_starting_point(), replay_start(), set_data(), swap(), to_config(), and write_config().

◆ starting_point_

config saved_game::starting_point_
private

The starting pos where the (non replay) game will be started from.

This can eigher be a [scenario] for a fresh game or a [snapshot] if this is a reloaded game

Definition at line 143 of file saved_game.hpp.

Referenced by cancel_orders(), check_require_scenario(), clear(), convert_to_start_save(), expand_mp_events(), expand_random_scenario(), expand_scenario(), get_replay_starting_point(), get_scenario_id(), get_starting_point(), load_mod(), remove_snapshot(), set_data(), set_defaults(), set_scenario(), set_snapshot(), swap(), to_config(), unify_controllers(), update_label(), and write_starting_point().

◆ starting_point_type_

STARTING_POINT_TYPE saved_game::starting_point_type_
private

The documentation for this class was generated from the following files: