The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cave_map_generator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[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 
15 /** @file */
16 
17 #ifndef CAVE_MAP_GENERATOR_HPP_INCLUDED
18 #define CAVE_MAP_GENERATOR_HPP_INCLUDED
19 
20 #include "config.hpp"
22 #include "terrain/translation.hpp"
23 
24 #include <set>
25 #include <boost/optional.hpp>
26 #include <boost/random.hpp>
27 
29 {
30 public:
32 
33  std::string name() const { return "cave"; }
34 
35  std::string config_name() const;
36 
37  std::string create_map(boost::optional<boost::uint32_t> randomseed = boost::none);
38  config create_scenario(boost::optional<boost::uint32_t> randomseed = boost::none);
39 
40 private:
42  {
43  cave_map_generator_job(const cave_map_generator& params, boost::optional<boost::uint32_t> randomseed = boost::none);
44 
45  struct chamber {
47  : center()
48  , locs()
49  , items(0)
50  {
51  }
52 
54  std::set<map_location> locs;
55  const config *items;
56  };
57 
58  struct passage {
60  : src(s), dst(d), cfg(c)
61  {}
64  };
65 
66  void generate_chambers();
67  void build_chamber(map_location loc, std::set<map_location>& locs, size_t size, size_t jagged);
68 
69  void place_chamber(const chamber& c);
70 
71  void place_passage(const passage& p);
72 
74  void place_castle(int starting_position, const map_location &loc);
75 
76  size_t translate_x(size_t x) const;
77  size_t translate_y(size_t y) const;
78 
79 
81  bool flipx_, flipy_;
82 
85  std::map<std::string,size_t> chamber_ids_;
86  std::vector<chamber> chambers_;
87  std::vector<passage> passages_;
89  boost::random::mt19937 rng_;
90  };
91 
92  bool on_board(const map_location& loc) const
93  {
94  return loc.x >= 0 && loc.y >= 0 && loc.x < width_ && loc.y < height_;
95  }
96 
98 
101 
102  // The scenario may have a chance to flip all x values or y values
103  // to make the scenario appear all random. This is kept track of here.
105 };
106 
107 #endif
std::string create_map(boost::optional< boost::uint32_t > randomseed=boost::none)
Creates a new map and returns it.
t_translation::tstarting_positions starting_positions_
boost::bimaps::bimap< boost::bimaps::set_of< std::string >, boost::bimaps::multiset_of< coordinate >> tstarting_positions
config create_scenario(boost::optional< boost::uint32_t > randomseed=boost::none)
const GLfloat * c
Definition: glew.h:12741
std::map< std::string, size_t > chamber_ids_
std::string config_name() const
Return a friendly name for the generator used to differentiate between different configs of the same ...
std::string name() const
Returns a string identifying the generator by name.
const GLfloat * params
Definition: glew.h:1499
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
GLenum src
Definition: glew.h:2392
#define d
GLdouble GLdouble t
Definition: glew.h:1366
Definitions for the interface to Wesnoth Markup Language (WML).
cave_map_generator_job(const cave_map_generator &params, boost::optional< boost::uint32_t > randomseed=boost::none)
std::vector< std::vector< t_terrain > > t_map
Definition: translation.hpp:76
t_translation::t_terrain keep_
GLenum GLenum dst
Definition: glew.h:2392
passage(map_location s, map_location d, const config &c)
GLfloat GLfloat p
Definition: glew.h:12766
t_translation::t_terrain village_
t_translation::t_terrain clear_
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
void place_castle(int starting_position, const map_location &loc)
Encapsulates the map of the game.
Definition: location.hpp:38
void build_chamber(map_location loc, std::set< map_location > &locs, size_t size, size_t jagged)
bool on_board(const map_location &loc) const
Game configuration data as global variables.
Definition: build_info.cpp:38
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
GLsizeiptr size
Definition: glew.h:1649
t_translation::t_terrain wall_
void set_terrain(map_location loc, const t_translation::t_terrain &t)
t_translation::t_terrain castle_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
cave_map_generator(const config &game_config)
GLdouble s
Definition: glew.h:1358
GLsizei const GLcharARB ** string
Definition: glew.h:4503