The Battle for Wesnoth  1.13.10+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 /*
2  Copyright (C) 2013 - 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
15 
16 #include "formula/string_utils.hpp"
17 #include "game_config_manager.hpp"
18 #include "mp_game_settings.hpp"
20 #include "settings.hpp"
21 #include "tod_manager.hpp"
22 
23 #include <cassert>
24 #include <iostream>
25 #include <sstream>
26 
27 namespace ng
28 {
30  : state_(state)
31  , parameters_(state_.mp_settings())
32  , initial_(initial ? initial : &state_.get_starting_pos())
33 {
35 }
36 
38 {
53 }
54 
56 {
57  return initial_cfg()["force_lock_settings"].to_bool(!state_.classification().is_normal_mp_game());
58 }
59 
61 {
62  utils::string_map i18n_symbols;
63  i18n_symbols["login"] = preferences::login();
64  return vgettext("$login|’s game", i18n_symbols);
65 }
66 
68 {
70 }
71 
73 {
74  return use_map_settings()
77 }
78 
80 {
81  return use_map_settings()
82  ? settings::get_village_support(initial_cfg()["mp_village_support"])
84 }
85 
87 {
88  return use_map_settings()
89  ? settings::get_xp_modifier(initial_cfg()["experience_modifier"])
91 }
92 
94 {
96 }
97 
99 {
101 }
102 
104 {
106 }
107 
109 {
111 }
112 
114 {
115  return preferences::countdown();
116 }
117 
119 {
121 }
122 
124 {
125  return use_map_settings()
126  ? initial_cfg()["random_start_time"].to_bool(false)
128 }
129 
131 {
132  return use_map_settings()
133  ? initial_cfg()["mp_fog"].to_bool(state_.classification().is_normal_mp_game())
134  : preferences::fog();
135 }
136 
138 {
139  return use_map_settings() ? initial_cfg()["mp_shroud"].to_bool(false) : preferences::shroud();
140 }
141 
143 {
145 }
146 
148 {
150 }
151 
153 {
155 }
156 
157 mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode_default() const
158 {
159  return mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(
160  preferences::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT);
161 }
162 
164 {
165  return preferences::options();
166 }
167 
169 {
171  const mp_game_settings& params = this->state_.mp_settings();
172 
173  if(params.random_start_time) {
174  if(!tod_manager::is_start_ToD(scenario["random_start_time"])) {
175  scenario["random_start_time"] = true;
176  }
177  } else {
178  scenario["random_start_time"] = false;
179  }
180 
181  scenario["experience_modifier"] = params.xp_modifier;
182  scenario["turns"] = params.num_turns;
183 
184  for(config& side : scenario.child_range("side")) {
185  if(!params.use_map_settings) {
186  side["fog"] = params.fog_game;
187  side["shroud"] = params.shroud_game;
188  side["village_gold"] = params.village_gold;
189  side["village_support"] = params.village_support;
190  } else {
191  if(side["fog"].empty()) {
192  side["fog"] = params.fog_game;
193  }
194 
195  if(side["shroud"].empty()) {
196  side["shroud"] = params.shroud_game;
197  }
198 
199  if(side["village_gold"].empty()) {
200  side["village_gold"] = params.village_gold;
201  }
202 
203  if(side["village_support"].empty()) {
204  side["village_support"] = params.village_support;
205  }
206  }
207  }
208 }
209 
210 } // end namespace ng
int mp_countdown_reservoir_time_default() const
void set_shroud_game(bool val)
std::vector< char_t > string
void set_mp_countdown_reservoir_time(int val)
std::string random_faction_mode()
Definition: game.cpp:485
std::map< std::string, t_string > string_map
int num_turns_default() const
bool use_map_settings_default() const
int xp_modifier()
Definition: game.cpp:690
bool use_map_settings() const
child_itors child_range(config_key_type key)
Definition: config.cpp:295
bool shuffle_sides()
Definition: game.cpp:475
int xp_modifier_default() const
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
Definition: settings.cpp:40
bool random_start_time_default() const
const config & initial_cfg() const
void set_random_start_time(bool val)
bool fog_game_default() const
void set_village_gold(int val)
int countdown_init_time()
Definition: game.cpp:626
int get_village_support(const std::string &value)
Gets the village unit level support.
Definition: settings.cpp:45
bool fog()
Definition: game.cpp:540
void set_use_map_settings(bool val)
const config & options()
Definition: game.cpp:570
int countdown_turn_bonus()
Definition: game.cpp:648
void set_default_values()
Set all parameters to their default values.
int village_support()
Definition: game.cpp:680
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
int countdown_reservoir_time()
Definition: game.cpp:637
void set_village_support(int val)
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const
const config & options_default() const
void set_mp_countdown(bool val)
void set_fog_game(bool val)
bool registered_users_only()
Definition: game.cpp:465
void set_mp_countdown_action_bonus(int val)
int village_gold()
Definition: game.cpp:670
config & get_starting_pos()
Definition: saved_game.cpp:488
bool force_lock_settings() const
Checks force_lock_settings in config.
static std::string game_name_default()
std::string login()
bool countdown()
Definition: game.cpp:616
bool shroud()
Definition: game.cpp:550
int village_gold_default() const
int mp_countdown_turn_bonus_default() const
void set_mp_countdown_init_time(int val)
bool use_map_settings()
Definition: game.cpp:493
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
Definition: settings.cpp:50
bool registered_users_only_default() const
std::string vgettext(const char *msgid, const utils::string_map &symbols)
static bool is_start_ToD(const std::string &)
bool allow_observers()
Definition: game.cpp:455
void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
int turns()
Definition: game.cpp:560
game_classification & classification()
Definition: saved_game.hpp:55
bool shroud_game_default() const
bool mp_countdown_default() const
int countdown_action_bonus()
Definition: game.cpp:659
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
bool random_start_time()
Definition: game.cpp:530
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:59
int get_turns(const std::string &value)
Gets the number of turns.
Definition: settings.cpp:28
void set_xp_modifier(int val)
int mp_countdown_action_bonus_default() const
int village_support_default() const
configure_engine(saved_game &state, const config *initial=nullptr)