The Battle for Wesnoth  1.19.4+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 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 
119  bool shuffle_sides() const
120  {
121  return parameters_.shuffle_sides;
122  }
123 
125  {
126  return parameters_.mode;
127  }
128 
129  const config& options() const
130  {
131  return parameters_.options;
132  }
133 
134  //
135  // Setter methods
136  //
137 
138  void set_game_name(const std::string& name)
139  {
140  parameters_.name = name;
141  }
142 
143  void set_game_password(const std::string& name)
144  {
145  parameters_.password = name;
146  }
147 
148  void set_num_turns(int val)
149  {
150  parameters_.num_turns = val;
151  }
152 
153  void set_village_gold(int val)
154  {
156  }
157 
158  void set_village_support(int val)
159  {
161  }
162 
163  void set_xp_modifier(int val)
164  {
165  parameters_.xp_modifier = val;
166  }
167 
169  {
171  }
172 
174  {
176  }
177 
179  {
181  }
182 
184  {
186  }
187 
188  void set_mp_countdown(bool val)
189  {
191  }
192 
193  void set_use_map_settings(bool val)
194  {
196  }
197 
198  void set_random_start_time(bool val)
199  {
201  }
202 
203  void set_fog_game(bool val)
204  {
205  parameters_.fog_game = val;
206  }
207 
208  void set_shroud_game(bool val)
209  {
210  parameters_.shroud_game = val;
211  }
212 
213  void set_allow_observers(bool val)
214  {
216  }
217 
218  void set_private_replay(bool val)
219  {
221  }
222 
223  void set_oos_debug(bool val)
224  {
226  }
227 
228  void set_shuffle_sides(bool val)
229  {
231  }
232 
234  {
235  parameters_.mode = val;
236  }
237 
238  void set_options(const config& cfg);
239 
240  //
241  // Parameter defaults
242  //
243 
244  static std::string game_name_default();
245  int num_turns_default() const;
246  int village_gold_default() const;
247  int village_support_default() const;
248  int xp_modifier_default() const;
249  int mp_countdown_init_time_default() const;
253  bool mp_countdown_default() const;
254  bool use_map_settings_default() const;
255  bool random_start_time_default() const;
256  bool fog_game_default() const;
257  bool shroud_game_default() const;
258  bool allow_observers_default() const;
259  bool shuffle_sides_default() const;
261  const config& options_default() const;
262 
264  {
265  return parameters_;
266  }
267 
268  void write_parameters();
269 
270  void update_initial_cfg(const config& cfg)
271  {
272  initial_ = &cfg;
273  }
274 
275 private:
277 
279 
280  /** Never nullptr. */
281  const config* initial_;
282 
283  /**
284  * Village gold, village support, fog, and shroud are per player but always show the
285  * player 1's values.
286  *
287  * @todo This might not be 100% correct, but at the moment it is not possible to show
288  * fog and shroud per player. This might change in the future.
289  *
290  * @todo: Is the above even still true?
291  * -- vultraz, 2017-10-05
292  *
293  * NOTE when 'load game' is selected there are no sides.
294  */
295  const config& side_cfg() const
296  {
297  return initial_->child_or_empty("side");
298  }
299 
300  const config& initial_cfg() const
301  {
302  return *initial_;
303  }
304 };
305 
306 } // end namespace ng
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:163
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:393
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