The Battle for Wesnoth  1.15.0-dev
configure_engine.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 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 "saved_game.hpp"
20 
21 namespace ng
22 {
23 /**
24  * configure_engine
25  *
26  * this class wraps the parameters relevant to mp_configure,
27  * as well as providing defaults for these parameters.
28  */
30 {
31 public:
32  configure_engine(saved_game& state, const config* initial = nullptr);
33 
34  /** Set all parameters to their default values. */
35  void set_default_values();
36 
37  /** Checks force_lock_settings in config. */
38  bool force_lock_settings() const;
39 
40  //
41  // Getter methods
42  //
43 
44  std::string game_name() const
45  {
46  return parameters_.name;
47  }
48 
49  int num_turns() const
50  {
51  return parameters_.num_turns;
52  }
53 
54  int village_gold() const
55  {
57  }
58 
59  int village_support() const
60  {
62  }
63 
64  int xp_modifier() const
65  {
66  return parameters_.xp_modifier;
67  }
68 
70  {
72  }
73 
75  {
77  }
78 
80  {
82  }
83 
85  {
87  }
88 
89  bool mp_countdown() const
90  {
92  }
93 
94  bool use_map_settings() const
95  {
97  }
98 
99  bool random_start_time() const
100  {
102  }
103 
104  bool fog_game() const
105  {
106  return parameters_.fog_game;
107  }
108 
109  bool shroud_game() const
110  {
111  return parameters_.shroud_game;
112  }
113 
114  bool allow_observers() const
115  {
117  }
118 
120  {
122  }
123 
124  bool shuffle_sides() const
125  {
126  return parameters_.shuffle_sides;
127  }
128 
129  mp_game_settings::RANDOM_FACTION_MODE random_faction_mode() const
130  {
131  return parameters_.random_faction_mode;
132  }
133 
134  const config& options() const
135  {
136  return parameters_.options;
137  }
138 
139  //
140  // Setter methods
141  //
142 
143  void set_game_name(std::string name)
144  {
145  parameters_.name = name;
146  }
147 
148  void set_game_password(std::string name)
149  {
150  parameters_.password = name;
151  }
152 
153  void set_num_turns(int val)
154  {
155  parameters_.num_turns = val;
156  }
157 
158  void set_village_gold(int val)
159  {
161  }
162 
163  void set_village_support(int val)
164  {
166  }
167 
168  void set_xp_modifier(int val)
169  {
170  parameters_.xp_modifier = val;
171  }
172 
174  {
176  }
177 
179  {
181  }
182 
184  {
186  }
187 
189  {
191  }
192 
193  void set_mp_countdown(bool val)
194  {
196  }
197 
198  void set_use_map_settings(bool val)
199  {
201  }
202 
203  void set_random_start_time(bool val)
204  {
206  }
207 
208  void set_fog_game(bool val)
209  {
210  parameters_.fog_game = val;
211  }
212 
213  void set_shroud_game(bool val)
214  {
215  parameters_.shroud_game = val;
216  }
217 
218  void set_allow_observers(bool val)
219  {
221  }
222 
224  {
226  }
227 
228  void set_oos_debug(bool val)
229  {
231  }
232 
233  void set_shuffle_sides(bool val)
234  {
236  }
237 
238  void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
239  {
240  parameters_.random_faction_mode = val;
241  }
242 
243  void set_options(const config& cfg);
244 
245  //
246  // Parameter defaults
247  //
248 
249  static std::string game_name_default();
250  int num_turns_default() const;
251  int village_gold_default() const;
252  int village_support_default() const;
253  int xp_modifier_default() const;
254  int mp_countdown_init_time_default() const;
258  bool mp_countdown_default() const;
259  bool use_map_settings_default() const;
260  bool random_start_time_default() const;
261  bool fog_game_default() const;
262  bool shroud_game_default() const;
263  bool allow_observers_default() const;
264  bool registered_users_only_default() const;
265  bool shuffle_sides_default() const;
266  mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const;
267  const config& options_default() const;
268 
270  {
271  return parameters_;
272  }
273 
274  void write_parameters();
275 
276  void update_initial_cfg(const config& cfg)
277  {
278  initial_ = &cfg;
279  }
280 
281 private:
283 
285 
286  /// Never nullptr.
287  const config* initial_;
288 
289  /**
290  * Village gold, village support, fog, and shroud are per player but always show the
291  * player 1's values.
292  *
293  * @todo This might not be 100% correct, but at the moment it is not possible to show
294  * fog and shroud per player. This might change in the future.
295  *
296  * @todo: Is the above even still true?
297  * -- vultraz, 2017-10-05
298  *
299  * NOTE when 'load game' is selected there are no sides.
300  */
301  const config& side_cfg() const
302  {
303  return initial_->child_or_empty("side");
304  }
305 
306  const config& initial_cfg() const
307  {
308  return *initial_;
309  }
310 };
311 
312 } // end namespace ng
void set_registered_users_only(bool val)
void update_initial_cfg(const config &cfg)
const config & options_default() const
void set_shroud_game(bool val)
std::string game_name() const
const config * initial_
Never nullptr.
configure_engine
void set_mp_countdown_reservoir_time(int val)
void set_shuffle_sides(bool val)
bool allow_observers_default() const
bool shroud_game_default() const
int mp_countdown_init_time_default() const
void set_mp_countdown_turn_bonus(int val)
int mp_countdown_turn_bonus() const
bool use_map_settings_default() const
mp_game_settings & parameters_
void set_random_start_time(bool val)
int mp_countdown_action_bonus() const
void set_village_gold(int val)
void set_use_map_settings(bool val)
void set_default_values()
Set all parameters to their default values.
void set_game_name(std::string name)
void set_village_support(int val)
bool random_start_time() const
void set_oos_debug(bool val)
const config & options() const
void set_mp_countdown(bool val)
const config & side_cfg() const
Village gold, village support, fog, and shroud are per player but always show the player 1&#39;s values...
void set_fog_game(bool val)
void set_mp_countdown_action_bonus(int val)
const mp_game_settings & get_parameters() const
const config & initial_cfg() const
static std::string game_name_default()
int mp_countdown_reservoir_time() const
int xp_modifier_default() const
void set_allow_observers(bool val)
bool shuffle_sides_default() const
void set_mp_countdown_init_time(int val)
void set_game_password(std::string name)
int mp_countdown_turn_bonus_default() const
int mp_countdown_reservoir_time_default() const
bool use_map_settings() const
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const
int mp_countdown_action_bonus_default() const
bool registered_users_only() const
bool mp_countdown_default() const
void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
bool force_lock_settings() const
Checks force_lock_settings in config.
int village_support_default() const
game_classification & classification()
Definition: saved_game.hpp:55
bool registered_users_only_default() const
bool random_start_time_default() const
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:456
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
void set_xp_modifier(int val)
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode() const
int mp_countdown_init_time() const
configure_engine(saved_game &state, const config *initial=nullptr)
void set_options(const config &cfg)
int village_gold_default() const