The Battle for Wesnoth  1.17.21+dev
configure_engine.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2023
3  by Nathan Walker <nathan.b.walker@vanderbilt.edu>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "gettext.hpp"
19 #include "mp_game_settings.hpp"
20 #include "saved_game.hpp"
21 
22 namespace ng
23 {
24 /**
25  * configure_engine
26  *
27  * this class wraps the parameters relevant 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 
45  std::string game_name() const
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 
120  bool shuffle_sides() const
121  {
122  return parameters_.shuffle_sides;
123  }
124 
126  {
127  return parameters_.mode;
128  }
129 
130  const config& options() const
131  {
132  return parameters_.options;
133  }
134 
135  //
136  // Setter methods
137  //
138 
139  void set_game_name(const std::string& name)
140  {
141  parameters_.name = name;
142  }
143 
144  void set_game_password(const std::string& name)
145  {
146  parameters_.password = name;
147  }
148 
149  void set_num_turns(int val)
150  {
151  parameters_.num_turns = val;
152  }
153 
154  void set_village_gold(int val)
155  {
157  }
158 
159  void set_village_support(int val)
160  {
162  }
163 
164  void set_xp_modifier(int val)
165  {
166  parameters_.xp_modifier = val;
167  }
168 
170  {
172  }
173 
175  {
177  }
178 
180  {
182  }
183 
185  {
187  }
188 
189  void set_mp_countdown(bool val)
190  {
192  }
193 
194  void set_use_map_settings(bool val)
195  {
197  }
198 
199  void set_random_start_time(bool val)
200  {
202  }
203 
204  void set_fog_game(bool val)
205  {
206  parameters_.fog_game = val;
207  }
208 
209  void set_shroud_game(bool val)
210  {
211  parameters_.shroud_game = val;
212  }
213 
214  void set_allow_observers(bool val)
215  {
217  }
218 
219  void set_private_replay(bool val)
220  {
222  }
223 
224  void set_oos_debug(bool val)
225  {
227  }
228 
229  void set_shuffle_sides(bool val)
230  {
232  }
233 
235  {
236  parameters_.mode = val;
237  }
238 
239  void set_options(const config& cfg);
240 
241  //
242  // Parameter defaults
243  //
244 
245  static std::string game_name_default();
246  int num_turns_default() const;
247  int village_gold_default() const;
248  int village_support_default() const;
249  int xp_modifier_default() const;
250  int mp_countdown_init_time_default() const;
254  bool mp_countdown_default() const;
255  bool use_map_settings_default() const;
256  bool random_start_time_default() const;
257  bool fog_game_default() const;
258  bool shroud_game_default() const;
259  bool allow_observers_default() const;
260  bool shuffle_sides_default() const;
262  const config& options_default() const;
263 
265  {
266  return parameters_;
267  }
268 
269  void write_parameters();
270 
271  void update_initial_cfg(const config& cfg)
272  {
273  initial_ = &cfg;
274  }
275 
276 private:
278 
280 
281  /** Never nullptr. */
282  const config* initial_;
283 
284  /**
285  * Village gold, village support, fog, and shroud are per player but always show the
286  * player 1's values.
287  *
288  * @todo This might not be 100% correct, but at the moment it is not possible to show
289  * fog and shroud per player. This might change in the future.
290  *
291  * @todo: Is the above even still true?
292  * -- vultraz, 2017-10-05
293  *
294  * NOTE when 'load game' is selected there are no sides.
295  */
296  const config& side_cfg() const
297  {
298  return initial_->child_or_empty("side");
299  }
300 
301  const config& initial_cfg() const
302  {
303  return *initial_;
304  }
305 };
306 
307 } // end namespace ng
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
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:399
void set_options(const config &cfg)
const config & options() const
int mp_countdown_reservoir_time_default() const
void set_village_gold(int val)
static std::string game_name_default()
void set_xp_modifier(int val)
const mp_game_settings & get_parameters() const
int mp_countdown_reservoir_time() const
void set_mp_countdown_init_time(int val)
const config * initial_
Never nullptr.
void set_fog_game(bool val)
random_faction_mode::type mode() const
int xp_modifier_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.
bool mp_countdown_default() const
int village_gold_default() const
const config & options_default() const
configure_engine(saved_game &state, const config *initial=nullptr)
bool random_start_time() const
const config & initial_cfg() const
bool shuffle_sides_default() const
void set_village_support(int val)
mp_game_settings & parameters_
bool allow_observers_default() const
void set_oos_debug(bool val)
int mp_countdown_action_bonus_default() const
void set_random_faction_mode(random_faction_mode::type val)
void set_shroud_game(bool val)
void set_game_password(const std::string &name)
int mp_countdown_action_bonus() const
void set_random_start_time(bool val)
void update_initial_cfg(const config &cfg)
bool random_start_time_default() const
void set_allow_observers(bool val)
void set_use_map_settings(bool val)
bool shroud_game_default() const
int mp_countdown_turn_bonus_default() const
int mp_countdown_init_time() const
bool force_lock_settings() const
Checks force_lock_settings in config.
void set_default_values()
Set all parameters to their default values.
void set_game_name(const std::string &name)
int mp_countdown_turn_bonus() const
void set_mp_countdown_reservoir_time(int val)
void set_private_replay(bool val)
void set_mp_countdown(bool val)
random_faction_mode::type random_faction_mode_default() const
std::string game_name() const
void set_mp_countdown_action_bonus(int val)
void set_shuffle_sides(bool val)
void set_mp_countdown_turn_bonus(int val)
bool use_map_settings() const
bool use_map_settings_default() const
int mp_countdown_init_time_default() const
int village_support_default() const
game_classification & classification()
Definition: saved_game.hpp:56
random_faction_mode::type mode