The Battle for Wesnoth  1.15.0-dev
configure_engine.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2018 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 "preferences/game.hpp"
21 #include "settings.hpp"
22 #include "tod_manager.hpp"
23 
24 #include <cassert>
25 #include <iostream>
26 #include <sstream>
27 
28 namespace ng
29 {
31  : state_(state)
32  , parameters_(state_.mp_settings())
33  , initial_(initial ? initial : &state_.get_starting_point())
34 {
36 }
37 
39 {
54 }
55 
57 {
58  return initial_cfg()["force_lock_settings"].to_bool(!state_.classification().is_normal_mp_game());
59 }
60 
62 {
63  utils::string_map i18n_symbols;
64  i18n_symbols["login"] = preferences::login();
65  return VGETTEXT("$login|’s game", i18n_symbols);
66 }
67 
69 {
71 }
72 
74 {
75  return use_map_settings()
78 }
79 
81 {
82  return use_map_settings()
83  ? settings::get_village_support(initial_cfg()["mp_village_support"])
85 }
86 
88 {
89  return use_map_settings()
90  ? settings::get_xp_modifier(initial_cfg()["experience_modifier"])
92 }
93 
95 {
97 }
98 
100 {
102 }
103 
105 {
107 }
108 
110 {
112 }
113 
115 {
116  return preferences::countdown();
117 }
118 
120 {
122 }
123 
125 {
126  return use_map_settings()
127  ? initial_cfg()["random_start_time"].to_bool(false)
129 }
130 
132 {
133  return use_map_settings()
134  ? initial_cfg()["mp_fog"].to_bool(state_.classification().is_normal_mp_game())
135  : preferences::fog();
136 }
137 
139 {
140  return use_map_settings() ? initial_cfg()["mp_shroud"].to_bool(false) : preferences::shroud();
141 }
142 
144 {
146 }
147 
149 {
151 }
152 
154 {
156 }
157 
158 mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode_default() const
159 {
160  return mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(
161  preferences::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT);
162 }
163 
165 {
166  parameters_.options = cfg;
168 }
169 
171 {
172  return preferences::options();
173 }
174 
176 {
178  const mp_game_settings& params = this->state_.mp_settings();
179 
180  if(params.random_start_time) {
181  if(!tod_manager::is_start_ToD(scenario["random_start_time"])) {
182  scenario["random_start_time"] = true;
183  }
184  } else {
185  scenario["random_start_time"] = false;
186  }
187 
188  scenario["experience_modifier"] = params.xp_modifier;
189  scenario["turns"] = params.num_turns;
190 
191  for(config& side : scenario.child_range("side")) {
192  if(!params.use_map_settings) {
193  side["fog"] = params.fog_game;
194  side["shroud"] = params.shroud_game;
195  side["village_gold"] = params.village_gold;
196  side["village_support"] = params.village_support;
197  } else {
198  if(side["fog"].empty()) {
199  side["fog"] = params.fog_game;
200  }
201 
202  if(side["shroud"].empty()) {
203  side["shroud"] = params.shroud_game;
204  }
205 
206  if(side["village_gold"].empty()) {
207  side["village_gold"] = params.village_gold;
208  }
209 
210  if(side["village_support"].empty()) {
211  side["village_support"] = params.village_support;
212  }
213  }
214  }
215 }
216 
217 } // end namespace ng
const config & options_default() const
void set_shroud_game(bool val)
void set_mp_countdown_reservoir_time(int val)
std::string random_faction_mode()
Definition: game.cpp:484
std::map< std::string, t_string > string_map
bool allow_observers_default() const
int xp_modifier()
Definition: game.cpp:689
bool shroud_game_default() const
void set_options(const config &values)
Definition: game.cpp:589
int mp_countdown_init_time_default() const
child_itors child_range(config_key_type key)
Definition: config.cpp:366
bool shuffle_sides()
Definition: game.cpp:474
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
Definition: settings.cpp:40
bool use_map_settings_default() const
mp_game_settings & parameters_
void set_random_start_time(bool val)
void set_village_gold(int val)
int countdown_init_time()
Definition: game.cpp:625
int get_village_support(const std::string &value)
Gets the village unit level support.
Definition: settings.cpp:45
bool fog()
Definition: game.cpp:539
void set_use_map_settings(bool val)
const config & options()
Definition: game.cpp:569
int countdown_turn_bonus()
Definition: game.cpp:647
void set_default_values()
Set all parameters to their default values.
int village_support()
Definition: game.cpp:679
void set_game_name(std::string name)
General settings and defaults for scenarios.
int countdown_reservoir_time()
Definition: game.cpp:636
void set_village_support(int val)
void set_mp_countdown(bool val)
config & get_starting_point()
Definition: saved_game.cpp:527
void set_fog_game(bool val)
bool registered_users_only()
Definition: game.cpp:464
void set_mp_countdown_action_bonus(int val)
int village_gold()
Definition: game.cpp:669
const config & initial_cfg() const
static std::string game_name_default()
std::string login()
bool countdown()
Definition: game.cpp:615
bool shroud()
Definition: game.cpp:549
int xp_modifier_default() const
bool shuffle_sides_default() const
void set_mp_countdown_init_time(int val)
bool use_map_settings()
Definition: game.cpp:492
int mp_countdown_turn_bonus_default() const
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
Definition: settings.cpp:50
int mp_countdown_reservoir_time_default() const
bool use_map_settings() const
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const
int mp_countdown_action_bonus_default() const
static bool is_start_ToD(const std::string &)
bool allow_observers()
Definition: game.cpp:454
void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
bool mp_countdown_default() const
bool force_lock_settings() const
Checks force_lock_settings in config.
int turns()
Definition: game.cpp:559
int village_support_default() const
game_classification & classification()
Definition: saved_game.hpp:55
bool registered_users_only_default() const
int countdown_action_bonus()
Definition: game.cpp:658
bool random_start_time_default() const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
bool random_start_time()
Definition: game.cpp:529
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)
configure_engine(saved_game &state, const config *initial=nullptr)
void set_options(const config &cfg)
int village_gold_default() const