The Battle for Wesnoth  1.17.4+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 <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 {
155  return random_faction_mode::get_enum(preferences::random_faction_mode()).value_or(random_faction_mode::type::independent);
156 }
157 
159 {
160  parameters_.options = cfg;
162 }
163 
165 {
166  return preferences::options();
167 }
168 
170 {
172  const mp_game_settings& params = this->state_.mp_settings();
173 
174  if(params.random_start_time) {
175  if(!tod_manager::is_start_ToD(scenario["random_start_time"])) {
176  scenario["random_start_time"] = true;
177  }
178  } else {
179  scenario["random_start_time"] = false;
180  }
181 
182  scenario["experience_modifier"] = params.xp_modifier;
183  scenario["turns"] = params.num_turns;
184 
185  for(config& side : scenario.child_range("side")) {
186  if(!params.use_map_settings) {
187  side["fog"] = params.fog_game;
188  side["shroud"] = params.shroud_game;
189  side["village_gold"] = params.village_gold;
190  side["village_support"] = params.village_support;
191  } else {
192  if(side["fog"].empty()) {
193  side["fog"] = params.fog_game;
194  }
195 
196  if(side["shroud"].empty()) {
197  side["shroud"] = params.shroud_game;
198  }
199 
200  if(side["village_gold"].empty()) {
201  side["village_gold"] = params.village_gold;
202  }
203 
204  if(side["village_support"].empty()) {
205  side["village_support"] = params.village_support;
206  }
207  }
208  }
209 }
210 
211 } // 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:478
std::map< std::string, t_string > string_map
bool allow_observers_default() const
int xp_modifier()
Definition: game.cpp:678
bool shroud_game_default() const
void set_options(const config &values)
Definition: game.cpp:582
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:468
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:618
int get_village_support(const std::string &value)
Gets the village unit level support.
bool fog()
Definition: game.cpp:532
void set_use_map_settings(bool val)
const config & options()
Definition: game.cpp:562
int countdown_turn_bonus()
Definition: game.cpp:638
void set_default_values()
Set all parameters to their default values.
int village_support()
Definition: game.cpp:668
int countdown_reservoir_time()
Definition: game.cpp:628
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:658
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:608
bool shroud()
Definition: game.cpp:542
int xp_modifier_default() const
bool shuffle_sides_default() const
void set_mp_countdown_init_time(int val)
void set_game_name(const std::string &name)
bool use_map_settings()
Definition: game.cpp:488
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:458
bool mp_countdown_default() const
bool force_lock_settings() const
Checks force_lock_settings in config.
int turns()
Definition: game.cpp:552
int village_support_default() const
static std::optional< typename T::type > get_enum(const std::string value)
Convert a string into its enum equivalent.
Definition: enum_base.hpp:52
game_classification & classification()
Definition: saved_game.hpp:55
int countdown_action_bonus()
Definition: game.cpp:648
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:522
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