The Battle for Wesnoth  1.17.0-dev
configure_engine.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2021
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 
153 mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode_default() const
154 {
155  return mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(
156  preferences::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT);
157 }
158 
160 {
161  parameters_.options = cfg;
163 }
164 
166 {
167  return preferences::options();
168 }
169 
171 {
173  const mp_game_settings& params = this->state_.mp_settings();
174 
175  if(params.random_start_time) {
176  if(!tod_manager::is_start_ToD(scenario["random_start_time"])) {
177  scenario["random_start_time"] = true;
178  }
179  } else {
180  scenario["random_start_time"] = false;
181  }
182 
183  scenario["experience_modifier"] = params.xp_modifier;
184  scenario["turns"] = params.num_turns;
185 
186  for(config& side : scenario.child_range("side")) {
187  if(!params.use_map_settings) {
188  side["fog"] = params.fog_game;
189  side["shroud"] = params.shroud_game;
190  side["village_gold"] = params.village_gold;
191  side["village_support"] = params.village_support;
192  } else {
193  if(side["fog"].empty()) {
194  side["fog"] = params.fog_game;
195  }
196 
197  if(side["shroud"].empty()) {
198  side["shroud"] = params.shroud_game;
199  }
200 
201  if(side["village_gold"].empty()) {
202  side["village_gold"] = params.village_gold;
203  }
204 
205  if(side["village_support"].empty()) {
206  side["village_support"] = params.village_support;
207  }
208  }
209  }
210 }
211 
212 } // 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:485
std::map< std::string, t_string > string_map
bool allow_observers_default() const
int xp_modifier()
Definition: game.cpp:685
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:344
bool shuffle_sides()
Definition: game.cpp:475
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:625
int get_village_support(const std::string &value)
Gets the village unit level support.
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:645
void set_default_values()
Set all parameters to their default values.
int village_support()
Definition: game.cpp:675
int countdown_reservoir_time()
Definition: game.cpp:635
void set_village_support(int val)
void set_mp_countdown(bool val)
config & get_starting_point()
Definition: saved_game.cpp:582
void set_fog_game(bool val)
void set_mp_countdown_action_bonus(int val)
int village_gold()
Definition: game.cpp:665
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: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)
void set_game_name(const std::string &name)
bool use_map_settings()
Definition: game.cpp:495
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.
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:465
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
int countdown_action_bonus()
Definition: game.cpp:655
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:61
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.
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