The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_data.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /** @file */
16 
17 #ifndef GAME_DATA_HPP_INCLUDED
18 #define GAME_DATA_HPP_INCLUDED
19 
20 #include "config.hpp"
21 #include "game_end_exceptions.hpp"
22 #include "map/location.hpp"
23 #include "mt_rng.hpp"
24 #include "variable_info.hpp"
25 
27 class t_string;
28 
29 class game_data : public variable_set {
30 public:
31  game_data();
32  explicit game_data(const config& level);
33  game_data(const game_data& data);
34 
35  std::vector<scoped_wml_variable*> scoped_variables;
36 
37  const config& get_variables() const { return variables_; }
38  /// throws invalid_variablename_exception if varname is no valid variable name.
40  /// returns a blank attribute value if varname is no valid variable name.
41  virtual config::attribute_value get_variable_const(const std::string& varname) const;
42  /// throws invalid_variablename_exception if varname is no valid variable name.
43  config& get_variable_cfg(const std::string& varname);
44  /// does nothing if varname is no valid variable name.
45  void set_variable(const std::string& varname, const t_string& value);
46  /// throws invalid_variablename_exception if varname is no valid variable name.
47  config& add_variable_cfg(const std::string& varname, const config& value=config());
48  /// returns a variable_access that cannot be used to change the game variables
50  {
51  activate_scope_variable(varname);
52  return variable_access_const(varname, variables_);
53  }
54  /// returns a variable_access that can be used to change the game variables
56  {
57  activate_scope_variable(varname);
58  return variable_access_create(varname, variables_);
59  }
60  /// Clears attributes config children
61  /// does nothing if varname is no valid variable name.
62  void clear_variable(const std::string& varname);
63  /// Clears only the config children
64  /// does nothing if varname is no valid variable name.
65  void clear_variable_cfg(const std::string& varname);
66 
67  const rand_rng::mt_rng& rng() const { return rng_; }
68  rand_rng::mt_rng& rng() { return rng_; }
69 
70  enum PHASE {
76  };
77 
78  PHASE phase() const { return phase_; }
80 
81  bool allow_end_turn() const { return can_end_turn_; }
83 
84  /** the last location where a select event fired. Used by wml menu items with needs_select=yes*/
86 
87  void write_snapshot(config& cfg) const;
88 
89  const std::string& next_scenario() const { return next_scenario_; }
91 
92 private:
93  void activate_scope_variable(std::string var_name) const;
94  ///Used to delete variables.
96  {
97  activate_scope_variable(varname);
98  return variable_access_throw(varname, variables_);
99  }
100 
105  std::string next_scenario_; /**< the scenario coming next (for campaigns) */
106 };
107 
108 #endif
PHASE phase() const
Definition: game_data.hpp:78
map_location last_selected
the last location where a select event fired.
Definition: game_data.hpp:85
const rand_rng::mt_rng & rng() const
Definition: game_data.hpp:67
void activate_scope_variable(std::string var_name) const
Definition: game_data.cpp:152
GLint level
Definition: glew.h:1220
config & get_variable_cfg(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
Definition: game_data.cpp:87
void set_next_scenario(const std::string &next_scenario)
Definition: game_data.hpp:90
variable_info< variable_info_detail::vit_const > variable_access_const
this variable accessor is takes a const reference and is guaranteed to not change the config...
Extends variable_info with methods that can only be applied if vit != vit_const.
non_const_variable_info< variable_info_detail::vit_throw_if_not_existent > variable_access_throw
this variable accessor will throw an exception when trying to access a non existent table...
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
bool can_end_turn_
Definition: game_data.hpp:104
Definitions for the interface to Wesnoth Markup Language (WML).
Variant for storing WML attributes.
Definition: config.hpp:223
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
Definition: game_data.cpp:70
const config & get_variables() const
Definition: game_data.hpp:37
void set_phase(PHASE phase)
Definition: game_data.hpp:79
rand_rng::mt_rng rng_
Definition: game_data.hpp:101
non_const_variable_info< variable_info_detail::vit_create_if_not_existent > variable_access_create
this variable accessor will create a childtable when resolving name if it doesn't exist yet...
std::string next_scenario_
the scenario coming next (for campaigns)
Definition: game_data.hpp:105
virtual config::attribute_value get_variable_const(const std::string &varname) const
returns a blank attribute value if varname is no valid variable name.
Definition: game_data.cpp:75
bool allow_end_turn() const
Definition: game_data.hpp:81
void write_snapshot(config &cfg) const
Definition: game_data.cpp:134
variable_access_create get_variable_access_write(const std::string &varname)
returns a variable_access that can be used to change the game variables
Definition: game_data.hpp:55
GLsizei const GLfloat * value
Definition: glew.h:1817
void set_variable(const std::string &varname, const t_string &value)
does nothing if varname is no valid variable name.
Definition: game_data.cpp:92
PHASE phase_
Definition: game_data.hpp:103
variable_access_throw get_variable_access_throw(const std::string &varname)
Used to delete variables.
Definition: game_data.hpp:95
void set_allow_end_turn(bool value)
Definition: game_data.hpp:82
Encapsulates the map of the game.
Definition: location.hpp:38
rand_rng::mt_rng & rng()
Definition: game_data.hpp:68
std::vector< scoped_wml_variable * > scoped_variables
Definition: game_data.hpp:35
const std::string & next_scenario() const
Definition: game_data.hpp:89
void clear_variable_cfg(const std::string &varname)
Clears only the config children does nothing if varname is no valid variable name.
Definition: game_data.cpp:110
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
Definition: game_data.hpp:49
config & add_variable_cfg(const std::string &varname, const config &value=config())
throws invalid_variablename_exception if varname is no valid variable name.
Definition: game_data.cpp:104
void clear_variable(const std::string &varname)
Clears attributes config children does nothing if varname is no valid variable name.
Definition: game_data.cpp:122
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
config variables_
Definition: game_data.hpp:102
GLsizei const GLcharARB ** string
Definition: glew.h:4503