The Battle for Wesnoth  1.13.10+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 - 2017 by David White <dave@whitevine.net>
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 #pragma once
18 
19 #include "config.hpp"
21 #include "terrain/translation.hpp"
22 
23 #include <set>
24 #include <boost/optional.hpp>
25 #include <random>
26 
28 {
29 public:
31 
32  std::string name() const { return "cave"; }
33 
34  std::string config_name() const;
35 
36  std::string create_map(boost::optional<uint32_t> randomseed = boost::none);
37  config create_scenario(boost::optional<uint32_t> randomseed = boost::none);
38 
39 private:
41  {
42  cave_map_generator_job(const cave_map_generator& params, boost::optional<uint32_t> randomseed = boost::none);
43 
44  struct chamber {
46  : center()
47  , locs()
48  , items(0)
49  {
50  }
51 
53  std::set<map_location> locs;
54  const config *items;
55  };
56 
57  struct passage {
59  : src(s), dst(d), cfg(c)
60  {}
63  };
64 
65  void generate_chambers();
66  void build_chamber(map_location loc, std::set<map_location>& locs, size_t size, size_t jagged);
67 
68  void place_chamber(const chamber& c);
69 
70  void place_passage(const passage& p);
71 
73  void place_castle(int starting_position, const map_location &loc);
74 
75  size_t translate_x(size_t x) const;
76  size_t translate_y(size_t y) const;
77 
78 
80  bool flipx_, flipy_;
81 
84  std::map<std::string,size_t> chamber_ids_;
85  std::vector<chamber> chambers_;
86  std::vector<passage> passages_;
88  std::mt19937 rng_;
89  };
90 
91  bool on_board(const map_location& loc) const
92  {
93  return loc.x >= 0 && loc.y >= 0 && loc.x < width_ && loc.y < height_;
94  }
95 
97 
100 
101  // The scenario may have a chance to flip all x values or y values
102  // to make the scenario appear all random. This is kept track of here.
104 };
std::vector< char_t > string
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 ...
t_translation::terrain_code village_
std::string name() const
Returns a string identifying the generator by name.
std::string create_map(boost::optional< uint32_t > randomseed=boost::none)
Creates a new map and returns it.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:55
t_translation::terrain_code clear_
#define d
Definitions for the interface to Wesnoth Markup Language (WML).
t_translation::terrain_code wall_
t_translation::terrain_code keep_
config create_scenario(boost::optional< uint32_t > randomseed=boost::none)
cave_map_generator_job(const cave_map_generator &params, boost::optional< uint32_t > randomseed=boost::none)
passage(map_location s, map_location d, const config &c)
void place_castle(int starting_position, const map_location &loc)
Encapsulates the map of the game.
Definition: location.hpp:40
size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
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
mock_party p
Game configuration data as global variables.
Definition: build_info.cpp:53
static map_location::DIRECTION s
double t
Definition: astarsearch.cpp:64
t_translation::terrain_code castle_
void set_terrain(map_location loc, const t_translation::terrain_code &t)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
mock_char c
cave_map_generator(const config &game_config)
t_translation::starting_positions starting_positions_
boost::bimaps::bimap< boost::bimaps::set_of< std::string >, boost::bimaps::multiset_of< coordinate >> starting_positions