The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
configure_engine.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2017 by Nathan Walker <nathan.b.walker@vanderbilt.edu>
3  Part of the Battle for Wesnoth Project http://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 
15 #pragma once
16 
17 #include "gettext.hpp"
18 #include "mp_game_settings.hpp"
19 #include "preferences/game.hpp"
20 #include "saved_game.hpp"
21 
22 namespace ng
23 {
24 /**
25  * configure_engine
26  *
27  * this class wraps the parameters relevent to mp_configure,
28  * as well as providing defaults for these parameters.
29  */
31 {
32 public:
33  configure_engine(saved_game& state, const config* initial = nullptr);
34 
35  /** Set all parameters to their default values. */
36  void set_default_values();
37 
38  /** Checks force_lock_settings in config. */
39  bool force_lock_settings() const;
40 
41  //
42  // Getter methods
43  //
44 
46  {
47  return parameters_.name;
48  }
49 
50  int num_turns() const
51  {
52  return parameters_.num_turns;
53  }
54 
55  int village_gold() const
56  {
58  }
59 
60  int village_support() const
61  {
63  }
64 
65  int xp_modifier() const
66  {
67  return parameters_.xp_modifier;
68  }
69 
71  {
73  }
74 
76  {
78  }
79 
81  {
83  }
84 
86  {
88  }
89 
90  bool mp_countdown() const
91  {
93  }
94 
95  bool use_map_settings() const
96  {
98  }
99 
100  bool random_start_time() const
101  {
103  }
104 
105  bool fog_game() const
106  {
107  return parameters_.fog_game;
108  }
109 
110  bool shroud_game() const
111  {
112  return parameters_.shroud_game;
113  }
114 
115  bool allow_observers() const
116  {
118  }
119 
121  {
123  }
124 
125  bool shuffle_sides() const
126  {
127  return parameters_.shuffle_sides;
128  }
129 
130  mp_game_settings::RANDOM_FACTION_MODE random_faction_mode() const
131  {
132  return parameters_.random_faction_mode;
133  }
134 
135  const config& options() const
136  {
137  return parameters_.options;
138  }
139 
140  //
141  // Setter methods
142  //
143 
145  {
147  }
148 
150  {
152  }
153 
154  void set_num_turns(int val)
155  {
156  parameters_.num_turns = val;
157  }
158 
159  void set_village_gold(int val)
160  {
162  }
163 
164  void set_village_support(int val)
165  {
167  }
168 
169  void set_xp_modifier(int val)
170  {
171  parameters_.xp_modifier = val;
172  }
173 
175  {
177  }
178 
180  {
182  }
183 
185  {
187  }
188 
190  {
192  }
193 
194  void set_mp_countdown(bool val)
195  {
197  }
198 
199  void set_use_map_settings(bool val)
200  {
202  }
203 
204  void set_random_start_time(bool val)
205  {
207  }
208 
209  void set_fog_game(bool val)
210  {
211  parameters_.fog_game = val;
212  }
213 
214  void set_shroud_game(bool val)
215  {
216  parameters_.shroud_game = val;
217  }
218 
219  void set_allow_observers(bool val)
220  {
222  }
223 
225  {
227  }
228 
229  void set_oos_debug(bool val)
230  {
232  }
233 
234  void set_shuffle_sides(bool val)
235  {
237  }
238 
239  void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
240  {
241  parameters_.random_faction_mode = val;
242  }
243 
244  void set_options(const config& cfg)
245  {
246  parameters_.options = cfg;
247  }
248 
249  //
250  // Parameter defaults
251  //
252 
254  int num_turns_default() const;
255  int village_gold_default() const;
256  int village_support_default() const;
257  int xp_modifier_default() const;
258  int mp_countdown_init_time_default() const;
262  bool mp_countdown_default() const;
263  bool use_map_settings_default() const;
264  bool random_start_time_default() const;
265  bool fog_game_default() const;
266  bool shroud_game_default() const;
267  bool allow_observers_default() const;
268  bool registered_users_only_default() const;
269  bool shuffle_sides_default() const;
270  mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const;
271  const config& options_default() const;
272 
274  {
275  return parameters_;
276  }
277 
278  void write_parameters();
279 
280  void update_initial_cfg(const config& cfg)
281  {
282  initial_ = &cfg;
283  }
284 
285 private:
287 
289 
290  /// Never nullptr.
291  const config* initial_;
292 
293  /**
294  * Village gold, village support, fog, and shroud are per player but always show the
295  * player 1's values.
296  *
297  * @todo This might not be 100% correct, but at the moment it is not possible to show
298  * fog and shroud per player. This might change in the future.
299  *
300  * @todo: Is the above even still true?
301  * -- vultraz, 2017-10-05
302  *
303  * NOTE when 'load game' is selected there are no sides.
304  */
305  const config& side_cfg() const
306  {
307  return initial_->child_or_empty("side");
308  }
309 
310  const config& initial_cfg() const
311  {
312  return *initial_;
313  }
314 };
315 
316 } // end namespace ng
void set_registered_users_only(bool val)
void update_initial_cfg(const config &cfg)
int mp_countdown_reservoir_time_default() const
const config & side_cfg() const
Village gold, village support, fog, and shroud are per player but always show the player 1's values...
void set_shroud_game(bool val)
std::vector< char_t > string
const config * initial_
Never nullptr.
configure_engine
void set_mp_countdown_reservoir_time(int val)
void set_shuffle_sides(bool val)
int num_turns_default() const
const mp_game_settings & get_parameters() const
int mp_countdown_init_time() const
bool use_map_settings_default() const
bool use_map_settings() const
bool registered_users_only() const
void set_mp_countdown_turn_bonus(int val)
int mp_countdown_action_bonus() const
bool random_start_time() const
int xp_modifier_default() const
bool random_start_time_default() const
mp_game_settings & parameters_
int mp_countdown_reservoir_time() const
const config & initial_cfg() const
void set_random_start_time(bool val)
bool fog_game_default() const
void set_village_gold(int val)
void set_use_map_settings(bool val)
bool allow_observers() const
void set_default_values()
Set all parameters to their default values.
int mp_countdown_init_time_default() const
void set_game_name(std::string name)
bool shuffle_sides_default() const
bool allow_observers_default() const
void set_village_support(int val)
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const
const config & options_default() const
void set_oos_debug(bool val)
void set_mp_countdown(bool val)
void set_fog_game(bool val)
void set_mp_countdown_action_bonus(int val)
bool force_lock_settings() const
Checks force_lock_settings in config.
std::string game_name() const
static std::string game_name_default()
void set_allow_observers(bool val)
int village_gold_default() const
int mp_countdown_turn_bonus_default() const
void set_mp_countdown_init_time(int val)
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
Definition: config.cpp:433
void set_game_password(std::string name)
bool registered_users_only_default() const
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode() const
void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
int village_support() const
game_classification & classification()
Definition: saved_game.hpp:55
bool shroud_game_default() const
bool mp_countdown() const
bool mp_countdown_default() const
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
const config & options() const
void set_xp_modifier(int val)
int mp_countdown_action_bonus_default() const
int village_support_default() const
configure_engine(saved_game &state, const config *initial=nullptr)
int mp_countdown_turn_bonus() const
void set_options(const config &cfg)