The Battle for Wesnoth  1.19.5+dev
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
game_data Class Reference

#include <game_data.hpp>

Inheritance diagram for game_data:

Public Types

enum  PHASE {
  INITIAL , PRELOAD , PRESTART , START ,
  TURN_STARTING_WAITING , TURN_STARTING , TURN_PLAYING , TURN_ENDED ,
  GAME_ENDING , GAME_ENDED
}
 

Public Member Functions

 game_data (const config &level)
 
 game_data (const game_data &data)
 
const configget_variables () const
 
config::attribute_valueget_variable (const std::string &varname)
 throws invalid_variablename_exception if varname is no valid variable name. More...
 
virtual config::attribute_value get_variable_const (const std::string &varname) const
 returns a blank attribute value if varname is no valid variable name. More...
 
configget_variable_cfg (const std::string &varname)
 throws invalid_variablename_exception if varname is no valid variable name. More...
 
void set_variable (const std::string &varname, const t_string &value)
 does nothing if varname is no valid variable name. More...
 
configadd_variable_cfg (const std::string &varname, const config &value=config())
 throws invalid_variablename_exception if varname is no valid variable name. More...
 
variable_access_const get_variable_access_read (const std::string &varname) const
 returns a variable_access that cannot be used to change the game variables More...
 
variable_access_create get_variable_access_write (const std::string &varname)
 returns a variable_access that can be used to change the game variables More...
 
void clear_variable (const std::string &varname)
 Clears attributes config children does nothing if varname is no valid variable name. More...
 
void clear_variable_cfg (const std::string &varname)
 Clears only the config children does nothing if varname is no valid variable name. More...
 
const randomness::mt_rngrng () const
 
randomness::mt_rngrng ()
 
PHASE phase () const
 
void set_phase (PHASE phase)
 
bool has_current_player () const
 returns where there is currently a well defiend "current player", that is for example not the case during start events or during linger mode. More...
 
bool is_before_screen () const
 
bool is_after_start () const
 
const t_stringcannot_end_turn_reason ()
 
bool allow_end_turn () const
 
void set_allow_end_turn (bool value, const t_string &reason="")
 
void write_snapshot (config &cfg) const
 
const std::string & next_scenario () const
 
void set_next_scenario (const std::string &next_scenario)
 
const std::string & get_id () const
 
void set_id (const std::string &value)
 
const std::string & get_theme () const
 
void set_theme (const std::string &value)
 
const std::vector< std::string > & get_defeat_music () const
 
void set_defeat_music (std::vector< std::string > value)
 
const std::vector< std::string > & get_victory_music () const
 
void set_victory_music (std::vector< std::string > value)
 
void set_end_turn_forced (bool v)
 
bool end_turn_forced () const
 
- Public Member Functions inherited from variable_set
virtual ~variable_set ()
 

Static Public Member Functions

static PHASE read_phase (const config &cfg)
 
static void write_phase (config &cfg, game_data::PHASE phase)
 

Public Attributes

std::vector< scoped_wml_variable * > scoped_variables
 
map_location last_selected
 the last location where a select event fired. More...
 

Private Member Functions

void activate_scope_variable (std::string var_name) const
 
variable_access_throw get_variable_access_throw (const std::string &varname)
 Used to delete variables. More...
 

Private Attributes

randomness::mt_rng rng_
 
config variables_
 
PHASE phase_
 
bool can_end_turn_
 
bool end_turn_forced_
 
t_string cannot_end_turn_reason_
 
std::string next_scenario_
 the scenario coming next (for campaigns) More...
 
std::string id_
 
std::string theme_
 
std::vector< std::string > defeat_music_
 
std::vector< std::string > victory_music_
 

Detailed Description

Definition at line 26 of file game_data.hpp.

Member Enumeration Documentation

◆ PHASE

Enumerator
INITIAL 

creating intitial [unit]s, executing toplevel [lua] etc.

next phase: PRELOAD

PRELOAD 

the preload [event] is fired next phase: PRESTART (normal game), TURN_STARTING_WAITING (reloaded game), TURN_PLAYING (reloaded game) or GAME_ENDED (reloadedgame)

PRESTART 

the prestart [event] is fired next phase: START (default), GAME_ENDING

START 

the start [event] is fired next phase: TURN_STARTING_WAITING (default), GAME_ENDING

TURN_STARTING_WAITING 

we are waiting for the turn to start.

The game can be saved here. next phase: TURN_STARTING

TURN_STARTING 

the turn, side turn etc.

[event]s are being fired next phase: TURN_PLAYING (default), GAME_ENDING

TURN_PLAYING 

The User is controlling the game and invoking actions The game can be saved here.

next phase: TURN_PLAYING (default), GAME_ENDING

TURN_ENDED 

The turn_end, side_turn_end etc [events] are fired next phase: TURN_STARTING_WAITING (default), GAME_ENDING.

GAME_ENDING 

The victory etc.

[event]s are fired. next phase: GAME_ENDED

GAME_ENDED 

The game has ended and the user is observing the final state "lingering" The game can be saved here.

Definition at line 70 of file game_data.hpp.

Constructor & Destructor Documentation

◆ game_data() [1/2]

game_data::game_data ( const config level)
explicit

Definition at line 34 of file game_data.cpp.

◆ game_data() [2/2]

game_data::game_data ( const game_data data)

Definition at line 52 of file game_data.cpp.

Member Function Documentation

◆ activate_scope_variable()

void game_data::activate_scope_variable ( std::string  var_name) const
private

◆ add_variable_cfg()

config & game_data::add_variable_cfg ( const std::string &  varname,
const config value = config() 
)

◆ allow_end_turn()

bool game_data::allow_end_turn ( ) const
inline

Definition at line 119 of file game_data.hpp.

References can_end_turn_.

◆ cannot_end_turn_reason()

const t_string& game_data::cannot_end_turn_reason ( )
inline

Definition at line 116 of file game_data.hpp.

References cannot_end_turn_reason_.

◆ clear_variable()

void game_data::clear_variable ( const std::string &  varname)

Clears attributes config children does nothing if varname is no valid variable name.

Definition at line 118 of file game_data.cpp.

References variable_info_mutable< V >::clear(), and get_variable_access_throw().

Referenced by get_global_variable(), and game_lua_kernel::intf_set_variable().

◆ clear_variable_cfg()

void game_data::clear_variable_cfg ( const std::string &  varname)

Clears only the config children does nothing if varname is no valid variable name.

Definition at line 106 of file game_data.cpp.

References variable_info_mutable< V >::clear(), and get_variable_access_throw().

Referenced by scoped_wml_variable::store(), and scoped_wml_variable::~scoped_wml_variable().

◆ end_turn_forced()

bool game_data::end_turn_forced ( ) const
inline

Definition at line 146 of file game_data.hpp.

References end_turn_forced_.

Referenced by playsingle_controller::play_some(), and synced_context::undo_blocked().

◆ get_defeat_music()

const std::vector<std::string>& game_data::get_defeat_music ( ) const
inline

Definition at line 139 of file game_data.hpp.

References defeat_music_.

◆ get_id()

const std::string& game_data::get_id ( ) const
inline

Definition at line 133 of file game_data.hpp.

References id_.

◆ get_theme()

const std::string& game_data::get_theme ( ) const
inline

Definition at line 136 of file game_data.hpp.

References theme_.

◆ get_variable()

config::attribute_value & game_data::get_variable ( const std::string &  varname)

◆ get_variable_access_read()

variable_access_const game_data::get_variable_access_read ( const std::string &  varname) const
inlinevirtual

returns a variable_access that cannot be used to change the game variables

Implements variable_set.

Definition at line 45 of file game_data.hpp.

References activate_scope_variable(), and variables_.

Referenced by get_variable_const(), game_lua_kernel::intf_get_variable(), and game_events::WML_HANDLER_FUNCTION().

◆ get_variable_access_throw()

variable_access_throw game_data::get_variable_access_throw ( const std::string &  varname)
inlineprivate

Used to delete variables.

Definition at line 150 of file game_data.hpp.

References activate_scope_variable(), and variables_.

Referenced by clear_variable(), and clear_variable_cfg().

◆ get_variable_access_write()

variable_access_create game_data::get_variable_access_write ( const std::string &  varname)
inline

returns a variable_access that can be used to change the game variables

Definition at line 51 of file game_data.hpp.

References activate_scope_variable(), and variables_.

Referenced by add_variable_cfg(), get_variable(), get_variable_cfg(), game_lua_kernel::intf_set_variable(), and game_events::WML_HANDLER_FUNCTION().

◆ get_variable_cfg()

config & game_data::get_variable_cfg ( const std::string &  varname)

throws invalid_variablename_exception if varname is no valid variable name.

Definition at line 83 of file game_data.cpp.

References variable_info< V >::as_container(), and get_variable_access_write().

Referenced by game_events::WML_HANDLER_FUNCTION().

◆ get_variable_const()

config::attribute_value game_data::get_variable_const ( const std::string &  varname) const
virtual

returns a blank attribute value if varname is no valid variable name.

Implements variable_set.

Definition at line 71 of file game_data.cpp.

References variable_info< V >::as_scalar(), and get_variable_access_read().

Referenced by storyscreen::story_parser::resolve_wml(), and game_events::builtin_conditions::variable_matches().

◆ get_variables()

const config& game_data::get_variables ( ) const
inline

Definition at line 33 of file game_data.hpp.

References variables_.

Referenced by set_global_variable().

◆ get_victory_music()

const std::vector<std::string>& game_data::get_victory_music ( ) const
inline

Definition at line 142 of file game_data.hpp.

References victory_music_.

◆ has_current_player()

bool game_data::has_current_player ( ) const

returns where there is currently a well defiend "current player", that is for example not the case during start events or during linger mode.

Definition at line 192 of file game_data.cpp.

References phase(), TURN_ENDED, TURN_PLAYING, and TURN_STARTING.

◆ is_after_start()

bool game_data::is_after_start ( ) const

Definition at line 202 of file game_data.cpp.

References INITIAL, phase(), PRELOAD, PRESTART, and START.

◆ is_before_screen()

bool game_data::is_before_screen ( ) const

◆ next_scenario()

const std::string& game_data::next_scenario ( ) const
inline

Definition at line 130 of file game_data.hpp.

References next_scenario_.

Referenced by carryover_show_gold(), game_state::has_next_scenario(), and set_next_scenario().

◆ phase()

PHASE game_data::phase ( ) const
inline

◆ read_phase()

game_data::PHASE game_data::read_phase ( const config cfg)
static

◆ rng() [1/2]

randomness::mt_rng& game_data::rng ( )
inline

Definition at line 68 of file game_data.hpp.

References rng_.

◆ rng() [2/2]

const randomness::mt_rng& game_data::rng ( ) const
inline

Definition at line 67 of file game_data.hpp.

References rng_.

Referenced by synced_context::get_rng_for_action(), and game_state::init().

◆ set_allow_end_turn()

void game_data::set_allow_end_turn ( bool  value,
const t_string reason = "" 
)
inline

Definition at line 120 of file game_data.hpp.

References can_end_turn_, and cannot_end_turn_reason_.

Referenced by game_lua_kernel::intf_allow_end_turn().

◆ set_defeat_music()

void game_data::set_defeat_music ( std::vector< std::string >  value)
inline

Definition at line 140 of file game_data.hpp.

References defeat_music_.

◆ set_end_turn_forced()

void game_data::set_end_turn_forced ( bool  v)
inline

◆ set_id()

void game_data::set_id ( const std::string &  value)
inline

Definition at line 134 of file game_data.hpp.

References id_.

◆ set_next_scenario()

void game_data::set_next_scenario ( const std::string &  next_scenario)
inline

Definition at line 131 of file game_data.hpp.

References next_scenario(), and next_scenario_.

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

◆ set_phase()

void game_data::set_phase ( PHASE  phase)
inline

◆ set_theme()

void game_data::set_theme ( const std::string &  value)
inline

Definition at line 137 of file game_data.hpp.

References theme_.

◆ set_variable()

void game_data::set_variable ( const std::string &  varname,
const t_string value 
)

does nothing if varname is no valid variable name.

Definition at line 88 of file game_data.cpp.

References ERR_NG, and get_variable().

Referenced by get_global_variable(), and SYNCED_COMMAND_HANDLER_FUNCTION().

◆ set_victory_music()

void game_data::set_victory_music ( std::vector< std::string >  value)
inline

Definition at line 143 of file game_data.hpp.

References victory_music_.

◆ write_phase()

void game_data::write_phase ( config cfg,
game_data::PHASE  phase 
)
static

Definition at line 207 of file game_data.cpp.

References INITIAL, phase(), PRELOAD, PRESTART, and TURN_STARTING_WAITING.

Referenced by write_snapshot().

◆ write_snapshot()

void game_data::write_snapshot ( config cfg) const

Member Data Documentation

◆ can_end_turn_

bool game_data::can_end_turn_
private

Definition at line 159 of file game_data.hpp.

Referenced by allow_end_turn(), set_allow_end_turn(), and write_snapshot().

◆ cannot_end_turn_reason_

t_string game_data::cannot_end_turn_reason_
private

Definition at line 161 of file game_data.hpp.

Referenced by cannot_end_turn_reason(), set_allow_end_turn(), and write_snapshot().

◆ defeat_music_

std::vector<std::string> game_data::defeat_music_
private

Definition at line 167 of file game_data.hpp.

Referenced by get_defeat_music(), set_defeat_music(), and write_snapshot().

◆ end_turn_forced_

bool game_data::end_turn_forced_
private

Definition at line 160 of file game_data.hpp.

Referenced by end_turn_forced(), and set_end_turn_forced().

◆ id_

std::string game_data::id_
private

Definition at line 165 of file game_data.hpp.

Referenced by get_id(), set_id(), and write_snapshot().

◆ last_selected

map_location game_data::last_selected

the last location where a select event fired.

Used by wml menu items with needs_select=yes

Definition at line 126 of file game_data.hpp.

Referenced by play_controller::init_side_begin(), and game_events::wml_event_pump::process_event().

◆ next_scenario_

std::string game_data::next_scenario_
private

the scenario coming next (for campaigns)

Definition at line 163 of file game_data.hpp.

Referenced by next_scenario(), set_next_scenario(), and write_snapshot().

◆ phase_

PHASE game_data::phase_
private

Definition at line 158 of file game_data.hpp.

Referenced by phase(), set_phase(), and write_snapshot().

◆ rng_

randomness::mt_rng game_data::rng_
private

Definition at line 156 of file game_data.hpp.

Referenced by rng(), and write_snapshot().

◆ scoped_variables

std::vector<scoped_wml_variable*> game_data::scoped_variables

◆ theme_

std::string game_data::theme_
private

Definition at line 166 of file game_data.hpp.

Referenced by get_theme(), set_theme(), and write_snapshot().

◆ variables_

config game_data::variables_
private

◆ victory_music_

std::vector<std::string> game_data::victory_music_
private

Definition at line 168 of file game_data.hpp.

Referenced by get_victory_music(), set_victory_music(), and write_snapshot().


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