The Battle for Wesnoth  1.19.5+dev
configure_engine.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2024
3  Part of the Battle for Wesnoth Project https://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 
16 
17 #include "formula/string_utils.hpp"
18 #include "mp_game_settings.hpp"
20 #include "map_settings.hpp"
21 #include "tod_manager.hpp"
22 
23 
24 namespace ng
25 {
27  : state_(state)
28  , parameters_(state_.mp_settings())
29  , initial_(initial ? initial : &state_.get_starting_point())
30 {
32 }
33 
35 {
50 }
51 
53 {
54  return initial_cfg()["force_lock_settings"].to_bool(!state_.classification().is_normal_mp_game());
55 }
56 
58 {
59  utils::string_map i18n_symbols;
60  i18n_symbols["login"] = prefs::get().login();
61  return VGETTEXT("$login|’s game", i18n_symbols);
62 }
63 
65 {
66  return use_map_settings() ? settings::get_turns(initial_cfg()["turns"]) : prefs::get().mp_turns();
67 }
68 
70 {
71  return use_map_settings()
74 }
75 
77 {
78  return use_map_settings()
79  ? settings::get_village_support(initial_cfg()["mp_village_support"])
81 }
82 
84 {
85  return use_map_settings()
86  ? settings::get_xp_modifier(initial_cfg()["experience_modifier"])
87  : prefs::get().xp_modifier();
88 }
89 
91 {
93 }
94 
96 {
98 }
99 
101 {
102  return prefs::get().countdown_turn_bonus();
103 }
104 
106 {
108 }
109 
111 {
112  return prefs::get().mp_countdown();
113 }
114 
116 {
117  return force_lock_settings() || prefs::get().mp_use_map_settings();
118 }
119 
121 {
122  return use_map_settings()
123  ? initial_cfg()["random_start_time"].to_bool(false)
124  : prefs::get().mp_random_start_time();
125 }
126 
128 {
129  return use_map_settings()
130  ? initial_cfg()["mp_fog"].to_bool(state_.classification().is_normal_mp_game())
131  : prefs::get().mp_fog();
132 }
133 
135 {
136  return use_map_settings() ? initial_cfg()["mp_shroud"].to_bool(false) : prefs::get().mp_shroud();
137 }
138 
140 {
141  return prefs::get().allow_observers();
142 }
143 
145 {
146  return prefs::get().shuffle_sides();
147 }
148 
150 {
151  return random_faction_mode::get_enum(prefs::get().random_faction_mode()).value_or(random_faction_mode::type::independent);
152 }
153 
155 {
156  parameters_.options = cfg;
157  prefs::get().set_options(cfg);
158 }
159 
161 {
162  return prefs::get().options();
163 }
164 
166 {
168  const mp_game_settings& params = this->state_.mp_settings();
169 
170  if(params.random_start_time) {
171  if(!tod_manager::is_start_ToD(scenario["random_start_time"])) {
172  scenario["random_start_time"] = true;
173  }
174  } else {
175  scenario["random_start_time"] = false;
176  }
177 
178  scenario["experience_modifier"] = params.xp_modifier;
179  scenario["turns"] = params.num_turns;
180 
181  for(config& side : scenario.child_range("side")) {
182  if(!params.use_map_settings) {
183  side["fog"] = params.fog_game;
184  side["shroud"] = params.shroud_game;
185  side["village_gold"] = params.village_gold;
186  side["village_support"] = params.village_support;
187  } else {
188  if(side["fog"].empty()) {
189  side["fog"] = params.fog_game;
190  }
191 
192  if(side["shroud"].empty()) {
193  side["shroud"] = params.shroud_game;
194  }
195 
196  if(side["village_gold"].empty()) {
197  side["village_gold"] = params.village_gold;
198  }
199 
200  if(side["village_support"].empty()) {
201  side["village_support"] = params.village_support;
202  }
203  }
204  }
205 }
206 
207 } // end namespace ng
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
void set_options(const config &cfg)
void set_village_gold(int val)
static std::string game_name_default()
std::chrono::seconds mp_countdown_action_bonus_default() const
void set_xp_modifier(int val)
void set_fog_game(bool val)
int xp_modifier_default() const
bool mp_countdown_default() const
int village_gold_default() const
const config & options_default() const
std::chrono::seconds mp_countdown_init_time_default() const
configure_engine(saved_game &state, const config *initial=nullptr)
const config & initial_cfg() const
bool shuffle_sides_default() const
void set_village_support(int val)
void set_mp_countdown_action_bonus(const std::chrono::seconds &val)
mp_game_settings & parameters_
bool allow_observers_default() const
void set_random_faction_mode(random_faction_mode::type val)
void set_shroud_game(bool val)
std::chrono::seconds mp_countdown_turn_bonus_default() const
void set_random_start_time(bool val)
bool random_start_time_default() const
void set_use_map_settings(bool val)
bool shroud_game_default() const
bool force_lock_settings() const
Checks force_lock_settings in config.
void set_default_values()
Set all parameters to their default values.
void set_game_name(const std::string &name)
void set_mp_countdown(bool val)
random_faction_mode::type random_faction_mode_default() const
bool use_map_settings() const
bool use_map_settings_default() const
void set_mp_countdown_init_time(const std::chrono::seconds &val)
std::chrono::seconds mp_countdown_reservoir_time_default() const
int village_support_default() const
void set_mp_countdown_reservoir_time(const std::chrono::seconds &val)
const config & options()
int village_support()
std::chrono::seconds countdown_turn_bonus()
static prefs & get()
std::chrono::seconds countdown_init_time()
void set_options(const config &values)
std::chrono::seconds countdown_action_bonus()
int village_gold()
std::string login()
std::chrono::seconds countdown_reservoir_time()
int xp_modifier()
game_classification & classification()
Definition: saved_game.hpp:56
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:60
config & get_starting_point()
Definition: saved_game.cpp:612
static bool is_start_ToD(const std::string &)
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
General settings and defaults for scenarios.
int get_village_support(const std::string &value)
Gets the village unit level support.
int get_turns(const std::string &value)
Gets the number of turns.
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
std::map< std::string, t_string > string_map
string_enums::enum_base< random_faction_mode_defines > random_faction_mode
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Definition: enum_base.hpp:57