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