The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
configure_engine.cpp
Go to the documentation of this file.
1 #include "configure_engine.hpp"
4 #include "mp_game_settings.hpp"
5 #include "settings.hpp"
6 #include "tod_manager.hpp"
7 
8 #include <cassert>
9 #include <sstream>
10 #include <iostream>
11 
12 namespace ng {
13 
15  state_(state),
16  parameters_(state_.mp_settings()),
17  side_cfg_(state_.get_starting_pos().child_or_empty("side"))
18 {
19  if (!state_.get_starting_pos().has_child("side")) {
20  std::stringstream msg;
21  msg << "Configure Engine: No sides found in scenario, aborting.";
22  std::cerr << msg.str();
23  std::cerr << "Full scenario config:\n";
24  std::cerr << state_.to_config().debug();
25  throw game::error(msg.str());
26  }
27 
29  if(state_.classification().get_tagname() == "scenario") {
30  for (const config& scenario :
32 
33  if (scenario["allow_new_game"].to_bool(true) || game_config::debug) {
34 
35  const std::string& title = (!scenario["new_game_title"].empty()) ?
36  scenario["new_game_title"] : scenario["name"];
37 
38  entry_points_.push_back(&scenario);
39  entry_point_titles_.push_back(title);
40  }
41  }
42  }
43 }
44 
60 }
61 
63  return state_.get_starting_pos()["force_lock_settings"].to_bool(!state_.classification().is_normal_mp_game());
64 }
65 
83 mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode() const { return parameters_.random_faction_mode; }
85 
104 void configure_engine::set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val) { parameters_.random_faction_mode = val;}
106 
107 void configure_engine::set_scenario(size_t scenario_num) {
108  const config& scenario = *entry_points_[scenario_num];
109 
110  parameters_.hash = scenario.hash();
111  state_.set_scenario(scenario);
112 }
113 
115  for (size_t i = 0; i < entry_points_.size(); ++i) {
116  if ((**(entry_points_.begin() + i))["id"] == scenario_id) {
117  set_scenario(i);
118  return true;
119  }
120  }
121  return false;
122 }
123 
125  utils::string_map i18n_symbols;
126  i18n_symbols["login"] = preferences::login();
127  return vgettext("$login|’s game", i18n_symbols);
128 }
130  return use_map_settings() ?
133 }
135  return use_map_settings() && !side_cfg_.empty() ?
138 }
140  return use_map_settings() && !side_cfg_.empty() ?
141  settings::get_village_support(side_cfg_["village_support"]) :
143 }
145  return use_map_settings() ?
146  settings::get_xp_modifier(state_.get_starting_pos()["experience_modifier"]) :
148 }
151 }
154 }
157 }
160 }
162  return preferences::countdown();
163 }
166 }
168  return use_map_settings() ?
169  state_.get_starting_pos()["random_start_time"].to_bool(false) :
171 }
173  return use_map_settings() && !side_cfg_.empty() ?
174  side_cfg_["fog"].to_bool(state_.classification().is_normal_mp_game()) :
176 }
178  return use_map_settings() && !side_cfg_.empty() ?
179  side_cfg_["shroud"].to_bool(false) :
181 }
184 }
186 {
188 }
191 }
192 mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode_default() const {
193  return mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(preferences::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT);
194 }
195 
197  return preferences::options();
198 }
199 
201  return parameters_;
202 }
203 
204 const std::vector<std::string>& configure_engine::entry_point_titles() const {
205  return entry_point_titles_;
206 }
207 
209 {
211  const mp_game_settings& params = this->state_.mp_settings();
212 
213  if (params.random_start_time) {
214  if (!tod_manager::is_start_ToD(scenario["random_start_time"])) {
215  scenario["random_start_time"] = true;
216  }
217  }
218  else {
219  scenario["random_start_time"] = false;
220  }
221  scenario["experience_modifier"] = params.xp_modifier;
222  scenario["turns"] = params.num_turns;
223 
224  for (config& side : scenario.child_range("side"))
225  {
226  side["fog"] = params.fog_game;
227  side["shroud"] = params.shroud_game;
228  if (!params.use_map_settings) {
229  side["village_gold"] = params.village_gold;
230  side["village_support"] = params.village_support;
231  }
232  }
233 }
234 
235 } //end namespace ng
void set_registered_users_only(bool val)
child_itors child_range(const std::string &key)
Definition: config.cpp:613
int mp_countdown_reservoir_time_default() const
void set_shroud_game(bool val)
void set_mp_countdown_reservoir_time(int val)
std::string random_faction_mode()
void set_shuffle_sides(bool val)
int num_turns_default() const
std::string get_tagname() const
config to_config() const
Definition: saved_game.cpp:510
int mp_countdown_init_time() const
bool use_map_settings_default() const
const mp_game_settings * mp_settings
Definition: resources.cpp:38
bool use_map_settings() const
void set_scenario(config scenario)
Definition: saved_game.cpp:458
static l_noret error(LoadState *S, const char *why)
Definition: lundump.cpp:29
const std::vector< std::string > & entry_point_titles() const
bool registered_users_only() const
void set_mp_countdown_turn_bonus(int val)
int mp_countdown_action_bonus() const
bool random_start_time() const
int xp_modifier_default() const
const mp_game_settings & get_parameters() const
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
Definition: settings.cpp:42
configure_engine(saved_game &state)
GLuint const GLfloat * val
Definition: glew.h:2614
bool random_start_time_default() const
mp_game_settings & parameters_
const GLfloat * params
Definition: glew.h:1499
int mp_countdown_reservoir_time() const
void set_random_start_time(bool val)
std::string debug() const
Definition: config.cpp:1438
bool fog_game_default() const
bool empty() const
Definition: config.cpp:1105
void set_village_gold(int val)
int get_village_support(const std::string &value)
Gets the village unit level support.
Definition: settings.cpp:47
void set_use_map_settings(bool val)
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
Definition: config.cpp:651
const config & options()
static game_config_manager * get()
bool allow_observers() const
int countdown_turn_bonus()
std::map< std::string, t_string > string_map
int mp_countdown_init_time_default() const
void set_game_name(std::string name)
bool shuffle_sides_default() const
General settings and defaults for scenarios.
bool allow_observers_default() const
std::string game_name_default() const
int countdown_reservoir_time()
void set_village_support(int val)
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const
const config & options_default() const
void set_oos_debug(bool val)
void set_mp_countdown(bool val)
void set_fog_game(bool val)
bool registered_users_only()
void set_mp_countdown_action_bonus(int val)
bool shuffle_sides() const
config & get_starting_pos()
Definition: saved_game.cpp:472
bool force_lock_settings() const
std::string game_name() const
std::string login()
void set_allow_observers(bool val)
int village_gold_default() const
int mp_countdown_turn_bonus_default() const
void set_mp_countdown_init_time(int val)
const config & game_config() const
size_t i
Definition: function.cpp:1057
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
Definition: settings.cpp:52
bool registered_users_only_default() const
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
void set_num_turns(int val)
std::vector< const config * > entry_points_
std::string vgettext(const char *msgid, const utils::string_map &symbols)
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode() const
static bool is_start_ToD(const std::string &)
std::string hash() const
Definition: config.cpp:1468
void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
int village_support() const
std::vector< std::string > entry_point_titles_
game_classification & classification()
Definition: saved_game.hpp:54
void set_scenario(size_t scenario_num)
bool shroud_game_default() const
bool mp_countdown() const
bool mp_countdown_default() const
int countdown_action_bonus()
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool random_start_time()
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:58
int get_turns(const std::string &value)
Gets the number of turns.
Definition: settings.cpp:29
void set_xp_modifier(int val)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
const config & options() const
int mp_countdown_action_bonus_default() const
int village_support_default() const
int mp_countdown_turn_bonus() const
void set_options(const config &cfg)