The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
create_engine.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2016 by Andrius Silinskas <[email protected]>
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 #ifndef MULTIPLAYER_CREATE_ENGINE_HPP_INCLUDED
15 #define MULTIPLAYER_CREATE_ENGINE_HPP_INCLUDED
16 
17 #include "config.hpp"
18 #include "utils/make_enum.hpp"
19 #include "map/map.hpp"
20 #include "mp_game_settings.hpp"
21 #include "sdl/utils.hpp"
22 
23 #include <boost/scoped_ptr.hpp>
24 #include <string>
25 #include <utility>
26 
27 class CVideo;
28 class saved_game;
29 class map_generator;
30 namespace ng {
31 namespace depcheck { class manager; }
32 class level
33 {
34 public:
35  level(const config& data);
36  virtual ~level() {}
37 
39  (SCENARIO, "scenario")
40  (USER_MAP, "user_map")
41  (USER_SCENARIO, "user_scenario")
42  (RANDOM_MAP, "random_map")
43  (CAMPAIGN, "campaign")
44  (SP_CAMPAIGN, "sp_campaign")
45  )
46 
47  virtual bool can_launch_game() const = 0;
48 
49  virtual surface create_image_surface(const SDL_Rect& image_rect) = 0;
50 
51  virtual void set_metadata() = 0;
52 
53  virtual std::string name() const;
54  virtual std::string icon() const;
55  virtual std::string description() const;
56  virtual std::string id() const;
57  virtual bool allow_era_choice() const;
58 
59  void set_data(const config& data);
60  const config& data() const;
61  config& data();
62 
63 protected:
65 
66 private:
67  level(const level&);
68  void operator=(const level&);
69 };
70 
71 class scenario : public level
72 {
73 public:
74  scenario(const config& data);
75  virtual ~scenario();
76 
77  bool can_launch_game() const;
78 
79  surface create_image_surface(const SDL_Rect& image_rect);
80 
81  void set_metadata();
82 
83  int num_players() const;
84  std::string map_size() const;
85 
86 protected:
87  void set_sides();
88 
89  boost::scoped_ptr<gamemap> map_;
90 
93 
94 private:
95  scenario(const scenario&);
96  void operator=(const scenario&);
97 
99 };
100 
101 class user_map : public scenario
102 {
103 public:
104  user_map(const config& data, const std::string& name, gamemap* map);
105  virtual ~user_map();
106 
107  void set_metadata();
108 
109  std::string name() const;
110  std::string description() const;
111  std::string id() const;
112 
113 private:
114  user_map(const user_map&);
115  void operator=(const user_map&);
116 
118 };
119 
120 class random_map : public scenario
121 {
122 public:
123  random_map(const config& data);
124  virtual ~random_map();
125 
126  const config& generator_data() const;
127 
128  std::string name() const;
129  std::string description() const;
130  std::string id() const;
131  std::string generator_name() const;
132 
134 
135  bool generate_whole_scenario() const;
136 
137 private:
138  random_map(const random_map&);
139  void operator=(const random_map&);
140 
142 
145 };
146 
147 class campaign : public level
148 {
149 public:
150  campaign(const config& data);
151  virtual ~campaign();
152 
153  bool can_launch_game() const;
154 
155  surface create_image_surface(const SDL_Rect& image_rect);
156 
157  void set_metadata();
158 
159  void mark_if_completed();
160 
161  std::string id() const;
162 
163  bool allow_era_choice() const;
164 
165  int min_players() const;
166  int max_players() const;
167 
168 private:
169  campaign(const campaign&);
170  void operator=(const campaign&);
171 
177 };
178 
180 {
181 public:
182  create_engine(CVideo& v, saved_game& state);
183  ~create_engine();
184 
185  enum MP_EXTRA { ERA, MOD };
186 
188  {
192  };
193 
195 
201 
202  void init_generated_level_data();
203 
204  void prepare_for_new_level();
205  void prepare_for_era_and_mods();
206  void prepare_for_scenario();
207  void prepare_for_campaign(const std::string& difficulty);
208  void prepare_for_saved_game();
209  //random maps, user maps
210  void prepare_for_other();
211 
212  std::string select_campaign_difficulty(int set_value = -1);
213 
214  void apply_level_filter(const std::string& name);
215  void apply_level_filter(int players);
216  void reset_level_filters();
217 
218  const std::string& level_name_filter() const;
219  int player_num_filter() const;
220 
221  std::vector<level_ptr> get_levels_by_type_unfiltered(level::TYPE type) const;
222  std::vector<level_ptr> get_levels_by_type(level::TYPE type) const;
223 
224  std::vector<std::string> levels_menu_item_names() const;
225  std::vector<std::string> extras_menu_item_names(
226  const MP_EXTRA extra_type, bool escape_markup = true) const;
227 
228  level& current_level() const;
229  const extras_metadata& current_extra(const MP_EXTRA extra_type) const;
230 
231  void set_current_level_type(const level::TYPE);
232  level::TYPE current_level_type() const;
233 
234  void set_current_level(const size_t index);
235 
236  void set_current_era_index(const size_t index, bool force = false);
237  void set_current_mod_index(const size_t index);
238 
239  size_t current_era_index() const;
240  size_t current_mod_index() const;
241 
242  const std::vector<extras_metadata_ptr>&
243  get_const_extras_by_type(const MP_EXTRA extra_type) const;
244  std::vector<extras_metadata_ptr>&
245  get_extras_by_type(const MP_EXTRA extra_type);
246 
247  bool toggle_current_mod(bool force = false);
248 
249  bool generator_assigned() const;
250  void generator_user_config(CVideo& v);
251 
252  int find_level_by_id(const std::string& id) const;
253  int find_extra_by_id(const MP_EXTRA extra_type, const std::string& id) const;
254  level::TYPE find_level_type_by_id(const std::string& id) const;
255 
256  const depcheck::manager& dependency_manager() const;
257 
258  void init_active_mods();
259  std::vector<std::string>& active_mods();
260 
261  const mp_game_settings& get_parameters();
262 
263  saved_game& get_state();
264 
265 private:
267  void operator=(const create_engine&);
268 
269  void init_all_levels();
270  void init_extras(const MP_EXTRA extra_type);
271  void apply_level_filters();
272 
273  size_t map_level_index(size_t index) const;
274 
277 
280 
283 
284  std::vector<scenario_ptr> scenarios_;
285  std::vector<user_map_ptr> user_maps_;
286  std::vector<scenario_ptr> user_scenarios_;
287  std::vector<campaign_ptr> campaigns_;
288  std::vector<campaign_ptr> sp_campaigns_;
289  std::vector<random_map_ptr> random_maps_;
290 
291  std::vector<size_t> scenarios_filtered_;
292  std::vector<size_t> user_maps_filtered_;
293  std::vector<size_t> user_scenarios_filtered_;
294  std::vector<size_t> campaigns_filtered_;
295  std::vector<size_t> sp_campaigns_filtered_;
296  std::vector<size_t> random_maps_filtered_;
297 
298  std::vector<std::string> user_map_names_;
299  std::vector<std::string> user_scenario_names_;
300 
301  std::vector<extras_metadata_ptr> eras_;
302  std::vector<extras_metadata_ptr> mods_;
303 
305 
307  //Never nullptr
308  boost::scoped_ptr<depcheck::manager> dependency_manager_;
309 
310  boost::scoped_ptr<map_generator> generator_;
311 };
312 
313 } // end namespace ng
314 #endif
boost::shared_ptr< extras_metadata > extras_metadata_ptr
config data_
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: image.hpp:208
std::vector< extras_metadata_ptr > mods_
boost::shared_ptr< campaign > campaign_ptr
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
Definition: video.hpp:58
virtual std::string name() const
std::vector< std::string > user_scenario_names_
MAKE_ENUM(TYPE,(SCENARIO,"scenario")(USER_MAP,"user_map")(USER_SCENARIO,"user_scenario")(RANDOM_MAP,"random_map")(CAMPAIGN,"campaign")(SP_CAMPAIGN,"sp_campaign")) virtual bool can_launch_game() const =0
bool generate_whole_scenario_
std::vector< size_t > user_maps_filtered_
STL namespace.
boost::shared_ptr< random_map > random_map_ptr
void set_data(const config &data)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
std::vector< random_map_ptr > random_maps_
Definitions for the interface to Wesnoth Markup Language (WML).
std::vector< size_t > scenarios_filtered_
std::string level_name_filter_
saved_game & state_
std::vector< scenario_ptr > scenarios_
const GLdouble * v
Definition: glew.h:1359
level::TYPE current_level_type_
Encapsulates the map of the game.
Definition: map.hpp:37
virtual void set_metadata()=0
std::vector< size_t > random_maps_filtered_
std::string image_label_
virtual surface create_image_surface(const SDL_Rect &image_rect)=0
boost::shared_ptr< level > level_ptr
map_generator * create_map_generator(const std::string &name, const config &cfg)
Definition: map_create.cpp:31
virtual bool allow_era_choice() const
std::string map_hash_
std::vector< campaign_ptr > sp_campaigns_
std::vector< user_map_ptr > user_maps_
level(const config &data)
GLuint index
Definition: glew.h:1782
boost::shared_ptr< scenario > scenario_ptr
std::vector< std::string > user_map_names_
boost::scoped_ptr< depcheck::manager > dependency_manager_
std::vector< size_t > sp_campaigns_filtered_
std::vector< scenario_ptr > user_scenarios_
GLuint const GLchar * name
Definition: glew.h:1782
std::string name_
boost::shared_ptr< user_map > user_map_ptr
std::vector< extras_metadata_ptr > eras_
boost::scoped_ptr< gamemap > map_
void operator=(const level &)
std::vector< size_t > campaigns_filtered_
virtual ~level()
std::string id_
virtual std::string description() const
virtual std::string icon() const
surface minimap_img_
std::vector< size_t > user_scenarios_filtered_
virtual std::string id() const
std::string generator_name_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
Defines the MAKE_ENUM macro.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::vector< campaign_ptr > campaigns_
boost::scoped_ptr< map_generator > generator_