The Battle for Wesnoth  1.17.10+dev
configure_engine.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2022
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 "preferences/game.hpp"
21 #include "map_settings.hpp"
22 #include "tod_manager.hpp"
23 
24 #include <cassert>
25 #include <sstream>
26 
27 namespace ng
28 {
30  : state_(state)
31  , parameters_(state_.mp_settings())
32  , initial_(initial ? initial : &state_.get_starting_point())
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 {
154  return random_faction_mode::get_enum(preferences::random_faction_mode()).value_or(random_faction_mode::type::independent);
155 }
156 
158 {
159  parameters_.options = cfg;
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
const config & options_default() const
void set_shroud_game(bool val)
void set_mp_countdown_reservoir_time(int val)
void set_random_faction_mode(random_faction_mode::type val)
std::string random_faction_mode()
Definition: game.cpp:472
std::map< std::string, t_string > string_map
bool allow_observers_default() const
int xp_modifier()
Definition: game.cpp:672
bool shroud_game_default() const
void set_options(const config &values)
Definition: game.cpp:576
int mp_countdown_init_time_default() const
child_itors child_range(config_key_type key)
Definition: config.cpp:344
bool shuffle_sides()
Definition: game.cpp:462
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
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:612
int get_village_support(const std::string &value)
Gets the village unit level support.
bool fog()
Definition: game.cpp:526
void set_use_map_settings(bool val)
const config & options()
Definition: game.cpp:556
int countdown_turn_bonus()
Definition: game.cpp:632
void set_default_values()
Set all parameters to their default values.
int village_support()
Definition: game.cpp:662
int countdown_reservoir_time()
Definition: game.cpp:622
void set_village_support(int val)
random_faction_mode::type random_faction_mode_default() const
void set_mp_countdown(bool val)
config & get_starting_point()
Definition: saved_game.cpp:583
void set_fog_game(bool val)
void set_mp_countdown_action_bonus(int val)
int village_gold()
Definition: game.cpp:652
General settings and defaults for scenarios.
const config & initial_cfg() const
static std::string game_name_default()
std::string login()
bool countdown()
Definition: game.cpp:602
bool shroud()
Definition: game.cpp:536
int xp_modifier_default() const
bool shuffle_sides_default() const
static constexpr std::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Definition: enum_base.hpp:57
void set_mp_countdown_init_time(int val)
void set_game_name(const std::string &name)
bool use_map_settings()
Definition: game.cpp:482
int mp_countdown_turn_bonus_default() const
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
int mp_countdown_reservoir_time_default() const
bool use_map_settings() const
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
int mp_countdown_action_bonus_default() const
static bool is_start_ToD(const std::string &)
bool allow_observers()
Definition: game.cpp:452
bool mp_countdown_default() const
bool force_lock_settings() const
Checks force_lock_settings in config.
int turns()
Definition: game.cpp:546
int village_support_default() const
game_classification & classification()
Definition: saved_game.hpp:55
int countdown_action_bonus()
Definition: game.cpp:642
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:60
bool random_start_time()
Definition: game.cpp:516
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.
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